Kodojdo Guide Chapter 8

xiaoxiao2021-03-06  84

Chapter 8 PersistenceManager

The above figure summarizes the most common methods and properties of the PersistenceManager interface. Refer to JavadoC to learn more complete information. Java

The bean style Getter and setter methods are given in the field declaration. The method of entering the ginseng to .... indicates the overload function. PersistenceManager is the primary interface that combines the application and JDO runtime. Each PersistenceManager manages one hold

The cache of a long service object and associates a single transaction. According to the function, PersistenceManager can classify: 1) Associated User Object 2) Property Configuration 3) Association Transaction 4) Energy Life Management 5) JDO Identification Management 6) Query Plant 7) Extended Factory 8)

8.1 Associated User Objects The userObject property of the PersistenceManager allows you to associate any object and a personistenceManager. This

An object cannot be an object used by a JDO implementation.

8.2. Properties Configuration The PersistenceManager includes both Getter and Setter methods for two configuration properties. Multithreaded and

Ignorecache. These properties have been discussed in detail in the PersistenceManagerFactory settings.

8.3 related transactions

PersistenceManager and transaction instance have a one-to-one relationship. In fact, many manufacturers use a single class to achieve

PersistenceManager and Transaction interface. If your program requires concurrent transactions, you have to use multiple

You can use the CurrentTransaction method to get the transactions associated with the current PersistenceManager.

8.4 Can lasting life management

PersistenceManagers perform many actions that affect the state of persistence of persistent class. This is manifested by providing multiple functions. example

For example, a certain persistent object can be used as a parameter, such as the MakePersistent method, or the entire capable array or collections can be made as

parameter. For example MakePersistentall

1) Transformation from temporary into new persistent states. This behavior can only be used in the context environment of active transactions. After the transaction is submitted, the new lasting

The instance will be inserted into the database.

2) This behavior transforms a persistent example to the temporary state. This instance immediately lost the associated PersistenceManager and JDO identity.

But records in the database will not be modified. This behavior can only be performed on the Clean object. If you execute in the Dirty object, you will throw JDOUSEREXCEPTION

3) Use this method to make the temporary object becomes Transient-Transactional status, or the persistent non-transaction object enters the current transaction.

. In the second case, this behavior must be executed in the active transaction.

4) Retrieving the object means telling PersistenceManager you no longer use this object. The status of the object will become Hollow and

PersistenceManager releases all the strong references to the object, allowing it to be recycled by garbage. Call the evicTALL method to indicate that all objects in the Persistent-Clean state in the PersistenceManager cache

5) Use the Refresh behavior to ensure that the object's persistent status and the value in the database are synchronized. The intention of this behavior is to avoid optimization for long-term operation.

The business is distressed in the business. The refreshall method is for transactional objects in all caches. This method is meaningless if there is no active transaction.

6) A persistent object takes out all persistent fields from the database and obtains the object with this method. Use this behavior to ensure that the state is turned to temporarily

Before sex, the fields of all instances are fully loaded. Note that this behavior is not recursive. If object A and B have a relationship, then call the RETRIEVE method as a parameter to load B, which will not be necessary to fill the field in the database in the database.

8.5 Survival Example

8.6 JDO Identification Management

Each PersistenceManager manages the JDO ID of the persistent object in the cache. Methods as below:

1) Return the JDO identity class capable of lasting class

2) Recreate the JDO identification object with the string returned by the jdo identification object's toString method. Suppose a long-lasting class and its JDO identity

String, this method uses the getObjectByid method described above to construct a JDO identification object, this object first creates a string,

After the persistent class object is obtained according to this string. 3) Return to PersistenceManager management's persistent class JDO ID

4) Returns the corresponding persistent class instance of the JDO identification object. If the instance has cached, the version of the cache will be returned. Otherwise you will create a new real

example. Whether loading data from the database is not necessarily. If the parameter of the method is True, the current JDO identifies the record in the database does not exist, then the JDO will thrown

JDODATOREEXCEPTION. Otherwise, JDO returns a cached instance that is not verified whether it is deleted by other persistent managers. some

JDO implementation returns a Hollow instance when there is no caching object exists. If you visit the persistent field of this object, it will not throw an exception.

8.7 EXTENT Factory

Expansion is a logical manifestation of all sustainable capabilities, including subclasses. The getExtent method using the PersistenceManager can be extended. There are two parameters: the class that extends the object included, and

A prompts that include the Boolean parameters of the subclass, if you have a long-lasting REQIRES-EXTENT property set to false, then you cannot get the extension of this class. 8.8 Query Factory Query Objects To find persistent objects that meet certain conditions. You can get queries by PersistenceManager's NewQuery

example. Refer to Query Chapter and Javadoc can get more details.

8.9 close

When you don't need PersistenceManager, you should call its Close method.

转载请注明原文地址:https://www.9cbs.com/read-95053.html

New Post(0)