|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jalios.jcms.db.HibernateUtil
public class HibernateUtil
Helper class providing static methods to perform common database operation using hibertnate
Field Summary | |
---|---|
static String |
REVISION
|
Fields inherited from interface com.jalios.jcms.db.DBConstants |
---|
AUTHOR_ID_FIELD, CDATE_FIELD, CHANNEL_JCMSDB_PROP, DBDATA_URID, HIBERNATE_MAPPING_ADATE, HIBERNATE_MAPPING_AUTHOR, HIBERNATE_MAPPING_CDATE, HIBERNATE_MAPPING_EDATE, HIBERNATE_MAPPING_MDATE, HIBERNATE_MAPPING_PDATE, HIBERNATE_MAPPING_PSTATUS, HIBERNATE_MAPPING_TITLE, HIBERNATE_MAPPING_WORKSPACE_ID, MDATE_FIELD, ROW_ID_FIELD |
Constructor Summary | |
---|---|
HibernateUtil()
|
Method Summary | ||
---|---|---|
static void |
beginTransaction()
Begins a new transaction in the session of the current thread. |
|
static org.hibernate.criterion.Criterion |
buildAndCriterion(org.hibernate.criterion.Criterion c1,
org.hibernate.criterion.Criterion c2)
Returns the AND of the two criterion. |
|
static String |
buildJcmsId(Class<?> clazz,
Long rowId)
Generates the internal JCMS id for the given database object. |
|
static org.hibernate.criterion.Criterion |
buildOrCriterion(org.hibernate.criterion.Criterion c1,
org.hibernate.criterion.Criterion c2)
Returns the OR of the two criterion. |
|
static void |
clearCache()
|
|
static void |
closeSession()
Close the hibernate session of the current thread. |
|
static void |
commitTransaction()
Commits the transaction of the current thread if it exists. |
|
static void |
delete(DBData data)
Deletes the specified object in the database. |
|
static void |
delete(String id)
Deletes the specified object in the database. |
|
static int |
deleteQuery(Class<?> clazz,
String property,
String value)
Delete all object matching the specified parameters. |
|
static void |
evict(Object obj)
Removes this instance from the Hibernate session cache to avoid automatic persistence by dirty checking. |
|
static List |
execQuery(org.hibernate.Query query)
Execute the specified hibernate query using the current thread's session. |
|
static List |
execQuery(String hql)
Execute the specified hibernate query using the current thread's session. |
|
static List |
execQuery(String hql,
int firstResult,
int maxResults)
Execute the specified hibernate query using the current thread's session. |
|
static Iterator |
execQueryIterator(org.hibernate.Query query)
Execute the specified hibernate query using the current thread's session. |
|
static Iterator |
execQueryIterator(String hql)
Execute the specified hibernate query using the current thread's session. |
|
static Object |
execQueryUnique(String hql)
Execute the specified hibernate query using the current thread's session. |
|
static int |
execUpdate(org.hibernate.Query query)
Execute the update or delete query. |
|
static int |
execUpdate(String hql)
Execute the update or delete HQL statement. |
|
static Data |
getData(String id)
Retrieves the Data bound to the specified jcms id from the database. |
|
static DBData |
getDBData(String id)
Retrieves the DBData bound to the specified jcms id from the database. |
|
static
|
getDBDataIterator(Class<T> clazz)
Retrieve all Objects of the specified class from the database. |
|
static
|
getDBDataList(Class<T> clazz)
Retrieve all Objects of the specified class from the database (limited to maxResults). |
|
static
|
getDBDataList(Class<T> clazz,
int firstResult,
int maxResults)
Retrieve all Objects of the specified class from the database. |
|
static Object |
getObject(Class clazz,
Long rowId)
Retrieves the Object of the specified class and using the specified id. |
|
static org.hibernate.Session |
getSession()
Retrieve and open an hibernate session for the current thread |
|
static org.hibernate.SessionFactory |
getSessionFactory()
Retrieve the Hibernate SessionFactory singleton |
|
static boolean |
isDBDataJcmsId(String id)
|
|
static
|
query(Class<? extends T> clazz,
Map<String,Object> paramsMap)
Retrieves all object matching the specified parameters. |
|
static
|
query(Class<? extends T> clazz,
Map<String,Object> paramsMap,
String orderBy)
Retrieves all object matching the specified parameters. |
|
static
|
query(Class<? extends T> clazz,
Map<String,Object> paramsMap,
String orderBy,
int firstResult,
int maxResults)
Retrieves all object matching the specified parameters. |
|
static
|
query(Class<? extends T> clazz,
String orderBy)
Retrieves all object of the specified Class. |
|
static
|
query(Class<? extends T> clazz,
String[] properties,
Object[] values)
Retrieves all object matching the specified parameters. |
|
static
|
query(Class<? extends T> clazz,
String[] properties,
Object[] values,
String orderBy)
Retrieves all object matching the specified parameters. |
|
static
|
query(Class<? extends T> clazz,
String property,
Object value)
Retrieves all object matching the specified parameters. |
|
static
|
query(Class<? extends T> clazz,
String property,
Object value,
String orderBy)
Retrieves all object matching the specified parameters. |
|
static
|
query(Class<T> clazz)
Retrieves all object of the specified Class. |
|
static int |
queryCount(Class<?> clazz)
Returns the count of objects matching the given class. |
|
static int |
queryCount(Class<?> clazz,
org.hibernate.criterion.Criterion criterion)
Returns the count of objects matching the given class with the given criterion. |
|
static int |
queryCount(Class<?> clazz,
String[] properties,
Object[] values)
Returns the count of objects matching the given class with the given criteria. |
|
static int |
queryCount(Class<?> clazz,
String property,
Object value)
Returns the count of objects matching the given class with the given criteria. |
|
static PageResult<Publication> |
queryPublication(PublicationCriteria pubCriteria)
Returns a list of publications in the database matching the given criteria. |
|
static
|
queryUnique(Class<? extends T> clazz,
String[] properties,
Object[] values)
Retrieves a unique object matching the specified parameters. |
|
static
|
queryUnique(Class<? extends T> clazz,
String[] properties,
Object[] values,
String orderBy)
Retrieves a unique object matching the specified parameters. |
|
static
|
queryUnique(Class<? extends T> clazz,
String property,
Object value)
Retrieves a unique object matching the specified parameters. |
|
static void |
rollbackTransaction()
Rollback the transaction of the current thread if it exists. |
|
static void |
save(Data data)
Saves or updates the specified Data in the database. |
|
static void |
save(Object obj)
Saves or updates the specified Object in the database. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
Constructor Detail |
---|
public HibernateUtil()
Method Detail |
---|
public static org.hibernate.SessionFactory getSessionFactory()
public static org.hibernate.Session getSession()
public static void closeSession()
public static void beginTransaction()
public static void commitTransaction()
public static void rollbackTransaction()
public static String buildJcmsId(Class<?> clazz, Long rowId)
clazz
- the Class of the object (required)rowId
- the row id in the database table (required)
IllegalArgumentException
- if clazz or rowId is nullpublic static boolean isDBDataJcmsId(String id)
public static Object execQueryUnique(String hql)
Return the unique query result. If the query contains multiple results per row, the results are returned in an instance of Object[].
hql
- the query as a string using the hibernate query language
public static List execQuery(String hql)
Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
hql
- the query as a string using the hibernate query language
public static List execQuery(String hql, int firstResult, int maxResults)
Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
hql
- the query as a string using the hibernate query languagefirstResult
- set the first data to retrieve. If <= 0, rows will be retrieved beginnning from first data (does not work with query on super classes).maxResults
- set the maximum number of data to retrieve. If < 0, there is no limit to the number of data retrieved (does not work with query on super classes).
public static List execQuery(org.hibernate.Query query)
Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
query
- the hibernate query
public static Iterator execQueryIterator(String hql)
Return the query results as an Iterator. If the query contains multiple results pre row, the results are returned in an instance of Object[].
Entities returned as results are initialized on demand. The first SQL query returns identifiers only.
hql
- the query as a string using the hibernate query language
public static Iterator execQueryIterator(org.hibernate.Query query)
Return the query results as an Iterator. If the query contains multiple results pre row, the results are returned in an instance of Object[].
Entities returned as results are initialized on demand. The first SQL query returns identifiers only.
query
- the hibernate query
public static int execUpdate(String hql)
hql
- the query as a string using the hibernate query language
public static int execUpdate(org.hibernate.Query query)
query
- the Hibernate query
public static <T> List<T> query(Class<T> clazz)
Example to retrieve all ArchivedPublication.
HibernateUtil.query(ArchivedPublication.class);Results will be sorted by cdate if the Class is a subclass of Data, otherwise, results are not sorted.
clazz
- the Class of object to retrieve, required must not be null
IllegalArgumentException
- if clazz is nullpublic static <T> List<T> query(Class<? extends T> clazz, String orderBy)
Example to retrieve all ArchivedPublication order by rowId.
HibernateUtil.query(ArchivedPublication.class, "rowId");
clazz
- the Class of object to retrieve, required must not be nullorderBy
- the field name to use to order the results. You can append "asc" or "desc" to indicate the order direction. Default is ascending.
IllegalArgumentException
- if clazz is nullpublic static <T> List<T> query(Class<? extends T> clazz, String property, Object value)
Example to retrieve all ReaderTracker of a publication
HibernateUtil.query(ReaderTracker.class, "publicationId", pub.getId());Results will be sorted by cdate if the Class is a subclass of Data, otherwise, results are not sorted.
clazz
- the Class of object to retrieve, required must not be nullproperty
- a field name. All results are return if null.value
- the value of the field to match. All results are return if null.
IllegalArgumentException
- if clazz is nullpublic static <T> List<T> query(Class<? extends T> clazz, String property, Object value, String orderBy)
Example to retrieve all ExtraDBData of a member, order by extradbdata name
HibernateUtil.query(ExtraDBData.class, "dataId", mbr.getId(), "extraName");
clazz
- the Class of object to retrieve, required must not be nullproperty
- a field name. All results are return if null.value
- the value of the field to match. All results are return if null.orderBy
- the field name to use to order the results. You can append "asc" or "desc" to indicate the order direction. Default is ascending.
IllegalArgumentException
- if clazz is nullpublic static <T> List<T> query(Class<? extends T> clazz, String[] properties, Object[] values)
Example to retrieve ReaderTracker of a publication for a specific member.
String[] properties = new String[] {"publicationId", "authorId"}; String[] values = new String[] {pub.getId(), mbr.getId()}; HibernateUtil.query(ReaderTracker.class, properties, values);Results will be sorted by cdate if the Class is a subclass of Data, otherwise, results are not sorted
clazz
- the Class of object to retrieve, required must not be nullproperties
- an array of fields name. All results are return if null or empty.values
- an array of values to match, must be the same size as properties. All results are return if null or empty.
IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> List<T> query(Class<? extends T> clazz, String[] properties, Object[] values, String orderBy)
clazz
- the Class of object to retrieve, required must not be nullproperties
- an array of fields name. All results are return if null or empty.values
- an array of values to match, must be the same size as properties. All results are return if null or empty.orderBy
- the field name to use to order the results. You can append "asc" or "desc" to indicate the order direction. Default is ascending.
IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> T queryUnique(Class<? extends T> clazz, String property, Object value)
clazz
- the Class of object to retrieve, requiredproperty
- a field name. All results are return if null.value
- the value of the field to match. All results are return if null.
IllegalArgumentException
- if clazz is nullpublic static <T> T queryUnique(Class<? extends T> clazz, String[] properties, Object[] values)
clazz
- the Class of object to retrieve, requiredproperties
- an array of fields name. All results are return if null or empty.values
- an array of values to match, must be the same size as properties. All results are return if null or empty.
IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> T queryUnique(Class<? extends T> clazz, String[] properties, Object[] values, String orderBy)
clazz
- the Class of object to retrieve, requiredproperties
- an array of fields name. All results are return if null or empty.values
- an array of values to match, must be the same size as properties. All results are return if null or empty.orderBy
- the field name to use to order the results. You can append "asc" or "desc" to indicate the order direction. Default is ascending.
IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> List<T> query(Class<? extends T> clazz, Map<String,Object> paramsMap)
Example to retrieve ReaderTracker of a publication for a specific member.
Map<String,String> paramsMap = new HashMap<String,String>(); paramsMap.put("publicationId", pub.getId()); paramsMap.put("authorId", mbr.getId()); HibernateUtil.query(ReaderTracker.class, paramsMap);Results will be sorted by cdate if the Class is a subclass of Data, otherwise, results are not sorted
clazz
- the Class of object to retrieve, requiredparamsMap
- a map of fields name and field value (if null or empty, no refinement is performed)
public static <T> List<T> query(Class<? extends T> clazz, Map<String,Object> paramsMap, String orderBy)
clazz
- the Class of object to retrieve, required must not be nullparamsMap
- a map of fields name and field value (if null or empty, no refinement is performed)orderBy
- the field name to use to order the results. You can append "asc" or "desc" to indicate the order direction. Default is ascending.
IllegalArgumentException
- if clazz is nullpublic static <T> List<T> query(Class<? extends T> clazz, Map<String,Object> paramsMap, String orderBy, int firstResult, int maxResults)
clazz
- the Class of object to retrieve, required must not be nullparamsMap
- a map of fields name and field value (if null or empty, no refinement is performed)orderBy
- the field name to use to order the results. You can append "asc" or "desc" to indicate the order direction. Default is ascending.firstResult
- set the first data to retrieve. If <= 0, rows will be retrieved beginnning from first data (does not work with query on super classes).maxResults
- set the maximum number of data to retrieve. If < 0, there is no limit to the number of data retrieved (does not work with query on super classes).
IllegalArgumentException
- if clazz is nullpublic static int deleteQuery(Class<?> clazz, String property, String value)
Example to delete all ReaderTracker of a publication
HibernateUtil.deleteQuery(ReaderTracker.class, "publicationId", pub.getId());
clazz
- the Class of object to retrieve and delete, requiredproperty
- a field name, requiredvalue
- the value of the field to match, required
public static <T> List<T> getDBDataList(Class<T> clazz)
T
- any DB typeclazz
- the Class of object to retrieve, required
public static <T> List<T> getDBDataList(Class<T> clazz, int firstResult, int maxResults)
T
- any DB typeclazz
- the Class of object to retrieve, requiredfirstResult
- set the first data to retrieve. If <= 0, rows will be retrieved beginnning from first data (does not work with query on super classes).maxResults
- set the maximum number of data to retrieve. If < 0, there is no limit to the number of data retrieved (does not work with query on super classes).
public static <T> Iterator<T> getDBDataIterator(Class<T> clazz)
T
- any DB typeclazz
- the Class of object to retrieve, required
public static int queryCount(Class<?> clazz)
clazz
- the class
public static int queryCount(Class<?> clazz, String property, Object value)
clazz
- the classproperty
- a field name.value
- the value of the field to match. All results are return if null.
public static int queryCount(Class<?> clazz, String[] properties, Object[] values)
clazz
- the classproperties
- an array of field name.values
- an array of values of the field to match.
public static int queryCount(Class<?> clazz, org.hibernate.criterion.Criterion criterion)
clazz
- the classcriterion
- the criterion
public static PageResult<Publication> queryPublication(PublicationCriteria pubCriteria)
pubCriteria
- the PublicationCriteria (required, must not be null)
IllegalArgumentException
- if pubCriteria is nullpublic static org.hibernate.criterion.Criterion buildAndCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2)
c1
- a criterionc2
- a criterion
public static org.hibernate.criterion.Criterion buildOrCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2)
c1
- a criterionc2
- a criterion
public static Object getObject(Class clazz, Long rowId)
clazz
- the Class (or super class in case of inheritance) of the object to retrieverowId
- the primary key value of the object or if could not be found, the value of the "id" column
public static DBData getDBData(String id)
id
- the JCMS id of this data (e.g. 1234_WFNOTE)
public static Data getData(String id)
id
- the JCMS id of this data (e.g. 1234_WFNOTE)
public static void save(Data data)
data
- the Data to be saved or updatedpublic static void save(Object obj)
obj
- the object to be saved or updatedpublic static void evict(Object obj)
obj
- Session.evict(Object)
public static void delete(DBData data)
data
- the data to be deletedpublic static void delete(String id)
id
- the identifier of the DBData to be deletedpublic static void clearCache()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |