T
- K
- @Repository @ConfigAware public abstract class PersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable> extends java.lang.Object implements IPersistenceManager<T,K>
IPersistenceManager
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ASC |
static java.lang.String |
DESC |
protected org.apache.logging.log4j.Logger |
log |
protected java.lang.String[] |
m_defaultOrderDirection |
protected java.lang.String[] |
m_defaultSortOrder |
protected java.lang.Class<?> |
m_genericClass |
protected SessionFactory |
m_sessionFactory |
Constructor and Description |
---|
PersistenceManager() |
Modifier and Type | Method and Description |
---|---|
protected Criteria |
buildCriteria(Criteria pCriteria,
java.util.Collection<FilterClause> pFilters)
For date and datetime property in the filter is actually a table column name rather than entity field name
|
protected Criteria |
buildCriteria(Criteria pCriteria,
java.util.Collection<FilterClause> pFilters,
boolean pKeepAliases) |
void |
clear()
Clear Hibernate session
|
void |
clearCache() |
void |
clearCache(java.lang.Class<?> pClass)
Clear caches in case database was touched by external tool
|
void |
clearCache(java.lang.Class<?> pClass,
K pId) |
void |
clearCache(K pId) |
void |
clearCache(T pEntity) |
protected Criterion |
createComplexCriterion(FilterClause pFilterClause,
Criteria pCriteria) |
protected Criterion |
createCriterion(FilterClause pFilterClause,
Criteria pCriteria) |
protected Criterion |
createSimpleCriterion(FilterClause pFilterClause,
Criteria pCriteria) |
void |
delete(Session pSession,
T pObject)
Delete object from database.
|
void |
delete(StatelessSession pSession,
T pObject)
Delete object from database.
|
void |
delete(T pObject)
Delete object from database.
|
void |
flush()
Flush session
|
T |
get(K pId)
Get object of class specified by getGenericClass()
|
java.lang.Object |
get(java.io.Serializable pId,
java.lang.Class<?> pClass)
Get object of class
|
T |
get(Session pSession,
K pId)
Get persistent entity by ID
|
T |
get(StatelessSession pSession,
K pId)
Get persistent entity by ID
|
T |
getByCode(java.lang.String pCode)
Get entity by code.
|
Criteria |
getClientFilter(Criteria pCriteria)
Add client filter to criteria
|
Session |
getCurrentSession() |
javax.sql.DataSource |
getDataSource() |
protected Criteria |
getDefaultClientFilter(Criteria pCriteria) |
java.lang.String[] |
getDefaultOrderDirection() |
java.lang.String[] |
getDefaultOrderField()
Returns name of the property which will be used as a default for sorting.
|
java.lang.Class<?> |
getGenericClass()
Return the implemented class T.
|
java.lang.Integer |
getResultSize(java.util.Collection<FilterClause> pFilters)
Pageable scrolling on UI layer requires total size of the result set.
|
protected void |
init() |
K |
insert(Session pSession,
T pObject)
Insert persistable object into the DB
|
K |
insert(StatelessSession pSession,
T pObject)
Insert persistable object into the DB
|
K |
insert(T pObject)
Insert persistable object into the DB
|
java.util.List<T> |
list()
In case of very large result set @link
OutOfMemoryError could be thrown. |
java.util.List<T> |
list(Session pSession)
In case of very large result set @link
OutOfMemoryError could be thrown. |
java.util.List<T> |
list(Session pSession,
boolean pUseClientFilter)
In case of very large result set @link
OutOfMemoryError could be thrown. |
java.util.List<T> |
list(StatelessSession pSession,
boolean pUseClientFilter)
In case of very large result set @link
OutOfMemoryError could be thrown. |
java.util.List<T> |
listAll()
In case of very large result set @link
OutOfMemoryError could be thrown. |
java.util.List<T> |
listAllInNewSession()
This method create new session internally.
|
java.util.List<java.util.Map<K,Nls>> |
listNls(java.lang.String pDefLangCode3,
java.lang.String pLangCode3,
java.lang.String pSimpleFilter,
java.lang.Integer pMaxResults,
java.lang.Integer pStartFrom)
Return map of nls values where key is ID of the original object and value is
Nls object. |
void |
lock(T pEntity,
LockOptions pLockOptions) |
T |
merge(T pObject) |
java.lang.Number |
nextVal(java.lang.String pSequenceName)
Manually get next value from specified sequence
|
java.util.List<T> |
page(java.lang.Integer pFirstResult,
java.lang.Integer pMaxResults,
java.lang.String pOrderField,
java.lang.Boolean pAscending)
Pageable scrolling on UI layer request data in pages.
|
java.util.List<T> |
page(java.lang.Integer pOffset,
java.lang.Integer pPageSize,
java.lang.String pSortField,
java.lang.Boolean pSortOrder,
java.util.Collection<FilterClause> pFilters)
Pageable scrolling on UI layer request data in pages.
|
java.util.List<T> |
page(Session pSession,
java.lang.Integer pFirstResult,
java.lang.Integer pMaxResults,
java.lang.String pOrderField,
java.lang.Boolean pAscending)
Pageable scrolling on UI layer request data in pages.
|
Criteria |
prepareCommonCriteria(Session pSession) |
Criteria |
prepareCommonCriteria(StatelessSession pSession) |
void |
registerOnBeforeChangeCallback(IOnBeforeChangeCallback<T> pOnBeforeChangeCallback) |
T |
save(Session pSession,
T pObject)
Persist object into the DB.
|
T |
save(T pObject)
Persist object into the DB.
|
void |
scroll(IScrollCallback<T> pScrollCallback)
In case of very large result sets when it is not possible to fit all data into the memory it is possible to iterate over the result set and invoke @link
IScrollCallback callback to process each individual result. |
void |
scroll(IScrollCallback<T> pScrollCallback,
boolean pUseClientFilter)
In case of very large result sets when it is not possible to fit all data into the memory it is possible to iterate over the result set and invoke @link
IScrollCallback callback to process each individual result. |
void |
scroll(Session pSession,
IScrollCallback<T> pScrollCallback)
In case of very large result sets when it is not possible to fit all data into the memory it is possible to iterate over the result set and invoke @link
IScrollCallback callback to process each individual result. |
void |
scroll(Session pSession,
IScrollCallback<T> pScrollCallback,
boolean pUseClientFilter)
In case of very large result sets when it is not possible to fit all data into the memory it is possible to iterate over the result set and invoke @link
IScrollCallback callback to process each individual result. |
void |
scroll(StatelessSession pSession,
IScrollCallback<T> pScrollCallback,
boolean pUseClientFilter)
In case of very large result sets when it is not possible to fit all data into the memory it is possible to iterate over the result set and invoke @link
IScrollCallback callback to process each individual result. |
protected void |
setOrder(Criteria crit) |
T |
update(Session pSession,
T pObject)
Update object in the database.
|
T |
update(StatelessSession pSession,
T pObject)
Update object in the database.
|
T |
update(T pObject)
Update object in the database.
|
protected org.apache.logging.log4j.Logger log
public static final java.lang.String ASC
public static final java.lang.String DESC
protected java.lang.Class<?> m_genericClass
protected java.lang.String[] m_defaultSortOrder
protected java.lang.String[] m_defaultOrderDirection
@Autowired protected SessionFactory m_sessionFactory
public void registerOnBeforeChangeCallback(IOnBeforeChangeCallback<T> pOnBeforeChangeCallback)
registerOnBeforeChangeCallback
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
@PostConstruct protected void init()
public java.lang.Class<?> getGenericClass()
IPersistenceManager
public class UserManager extends PersistenceManager implements IUserManager
then this method should be implemented as
public Class> getGenericClass() {
return User.class;
}
getGenericClass
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public java.lang.String[] getDefaultOrderField()
IPersistenceManager
getDefaultOrderField
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public java.lang.String[] getDefaultOrderDirection()
getDefaultOrderDirection
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public java.lang.Number nextVal(java.lang.String pSequenceName)
IPersistenceManager
nextVal
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public Session getCurrentSession()
getCurrentSession
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public javax.sql.DataSource getDataSource()
public Criteria getClientFilter(Criteria pCriteria)
IPersistenceManager
getClientFilter
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pCriteria
- input criteriapublic Criteria prepareCommonCriteria(StatelessSession pSession)
public java.util.List<java.util.Map<K,Nls>> listNls(java.lang.String pDefLangCode3, java.lang.String pLangCode3, java.lang.String pSimpleFilter, java.lang.Integer pMaxResults, java.lang.Integer pStartFrom) throws java.lang.Exception
IPersistenceManager
Nls
object. Value is either Nls
in requested language or in default languatelistNls
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pDefLangCode3
- - default language. Use it if requested language is not found.pLangCode3
- - requested languagepSimpleFilter
- - simple string filter for ilike on Nls.name propertypMaxResults
- - maximum number of results returned by this queryjava.lang.Exception
public java.lang.Integer getResultSize(java.util.Collection<FilterClause> pFilters) throws java.lang.Exception
IPersistenceManager
getResultSize
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pFilters
- collection of FilterClause
java.lang.Exception
public java.util.List<T> page(java.lang.Integer pOffset, java.lang.Integer pPageSize, java.lang.String pSortField, java.lang.Boolean pSortOrder, java.util.Collection<FilterClause> pFilters) throws java.lang.Exception
IPersistenceManager
page
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pOffset
- position in the result set. Range from 0 to the value returned by getDefaultOredField
method.pPageSize
- size of the data set to return. Usually should be enough to fit into one screen.pSortField
- field to sort over. Note that this is a class property and NOT the database fieldpSortOrder
- sort order. Boolean.TRUE - ascending, Boolean.FALSE - descendingpFilters
- collection of FilterClause
java.lang.Exception
protected Criteria buildCriteria(Criteria pCriteria, java.util.Collection<FilterClause> pFilters) throws java.lang.Exception
pCriteria
- pFilters
- java.lang.Exception
protected Criteria buildCriteria(Criteria pCriteria, java.util.Collection<FilterClause> pFilters, boolean pKeepAliases) throws java.lang.Exception
java.lang.Exception
protected Criterion createCriterion(FilterClause pFilterClause, Criteria pCriteria) throws java.text.ParseException, java.lang.ClassNotFoundException
java.text.ParseException
java.lang.ClassNotFoundException
protected Criterion createComplexCriterion(FilterClause pFilterClause, Criteria pCriteria) throws java.text.ParseException, java.lang.ClassNotFoundException
java.text.ParseException
java.lang.ClassNotFoundException
protected Criterion createSimpleCriterion(FilterClause pFilterClause, Criteria pCriteria) throws java.text.ParseException, java.lang.ClassNotFoundException
java.text.ParseException
java.lang.ClassNotFoundException
public void clearCache()
clearCache
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public void clearCache(java.lang.Class<?> pClass)
IPersistenceManager
clearCache
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public void clearCache(T pEntity)
clearCache
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public void clearCache(K pId)
clearCache
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public void clearCache(java.lang.Class<?> pClass, K pId)
clearCache
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public void lock(T pEntity, LockOptions pLockOptions)
lock
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public java.lang.Object get(java.io.Serializable pId, java.lang.Class<?> pClass)
IPersistenceManager
get
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pId
- primary keypClass
- entity classpublic T getByCode(java.lang.String pCode)
IPersistenceManager
getByCode
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pCode
- codepublic T get(K pId)
IPersistenceManager
get
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pId
- primary keypublic T get(Session pSession, K pId)
IPersistenceManager
get
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pId
- primary key of the persistent entitypublic T get(StatelessSession pSession, K pId)
IPersistenceManager
get
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link StatelessSession
pId
- primary key of the persistent entitypublic java.util.List<T> list()
IPersistenceManager
OutOfMemoryError
could be thrown.list
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public java.util.List<T> listAll()
IPersistenceManager
OutOfMemoryError
could be thrown.listAll
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public java.util.List<T> list(Session pSession)
IPersistenceManager
OutOfMemoryError
could be thrown.list
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
public java.util.List<T> listAllInNewSession()
IPersistenceManager
OutOfMemoryError
could be thrown.listAllInNewSession
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
protected void setOrder(Criteria crit)
public java.util.List<T> list(StatelessSession pSession, boolean pUseClientFilter)
IPersistenceManager
OutOfMemoryError
could be thrown. This method uses @link StatelessSession
, which means there is no caching and lazy loading is involved.list
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link StatelssSession
pUseClientFilter
- apply client filter on the result set.public java.util.List<T> list(Session pSession, boolean pUseClientFilter)
IPersistenceManager
OutOfMemoryError
could be thrown.list
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pUseClientFilter
- apply client filter on the result set.public void scroll(IScrollCallback<T> pScrollCallback)
IPersistenceManager
IScrollCallback
callback to process each individual result.scroll
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pScrollCallback
- callback to call on each result.public void scroll(IScrollCallback<T> pScrollCallback, boolean pUseClientFilter)
IPersistenceManager
IScrollCallback
callback to process each individual result.scroll
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pScrollCallback
- callback to call on each result.pUseClientFilter
- apply client filter on result setpublic void scroll(Session pSession, IScrollCallback<T> pScrollCallback)
IPersistenceManager
IScrollCallback
callback to process each individual result.scroll
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pScrollCallback
- callback to call on each result.public void scroll(StatelessSession pSession, IScrollCallback<T> pScrollCallback, boolean pUseClientFilter)
IPersistenceManager
IScrollCallback
callback to process each individual result.scroll
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link StatelssSession
pScrollCallback
- callback to call on each result.public void scroll(Session pSession, IScrollCallback<T> pScrollCallback, boolean pUseClientFilter)
IPersistenceManager
IScrollCallback
callback to process each individual result.scroll
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link StatelssSession
pScrollCallback
- callback to call on each result.pUseClientFilter
- apply client filter on result setpublic java.util.List<T> page(java.lang.Integer pFirstResult, java.lang.Integer pMaxResults, java.lang.String pOrderField, java.lang.Boolean pAscending)
IPersistenceManager
page
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pFirstResult
- position in the result set. Range from 0 to the value returned by getDefaultOredField
method.pMaxResults
- size of the data set to return. Usually should be enough to fit into one screen.pOrderField
- field to sort over. Note that this is a class property and NOT the database fieldpAscending
- sort order. Boolean.TRUE - ascending, Boolean.FALSE - descendingpublic java.util.List<T> page(Session pSession, java.lang.Integer pFirstResult, java.lang.Integer pMaxResults, java.lang.String pOrderField, java.lang.Boolean pAscending)
IPersistenceManager
page
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pFirstResult
- position in the result set. Range from 0 to the value returned by getDefaultOredField
method.pMaxResults
- size of the data set to return. Usually should be enough to fit into one screen.pOrderField
- field to sort over. Note that this is a class property and NOT the database fieldpAscending
- sort order. Boolean.TRUE - ascending, Boolean.FALSE - descendingpublic K insert(T pObject)
IPersistenceManager
insert
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pObject
- object to persistpublic K insert(Session pSession, T pObject)
IPersistenceManager
insert
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pObject
- object to persistpublic K insert(StatelessSession pSession, T pObject)
IPersistenceManager
insert
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link StatelssSession
pObject
- object to persistpublic T update(T pObject)
IPersistenceManager
update
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pObject
- object to updatepublic T update(Session pSession, T pObject)
IPersistenceManager
update
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pObject
- object to updatepublic T update(StatelessSession pSession, T pObject)
IPersistenceManager
update
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link StatelssSession
pObject
- object to updatepublic void flush()
IPersistenceManager
flush
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public void clear()
IPersistenceManager
clear
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public T save(T pObject)
IPersistenceManager
save
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pObject
- object to persistpublic T save(Session pSession, T pObject)
IPersistenceManager
save
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pObject
- object to persistpublic T merge(T pObject)
merge
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
public void delete(T pObject)
IPersistenceManager
delete
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pObject
- object to deletepublic void delete(Session pSession, T pObject)
IPersistenceManager
delete
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link Session
pObject
- object to deletepublic void delete(StatelessSession pSession, T pObject)
IPersistenceManager
delete
in interface IPersistenceManager<T extends Identifiable<K>,K extends java.io.Serializable>
pSession
- Hibernate @link StatelessSession
pObject
- object to deleteCopyright © 2015 Pixel Nation Inc. All Rights Reserved.