2012年1月10日星期二

OEPE_009:Trouble Ticket System 项目实战开发之JPA:JUnit测试

开发运行环境:OEPE 12c(12.1.1.1.0)+ WebLogic Server 12c(12.1.1.1.0)+ Oracle Database 10g Express Edition 10.2.0.1

至此,JPA的开发工作已基本完成,下面使用JUnit进行单元测试。

1. 安装JUnit Library

2. LoginDaoTest.java 

package com.oracle.ticketsystem.dao.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.junit.Before;
import org.junit.Test;

import com.oracle.ticketsystem.beans.Technician;
import com.oracle.ticketsystem.dao.ILoginDao;
import com.oracle.ticketsystem.dao.impl.LoginJPADao;

public class LoginDaoTest {

private ILoginDao loginDao = null;

@Before
public void setUp() throws Exception {
loginDao = new LoginJPADao();
}

@Test
public void testLogin() {

// testing valid technician
String id = "peter";
String pwd = "peter";
Technician technician = loginDao.login(id, pwd);

assertNotNull("No technician found for the ID " + id + " and password "
+ pwd, technician);

// testing in-valid technician with junk parameters
id = "junk";
pwd = "junk";
technician = loginDao.login(id, pwd);

assertNull(
"Technician found for the ID " + id + " and password " + pwd,
technician);

}

}

3. ProductDaoTest.java 

package com.oracle.ticketsystem.dao.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.oracle.ticketsystem.beans.Product;
import com.oracle.ticketsystem.dao.IProductDao;
import com.oracle.ticketsystem.dao.impl.ProductJPADao;

public class ProductDaoTest {

private IProductDao productDao = null;

@Before
public void setUp() throws Exception {
productDao = new ProductJPADao();
}

@Test
public void testGetAllProducts() {
List allProducts = productDao.getAllProducts();
assertTrue("No results found", allProducts.size() > 0);
}

@Test
public void testGetProduct() {
long productId = 1001;
Product product = productDao.getProduct(productId);
assertNotNull("No product found for the ID " + productId, product);
}

}

4. ProductDaoTest.java 
package com.oracle.ticketsystem.dao.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.oracle.ticketsystem.beans.Ticket;
import com.oracle.ticketsystem.dao.ITicketDao;
import com.oracle.ticketsystem.dao.impl.TicketJPADao;

public class TicketDaoTest {

private ITicketDao ticketDao = null;
private static long testTicketId = 0;

@Before
public void setUp() throws Exception {
ticketDao = new TicketJPADao();
}

@Test
public void testAdd() {

// adding a test ticket
Ticket ticket = ticketDao.add(1001, "Mark", "mark@gmail.com",
"TestTicket", "Ticket about the test");

assertTrue("Could not add test ticket.", (ticket.getId() > 0));

testTicketId = ticket.getId();

}

@Test
public void testGet() {

// finding a test ticket
Ticket ticket = ticketDao.get(testTicketId);

assertNotNull("Could not find test ticket.", ticket);

}

@Test
public void testUpdate() {

// finding a test ticket
Ticket ticket = ticketDao.update(testTicketId, "peter",
"Getting the test ticket", "ASSIGNED");

assertNotNull("Could not update the test ticket.",
ticket.getTechnician());
assertTrue("Could not add history to test ticket.", (ticket
.getTicketHistory().size() > 0));

}

@Test
public void testGetTicketsOwnedByTechnician() {

// finding a test ticket
List tickets = ticketDao.getTicketsOwnedByTechnician("peter");

assertTrue("Could not find tickets assigned to technician 'peter'",
(tickets.size() > 0));

}

@Test
public void testGetOpenTickets() {

// finding a test ticket
List tickets = ticketDao.getOpenTickets();

assertTrue("Could not find open tickets.", (tickets.size() > 0));

}

@Test
public void testRemove() {

// finding a test ticket
ticketDao.remove(testTicketId);

// the ticket has been removed
assertTrue(true);

}

}

4. 测试
分别右键点击三个测试类,选择Run As,选择JUnit Test。

看到绿色的颜色条,说明测试通过。

