本文主要是介绍Ejb3InAction Sample02 for Glassfish - Simple example of Stateless, Stateful, MDB and JPA Enity,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
0. Prerequisite
1) JDBC resources
We use default JDBC resources, which is based on database sun-appserv-samples:
Connection pool – DerbyPool
Resource – jdbc/__default
2) JMS resources
We use default JMS connection factory – jms/__defaultConnectionFactory
1. Customize code in chapter2
$ cd $HOME/student/ejbactGF/chapter2
$ for i in `find * -name "*.orig"`; do j=`expr $i :'\(.*\).orig'`; echo diff -u $i $j; diff -ub $i $j; echo; echo; done
diff-u build.xml.orig build.xml
...
+ <!-- Drop and Create JMS Connection destination -->
+ <property name="jms.queue" value="jms/OrderBillingQueue"/>
diff -u etc/persistence.xml.orig etc/persistence.xml
...
<persistence>
<persistence-unitname="actionBazaar">
- <jta-data-source>jdbc/ActionBazaarDS</jta-data-source>
- <properties>
- <property name = "toplink.ddl-generation"
- value = "create-tables"/>
- <property name = "toplink.ddl-generation.output-mode" value = "database"/>
- </properties>
+ <jta-data-source>jdbc/__default</jta-data-source>
+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
</persistence>
diff -u src/ejb/bean/ejb3inaction/example/buslogic/PlaceOrderBean.java.orig src/ejb/bean/ejb3inaction/example/buslogic/PlaceOrderBean.java
...
@Stateful
public class PlaceOrderBean implements PlaceOrder {
- @Resource(name = "jms/QueueConnectionFactory")
+ @Resource(name = "jms/QueueConnectionFactory", mappedName = "jms/__defaultConnectionFactory")
private ConnectionFactory connectionFactory;
- @Resource(name = "jms/OrderBillingQueue", mappedName= "OrderBillingQueue")
+ @Resource(name = "jms/OrderBillingQueue", mappedName = "jms/OrderBillingQueue")
private Destination billingQueue;
diff -u src/ejb/bean/ejb3inaction/example/buslogic/OrderBillingMDB.java.orig src/ejb/bean/ejb3inaction/example/buslogic/OrderBillingMDB.java
...
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName="destinationName",propertyValue="OrderBillingQueue"),
@ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue")
- },mappedName = "OrderBillingQueue"
+ }, mappedName = "jms/OrderBillingQueue"
)
2. Build, deploy and run
$ cd $HOME/student/ejbactGF/chapter2
$ ant drop-que crt-que # drop / create queue, if need
$ ant undeploy # if need
$ ant clean build
$ ant deploy
$ ant run # run the stateless EJB with JPA entity sample
run:
[echo] Executing client class using/home/weblogic/glassfish4/glassfish/bin/appclient
[exec] Bid Successful, BidId Received is:1
In server log, we can see following messages:
Adding bid, bidder ID=npanda, item ID=100, bid amount=20000.4.
Your bid your item id:100was successful
Your bid id is: 1
The result can be observed from ij tool as well:
$ ../ij.sh
ij> select * from BIDS;
BID_ID |BID_DATE |BID_STATUS |BID_PRICE |BID_ITEM_ID |BID_BIDDER
------------------------------------------------------------------------------------------------------------------------------
1 |NULL |NULL |20000.4 |100 |npanda
1 row selected
$ ant run-sfsb # run the stateful EJB with MDB sample
run-sfsb:
[echo] Executing client class using/home/weblogic/glassfish4/glassfish/bin/appclient
[exec] Exercising PlaceOrder EJB...
[exec] Order confirmation number: 1000
In server log, we can see following messages:
Billing Completed by MDB ..
A/c No:123456789 charged..
这篇关于Ejb3InAction Sample02 for Glassfish - Simple example of Stateless, Stateful, MDB and JPA Enity的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!