Sample03 for Weblogic - Session beans with lifecycle callbacks and @Resource inject

0. Prerequisite


We take advantage of Weblogic attached sample db here, the data source has been configured in Weblogic domain as following:

Name:

examples-demoXA

JNDI Name:

examples-dataSource-demoXAPool

URL:

jdbc:derby://localhost:1527/examples;ServerName=localhost;databaseName=examples;create=true

Driver Class Name:

org.apache.derby.jdbc.ClientXADataSource

Properties:

user=examples

portNumber=1527

databaseName=examples;create=true

serverName=localhost



1. Customize general configuration


$ cd $HOME/student/ejbAction

$ vi common.xml                                         # customize general configure for all chapters

$ diff -u common.xml.orig common.xml


+<property name="derby.driver" value="org.apache.derby.jdbc.ClientDriver" />

+<property name="derby.url" value="jdbc:derby://localhost:1527/examples;create=true;ServerName=localhost;databaseName=examples"/>

+<property name="derby.username" value="examples" />

+<property name="derby.password" value="examples" />



2. Customize code in chapter3


$ cd chapter3

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

</java>

...

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

</java>


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

...

-create table BIDDERS

-(username varchar2(10) primary key,

-first_name varchar2(30),

-credit_card_type varchar2(20))

-/

+drop table BIDDERS;

+create table BIDDERS (

+ username varchar(10) primary key,

+ first_name varchar(30),

+ credit_card_type varchar(20)

+);

-create table BIDS(

-BID_ID NUMBER(19) primary key,

-BID_DATE DATE,

-BID_STATUS VARCHAR2(20),

-BID_PRICE NUMBER(19,4),

-BID_ITEM_ID NUMBER(19),

-BID_BIDDER VARCHAR2(45))

-/

+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/BidderAccountCreatorBean.java.orig src/ejb/bean/actionbazaar/buslogic/BidderAccountCreatorBean.java

...

@Stateful(mappedName = "BidderAccountCreator")

public class BidderAccountCreatorBean implements BidderAccountCreator {

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

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

private DataSource dataSource;

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

@Resource

privateSessionContext sc;

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

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

private DataSource dataSource;



3. Build, deploy and run


$ cd $ORACLE_HOME/wlserver/samples/server

$ . ./setExamplesEnv.sh                                            # set environment variables


$ cd $HOME/student/ejbAction/chapter3

$ ant undeploy                                                           # if need

$ ant clean

$ ant db-setup                                                            # create db tables

$ ant                                                                            # build and deploy

$ ant run run-sfsb                                                       # run the case


The result can be observed from ij tool:

$ cd sql

$ cat ij.sh

java \

-Dij.driver=org.apache.derby.jdbc.ClientDriver \

-Dij.protocol=jdbc:derby:-Dij.database=//localhost:1527/examples \

-Dij.user=examples-Dij.password=examples \

org.apache.derby.tools.ij


$ ij.sh

ij> select * from BIDS;

BID_ID |BID_DATE |BID_STATUS |BID_PRICE |BID_ITEM_ID |BID_BIDDER

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

1002 |NULL |NULL |10000.5 |100 |viper

1 row selected

ij> select * from BIDDERS;

USERNAME |FIRST_NAME |CREDIT_CARD_TYPE

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

dpanda |Debu |VISA

1 row selected


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