说明:测试时,Console中总是会报出警告:[EL Warning]: 2012-10-01 21:12:50.858--java.lang.ClassNotFoundException: weblogic.version。
但JUnit测试是全部通过了。

Project 下载:TroubleTickitSystem_JPA.7z

2012年1月8日星期日

OEPE_008:Trouble Ticket System 项目实战开发之JPA:创建JPA DAO类

开发运行环境:OEPE 12c(12.1.1.1.0)+ WebLogic Server 12c(12.1.1.1.0)+ Oracle Database 10g Express Edition 10.2.0.1

JPA Entity创建好了,谁来使用这些对象呢?答案是Data Access Objects(DAO)。
DAO负责对Entity的增加、修改、删除、查询。

1. LoginJPADao.java
package com.oracle.ticketsystem.dao.impl;

import com.oracle.ticketsystem.beans.Technician;
import com.oracle.ticketsystem.dao.ILoginDao;

public class LoginJPADao extends BaseJPADao implements ILoginDao {

public LoginJPADao() {
// TODO Auto-generated constructor stub
}

@Override
public Technician login(String id, String pwd) {

Technician technician = getEntityManager().find(Technician.class, id);
if (technician == null) {
return null;
}

if (technician.getPassword().equals(pwd)) {
return technician;
}

return null;
}

}

2. ProductJPADao.java

/**
 * 
 */
package com.oracle.ticketsystem.dao.impl;

import java.util.List;

import javax.persistence.Query;

import com.oracle.ticketsystem.beans.Product;
import com.oracle.ticketsystem.dao.IProductDao;

/**
 * The JPA DAO implementation for Product entity.
 * 
 */
public class ProductJPADao extends BaseJPADao implements IProductDao {

/**
* Default no-arg constructor
*/
public ProductJPADao() {
super();
}

/*
* (non-Javadoc)
* @see com.oracle.ticketsystem.dao.IProductDAO#getAllProducts()
*/
@SuppressWarnings("unchecked")
@Override
public List getAllProducts() {
Query allProductsQuery = getEntityManager().createQuery(
"select p from Product p");
List allProducts = allProductsQuery.getResultList();
return allProducts;
}

/*
* (non-Javadoc)
* @see com.oracle.ticketsystem.dao.IProductDAO#getProduct(int)
*/
@Override
public Product getProduct(long id) {
return getEntityManager().find(Product.class, id);
}

}

3. TicketJPADao.java
package com.oracle.ticketsystem.dao.impl;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import com.oracle.ticketsystem.beans.Product;
import com.oracle.ticketsystem.beans.Technician;
import com.oracle.ticketsystem.beans.Ticket;
import com.oracle.ticketsystem.beans.TicketHistory;
import com.oracle.ticketsystem.dao.ITicketDao;

