class Persister
extends java.lang.Object
The methods in this class are highly dependent upon the order of the elements in BaseRecord's internal data array, which are laid out in a well-known order.
Loader| Modifier and Type | Class and Description |
|---|---|
private static class |
Persister.UpdateInfo
This class acts both as key and value for storing the information on a cached
UPDATE
set of statements. |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
allowDBUniqueCheck
Flag (only for temporary databases) that marks if the index server-validation was skipped and
it should be done by H2.
|
private org.h2.embedded.DirectAccessDriver |
directAccessDriver
The
DirectAccessDriver for H2. |
private static CentralLogger |
LOG
Logger
|
private Session |
session
Active database session
|
private static ExpiryCache<Persister.UpdateInfo,Persister.UpdateInfo> |
updateCache
Cache of FQL strings, with or without max results and start offsets, to queries.
|
| Constructor and Description |
|---|
Persister(Session session)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) <T extends BaseRecord> |
bulkInsert(java.util.List<T> records)
Insert the data of the given list of DMOs into its corresponding primary table and any
secondary tables in the database.
|
private void |
closePreparedStatements(java.sql.PreparedStatement[] ps)
Close the given prepared statements.
|
(package private) static java.lang.String[] |
composeDeleteStatements(java.lang.String[] tables)
Compose the statements needed to delete a DMO and all of its normalized extent field data.
|
(package private) static java.lang.String[] |
composeInsertStatements(java.lang.String table,
PropertyMeta[] allPropMeta,
boolean temp)
Compose the SQL statements used to insert a single DMO into the database.
|
(package private) boolean |
delete(BaseRecord dmo)
Delete the record(s) associated with the given DMO from the database.
|
(package private) boolean |
delete(java.lang.Class<? extends BaseRecord> dmoClass,
java.lang.Long id)
Delete the record(s) associated with the given DMO from the database.
|
private int |
executeBatch(java.sql.PreparedStatement ps)
Execute a batch of commands using the given prepared statement.
|
(package private) boolean |
getAllowDBUniqueCheck()
Getter for the
allowDBUniqueCheck field. |
static void |
initializeCache()
Initializes the cache using CacheManager.
|
(package private) <T extends BaseRecord> |
insert(T dmo)
Insert the data of the given DMO into its corresponding primary table and any secondary
tables in the database.
|
private <T extends BaseRecord> |
insert(T dmo,
java.sql.PreparedStatement[] preparedStatements,
boolean bulk)
Insert the data of the given DMO into its corresponding primary table and any secondary
tables in the database.
|
private <T extends BaseRecord> |
prepareInsertStatements(T dmo)
Prepare the insert statements for the table(s) associated with the given DMO.
|
(package private) boolean |
setAllowDBUniqueCheck(boolean value)
Setter for the
allowDBUniqueCheck field. |
(package private) <T extends BaseRecord> |
update(T dmo)
Saves changes of the
dmo by executing one or more UPDATE statements. |
private static final CentralLogger LOG
private static ExpiryCache<Persister.UpdateInfo,Persister.UpdateInfo> updateCache
private final Session session
private org.h2.embedded.DirectAccessDriver directAccessDriver
DirectAccessDriver for H2.private boolean allowDBUniqueCheck
Persister(Session session)
session - Active database associated with this persister.public static void initializeCache()
static java.lang.String[] composeInsertStatements(java.lang.String table,
PropertyMeta[] allPropMeta,
boolean temp)
table - SQL name of the primary table. The naming convention assumed for secondary tables
is: <primary_table>__<extent_size>.allPropMeta - Array of PropertyMeta objects in their natural order.temp - Pass true for _temp DMOs. In this case the insert statement
will be build with the mandatory _multiplex field for temp-tables.PropertyMeta.compareTo(PropertyMeta)static java.lang.String[] composeDeleteStatements(java.lang.String[] tables)
tables - Table names for this DMO, primary first.boolean getAllowDBUniqueCheck()
allowDBUniqueCheck field.allowDBUniqueCheck field.boolean setAllowDBUniqueCheck(boolean value)
allowDBUniqueCheck field.value - The value which will be assigned to the allowDBUniqueCheck field.<T extends BaseRecord> int bulkInsert(java.util.List<T> records) throws PersistenceException
This method must be called within a transaction for the data to be preserved. Scalar data is inserted first into the primary table, followed by normalized extent field data, if any, into any secondary tables.
records - List of one or more DMO instances whose data is to be inserted into the database.PersistenceException - if an error occurs accessing the database.<T extends BaseRecord> int insert(T dmo) throws PersistenceException
dmo - DMO instance whose data is to be inserted into the database.PersistenceException - if an error occurs accessing the database.boolean delete(BaseRecord dmo) throws PersistenceException
dmo - DMO whose records are to be deleted.PersistenceException - if there is a database error.boolean delete(java.lang.Class<? extends BaseRecord> dmoClass, java.lang.Long id) throws PersistenceException
dmoClass - DMO implementation class.id - Primary key of record to be deleted.PersistenceException - if there is a database error.<T extends BaseRecord> void update(T dmo) throws PersistenceException
dmo by executing one or more UPDATE statements.T - The type(class) of the Record.dmo - The object whose changes will be flushed to database.PersistenceException - In case of any issue encountered in the process.private <T extends BaseRecord> int insert(T dmo, java.sql.PreparedStatement[] preparedStatements, boolean bulk) throws PersistenceException
dmo - DMO instance whose data is to be inserted into the database.preparedStatements - Array of prepared, insert statements corresponding with dmo's primary
table and any secondary tables for normalized extent fields, in ascending order of
extent.bulk - true if this insert is part of a bulk insert; false if it
represents the insert of a single record. If the former, the caller is responsible
for executing the batches of statements this method prepares; if the latter, this
method will execute the batch of statements directly.PersistenceException - if an error occurs accessing the database.private <T extends BaseRecord> java.sql.PreparedStatement[] prepareInsertStatements(T dmo) throws PersistenceException
dmo - Data model object whose type is used to determine the insert statements to be
prepared.PersistenceException - if there is an error preparing the statements.private void closePreparedStatements(java.sql.PreparedStatement[] ps)
throws PersistenceException
ps - Array of prepared statements to close.PersistenceException - if there is an error closing the prepared statements.private int executeBatch(java.sql.PreparedStatement ps)
throws java.sql.SQLException
ps - Prepared statement.java.sql.SQLException - if a database error occurs.