JDO's JDOHELPER assistant introduction

zhaozj2021-02-16  52

JDOHELPER

In this section, we mainly tell the method in the assistant class of JDoHelper. The following table lists several common methods in JDOHELPER, if you want to know more about the JDoHelper all methods, please refer to the definition in the JavaDoc document.

JDOHELPER Static Void Makedirty (Object PC, String Field)

Static Object GetObjectId (Object PC)

Static PresistenceManager GetPersistenceManager (Object PC)

Static Boolean IsdiRTY (Object PC)

Static Boolean IsTransactional (Object PC)

Static Boolean IsPersistent (Object PC)

Static Boolean IsNew (Object PC)

Static Boolean IsDelete (Object PC)

Static PersistenceManagerFactory GetPersistenceManagerFactory (Properties Props)

JDOHELPER mainly performs three types of operations: 1. Object of persistence 2, Operation of the object life 3, create a PersistenceManagerFactory object. Below I will tell the process of these three operations: 1. Object persistence operation

Object persistence operations To use 3 methods: Makedirty, GetObjectID and GetPersistenceManager. Where the MakeDirty (Object PC, String Field) is used when you operate an array field of a persistent object, you only call this method to incorporate the persistent object to be operated, and the field that has changed the value will notify JDO. Implementation, you have modified the value of the field, you can save the new value to the database. GetObjectID users compare persistent object consistency, if the incoming parameter object is not the same object, which is not the same object, with the current comparison persistence object. The last method will get a PersistenceManager object.

2, object life cycle operation

Public Static Boolean ISDIRTY (Object PC);

Public Static Boolean Istransactional (Object PC);

Public Static Boolean IsPersistent (Object PC);

Public Static Boolean Isnew (Object PC);

Public Static Boolean IsDeleted (Object PC); The few methods listed above are judgments of a persistent object state, and the judgment of these states is made by JDO implementation, you don't have to worry about it at all. 3. Create a PersistenceManagerFactory object

Public Static PersistenceManagerFactory GetPersistenceManagerFactory (Properties Props);

You can get the PersistenceManagerFactory object through JDOHELPER's getPersistenceManagerFactory method, this method has only one parameter, is a java.util.properties object. You have to set an instance of this Properties object before use. By calling the GetPersistenceManagerFactory method JDO implementation creates a PersistenceManagerFactory object or a pool-containing instance pool containing many PersistenceManagerFactory. Below I gave an example of getting PersistenceManagerFactory: // Properties usually comes from a file

Properties PROPS = New Properties ();

// This property parameter tells JDoHelper what kind of PMFactory will

Props.SetProperty ("javax.jdo.PersistenceManagerFactoryClass",

"kodo.jdbc.Runtime.jdbcPersistenceManagerFactory");

// Project method defines the default settings for Persistence Managers

Props.SetProperty ("javax.jdo.option.optimistic", "true");

Props.SetProperty ("javax.jdo.opption.retainvalues", "TRUE");

// The following is to set the database information, including username, password, drive, connection

Props.SetProperty ("javax.jdo.opption.connectionusername", "solarmetric"); //

Props.SetProperty ("javax.jdo.opption.connectionpassword", "kodo"); //

Props.SetProperty ("javax.jdo.opption.connectionURL", "JDBC: HSQL: Database"); //

Props.SetProperty ("javax.jdo.option.connectionDrivername", //

"org.hsqldb.jdbcdriver");

// Get a PMFactory object.

PersistenceManagerFactory PMF = JDOHELPER.GETPERSISTENCEMANAGERFAACTORY (PROPS);

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

New Post(0)