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 Details

  • Method Details

    • tableCreate

      public int tableCreate​(Connection connection, Class<T> clazz)
      Create a table by a provided Class.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      Returns:
      the result status of the create statement execution
    • tableDrop

      public int tableDrop​(Connection connection, Class<T> clazz)
      Drop a table by a provided Class.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      Returns:
      the result status of the drop statement execution
    • tableExists

      public boolean tableExists​(Connection connection, Class<T> clazz)
      Check whether a table by a provided Class already exists.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      Returns:
      true if exists and false otherwise
    • tableCheck

      public void tableCheck​(Connection connection, Class clazz)
      Check whether the table already exists in the database and create it if needed.
      Parameters:
      connection - the database connection
      clazz - the clazz
    • reset

      public void reset()
      Clean up the existing tables cache.
    • reset

      public void reset​(Connection connection, Class<T> clazz)
    • insert

      public Object insert​(Connection connection, T pojo)
      Insert a single record in the table representing the POJO instance.
      Parameters:
      connection - the database connection
      pojo - the POJO instance
      Returns:
      the id of the pojo just inserted
    • find

      public T find​(Connection connection, Class<T> clazz, Object id)
      Getter for the single POJO instance.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      id - the primary key field's value
      Returns:
      a POJO instance
    • lock

      public T lock​(Connection connection, Class<T> clazz, Object id)
      Getter for the single POJO instance and locks it for update.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      id - the primary key field's value
      Returns:
      a POJO instance
    • findAll

      public List<T> findAll​(Connection connection, Class<T> clazz)
      Getter for all the POJO instances.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      Returns:
      a list with the POJO instances
    • query

      public List<T> query​(Connection connection, Class<T> clazz, String sql, List<Object> values)
      Custom query for narrow the search.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      sql - the custom SQL script
      values - ordered parameters values
      Returns:
      a list with the POJO instances
    • query

      public List<T> query​(Connection connection, Class<T> clazz, String sql, Object... values)
      Custom query for narrow the search.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      sql - the custom SQL script
      values - ordered parameters values
      Returns:
      a list with the POJO instances
    • execute

      public int execute​(Connection connection, String sql, List<Object> values)
      Custom update statement.
      Parameters:
      connection - the database connection
      sql - the custom SQL script
      values - ordered parameters values
      Returns:
      a list with the POJO instances
    • execute

      public int execute​(Connection connection, String sql, Object... values)
      Custom update statement.
      Parameters:
      connection - the database connection
      sql - the custom SQL script
      values - ordered parameters values
      Returns:
      a list with the POJO instances
    • delete

      public int delete​(Connection connection, Class<T> clazz, Object id)
      Delete a single record representing a single POJO instance.
      Parameters:
      connection - the database connection
      clazz - the POJO's Class
      id - the primary key field's value
      Returns:
      the result status of the delete statement execution
    • update

      public int update​(Connection connection, T pojo)
      Update.
      Parameters:
      connection - the database connection
      pojo - the POJO instance
      Returns:
      the result status of the update statement execution
    • getEntityManagerInterceptor

      public IEntityManagerInterceptor getEntityManagerInterceptor()
      Gets the entity manager interceptor.
      Returns:
      the entity manager interceptor
    • setEntityManagerInterceptor

      public void setEntityManagerInterceptor​(IEntityManagerInterceptor entityManagerInterceptor)
      Sets the entity manager interceptor.
      Parameters:
      entityManagerInterceptor - the new entity manager interceptor