JDO示例 - JPOX
来源:互联网 发布:linux node.js 安装 编辑:程序博客网 时间:2024/06/05 14:11
(ALin 2006-12-27 00:28)
1. 源代码生成,即是实现相关的接口,自己编写相关的方法,在点类似于BMP EJB。
2. 源代码处理。
3. 字节码增强(使用字节码增强工具:byte-code enhancer)。
Ø package.jdo
Ø alin/package.jdo
Ø alin/scut/package.jdo
Ø alin/scut/jdo/package.jdo
Ø alin/scut/jdo/Author.jdo
代码1: Author.java
private int books;
private String name;
public Author(String name, int books) {
this.name = name;
this.books = books;
protected Author() {
public String getName() {
return name;
public void setName(String name) {
this.name = name;
public int getBooks() {
return books;
public void setBooks(int books) {
this.books = books;
<?xml version="1.0" encoding="UTF-8"?>
"-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN"
"http://java.sun.com/dtd/jdo_2_0.dtd">
<package name="alin.demo">
<class name="Author" identity-type="datastore">
<field name="books" persistence-modifier="persistent">
</field>
<field name="name" persistence-modifier="persistent">
<column length="50" jdbc-type="VARCHAR"/>
</field>
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n
# Each category can be set to a "level", and to direct to an appender
# Commented out sub-categories since the above setting applies to all subcategories
log4j.category.com.mchange.v2.resourcepool=INFO, A1
java org.jpox.enhancer.JPOXEnhancer alin/jpox/package.jdo
JPOX Enhancer completed with success for 2 classes. Consult the log for full details
java org.jpox.SchemaTool -props jpox.properties -create alin/jpox/package.jdo
JPOX SchemaTool (version 1.1.4) : Creation of the schema
2006-11-28 19:29:52 org.jpox.util.JDK14Logger info
信息: PersistenceManagerFactory - Vendor: JPOX Version: 1.1.4
2006-11-28 19:29:52 org.jpox.util.JDK14Logger info
信息: PersistenceManagerFactory initialised for datastore URL=jdbc:microsoft:sql
server://localhost:1433;DatabaseName=JDO driver=com.microsoft.jdbc.sqlserver.SQL
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: ================ DatabaseAdapter ==================
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: Adapter : org.jpox.store.rdbms.adapter.MSSQLServerAdapter
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: Datastore : name="Microsoft SQL Server" version="Microsoft SQL Server 200
May 3 2005 23:18:38
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: Driver : name="SQLServer" version="2.2.0022" (major=2, minor=2)
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: ===================================================
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: Initialising Catalog "JDO", Schema "" using "None" auto-start option
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: Catalog "JDO", Schema "" initialised - managing 0 classes
2006-11-28 19:29:53 org.jpox.util.JDK14Logger warn
警告: No manager for annotations was found in the CLASSPATH so all annotations a
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: Managing Persistence of Class : alin.jpox.Product [Table : PRODUCT, Inheri
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
信息: Managing Persistence of Class : alin.jpox.Book [Table : BOOK, InheritanceS
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
2006-11-28 19:29:53 org.jpox.util.JDK14Logger info
2006-11-28 19:29:54 org.jpox.util.JDK14Logger info
2006-11-28 19:29:54 org.jpox.util.JDK14Logger info
信息: Creating foreign key constraint : "BOOK_FK1" in catalog "" schema ""
2006-11-28 19:29:54 org.jpox.util.JDK14Logger info
2006-11-28 19:29:54 org.jpox.util.JDK14Logger info
信息: Validated 1 unique key(s) for table PRODUCT
2006-11-28 19:29:54 org.jpox.util.JDK14Logger info
2006-11-28 19:29:54 org.jpox.util.JDK14Logger info
// MakePersistent.java -- Create an Author object and persist it.
public class MakePersistent {
PersistenceManager pm = pmf.getPersistenceManager();
Author au = new Author("Eric Ben", 5);
System.out.println("Author: " + au.getName() + "/t" + au.getBooks()
// Can not read fields outside of transactions. Or set:
// System.out.println("Author: " + au.getName() + "/t" + au.getBooks()
System.out.println("Author: " + name);
// MakePersistent.java -- Create an Author object and persist it.
public static void main(String[] args) {
PersistenceManagerFactory pmf =
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
// Do other things.
public static void main(String[] args) {
PersistenceManagerFactory pmf = JDOHelper
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Query query = pm.newQuery(Author.class, "name == /"Eric Ben/"");
Collection result = (Collection)query.execute();
Author au = null;
if(result.iterator().hasNext()) {
au = (Author)(result.iterator().next());
// query.closeAll();
if(au == null) {
System.out.println("No Author found!");
// Can npt read fields from deleted objects. So this statement below
// will throws Runtime Exception: JDOUserException.
// System.out.println(au.getName());
// If we don't want update, we can use tx.rollback() instead of
// tx.commit()
String name = au.getName();
System.out.println("Author: " + name + " |/t" + au.getBooks());
Query query = pm.newQuery(Author.class, "name == /"Eric Ben/"");这一句创建了一个查询,第二个参数是JDO QL语句,具体语法这里不说了,较多。有的实现可以设置成使用SQL语句。
public static void main(String[] args) {
PersistenceManagerFactory pmf = JDOHelper
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Query query = pm.newQuery(Author.class, "name == /"WeiQin Sun/"");
Collection result = (Collection) query.execute();
Author au = null;
if (result.iterator().hasNext()) {
au = (Author) (result.iterator().next());
// query.closeAll();
if(au == null) {
System.out.println("No Author named [WeiQin Sun] found!");
au.setName("Jie Hou");
// If we don't want update, we can use tx.rollback() instead of
// tx.commit()
String name = au.getName();
System.out.println("Author: " + name + " |/t" + au.getBooks());
Ø 使用导航
Ø Extent查询,Extent代表某个可持久类的所有实例(可以包括其子类)
Ø Query查询,Query则代表满足一些条件的实例,如叫某个特定名字
String name = author.getName(); // author是导航引用
// ReadExtent.java -- Read by Extent.
import java.util.Iterator;
public class ReadExtent {
PersistenceManager pm = pmf.getPersistenceManager();
Extent extent = pm.getExtent(Author.class, false);
System.out.println("Author: " + au.getName() + " |/t"
public static void main(String[] args) {
PersistenceManagerFactory pmf =
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Query query = pm.newQuery(Author.class, "books == 5");
Collection result = (Collection)query.execute();
Iterator itor = result.iterator();
Author au;
while(itor.hasNext()) {
au = (Author)itor.next();
System.out.println("Author: " + au.getName() + " |/t"
+ au.getBooks());
出现:Can't start a cloned connection while in manual transaction mode
- JDO示例 - JPOX
- JPOX:免费的JDO实现(1.2版本开始支持JPA1)
- DataNucleus之JDO操作示例
- JDO
- JDO
- Jdo
- JDO
- 高级:JDO技术及如何进入企业应用示例
- jdo:jdo-tutorial索引
- jdo是什么
- JDO 是什么?
- JDO 是什么
- JDO是什么
- 什么是JDO
- JDO query
- JDO-1
- JDO-2
- JDO简介
- c#接收电子邮件类
- .Net环境下有关打印页面设置、打印机设置、打印预览对话框的实现(开源)---转
- 方新: 我对创新型国家的理解
- UTF-8 编码
- 电信网通证实台湾地震影响内地访问国际网站(12月27日)
- JDO示例 - JPOX
- 推荐好文:javascript的函数
- 同ibm工程师的邮件--有关wasce的
- 耶利亚的故事
- 状态对象:数据库的替代者
- 《win2003服务器安全设置》
- 这个太慢了,我一直用http://weiweictgu.cnblogs.com
- 腾讯互动状态代码生成页
- gridview添加删除确认对话框