public class TicketJPADao extends BaseJPADao implements ITicketDao {

/**
* Date pattern used across the application.
*/
public static final String DATE_PATTERN = "MM/dd/yyyy hh:mm:ss aa"; //$NON-NLS-1$

/**
* Default no-arg constructor
*/
public TicketJPADao() {
}

@Override
public Ticket add(long productId, String customerName,
String customerEmail, String title, String description) {

Product product = getEntityManager().find(Product.class, productId);

if (product == null) {
throw new RuntimeException("While adding a new ticket, "
+ "could not find reference to the given product Id: "
+ productId);
}

Ticket ticket = new Ticket();
ticket.setProduct(product);
ticket.setCustomerName(customerName);
ticket.setCustomerEmail(customerEmail);
ticket.setTitle(title);
ticket.setDescription(description);
ticket.setState("NEW"); // always NEW state
SimpleDateFormat dtFormat = new SimpleDateFormat(DATE_PATTERN);
ticket.setSubmissionDate(dtFormat.format(new Date()));

Long maxId = getMaxId("SELECT max(t.id) FROM Ticket t");

// setting the ticket Id
ticket.setId((maxId == null) ? 0 : maxId + 1);

EntityTransaction t = getEntityManager().getTransaction();
t.begin();
getEntityManager().persist(ticket);
t.commit();

return ticket;
}

@Override
public Ticket get(long ticketId) {
return getEntityManager().find(Ticket.class, ticketId);
}

@SuppressWarnings("unchecked")
@Override
public List getTicketsOwnedByTechnician(String technicianId) {

Query query = getEntityManager().createQuery(
"SELECT t from Ticket t WHERE t.technician.id = :technicianId");
query.setParameter("technicianId", technicianId);

return query.getResultList();
}

@Override
public Ticket update(long ticketId, String technicianId, String comment,
String state) {

EntityTransaction t = getEntityManager().getTransaction();
t.begin();

Ticket ticket = get(ticketId);

if (ticket == null) {
return null;
}

ticket.setState(state);
Technician technician = null;

if (technicianId != null) {

technician = getEntityManager()
.find(Technician.class, technicianId);

if (technician == null) {
throw new RuntimeException("No technician found for the ID '"
+ technicianId + "'");
}

}
ticket.setTechnician(technician);

TicketHistory ticketHistory = new TicketHistory();
Long maxTicketHistoryId = getMaxId("SELECT max(h.id) FROM TicketHistory h");

// setting the ticketHistory Id
ticketHistory.setId((maxTicketHistoryId == null) ? 0
: maxTicketHistoryId + 1);

if (technician != null) {
ticketHistory.setTechnician(technician);
}
ticketHistory.setState(state);
ticketHistory.setComments(comment);
ticketHistory.setTicket(ticket);

SimpleDateFormat dtFormat = new SimpleDateFormat(DATE_PATTERN);
ticketHistory.setUpdateDate(dtFormat.format(new Date()));

getEntityManager().persist(ticketHistory);

ticket.getTicketHistory().add(ticketHistory);

t.commit();
return ticket;
}

@SuppressWarnings("unchecked")
@Override
public List getOpenTickets() {

Query openTicketsQuery = getEntityManager().createQuery(
"SELECT t FROM Ticket t " + "WHERE t.state = :newState "
+ "OR t.state = :openState");
openTicketsQuery.setParameter("newState", "NEW");
openTicketsQuery.setParameter("openState", "OPEN");

return openTicketsQuery.getResultList();
}

@Override
public void remove(long ticketId) {

Ticket ticket = get(ticketId);
if (ticket != null) {
EntityTransaction trx = getEntityManager().getTransaction();
trx.begin();

for (TicketHistory ticketHistory : ticket.getTicketHistory()) {
getEntityManager().remove(ticketHistory);
}

ticket.getTicketHistory().clear();

getEntityManager().remove(ticket);

trx.commit();
}

}

private long getMaxId(String maxQuery) {

Query maxIdQuery = getEntityManager().createQuery(maxQuery);

Long maxId = 1L;

if ((maxIdQuery.getResultList() != null)
&& (maxIdQuery.getResultList().size() > 0)) {
maxId = (Long) maxIdQuery.getResultList().get(0);
}
return maxId;
}

}

4.  JPADaoFactory .java

/**
 * 
 */
package com.oracle.ticketsystem.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * A JPA DAO factory for providing reference to EntityManager.
 * 
 */
public class JPADaoFactory {

private static final String PERSISTENCE_UNIT_NAME = "TroubleTicketSystemServer";

private static EntityManagerFactory entityManagerFactory;
private static EntityManager entityManager;

/**
* Returns reference to EntityManager instance. If null then create it using
* the persistence unit name as defined in the persistence.xml
* @return EntityManager
*/
public static EntityManager createEntityManager() {

if (entityManager == null) {
entityManagerFactory = Persistence
.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
entityManager = entityManagerFactory.createEntityManager();
}
return entityManager;
}

public static void close() {
entityManager.close();
entityManagerFactory.close();
}

}

5.   BaseJPADao .java
package com.oracle.ticketsystem.dao.impl;

import javax.persistence.EntityManager;

public class BaseJPADao {

/**
* Default no-arg constructor
*/
public BaseJPADao() {
}

/**
* Returns JPA EntityManager reference.
* @return
*/
public EntityManager getEntityManager() {
return JPADaoFactory.createEntityManager();
}

}

2012年1月7日星期六

OEPE_007:Trouble Ticket System 项目实战开发之JPA:根据POJO类创建JPA Entity


