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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章