<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..


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值