Package com.logicaldoc.core
Class HibernatePersistentObjectDAO<T extends PersistentObject>
java.lang.Object
com.logicaldoc.core.HibernatePersistentObjectDAO<T>
- All Implemented Interfaces:
PersistentObjectDAO<T>
- Direct Known Subclasses:
HibernateAttributeOptionDAO
,HibernateAttributeSetDAO
,HibernateBookmarkDAO
,HibernateContactDAO
,HibernateDashletDAO
,HibernateDeviceDAO
,HibernateDocumentDAO
,HibernateDocumentHistoryDAO
,HibernateDocumentLinkDAO
,HibernateDocumentNoteDAO
,HibernateFolderDAO
,HibernateFolderHistoryDAO
,HibernateGenericDAO
,HibernateGroupDAO
,HibernateMenuDAO
,HibernateMessageTemplateDAO
,HibernatePasswordHistoryDAO
,HibernateRatingDAO
,HibernateSearchDAO
,HibernateSequenceDAO
,HibernateSessionDAO
,HibernateSystemMessageDAO
,HibernateTemplateDAO
,HibernateTenantDAO
,HibernateTicketDAO
,HibernateUserDAO
,HibernateUserHistoryDAO
,HibernateVersionDAO
,HibernateWebserviceCallDAO
public abstract class HibernatePersistentObjectDAO<T extends PersistentObject>
extends Object
implements PersistentObjectDAO<T>
Hibernate implementation of
PersistentObjectDAO
- Since:
- 4.0
- Author:
- Marco Meschieri - LogicalDOC
-
Field Summary
Fields inherited from interface com.logicaldoc.core.PersistentObjectDAO
ENTITY
-
Method Summary
Modifier and TypeMethodDescriptionint
bulkUpdate
(String expression, Map<String, Object> parameters) Executes a bulk update as specified by the given expressionvoid
delete
(long id) This method deletes an entity.void
delete
(long id, int code) This method deletes an entity and you can give a deletion codevoid
deleteAll
(Collection<T> entities) Deletes all entries form the databasevoid
deleteAll
(Collection<T> entities, int code) Deletes all entries form the database giving a specific deletion codefindAll()
Finds all entities in the databasefindAll
(long tenantId) Finds all entities in a specific tenant.Finds all entities idsfindAllIds
(long tenantId) Finds all entities ids in a specific tenant.findById
(long id) This method finds an entity by IDfindById
(long id, boolean initialize) This method finds an entity by IDFinds all entities by the given object query.Find everything you want from the DB using the ORM query languagefindByWhere
(String where, String order, Integer max) Finds all entities by the given expression.Finds all entities by the given expression.findIdsByWhere
(String where, String order, Integer max) Finds all entities ids by the given expression.Finds all entities ids by the given expression.Retrieves the metadata from the databasegetDbms()
Get the DBMS name currently connected(possible values are: mysql, mariadb, postgresql, hsqldb, oracle, mssql)org.hibernate.SessionFactory
void
initialize
(T entity) Doesn't do anything by defaultboolean
isOracle()
int
jdbcUpdate
(String statement) Executes the given SQL update statementint
jdbcUpdate
(String statement, Map<String, Object> parameters) Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given argumentsquery
(String sql, Map<String, Object> parameters, org.springframework.jdbc.core.RowMapper rowMapper, Integer maxRows) Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.double
queryForDouble
(String sql) Execute a query that results in a double value, given static SQL.double
queryForDouble
(String sql, Map<String, Object> parameters) Execute a query that results in a double value, given static SQL.int
queryForInt
(String sql) Execute a query that results in an int value, given static SQL.queryForList
(String sql, Class elementType) Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.queryForList
(String sql, Class elementType, Integer maxRows) Execute a query for a result list, given static SQL.Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.long
queryForLong
(String sql) Execute a query that results in an long value, given static SQL.long
queryForLong
(String sql, Map<String, Object> parameters) Execute a query that results in an long value, given static SQL.queryForObject
(String sql, Class type) Execute a query that results in a Object value, given static SQL.org.springframework.jdbc.support.rowset.SqlRowSet
queryForRowSet
(String sql, Integer maxRows) Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, returns a navigable RowSetorg.springframework.jdbc.support.rowset.SqlRowSet
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, returns a navigable RowSetqueryForString
(String sql) Execute a query that results in an string value, given static SQL.void
setSessionFactory
(org.hibernate.SessionFactory sessionFactory) void
This method persists the entity object
-
Method Details
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory) -
delete
Description copied from interface:PersistentObjectDAO
This method deletes an entity and you can give a deletion code- Specified by:
delete
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
id
- ID of the entity which should be deletedcode
- Deletion code- Throws:
PersistenceException
- raised in case of errors in the database
-
delete
Description copied from interface:PersistentObjectDAO
This method deletes an entity. Same as delete(id, 1)- Specified by:
delete
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
id
- ID of the entity which should be deleted.- Throws:
PersistenceException
- raised in case of errors in the database
-
findAll
Description copied from interface:PersistentObjectDAO
Finds all entities in the database- Specified by:
findAll
in interfacePersistentObjectDAO<T extends PersistentObject>
- Returns:
- The list of all entities
-
findAll
Description copied from interface:PersistentObjectDAO
Finds all entities in a specific tenant.- Specified by:
findAll
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
tenantId
- Identifier of the tenant to search in- Returns:
- The list of all entities
-
findAllIds
Description copied from interface:PersistentObjectDAO
Finds all entities ids- Specified by:
findAllIds
in interfacePersistentObjectDAO<T extends PersistentObject>
- Returns:
- The list of all entities ids
-
findAllIds
Description copied from interface:PersistentObjectDAO
Finds all entities ids in a specific tenant.- Specified by:
findAllIds
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
tenantId
- Identifier of the tenant to search in- Returns:
- The list of all entities ids
-
findById
Description copied from interface:PersistentObjectDAO
This method finds an entity by ID- Specified by:
findById
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
id
- ID of the entityinitialize
- True if the instance's lazy collections have to be initialized- Returns:
- Entity with given ID
- Throws:
PersistenceException
- raised in case of errors in the database
-
findById
Description copied from interface:PersistentObjectDAO
This method finds an entity by ID- Specified by:
findById
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
id
- ID of the entity- Returns:
- Entity with given ID
- Throws:
PersistenceException
- raised in case of errors in the database
-
findByWhere
Description copied from interface:PersistentObjectDAO
Finds all entities by the given expression. Use "_entity" alias to reference attributes in the where expression.- Specified by:
findByWhere
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
where
- The where clause expressionorder
- The order clause expressionmax
- Maximum results number (optional)- Returns:
- The list of marching entities
- Throws:
PersistenceException
- raised in case of errors in the database
-
findByWhere
public List<T> findByWhere(String where, Map<String, Object> parameters, String order, Integer max) throws PersistenceExceptionDescription copied from interface:PersistentObjectDAO
Finds all entities by the given expression. Use "_entity" alias to reference attributes in the where expression.- Specified by:
findByWhere
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
where
- The where clause expressionparameters
- Parameters used in the where expressionorder
- The order clause expressionmax
- Maximum results number (optional)- Returns:
- The list of marching entities
- Throws:
PersistenceException
- raised in case of errors in the database
-
findByObjectQuery
public List<T> findByObjectQuery(String query, Map<String, Object> parameters, Integer max) throws PersistenceExceptionDescription copied from interface:PersistentObjectDAO
Finds all entities by the given object query.- Specified by:
findByObjectQuery
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
query
- The query expressionparameters
- Parameters used in the where expressionmax
- Maximum results number (optional)- Returns:
- The list of matching entities
- Throws:
PersistenceException
- raised in case of errors in the database
-
findByQuery
public List findByQuery(String query, Map<String, Object> parameters, Integer max) throws PersistenceExceptionDescription copied from interface:PersistentObjectDAO
Find everything you want from the DB using the ORM query language- Specified by:
findByQuery
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
query
- The query to executeparameters
- The map of the parametersmax
- Maximum results number (optional)- Returns:
- Query result
- Throws:
PersistenceException
- raised in case of errors in the database
-
findIdsByWhere
public List<Long> findIdsByWhere(String where, String order, Integer max) throws PersistenceException Description copied from interface:PersistentObjectDAO
Finds all entities ids by the given expression. Use "_entity" alias to reference attributes in the where expression.- Specified by:
findIdsByWhere
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
where
- The where clause expressionorder
- The order clause expressionmax
- Maximum results number (optional)- Returns:
- The list of marching entities ids
- Throws:
PersistenceException
- raised in case of errors in the database
-
findIdsByWhere
public List<Long> findIdsByWhere(String where, Map<String, Object> parameters, String order, Integer max) throws PersistenceExceptionDescription copied from interface:PersistentObjectDAO
Finds all entities ids by the given expression. Use "_entity" alias to reference attributes in the where expression.- Specified by:
findIdsByWhere
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
where
- The where clause expression (for parameters, please use JPA-style: :paramA, :paramB ...)parameters
- The map of the parametersorder
- The order clause expressionmax
- Maximum results number (optional)- Returns:
- The list of marching entities ids
- Throws:
PersistenceException
- raised in case of errors in the database
-
store
Description copied from interface:PersistentObjectDAO
This method persists the entity object- Specified by:
store
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
entity
- entity to be stored- Throws:
PersistenceException
- raised in case of errors in the database
-
initialize
Doesn't do anything by default- Specified by:
initialize
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
entity
- The entity to be initialised
-
query
public List query(String sql, org.springframework.jdbc.core.RowMapper rowMapper, Integer maxRows) throws PersistenceException Description copied from interface:PersistentObjectDAO
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.- Specified by:
query
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to executerowMapper
- object that will map one object per rowmaxRows
- the new max rows limit; null means there is no limit- Returns:
- the result List, containing mapped objects
- Throws:
PersistenceException
- raised in case of errors in the database
-
query
public List query(String sql, Map<String, Object> parameters, org.springframework.jdbc.core.RowMapper rowMapper, Integer maxRows) throws PersistenceExceptionDescription copied from interface:PersistentObjectDAO
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.- Specified by:
query
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute (for parameters please use JPA-style: :paramA, :paramB ...)parameters
- Parameters used in the where expression (map name-value)rowMapper
- object that will map one object per rowmaxRows
- the new max rows limit; null means there is no limit- Returns:
- the result List, containing mapped objects
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForList
Description copied from interface:PersistentObjectDAO
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list. The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.- Specified by:
queryForList
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to executeelementType
- the required type of element in the result list (for example, Integer.class)- Returns:
- a List of objects that match the specified element type
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForList
public List queryForList(String sql, Class elementType, Integer maxRows) throws PersistenceException Description copied from interface:PersistentObjectDAO
Execute a query for a result list, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForList method with null as argument array. The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.- Specified by:
queryForList
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to executeelementType
- the required type of element in the result list (for example, Integer.class)maxRows
- maximum number of returned records- Returns:
- a List of objects that match the specified element type
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForList
public List queryForList(String sql, Map<String, Object> prameters, Class elementType, Integer maxRows) throws PersistenceExceptionDescription copied from interface:PersistentObjectDAO
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list. The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.- Specified by:
queryForList
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute (for parameters please use JPA-style: :paramA, :paramB ...)prameters
- Parameters used in the where expression (map name-value)elementType
- the required type of element in the result list (for example, Integer.class)maxRows
- maximum number of returned records- Returns:
- a List of objects that match the specified element type
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForRowSet
public org.springframework.jdbc.support.rowset.SqlRowSet queryForRowSet(String sql, Integer maxRows) throws PersistenceException Description copied from interface:PersistentObjectDAO
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, returns a navigable RowSet- Specified by:
queryForRowSet
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to executemaxRows
- the new max rows limit; null means there is no limit- Returns:
- the result row set
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForRowSet
public org.springframework.jdbc.support.rowset.SqlRowSet queryForRowSet(String sql, Map<String, Object> parameters, Integer maxRows) throws PersistenceExceptionDescription copied from interface:PersistentObjectDAO
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, returns a navigable RowSet- Specified by:
queryForRowSet
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute (for parameters please use JPA-style: :paramA, :paramB ...)parameters
- Parameters used in the where expression (map name-value)maxRows
- the new max rows limit; null means there is no limit- Returns:
- the result row set
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForInt
Description copied from interface:PersistentObjectDAO
Execute a query that results in an int value, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForInt method with null as argument array. This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in an int value.- Specified by:
queryForInt
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute- Returns:
- the int value, or 0 in case of SQL NULL
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForLong
Description copied from interface:PersistentObjectDAO
Execute a query that results in an long value, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForInt method with null as argument array. This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.- Specified by:
queryForLong
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute- Returns:
- the long value, or 0 in case of SQL NULL
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForLong
Description copied from interface:PersistentObjectDAO
Execute a query that results in an long value, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForInt method with null as argument array. This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.- Specified by:
queryForLong
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute (for parameters please use JPA-style: :paramA, :paramB ...)parameters
- Parameters used in the where expression (map name-value)- Returns:
- the long value, or 0 in case of SQL NULL
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForDouble
Description copied from interface:PersistentObjectDAO
Execute a query that results in a double value, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForInt method with null as argument array. This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.- Specified by:
queryForDouble
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute- Returns:
- the double value, or 0 in case of SQL NULL
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForDouble
Description copied from interface:PersistentObjectDAO
Execute a query that results in a double value, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForInt method with null as argument array. This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a long value.- Specified by:
queryForDouble
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute (for parameters please use JPA-style: :paramA, :paramB ...)parameters
- Parameters used in the where expression (map name-value)- Returns:
- the double value, or 0 in case of SQL NULL
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForString
Description copied from interface:PersistentObjectDAO
Execute a query that results in an string value, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForInt method with null as argument array. This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a string value.- Specified by:
queryForString
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to execute- Returns:
- the string value
- Throws:
PersistenceException
- raised in case of errors in the database
-
queryForObject
Description copied from interface:PersistentObjectDAO
Execute a query that results in a Object value, given static SQL. Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement. This method is useful for running static SQL with a known outcome. The query is expected to be a single row/single column query that results in a object value.- Specified by:
queryForObject
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
sql
- SQL query to executetype
- The type of the returned value- Returns:
- the object value
- Throws:
PersistenceException
- raised in case of errors in the database
-
jdbcUpdate
Description copied from interface:PersistentObjectDAO
Executes the given SQL update statement- Specified by:
jdbcUpdate
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
statement
- the SQL statement to execute against the database- Returns:
- the value returned by the database after execution
- Throws:
PersistenceException
- raised in case of errors in the database
-
deleteAll
Description copied from interface:PersistentObjectDAO
Deletes all entries form the database giving a specific deletion code- Specified by:
deleteAll
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
entities
- The entities to be deletedcode
- The deletion code- Throws:
PersistenceException
- raised in case of errors in the database
-
deleteAll
Description copied from interface:PersistentObjectDAO
Deletes all entries form the database- Specified by:
deleteAll
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
entities
- The entities to be deleted- Throws:
PersistenceException
- raised in case of errors in the database
-
bulkUpdate
Description copied from interface:PersistentObjectDAO
Executes a bulk update as specified by the given expression- Specified by:
bulkUpdate
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
expression
- The update expression.parameters
- Optional map of parameters- Returns:
- the number of modified records
- Throws:
PersistenceException
- raised in case of errors in the database
-
jdbcUpdate
Description copied from interface:PersistentObjectDAO
Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments- Specified by:
jdbcUpdate
in interfacePersistentObjectDAO<T extends PersistentObject>
- Parameters:
statement
- SQL statement to execute (for parameters please use JPA-style: :paramA, :paramB ...)parameters
- Parameters used in the where expression (map name-value)- Returns:
- the number of rows affected
- Throws:
PersistenceException
- raised in case of errors in the database
-
getDbms
Description copied from interface:PersistentObjectDAO
Get the DBMS name currently connected(possible values are: mysql, mariadb, postgresql, hsqldb, oracle, mssql)- Specified by:
getDbms
in interfacePersistentObjectDAO<T extends PersistentObject>
- Returns:
- the database identifier
-
isOracle
public boolean isOracle()- Specified by:
isOracle
in interfacePersistentObjectDAO<T extends PersistentObject>
-
getSessionFactory
public org.hibernate.SessionFactory getSessionFactory() -
getDatabaseMetadata
Description copied from interface:PersistentObjectDAO
Retrieves the metadata from the database- Specified by:
getDatabaseMetadata
in interfacePersistentObjectDAO<T extends PersistentObject>
- Returns:
- a map of metadata from the database driver
-