Tips on Sun ONE App Server 7 and Postgres 7.2 - Mailing list pgsql-jdbc

From Joe Howes
Subject Tips on Sun ONE App Server 7 and Postgres 7.2
Date
Msg-id 3E645219.30308@guild1.com
Whole thread Raw
List pgsql-jdbc
I got Sun ONE Application Server (SOAS) 7 talking to Postgres this
morning and since I had a heck of a time finding anyone else on the net
who's done it, here's what I discovered.

Coming from JBoss, the following things needed to be done to my application:


1) SOAS is way more picky about all your DAOs implementing
java.io.Serializable. Although it won't tell you this directly, it will
solve runtime problems when you find the app server has trouble passing
some filled out DAO around.


2) If you are using Struts Tiles, SOAS is more picky about the paths you
refer to. So, if your layout and other pages exist in the same
directory, you still need to enter their absolute paths. Instead of:

<tiles:insert page="appLayout.jsp" flush="true">
<tiles:put name="left" value="nav.jsp"/>
<tiles:put name="content" value="createAccount-content.jsp"/>
</tiles:insert>

you need:

<tiles:insert page="/jsp/appLayout.jsp" flush="true">
<tiles:put name="left" value="/jsp/nav.jsp"/>
<tiles:put name="content" value="/jsp/createAccount-content.jsp"/>
</tiles:insert>


3) JBoss is very forgiving about not having resource-ref settings in the
DDs, SOAS is not. Put them EVERYWHERE you will have DB access.



SOAS and Application Settings
=============================

SOAS Admin Interface (Under server1 | JDBC):
--------------------------------------------

JDBC Resources:
- JNDI Name: jdbc/jdbc-fooDS
- Pool Name: FooPool

Connection Pools:
- JNDI Name: FooPool
- Datasource Classname: org.postgresql.jdbc3.Jdbc3SimpleDataSource
(You can choose a Type 2 or pooling implementation here...see
www.postgresql.org)
- Properties:
- serverName: localhost
- portNumber: 0
- user: foo
- password: foo
- databaseName: foo
(Having used 'createdb foo' and 'createuser foo')


Deployment Descriptor Excerpts:
-------------------------------

ejb-jar.xml:

<session>
<description>Test Controller Bean</description>
<display-name>TestControllerEJB</display-name>
<ejb-name>TestControllerEJB</ejb-name>
<home>ca.joehowes.soastest.ejb.TestControllerHome</home>
<remote>ca.joehowes.soastest.ejb.TestController</remote>
<ejb-class>ca.joehowes.soastest.ejb.TestControllerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
<resource-ref>
<res-ref-name>jdbc/jdbc-fooDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</session>

<entity>
<description>Foo Bean</description>
<display-name>FooEJB</display-name>
<ejb-name>FooEJB</ejb-name>
<home>ca.joehowes.soastest.ejb.TestHome</home>
<remote>ca.joehowes.soastest.ejb.Test</remote>
<ejb-class>ca.joehowes.soastest.ejb.TestBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
<res-ref-name>jdbc/jdbc-coachds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</entity>


sun-ejb-jar.xml:

<ejb>
<ejb-name>TestControllerEJB</ejb-name>
<jndi-name>ejb/soastest/TestControllerEJB</jndi-name>
<resource-ref>
<res-ref-name>jdbc/jdbc-fooDS</res-ref-name>
<jndi-name>jdbc/jdbc-fooDS</jndi-name>
</resource-ref>
<is-read-only-bean>false</is-read-only-bean>
<bean-pool>
<steady-pool-size>20</steady-pool-size>
<resize-quantity>5</resize-quantity>
<max-pool-size>100</max-pool-size>
<pool-idle-timeout-in-seconds>3600</pool-idle-timeout-in-seconds>
</bean-pool>
</ejb>

<ejb>
<ejb-name>TestEJB</ejb-name>
<jndi-name>ejb/soastest/TestEJB</jndi-name>
<resource-ref>
<res-ref-name>jdbc/jdbc-fooDS</res-ref-name>
<jndi-name>jdbc/jdbc-fooDS</jndi-name>
</resource-ref>
<is-read-only-bean>false</is-read-only-bean>
<bean-pool>
<steady-pool-size>20</steady-pool-size>
<resize-quantity>5</resize-quantity>
<max-pool-size>100</max-pool-size>
<pool-idle-timeout-in-seconds>3600</pool-idle-timeout-in-seconds>
</bean-pool>
</ejb>


Code to lookup the resource and connect:
----------------------------------------

javax.naming.InitialContext ic = new javax.naming.InitialContext();
javax.sql.DataSource ds =
(javax.sql.DataSource)ic.lookup(java:comp/env/jdbc/jdbc-coachds);
con = ds.getConnection();
if (con == null) {
throw new RemoteException("Unable to establish a connection to the
database.");
}




This should save some of you some time...


- Joe


pgsql-jdbc by date:

Previous
From: Daniel Bruce Lynes
Date:
Subject: Re: I can't insert the chinese words.
Next
From: Ian McFarland
Date:
Subject: Closing one connection closes all connections?