PersistenceManageFactory
A very important class in JDO is this PersistenceManagerFactory except for the JDOHELPER assistant. It is a factory class for JDO development initialization configuration and obtaining the PersistenceManager. The purpose of writing this article is to introduce the internal method of this class and their Use so that everyone is using JDO as a reference.
The above figure shows the main properties and methods of PersistenceManagerFactory. PersistenceManagerFactory is responsible for creating a PersistenceManager object instance for the application, which can set the relevant parameters for the database connection and set the default settings for the created PersistenceManager object. You can also use it to plan the implementation of the JDO vendor, and implement the optimization of the application according to additional support provided by different manufacturers. Below I will introduce PersistenceManagerFactory:
1, how to get PersistenceManagerFactory
Most JDO vendors provide a way to construct the PersistenceManagerFactory. Each vendor may have different, but in general, it is recommended to use the standard JDOHELPER's getPersistenceManagerFactory method. This method's Properties parameter can set the properties of this factory object, once this Factory object, then all of his attributes will be "frozen", that is, you can't modify the properties of this object, if you try to do this, you will throw a JDOUSEREXCEPTION exception, because this factory object may be from one Object pools or it is also available for use by other applications.
JDO requires the specific PersistenceManagerFactory class to implement the Serializable interface, so you can put it in a file or in the JNDI tree to use it at any time.
2, PersistenceManagerFactory properties
Most of the PersistenceManagerFactory is a standard JavaBean style Getter and Setter methods they correspond to the corresponding properties field (as shown above). These properties can be divided into two category Connection configurations and the default options for PersistenceManager and Transaction.
1) Connection configuration
The so-called connection is a database connection, and I tell the setup process through a piece of code. Below this code tells JDoHelper to log in to the database and database, the login user name public string getConnectionUserName ();
Public void setConnectionUserName (String User);
Props.SetProperty ("javax.jdo.opption.connectionusername", user);
Set the password to connect the database
Public String getConnectionPassword ();
Public void setConnectionPassword (String Pass);
Props.SetProperty ("javax.jdo.option.connectionpassword", pass);
Set up the information of the database connection PUBLIC STRING GETCONNECTIONURL ();
Public void setConnectionURL (String URL);
Props.SetProperty ("javax.jdo.opption.connectionURL", URL);
Set the driver of the database public string getConnectionFactoryName ();
public void setConnectionFactoryName (String name); props.setProperty ( "javax.jdo.option.ConnectionFactoryName", name); through a JNDI lookup connection factory, you can use connection pooling DataSource get through this connection factory public Object getConnectionFactory ();
Public void setConnectionFactory (Object Factory);
// Used to obtain a local connection method public object getConnectionFactory2 ();
Public void setConnectionFactory2 (Object Factory);
2) The default option for PersistenceManager and Transaction
The following method sets the default properties of the PersistenceMangere and the relevant Transaction object created by PersistenceManagerFactory. Some JDO realizes that manufacturers may not implement all of these properties, when you set an attribute that is not supported, you will throw a jdounsupportedOptionException. Public Boolean getMultithreaded ();
Public void setmultithreaded (Boolean Multithreaded);
Props.SetProperty ("javax.jdo.opption.multithreaded", multithreaded;
The above value If set to true, representing the persistenceManger object and persistence objects controlled by this object can be accessed simultaneously, if set to false, some JDO implementations can be optimized by avoiding synchronization. Public boolean getoptimistic ();
Public void setoptimistic (Boolean Optimistic);
Props.SetProperty ("javax.jdo.option.Optimistic", Optimistic); The above method defaults to TRUE, represents optimization processing, and the optimization process will be discussed in the TransactionType section. Public boolean getretainvalues ();
Public void setRetainVale (Boolean Retain);
Props.SetProperty ("javax.jdo.opption.retainvalues", retain;
If the above value is set to True, the field value of the persistent object is still retained after the data is submitted to the database, otherwise the value of the field is cleared. Public Boolean getrestoreValues ();
Public void setRestoreValues (Boolean Restore);
Props.SetProperty ("javax.jdo.opption.restorevalues", restore;
The above method is used to control the rollback of the behavior and field of the persistent object. Public Boolean getnontransactionalread ();
Public void setnontrarsactionalRead (Boolean Read);
Props.SetProperty ("Javax.jdo.Option.nontransactionalRead", Read); these methods define if you can read the status of persistent objects through Transaction. If you are set to false, then you will throw a JDOUSEREXCEPTION exception to the persistent object to perform a query through the external Transaction. Public Boolean getnontransactionalwrite (); public void setnontransactionalwrite (Boolean Write);
Props.SetProperty ("javax.jdo.option.nontransactionalwrite", Write; these methods define if you can write through the outside transaction, if you are false, then you have a long time through the outside transaction A JDOUSEREXCEPTION is throwing an object when performing an update operation.
Public boolean getignorecache ();
Public void setignorecache (Boolean Ignore);
Props.SetProperty ("javax.jdo.opption.ignorecache", ignore;
The above method setting When "test query" is executed on a persistent object, whether the state of the persistent object is changed during the current process, the TRUE identifier ignores the changes. If set to false then update the result is updated to the database when the query is executed. 3, how to get PersistenceManager
Get the PersistenceManager to call the following method public persistenceManager getPersistenceManager ();
Public PersistenceManager getPersistenceManager (String User, String Pass);
Both methods can get PersistenceManage, the first method to set the database connection information through the PersistenceManagerFactory's setConnectionUserName and SetConnectionPassword methods, the second user name and password to set the database connection through the incoming parameters.
4, property and support option settings
Public property getProperties ();