开发运行环境:OEPE 12c(12.1.1.1.0)+ WebLogic Server 12c(12.1.1.1.0)+ Oracle Database 10g Express Edition 10.2.0.1

1. 创建Department.java

2. 右键TroubleTicketSystemServer,选择JPA Tools,选择Generate Entities from Java Class



3. 修改Technician.java,增加@ManyToOne,引用Department。
package com.oracle.ticketsystem.beans;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Set;

/**
 * The persistent class for the TECHNICIAN database table.
 * 
 */
@Entity
public class Technician implements Serializable {
private static final long serialVersionUID = 1L;

@Id
private String id;

@ManyToOne()
@JoinColumn(name = "DEPTID", referencedColumnName = "ID")
private Department department;

private String email;

private String name;

private String password;

// bi-directional many-to-one association to Ticket
@OneToMany(mappedBy = "technician")
private Set tickets;

// bi-directional one-to-one association to TechnicianPrivateData
@OneToOne(mappedBy = "technician")
private TechnicianPrivateData technicianPrivateData;

public Technician() {
}

public String getId() {
return this.id;
}

public void setId(String id) {
this.id = id;
}

public Department getDepartment() {
return department;
}

public void setDepartment(Department department) {
this.department = department;
}

public String getEmail() {
return this.email;
}

public void setEmail(String email) {
this.email = email;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getPassword() {
return this.password;
}

public void setPassword(String password) {
this.password = password;
}

public Set getTickets() {
return this.tickets;
}

public void setTickets(Set tickets) {
this.tickets = tickets;
}

public TechnicianPrivateData getTechnicianPrivateData() {
return this.technicianPrivateData;
}

public void setTechnicianPrivateData(
TechnicianPrivateData technicianPrivateData) {
this.technicianPrivateData = technicianPrivateData;
}


4. 修改 Department.java,增加@OneToMany,引用Technician。
package com.oracle.ticketsystem.beans;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Basic;
import javax.persistence.OneToMany;

import java.util.Set;

@Entity()
@Table(name = "DEPARTMENT", schema = "TROUBLETICKETUSER")
public class Department implements Serializable {
private static final long serialVersionUID = 1L;
@Id()
@Column(name = "ID", unique = true, nullable = false, precision = 22)
private long id;

@Basic()
@Column(name = "NAME", nullable = false, length = 100)
private String name;

@OneToMany(mappedBy = "department")
private Set technicians;

public Department() {
// TODO Auto-generated constructor stub
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Set getTechnicians() {
return technicians;
}

public void setTechnicians(Set technicians) {
this.technicians = technicians;
}

public boolean equals(Object obj) {
if ((this == obj))
return true;
if (!(obj instanceof Department))
return false;

Department castOther = (Department) obj;
if (this.getId() == castOther.getId()) {
return true;
} else {
return false;
}
}

public int hashCode() {
return (new Long(this.getId())).hashCode();
}

}

2012年1月6日星期五

OEPE_006:Trouble Ticket System 项目实战开发之JPA:根据数据库表创建JPA Entity

开发运行环境:OEPE 12c(12.1.1.1.0)+ WebLogic Server 12c(12.1.1.1.0)+ Oracle Database 10g Express Edition 10.2.0.1

创建JPA Entities有两种方式,一种是根据数据库表来创建,另一种是根据POJO类来创建。
我们先介绍第一种,再介绍第二种。

1.  右键TroubleTicketSystemServer,选择JPA Tools,选择Generate Entities from Tables


2.  选择除Department表以外的其它表,Department Entity我们将通过POJO类创建。


 3.  默认自动关联的Table Association


 4.  选择TECHNICIANPRIVATEDATA 和 TECHNICIAN 关联关系
取消勾上Generate this association,因为我们不想建立二者之间一对多的关联关系,之后会手工建立二者之间一对一的关联关系。

 5.  选择TICKETHISTORY 和 TECHNICIAN 关联关系
取消勾上Generate a reference to a collection of TICKETHISTORY in TECHNICIAN,因为我们不想在TECHNICIAN中有TICKETHISTORY 集合对象。
也就是说,二者是一个单向一对多的关系。



6.  选择TICKETHISTORY 和 TICKET 关联关系
 修改Property,把tickethistories 改为ticketHistory,这样更符合Java命名规范。


7.  点击绿色的加号,手工建立TECHNICIANPRIVATEDATA 和 TECHNICIAN 关联关系
(1)选择Simple association,并选择相应的表
(2)选择两个表的关联主键
(3)选择一对一的关联关系


 8. 准备生成Entity的Java类
(1)Collection类型选择Set,并设置package路径
(2)默认要生成的Entities
 (3)修改不符合Java规范的类名。
 (4)修改不符合Java规范的变量名。

 9. 查看生成的Entity Java类
(1)@Basic批注
不带批注的Property,默认是@Basic类型
(2)@Column批注
表示对应数据库表中的字段,包括名称、是否唯一、长度、是否允许为null。
(3)@Id批注
表示主键
(4)@OneToOne批注 
表示一对一的关联关系,
其中在源方Entity定义中后面跟@JointColumn 批注,表示与目标Entity中关联的数据库字段;
比如在TechnicianPrivateData.java中:
//bi-directional one-to-one association to Technician
@OneToOne
@JoinColumn(name="ID")
private Technician technician;
在目标方Entity定义中会使用mappedBy来指向源方引用的属性名称。
比如在Technician.java中:
// bi-directional one-to-one association to TechnicianPrivateData
@OneToOne(mappedBy = "technician")
private TechnicianPrivateData technicianPrivateData;
(5)@OneToMany批注
表示一个Entity A可以有多个Entity B;但是两个 Entity B 不可以被同一个 Entity A引用 。
比如一个Technician可以有多个Tickets,但是一个Ticket只能被一个Technician引用。
比如在Technician.java中:
// bi-directional many-to-one association to Ticket
@OneToMany(mappedBy = "technician")
private Set tickets;
(6)@ManyToOne批注
表示多个Entity A可以被同一个Entity B引用。
比如在Ticket.java中:
//bi-directional many-to-one association to Technician
@ManyToOne
@JoinColumn(name="TECHNICIANID")
private Technician technician;
在@ManyToOne批注中还可以定义FetchType,可以设置的值有FetchType.EAGER(默认),FetchType.LAZY。

2012年1月5日星期四

OEPE_005:Trouble Ticket System 项目实战开发之JPA:创建项目

开发运行环境:OEPE 12c(12.1.1.1.0)+ WebLogic Server 12c(12.1.1.1.0)+ Oracle Database 10g Express Edition 10.2.0.1

1. 与 WebLogic Server 集成
请参考《与 WebLogic Server 集成》。
2. 与 Oracle Database 集成
请参考《与 Oracle Database 集成》。

3. 创建EAR Project:TroubleTicketSystemEAR
(1)
(2)
3. 创建Dynamic Web Project:TroubleTicketSystemServer
 (1)
(2)勾上Add Project to an EAR,并点击Modify...
(3)勾上JPA,版本2.0。
(4)选择EclipseLink 2.4x,点击下载按钮
(5)选择EclipseLink 2.4.0 Juno,点击Next
(6)下载EclipseLink 2.4.0 Juno
(7)选择之前建好的数据库连接,并勾上Add driver library to build path

参考文献:
1. http://www.oracle.com/technetwork/developer-tools/eclipse/overview/tutorials-101794.html

2012年1月4日星期三

Tips_015:Outlook中如何把"回复"改成"Re"?

我的Outlook2007是中文版的,平时写信,中英文内容都可以正常显示。但是因为老板只能看英文,而且习惯按英文排序,比如他会看哪些人回复了他的邮件。
因为我回复的邮件前缀是中文的”回复“,所以被排到很后面,导致老板经常会错过我的邮件,以为我迟迟没有回复。
那么,如何把"回复"改成"Re"呢?难道非要安装英文版的Outlook 2007?
几经实验,终于找到了设置的地方。

1. 点击工具-->选项

2. 点击邮件格式-->国际选项
勾上”答复和转发时,邮件头使用英语“。顺便把编码都改为Unicode(UTF-8)。

OEPE_004:与Oracle Database集成

开发运行环境:OEPE 12c(12.1.1.1.0)+  Oracle Database 10g Express Edition 10.2.0.1

1.  SQL脚本

(1)创建troubleticketuser用户

sqlplus system/welcome1 @create_troubleticketuser_user.sql
grant connect, resource to  troubleticketuser identified by welcome1;
Exit;

(2)创建表

drop table PRODUCT cascade constraints;
drop table TECHNICIAN cascade constraints;
drop table TECHNICIANPRIVATEDATA cascade constraints;
drop table DEPARTMENT cascade constraints;
drop table TICKET cascade constraints;
drop table TICKETHISTORY cascade constraints;

CREATE TABLE PRODUCT (ID INTEGER NOT NULL PRIMARY KEY, CODE VARCHAR(10) NOT NULL, NAME VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255), CONSTRAINT UNI_PROD_CODE UNIQUE(CODE) );
CREATE TABLE DEPARTMENT (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(100) NOT NULL );
CREATE TABLE TECHNICIAN (ID VARCHAR(30) NOT NULL PRIMARY KEY, PASSWORD VARCHAR(30) NOT NULL, NAME VARCHAR(255) NOT NULL, EMAIL VARCHAR(100), DEPTID INTEGER NOT NULL, CONSTRAINT DEPT_ID_REF FOREIGN KEY(DEPTID) REFERENCES DEPARTMENT(ID) );
CREATE TABLE TECHNICIANPRIVATEDATA(PK_ID INTEGER NOT NULL PRIMARY KEY, ID VARCHAR(30) NOT NULL, SSN_NO INTEGER NOT NULL, CONSTRAINT UNI_SSN_NO UNIQUE(SSN_NO), CONSTRAINT TECHPRIVATE_ID_REF FOREIGN KEY(ID) REFERENCES TECHNICIAN(ID) );
CREATE TABLE TICKET (ID INTEGER NOT NULL PRIMARY KEY, PRODUCTID INTEGER NOT NULL, CUSTOMERNAME VARCHAR(100) NOT NULL, CUSTOMEREMAIL VARCHAR(100), TITLE VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255), SUBMISSIONDATE VARCHAR(30) NOT NULL, TECHNICIANID VARCHAR(30), STATE VARCHAR(15) NOT NULL, CONSTRAINT PRODID FOREIGN KEY(PRODUCTID) REFERENCES PRODUCT(ID), CONSTRAINT TECH_ASSOCIATE_ID FOREIGN KEY(TECHNICIANID) REFERENCES TECHNICIAN(ID) );
CREATE TABLE TICKETHISTORY (ID INTEGER NOT NULL PRIMARY KEY, TICKETID NOT NULL, TECHNICIANID VARCHAR(30), STATE VARCHAR(15) NOT NULL, COMMENTS VARCHAR(255), UPDATEDATE VARCHAR(30) NOT NULL, CONSTRAINT TICKET_ID_FK FOREIGN KEY(TICKETID) REFERENCES TICKET(ID), CONSTRAINT TECH_ASSOCIATE_HISTORY_ID FOREIGN KEY(TECHNICIANID) REFERENCES TECHNICIAN(ID) );

INSERT INTO PRODUCT VALUES(1001,'11gDB','Oracle Database 11g', 'Oracle gives Oracle customers the agility to respond faster to changing business conditions, gain competitive advantage through technology innovation, and reduce costs.');
INSERT INTO PRODUCT VALUES(2001,'OEPE11g','Oracle Enterprise Pack for Eclispe 11g', 'OEPE is a set of Eclipse plug-ins that is designed to help develop, deploy and debug applications for Oracle WebLogic Server.');
INSERT INTO PRODUCT VALUES(3001,'JDeveloper','Oracle JDeveloper','Oracle JDeveloper is a free integrated development environment that simplifies the development of Java-based SOA applications and user interfaces with support for the full development life cycle.');
INSERT INTO DEPARTMENT VALUES (99, 'SALES');
INSERT INTO DEPARTMENT VALUES (199, 'MARKETING');
INSERT INTO TECHNICIAN VALUES ('david', 'david', 'David Dodd', 'david@oracle.com', 99);
INSERT INTO TECHNICIAN VALUES ('peter', 'peter', 'Peter Smith', 'peter@oracle.com', 199);
INSERT INTO TECHNICIANPRIVATEDATA values (25,'david',123456);
INSERT INTO TECHNICIANPRIVATEDATA values (35,'peter',678910);
INSERT INTO TICKET VALUES (101, 1001, 'john', 'john@hotmail.com', '11g JDBC Driver could not connect', 'Oracle 11g JDBC driver hangs while connecting with the database.', '05/16/2009 11:10:15 AM', 'peter', 'ASSIGNED' );
INSERT INTO TICKET VALUES (102, 2001, 'tom', 'tom@yahoo.com', 'OEPE crashes while starting', 'Oracle Enterprise Pack for Eclipse crashes while launching it.', '06/12/2009 10:40:15 AM', null, 'NEW' );
INSERT INTO TICKET VALUES (103, 3001, 'kelly', 'kelly@ibm.com', 'JDeveloper compiler fails', 'The java compiler fails while compiling the files.', '06/12/2009 09:35:15 AM', null, 'OPEN' );
INSERT INTO TICKETHISTORY VALUES (11, 101, 'david', 'ASSIGNED', 'Assigned to David', '05/10/2009 13:20:15 PM');
INSERT INTO TICKETHISTORY VALUES (12, 101, null, 'OPEN', 'Released from David', '05/11/2009 13:20:15 PM');
INSERT INTO TICKETHISTORY VALUES (13, 101, 'peter', 'ASSIGNED', 'Assigned to Peter', '05/16/2009 11:10:15 AM');
INSERT INTO TICKETHISTORY VALUES (14, 102, 'peter', 'ASSIGNED', 'Assigned to Peter', '06/12/2009 11:20:15 AM');
INSERT INTO TICKETHISTORY VALUES (15, 102, null, 'OPEN', 'Keep it open for the next patch release.', '06/12/2009 13:35:15 PM');

2.  打开Data Source Explorer


3.  创建数据库连接
(1)右键Database Connections,选择New



(2)选择Oracle Database Connection

(3)配置参数

(4)点击Test Connection,测试通过后就可以连接数据库了。

3.  连接数据库,查看表结构
(1)右键数据库连接名称,选择Connect
(2)右键Schema名称,选择Show Schema Viewer


(3)右键数据库连接名称,选择Open SQL Scrapbook
选择Type,Name,Database,然后在空白处右键,选择Edit in SQL Query Builder

(4)在SQL Query Builder中输入SQL语句
(5)右键某个表,选择Data,选择Edit,可以直接查看该表的数据。

2012年1月3日星期二

2012年1月2日星期一

OEPE_002:与WebLogic Server集成


开发运行环境:Oracle Enterprise Pack for Eclipse 12.1.1.1.0 + WebLogic Server开发版12c(12.1.1.1.0)

配置步骤说明:

