Google

Campaign0

Thursday, January 17, 2008

Project Phobos - modifying the JPA example for PostgreSQL

Ran across Project Phobos the other day. It looks like a promising platform for rapid web application development. In a short while and after some input from the mailing list, I modified the JPA example to use PostgreSQL as the data store. Turned out to be a very easy switch from the builtin Netbeans JAVA DB to Pg.
To alter the JPA example to use PostgreSQL.
File/New Project/Scripting/Samples/Java Persistence APIs (JPA)
sample
Right click on libraries under jpaExample and add the
PostgreSQL JDBC library
Replace the current persistence properties with
( right click image to open in a new window )

verify that the pg_userid and pg_userpasswd can connect to the db
via psql on the command line
right click on jpaexamplesrc and clean and build the project
right click on jpaExample and run project.
I don't think I missed noting anything.
The web page( right click image to open in a new window ):

-------------------------------------------------------------
The correlating terminal capture from Pg.

jake@endpoint:~$ psql test
Welcome to psql 8.2.5, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

test=# \d
List of relations
Schema | Name | Type | Owner
--------+----------------------+----------+-------
public | author | table | jake
public | author_author_id_seq | sequence | jake
public | book | table | jake
(3 rows)

test=# \d author
Table "public.author"
Column | Type | Modifiers
--------------+------------------------+------------------------------------------------------------
author_id | integer | not null default nextval('author_author_id_seq'::regclass)
organisation | character varying(255) |
name | character varying(255) |
Indexes:
"author_pkey" PRIMARY KEY, btree (author_id)

test=# \d book
Table "public.book"
Column | Type | Modifiers
---------------+------------------------+-----------
book_id | integer | not null
isbn | character varying(255) |
authorid | integer |
publisheddate | date |
title | character varying(255) |
Indexes:
"book_pkey" PRIMARY KEY, btree (book_id)

test=# select * from author;
author_id | organisation | name
-----------+----------------+-----------------
1 | jMaki | Greg Murray
2 | Sun US | Ludo Champenois
3 | Java Inc | James Gosling
4 | Wrox Press Inc | Paul Wilton
5 | O'Reilly | Danny Goodman
6 | JPA Press Inc | Pramod Gopinath
(6 rows)

test=# select * from book;
book_id | isbn | authorid | publisheddate | title
---------+------+----------+---------------+-------
(0 rows)

No comments: