...
The deployment plan should always use the OpenEJB namespace, and it typically requires elements from the Geronimo Naming, Geronimo Security, and Geronimo System namespaces. Additionally, it has a required attribute to identify its configuration name, and an optional attribute to select a parent configuration. A typical deployment for openejb-jar.xml can be presented as follows:
Code Block |
---|
| xml |
---|
| xml |
---|
title | openejb-jar |
---|
borderStyle | solid | xml |
---|
|
<openejb-jar
xmlns:openejb="http://www.openejb.org/xml/ns/openejb-jar-2.1"
targetNamespace="http://www.openejb.org/xml/ns/openejb-jar-2.1"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
version="1.0">
...
</openejb-jar>
|
...
A secondary namespace, used to identify the common elements for configuring automatic primary key generation for CMP entity beans (such as, using a sequence or auto-increment column). If there are any primary key generators present in the deployment plan, this attribute should be present, and should be set to http://www.openejb.org/xml/ns/pkgen-2.0
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
<dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
<dep:moduleId>
<dep:groupId>default</dep:groupId>
<dep:artifactId>BankEJB</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
<dep:dependencies/>
<dep:hidden-classes/>
<dep:non-overridable-classes/>
</dep:environment>
<cmp-connection-factory>
<resource-link>BankPool</resource-link>
</cmp-connection-factory>
<enterprise-beans>
<session>
<ejb-name>BankManagerFacadeBean</ejb-name>
<jndi-name>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean</jndi-name>
<ejb-ref>
<ref-name>ejb/Customer</ref-name>
<ejb-link>Customer</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/Account</ref-name>
<ejb-link>Account</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/ExchangeRate</ref-name>
<ejb-link>ExchangeRate</ejb-link>
</ejb-ref>
</session>
<entity>
<ejb-name>Account</ejb-name>
<local-jndi-name>AccountLocalEntity</local-jndi-name>
<table-name>Account</table-name>
<cmp-field-mapping>
<cmp-field-name>accountNumber</cmp-field-name>
<table-column>ACC_NO</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>accountType</cmp-field-name>
<table-column>ACC_TYPE</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customer</cmp-field-name>
<table-column>CUSTID_FK</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>balance</cmp-field-name>
<table-column>BALANCE</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>Customer</ejb-name>
<local-jndi-name>CustomerLocalEntity</local-jndi-name>
<table-name>Customer</table-name>
<cmp-field-mapping>
<cmp-field-name>customerId</cmp-field-name>
<table-column>CUST_ID</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customerName</cmp-field-name>
<table-column>CUST_NAME</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>ExchangeRate</ejb-name>
<local-jndi-name>ExchangeRate</local-jndi-name>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Customer-Account</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Account-to-Customer</ejb-relationship-role-name>
<relationship-role-source>
<ejb-name>Account</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>customer</cmr-field-name>
</cmr-field>
<foreign-key-column-on-source/>
<role-mapping>
<cmr-field-mapping>
<key-column>CUST_ID</key-column>
<foreign-key-column>CUSTID_FK</foreign-key-column>
</cmr-field-mapping>
</role-mapping>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</openejb-jar>
|
...
When considering the JMS and MDB Sample given(link the sample application) and it does not have any dependencies and imports.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
<sys:environment>
<sys:moduleId>
<sys:groupId>samples</sys:groupId>
<sys:artifactId>OrderEjb</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
<sys:dependencies>
<sys:dependency>
<sys:groupId>geronimo</sys:groupId>
<sys:artifactId>activemq-broker</sys:artifactId>
<sys:version>1.1</sys:version>
<sys:type>car</sys:type>
</sys:dependency>
<sys:dependency>
<sys:groupId>samples</sys:groupId>
<sys:artifactId>jms-resources</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>rar</sys:type>
</sys:dependency>
</sys:dependencies>
<sys:hidden-classes/>
<sys:non-overridable-classes/>
</sys:environment>
|
...
The following openejb-jar.xml has taken from the http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html
This example is using a EJB session bean and how it has implemented inside the openejb-jar.xml
Code Block |
---|
| xml |
---|
| xml |
---|
title | openejb-jar.xml |
---|
borderStyle | solidxml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
<dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
<dep:moduleId>
<dep:groupId>default</dep:groupId>
<dep:artifactId>BankEJB</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
<dep:dependencies/>
<dep:hidden-classes/>
<dep:non-overridable-classes/>
</dep:environment>
<cmp-connection-factory>
<resource-link>BankPool</resource-link>
</cmp-connection-factory>
<enterprise-beans>
<session>
<ejb-name>BankManagerFacadeBean</ejb-name>
<jndi-name>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean</jndi-name>
<ejb-ref>
<ref-name>ejb/Customer</ref-name>
<ejb-link>Customer</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/Account</ref-name>
<ejb-link>Account</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/ExchangeRate</ref-name>
<ejb-link>ExchangeRate</ejb-link>
</ejb-ref>
</session>
<entity>
<ejb-name>Account</ejb-name>
<local-jndi-name>AccountLocalEntity</local-jndi-name>
<table-name>Account</table-name>
<cmp-field-mapping>
<cmp-field-name>accountNumber</cmp-field-name>
<table-column>ACC_NO</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>accountType</cmp-field-name>
<table-column>ACC_TYPE</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customer</cmp-field-name>
<table-column>CUSTID_FK</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>balance</cmp-field-name>
<table-column>BALANCE</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>Customer</ejb-name>
<local-jndi-name>CustomerLocalEntity</local-jndi-name>
<table-name>Customer</table-name>
<cmp-field-mapping>
<cmp-field-name>customerId</cmp-field-name>
<table-column>CUST_ID</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customerName</cmp-field-name>
<table-column>CUST_NAME</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>ExchangeRate</ejb-name>
<local-jndi-name>ExchangeRate</local-jndi-name>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Customer-Account</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Account-to-Customer</ejb-relationship-role-name>
<relationship-role-source>
<ejb-name>Account</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>customer</cmr-field-name>
</cmr-field>
<foreign-key-column-on-source/>
<role-mapping>
<cmr-field-mapping>
<key-column>CUST_ID</key-column>
<foreign-key-column>CUSTID_FK</foreign-key-column>
</cmr-field-mapping>
</role-mapping>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</openejb-jar>
|
...
In order to deploy a JMS/MDB with Geronimo it's required to create a JMS resource plan.The purpose of creating the JMS plan is that from the geronimo server end you will be accessing JMS/MDB resource using this plan which will define all the definitions for the connection factories and the Queues/Topics
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | JMS_resource_plan.xmlxml |
---|
|
<?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>samples</dep:groupId>
<dep:artifactId>jms-resources</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>rar</dep:type>
</dep:moduleId>
<dep:dependencies>
<dep:dependency>
<dep:groupId>geronimo</dep:groupId>
<dep:artifactId>activemq-broker</dep:artifactId>
<dep:type>car</dep:type>
</dep:dependency>
</dep:dependencies>
</dep:environment>
<resourceadapter>
<resourceadapter-instance>
<resourceadapter-name>CommonConnectionFactory</resourceadapter-name>
<config-property-setting name="Password">geronimo</config-property-setting>
<config-property-setting name="UserName">geronimo</config-property-setting>
<nam:workmanager xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1">
<nam:gbean-link>DefaultWorkManager</nam:gbean-link>
</nam:workmanager>
</resourceadapter-instance>
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface>
<connectiondefinition-instance>
<name>CommonConnectionFactory</name>
<connectionmanager>
<xa-transaction>
<transaction-caching/>
</xa-transaction>
<single-pool>
<match-one/>
</single-pool>
</connectionmanager>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
<adminobject>
<adminobject-interface>javax.jms.Queue</adminobject-interface>
<adminobject-class>org.activemq.message.ActiveMQQueue</adminobject-class>
<adminobject-instance>
<message-destination-name>OrderQueue</message-destination-name>
<config-property-setting name="PhysicalName">OrderQueue</config-property-setting>
</adminobject-instance>
<adminobject-instance>
<message-destination-name>ConsignmentQueue</message-destination-name>
<config-property-setting name="PhysicalName">ConsignmentQueue</config-property-setting>
</adminobject-instance>
</adminobject>
<adminobject>
<adminobject-interface>javax.jms.Topic</adminobject-interface>
<adminobject-class>org.activemq.message.ActiveMQTopic</adminobject-class>
</adminobject>
</connector>
|
Geronimo web console provides the needful to create a JMS resource plan structure and it's required to fill your bunisess logic to map to fill your requirements.Once you log in to the web console in your left hand side navigation you will find a JMS resource link under services.In this application there is a MDB that will listen on OrderQueue. openejb-jar.xml defines Geronimo specific JMS resource services available of that MDB. It links OrderRecv MDB with OrderQueue via CommonConnectionFactory.This Article will be discussing further details of the relationship of the JMS resource plan and the openejb-jar.xml in Resolving references session(link this to the topic)
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | openejb-jar.xml | xml |
---|
|
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
<sys:environment>
<sys:moduleId>
<sys:groupId>samples</sys:groupId>
<sys:artifactId>OrderEjb</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
<sys:dependencies>
<sys:dependency>
<sys:groupId>geronimo</sys:groupId>
<sys:artifactId>activemq-broker</sys:artifactId>
<sys:type>car</sys:type>
</sys:dependency>
<sys:dependency>
<sys:groupId>samples</sys:groupId>
<sys:artifactId>jms-resources</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>rar</sys:type>
</sys:dependency>
</sys:dependencies>
<sys:hidden-classes/>
<sys:non-overridable-classes/>
</sys:environment>
<enterprise-beans>
<message-driven>
<ejb-name>OrderRecvMDB</ejb-name>
<resource-adapter>
<resource-link>CommonConnectionFactory</resource-link>
</resource-adapter>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>OrderQueue</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</openejb-jar>
|
...
The Scenario of the Sample is a Web Client(JSP) which locate and access a EJB by referring it locally.Simply it has used home interface to locate the EJB(service) and the remote interface has used to invoke methods on the EJB. The remote interface is just like a ordinary Remote Method Invocation interface (RMI). This EJB service is used only by the JSP web client which is run in the same Geronimo server (same JVM). Let's discuss how the EJB locally in deployment plans
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | web.xml | xml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
MyTImeWeb</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- To refer local EJB's -->
<ejb-local-ref>
<ejb-ref-name>ejb/MyTimeBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>mytimepak.MyTimeLocalHome</local-home>
<local>mytimepak.MyTimeLocal</local>
<ejb-link>MyTimeBean</ejb-link>
</ejb-local-ref>
</web-app>
|
As above shown in the web.xml file <ejb-local-ref> tag has used to define and set the values for locally referring EJB interfaces MyTimeLocalHome and MyTimeLocal.As you can see in the following geronimo-web.xml has not defined any entry for it that means for there is not server specific entry need to be define for a EJB reference.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | geronimo-web.xmlxml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
<sys:environment>
<sys:moduleId>
<sys:groupId>default</sys:groupId>
<sys:artifactId>MyTimeWeb</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
</sys:environment>
<context-root>/mytime</context-root>
</web-app>
|
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | ejb-jar.xmlxml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_1" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
<description>Example of a session bean</description>
<display-name>MyTimeBeanEJBName</display-name>
<enterprise-beans>
<session id="Session_MyTime">
<description>An EJB named MyTimeBean</description>
<display-name>MyTimeBeanName</display-name>
<ejb-name>MyTimeBean</ejb-name>
<local-home>mytimepak.MyTimeLocalHome</local-home>
<local>mytimepak.MyTimeLocal</local>
<ejb-class>mytimepak.MyTimeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
|
In the ejb-jar.xml shows the normal deployment descriptor entries as usual for any server deployment.
Code Block |
---|
| xml |
---|
| xml |
---|
2 | openejb-jar.xml |
---|
borderStyle | solidxml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
<sys:environment>
<sys:moduleId>
<sys:groupId>default</sys:groupId>
<sys:artifactId>TimeBean_artifact_in_openejb</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
</sys:environment>
<enterprise-beans>
<session>
<ejb-name>MyTimeBean</ejb-name>
<ejb-ref>
<ref-name>ejb/MyTimeBean</ref-name>
<ejb-link>MyTimeBean</ejb-link>
</ejb-ref>
</session>
</enterprise-beans>
</openejb-jar>
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
<sys:environment>
<sys:moduleId>
<sys:groupId>default</sys:groupId>
<sys:artifactId>TimeBean_artifact_in_openejb</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
</sys:environment>
<enterprise-beans>
<session>
<ejb-name>MyTimeBean</ejb-name>
<ejb-ref>
<ref-name>ejb/MyTimeBean</ref-name>
<ejb-link>MyTimeBean</ejb-link>
</ejb-ref>
</session>
</enterprise-beans>
</openejb-jar>
|
As you already know openejb-jar.xml is the Geronimo specific deployment plan to deploy an EJB on Geronimo server.The following peice of code has been excerpt from the above to discuss further.The session bean is defined by giving the information for the client access.Note that ref-name=ejb/MyTimeBean is the same that clients use to lookup for the EJB. ejb-link=MyTimeBean in the openejb-jar.xml is the same for the ejb-name=MyTimeBean in ejb-jar.xml. The ejb-link and the ejb-name must be the same and then only a client will locate the EJB.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<session>
<ejb-name>MyTimeBean</ejb-name>
<ejb-ref>
<ref-name>ejb/MyTimeBean</ref-name>
<ejb-link>MyTimeBean</ejb-link>
</ejb-ref>
</session>
|
...
In EJB applications require to refer many external resources typically JDBC resources,JMS resources or URLS.The geronimo deployment plan for EJB (openejb-jar.xml) handles such situations using the resource-ref .This element is used to map resource references to specific resources available in the geronimo server itself. The elements available for mapping resource references are defined as follows and it has used to some excerpt codes from the sample application to demonstrate these elements.Therefore consider the following openejb-jar.xml in the http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
<dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
<dep:moduleId>
<dep:groupId>default</dep:groupId>
<dep:artifactId>BankEJB</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
<dep:dependencies/>
<dep:hidden-classes/>
<dep:non-overridable-classes/>
</dep:environment>
<cmp-connection-factory>
<resource-link>BankPool</resource-link>
</cmp-connection-factory>
<enterprise-beans>
<session>
<ejb-name>BankManagerFacadeBean</ejb-name>
<jndi-name>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean</jndi-name>
<ejb-ref>
<ref-name>ejb/Customer</ref-name>
<ejb-link>Customer</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/Account</ref-name>
<ejb-link>Account</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/ExchangeRate</ref-name>
<ejb-link>ExchangeRate</ejb-link>
</ejb-ref>
</session>
<entity>
<ejb-name>Account</ejb-name>
<local-jndi-name>AccountLocalEntity</local-jndi-name>
<table-name>Account</table-name>
<cmp-field-mapping>
<cmp-field-name>accountNumber</cmp-field-name>
<table-column>ACC_NO</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>accountType</cmp-field-name>
<table-column>ACC_TYPE</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customer</cmp-field-name>
<table-column>CUSTID_FK</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>balance</cmp-field-name>
<table-column>BALANCE</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>Customer</ejb-name>
<local-jndi-name>CustomerLocalEntity</local-jndi-name>
<table-name>Customer</table-name>
<cmp-field-mapping>
<cmp-field-name>customerId</cmp-field-name>
<table-column>CUST_ID</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customerName</cmp-field-name>
<table-column>CUST_NAME</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>ExchangeRate</ejb-name>
<local-jndi-name>ExchangeRate</local-jndi-name>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Customer-Account</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Account-to-Customer</ejb-relationship-role-name>
<relationship-role-source>
<ejb-name>Account</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>customer</cmr-field-name>
</cmr-field>
<foreign-key-column-on-source/>
<role-mapping>
<cmr-field-mapping>
<key-column>CUST_ID</key-column>
<foreign-key-column>CUSTID_FK</foreign-key-column>
</cmr-field-mapping>
</role-mapping>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</openejb-jar>
|
...
Each resource reference must have a ref-name, which is used to match the definition in the openejb-jar.xml to the resource reference in ejb-jar.xml. Specifically, the value here must match the res-ref-name in the resource-ref in ejb-jar.xml.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | Excerpt from openejb-jar.xmlxml |
---|
|
<entity>
....
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
|
...
This element can be used to identify any resource deployed as a J2EE connector (including JDBC pools and JMS connection factories). The value specified here should match the connectiondefinition-instance/name element in the Geronimo deployment plan for the connector.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | Excerpt from openejb-jar.xmlxml |
---|
|
<entity>
<ejb-name>ExchangeRate</ejb-name>
<local-jndi-name>ExchangeRate</local-jndi-name>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
|
...
This section will be covered how to resolve JBM references from EJB in geronimo.It's used the JMS sample application in the Uder Guide to demonstrate the deployment plans configurations in order to use JMS in applications(http://cwiki.apache.org/GMOxDOC11/jms-and-mdb-sample-application.html) JMS resource can be a topic or queue which need to be configured specifically in the ejb-jar.xml file, as shown below. In this example it has been generated using Xdoclet at the build time.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
......
<enterprise-beans>
<!-- Message Driven Beans -->
<message-driven >
<description>
<![CDATA[Order Recieve Message Driven Bean]]>
</description>
<display-name>OrderRecvMDB</display-name>
<ejb-name>OrderRecvMDB</ejb-name>
<ejb-class>org.apache.geronimo.samples.order.ejb.OrderRecvMDB</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Container</transaction-type>
<message-destination-type>javax.jms.Queue</message-destination-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
<assembly-descriptor >
</assembly-descriptor>
</ejb-jar>
|
...
Message Listener allows a listener to be notified when a message arrives. Contrary to the pull-style of channels, some building blocks (e.g., PullPushAdapter) provide an event-like, push-style message delivery model. In this case, the entity to be notified of message reception needs to provide a callback to be invoked whenever a message has been received. The MessageListener interface provides a method to do so
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | openejb-jar.xml | xml |
---|
|
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
<sys:environment>
<sys:moduleId>
<sys:groupId>samples</sys:groupId>
<sys:artifactId>OrderEjb</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
<sys:dependencies>
<sys:dependency>
<sys:groupId>geronimo</sys:groupId>
<sys:artifactId>activemq-broker</sys:artifactId>
<sys:type>car</sys:type>
</sys:dependency>
<sys:dependency>
<sys:groupId>samples</sys:groupId>
<sys:artifactId>jms-resources</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>rar</sys:type>
</sys:dependency>
</sys:dependencies>
<sys:hidden-classes/>
<sys:non-overridable-classes/>
</sys:environment>
<enterprise-beans>
<message-driven>
<ejb-name>OrderRecvMDB</ejb-name>
<resource-adapter>
<resource-link>CommonConnectionFactory</resource-link>
</resource-adapter>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>OrderQueue</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</openejb-jar>
|
...
For reference, here's a snippet from a JMS connector deployment plan that matches the EJB JAR configuration above and this can be generated using the geronimo web console.One can identify the <moduleId> ,<dependency> and <adminobject> are mapped the ejb-jar.xml.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | jms-resource-plan.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>samples</dep:groupId>
<dep:artifactId>jms-resources</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>rar</dep:type>
</dep:moduleId>
<dep:dependencies>
<dep:dependency>
<dep:groupId>geronimo</dep:groupId>
<dep:artifactId>activemq-broker</dep:artifactId>
<dep:type>car</dep:type>
</dep:dependency>
</dep:dependencies>
</dep:environment>
<resourceadapter>
<resourceadapter-instance>
<resourceadapter-name>CommonConnectionFactory</resourceadapter-name>
<config-property-setting name="Password">geronimo</config-property-setting>
<config-property-setting name="UserName">geronimo</config-property-setting>
<nam:workmanager xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1">
<nam:gbean-link>DefaultWorkManager</nam:gbean-link>
</nam:workmanager>
</resourceadapter-instance>
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface>
<connectiondefinition-instance>
<name>CommonConnectionFactory</name>
<connectionmanager>
<xa-transaction>
<transaction-caching/>
</xa-transaction>
<single-pool>
<match-one/>
</single-pool>
</connectionmanager>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
<adminobject>
<adminobject-interface>javax.jms.Queue</adminobject-interface>
<adminobject-class>org.activemq.message.ActiveMQQueue</adminobject-class>
<adminobject-instance>
<message-destination-name>OrderQueue</message-destination-name>
<config-property-setting name="PhysicalName">OrderQueue</config-property-setting>
</adminobject-instance>
<adminobject-instance>
<message-destination-name>ConsignmentQueue</message-destination-name>
<config-property-setting name="PhysicalName">ConsignmentQueue</config-property-setting>
</adminobject-instance>
</adminobject>
<adminobject>
<adminobject-interface>javax.jms.Topic</adminobject-interface>
<adminobject-class>org.activemq.message.ActiveMQTopic</adminobject-class>
</adminobject>
</connector>
|
...
Following openejb-jar.xml has taken from the http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html.It has defined the dependencies in the <environment> segment and <cmp-connection-factory> is set to the Data Base plan.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | openejb-jar.xmlxml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
<dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
<dep:moduleId>
<dep:groupId>default</dep:groupId>
<dep:artifactId>BankEJB</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
<dep:dependencies/>
<dep:hidden-classes/>
<dep:non-overridable-classes/>
</dep:environment>
<cmp-connection-factory>
<resource-link>BankPool</resource-link>
</cmp-connection-factory>
<enterprise-beans>
<session>
<ejb-name>BankManagerFacadeBean</ejb-name>
<jndi-name>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean</jndi-name>
<ejb-ref>
<ref-name>ejb/Customer</ref-name>
<ejb-link>Customer</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/Account</ref-name>
<ejb-link>Account</ejb-link>
</ejb-ref>
<ejb-ref>
<ref-name>ejb/ExchangeRate</ref-name>
<ejb-link>ExchangeRate</ejb-link>
</ejb-ref>
</session>
<entity>
<ejb-name>Account</ejb-name>
<local-jndi-name>AccountLocalEntity</local-jndi-name>
<table-name>Account</table-name>
<cmp-field-mapping>
<cmp-field-name>accountNumber</cmp-field-name>
<table-column>ACC_NO</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>accountType</cmp-field-name>
<table-column>ACC_TYPE</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customer</cmp-field-name>
<table-column>CUSTID_FK</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>balance</cmp-field-name>
<table-column>BALANCE</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>Customer</ejb-name>
<local-jndi-name>CustomerLocalEntity</local-jndi-name>
<table-name>Customer</table-name>
<cmp-field-mapping>
<cmp-field-name>customerId</cmp-field-name>
<table-column>CUST_ID</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customerName</cmp-field-name>
<table-column>CUST_NAME</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
<entity>
<ejb-name>ExchangeRate</ejb-name>
<local-jndi-name>ExchangeRate</local-jndi-name>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Customer-Account</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Account-to-Customer</ejb-relationship-role-name>
<relationship-role-source>
<ejb-name>Account</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>customer</cmr-field-name>
</cmr-field>
<foreign-key-column-on-source/>
<role-mapping>
<cmr-field-mapping>
<key-column>CUST_ID</key-column>
<foreign-key-column>CUSTID_FK</foreign-key-column>
</cmr-field-mapping>
</role-mapping>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</openejb-jar>
|
Let's consider the CMP mapping implementation of the following code which is excerpt from the above openejb-jar.xml
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | Excerpt from openejb-jar.xml |
---|
|
<entity>
<ejb-name>Customer</ejb-name>
<local-jndi-name>CustomerLocalEntity</local-jndi-name>
<table-name>Customer</table-name>
<cmp-field-mapping>
<cmp-field-name>customerId</cmp-field-name>
<table-column>CUST_ID</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>customerName</cmp-field-name>
<table-column>CUST_NAME</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/BankDataSource</ref-name>
<resource-link>BankPool</resource-link>
</resource-ref>
</entity>
|
Each DataBase mapping are configured with in the <cmp-field-mapping> and <cmp-field-mapping> is set to the customerId which is deployment plan specific reference for the name of the data field."CUS_ID" is the actual name of the data base field in the DataBase.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid |
---|
title | BankDB.sql |
---|
|
CREATE TABLE customer(
CUST_ID VARCHAR(15) PRIMARY KEY,
CUST_NAME VARCHAR(40)
);
|