 1. 在Server View Tab中,右键空白处,选择New,选择WebLogic Server12c



2. 设置Weblogic home,Java home



 3. 设置Domain路径


 4. 点击绿色的三角图标,启动WebLogic Server

5. 右键WebLogic Server连接,选择访问Admin Console

6. 成功登录Admin Console


2012年1月1日星期日

OEPE_001:与Glassfish集成

开发运行环境:Oracle Enterprise Pack for Eclipse 12.1.1.1.0 + Glassfish3.1.2.2

Glassfish是原来SUN的Application Server。
下载地址:http://glassfish.java.net/
OEPE 是 Oracle Enterprise Pack for Eclipse,是Oracle定制后的Eclipse,习惯使用Eclipse开发的朋友可以试用一下。
下载地址:http://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html
两个软件都有.zip格式的,解压即可以使用,非常方便,我爱绿色软件。

配置步骤说明:

1. 在Server View Tab中,右键空白处,选择New,选择Glassfish3.1.2


2. 设置JRE和Glassfish路径
我这里没有单独安装使用的是Netbeans7.2安装自带的Glassfish3.1.2.2。


 3. 设置管理员用户和口令



  4. 设置管理员用户和口令
勾掉"Anonmymous Connection for Admin Commands“。
5. 点击绿色的三角图标,启动Glassfish

6. 右键Glassfish连接,选择访问Admin Console


7. 成功登录Glassfish Console