public class HibernateUtil extends java.lang.Object implements DBConstants, JaliosConstants
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BATCH_SIZE |
static java.lang.String |
REVISION |
ALL_CATEGORIES_SET_FIELD, AUTH_GRP_SET_FIELD, AUTH_MBR_SET_FIELD, AUTHOR_ID_FIELD, CATEGORIES_SET_FIELD, CDATE_FIELD, CHANNEL_JCMSDB_PROP, DBDATA_URID, HAS_NO_READ_RIGHTS, HIBERNATE_MAPPING_ADATE, HIBERNATE_MAPPING_AUTHOR, HIBERNATE_MAPPING_CDATE, HIBERNATE_MAPPING_EDATE, HIBERNATE_MAPPING_HASNOREADRIGHTS, HIBERNATE_MAPPING_MAJORVERSION, HIBERNATE_MAPPING_MDATE, HIBERNATE_MAPPING_MINORVERSION, HIBERNATE_MAPPING_PDATE, HIBERNATE_MAPPING_PSTATUS, HIBERNATE_MAPPING_READERCOUNT, HIBERNATE_MAPPING_ROLEMAPSTR, HIBERNATE_MAPPING_TITLE, HIBERNATE_MAPPING_TRACKED, HIBERNATE_MAPPING_UDATE, HIBERNATE_MAPPING_VOTECOUNT, HIBERNATE_MAPPING_VOTESCORE, HIBERNATE_MAPPING_WORKFLOW_ID, HIBERNATE_MAPPING_WORKSPACE_ID, MAX_HIBERNATE_MAPPING_PUBLICATION, MDATE_FIELD, PSTATUS_FIELD, ROW_ID_FIELD, SCROLL_FETCH_SIZE, WORKFLOW_ID_FIELD, WORKSPACE_ID_FIELD
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
Constructor and Description |
---|
HibernateUtil() |
Modifier and Type | Method and Description |
---|---|
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 org.hibernate.criterion.Criterion |
buildCollectionCriterion(java.lang.Class clazz,
java.lang.String property,
java.lang.Object value,
org.hibernate.type.Type valueType)
Apply a constraint on a value of the collection of the given clazz.
|
static org.hibernate.criterion.Criterion |
buildCollectionCriterion(java.lang.Class clazz,
java.lang.String property,
java.lang.String value)
Apply a constraint on a value of the collection of the given clazz.
|
static org.hibernate.criterion.Criterion |
buildCollectionCriterion(java.lang.String entityTable,
java.lang.String idColumn,
java.lang.String collectionTable,
java.lang.String itemIdColumn,
java.lang.String valueColumn,
java.lang.Object value,
org.hibernate.type.Type valueType)
Apply a constraint on a value of the collection of the given entity.
|
static java.lang.String |
buildJcmsId(java.lang.Class<?> clazz,
java.lang.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 <T> org.hibernate.Query |
buildQueryCollection(java.lang.Class<? extends T> clazz,
java.lang.String property,
java.lang.Object value,
boolean retreiveRowId)
Returns the Hibernate query to search the instance of the given class with the collection property matching the given value.
|
static org.hibernate.Criteria |
buildQueryCriteria(org.hibernate.Session session,
java.lang.Class<?> clazz,
java.lang.String[] properties,
java.lang.Object[] values,
java.lang.String orderBy,
int firstResult,
int maxResults)
Retrieves the result(s) matching the specified parameters.
|
static org.hibernate.Criteria |
buildQueryCriteria(org.hibernate.Session session,
java.lang.Class<?> clazz,
java.lang.String[] properties,
java.lang.Object[] values,
java.lang.String orderBy,
int firstResult,
int maxResults,
boolean cacheable)
Retrieves the result(s) matching the specified parameters.
|
static java.lang.String |
checkSQLInjection(java.lang.String... strings)
Checks if the given strings may contains an SQL injection.
|
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 boolean |
dateEquals(java.util.Date date1,
java.util.Date date2)
Check if both date are equals, skipping any difference due to Timestamp implemantation.
|
static void |
delete(DBData data)
Deletes the specified object in the database.
|
static void |
delete(DBData data,
boolean cleanSession)
Deletes the specified object in the database.
|
static void |
delete(java.lang.String id)
Deletes the specified object in the database.
|
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String[] properties,
java.lang.Object[] values)
Delete all object matching the specified parameters.
|
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String[] properties,
java.lang.Object[] values,
boolean cleanSession)
Delete all object matching the specified parameters.
|
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String[] properties,
java.lang.String[] values)
Deprecated.
this method only supports string properties, use
deleteQuery(Class, String[], Object[]) |
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String[] properties,
java.lang.String[] values,
boolean cleanSession)
Deprecated.
this method only supports string properties, use
deleteQuery(Class, String[], Object[], boolean) |
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.Object value)
Delete all object matching the specified parameters.
|
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.Object value,
boolean cleanSession)
Delete all object matching the specified parameters.
|
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.String value)
Deprecated.
this method only supports string property, use
deleteQuery(Class, String, Object) |
static int |
deleteQuery(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.String value,
boolean cleanSession)
Deprecated.
this method only supports string properties, use
deleteQuery(Class, String, Object, boolean) |
static void |
evict(java.lang.Object obj)
Removes this instance from the Hibernate session cache to avoid automatic persistence by dirty checking.
|
static java.util.List |
execQuery(org.hibernate.Query query)
Execute the specified hibernate query using the current thread's session.
|
static java.util.List |
execQuery(java.lang.String hql)
Execute the specified hibernate query using the current thread's session.
|
static java.util.List |
execQuery(java.lang.String hql,
int firstResult,
int maxResults)
Execute the specified hibernate query using the current thread's session.
|
static java.util.Iterator |
execQueryIterator(org.hibernate.Query query)
Execute the specified hibernate query using the current thread's session.
|
static java.util.Iterator |
execQueryIterator(java.lang.String hql)
Execute the specified hibernate query using the current thread's session.
|
static java.lang.Object |
execQueryUnique(java.lang.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(java.lang.String hql)
Execute the update or delete HQL statement.
|
static java.util.LinkedHashMap<java.lang.String,java.lang.Float> |
filterSearchResultByIdList(java.util.LinkedHashMap<java.lang.String,java.lang.Float> resultMap,
java.util.List<java.lang.String> idList)
Filters the lucene search result with the given list of publication's identifier.
|
static java.util.Set<java.util.Set<java.lang.Long>> |
getBatchSet(java.util.Collection<java.lang.Long> idColl,
int batchSize)
Convenient method to convert a Collection of rowId into many smaller
collections, allowing batch select using method
getDBDataList(Class, Collection) . |
static Data |
getCurrentData(java.lang.String id)
Return the current persisted state of the Data with the given id.
|
static java.util.Date |
getCurrentDate()
Returns a new date.
|
static DBData |
getCurrentDBData(java.lang.String id)
Return the current persisted state of the DBData with the given id.
|
static java.lang.Object |
getCurrentObject(java.lang.Class clazz,
java.lang.Long rowId)
Return the current persisted state of the object with the given rowId.
|
static Data |
getData(java.lang.String id)
Retrieves the Data bound to the specified jcms id from the database.
|
protected static java.util.Date |
getDate(java.util.Date date)
Return a new java.util.Date if the specified Date is a timestamp, otherwise return the date as is.
|
static DBData |
getDBData(java.lang.String id)
Retrieves the DBData bound to the specified jcms id from the database.
|
static <T> java.util.Iterator<T> |
getDBDataIterator(java.lang.Class<T> clazz)
Retrieve all Objects of the specified class from the database.
|
static <T> java.util.List<T> |
getDBDataList(java.lang.Class<T> clazz)
Retrieve all Objects of the specified class from the database (limited to maxResults).
|
static <T> java.util.List<T> |
getDBDataList(java.lang.Class<T> clazz,
java.util.Collection<java.lang.Long> rowIdColl)
Retrieve a List of Objects from their Class and rowId.
|
static <T> java.util.List<T> |
getDBDataList(java.lang.Class<T> clazz,
int firstResult,
int maxResults)
Retrieve all Objects of the specified class from the database.
|
static java.lang.Object |
getObject(java.lang.Class clazz,
java.lang.Long rowId)
Retrieves the Object of the specified class and using the specified id.
|
static java.lang.Object |
getObject(org.hibernate.Session session,
java.lang.Class clazz,
java.lang.Long rowId)
Retrieves the Object of the specified class and using the specified id in the given session.
|
static java.lang.Long |
getRowId(java.lang.String id)
Retrieve the row id from a DBData id
|
static java.util.Set<java.util.Set<java.lang.Long>> |
getRowIdBatchSet(java.util.Collection<java.lang.String> idColl,
int batchSize)
Convenient method to convert a Collection of id into many smaller
collections, allowing batch select using method
getDBDataList(Class, Collection) . |
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 void |
handleTimeoutException(java.lang.Throwable th)
Handle time out exception
|
static boolean |
isDBDataJcmsId(java.lang.String id) |
static boolean |
isVarcharInBytes()
Returns true if the database count varchar length in bytes (i.e. varchar(255) = 255 bytes, not 255 UTF-8 chars !)
|
static java.lang.Object[] |
parseJcmsId(java.lang.String id)
Returns the 2 component of the given JCMS ID.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.util.Map<java.lang.String,java.lang.Object> paramsMap)
Retrieves all object matching the specified parameters.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.util.Map<java.lang.String,java.lang.Object> paramsMap,
java.lang.String orderBy)
Retrieves all object matching the specified parameters.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.util.Map<java.lang.String,java.lang.Object> paramsMap,
java.lang.String orderBy,
int firstResult,
int maxResults)
Retrieves all object matching the specified parameters.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.lang.String orderBy)
Retrieves all object of the specified Class.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.lang.String[] properties,
java.lang.Object[] values)
Retrieves all object matching the specified parameters.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.lang.String[] properties,
java.lang.Object[] values,
java.lang.String orderBy)
Retrieves all object matching the specified parameters.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.lang.String property,
java.lang.Object value)
Retrieves all object matching the specified parameters.
|
static <T> java.util.List<T> |
query(java.lang.Class<? extends T> clazz,
java.lang.String property,
java.lang.Object value,
java.lang.String orderBy)
Retrieves all object matching the specified parameters.
|
static <T> java.util.List<T> |
query(java.lang.Class<T> clazz)
Retrieves all object of the specified Class.
|
static <T> java.util.List<T> |
queryCollection(java.lang.Class<? extends T> clazz,
java.lang.String property,
java.lang.Object value)
Retreives the instance of the given class with the collection property matching the given value.
|
static <T> java.util.List<java.lang.Long> |
queryCollectionRowId(java.lang.Class<? extends T> clazz,
java.lang.String property,
java.lang.Object value)
Retreives the instance of the given class with the collection property matching the given value.
|
static int |
queryCount(java.lang.Class<?> clazz)
Returns the count of objects matching the given class.
|
static int |
queryCount(java.lang.Class<?> clazz,
org.hibernate.criterion.Criterion criterion)
Returns the count of objects matching the given class with the given criterion.
|
static int |
queryCount(java.lang.Class<?> clazz,
java.lang.String[] properties,
java.lang.Object[] values)
Returns the count of objects matching the given class with the given criteria.
|
static int |
queryCount(java.lang.Class<?> clazz,
java.lang.String property,
java.lang.Object value)
Returns the count of objects matching the given class with the given criteria.
|
static int |
queryCount(org.hibernate.Criteria criteria)
Returns the count of objects matching the given criteria.
|
static PageResult<Publication> |
queryPublication(PublicationCriteria pubCriteria)
Returns a list of publications in the database matching the given criteria.
|
static <T> T |
queryUnique(java.lang.Class<? extends T> clazz,
java.lang.String[] properties,
java.lang.Object[] values)
Retrieves a unique object matching the specified parameters.
|
static <T> T |
queryUnique(java.lang.Class<? extends T> clazz,
java.lang.String[] properties,
java.lang.Object[] values,
java.lang.String orderBy)
Retrieves a unique object matching the specified parameters.
|
static <T> T |
queryUnique(java.lang.Class<? extends T> clazz,
java.lang.String property,
java.lang.Object value)
Retrieves a unique object matching the specified parameters.
|
static void |
removeSecondLevelCacheEntry(java.lang.String entityName,
java.lang.Long rowId)
Removes an
DBData from the second level cache. |
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(java.lang.Object obj)
Saves or updates the specified Object in the database.
|
static org.hibernate.ScrollableResults |
scroll(java.lang.Class clazz)
Scroll over a class.
|
static org.hibernate.ScrollableResults |
scroll(java.lang.Class clazz,
org.hibernate.ScrollMode scrollMode)
Scroll over a class with a given scroll mode.
|
static <T> org.hibernate.ScrollableResults |
scrollCollection(java.lang.Class<? extends T> clazz,
java.lang.String property,
java.lang.Object value,
boolean retreiveRowId)
Scroll the instance of the given class with the collection property matching the given value.
|
static boolean |
supportDateMillis()
Returns true if the database supports millis for date.
|
static boolean |
supportFullJoin()
Returns true if the database supports full join.
|
static java.lang.String |
truncateVarchar(java.lang.String value)
Returns the value truncated to the varchar length (i.e. 255 chars)
|
public static final java.lang.String REVISION
public static final int DEFAULT_BATCH_SIZE
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 java.lang.String buildJcmsId(java.lang.Class<?> clazz, java.lang.Long rowId)
clazz
- the Class of the object (required)rowId
- the row id in the database table (required)java.lang.IllegalArgumentException
- if clazz or rowId is nullpublic static boolean isDBDataJcmsId(java.lang.String id)
public static java.lang.Object execQueryUnique(java.lang.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 languagepublic static java.util.List execQuery(java.lang.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 languagepublic static java.util.List execQuery(java.lang.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 java.util.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 querypublic static java.util.Iterator execQueryIterator(java.lang.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 languagepublic static java.util.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 querypublic static int execUpdate(java.lang.String hql)
hql
- the query as a string using the hibernate query languagepublic static int execUpdate(org.hibernate.Query query)
query
- the Hibernate querypublic static <T> java.util.List<T> query(java.lang.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.
T
- Hibernate class corresponding to a table in the databaseclazz
- the Class of object to retrieve, required must not be nulljava.lang.IllegalArgumentException
- if clazz is nullpublic static <T> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.lang.String orderBy)
Example to retrieve all ArchivedPublication order by rowId.
HibernateUtil.query(ArchivedPublication.class, "rowId");
T
- Hibernate class corresponding to a table in the databaseclazz
- the Class of object to retrieve, required must not be nullorderBy
- the names of the fields to be used to order the results (comma separeted). You can append "asc" or "desc" to indicate the order direction. Default is ascending.java.lang.IllegalArgumentException
- if clazz is nullpublic static <T> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.lang.String property, java.lang.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.
T
- Hibernate class corresponding to a table in the databaseclazz
- 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.java.lang.IllegalArgumentException
- if clazz is nullpublic static <T> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.lang.String property, java.lang.Object value, java.lang.String orderBy)
Example to retrieve all ExtraDBData of a member, order by extradbdata name
HibernateUtil.query(ExtraDBData.class, "dataId", mbr.getId(), "extraName");
T
- Hibernate class corresponding to a table in the databaseclazz
- 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 names of the fields to be used to order the results (comma separated). You can append "asc" or "desc" to indicate the order direction. Default is ascending.java.lang.IllegalArgumentException
- if clazz is nullpublic static <T> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.lang.String[] properties, java.lang.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
T
- Hibernate class corresponding to a table in the databaseclazz
- 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.java.lang.IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.lang.String[] properties, java.lang.Object[] values, java.lang.String orderBy)
T
- Hibernate class corresponding to a table in the databaseclazz
- 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 names of the fields to be used to order the results (comma separated). You can append "asc" or "desc" to indicate the order direction. Default is ascending.java.lang.IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> T queryUnique(java.lang.Class<? extends T> clazz, java.lang.String property, java.lang.Object value)
T
- Hibernate class corresponding to a table in the databaseclazz
- 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.java.lang.IllegalArgumentException
- if clazz is nullpublic static <T> T queryUnique(java.lang.Class<? extends T> clazz, java.lang.String[] properties, java.lang.Object[] values)
T
- Hibernate class corresponding to a table in the databaseclazz
- 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.java.lang.IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> T queryUnique(java.lang.Class<? extends T> clazz, java.lang.String[] properties, java.lang.Object[] values, java.lang.String orderBy)
T
- Hibernate class corresponding to a table in the databaseclazz
- 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 names of the fields to be used to order the results (comma separated). You can append "asc" or "desc" to indicate the order direction. Default is ascending.java.lang.IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.util.Map<java.lang.String,java.lang.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
T
- Hibernate class corresponding to a table in the databaseclazz
- 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> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.util.Map<java.lang.String,java.lang.Object> paramsMap, java.lang.String orderBy)
T
- Hibernate class corresponding to a table in the databaseclazz
- 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 names of the fields to be used to order the results (comma separated). You can append "asc" or "desc" to indicate the order direction. Default is ascending.java.lang.IllegalArgumentException
- if clazz is nullpublic static <T> java.util.List<T> query(java.lang.Class<? extends T> clazz, java.util.Map<java.lang.String,java.lang.Object> paramsMap, java.lang.String orderBy, int firstResult, int maxResults)
T
- Hibernate class corresponding to a table in the databaseclazz
- 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 names of the fields to be used to order the results (comma separated). 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).java.lang.IllegalArgumentException
- if clazz is nullpublic static void handleTimeoutException(java.lang.Throwable th)
th
- the throwablepublic static org.hibernate.Criteria buildQueryCriteria(org.hibernate.Session session, java.lang.Class<?> clazz, java.lang.String[] properties, java.lang.Object[] values, java.lang.String orderBy, int firstResult, int maxResults)
Returns either a List or an object depending on value of the unique parameter.
session
- the Hibernate session to useclazz
- 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 names of the fields to be used to order the results (comma separated). 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).java.lang.IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static org.hibernate.Criteria buildQueryCriteria(org.hibernate.Session session, java.lang.Class<?> clazz, java.lang.String[] properties, java.lang.Object[] values, java.lang.String orderBy, int firstResult, int maxResults, boolean cacheable)
Returns either a List or an object depending on value of the unique parameter.
session
- the Hibernate session to useclazz
- 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 names of the fields to be used to order the results (comma separated). 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).cacheable
- if true set the criteria cacheable.java.lang.IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> java.util.List<T> queryCollection(java.lang.Class<? extends T> clazz, java.lang.String property, java.lang.Object value)
T
- Hibernate class corresponding to a table in the databaseclazz
- the Class of object to retrieve, required must not be nullproperty
- the collection field namevalue
- the value to matchpublic static <T> java.util.List<java.lang.Long> queryCollectionRowId(java.lang.Class<? extends T> clazz, java.lang.String property, java.lang.Object value)
T
- Hibernate class corresponding to a table in the databaseclazz
- the Class of object to retrieve, required must not be nullproperty
- the collection field namevalue
- the value to matchpublic static <T> org.hibernate.ScrollableResults scrollCollection(java.lang.Class<? extends T> clazz, java.lang.String property, java.lang.Object value, boolean retreiveRowId)
T
- Hibernate class corresponding to a table in the databaseclazz
- the Class of object to retrieve, required must not be nullproperty
- the collection field namevalue
- the value to matchretreiveRowId
- if true returns rowId instead of objectpublic static <T> org.hibernate.Query buildQueryCollection(java.lang.Class<? extends T> clazz, java.lang.String property, java.lang.Object value, boolean retreiveRowId)
T
- Hibernate class corresponding to a table in the databaseclazz
- the Class of object to retrieve, required must not be nullproperty
- the collection field namevalue
- the value to matchretreiveRowId
- if true returns rowId instead of objectpublic static int deleteQuery(java.lang.Class<?> clazz, java.lang.String property, java.lang.String value)
deleteQuery(Class, String, Object)
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, requiredpublic static int deleteQuery(java.lang.Class<?> clazz, java.lang.String property, java.lang.Object 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, requiredpublic static int deleteQuery(java.lang.Class<?> clazz, java.lang.String[] properties, java.lang.String[] values)
deleteQuery(Class, String[], Object[])
Example to delete all ReaderTracker of a publication for a specific Member.
HibernateUtil.deleteQuery(ReaderTracker.class, new String[] { "publicationId", "authorId"}, new String[] { pub.getId(), mbr.getId() }, true);
clazz
- the Class of object to retrieve and delete, requiredproperties
- the fields name, requiredvalues
- the value of the field to match, requiredpublic static int deleteQuery(java.lang.Class<?> clazz, java.lang.String[] properties, java.lang.Object[] values)
Example to delete all ReaderTracker of a publication when the access count is 1
HibernateUtil.deleteQuery(ReaderTracker.class, new String[] { "publicationId", "accessCount" }, new Object[] { pub.getId(), 1}, true);
clazz
- the Class of object to retrieve and delete, requiredproperties
- the fields name, requiredvalues
- the value of the field to match, requiredpublic static int deleteQuery(java.lang.Class<?> clazz, java.lang.String property, java.lang.String value, boolean cleanSession)
deleteQuery(Class, String, Object, boolean)
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, requiredcleanSession
- if true clean the session (i.e. flush/clear). Should be true unless you have others DB access to perform after this call.public static int deleteQuery(java.lang.Class<?> clazz, java.lang.String property, java.lang.Object value, boolean cleanSession)
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, requiredcleanSession
- if true clean the session (i.e. flush/clear). Should be true unless you have others DB access to perform after this call.public static int deleteQuery(java.lang.Class<?> clazz, java.lang.String[] properties, java.lang.String[] values, boolean cleanSession)
deleteQuery(Class, String[], Object[], boolean)
Example to delete all ReaderTracker of a publication for a specific Member.
HibernateUtil.deleteQuery(ReaderTracker.class, new String[] { "publicationId", "authorId" }, new String[] { pub.getId(), mbr.getId()}, true);
clazz
- the Class of object to retrieve and delete, requiredproperties
- the fields name, requiredvalues
- the value of the field to match, requiredcleanSession
- if true clean the session (i.e. flush/clear). Should be true unless you have others DB access to perform after this call.public static int deleteQuery(java.lang.Class<?> clazz, java.lang.String[] properties, java.lang.Object[] values, boolean cleanSession)
Example to delete all ReaderTracker of a publication when the access count is 1
HibernateUtil.deleteQuery(ReaderTracker.class, new String[] { "publicationId", "accessCount" }, new Object[] { pub.getId(), 1}, true);
clazz
- the Class of object to retrieve and delete, requiredproperties
- the fields name, requiredvalues
- the value of the field to match, requiredcleanSession
- if true clean the session (i.e. flush/clear). Should be true unless you have others DB access to perform after this call.public static <T> java.util.List<T> getDBDataList(java.lang.Class<T> clazz)
T
- any DB typeclazz
- the Class of object to retrieve, requiredpublic static <T> java.util.List<T> getDBDataList(java.lang.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> java.util.List<T> getDBDataList(java.lang.Class<T> clazz, java.util.Collection<java.lang.Long> rowIdColl)
Warning : Only use this method with a specific type class *WITHOUT ANY* descendant.
Using this method with a "super type" (such as Publication.class) will result in a polymorphic query
and may result in different instance of DBData with same row id being returned.
For example, with arguments clazz=Publication.class and rowIdColl={42}
you would retrive 42_MyType, 42_OtherType which is not usually expected !
This method is only meant to work on one specific type (without subtype!)
T
- any DB typeclazz
- the Class of object to retrieve, required DO NOT use a super classrowIdColl
- a collection of rowIdpublic static <T> java.util.Iterator<T> getDBDataIterator(java.lang.Class<T> clazz)
T
- any DB typeclazz
- the Class of object to retrieve, requiredpublic static java.util.Set<java.util.Set<java.lang.Long>> getRowIdBatchSet(java.util.Collection<java.lang.String> idColl, int batchSize)
getDBDataList(Class, Collection)
.
Example :
// HibernateUtil.beginTransaction(); already done HibernateSessionFilter for standard HTTP request // Retrieve DBMember id list from caddy List<String> dbMemberIdList = getCaddy().getDBMemberList(); // Process DBMember in batch Set<Set<Long>> batchSet = HibernateUtil.getRowIdBatchSet(dbMemberIdList, -1) for (Set<Long> mbrRowIdSet : batchSet) { List<DBMember> dbmbrList = HibernateUtil.getDBDataList(DBMember.class, mbrRowIdSet); for (DBMember dbmbr : dbmbrList) { // dbmbr.set... HibernateUtil.save(dbmbr); } // Commit transaction on end of batch HibernateUtil.commitTransaction(); HibernateUtil.beginTransaction(); } // HibernateUtil.commitTransaction(); already done HibernateSessionFilter for standard HTTP request
Warning : Only use this method with a collection of *only one without any descendant* type (eg 42_MyType, 666_MyType) Using this method with mixed type in source collection (eg 42_MyType, 66_OtherType, 42_OtherType) may result in conflicting rowid. This method is only meant to work on one specific type (excluding its subtype!).
idColl
- a collection of jcmsid for DBData (e.g 42_YourType)batchSize
- the size of subset to be create
(defaut value DEFAULT_BATCH_SIZE
is used if specified valued is less or equal 1)public static java.util.Set<java.util.Set<java.lang.Long>> getBatchSet(java.util.Collection<java.lang.Long> idColl, int batchSize)
getDBDataList(Class, Collection)
.idColl
- a collection of rowId for DBDatabatchSize
- the size of subset to be create
(defaut value DEFAULT_BATCH_SIZE
is used if specified value is less or equal 1)getRowIdBatchSet(Collection, int)
public static int queryCount(java.lang.Class<?> clazz)
clazz
- the classpublic static int queryCount(java.lang.Class<?> clazz, java.lang.String property, java.lang.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(java.lang.Class<?> clazz, java.lang.String[] properties, java.lang.Object[] values)
clazz
- the classproperties
- an array of field name.values
- an array of values of the field to match.public static int queryCount(java.lang.Class<?> clazz, org.hibernate.criterion.Criterion criterion)
clazz
- the classcriterion
- the criterionpublic static int queryCount(org.hibernate.Criteria criteria)
criteria
- the criteriapublic static PageResult<Publication> queryPublication(PublicationCriteria pubCriteria)
pubCriteria
- the PublicationCriteria (required, must not be null)java.lang.IllegalArgumentException
- if pubCriteria is nullpublic static java.util.LinkedHashMap<java.lang.String,java.lang.Float> filterSearchResultByIdList(java.util.LinkedHashMap<java.lang.String,java.lang.Float> resultMap, java.util.List<java.lang.String> idList)
resultMap
- a given map of JCMS id with score associated.idList
- the list of publication's identifieridList
and respect its order.public static org.hibernate.criterion.Criterion buildAndCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2)
c1
- a criterionc2
- a criterionpublic static org.hibernate.criterion.Criterion buildOrCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2)
c1
- a criterionc2
- a criterionpublic static org.hibernate.criterion.Criterion buildCollectionCriterion(java.lang.Class clazz, java.lang.String property, java.lang.String value)
clazz
- the entity classproperty
- the name of the collection propertyvalue
- the searched valuepublic static org.hibernate.criterion.Criterion buildCollectionCriterion(java.lang.Class clazz, java.lang.String property, java.lang.Object value, org.hibernate.type.Type valueType)
clazz
- the entity class. This class must be an Hibernate mapped class.property
- the name of the collection propertyvalue
- the searched valuevalueType
- the type of the value (e.g. Hibernate.STRING)public static org.hibernate.criterion.Criterion buildCollectionCriterion(java.lang.String entityTable, java.lang.String idColumn, java.lang.String collectionTable, java.lang.String itemIdColumn, java.lang.String valueColumn, java.lang.Object value, org.hibernate.type.Type valueType)
entityTable
- the entity table nameidColumn
- the ID column name of the entity tablecollectionTable
- the collection table nameitemIdColumn
- the ID column name of the collection tablevalueColumn
- the name of the value columnvalue
- the searched valuevalueType
- the type of the value (e.g. Hibernate.STRING)public static java.lang.String checkSQLInjection(java.lang.String... strings)
strings
- an array of Stringpublic static java.lang.Object getObject(java.lang.Class clazz, java.lang.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" columnpublic static java.lang.Object getObject(org.hibernate.Session session, java.lang.Class clazz, java.lang.Long rowId)
session
- the session, must not be null (otherwise, null is returned)clazz
- the Class (or super class in case of inheritance) of the object to retrieve, must not be nullrowId
- the primary key value of the object or if could not be found, the value of the "id" column, must not be nullpublic static DBData getDBData(java.lang.String id)
id
- the JCMS id of this data (e.g. 1234_WFNOTE)public static java.lang.Object[] parseJcmsId(java.lang.String id)
id
- the JCMS idpublic static java.lang.Long getRowId(java.lang.String id)
id
- the full DBData id as returned by dbdata.getId()
(e.g 42_YourType)public static Data getData(java.lang.String id)
id
- the JCMS id of this data (e.g. 1234_WFNOTE)public static java.lang.Object getCurrentObject(java.lang.Class clazz, java.lang.Long rowId)
clazz
- the class of the objectrowId
- the rowId of the objectpublic static DBData getCurrentDBData(java.lang.String id)
id
- the JCMS idpublic static Data getCurrentData(java.lang.String id)
id
- the JCMS idprotected static java.util.Date getDate(java.util.Date date)
date
- the date object to checkpublic static boolean dateEquals(java.util.Date date1, java.util.Date date2)
date1
- the first Date to comparedate2
- the second Date to comparepublic static void save(Data data)
data
- the Data to be saved or updatedpublic static void save(java.lang.Object obj)
obj
- the object to be saved or updatedpublic static boolean supportDateMillis()
public static boolean supportFullJoin()
public static boolean isVarcharInBytes()
public static java.util.Date getCurrentDate()
public static void evict(java.lang.Object obj)
obj
- the object to be removedSession.evict(Object)
public static void delete(DBData data, boolean cleanSession)
data
- the data to be deletedcleanSession
- if true clean the sessionpublic static void delete(DBData data)
data
- the data to be deletedpublic static void delete(java.lang.String id)
id
- the identifier of the DBData to be deletedpublic static void clearCache()
public static void removeSecondLevelCacheEntry(java.lang.String entityName, java.lang.Long rowId)
DBData
from the second level cache.
Synchronization is handled within the method.
entityName
- the id of the DBData to removerowId
- the rowId of the DBData to removejava.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
public static org.hibernate.ScrollableResults scroll(java.lang.Class clazz)
clazz
- the class to scroll over.public static org.hibernate.ScrollableResults scroll(java.lang.Class clazz, org.hibernate.ScrollMode scrollMode)
clazz
- the class to scroll over.scrollMode
- Indicates the type of underlying database cursor to request.public static java.lang.String truncateVarchar(java.lang.String value)
value
- the value to be truncatedCopyright © 2001-2010 Jalios SA. All Rights Reserved.