JDO示例 - JPOX
(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
lib
|
jdo.jar( 或者叫 jdo2-api.jar)
|
JDO2.0 AIPI
|
jpox.jar
|
JPOX1.1.4 实现
|
|
jpox-enhancer.jar
|
JPOX 的字节码增强器
|
|
log4j.jar
|
Log4j
|
|
bcel.jar
(jboss-4.0.2/server/default/lib 目录下面有 )
|
Byte Code Engineering Library
(BCEL) ,这是 Apache Software
Foundation 的 Jakarta 项目的一部分。
|
|
src
|
alin/demo/Author.java
|
|
alin/main/ …… .java
|
这个包下面的源文件是示例应用程序
|
|
alin/demo/Author.jdo
|
||
jpox.properties
|
注意数据库 URL 后面部分的作用:
SelectMethod=cursor( 后面会说明 )
|
|
log4j.properties
|
||
bin
|
alin/demo/Author.class
|
|
alin/main/ …… .class
|
||
alin/demo/Author.jdo
|
这些文件都是直接从 src 目录下面复制过来的。
|
|
jpox.properties
|
||
log4j.properties
|
代码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相关推荐
- Hive 快速上手--官网中文翻译
目录 安装和配置 从一个稳定的发行版安装Hive 编译Hive源码 编译主干的Hive 编译分支branch-1 在Hadoop 0.20上在0.13之前编译Hive 在Hadoop 0.23上在0. ...
- 转载:使用Spring进行数据访问(Data Access With Spring)
Table of Contents 1.1. 统一的数据访问异常层次体系(Consistent Exception Hierarchy In Spring) 1.1.1. DAO模式的背景(Backg ...
- DataNucleus之JDO操作示例
JDO(Java Data Object )是Java对象持久化的新的规范,也是一个用于存取某种数据仓库中的对象的标准化API.注意JDO是一种规范,而不是一个产品.而DataNucleus正是实现J ...
- Google App Engine + JDO + Spring MVC,CRUD示例
注意 本教程更多关于实践指南,请参考此官方的在数据存储区中使用JDO了解详细说明. 请参阅以下代码段,以使用Java数据对象(JDO)在GAE数据存储上执行CRUD. 只需使用JDO注释为客户注释,然 ...
- Java数据对象(JDO)快速入门
JDO有一个充满活力的社区.所以如果你正在为你的POJO寻找持久化 解决方案,JDO是一个通过JCP项目开发的标准.JDO为POJO持久化提供了一个丰富和具有全部特征的JSR规范,并且很多开发商正在提 ...
- Spring事务管理示例JDBC
Spring事务管理示例JDBC Spring Transaction Management是Spring框架中使用最广泛且最重要的特性之一.事务管理在任何企业应用程序中都是一项微不足道的任务.我们已 ...
- spring事务 jdbc_Spring事务管理示例JDBC
spring事务 jdbc Spring Transaction Management is one of the most widely used and important feature of ...
- DataNucleus JDO基础入门
开发应用程序通常是一项复杂的任务,涉及许多组件. 开发所有这些组件可能非常耗时. Java 数据对象 API (JDO) 旨在减少花费的一些时间,提供一个 API 以允许 Java 开发人员将面向对象 ...
- JDO持久框架——DataNucles
1. JDO框架简介 Java数据对象(Java Data Objects,JDO)是一个应用程序接口(API),它是Java程序员能够间接地访问数据库,也就是说,不需使用直接的结构化查询语言(SQL ...
最新文章
- python使用matplotlib可视化折线图、在可视化图像中同时绘制多条折线图
- mysql 查询缓存
- 安卓三维展示源码_手机(安卓)自动化脚本开发线上培训
- 使用SecureCRT脚本备份网络设备配置的一点感悟
- remote vscode无git_vs code 使用git
- java 除法向上,向下取整
- LoudMiner:伪装在VST软件中的跨平台挖矿软件
- 《黑客X档案2007配套光盘》2007年上半年合集(6期)
- MATLAB Simulink工具箱
- html怎么显示五线谱,教你一个怎么看五线谱的绝招!
- 东方时尚驾校科目一网上视频快速通过方法
- 关于侵权Sinesafe官方网站,仿冒、抄袭等恶劣行为的公告
- 由于哈希冲突,不同值的对象也可能具有相同的哈希值
- 使用HBuilder制作一个简单的HTML5动漫网页——紫罗兰永恒花园动漫价绍网页 7页
- Editor\Data\il2cpp/build/deploy/net471/il2cpp.exe did not run properly!
- {电脑救助站}常用知识1 来自常用知识( 网络安全中起重大作用的 Windows 命令)
- 通过css和js实现流星雨效果
- 作者:​孙少陵(1972-),男,中移(苏州)软件技术有限公司高级工程师、副总经理。...
- latex 大于小于大于等于小于等于
- React类式组件基础内容补充