Class HibSessionImpl
- java.lang.Object
-
- org.bedework.carddav.server.dirHandlers.db.HibSessionImpl
-
- All Implemented Interfaces:
Serializable,HibSession,org.bedework.util.logging.Logged
public class HibSessionImpl extends Object implements HibSession, org.bedework.util.logging.Logged
Convenience class to do the actual hibernate interaction. Intended for one use only.- Author:
- Mike Douglass douglm rpi.edu
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description HibSessionImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginTransaction()Begin a transactionvoidcacheableQuery()Mark the query as cacheablevoidclear()Clear a sessionvoidclose()voidcommit()Commit a transactionorg.hibernate.CriteriacreateCriteria(Class cl)Create a Criteria ready for the additon of Criterion.voidcreateNoFlushQuery(String s)Create a query ready for parameter replacement or execution and flag it for no flush.voidcreateQuery(String s)Create a query ready for parameter replacement or execution.voidcreateSQLQuery(String s, String returnAlias, Class returnClass)Create a sql query ready for parameter replacement or execution.voiddelete(Object obj)Delete an objectvoiddisconnect()Disconnect a sessionvoidevict(Object val)Evict an object from the session.intexecuteUpdate()voidflush()Objectget(Class cl, int id)Return an object of the given class with the given id if it is already associated with this session.Objectget(Class cl, Serializable id)Return an object of the given class with the given id if it is already associated with this session.ListgetList()Return a list resulting from the query.org.bedework.util.logging.BwLoggergetLogger()StringgetQueryString()org.hibernate.SessiongetSession()ObjectgetUnique()Return the single object resulting from the query.voidinit(org.hibernate.SessionFactory sessFactory)Set up for a hibernate interaction.booleanisOpen()voidlockRead(Object o)voidlockUpdate(Object o)Objectmerge(Object obj)Merge and update an object which may have been loaded in a previous hibernate sessionvoidnamedQuery(String name)Create a named query ready for parameter replacement or execution.voidreAttach(UnversionedDbentity<?> val)voidrestore(Object obj)Save a new object with the given id.voidrollback()Rollback a transactionbooleanrolledback()Did we rollback the transaction?voidsave(Object obj)Save a new object.voidsaveOrUpdate(Object obj)Save a new object or update an object which may have been loaded in a previous hibernate sessionObjectsaveOrUpdateCopy(Object obj)Copy the state of the given object onto the persistent object with the same identifier.voidsetBool(String parName, boolean parVal)Set the named parameter with the given valuevoidsetDate(String parName, Date parVal)Set the named parameter with the given valuevoidsetEntity(String parName, Object parVal)Set the named parameter with the given valuevoidsetFirstResult(int val)Set the first result for a paged batchvoidsetFlushMode(org.hibernate.FlushMode val)set the flushmodevoidsetInt(String parName, int parVal)Set the named parameter with the given valuevoidsetLong(String parName, long parVal)Set the named parameter with the given valuevoidsetMaxResults(int val)Set the max number of results for a paged batchvoidsetParameter(String parName, Object parVal)Set the named parameter with the given valuevoidsetParameterList(String parName, Collection parVal)Set the named parameter with the given CollectionvoidsetString(String parName, String parVal)Set the named parameter with the given valuebooleantransactionStarted()Return true if we have a transaction startedvoidupdate(Object obj)Update an object which may have been loaded in a previous hibernate session-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.bedework.util.logging.Logged
audit, debug, debug, enableAuditLogger, enableErrorLogger, enableMetricsLogger, error, error, error, getLogLevel, info, isAuditLoggerEnabled, isErrorLoggerEnabled, isMetricsDebugEnabled, isMetricsLoggerEnabled, metrics, setLoggerClass, setLoggerClass, setLogLevel, trace, trace, warn
-
-
-
-
Method Detail
-
init
public void init(org.hibernate.SessionFactory sessFactory) throws org.bedework.webdav.servlet.shared.WebdavExceptionSet up for a hibernate interaction. Throw the object away on exception.- Specified by:
initin interfaceHibSession- Parameters:
sessFactory-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
getSession
public org.hibernate.Session getSession() throws org.bedework.webdav.servlet.shared.WebdavException- Specified by:
getSessionin interfaceHibSession- Returns:
- Session
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
isOpen
public boolean isOpen() throws org.bedework.webdav.servlet.shared.WebdavException- Specified by:
isOpenin interfaceHibSession- Returns:
- boolean true if open
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
clear
public void clear() throws org.bedework.webdav.servlet.shared.WebdavExceptionClear a session- Specified by:
clearin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
disconnect
public void disconnect() throws org.bedework.webdav.servlet.shared.WebdavExceptionDisconnect a session- Specified by:
disconnectin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setFlushMode
public void setFlushMode(org.hibernate.FlushMode val) throws org.bedework.webdav.servlet.shared.WebdavExceptionset the flushmode- Specified by:
setFlushModein interfaceHibSession- Parameters:
val-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
beginTransaction
public void beginTransaction() throws org.bedework.webdav.servlet.shared.WebdavExceptionBegin a transaction- Specified by:
beginTransactionin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
transactionStarted
public boolean transactionStarted()
Return true if we have a transaction started- Specified by:
transactionStartedin interfaceHibSession- Returns:
- boolean
-
commit
public void commit() throws org.bedework.webdav.servlet.shared.WebdavExceptionCommit a transaction- Specified by:
commitin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
rollback
public void rollback() throws org.bedework.webdav.servlet.shared.WebdavExceptionRollback a transaction- Specified by:
rollbackin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
rolledback
public boolean rolledback() throws org.bedework.webdav.servlet.shared.WebdavExceptionDescription copied from interface:HibSessionDid we rollback the transaction?- Specified by:
rolledbackin interfaceHibSession- Returns:
- boolean
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
createCriteria
public org.hibernate.Criteria createCriteria(Class cl) throws org.bedework.webdav.servlet.shared.WebdavException
Create a Criteria ready for the additon of Criterion.- Specified by:
createCriteriain interfaceHibSession- Parameters:
cl- Class for criteria- Returns:
- Criteria created Criteria
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
evict
public void evict(Object val) throws org.bedework.webdav.servlet.shared.WebdavException
Description copied from interface:HibSessionEvict an object from the session.- Specified by:
evictin interfaceHibSession- Parameters:
val- Object to evict- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
createQuery
public void createQuery(String s) throws org.bedework.webdav.servlet.shared.WebdavException
Description copied from interface:HibSessionCreate a query ready for parameter replacement or execution.- Specified by:
createQueryin interfaceHibSession- Parameters:
s- String hibernate query- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
createNoFlushQuery
public void createNoFlushQuery(String s) throws org.bedework.webdav.servlet.shared.WebdavException
Description copied from interface:HibSessionCreate a query ready for parameter replacement or execution and flag it for no flush. This assumes that any queued changes will not affect the result of the query.- Specified by:
createNoFlushQueryin interfaceHibSession- Parameters:
s- String hibernate query- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
getQueryString
public String getQueryString() throws org.bedework.webdav.servlet.shared.WebdavException
- Specified by:
getQueryStringin interfaceHibSession- Returns:
- query string
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
createSQLQuery
public void createSQLQuery(String s, String returnAlias, Class returnClass) throws org.bedework.webdav.servlet.shared.WebdavException
Create a sql query ready for parameter replacement or execution.- Specified by:
createSQLQueryin interfaceHibSession- Parameters:
s- String hibernate queryreturnAlias-returnClass-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
namedQuery
public void namedQuery(String name) throws org.bedework.webdav.servlet.shared.WebdavException
Create a named query ready for parameter replacement or execution.- Specified by:
namedQueryin interfaceHibSession- Parameters:
name- String named query name- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
cacheableQuery
public void cacheableQuery() throws org.bedework.webdav.servlet.shared.WebdavExceptionMark the query as cacheable- Specified by:
cacheableQueryin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setString
public void setString(String parName, String parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Set the named parameter with the given value- Specified by:
setStringin interfaceHibSession- Parameters:
parName- String parameter nameparVal- String parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setDate
public void setDate(String parName, Date parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Set the named parameter with the given value- Specified by:
setDatein interfaceHibSession- Parameters:
parName- String parameter nameparVal- Date parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setBool
public void setBool(String parName, boolean parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Set the named parameter with the given value- Specified by:
setBoolin interfaceHibSession- Parameters:
parName- String parameter nameparVal- boolean parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setInt
public void setInt(String parName, int parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Set the named parameter with the given value- Specified by:
setIntin interfaceHibSession- Parameters:
parName- String parameter nameparVal- int parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setLong
public void setLong(String parName, long parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Set the named parameter with the given value- Specified by:
setLongin interfaceHibSession- Parameters:
parName- String parameter nameparVal- long parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setEntity
public void setEntity(String parName, Object parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Set the named parameter with the given value- Specified by:
setEntityin interfaceHibSession- Parameters:
parName- String parameter nameparVal- Object parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setParameter
public void setParameter(String parName, Object parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Description copied from interface:HibSessionSet the named parameter with the given value- Specified by:
setParameterin interfaceHibSession- Parameters:
parName- String parameter nameparVal- Object parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setParameterList
public void setParameterList(String parName, Collection parVal) throws org.bedework.webdav.servlet.shared.WebdavException
Description copied from interface:HibSessionSet the named parameter with the given Collection- Specified by:
setParameterListin interfaceHibSession- Parameters:
parName- String parameter nameparVal- Collection parameter value- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setFirstResult
public void setFirstResult(int val) throws org.bedework.webdav.servlet.shared.WebdavExceptionDescription copied from interface:HibSessionSet the first result for a paged batch- Specified by:
setFirstResultin interfaceHibSession- Parameters:
val- int first index- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
setMaxResults
public void setMaxResults(int val) throws org.bedework.webdav.servlet.shared.WebdavExceptionDescription copied from interface:HibSessionSet the max number of results for a paged batch- Specified by:
setMaxResultsin interfaceHibSession- Parameters:
val- int max number- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
getUnique
public Object getUnique() throws org.bedework.webdav.servlet.shared.WebdavException
Description copied from interface:HibSessionReturn the single object resulting from the query.- Specified by:
getUniquein interfaceHibSession- Returns:
- Object retrieved object or null
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
getList
public List getList() throws org.bedework.webdav.servlet.shared.WebdavException
Return a list resulting from the query.- Specified by:
getListin interfaceHibSession- Returns:
- List list from query
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
executeUpdate
public int executeUpdate() throws org.bedework.webdav.servlet.shared.WebdavException- Specified by:
executeUpdatein interfaceHibSession- Returns:
- int number updated
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
update
public void update(Object obj) throws org.bedework.webdav.servlet.shared.WebdavException
Update an object which may have been loaded in a previous hibernate session- Specified by:
updatein interfaceHibSession- Parameters:
obj-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
merge
public Object merge(Object obj) throws org.bedework.webdav.servlet.shared.WebdavException
Merge and update an object which may have been loaded in a previous hibernate session- Specified by:
mergein interfaceHibSession- Parameters:
obj-- Returns:
- Object the persistent object
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
saveOrUpdate
public void saveOrUpdate(Object obj) throws org.bedework.webdav.servlet.shared.WebdavException
Save a new object or update an object which may have been loaded in a previous hibernate session- Specified by:
saveOrUpdatein interfaceHibSession- Parameters:
obj-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
saveOrUpdateCopy
public Object saveOrUpdateCopy(Object obj) throws org.bedework.webdav.servlet.shared.WebdavException
Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved or does not exist in the database, save it and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session.- Specified by:
saveOrUpdateCopyin interfaceHibSession- Parameters:
obj-- Returns:
- Object
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
get
public Object get(Class cl, Serializable id) throws org.bedework.webdav.servlet.shared.WebdavException
Return an object of the given class with the given id if it is already associated with this session. This must be called for specific key queries or we can get a NonUniqueObjectException later.- Specified by:
getin interfaceHibSession- Parameters:
cl- Class of the instanceid- A serializable key- Returns:
- Object
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
get
public Object get(Class cl, int id) throws org.bedework.webdav.servlet.shared.WebdavException
Return an object of the given class with the given id if it is already associated with this session. This must be called for specific key queries or we can get a NonUniqueObjectException later.- Specified by:
getin interfaceHibSession- Parameters:
cl- Class of the instanceid- int key- Returns:
- Object
- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
save
public void save(Object obj) throws org.bedework.webdav.servlet.shared.WebdavException
Save a new object.- Specified by:
savein interfaceHibSession- Parameters:
obj-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
delete
public void delete(Object obj) throws org.bedework.webdav.servlet.shared.WebdavException
Delete an object- Specified by:
deletein interfaceHibSession- Parameters:
obj-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
restore
public void restore(Object obj) throws org.bedework.webdav.servlet.shared.WebdavException
Save a new object with the given id. This should only be used for restoring the db from a save.- Specified by:
restorein interfaceHibSession- Parameters:
obj-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
reAttach
public void reAttach(UnversionedDbentity<?> val) throws org.bedework.webdav.servlet.shared.WebdavException
- Specified by:
reAttachin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
lockRead
public void lockRead(Object o) throws org.bedework.webdav.servlet.shared.WebdavException
- Specified by:
lockReadin interfaceHibSession- Parameters:
o-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
lockUpdate
public void lockUpdate(Object o) throws org.bedework.webdav.servlet.shared.WebdavException
- Specified by:
lockUpdatein interfaceHibSession- Parameters:
o-- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
flush
public void flush() throws org.bedework.webdav.servlet.shared.WebdavException- Specified by:
flushin interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
close
public void close() throws org.bedework.webdav.servlet.shared.WebdavException- Specified by:
closein interfaceHibSession- Throws:
org.bedework.webdav.servlet.shared.WebdavException
-
getLogger
public org.bedework.util.logging.BwLogger getLogger()
- Specified by:
getLoggerin interfaceorg.bedework.util.logging.Logged
-
-