|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jalios.jcms.db.HibernateUtil
public class HibernateUtil
Helper class providing static methods to perform common database operation using hibertnate
Field Summary | |
---|---|
static int |
DEFAULT_BATCH_SIZE
|
static String |
REVISION
|
Fields inherited from interface com.jalios.util.JaliosConstants |
---|
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 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 org.hibernate.criterion.Criterion |
buildCollectionCriterion(Class clazz,
String property,
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(Class clazz,
String property,
String value)
Apply a constraint on a value of the collection of the given clazz. |
|
static org.hibernate.criterion.Criterion |
buildCollectionCriterion(String entityTable,
String idColumn,
String collectionTable,
String itemIdColumn,
String valueColumn,
Object value,
org.hibernate.type.Type valueType)
Apply a constraint on a value of the collection of the given entity. |
|
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
|
buildQueryCollection(Class<? extends T> clazz,
String property,
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,
Class<?> clazz,
String[] properties,
Object[] values,
String orderBy,
int firstResult,
int maxResults)
Retrieves the result(s) matching the specified parameters. |
|
static String |
checkSQLInjection(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 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(String id)
Deletes the specified object in the database. |
|
static int |
deleteQuery(Class<?> clazz,
String[] properties,
Object[] values)
Delete all object matching the specified parameters. |
|
static int |
deleteQuery(Class<?> clazz,
String[] properties,
Object[] values,
boolean cleanSession)
Delete all object matching the specified parameters. |
|
static int |
deleteQuery(Class<?> clazz,
String[] properties,
String[] values)
Deprecated. this method only supports string properties, use deleteQuery(Class, String[], Object[]) |
|
static int |
deleteQuery(Class<?> clazz,
String[] properties,
String[] values,
boolean cleanSession)
Deprecated. this method only supports string properties, use deleteQuery(Class, String[], Object[], boolean) |
|
static int |
deleteQuery(Class<?> clazz,
String property,
Object value)
Delete all object matching the specified parameters. |
|
static int |
deleteQuery(Class<?> clazz,
String property,
Object value,
boolean cleanSession)
Delete all object matching the specified parameters. |
|
static int |
deleteQuery(Class<?> clazz,
String property,
String value)
Deprecated. this method only supports string property, use deleteQuery(Class, String, Object) |
|
static int |
deleteQuery(Class<?> clazz,
String property,
String value,
boolean cleanSession)
Deprecated. this method only supports string properties, use deleteQuery(Class, String, Object, boolean) |
|
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 LinkedHashMap<String,Float> |
filterSearchResultByIdList(LinkedHashMap<String,Float> resultMap,
List<String> idList)
Filters the lucene search result with the given list of publication's identifier. |
|
static Set<Set<Long>> |
getBatchSet(Collection<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(String id)
Return the current persisted state of the Data with the given id. |
|
static Date |
getCurrentDate()
Returns a new date. |
|
static DBData |
getCurrentDBData(String id)
Return the current persisted state of the DBData with the given id. |
|
static Object |
getCurrentObject(Class clazz,
Long rowId)
Return the current persisted state of the object with the given rowId. |
|
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,
Collection<Long> rowIdColl)
Retrieve a List of Objects from their Class and rowId. |
|
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 Object |
getObject(org.hibernate.Session session,
Class clazz,
Long rowId)
Retrieves the Object of the specified class and using the specified id in the given session. |
|
static Long |
getRowId(String id)
Retrieve the row id from a DBData id |
|
static Set<Set<Long>> |
getRowIdBatchSet(Collection<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(Throwable th)
Handle time out exception |
|
static boolean |
isDBDataJcmsId(String id)
|
|
static Object[] |
parseJcmsId(String id)
Returns the 2 component of the given JCMS 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
|
queryCollection(Class<? extends T> clazz,
String property,
Object value)
Retreives the instance of the given class with the collection property matching the given value. |
|
static
|
queryCollectionRowId(Class<? extends T> clazz,
String property,
Object value)
Retreives the instance of the given class with the collection property matching the given value. |
|
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 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
|
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 |
removeSecondLevelCacheEntry(String entityName,
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(Object obj)
Saves or updates the specified Object in the database. |
|
static org.hibernate.ScrollableResults |
scroll(Class clazz)
Scroll over a class. |
|
static org.hibernate.ScrollableResults |
scroll(Class clazz,
org.hibernate.ScrollMode scrollMode)
Scroll over a class with a given scroll mode. |
|
static
|
scrollCollection(Class<? extends T> clazz,
String property,
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. |
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
public static final int DEFAULT_BATCH_SIZE
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.
T
- Hibernate class corresponding to a table in the databaseclazz
- 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");
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.
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.
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.
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");
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.
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
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.
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)
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.
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)
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.
IllegalArgumentException
- if clazz is nullpublic static <T> T queryUnique(Class<? extends T> clazz, String[] properties, 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.
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)
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.
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
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> List<T> query(Class<? extends T> clazz, Map<String,Object> paramsMap, 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.
IllegalArgumentException
- if clazz is nullpublic static <T> List<T> query(Class<? extends T> clazz, Map<String,Object> paramsMap, 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).
IllegalArgumentException
- if clazz is nullpublic static void handleTimeoutException(Throwable th)
th
- the throwablepublic static org.hibernate.Criteria buildQueryCriteria(org.hibernate.Session session, Class<?> clazz, String[] properties, Object[] values, 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).
IllegalArgumentException
- if clazz is null or if propreties and values are not of the same lengthpublic static <T> List<T> queryCollection(Class<? extends T> clazz, String property, 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 match
public static <T> List<Long> queryCollectionRowId(Class<? extends T> clazz, String property, 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 match
public static <T> org.hibernate.ScrollableResults scrollCollection(Class<? extends T> clazz, String property, 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 match
public static <T> org.hibernate.Query buildQueryCollection(Class<? extends T> clazz, String property, 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 match
public static int deleteQuery(Class<?> clazz, String property, 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, required
public static int deleteQuery(Class<?> clazz, String property, 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, required
public static int deleteQuery(Class<?> clazz, String[] properties, 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, required
public static int deleteQuery(Class<?> clazz, String[] properties, 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, required
public static int deleteQuery(Class<?> clazz, String property, 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(Class<?> clazz, String property, 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(Class<?> clazz, String[] properties, 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(Class<?> clazz, String[] properties, 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> 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> List<T> getDBDataList(Class<T> clazz, Collection<Long> rowIdColl)
T
- any DB typeclazz
- the Class of object to retrieve, requiredrowIdColl
- a collection of rowId
public static <T> Iterator<T> getDBDataIterator(Class<T> clazz)
T
- any DB typeclazz
- the Class of object to retrieve, required
public static Set<Set<Long>> getRowIdBatchSet(Collection<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
idColl
- a collection of jcmsid for DBData (e.g 42_Review)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 Set<Set<Long>> getBatchSet(Collection<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 valued is less or equal 1)
getRowIdBatchSet(Collection, int)
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 int queryCount(org.hibernate.Criteria criteria)
criteria
- the criteria
public static PageResult<Publication> queryPublication(PublicationCriteria pubCriteria)
pubCriteria
- the PublicationCriteria (required, must not be null)
IllegalArgumentException
- if pubCriteria is nullpublic static LinkedHashMap<String,Float> filterSearchResultByIdList(LinkedHashMap<String,Float> resultMap, List<String> idList)
resultMap
- a given map of JCMS id with score associated.idList
- the list of publication's identifier
idList
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 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 org.hibernate.criterion.Criterion buildCollectionCriterion(Class clazz, String property, String value)
clazz
- the entity classproperty
- the name of the collection propertyvalue
- the searched value
public static org.hibernate.criterion.Criterion buildCollectionCriterion(Class clazz, String property, 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(String entityTable, String idColumn, String collectionTable, String itemIdColumn, String valueColumn, 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 String checkSQLInjection(String... strings)
strings
- an array of String
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 Object getObject(org.hibernate.Session session, Class clazz, 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 null
public static DBData getDBData(String id)
id
- the JCMS id of this data (e.g. 1234_WFNOTE)
public static Object[] parseJcmsId(String id)
id
- the JCMS id
public static Long getRowId(String id)
id
- the full DBData id as returned by dbdata.getId()
(e.g 42_Review)
public static Data getData(String id)
id
- the JCMS id of this data (e.g. 1234_WFNOTE)
public static Object getCurrentObject(Class clazz, Long rowId)
clazz
- the class of the objectrowId
- the rowId of the object
public static DBData getCurrentDBData(String id)
id
- the JCMS id
public static Data getCurrentData(String id)
id
- the JCMS id
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 boolean supportDateMillis()
public static boolean supportFullJoin()
public static Date getCurrentDate()
public static void evict(Object obj)
obj
- Session.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(String id)
id
- the identifier of the DBData to be deletedpublic static void clearCache()
public static void removeSecondLevelCacheEntry(String entityName, Long rowId)
DBData
from the second level cache.
Synchronization is handled within the method.
entityName
- the id of the DBData to remove in the second level cache.
IllegalStateException
- if the cache is not Status.STATUS_ALIVE
public static org.hibernate.ScrollableResults scroll(Class clazz)
clazz
- the class to scroll over.
public static org.hibernate.ScrollableResults scroll(Class clazz, org.hibernate.ScrollMode scrollMode)
clazz
- the class to scroll over.scrollMode
- Indicates the type of underlying database cursor to request.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |