Javax.jdo.PersistenceManagerFactory
PersistenceManagerFactory接口 被用来获得一个PersistenceManager 实例。这个接口中定义两个工厂方法(有关工厂方法的内容可以参考Java设计模式)。
public PersistenceManager getPersistenceManager()
public PersistenceManager getPersistenceManager(String userid,
String passWord)
Because PersistenceManagerFactory is an interface, some vendor specific class, which implements this interface, must be used as a bootstrap mechanism. This should turn out to be the only vendor specific code that a JDO application uses. Because of this, the JDO specification suggests that an application level factory class be implemented which returns the appropriate instance of the PersistenceManagerFactory so that implementations may be swapped out with minimal impact on application code. Only the application's factory would need to be modified in this case.
因为PersistenceManagerFactory 是一个接口,一些实现该接口的厂商特定的类必须通过一种“自举”机制来使用。
// SolarMetric's 实现PersistenceManagerFactory 接口的例子...
PersistenceManagerFactory managerFactory =
new com.solarmetric.kodo.impl.jdbc.JDBCPersistenceManagerFactory();
// 获得一个控制器 manager...
PersistenceManager manager = managerFactory.getPersistenceManager();
javax.jdo.PersistenceManager
The PersistenceManager interface is the primary point of contact between a Java application and the JDO implementation. Application code uses a PersistenceManager to retrieve Java objects from the data store and to add Java objects to the data store. The PersistenceManager interface also serves as a factory for several other JDO components discussed below.
PersistenceManager 接口是连接Java应用程序和JDO实现的要点。应用程序使用PersistenceManager 从数据存储中获得对象或者把一个Java对象放到数据存储中。PersistenceManager 接口也为下面将要讨论的几个JDO组件提供服务。
PersistenceManager 接口中定义了几个方法来把JDO实例对象添加到数据存储中。
public abstract void makePersistent(Object);
public abstract void makePersistentAll(Object[]);
public abstract void makePersistentAll(java.util.Collection);
通过下面几个方法实现把JDO实例对象添加到数据存储中的过程:
// 获得一个 manager...
PersistenceManager manager = managerFactory.getPersistenceManager();
// 下面的 Employee 必须扩展了 PersistenceCapable...
Employee newEmployee = new Employee(...);
manager.makePersistent(newEmployee);
javax.jdo.Extent
Extent (范围)对象表示所有的在当前数据库中实际的类对象。在PersistenceManager 中的一个工厂方法负责获得一个Extent (范围)对象。
public Extent getExtent(Class persistenceCapableClass, boolean subclasses)
Class参数标明了接收的对象类型。boolean 参数标明是否包含第一个参数指定的类的子类。
Extent 接口定义了一个iterator()方法,它返回一个 java.util.Iterator来遍历所有由Extent 描述的实例。