![]() |
![]() |
Back to the Speedo tutorial home page
Speedo can be
integrated into application servers as a resource
adapter (JCA Connector SUN specification). Speedo is fully integrated
in JOnAS and WebLogic.
To use Speedo inside
an application server, you need to use the rar file provided in the
Speedo binary distribution.
JDO code can be integrated into a servlet as shown in the figure
below:
JDO code can also be integrated into a session bean or a message driven
bean as shown in the figure below:
As said
before, the PersistenceManagerFactory is the main element of Speedo: it
creates PersistenceManager instances.
One Speedo instance can be associated to one PMF.
In a standalone application, the PMF
is created using the speedo.properties file. Properties in this file
are loaded to create the PMF instance as described in the code below:
Properties p = new Properties();
p.load(new FileInputStream(porpertiesFileName));
PersistenceMnanagerFactory pmf = JDOHelper.getPersistenceManagerFactory(p);
In a J2EE application, the creation of the PMF is performed using the
JNDI name of the Speedo instance. This name can be defined in the
ejb-jar xml descriptor of the application. You can also define it in
the server dedicated ejb-jar xml descriptor. If it has been defined in
both files, the registered name will be the server dedicated ejb-jar
xml descriptor one.
Let's say you have a bank application using Speedo. You declare your Speedo resource in the bank.xml deployment descriptor as follows:
<resource-ref>
<res-ref-name>jdo/pmf</res-ref-name>
<res-type>javax.jdo.PersistenceManagerFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
If you want to deploy your application into the JOnAS server, you
define the JNDI resource name in the jonas-bank.xml, the JOnAS
dedicated deployment descriptor, as follows:
<jonas-resource>
<res-ref-name>jdo/pmf</res-ref-name>
<jndi-name>speedo</jndi-name>
</jonas-resource>
In the speedo_for_jonas.rar archive, you'll find two files:
To finish, in your J2EE application
you can get the PMF performing a lookup in the JNDI context as follows:
final String PMF_CTX_NAME = "java:comp/env/jdo/pmf";
PersistenceMnanagerFactory pmf = (PersistenceManagerFactory) new InitialContext().lookup(PMF_CTX_NAME);
In a standalone application, the user has to write the transaction demarcation using the jdo api, as described below:
public void makeAgencyPersistent(Agency agency){In a J2EE application, as Speedo is integrated as a resource adapter, transactions are demarcated by the EJB container.
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
pm.makePersistent(agency);
pm.currentTransaction().commit();
}
Application Server | JNDI name of TransactionManager instance |
JOnAS | javax.transaction.UserTransaction |
JBoss | java:/TransactionManager |
WebLogic | javax.transaction.TransactionManager |
WebSphere | jta/usertransaction |
Orion | java:comp/UserTransaction |
public void makeAgencyPersistent(Agency agency){Transactions are demarcated by the EJB container if the methods have the "required" tag in the bank.xml deployment descriptor:
PersistenceManager pm = pmf.getPersistenceManager();
pm.makePersistent(agency);
}
<container-transaction>Nevertheless, it is always possible for him to perform transaction demarcation by himself. To do so, he needs to get the transaction manager instance via JNDI
<method>
<ejb-name>BankApplication</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
Speedo is able, through Jorm, to create the data structure during the first use of a persistent class. But some data support does not allow to create data structures (SQL relations) inside XA transactions. As a consequence, Speedo allows only the DO_NOTHING value for the property org.objectweb.speedo.mappingStructure.
DataStructureCreation (<class name to initialize> | <.jdo file name>)*Top
[-Djavax.jdo.option.DriverClassName=<driver class name>]
[-Djavax.jdo.option.ConnectionURL=<database url>]
[-Djavax.jdo.option.ConnectionUserName=<user name>]
[-Djavax.jdo.option.ConnectionPassword=<user password>]
The speedo_ra.rar and jdbc_ra.rar archives are not merged into a single archive.