UltraEdit+Weblogic實體Bean
一、系統設置:
1.編輯工具:UltraEdit
2.應用服務器:Weblogic 8.1
3.數據庫:MySQL4.0
二、基本類的編寫:(例子源於MasteringEJB中的第6章的實體Bean實例)
1.Home接口: AccountHome.java
2.本地Home接口: AccountLocalHome.java
3.Remote接口: Account.java
4.Remote Home接口: AccountLocal.java
5.實現類: AccountBean.java
6.主健類: AccountPK.java
7.用戶測試類: AccountClient.java
三、數據庫設置
1. 數據庫用MySQL中的test數據庫;
2. 數據表爲:
drop table accounts;
create table accounts (id varchar(64),ownername varchar(64),balance numeric(18));
3. 插入一條測試記錄
insert into accounts(id,ownername,balance) values(“0000”,”Dosany”,1000000);
四、在WebLogic中設置數據連接池和數據源
1. 下載MySQL的JDBC驅動,並把它的路徑加入到系統classpath中;
2. 啓動WebLogic中的用戶域,這個實例爲 mydomain;
3. 打開WebLogic管理界面:http://localhost:7001/console,輸入用戶名和密碼進入;
4. 進入Services-JDBC-ConnectionPools
5. 點擊Configure a new JDBC Connection Pool... ,
6. Database Type:MySQL,DatabaseDriver:MySQL’s Driver(Type 4) Version:Any;
7. 點擊 Continue;
8. Name:MySQLDatePool;DatabaseName:test;Host Name:127.0.0.1;
Port:3306;Database User Name:hhdsf;Password:baobao 下同;continue;
9. Driver Classname: org.gjt.mm.mysql.Driver
URL: jdbc:mysql://127.0.0.1:3306/test
10. Test Driver Configuration,可以看到成功;
注意:MySQL中的用戶hhdsf是安裝MySQL後加入的,因爲MySQL安裝後的默認用戶是 root;密碼是空,而在WebLogic中密碼不能爲空;
設置數據源:
1. 進入Services-JDBC-DataSources
2. 選擇Configure a new JDBC Data Source
3. Name:MySQLDataSource;JNDI:mySqlDs;點擊Next;
4. 在Connect to connection pool 中選擇剛剛建立的connection pool;點擊Next;
5. 點擊Create,創建DataSource。
五、部署文件
1. Ejb-jar部署文件:
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>Account</ejb-name>
<home>AccountHome</home>
<remote>Account</remote>
<local-home>AccountLocalHome</local-home>
<local>AccountLocal</local>
<ejb-class>AccountBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>AccountPK</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
<res-ref-name>jdbc/ MySQLDatePool </res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Account</ejb-name>
<method-intf>Local</method-intf>
<method-name>*</method-name>
</method>
<method>
<ejb-name>Account</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
2. weblogic-ejb-jar部署文件:
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN' 'http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd'>
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Account</ejb-name>
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>100</max-beans-in-cache>
</entity-cache>
</entity-descriptor>
<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/ MySQLDatePool </res-ref-name>
<jndi-name> mySqlDs </jndi-name>
</resource-description>
</reference-descriptor>
<jndi-name>AccountHome</jndi-name>
<local-jndi-name>AccountLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
六、編譯和運行
1. 編譯命令:
@echo *******************************************************
@echo Cleaning things up...
@echo *******************************************************
md classes
md lib
del classes/*.class
del lib/*.jar
@echo *******************************************************
@echo Compiling files...
@echo *******************************************************
javac -d classes src/*.java
@echo *******************************************************
@echo Copying Deployment Descriptor...
@echo *******************************************************
md classes/META-INF
copy deployment/*.xml classes/META-INF
@echo *******************************************************
@echo Creating temporary ejb-jar file...
@echo *******************************************************
cd classes
jar cf ../lib/tmp.jar *
cd ..
@echo *******************************************************
@echo Generating helper code, and creating new ejb-jar file...
@echo *******************************************************
pushd lib
java weblogic.ejbc tmp.jar -d EJB.jar
copy EJB.jar %DEPLOY_HOME%/Account.jar
popd
@echo *******************************************************
@echo Removing temporary ejb-jar file
@echo *******************************************************
del lib/tmp.jar
2. 運行測試客戶端程序:
copy src/AccountClient.java classes
cd classes
javac AccountClient.java
del AccountClient.java
java -Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory -Djava.naming.provider.url=t3://localhost:7001 AccountClient
cd ..
1.編輯工具:UltraEdit
2.應用服務器:Weblogic 8.1
3.數據庫:MySQL4.0
二、基本類的編寫:(例子源於MasteringEJB中的第6章的實體Bean實例)
1.Home接口: AccountHome.java
2.本地Home接口: AccountLocalHome.java
3.Remote接口: Account.java
4.Remote Home接口: AccountLocal.java
5.實現類: AccountBean.java
6.主健類: AccountPK.java
7.用戶測試類: AccountClient.java
三、數據庫設置
1. 數據庫用MySQL中的test數據庫;
2. 數據表爲:
drop table accounts;
create table accounts (id varchar(64),ownername varchar(64),balance numeric(18));
3. 插入一條測試記錄
insert into accounts(id,ownername,balance) values(“0000”,”Dosany”,1000000);
四、在WebLogic中設置數據連接池和數據源
1. 下載MySQL的JDBC驅動,並把它的路徑加入到系統classpath中;
2. 啓動WebLogic中的用戶域,這個實例爲 mydomain;
3. 打開WebLogic管理界面:http://localhost:7001/console,輸入用戶名和密碼進入;
4. 進入Services-JDBC-ConnectionPools
5. 點擊Configure a new JDBC Connection Pool... ,
6. Database Type:MySQL,DatabaseDriver:MySQL’s Driver(Type 4) Version:Any;
7. 點擊 Continue;
8. Name:MySQLDatePool;DatabaseName:test;Host Name:127.0.0.1;
Port:3306;Database User Name:hhdsf;Password:baobao 下同;continue;
9. Driver Classname: org.gjt.mm.mysql.Driver
URL: jdbc:mysql://127.0.0.1:3306/test
10. Test Driver Configuration,可以看到成功;
注意:MySQL中的用戶hhdsf是安裝MySQL後加入的,因爲MySQL安裝後的默認用戶是 root;密碼是空,而在WebLogic中密碼不能爲空;
設置數據源:
1. 進入Services-JDBC-DataSources
2. 選擇Configure a new JDBC Data Source
3. Name:MySQLDataSource;JNDI:mySqlDs;點擊Next;
4. 在Connect to connection pool 中選擇剛剛建立的connection pool;點擊Next;
5. 點擊Create,創建DataSource。
五、部署文件
1. Ejb-jar部署文件:
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>Account</ejb-name>
<home>AccountHome</home>
<remote>Account</remote>
<local-home>AccountLocalHome</local-home>
<local>AccountLocal</local>
<ejb-class>AccountBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>AccountPK</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
<res-ref-name>jdbc/ MySQLDatePool </res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Account</ejb-name>
<method-intf>Local</method-intf>
<method-name>*</method-name>
</method>
<method>
<ejb-name>Account</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
2. weblogic-ejb-jar部署文件:
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN' 'http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd'>
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Account</ejb-name>
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>100</max-beans-in-cache>
</entity-cache>
</entity-descriptor>
<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/ MySQLDatePool </res-ref-name>
<jndi-name> mySqlDs </jndi-name>
</resource-description>
</reference-descriptor>
<jndi-name>AccountHome</jndi-name>
<local-jndi-name>AccountLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
六、編譯和運行
1. 編譯命令:
@echo *******************************************************
@echo Cleaning things up...
@echo *******************************************************
md classes
md lib
del classes/*.class
del lib/*.jar
@echo *******************************************************
@echo Compiling files...
@echo *******************************************************
javac -d classes src/*.java
@echo *******************************************************
@echo Copying Deployment Descriptor...
@echo *******************************************************
md classes/META-INF
copy deployment/*.xml classes/META-INF
@echo *******************************************************
@echo Creating temporary ejb-jar file...
@echo *******************************************************
cd classes
jar cf ../lib/tmp.jar *
cd ..
@echo *******************************************************
@echo Generating helper code, and creating new ejb-jar file...
@echo *******************************************************
pushd lib
java weblogic.ejbc tmp.jar -d EJB.jar
copy EJB.jar %DEPLOY_HOME%/Account.jar
popd
@echo *******************************************************
@echo Removing temporary ejb-jar file
@echo *******************************************************
del lib/tmp.jar
2. 運行測試客戶端程序:
copy src/AccountClient.java classes
cd classes
javac AccountClient.java
del AccountClient.java
java -Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory -Djava.naming.provider.url=t3://localhost:7001 AccountClient
cd ..
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.