📄 day01.txt
字号:
准备开发环境
开发工具: JBuilder 9
数据库 : Pointbase
中间件 : Weblogic 8.x
1,创建数据库:ec_port
2,建表:
create table admin(
userid varchar2(30) primary key ,
password varchar2(30) not null
);
insert into admin( userid,password )
values( 'admin','admin' );
create table user(
userid varchar2(16) primary key,
password varchar2(8) not null
);
create table contactinfo(
contactid integer primary key,
userid varchar2(16) references user(userid),
street1 varchar2(64),
street2 varchar2(64),
city varchar2(32),
province varchar2(32),
country varchar2(64),
zip varchar2(8),
email varchar2(32),
homephone varchar2(16),
cellphone varchar2(16),
officephone varchar2(16)
);
create table contactinfoseq(
pKey integer primary key ,
value integer not null
);
insert into contactinfoseq ( pkey , value )
values( 1, 0 );
3,在weblogic上配置连接池:
a) 启动webLogic
b) 进入webLogic控制台 http://localhost:7001/console
c) 选择Services --> jdbc --> connectionPool -->
Configure a new JDBC Connection Pool...
选择 Database Type : PointBase
Driver Type : PointBase`s Dirver( type 4 )
--> Continue
填写:
Name : JDBC Pointbase Connection Pool
DataBaseName : ec_port
DataBaseUserName: ...
password : ...
Confirm password: ...
--> continue
--> test Driver Configuration
通过之后 选择 --> Create and deploy
4,为连接池配置数据源
选择 services--> jdbc --> datasource
--> Configure a new JDBC Data Source
填写
name : PointBase Data Source
jndi name : jdbc/pointbase/ds
pool name : JDBC Pointbase Connection Pool
选择 --> apply
5,在JBuilder中创建工程并导入数据源
a) 启动JBuilder,新建工程 Ec_Port
b) 将中间件服务器配置为webLogic
* 前提:weblogic 已经在JBuilder中配置成功
右键点击工程图标(Ec_Port.jpx) --> properties
--> server --> sigal server for all services ...
--> weblogic platform server 8.x --> ok
c) 新建web应用 ec_port
file --> new --> web --> webapp --> ok
填写:
name : ec_port
directory : ec_port
在jsp/framework 中选择struts1.1
--> ok
d) 新建ejb module ( ec_port_em )
file --> new --> Enterprise --> ejb Module
填写 name : ec_port_em
--> ok
e) 导入webLogic中的数据源
双击ejb Module 的图标 ,在窗口右下角的Datasources
图标上点击右键 选择--> add datasource
将新建的Datasource的名字改为 jdbc/pointbase/ds
( * 同weblogic中的一致 )
右键点击jdbc/pointbase/ds数据源
--> Edit Datasource Properties
选中: all schemas
填写:
Dirver :com.pointbase.jdbc.jdbcUniversalDriver
URL:
jdbc:pointbase:server://localhost:9092/ec_port
User name : ...
password : ...
Database name: ec_port
jndi name : jdbc/pointbase/ds
--> ok
右键点击数据源 --> refresh
这时 ec_port 库中的表格全部都显示出来。
==========================================================
在 工程中新建package : ejb , util , excpetion , dto .
在exception 包中新建 ServiceLocatorException :
package exception;
public class ServiceLocatorException extends Exception {
public ServiceLocatorException() {
}
public ServiceLocatorException(String message) {
super(message);
}
public ServiceLocatorException(String message,
Throwable cause) {
super(message, cause);
}
public ServiceLocatorException(Throwable cause) {
super(cause);
}
}
==========================================================
在exceptions 包中创建 RegistryException
==========================================================
在util包中新建ServiceLocator类,用于进行jndi查找
package util;
import exception.ServiceLocatorException;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ServiceLocator {
private static ServiceLocator instance ;
private Context ctx;
private ServiceLocator() throws ServiceLocatorException{
try{
ctx = new InitialContext();
}catch(NamingException e ){
e.printStackTrace();
throw new ServiceLocatorException( e.getMessage() );
}
}
public static ServiceLocator getInstance()
throws ServiceLocatorException{
if( instance == null ){
instance = new ServiceLocator();
}
return instance;
}
public EJBLocalHome getEJBLocalHome( String jndiName ) throws ServiceLocatorException{
try{
return (EJBLocalHome) ctx.lookup(jndiName);
}catch( NamingException e ){
e.printStackTrace();
throw new ServiceLocatorException( e.getMessage() );
}
}
public EJBHome getEJBHome( String jndiName)
throws ServiceLocatorException{
return null;
}
}
==========================================================
在 dto 包中,新建类 UserDTO 和 ContactInfoDTO , 用于封装
用户和用户联系方式的数据。
package dto;
import java.io.Serializable;
public class UserDTO implements Serializable{
private String userId ;
private String password;
public UserDTO(String id,String pw) {
this.userId = id;
this.password = pw;
}
public void setUserId( String id ){
this.userId = id;
}
public String getUserId(){
return this.userId;
}
public void setPassword( String pw ){
this.password = pw;
}
public String getPassword(){
return this.password;
}
}
==========================================================
package dto;
import java.io.Serializable;
public class ContactInfoDTO implements Serializable{
private String userid;
private String street1;
private String street2;
private String city;
private String province;
private String country;
private String zip;
private String email;
private String homephone;
private String cellphone;
private String officephone;
public ContactInfoDTO(
String userid,String street1,String street2,
String city,String province,String country,
String zip,String email,String homephone,
String cellphone,String officephone) {
this.userid = userid;
this.street1 = street1;
this.street2 = street2;
this.city = city;
this.province = province;
this.country = country;
this.zip = zip;
this.email = email;
this.homephone = homephone;
this.cellphone = cellphone;
this.officephone = officephone;
}
public void setUserid( String userid ){
this.userid = userid;
}
public String getUserid(){
return this.userid;
}
public void setStreet1( String street1 ){
this.street1 = street1;
}
public String getStreet1(){
return this.street1;
}
public void setStreet2( String street2 ){
this.street2 = street2;
}
public String getStreet2(){
return this.street2;
}
public void setCity( String city ){
this.city = city;
}
public String getCity(){
return this.city;
}
public void setProvince( String province ){
this.province = province;
}
public String getProvince(){
return this.province;
}
public void setCountry( String country ){
this.country = country;
}
public String getCountry(){
return this.country;
}
public void setZip( String zip ){
this.zip = zip;
}
public String getZip(){
return this.zip;
}
public void setEmail( String email ){
this.email = email;
}
public String getEmail(){
return this.email;
}
public void setHomephone( String homephone ){
this.homephone = homephone;
}
public String getHomephone(){
return this.homephone;
}
public void setCellphone( String cellphone ){
this.cellphone = cellphone;
}
public String getCellphone(){
return this.cellphone;
}
public void setOfficephone( String officephone ){
this.officephone = officephone;
}
public String getOfficephone(){
return this.officephone;
}
}
==========================================================
创建 ContactInfoSeqEJB
a) 右键点击数据源中的ContactInfoSeq
--> create cmp 2.0 Entity Bean
b) 修改bean properties
bean name : ContactInfoSeqEJB
abstract schema name : ContactInfoSeq
interface : Local
always wrap primary key : false
sigle table mapping : ContactInfoSeq
--> class and package
修改
package : ejb
bean name : ContactInfoSeqEJB
Bean class: ejb.ContactInfoSeqBean
Local Home: ejb.ContactInfoSeqLocalHome
Local : ejb.ContactInfoSeqLocal
c) 修改字段属性
pKey :
field name : pkey
is persisted : true
type : java.lang.Integer
isPrimaryKey : true
in ejbcreate : true
getter : local
setter : none
column name : pkey
value :
field name : value
is persisted : true
type : int
isPrimaryKey : false
in ejbcreate : false
getter : local
setter : local
column name : value
==========================================================
为ContactInfoSeqEJB 添加 getSequence方法:
a)点击ContactInfoSeqEJB --> add --> Method
修改属性:
method name : getSequence
input parameter :
return type : int
interface : local
b)选择 view Bean source 为 getSequence 填写函数体
public int getSequence() {
int i = this.getValue();
this.setValue( i+1 );
return i;
}
c) 编辑 ContactInfoSeqLocalHome.java
注释 其中的 create 方法
d) 编译ejb module
==========================================================
创建UserEJB
a) 右键点击数据源中的User表
--> create cmp 2.0 Entity Bean
b) 修改bean properties
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -