Sun ONE Application Server 7

Introduction

As of JAG 3.3 initial support for the Sun ONE Application Server 7 has been added. CMP With Container Managed Relations have been tested on a MySQL database.

Setting up a mysql database

To use the Sun ONE Application Server 7 with JAG a small example will be described using a mysql database. Use the following instructions to setup a mysql database for this Example. Create a "test" database and run the following sql scripts:

mysql use test

drop table song;

drop table cd;

drop table pktest;

CREATE TABLE CD ( CD_ID INT NOT NULL, CD_TITLE TEXT, INDEX (CD_ID), PRIMARY KEY (CD_ID)) TYPE = INNODB;

CREATE TABLE SONG (SONG_ID INT NOT NULL, CD_ID INT, SONG_NAME TEXT, INDEX CD_IND (CD_ID), PRIMARY KEY (SONG_ID), FOREIGN KEY (CD_ID) REFERENCES CD(CD_ID) ON DELETE CASCADE) TYPE=INNODB;

CREATE TABLE PKTEST (SONG_ID INT NOT NULL, CD_ID INT NOT NULL, INDEX CD_IND1 (CD_ID), INDEX SONG_IND1 (SONG_ID), PRIMARY KEY (SONG_ID, CD_ID), FOREIGN KEY (SONG_ID) REFERENCES SONG(SONG_ID), FOREIGN KEY (CD_ID) REFERENCES CD(CD_ID) ON DELETE CASCADE) TYPE=INNODB;

insert into CD (CD_ID, CD_TITLE) values (10000000, 'my cd title');

insert into SONG values (20000000, 10000000, 'my first song');

insert into SONG values (20000001, 10000000, 'my second song');

insert into PKTEST values (3,11);

You must run the mySQL server in ANSI mode for CMP to work.

Add the option ansi to your mySQL command line startup, or add it in the "my.ini" options file

Now we can configure JAG to use this database. In the Datasource section set the following:

  • Set the JNDI name of the Datasource to: jdbc/CDPlayer

  • Select as database type: MySQL

  • Select as jdbc url: jdbc:mysql://localhost/test (in case the mysql runs on the same machine as the appserver).

  • In the default setup the test database of MySQL doesn't need any username/password. So keep them empty.

Configure the SunOne Application Server for the application

  • Start S1AS 7 and goto the admin webpages.

  • Select your server, and click on the "JVM Settings" tab Then select the "Path Settings". In the "Classpath suffix" add a line containing:

    C:\...path_to_the_my_sql_driver\mm.mysql-2.0.13-bin.jar

    Save, and apply changes

  • Goto the "JDBC", then "Connection Pools" and create a new one. JNDI name: "CDPlayerConnectionPool"

    Datasource classname: "org.gjt.mm.mysql.jd bc2.optional.MysqlConnectionPoolDataSource"

    Set the following properties for the Connection Pool.

    <property value="localhost" name="serverName/">

    <property value="3306" name="port">

    <property value="" name="user">

    <property value="" name="password">

    <property value="test" name="databaseName">

  • Goto the "JDBC", then "JDBC Resources" and create a new one.

    JNDI name: "jdbc/CDPlayer" Pool name: "CDPlayerConnectionPool"

  • And finally a Plugable Persistence Manger has to be created: Create the PPM: jdbc/CDPlayerPPM and selected the previously create connection pool.

  • Save, apply changes & stop/start server

Now the datasource have been configure, also log4j has to be added to the classpath of the appserver, even if the generated application used jdk logging because struts1-1 will need it.

In the "Classpath suffix" add a line containing: C:\...path_to_log4j\log4j.jar

Also add a -D parameter to the JVM Options that specifies a logging directory: -Dcom.finalist.LogDir=c:/temp

If this parameter isn't set, S1AS 7 will throw Security Exceptions because a System properies is being set.

Save, and apply changes

When creating new EntityEJBs the sequence generator should be deployed as an EJB Module. The Sequence Generator EJB jar has been distributed along with jag and can be found in the lib dir of the generated project.

Using JAG with the test database

Now JAG can be used to create 2 entity EJBs (CD and Song) and add a session Facade to them. Run JAG and build the generated project

One thing required by the S1AS is a database schema. This can be done by running the capture-schema script in the bin directory of the S1AS. This script will be called from the ANT build, but it may be necessary to put the JDBC driver in the classpath of the capture script. This can be done easily by adding it once to the script.

Issues with the SunOne Application Server for the application

For an Entity EJB the Primary key must be defined in the database to make it work! It is not enought to tell JAG what should be the primary key.

MySQL can only be used in ansi mode, otherwise CMP won't work with S1AS.

For CMR to work, both the foreign key and the primary key of the foreign table should have the same column name.