public abstract class HibernatePersistentObjectDAO<T extends PersistentObject> extends Object implements PersistentObjectDAO<T>
PersistentObjectDAO
Modifier and Type | Field and Description |
---|---|
protected Class<T> |
entityClass |
protected org.slf4j.Logger |
log |
protected org.hibernate.SessionFactory |
sessionFactory |
Modifier | Constructor and Description |
---|---|
protected |
HibernatePersistentObjectDAO(Class<T> entityClass) |
Modifier and Type | Method and Description |
---|---|
int |
bulkUpdate(String expression,
Object[] values)
Executes a bulk update as specified by the given expression
|
boolean |
delete(long id)
This method deletes an entity.
|
void |
deleteAll(Collection<T> entities)
Deletes all entries form the database
|
protected void |
evict(Object entity) |
List<T> |
findAll()
Finds all entities in the database
|
List<Long> |
findAllIds()
Finds all entities ids
|
T |
findById(long id)
This method finds an entity by ID.
|
List |
findByQuery(String query,
Object[] values,
Integer max)
Find everything you want from the DB using the ORM query language
|
List<T> |
findByWhere(String where,
Object[] values,
String order,
Integer max)
Finds all entities by the given expression.
|
List<T> |
findByWhere(String where,
String order,
Integer max)
Finds all entities by the given expression.
|
List<Long> |
findIdsByWhere(String where,
Object[] values,
String order,
Integer max)
Finds all entities ids by the given expression.
|
List<Long> |
findIdsByWhere(String where,
String order,
Integer max)
Finds all entities ids by the given expression.
|
protected void |
flush() |
protected Connection |
getConnection() |
protected org.hibernate.Session |
getCurrentSession() |
String |
getDbms()
Get the DBMS currently connected( possible values are: mysql, hsqldb, oracle, mssql)
|
org.hibernate.SessionFactory |
getSessionFactory() |
void |
initialize(T entity)
Doesn't do anything by default
|
protected boolean |
isHsql() |
protected boolean |
isMySQL() |
protected boolean |
isOracle() |
protected boolean |
isSqlServer() |
int |
jdbcUpdate(String statement)
Executes the given SQL update statement
|
int |
jdbcUpdate(String statement,
Object... args)
Issue a single SQL update operation (such as an insert, update or delete
statement) via a prepared statement, binding the given arguments.
|
protected Object |
merge(Object entity) |
protected org.hibernate.Query |
prepareQuery(String expression,
Object[] values,
Integer max)
Utility method useful for preparing an Hibernate query
|
List |
query(String sql,
Object[] args,
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.
|
int |
queryForInt(String sql)
Execute a query that results in an int value, given static SQL.
|
List |
queryForList(String sql,
Class elementType)
Execute a query for a result list, given static SQL.
|
List |
queryForList(String sql,
Object[] args,
Class elementType,
Integer maxRows)
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.
|
org.springframework.jdbc.support.rowset.SqlRowSet |
queryForRowSet(String sql,
Object[] args,
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 RowSet
|
protected void |
refresh(Object entity) |
protected void |
saveOrUpdate(Object entity) |
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory) |
boolean |
store(T entity)
This method persists the entity object.
|
protected org.slf4j.Logger log
protected Class<T extends PersistentObject> entityClass
protected org.hibernate.SessionFactory sessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
public boolean delete(long id)
PersistentObjectDAO
delete
in interface PersistentObjectDAO<T extends PersistentObject>
id
- ID of the entity which should be deleted.public List<T> findAll()
PersistentObjectDAO
findAll
in interface PersistentObjectDAO<T extends PersistentObject>
public List<Long> findAllIds()
PersistentObjectDAO
findAllIds
in interface PersistentObjectDAO<T extends PersistentObject>
public T findById(long id)
PersistentObjectDAO
findById
in interface PersistentObjectDAO<T extends PersistentObject>
public List<T> findByWhere(String where, String order, Integer max)
PersistentObjectDAO
findByWhere
in interface PersistentObjectDAO<T extends PersistentObject>
where
- The where clause expressionorder
- The order clause expressionmax
- Maximum results number (optional)public List<T> findByWhere(String where, Object[] values, String order, Integer max)
PersistentObjectDAO
findByWhere
in interface PersistentObjectDAO<T extends PersistentObject>
where
- The where clause expression (for positional parameters, please use JPA-style: ?1, ?2 ...)values
- Parameters used in the where expressionorder
- The order clause expressionmax
- Maximum results number (optional)public List findByQuery(String query, Object[] values, Integer max)
PersistentObjectDAO
findByQuery
in interface PersistentObjectDAO<T extends PersistentObject>
query
- The query to execute (for positional parameters, please use JPA-style: ?1, ?2 ...)values
- Array of paramatersmax
- Maximum results number (optional)public List<Long> findIdsByWhere(String where, String order, Integer max)
PersistentObjectDAO
findIdsByWhere
in interface PersistentObjectDAO<T extends PersistentObject>
where
- The where clause expressionorder
- The order clause expressionmax
- Maximum results number (optional)public List<Long> findIdsByWhere(String where, Object[] values, String order, Integer max)
PersistentObjectDAO
findIdsByWhere
in interface PersistentObjectDAO<T extends PersistentObject>
where
- The where clause expression (for positional parameters, please use JPA-style: ?1, ?2 ...)values
- Parameters used in the where expressionorder
- The order clause expressionmax
- Maximum results number (optional)public boolean store(T entity)
PersistentObjectDAO
store
in interface PersistentObjectDAO<T extends PersistentObject>
entity
- entity to be stored.protected void saveOrUpdate(Object entity)
protected void flush()
protected void refresh(Object entity)
protected void evict(Object entity)
protected org.hibernate.Query prepareQuery(String expression, Object[] values, Integer max)
expression
- The expression for the queryvalues
- The parameters values to be used (optional, if the query is
parametric)max
- Optional maximum number of wanted resultspublic void initialize(T entity)
initialize
in interface PersistentObjectDAO<T extends PersistentObject>
entity
- The entity to be initialisedprotected org.hibernate.Session getCurrentSession()
public List query(String sql, Object[] args, org.springframework.jdbc.core.RowMapper rowMapper, Integer maxRows)
PersistentObjectDAO
query
in interface PersistentObjectDAO<T extends PersistentObject>
sql
- SQL query to executeargs
- arguments to bind to the query (leaving it to the
PreparedStatement to guess the corresponding SQL type); may also
contain SqlParameterValue objects which indicate not only the
argument value but also the SQL type and optionally the scalerowMapper
- object that will map one object per rowmaxRows
- the new max rows limit; null means there is no limitpublic List queryForList(String sql, Object[] args, Class elementType, Integer maxRows)
PersistentObjectDAO
queryForList
in interface PersistentObjectDAO<T extends PersistentObject>
sql
- SQL query to executeargs
- arguments to bind to the query (leaving it to the
PreparedStatement to guess the corresponding SQL type); may also
contain SqlParameterValue objects which indicate not only the
argument value but also the SQL type and optionally the scaleelementType
- the required type of element in the result list (for
example, Integer.class)public org.springframework.jdbc.support.rowset.SqlRowSet queryForRowSet(String sql, Object[] args, Integer maxRows)
PersistentObjectDAO
queryForRowSet
in interface PersistentObjectDAO<T extends PersistentObject>
sql
- SQL query to executeargs
- arguments to bind to the query (leaving it to the
PreparedStatement to guess the corresponding SQL type); may also
contain SqlParameterValue objects which indicate not only the
argument value but also the SQL type and optionally the scalemaxRows
- the new max rows limit; null means there is no limitpublic List queryForList(String sql, Class elementType)
PersistentObjectDAO
queryForList
in interface PersistentObjectDAO<T extends PersistentObject>
sql
- SQL query to executeelementType
- the required type of element in the result list (for
example, Integer.class)public int queryForInt(String sql)
PersistentObjectDAO
queryForInt
in interface PersistentObjectDAO<T extends PersistentObject>
sql
- SQL query to executepublic long queryForLong(String sql)
PersistentObjectDAO
queryForLong
in interface PersistentObjectDAO<T extends PersistentObject>
sql
- SQL query to executepublic int jdbcUpdate(String statement)
PersistentObjectDAO
jdbcUpdate
in interface PersistentObjectDAO<T extends PersistentObject>
public void deleteAll(Collection<T> entities)
PersistentObjectDAO
deleteAll
in interface PersistentObjectDAO<T extends PersistentObject>
entities
- The entities to be deletedpublic int bulkUpdate(String expression, Object[] values)
PersistentObjectDAO
bulkUpdate
in interface PersistentObjectDAO<T extends PersistentObject>
public int jdbcUpdate(String statement, Object... args)
PersistentObjectDAO
jdbcUpdate
in interface PersistentObjectDAO<T extends PersistentObject>
statement
- SQL containing bind parametersargs
- arguments to bind to the query (leaving it to the
PreparedStatement to guess the corresponding SQL type); may also
contain SqlParameterValue objects which indicate not only the
argument value but also the SQL type and optionally the scaleprotected Connection getConnection() throws SQLException
SQLException
public String getDbms()
PersistentObjectDAO
getDbms
in interface PersistentObjectDAO<T extends PersistentObject>
protected boolean isHsql()
protected boolean isMySQL()
protected boolean isOracle()
protected boolean isSqlServer()
public org.hibernate.SessionFactory getSessionFactory()
Copyright © 2008-2014 Logical Objects. All Rights Reserved.