public abstract class SessionTemplate extends Object implements AutoCloseable
| Modifier and Type | Field and Description |
|---|---|
protected org.hibernate.Session |
session |
| Modifier | Constructor and Description |
|---|---|
protected |
SessionTemplate() |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
<T> long |
count(Class<T> cls)
Returns count of datasets for given class
|
<T> org.hibernate.Criteria |
createCriteria(Class<T> persistentClass)
Returns criteria associated with this session for given class
|
org.hibernate.Query |
createQuery(String stmt)
Create query
|
org.hibernate.SQLQuery |
createSQLQuery(String stmt)
Create SQL query
|
org.hibernate.StatelessSession |
createStatelessSession()
Creates a new
StatelessSession instance |
void |
delete(Object obj)
Calls
Session.delete(Object) |
void |
evict(Object obj)
Evict
|
<T> Collection<T> |
executeHQLQuery(String query) |
<T> Collection<T> |
executeHQLQuery(String query,
int maxResults) |
<T> T |
executeHQLQueryUniqueResult(String query) |
<T> Collection<T> |
executeNamedQuery(String query) |
<T> Collection<T> |
executeNamedQuery(String query,
int maxResults) |
<T> T |
executeNamedQueryUniqueResult(String query) |
<T> Collection<T> |
executeQuery(org.hibernate.Criteria crit)
Executes given
Criteria |
<T> Collection<T> |
executeQuery(org.hibernate.Criteria crit,
int maxResults)
Executes given
Criteria |
<T> Collection<T> |
executeQuery(org.hibernate.Criteria crit,
int maxResults,
boolean chacheable)
Executes given Criteria
|
<T> Collection<T> |
executeQuery(org.hibernate.Query q)
Executes given
Query |
<T> Collection<T> |
executeQuery(org.hibernate.Query q,
int maxResults)
Executes given
Query |
<T> Collection<T> |
executeQuery(org.hibernate.Query q,
int maxResults,
boolean chacheable)
Executes given Query
|
<T> T |
executeQueryUniqueResult(org.hibernate.Criteria q) |
<T> T |
executeQueryUniqueResult(org.hibernate.Criteria crit,
boolean chacheable) |
<T> T |
executeQueryUniqueResult(org.hibernate.Query q) |
<T> T |
executeQueryUniqueResult(org.hibernate.Query q,
boolean chacheable) |
<T> Collection<T> |
executeSQLQuery(String query) |
<T> Collection<T> |
executeSQLQuery(String query,
int maxResults) |
<T> T |
executeSQLQueryUniqueResult(String query) |
int |
executeUpdate(org.hibernate.Query q)
Executes Update Statement
|
static <T> Collection<T> |
filterNull(Collection<T> input) |
void |
flush()
Flush
|
<T> Collection<T> |
getAll(Class<T> entityClass)
Returns all instances of given class.
|
<T> Collection<T> |
getAll(Class<T> entityClass,
int maxResults)
Returns maxResults instances of given class
|
protected abstract IHibernateConfig |
getHibernateConfig() |
<T> T |
getObjectForPK(Class<T> cls,
Serializable id)
Get the pojo object for the given Pojo Class and identifier
|
<T,K> Collection<T> |
getObjectsForPK(Class<T> cls,
Collection<K> ids)
get Objects for primary key
|
protected org.hibernate.Session |
getSession()
returns low level Hibernate
Session |
org.hibernate.SessionFactory |
getSessionFactory()
Returns active Session Factory
|
boolean |
isOpen()
Check if the Session is still opened
|
<T> Iterator<T> |
iterator(org.hibernate.Criteria crit,
boolean stateless)
Scroll over the query results with a iterator
|
<T> Iterator<T> |
iterator(org.hibernate.Query q,
boolean stateless)
Scroll over the query results with a iterator
|
<T> T |
merge(T obj)
Calls
Session.merge(Object) |
void |
persist(Object obj)
Calls
Session.delete(Object) |
static String[][] |
printOpenSessionInfo()
Returns information for open sessions
|
void |
refresh(Object obj)
Calls
Session.refresh(Object) |
protected void |
rollback()
Rollback a Transaction
|
void |
save(Object obj)
Calls
Session.save(Object) |
void |
saveOrUpdate(Object obj)
Calls
Session.saveOrUpdate(Object) |
<T> Iterable<T> |
scroll(org.hibernate.Criteria crit)
Scroll over the query results
|
<T> Iterable<T> |
scroll(org.hibernate.Criteria crit,
boolean stateless)
Scroll over the query results
|
<T> Iterable<T> |
scroll(org.hibernate.Query q)
Scroll over the query results
|
<T> Iterable<T> |
scroll(org.hibernate.Query q,
boolean stateless)
Scroll over the query results
|
<T> Iterable<T> |
scrollAll(Class<T> entityClass)
Returns a iterator with all entityClass instances in database
|
<T,K> Iterable<T> |
scrollObjectsForPK(Class<T> cls,
Collection<K> ids)
get Objects for primary key
|
static void |
shutdown() |
<T> Stream<T> |
stream(org.hibernate.Criteria crit)
crates a Stream with given
Criteria crit |
<T> Stream<T> |
stream(org.hibernate.Query q)
crates a Stream with given
Query q |
<T,K> Stream<T> |
streamObjectsForPK(Class<T> cls,
Collection<K> ids)
get Objects for primary key
|
<T> Stream<T> |
streamReadOnly(org.hibernate.Criteria crit)
Creates
Stream with given criteria Result |
<T> Stream<T> |
streamReadOnly(org.hibernate.Query q)
Creates
Stream with given query Result |
<T> Stream<T> |
streamStateless(Class<?> persistentClass,
Function<org.hibernate.Criteria,org.hibernate.Criteria> criteriaFilter)
creates a
Stream with given query String in a
StatelessSession |
<T> Stream<T> |
streamStateless(String query)
creates a
Stream with given query String in a
StatelessSession |
void |
update(Object obj)
Calls
Session.update(Object) |
public static void shutdown()
protected abstract IHibernateConfig getHibernateConfig()
public <T> T getObjectForPK(Class<T> cls, Serializable id)
cls - - the Pojo Classid - - the identifier for the pojo objectpublic <T,K> Collection<T> getObjectsForPK(Class<T> cls, Collection<K> ids)
cls - - given persistence classids - - identifierpublic <T,K> Stream<T> streamObjectsForPK(Class<T> cls, Collection<K> ids)
cls - - given persistence classids - - identifierpublic <T,K> Iterable<T> scrollObjectsForPK(Class<T> cls, Collection<K> ids)
cls - - given persistence classids - - identifierpublic org.hibernate.StatelessSession createStatelessSession()
StatelessSession instanceStatelessSessionpublic static String[][] printOpenSessionInfo()
public void save(Object obj) throws Exception
Session.save(Object)obj - Exceptionpublic void saveOrUpdate(Object obj) throws Exception
Session.saveOrUpdate(Object)obj - Exceptionpublic <T> T merge(T obj)
throws Exception
Session.merge(Object)obj - Exceptionpublic void update(Object obj) throws Exception
Session.update(Object)obj - Exceptionpublic void refresh(Object obj) throws Exception
Session.refresh(Object)obj - Exceptionpublic void delete(Object obj) throws Exception
Session.delete(Object)obj - Exceptionpublic void persist(Object obj) throws Exception
Session.delete(Object)obj - Exceptionpublic org.hibernate.SessionFactory getSessionFactory()
protected void rollback()
public boolean isOpen()
public org.hibernate.Query createQuery(String stmt)
stmt - the statementpublic org.hibernate.SQLQuery createSQLQuery(String stmt)
stmt - the SQL statementpublic void flush()
public void evict(Object obj)
protected org.hibernate.Session getSession()
Sessionpublic <T> org.hibernate.Criteria createCriteria(Class<T> persistentClass)
persistentClass - - given classpublic <T> Collection<T> executeQuery(org.hibernate.Criteria crit)
Criteriacrit - - criteria to executepublic <T> Collection<T> executeQuery(org.hibernate.Criteria crit, int maxResults)
Criteriacrit - - criteria to executemaxResults - - maximal resultspublic <T> Collection<T> executeQuery(org.hibernate.Query q)
Queryq - - query to executepublic <T> Collection<T> executeQuery(org.hibernate.Query q, int maxResults)
Queryq - - query to executemaxResults - - maximal resultspublic int executeUpdate(org.hibernate.Query q)
q - - given querypublic <T> Collection<T> executeQuery(org.hibernate.Query q, int maxResults, boolean chacheable)
q - - given querymaxResults - - maximal resultschacheable - - cachablepublic <T> Collection<T> executeQuery(org.hibernate.Criteria crit, int maxResults, boolean chacheable)
crit - - given criteriamaxResults - - maxResultschacheable - - cacheablepublic <T> Iterable<T> scroll(org.hibernate.Query q)
q - - given queryIterator instancepublic <T> Iterable<T> scroll(org.hibernate.Query q, boolean stateless)
q - - given querystateless - - stateless flagIterable instancepublic <T> Iterator<T> iterator(org.hibernate.Query q, boolean stateless)
q - - given querystateless - - stateless flagIterable instanceSessionTemplate#scroll(Query)}public <T> Iterable<T> scroll(org.hibernate.Criteria crit)
cri - - given criteriaIterator instancepublic <T> Iterable<T> scroll(org.hibernate.Criteria crit, boolean stateless)
crit - - given criteriastateless - - stateless flagIterable instancepublic <T> Iterator<T> iterator(org.hibernate.Criteria crit, boolean stateless)
crit - - given criteriastateless - - stateless flagIterator instanceSessionTemplate#scroll(Criteria)}public <T> Stream<T> streamReadOnly(org.hibernate.Query q)
Stream with given query Resultq - - given Query q. q is marked as ReadOnly with
Query#setReadOnly(true)Stream with given ResultSetpublic <T> Stream<T> stream(org.hibernate.Query q)
Query qq - - given QueryStream with given ResultSetpublic <T> Stream<T> streamStateless(String query)
Stream with given query String in a
StatelessSessionquery - - given query StringStream with given ResultSetpublic <T> Stream<T> streamReadOnly(org.hibernate.Criteria crit)
Stream with given criteria Resultcrit - - given Critera crit. crit is marked as ReadOnly with
Query#setReadOnly(true)Stream with given ResultSetpublic <T> Stream<T> stream(org.hibernate.Criteria crit)
Criteria critcrit - - given CriteriaStream with given ResultSetpublic <T> Stream<T> streamStateless(Class<?> persistentClass, Function<org.hibernate.Criteria,org.hibernate.Criteria> criteriaFilter)
Stream with given query String in a
StatelessSessionpersistentClass - - class parameter for
SharedSessionContract.createCriteria(Class) - given query
StringcriteriaFilter - - manipulationFunction for created Criteria. Called before
executingStream with given ResultSetpublic <T> Collection<T> getAll(Class<T> entityClass)
USE SCROLLING IF RESULT SET MAY BE LARGE
use SessionTemplate#scrollAll(Class instead
entityClass - - given entityClasspublic <T> Collection<T> getAll(Class<T> entityClass, int maxResults)
entityClass - - given entityClassmaxResults - - maximalResultCountpublic <T> long count(Class<T> cls)
cls - public <T> Iterable<T> scrollAll(Class<T> entityClass)
entityClass - - given entity classIterator of result setpublic <T> Collection<T> executeHQLQuery(String query, int maxResults)
public <T> Collection<T> executeSQLQuery(String query, int maxResults)
public <T> Collection<T> executeNamedQuery(String query, int maxResults)
public <T> Collection<T> executeHQLQuery(String query)
public <T> Collection<T> executeSQLQuery(String query)
public <T> Collection<T> executeNamedQuery(String query)
public <T> T executeQueryUniqueResult(org.hibernate.Query q)
public <T> T executeQueryUniqueResult(org.hibernate.Query q,
boolean chacheable)
public <T> T executeQueryUniqueResult(org.hibernate.Criteria q)
public <T> T executeQueryUniqueResult(org.hibernate.Criteria crit,
boolean chacheable)
public <T> T executeHQLQueryUniqueResult(String query)
public <T> T executeSQLQueryUniqueResult(String query)
public <T> T executeNamedQueryUniqueResult(String query)
public static <T> Collection<T> filterNull(Collection<T> input)
public void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2014–2015. All rights reserved.