Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anyhow, I have a table in my derby database that I called phonebook. I started by using the DBManager in the geronimo console ( http://localhost:8080/console/portal/internalDB/internalDB_DBManagerImage Removed ) And created a new database that I called PhonebookDB.

...

The fist methods are part of the EntityBean interface. They are never used for any good as far as I know and are only there to mess upp your code. ejbCreate is a constructor, and when you craete a bean it is stored in the database. There are many pages out there that explains the diffrence between ejbCreate and ejbPostCreate. This text below is cited from http://www.jguru.com/faq/view.jsp?EID=1036904Image Removed
---8<----------------------------------------
ejbCreate() is called before the state of the bean is written to the persistence storage (database). After this method is completed, a new record (based on the persistence fields) is created and written. If the Entity EJB is BMP, then this method must contain the code for writing the new record to the persistence storage. If you are developing an EJB following 2.0 specs, you can have overloading methods in the form of ejbCreateXXX(). This will improve the development so you can have different behaviour for creating a bean, if the parameters differs. The only requirement is that for each ejbCreateXXX() you need to have corrisponding createXXX() methods in the home or local interface.

ejbPostCreate() is called after the bean has been written to the database and the bean data has been assigned to an EJB object, so when the bean is available. In an CMP Entity EJB, this method is normally used to manage the beans' container-managed relationship fields.
----------------------------------------->8->8--

Note the talk about ejbCreateXXX if you don't have all the parameters needed for inserating a new row with all fileds in a table, if I understand it right.

...

This is similar to what we saw in the former time bean example.
Finally there is the deployment descriptors for the EAR-file, that in this case also includes a database pool xml-file. The best thing to do is to start with the database pool. In Geronimo console there a link in the left navigation called "Database Pools". From there, click the link "Using the Geronimo database pool wizard". You will end upp here:

http://localhost:8080/console/portal/services/services_jdbc/Image Removed
_rp_services_jdbc_row1_col1_p1_adapterDisplayName/
1_TranQL0x8Generic0x8JDBC0x8Resource0x8Adapter/_rp_services_jdbc_row1_col1_p1_mode/1_rdbms/
_pm_services_jdbc_row1_col1_p1/view/_st_services_jdbc_row1_col1_p1/normal/_pid/
services_jdbc_row1_col1_p1/_md_services_jdbc_row1_col1_p1/view

...

Code Block
xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.1">
    <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
        <dep:moduleId>
            <dep:groupId>console.dbpool</dep:groupId>
            <dep:artifactId>PhonebookPool</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>rar</dep:type>
        </dep:moduleId>
        <dep:dependencies>
            <dep:dependency>
                <dep:groupId>org.apache.derby</dep:groupId>
                <dep:artifactId>derby</dep:artifactId>
                <dep:version>10.1.1.0</dep:version>
                <dep:type>jar</dep:type>
            </dep:dependency>
        </dep:dependencies>
    </dep:environment>
    <resourceadapter>
        <outbound-resourceadapter>
            <connection-definition>
                <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
                <connectiondefinition-instance>
                    <name>PhonebookPool</name>

                    <config-property-setting name="Driver">org.apache.derby.jdbc.EmbeddedDriver</config-property-setting>
                    <config-property-setting name="UserName">app</config-property-setting>
                    <config-property-setting name="ConnectionURL">jdbc:derby:PhonebookDB</config-property-setting>
                    <connectionmanager>
                        <local-transaction/>
                        <single-pool>
                            <max-size>10</max-size>
                            <min-size>0</min-size>
                            <match-one/>
                        </single-pool>
                    </connectionmanager>
                </connectiondefinition-instance>
            </connection-definition>
        </outbound-resourceadapter>
    </resourceadapter>
</connector>

<!--
Here is a comment with the text from the wizard explaining how to use this pool file
Add to EAR: Instead of deploying as a top-level database pool, you can deploy this pool as part of an EAR. 
To add a database pool to an EAR using this plan:
Copy and paste the plan to a file
Save the plan file to the top level of your EAR
Copy the RAR file from GERONIMO_HOME/\repository\tranql\tranql-connector\1.2\tranql-connector-1.2.rar to 
the top level of your EAR
Create a META-INF/geronimo-application.xml file in your EAR that has a module entry like this 
(substituting the correct RAR file name and plan file name):
<application
   xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.0"
   configId="MyApplication">
  <module>
    <connector>rar-file-name.rar</connector>
    <alt-dd>plan-file-name.xml</alt-dd>
  </module>
</application>
-->

...

Now you can look at the application at: http://localhost:8080/myphonebookImage Removed
If you change things, compile and pack evrything again and change the above deployment command to redeploy myphonebook-ear.ear in the end of the line.

All soure code can be downloaded in the zip-file: myphonebook.zip@http://www.freefarm.se/j2ee/ejb/ex2/ myphonebook.zip

Using MySQL as a database instead of derby

...

Code Block
xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.1">
    <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
        <dep:moduleId>
            <dep:groupId>console.dbpool</dep:groupId>
            <dep:artifactId>PhonebookPool</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>rar</dep:type>
        </dep:moduleId>
        <dep:dependencies>
            <dep:dependency>
                <dep:groupId>mysql</dep:groupId>
                <dep:artifactId>mysql-connector-java</dep:artifactId>
                <dep:version>3.1.12</dep:version>
                <dep:type>jar</dep:type>
            </dep:dependency>
        </dep:dependencies>
    </dep:environment>
    <resourceadapter>
        <outbound-resourceadapter>
            <connection-definition>
                <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
                <connectiondefinition-instance>
                    <name>PhonebookPool</name>
                    <config-property-setting name="Password">book</config-property-setting>
                    <config-property-setting name="Driver">com.mysql.jdbc.Driver</config-property-setting>
                    <config-property-setting name="UserName">phone</config-property-setting>
                    <config-property-setting 
name="ConnectionURL">jdbc:mysql://localhost:3306/PhonebookDB</config-property-setting>
                    <connectionmanager>
                        <local-transaction/>
                        <single-pool>
                            <max-size>10</max-size>
                            <min-size>0</min-size>
                            <match-one/>
                        </single-pool>
                    </connectionmanager>
                </connectiondefinition-instance>
            </connection-definition>
        </outbound-resourceadapter>
    </resourceadapter>
</connector>

...