Tuesday June 10, 2008
Using Java2DB feature of GlassFish v2
GlassFish V2 provides Java2DB feature which let users to specify database schema information in a JPA application. The persistence provider will use the information to define the corresponding schema in a database. I am using a Datatype test application as an example below to show how to use the Java2DB feature of GlassFish V2.
| ~/testbed > asadmin start-domain
~/testbed > asadmin start-database |
| ~/testbed >
asadmin create-jdbc-connection-pool --user admin --terse=false --target server
--property User=dbuser:Password=dbpassword:dataBaseName=testdb:serverName=localhost:portNumber=1527:create=true --echo=true --port 4848 --allownoncomponentcallers=false --interactive=true --passwordfile ~/testbed/adminpassword.txt --host localhost --datasourceclassname org.apache.derby.jdbc.ClientDataSource --nontransactionalconnections=false --restype javax.sql.DataSource datatype-pool1
|
| ~/testbed > asadmin create-jdbc-resource --interactive=true --passwordfile ~/testbed/adminpassword.txt --user admin --terse=false --enabled=true --host localhost --target server --echo=true --connectionpoolid datatype-pool1 --port 4848 jdbc/datatype1
|
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name ="manager">
<jta-data-source>jdbc/datatype1</jta-data-source>
<properties>
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>
| ~/testbed > asadmin deploy --user admin --terse=false --target server --echo=true --upload=true --port 4848 --interactive=true --passwordfile ~/testbed/adminpassword.txt --availabilityenabled=false --enabled=true --retrieve ~/testbed/ejb-cmp/archive --host localhost --generatermistubs=false --precompilejsp=false --force=true --name ejb-cmp-datatypesApp --verify=false ~/testbed/ejb-cmp/archive/ejb-cmp-datatypesApp.ear
|
| ~/testbed > appclient -client ~/testbed/ejb-cmp/archive/ejb-cmp-datatypesAppClient.jar EJB3_DataTypes_Java2DB
|
----------------------------------------- - Update_row : PASS - - Query_Integer : PASS - - Read_row: PASS - - Populate_INTEGER_MAXVAL: PASS - - Query_Long : PASS - - : PASS - - Create_row_ZEROVAL: PASS - - Average_LongData : PASS - - Average_FloatData : PASS - - Query_Short : PASS - - Query_Byte : PASS - - Query_SqlDate : PASS - - Average_ByteData : PASS - - Populate_LONG_MAXVAL: PASS - - Create_row_MEDIANVAL : PASS - - Average_IntegerData : PASS - - Query_Float : PASS - - Populate_BYTE_MAXVAL: PASS - - Populate_SHORT_MAXVAL: PASS - - Average_ShortData : PASS - - Query_Row_MAX_Value : PASS - - Query_UtilDate : PASS - - Query_TimeStamp : PASS - - Query_Character : PASS - - Delete_row : PASS - ----------------------------------------- Total PASS: 25 Total FAIL: 0 Total DNR: 0 -----------------------------------------
Posted at 01:16PM Jun 10, 2008 by Ming Zhang in Sun | Comments[0]
Friday May 23, 2008
JRuby/Rails with JPA on Glassfish V3
JRuby/Rails by default uses ActiveRecords package for the purposes of Object Relational Mapping (ORM). JPA is a JavaEE ORM technology and the advantage of JPA is its pluggability. Modeling class and database migration in Rails are what Entity class and persistence provider do in JavaEE.
The TP2 of GlassFish V3 was released just before 2008 JavaONE and the default persistence provider of V3 is Eclipse Link. It'll be interesting to see how easy it is to use JPA in a classic blog rails application. Vivek wrote in his blog that he used JPA and Rails on GlassFish V2 with TopLink as persistence provider. Here I would modify the blog demo application in his blog to fit for GlassFish V3 and Eclipse Link.
gem install rails -v=1.2.6 --no-rdoc --no-ri -–include-dependenciesThe latest Rails release 2.0.2 has a lot of differences with Rails 1.2.6. In this blog, JRuby1.0.3/Rails1.2.6 will be used and I'll write a follow up blog for the combination of JRuby 1.1.1/Rails 2.0.2.
gem install warblerWarbler is needed for creating war file from JRuby application.
JRUBY_HOME=/opt/jruby-1.0.3to the bottom of [Install_Dir]/glassfishv3-tp2/glassfish/config/asenv.conf
[Install_Dir]/glassfishv3-tp2/glassfish/asadmin start-domain.
Create Java Entity bean by following the steps described in Vivek’s blog. A short cut is to download the Entity code and import the code to Netbeans 6.1. The persistence provider in persistence.xml needs to be changed to Eclipse Link as shown below:
If the image appears small in your browser, please right click the image and choose "View Image" to see details. Build the project with “Shift + F11” and a new Post.jar will be created under Post/dist dir.
Deploy the repackaged Rails application onto GlassFish V3:
[Install_Dir]/glassfishv3-tp2/glassfish/asadmin deploy jpa_blog.warIn the GlassFish V3 server.log, the following message should display if the deployment is successful:
[#|2008-05-22T18:42:08.977-0700|INFO|GlassFish10.0|javax.enterprise.system.container.web|_ThreadID=12;_ThreadName=Thread-5;|PWC1412: WebModule[/jpa_blog] ServletContext.log():Info: using runtime pool timeout of 30 seconds|#] [#|2008-05-22T18:42:08.979-0700|INFO|GlassFish10.0|javax.enterprise.system.container.web|_ThreadID=12;_ThreadName=Thread-5;|PWC1412: WebModule[/jpa_blog] ServletContext.log():Warning: no initial runtimes specified.|#] [#|2008-05-22T18:42:08.981-0700|INFO|GlassFish10.0|javax.enterprise.system.container.web|_ThreadID=12;_ThreadName=Thread-5;|PWC1412: WebModule[/jpa_blog] ServletContext.log():Warning: no max runtimes specified.|#] [#|2008-05-22T18:42:09.009-0700|INFO|GlassFish10.0|javax.enterprise.system.container.web|_ThreadID=12;_ThreadName=Thread-5;|Loading application jpa_blog at /jpa_blog|#] [#|2008-05-22T18:42:09.034-0700|INFO|GlassFish10.0|javax.enterprise.system.tools.deployment|_ThreadID=12;_ThreadName=Thread-5;|Deployment of jpa_blog done is 15526 ms|#]
Then, access the blog application at: http://[HOST_NAME]:8080/jpa_blog/blog and the application should display:
Click “New post” link to create new blog entry:
Click “Create” button to submit the blog and the application will show the new blog created and a list of blogs created before:
Posted at 02:01PM May 23, 2008 by Ming Zhang in Sun | Comments[2]