Kodojdo Guide Chapter 6

xiaoxiao2021-03-06  76

Chapter 6 JDOHELPER

The figure above lists the most common ways of jdohelper. For detailed API information, please refer to the class Javadoc document application to use JDOHELPER for three types of operations: persistent operation, survival operation, and creation of PersistenceManagerFactory

. We study one by one.

6.1 Makedirty and getObjectid we have seen it. Suppose a one-to-lasting object and field name are modified,

Makedirty method tells the JDO field value has changed, and the new value is written to the data store. Usually JDO automatic tracking field modification, you make

The only chance to use this method is that you want to assign a new value to an array index. GetObjectID method Returns the JDO logo object, which requires a persistent class instance as a parameter. If the class of the instance is not a lasting

So this method returns NULL as the name suggests, getPersistenceManager to manage this persistent class for PersistenceManager

. Returns NULL if the parameter instance is not lasting

6.2 Survival operation

JDO can identify several survival status of persistent classes. The status of the JDO specification specified instances comply with strict rules. State conversion can be

Explicit behavior trigger, for example, calling the deletePersistent method for PersistenceManager to delete a lasting object, can also be hidden

Behavior trigger, for example, read a persistent field. The survival status of the ability to persistence instance is listed below. Unless specifically declared, each state can be supported by all JDOs. Don't care if you can

Can remember status and conversion behavior, you rarely take them in practice.

1) Transient: Creating a custom constructor without the object associated with a persistent framework is called a temporary object. If there is no JDO, then

Object is a temporary object. 2) Persistent-new: Object calls the persistencemanager.makepersistent method to make it last last day without inserting

The state in the data store is called a "new persistence" state. When the object is converted to this state, a JDO identifier is obtained. In the transaction, the information of the new persistent state object is inserted into the data storage. When the transaction rolls, a new lasting instance replys temporary state

. Data storage does not work. If the RESTOREVALUES attribute of the transaction is assigned to true, the laster transaction field of the instance will reply to the transaction just opened

The value of the beginning. 3) Persistent-new-deleded: In the current transaction, the object is just created by PersistenceManager.makePersistent or by

PersistenceManager.deletePersistent delete will enter this state. At this point you can only access the primary key field of the object. If you try

Figure Accessing other persistent fields will return JDOUSEREXCEPTION

When the transaction is submitted, the object in the persistent-new-deleted state will turn to a temporary state. The value of its persistence field will be by Java

The default is replaced. The transaction rollback is that the object in the persistent-new-deleted state will also turn to a temporary state in which case

If the RESTOREVALUES attribute of the transaction is set to TRUE, its persistent transactionality field value will reply to the transaction. Otherwise it will not change

change.

4) Persistent-Clean: The state of the object that does not make changes in the current transaction is called

Persistent-clean

5) Persistent-dirty: The object state of the persistent field value change in the current transaction is called Persistent-Dirty. Transaction

After the data store updates the persistence of the object.

6) Persistent-deleted: If a persistent object is the parameter of the persistenceManager.deletePersistent object, it changes to the state of the persistenceManager.deletePersistent. When the object is in this state, you can only access it.

Key fields, accessing other fields can cause JDOUSEREXCEPTION. Objects in the persistent-deleted state are turned to temporary. The storage record of the object has been cleared.

7) HOLLOW: The lasting object that does not read the value from the data is in the HOLLOW state, as long as the instance enters the Hollow status, it is in the persistent field

The value will be in a Java default value. When you first access these fields, these fields are reloaded from the data store, if necessary

You can delay the time of reading information, which is called lazy loading. The JDO implementation is not strong to the tracking of the HOLLOW state instance. If your application does not retain the reference to them, then they

Will be recycled by garbage.

8) Persistent-Nontransactional: Objects in the Persistent-Nontransactional status are persistent data

In data storage, but not guaranteed is the latest value. A state that allows access to the old value is useless, but if you use it, you will send it.

Objects in this status can provide better performance when you introduce outdated data of the program. This state is an optional feature of JDO, which may not be supported by many JDO. This is also the most complex survival period, it is affected by affairs.

NontransactionalRead, NontransactionAlwrite, RetainValues, and Optimistic Properties, etc.

management. When the PersistenceManagerFactory property is introduced, we will discuss these properties. In addition to the transaction, the persistence field that reads and writes is in the Persistent-Nontransactional state does not cause a status change. Began data things

When you have any modifications made to this instance's persistence fields. And when you read within the business

The persistence of the Persistent-Nontransactional status object will be converted to the persistent-clean state, and the writing will be converted to

Persistent-dirty status. In the optimal transaction, reading will not be transformed, and write will be converted to the Persistent-Dirty state.

9) Transient-Clean: Transient-Clean and Transient-Dirty can be returned to

TRANSIENT-TRANSACTIONAL category, the object in the Transient-Transactional state is not persistent, but their fields

It can be used as a border of the transaction. It means that they can reply to the previous value when the transaction is rolled. By using the temporary instance as a parameter, call

PersistenceManager's MakeTransactional method, you can make it transient-transactional. Some

JDO vendors do not support Transient-Transactional status, which is an optional feature of the JDO specification.

10) Transient-dirty: An instance of the transient-transactional state is modified in the current transaction.

TRANSIENT-DIRTY state, after the transaction is completed, the object in this state becomes transient-clean. If the transaction rolls back and its Restorevalues

Sex True, then the persistence and transaction fields reply to the value before the transaction begins.

The figure below describes the state transformation of persistent objects. The arrow indicates that the transition from one state is another state. The text under the arrow shows the trigger state

Change event. The method named in purple is the method in the transaction interface, the method named in red is the method of the PersistenceManager interface. Waiting we will introduce these interfaces.

After reviewing the status of the JDO survival, JDOHELPER's survival operation --Indirty, Istransactional,

ISPERSISTENT, ISNEW, ISDELETED - The purpose is completely clear. Everyone tells you that you can last in the name of the name.

That property, these attributes are determined by the instance's lifetime status. In fact, according to the table below, you can calculate the state of the instance based on these attributes.

However, declare again, there are little need to worry about the survival status of you can persist.

6.3. PersistenceManagerFactory constructor

You can call the jdohelper's getPersistenceManagerFactory method for the style-independent style.

PersistenceManagerFactory PersistenceManagerFactory object, this method requires a parameter: one

An instance of the Java.util.Properties class. This instance is to set the PersistenceManagerFactory, each calling this party.

Method, manufacturers can construct a new PersistenceManagerFactory object, or return to the matching pool to match the properties

The PersistenceManagerFactory object. The configuration options and related property names available for use will be discussed in the next chapter.

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

New Post(0)