Javax.jdo.PersistenceManagerFactory
The PersistenceManagerFactory interface is used to get a PersistenceManager instance. Two factory methods are defined in this interface (the content of the factory method can refer to the Java design mode).
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.
Because PersistenceManagerFactory is an interface, some vendor-specific classes that implement the interface must be used by a "bootstrap" mechanism.
Examples // SolarMetric's interface implemented PersistenceManagerFactory ... PersistenceManagerFactory managerFactory = new com.solarmetric.kodo.impl.jdbc.JDBCPersistenceManagerFactory (); // get a controller 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.
The PersistenceManager interface is the point of connecting the Java application and JDO implementation. The application uses PersistenceManager to get an object from the data store or put a Java object in the data store. The PersistenceManager interface is also serving several JDO components that will be discussed below. Several methods are defined in the PersistenceManager interface to add the JDO instance object to the data store.
Public Abstract void makepersistent (Object); Public Abstract void makepersistentall (Object []); public abstract void makepersistentall (java.util.collection);
The process of adding a JDO instance object to a data store by the following methods:
// get a manager ... PersistenceManager manager = managerFactory.getPersistenceManager (); // Employee must extend below the PersistenceCapable ... Employee newEmployee = new Employee (...); manager.makePersistent (newEmployee);
Javax.jdo.extentextent object represents all the actual class objects in the current database. A factory approach in PersistenceManager is responsible for obtaining an extent (range) object.
Public Extent getExtent (Class Persistencecapableclass, Boolean Subclasses)
The Class parameter indicates the type of object received. The Boolean parameter indicates whether there is a subclass of the class specified by the first parameter.
The Extent interface defines an Iterator () method, which returns a java.util.iterator to traverse all instances described by Extent.
// get a manager ... PersistenceManager manager = managerFactory.getPersistenceManager (); // the Employee class must implement PersistenceCapable ... Extent employeesExtent = manager.getExtent (Employee.class, false); java.util.Iterator iterator = employeesExtent .iterator ();
Javax.jdo.QueryQuery interface allows examples that meet certain conditions from the data store. The Query instance can be obtained from the NewQuery () method from the PersistenceManager interface.
The Query interface defines several different versions of the overload execute () method, which will execute the query (query) and return the results of the match.
// get a manager ... PersistenceManager manager = managerFactory.getPersistenceManager (); // Employee class must implement the interface PersistenceCapable ... Extent employeesExtent = manager.getExtent (Employee.class, false); // Query to get all in a company Employees .... query query = manager.newquery (Employee.class, Employeesextent, "YearsofemployEment> 5"); // Execute Query ... Collection Employees = () Query.execute (); // Processing result ... item itrator = Employees.ITerator (); while (item.hasnext ()) {Employee Employee = (Employee) iterator.next (); (...)} Note NEWQUERY () method Three parameters "YearsofemployEment> 5". It indicates the conditions for returning results. The above implementation requires that there must be a property field in the Employee class called YearsofemPloyment.