<Ejb3InAction> Sample02 for Weblogic - Simple example of Stateless, Stateful, MDB and JPA Enity

0. Prerequisite


Actually this sample is postponed, please reference to prerequisites of sample03 and 04.



1. Customize code in chapter2


$ cd $HOME/student/ejbAction

$ cd 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

...

<classpath>

<pathelement location="${lib.dir}/${cli.name}.jar"/>

<pathelementl ocation="${bld.ejb.dir}"/>

- <pathelement location="${WLS_HOME}/server/lib/wlclient.jar"/>

+ <pathelement location="${WLS_HOME}/server/lib/weblogic.jar"/>

</classpath>

...

<classpath>

<pathelement location="${lib.dir}/${cli.name}.jar"/>

<pathelement location="${bld.ejb.dir}"/>

- <pathelement location="${WLS_HOME}/server/lib/wlclient.jar"/>

+ <pathelement location="${WLS_HOME}/server/lib/weblogic.jar"/>

</classpath>


diff -u etc/persistence.xml.orig etc/persistence.xml

...

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

version="1.0">

<persistence-unit name="actionBazaar">

-<jta-data-source>ActionBazaarDS</jta-data-source>

-<properties>

- <property name="kodo.jdbc.SynchronizeMappings"value="buildSchema"/>

-</properties>

+ <jta-data-source>examples-dataSource-demoXAPool</jta-data-source>

</persistence>


diff -u etc/jndi.properties.orig etc/jndi.properties

...

#Set required appropriate for your environment

java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory

-java.naming.provider.url=t3://localhost:7001

+java.naming.provider.url=t3://localhost:8001


diff -u src/ejb/bean/ejb3inaction/example/buslogic/PlaceOrderBean.java.orig src/ejb/bean/ejb3inaction/example/buslogic/PlaceOrderBean.java

...

@Stateful(mappedName = "PlaceOrder")

public class PlaceOrderBean implements PlaceOrder {

- @Resource(name = "jms/QueueConnectionFactory",mappedName="weblogic.examples.ejb30.QueueConnectionFactory")

+ @Resource(name = "weblogic.examples.ejb30.QueueConnectionFactory",mappedName="weblogic.examples.ejb30.QueueConnectionFactory")

private QueueConnectionFactory connectionFactory;


$ cat sql/tables.sql                                                                 # besides, need to a db table

drop table BIDS;
create table BIDS (
    BID_ID BIGINT primary key,
    BID_DATE DATE,
    BID_STATUS VARCHAR(20),
    BID_PRICE FLOAT,
    BID_ITEM_ID BIGINT,
    BID_BIDDER VARCHAR(45)
);


2. Build, deploy and run


$ cd $ORACLE_HOME/wlserver/samples/server

$ . ./setExamplesEnv.sh                                                          # set environment variables


$ cd $HOME/student/ejbAction/chapter4

$ ant undeploy                                                                          # if need

$ ant clean

$ ant db-setup                                                                           # create db tables

$ ant # build and deploy

$ ant run                                                                                     # run the stateless EJB with JPA entity sample

run:

[echo] Executing client class

[java] Bid Successful, BidId Received is:251


In console, 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: 251


The result can be observed from ij tool as well:

$ ../ij.sh

ij version 10.11

CONNECTION0* - jdbc:derby://localhost:1527/examples

* = current connection

ij> select * from BIDS;

BID_ID |BID_DATE |BID_STATUS |BID_PRICE |BID_ITEM_ID |BID_BIDDER

------------------------------------------------------------------------------------------------------------------------------

251 |NULL |NULL |20000.4 |100 |npanda

1 row selected

ij> disconnect;

ij> exit;


$ ant run-sfsb                                                                          # run the stateful EJB with MDB sample

run-sfsb:

[echo] Executing client class

[java] Exercising PlaceOrder EJB...

[java] Order confirmation number: 1000


In console, 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、付费专栏及课程。

余额充值