Class PersistenceManager<T>
java.lang.Object
org.eclipse.dirigible.database.persistence.PersistenceManager<T>
- Type Parameters:
T- the entity type
public class PersistenceManager<T> extends Object
PersistenceManager is a simple transport mechanism to store and retrieve
POJO object to/from underlying JDBC compliant database.
It reads a limited set of the standard JPA annotations from the POJO, such as Table, Id, Column, etc.
and generate a dialect dependent SQL script.
It works on flat POJOs and no lazy loading, associations, caches, etc. are supported.
It is the simplest possible persistence channel for POJOs and will stay at this level in the future
The POJO supported by this manager must have a single mandatory Id (PRIMARY KEY) field
-
Constructor Summary
Constructors Constructor Description PersistenceManager() -
Method Summary
Modifier and Type Method Description intdelete(Connection connection, Class<T> clazz, Object id)Delete a single record representing a single POJO instance.intexecute(Connection connection, String sql, Object... values)Custom update statement.intexecute(Connection connection, String sql, List<Object> values)Custom update statement.Tfind(Connection connection, Class<T> clazz, Object id)Getter for the single POJO instance.List<T>findAll(Connection connection, Class<T> clazz)Getter for all the POJO instances.IEntityManagerInterceptorgetEntityManagerInterceptor()Gets the entity manager interceptor.Objectinsert(Connection connection, T pojo)Insert a single record in the table representing the POJO instance.Tlock(Connection connection, Class<T> clazz, Object id)Getter for the single POJO instance and locks it for update.List<T>query(Connection connection, Class<T> clazz, String sql, Object... values)Custom query for narrow the search.List<T>query(Connection connection, Class<T> clazz, String sql, List<Object> values)Custom query for narrow the search.voidreset()Clean up the existing tables cache.voidreset(Connection connection, Class<T> clazz)voidsetEntityManagerInterceptor(IEntityManagerInterceptor entityManagerInterceptor)Sets the entity manager interceptor.voidtableCheck(Connection connection, Class clazz)Check whether the table already exists in the database and create it if needed.inttableCreate(Connection connection, Class<T> clazz)Create a table by a provided Class.inttableDrop(Connection connection, Class<T> clazz)Drop a table by a provided Class.booleantableExists(Connection connection, Class<T> clazz)Check whether a table by a provided Class already exists.intupdate(Connection connection, T pojo)Update.
-
Constructor Details
-
PersistenceManager
public PersistenceManager()
-
-
Method Details
-
tableCreate
Create a table by a provided Class.- Parameters:
connection- the database connectionclazz- the POJO's Class- Returns:
- the result status of the create statement execution
-
tableDrop
Drop a table by a provided Class.- Parameters:
connection- the database connectionclazz- the POJO's Class- Returns:
- the result status of the drop statement execution
-
tableExists
Check whether a table by a provided Class already exists.- Parameters:
connection- the database connectionclazz- the POJO's Class- Returns:
- true if exists and false otherwise
-
tableCheck
Check whether the table already exists in the database and create it if needed.- Parameters:
connection- the database connectionclazz- the clazz
-
reset
public void reset()Clean up the existing tables cache. -
reset
-
insert
Insert a single record in the table representing the POJO instance.- Parameters:
connection- the database connectionpojo- the POJO instance- Returns:
- the id of the pojo just inserted
-
find
Getter for the single POJO instance.- Parameters:
connection- the database connectionclazz- the POJO's Classid- the primary key field's value- Returns:
- a POJO instance
-
lock
Getter for the single POJO instance and locks it for update.- Parameters:
connection- the database connectionclazz- the POJO's Classid- the primary key field's value- Returns:
- a POJO instance
-
findAll
Getter for all the POJO instances.- Parameters:
connection- the database connectionclazz- the POJO's Class- Returns:
- a list with the POJO instances
-
query
Custom query for narrow the search.- Parameters:
connection- the database connectionclazz- the POJO's Classsql- the custom SQL scriptvalues- ordered parameters values- Returns:
- a list with the POJO instances
-
query
Custom query for narrow the search.- Parameters:
connection- the database connectionclazz- the POJO's Classsql- the custom SQL scriptvalues- ordered parameters values- Returns:
- a list with the POJO instances
-
execute
Custom update statement.- Parameters:
connection- the database connectionsql- the custom SQL scriptvalues- ordered parameters values- Returns:
- a list with the POJO instances
-
execute
Custom update statement.- Parameters:
connection- the database connectionsql- the custom SQL scriptvalues- ordered parameters values- Returns:
- a list with the POJO instances
-
delete
Delete a single record representing a single POJO instance.- Parameters:
connection- the database connectionclazz- the POJO's Classid- the primary key field's value- Returns:
- the result status of the delete statement execution
-
update
Update.- Parameters:
connection- the database connectionpojo- the POJO instance- Returns:
- the result status of the update statement execution
-
getEntityManagerInterceptor
Gets the entity manager interceptor.- Returns:
- the entity manager interceptor
-
setEntityManagerInterceptor
Sets the entity manager interceptor.- Parameters:
entityManagerInterceptor- the new entity manager interceptor
-