<Ejb3InAction> Sample05 for Weblogic - Interceptors and Timers

1. Customize code in chapter5


$ cd $HOME/student/ejbAction

$ cd chapter5

$ for i in `find * -name "*.orig"`; do j=`expr $i :'\(.*\).orig'`; echo diff -u $i $j; diff -u $i $j; echo; echo; done


diff -u build.xml.orig build.xml

...

+ <target name="db-setup" depends="init"description="Database setup for Derby">

+ <sql driver="${derby.driver}"

+ url="${derby.url}"

+ userid="${derby.username}"password="${derby.password}"

+ οnerrοr="continue"

+ print="yes"

+ src="sql/tables.sql"/>

+ </target>


...

<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/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 sql/tables.sql.orig sql/tables.sql

...

-CREATETABLE BIDS (BID_ID NUMBER(19) NOT NULL,

-BID_PRICENUMBER(19,4) NULL,

-BID_STATUSVARCHAR2(255) NULL,

-BID_DATEDATE NULL,

-BID_ITEM_IDNUMBER(19) NULL,

-BID_BIDDERVARCHAR2(255) NULL,

-PRIMARYKEY (BID_ID))

-/

+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)

+);


diff -u src/ejb/bean/actionbazaar/buslogic/PlaceBidBean.java.orig src/ejb/bean/actionbazaar/buslogic/PlaceBidBean.java

...

private SessionContext sc;

- @Resource(name = "jdbc/ActionBazaarDS", mappedName="ActionBazaarDS")

+ @Resource(name = "examples-dataSource-demoXAPool")

public void setDs(DataSource ds) {

    this.ds= ds;

}

...

TimerService ts = sc.getTimerService();

// Created a single event timer that expires after half hour

- Timer timer = ts.createTimer(1800000, bidId);

+ Timer timer = ts.createTimer(3000, bidId);



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 case


In console, we can see following messages:

*** ActionBazaar Profile Interceptor invoked foractionbazaar.buslogic.PlaceBidBean_59qs3w_Impl@587859be ***

*** DiscountVerifier Interceptor invoked for addBid ***

*** DiscountVerifier Reducing Price by 1 percent ***

Bid for 403 received with price 19800.495

*** Method public java.lang.Long actionbazaar.buslogic.PlaceBidBean.addBid(java.lang.String,java.lang.Long,java.lang.Double) executed in 32ms ***

BidManager EJB: Monitor status of BidId:1002


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

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

1002     |NULL          |NULL                |19800.495   |403                   |dpanda

1 row selected

ij> disconnect;

ij> exit;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值