Class HibernateUtil
- All Implemented Interfaces:
DBConstants,JaliosConstants
- Since:
- jcms-6.0
-
Field Summary
FieldsFields inherited from interface com.jalios.jcms.db.DBConstants
ALL_CATEGORIES_SET_FIELD, ATTACH_WS_SET_FIELD, AUTH_GRP_SET_FIELD, AUTH_MBR_SET_FIELD, AUTHOR_ID_FIELD, CATEGORIES_SET_FIELD, CDATE_FIELD, CHANNEL_JCMSDB_PROP, CLASSIFICATION_LEVEL_FIELD, DBDATA_URID, EXTENDED_READ_RIGHTS, HAS_ATTACH_WS_FIELD, HAS_NO_READ_RIGHTS, HIBERNATE_MAPPING_ADATE, HIBERNATE_MAPPING_AUTHOR, HIBERNATE_MAPPING_CDATE, HIBERNATE_MAPPING_EDATE, HIBERNATE_MAPPING_HAS_ATTACH_WS, HIBERNATE_MAPPING_HASNOREADRIGHTS, HIBERNATE_MAPPING_MAININSTANCE_ID, HIBERNATE_MAPPING_MAJORVERSION, HIBERNATE_MAPPING_MDATE, HIBERNATE_MAPPING_MERGE_DATE, HIBERNATE_MAPPING_MERGE_ID, HIBERNATE_MAPPING_MINORVERSION, HIBERNATE_MAPPING_OPAUTHOR, HIBERNATE_MAPPING_PDATE, HIBERNATE_MAPPING_PSTATUS, HIBERNATE_MAPPING_READ_ACK, HIBERNATE_MAPPING_READERCOUNT, HIBERNATE_MAPPING_RESTRICTIVE_UPDATE_RIGHTS, 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, OPAUTHOR_ID_FIELD, PSTATUS_FIELD, ROW_ID_FIELD, SCROLL_FETCH_SIZE, WORKFLOW_ID_FIELD, WORKSPACE_ID_FIELDFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidBegins a new transaction in the session of the current thread.static org.hibernate.criterion.CriterionbuildAndCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2) Returns the AND of the two criterion.static org.hibernate.criterion.CriterionbuildCollectionCriterion(Class clazz, String property, Object value, org.hibernate.type.Type valueType, boolean equality) Apply a constraint on a value of the collection of the given clazz.static org.hibernate.criterion.CriterionbuildCollectionCriterion(Class clazz, String property, String value) Apply a constraint on a value of the collection of the given clazz.static org.hibernate.criterion.CriterionbuildCollectionCriterion(String entityTable, String idColumn, String collectionTable, String itemIdColumn, String valueColumn, Object value, org.hibernate.type.Type valueType, boolean equality) Apply a constraint on a value of the collection of the given entity.static <T> org.hibernate.criterion.CriterionbuildInCriterion(String propertyName, Collection<T> values) Returns an "in" criterion.static <T> org.hibernate.criterion.CriterionbuildInCriterion(String propertyName, Collection<T> values, int max) Returns an "in" criterion.static StringbuildJcmsId(Class<?> clazz, Long rowId) Generates the internal JCMS id for the given database object.static org.hibernate.criterion.CriterionbuildOrCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2) Returns the OR of the two criterion.static <T> org.hibernate.QuerybuildQueryCollection(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.CriteriabuildQueryCriteria(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 org.hibernate.CriteriabuildQueryCriteria(org.hibernate.Session session, Class<?> clazz, String[] properties, Object[] values, String orderBy, int firstResult, int maxResults, boolean cacheable) Retrieves the result(s) matching the specified parameters.static StringcheckSQLInjection(String... strings) Checks if the given strings may contains an SQL injection.static voidstatic voidClose the hibernate session of the current thread.static voidCommits the transaction of the current thread if it exists.static voidCommits the transaction of the current thread if it exists but NEVER call the code about hibernate send event.static org.hibernate.CriteriacreateCriteria(Class clazz) Returns a criteria for the given clazz.static booleandateEquals(Date date1, Date date2) Check if both date are equals, skipping any difference due to Timestamp implemantation.static voidDeletes the specified object in the database.static voidDeletes the specified object in the database.static voidDeletes the specified object in the database.static intdeleteQuery(Class<?> clazz, String[] properties, Object[] values) Delete all object matching the specified parameters.static intdeleteQuery(Class<?> clazz, String[] properties, Object[] values, boolean cleanSession) Delete all object matching the specified parameters.static intdeleteQuery(Class<?> clazz, String property, Object value) Delete all object matching the specified parameters.static intdeleteQuery(Class<?> clazz, String property, Object value, boolean cleanSession) Delete all object matching the specified parameters.static voidCheck the features supported by the database.static voidRemoves this instance from the Hibernate session cache to avoid automatic persistence by dirty checking.static voidexcludeFromCommit(Object entity, boolean exclude) Add or remove the specified object to internal collection of entity to be evicted right before the next commit.static ListExecute the specified hibernate query using the current thread's session.static ListExecute the specified hibernate query using the current thread's session.static ListexecQuery(org.hibernate.Query query) Execute the specified hibernate query using the current thread's session.static IteratorexecQueryIterator(String hql) Execute the specified hibernate query using the current thread's session.static IteratorexecQueryIterator(org.hibernate.Query query) Execute the specified hibernate query using the current thread's session.static ObjectexecQueryUnique(String hql) Execute the specified hibernate query using the current thread's session.static intexecUpdate(String hql) Execute the update or delete HQL statement.static intexecUpdate(org.hibernate.Query query) Execute the update or delete query.static <T> TexecuteTransaction(Transaction<T> transaction) Execute the specified function in a new hibernate Session/Transaction.static voidexecuteTransaction(Runnable runnable) Execute the specified function in a new hibernate Session/Transaction.static <T> TexecuteTransaction(Supplier<? extends T> supplier) Execute the specified function in a new hibernate Session/Transaction and return a result.static <T> TexecuteTransactionInNewThread(Transaction<T> transaction) Execute the specified function in a new hibernate Session/Transaction/Thread.static <T> TexecuteTransactionInNewThread(Transaction<T> transaction, int timeout) Execute the specified function in a new hibernate Session/Transaction/Thread.static MembergetAuthorFromEventState(Object[] state) getBatchSet(Collection<Long> idColl, int batchSize) Convenient method to convert a Collection of rowId into many smaller collections, allowing batch select using methodgetDBDataList(Class, Collection).static DategetCdateFromEventState(Object[] state) static DatagetCurrentData(String id) Return the current persisted state of the Data with the given id.static DateReturns a new date.static DBDataReturn the current persisted state of the DBData with the given id.static ObjectgetCurrentObject(Class clazz, Long rowId) Return the current persisted state of the object with the given rowId.static DataRetrieves the Data bound to the specified jcms id from the database.static <T extends Data>
TgetDataFromEventState(Object[] state, Class<T> clazz, int fieldIndex) protected static DateReturn a new java.util.Date if the specified Date is a timestamp, otherwise return the date as is.static DBDataRetrieves the DBData bound to the specified jcms id from the database.static <T> Iterator<T> getDBDataIterator(Class<T> clazz) Retrieve all Objects of the specified class from the database.static <T> List<T> getDBDataList(Class<T> clazz) Retrieve all Objects of the specified class from the database (limited to maxResults).static <T> List<T> getDBDataList(Class<T> clazz, int firstResult, int maxResults) Retrieve all Objects of the specified class from the database.static <T> List<T> getDBDataList(Class<T> clazz, Collection<Long> rowIdColl) Retrieve a List of Objects from their Class and rowId.static DategetMdateFromEventState(Object[] state) static ObjectRetrieves the Object of the specified class and using the specified id.static ObjectRetrieves the Object of the specified class and using the specified id in the given session.static <T> TgetObjectFromEventState(Object[] state, Class<T> clazz, int fieldIndex) static LongRetrieve the row id from a DBData idgetRowIdBatchSet(Collection<String> idColl, int batchSize) Convenient method to convert a Collection of id into many smaller collections, allowing batch select using methodgetDBDataList(Class, Collection).static org.hibernate.SessionRetrieve and open an hibernate session for the current threadstatic org.hibernate.SessionFactoryRetrieve the Hibernate SessionFactory singletonstatic voidHandle time out exceptionstatic booleanCheck if the current thread has a valid and active transaction.static booleanisDBDataJcmsId(String id) static booleanReturns true if the database count varchar length in bytes (i.e.static Object[]parseJcmsId(String id) Returns the 2 component of the given JCMS ID.static <T> List<T> Retrieves all object of the specified Class.static <T> List<T> Retrieves all object matching the specified parameters.static <T> List<T> Retrieves all object matching the specified parameters.static <T> List<T> Retrieves all object matching the specified parameters.static <T> List<T> Retrieves all object matching the specified parameters.static <T> List<T> Retrieves all object matching the specified parameters.static <T> List<T> Retrieves all object matching the specified parameters.static <T> List<T> query(Class<? extends T> clazz, Map<String, Object> paramsMap, String orderBy, int firstResult, int maxResults) Retrieves all object matching the specified parameters.static <T> List<T> Retrieves all object of the specified Class.static <T> List<T> queryCollection(Class<? extends T> clazz, String property, Object value) Retreives the instance of the given class with the collection property matching the given value.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 intqueryCount(Class<?> clazz) Returns the count of objects matching the given class.static intqueryCount(Class<?> clazz, String[] properties, Object[] values) Returns the count of objects matching the given class with the given criteria.static intqueryCount(Class<?> clazz, String property, Object value) Returns the count of objects matching the given class with the given criteria.static intqueryCount(Class<?> clazz, org.hibernate.criterion.Criterion criterion) Returns the count of objects matching the given class with the given criterion.static intqueryCount(org.hibernate.Criteria criteria) Returns the count of objects matching the given criteria.static intqueryCount(org.hibernate.Criteria criteria, boolean distinct) static intqueryCountExact(Class<?> clazz) Returns the count of objects matching the exact specified class, without using polymorphism.static PageResult<Publication> queryPublication(PublicationCriteria pubCriteria) Returns a list of publications in the database matching the given criteria.static <T> TqueryUnique(Class<? extends T> clazz, String[] properties, Object[] values) Retrieves a unique object matching the specified parameters.static <T> TqueryUnique(Class<? extends T> clazz, String[] properties, Object[] values, String orderBy) Retrieves a unique object matching the specified parameters.static <T> TqueryUnique(Class<? extends T> clazz, String property, Object value) Retrieves a unique object matching the specified parameters.static voidRemoves aDBDatafrom the second level cache.static voidremoveSecondLevelCacheEntry(String entityName, Long rowId) Removes aDBDatafrom the second level cache.static voidRollback the transaction of the current thread if it exists.static voidSaves or updates the specified Data in the database.static voidSaves or updates the specified Object in the database.static org.hibernate.ScrollableResultsScroll over a class.static org.hibernate.ScrollableResultsScroll over a class with a given scroll mode.static <T> org.hibernate.ScrollableResultsscrollCollection(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 booleanReturns true if the database supports updating collection of CLOB using a where clause as opposed to specifying a completely new set of values.static booleanReturns true if the database supports millis for date.static booleanReturns true if the database supports full join.static StringtruncateVarchar(String value) Returns the value truncated to the varchar length (i.e.static <T> List<T> updateCollection(List<T> listToUpdate, List<T> newValues, boolean isLargeText) Return an updated List enforcing constraint required by Hibernate and current databasestatic <T> Set<T> updateCollection(Set<T> setToUpdate, Set<T> newValues, boolean isLargeText) Return an updated Set enforcing constraint required by Hibernate and current database
-
Field Details
-
HIBERNATE_CAPABILITIES_PREFIX
-
DEFAULT_BATCH_SIZE
public static final int DEFAULT_BATCH_SIZE- See Also:
-
-
Constructor Details
-
HibernateUtil
public HibernateUtil()
-
-
Method Details
-
getSessionFactory
public static org.hibernate.SessionFactory getSessionFactory()Retrieve the Hibernate SessionFactory singleton- Returns:
- the SessionFactory singleton
- Since:
- jcms-6.0
-
getSession
public static org.hibernate.Session getSession() throws org.hibernate.HibernateExceptionRetrieve and open an hibernate session for the current thread- Returns:
- an opened Session ready to be used for hibernate transaction
- Throws:
org.hibernate.HibernateException- if error occured with database- Since:
- jcms-6.0
-
closeSession
public static void closeSession() throws org.hibernate.HibernateExceptionClose the hibernate session of the current thread.- Throws:
org.hibernate.HibernateException- if error occured with database- Since:
- jcms-6.0
-
beginTransaction
public static void beginTransaction() throws org.hibernate.HibernateExceptionBegins a new transaction in the session of the current thread.- Throws:
org.hibernate.HibernateException- if error occured with database- Since:
- jcms-6.0
-
hasActiveTransaction
public static boolean hasActiveTransaction()Check if the current thread has a valid and active transaction.An active transaction is begun, non commited, non rollbacked, without commit failed.
In JCMS, an inactive transaction generally indicates a database failure or a forgotten call tobeginTransaction().Use this method to improve code robustness, by skipping optional database operations that would fail without an active transaction.
- Returns:
- true if there is an active transaction ready for use, false if there is no transaction for current thread
- Since:
- JCMS-5756
-
commitTransaction
public static void commitTransaction() throws org.hibernate.HibernateExceptionCommits the transaction of the current thread if it exists.- Throws:
org.hibernate.HibernateException- if error occured with database- Since:
- jcms-6.0
-
rollbackTransaction
public static void rollbackTransaction()Rollback the transaction of the current thread if it exists.- Since:
- jcms-6.0
-
commitTransactionWithoutSendHibernateEvent
public static void commitTransactionWithoutSendHibernateEvent() throws org.hibernate.HibernateExceptionCommits the transaction of the current thread if it exists but NEVER call the code about hibernate send event.- Throws:
org.hibernate.HibernateException- if error occured with database- Since:
- jcms-10.0.6
-
executeTransaction
public static <T> T executeTransaction(Transaction<T> transaction) throws org.hibernate.TransactionException Execute the specified function in a new hibernate Session/Transaction.Important : because the function is being executed in a new hibernate Session/Transaction (since JCMS-10462) : You MUST load/reload any object inside your function before any modification or complete access (e.g collection access).
You MUST NOT modify any object loaded in another session such as the one of the caller method.A
TransactionExceptioncan be thrown when there is any Exception: It gets propagated to the caller of this method.Allows for returning a result object, that is a domain object or a collection of domain objects.
Note: code of
Transactionimplementation is not supposed to manage transactions itself! Generally, code ofTransactionimplementation must not touch any Session lifecycle methods, like close, disconnect, or reconnect, to let this method do its work.Examples:
// Example with id as result String myDataId = HibernateUtil.executeTransaction(session -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] myData.performCreate(admin); return myData.getId(); }); // Example with domain object as result // /!\ DO NOT alter or modify the returned object as it belongs to a closed Hibernate session, this approach is not recommended. MyData myData = HibernateUtil.executeTransaction(session -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] myData.performCreate(admin); return myData; }); // Example with collection of domain objects as result // /!\ DO NOT alter or modify the returned objects as they belongs to a closed Hibernate session, this approach is not recommended. List<MyData> myDataList = HibernateUtil.executeTransaction(session -> { Criteria criteria = HibernateUtil.getSession().createCriteria(MyData.class); criteria.add(Restrictions.ilike("title", "%title%")); return criteria.list(); }); // Example with no result Article article = ...; Member member = ... ; HibernateUtil.executeTransaction(session -> { VoteManager.getInstance().performVote(article, member, true); article.trackReader(member); return null; });- Type Parameters:
T- type of the result object- Parameters:
transaction-Transaction- Returns:
- a result object returned by the action, or null
- Throws:
org.hibernate.TransactionException- if there is any Exception- See Also:
-
executeTransactionInNewThread
Execute the specified function in a new hibernate Session/Transaction/Thread.Important : because the function is being executed in a new hibernate Session/Transaction (since JCMS-10462), and new thread : You MUST load/reload any object inside your function before any modification or complete access (e.g collection access).
You MUST NOT modify any object loaded in another session such as the one of the caller method. The new thread prevents the current session from being reused.A
TransactionExceptioncan be thrown when there is any Exception: It gets propagated to the caller of this method.Allows for returning a result object, that is a domain object or a collection of domain objects.
Note: code of
Transactionimplementation is not supposed to manage transactions itself! Generally, code ofTransactionimplementation must not touch any Session lifecycle methods, like close, disconnect, or reconnect, to let this method do its work.Examples:
// Example with id as result String myDataId = HibernateUtil.executeTransactionInNewThread(session -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] myData.performCreate(admin); return myData.getId(); }); // Example with domain object as result // /!\ DO NOT alter or modify the returned object as it belongs to a closed Hibernate session, this approach is not recommended. MyData myData = HibernateUtil.executeTransactionInNewThread(session -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] myData.performCreate(admin); return myData; }); // Example with collection of domain objects as result // /!\ DO NOT alter or modify the returned objects as they belongs to a closed Hibernate session, this approach is not recommended. List<MyData> myDataList = HibernateUtil.executeTransactionInNewThread(session -> { Criteria criteria = HibernateUtil.getSession().createCriteria(MyData.class); criteria.add(Restrictions.ilike("title", "%title%")); return criteria.list(); }); // Example with no result Article article = ...; Member member = ... ; HibernateUtil.executeTransactionInNewThread(session -> { VoteManager.getInstance().performVote(article, member, true); article.trackReader(member); return null; });- Type Parameters:
T- type of the result object- Parameters:
transaction-Transaction- Returns:
- a result object returned by the action, or null
- Throws:
org.hibernate.TransactionException- if there is any ExceptionException- See Also:
-
executeTransactionInNewThread
public static <T> T executeTransactionInNewThread(Transaction<T> transaction, int timeout) throws Exception Execute the specified function in a new hibernate Session/Transaction/Thread.Important : because the function is being executed in a new hibernate Session/Transaction (since JCMS-10462), and new thread : You MUST load/reload any object inside your function before any modification or complete access (e.g collection access).
You MUST NOT modify any object loaded in another session such as the one of the caller method. The new thread prevents the current session from being reused.A
TransactionExceptioncan be thrown when there is any Exception: It gets propagated to the caller of this method.Allows for returning a result object, that is a domain object or a collection of domain objects.
Note: code of
Transactionimplementation is not supposed to manage transactions itself! Generally, code ofTransactionimplementation must not touch any Session lifecycle methods, like close, disconnect, or reconnect, to let this method do its work.Examples:
// Example with id as result String myDataId = HibernateUtil.executeTransactionInNewThread(session -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] myData.performCreate(admin); return myData.getId(); }); // Example with domain object as result // /!\ DO NOT alter or modify the returned object as it belongs to a closed Hibernate session, this approach is not recommended. MyData myData = HibernateUtil.executeTransactionInNewThread(session -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] myData.performCreate(admin); return myData; }); // Example with collection of domain objects as result // /!\ DO NOT alter or modify the returned objects as they belongs to a closed Hibernate session, this approach is not recommended. List<MyData> myDataList = HibernateUtil.executeTransactionInNewThread(session -> { Criteria criteria = HibernateUtil.getSession().createCriteria(MyData.class); criteria.add(Restrictions.ilike("title", "%title%")); return criteria.list(); }); // Example with no result Article article = ...; Member member = ... ; HibernateUtil.executeTransactionInNewThread(session -> { VoteManager.getInstance().performVote(article, member, true); article.trackReader(member); return null; });- Type Parameters:
T- type of the result object- Parameters:
transaction-Transactiontimeout- maximum waiting time- Returns:
- a result object returned by the action, or null
- Throws:
org.hibernate.TransactionException- if there is any ExceptionException- See Also:
-
executeTransaction
Execute the specified function in a new hibernate Session/Transaction and return a result.Important : because the function is being executed in a new hibernate Session/Transaction : You MUST load/reload any object inside your function before any modification or complete access (e.g collection access).
You MUST NOT modify any object loaded in another session such as the one of the caller method.Examples:
ControllerStatus status = HibernateUtil.executeTransaction(() -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] return myData.checkAndPerformCreate(admin); }); // Load/Reload of DB object is required Media someMedia = ...; String dbDocId = ...; boolean success = HibernateUtil.executeTransaction(() -> { Media someMediaReloaded = Channel.getChannel().getData(Media.class, someMedia.getId()); if (someMediaReloaded != null) { someMediaReloaded.performUpdate(member); return false; } DBFileDocument dbDoc = Channel.getChannel().getData(DBFileDocument.class, dbDocId); if (dbDoc != null) { dbDoc.performDelete(member); } return true; });- Type Parameters:
T- the function's return type Warning, you should NOT return a database object as it will belong to other another hibernate session.- Parameters:
supplier- a function to be executed inside a new session/transaction- Returns:
- the result of your supplier function.
- Since:
- JCMS-10463
- See Also:
-
executeTransaction
Execute the specified function in a new hibernate Session/Transaction.Important : because the function is being executed in a new hibernate Session/Transaction : You MUST load/reload any object inside your function before any modification or complete access (e.g collection access).
You MUST NOT modify any object loaded in another session such as the one of the caller method.Examples:
HibernateUtil.executeTransaction(() -> { MyData myData = new MyData(); myData.setTitle("new title"); [...] myData.checkAndPerformCreate(admin); }); // Load/Reload of DB object is required Media someMedia = ...; String dbDocId = ...; HibernateUtil.executeTransaction(() -> { Media someMediaReloaded = Channel.getChannel().getData(Media.class, someMedia.getId()); if (someMediaReloaded != null) { someMediaReloaded.performUpdate(member); } DBFileDocument dbDoc = Channel.getChannel().getData(DBFileDocument.class, dbDocId); if (dbDoc != null) { dbDoc.performDelete(member); } });- Parameters:
runnable- a function to be executed inside a new session/transaction- Since:
- JCMS-10463
- See Also:
-
buildJcmsId
Generates the internal JCMS id for the given database object.- Parameters:
clazz- the Class of the object (required)rowId- the row id in the database table (required)- Returns:
- the internal JCMS id for the given database object.
- Throws:
IllegalArgumentException- if clazz or rowId is null- Since:
- jcms-6.0.0
-
isDBDataJcmsId
-
execQueryUnique
Execute the specified hibernate query using the current thread's session.Return the unique query result. If the query contains multiple results per row, the results are returned in an instance of Object[].
- Parameters:
hql- the query as a string using the hibernate query language- Returns:
- the result or null if it could not be found (or if an error occured)
- Since:
- jcms-6.0
-
execQuery
Execute the specified hibernate query using the current thread's session.Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
- Parameters:
hql- the query as a string using the hibernate query language- Returns:
- the result list (never return null)
- Since:
- jcms-6.0
-
execQuery
Execute the specified hibernate query using the current thread's session.Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
- Parameters:
hql- the query as a string using the hibernate query languagefirstResult- set the first data to retrieve. If <= 0, rows will be retrieved beginning 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).- Returns:
- the result list (never return null)
- Since:
- jcms-6.0
-
execQuery
Execute the specified hibernate query using the current thread's session.Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
- Parameters:
query- the hibernate query- Returns:
- the result list (never return null)
- Since:
- jcms-6.0
-
execQueryIterator
Execute the specified hibernate query using the current thread's session.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.- Parameters:
hql- the query as a string using the hibernate query language- Returns:
- the result iterator (never return null)
- Since:
- jcms-6.0
-
execQueryIterator
Execute the specified hibernate query using the current thread's session.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.- Parameters:
query- the hibernate query- Returns:
- the result iterator
- Since:
- jcms-6.0
-
execUpdate
Execute the update or delete HQL statement.- Parameters:
hql- the query as a string using the hibernate query language- Returns:
- the number of entities updated or deleted.
- Since:
- jcms-6.0
-
execUpdate
public static int execUpdate(org.hibernate.Query query) Execute the update or delete query.- Parameters:
query- the Hibernate query- Returns:
- the number of entities updated or deleted.
- Since:
- jcms-6.0
-
query
Retrieves all object of the specified Class.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.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
clazz- the Class of object to retrieve, required must not be null- Returns:
- a list of all object found in the database (never return null)
- Throws:
IllegalArgumentException- if clazz is null- Since:
- jcms-6.0
-
query
Retrieves all object of the specified Class.Example to retrieve all ArchivedPublication order by rowId.
HibernateUtil.query(ArchivedPublication.class, "rowId");
- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
clazz- 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.- Returns:
- a list of all object found in the database (never return null)
- Throws:
IllegalArgumentException- if clazz is null- Since:
- jcms-6.0
-
query
Retrieves all object matching the specified parameters.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.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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.- Returns:
- a list of all object found in the database (never return null)
- Throws:
IllegalArgumentException- if clazz is null- Since:
- jcms-6.0
-
query
public static <T> List<T> query(Class<? extends T> clazz, String property, Object value, String orderBy) Retrieves all object matching the specified parameters.Example to retrieve all ExtraDBData of a member, order by extradbdata name
HibernateUtil.query(ExtraDBData.class, "dataId", mbr.getId(), "extraName");
- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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 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.- Returns:
- a list of all object found in the database (never return null)
- Throws:
IllegalArgumentException- if clazz is null- Since:
- jcms-6.0
-
query
Retrieves all object matching the specified parameters.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- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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.- Returns:
- a list of all object found in the database (never return null)
- Throws:
IllegalArgumentException- if clazz is null or if propreties and values are not of the same length- Since:
- jcms-6.0
-
query
public static <T> List<T> query(Class<? extends T> clazz, String[] properties, Object[] values, String orderBy) Retrieves all object matching the specified parameters.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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 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.- Returns:
- a list of all object found in the database
- Throws:
IllegalArgumentException- if clazz is null or if propreties and values are not of the same length- Since:
- jcms-6.0
-
queryUnique
Retrieves a unique object matching the specified parameters.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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.- Returns:
- the object found in the database
- Throws:
IllegalArgumentException- if clazz is null- Since:
- jcms-6.0
-
queryUnique
Retrieves a unique object matching the specified parameters.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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.- Returns:
- the object found in the database
- Throws:
IllegalArgumentException- if clazz is null or if propreties and values are not of the same length- Since:
- jcms-6.0
-
queryUnique
public static <T> T queryUnique(Class<? extends T> clazz, String[] properties, Object[] values, String orderBy) Retrieves a unique object matching the specified parameters.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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 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.- Returns:
- the object found in the database
- Throws:
IllegalArgumentException- if clazz is null or if propreties and values are not of the same length- Since:
- jcms-6.0
-
query
Retrieves all object matching the specified parameters.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- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
clazz- the Class of object to retrieve, requiredparamsMap- a map of fields name and field value (if null or empty, no refinement is performed)- Returns:
- a list of all object found in the database (never return null)
- Since:
- jcms-6.0
-
query
public static <T> List<T> query(Class<? extends T> clazz, Map<String, Object> paramsMap, String orderBy) Retrieves all object matching the specified parameters.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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 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.- Returns:
- a list of all object found in the database (never return null)
- Throws:
IllegalArgumentException- if clazz is null- Since:
- jcms-6.0
-
query
public static <T> List<T> query(Class<? extends T> clazz, Map<String, Object> paramsMap, String orderBy, int firstResult, int maxResults) Retrieves all object matching the specified parameters.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
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 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 beginning 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).- Returns:
- a list of all object found in the database (never return null)
- Throws:
IllegalArgumentException- if clazz is null- Since:
- jcms-6.0
-
handleTimeoutException
Handle time out exception- Parameters:
th- the throwable- Since:
- jcms-6.1.3
-
createCriteria
Returns a criteria for the given clazz.- Parameters:
clazz- the class- Returns:
- a criteria for the given clazz.
- Since:
- jcms-10.0.0
-
buildQueryCriteria
public 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.Returns either a List or an object depending on value of the unique parameter.
- Parameters:
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 beginning 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).- Returns:
- if unique is false, a List (never return null). if unique is true, an Object (may be null)
- Throws:
IllegalArgumentException- if clazz is null or if properties and values are not of the same length- Since:
- jcms-6.0
-
buildQueryCriteria
public static org.hibernate.Criteria buildQueryCriteria(org.hibernate.Session session, Class<?> clazz, String[] properties, Object[] values, String orderBy, int firstResult, int maxResults, boolean cacheable) Retrieves the result(s) matching the specified parameters.Returns either a List or an object depending on value of the unique parameter.
- Parameters:
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 beginning 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.- Returns:
- if unique is false, a List (never return null). if unique is true, an Object (may be null)
- Throws:
IllegalArgumentException- if clazz is null or if properties and values are not of the same length- Since:
- jcms-6.0
-
queryCollection
Retreives the instance of the given class with the collection property matching the given value.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
clazz- the Class of object to retrieve, required must not be nullproperty- the collection field namevalue- the value to match- Returns:
- a list of data
- Since:
- jcms-6.1.0
-
queryCollectionRowId
public static <T> List<Long> queryCollectionRowId(Class<? extends T> clazz, String property, Object value) Retreives the instance of the given class with the collection property matching the given value.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
clazz- the Class of object to retrieve, required must not be nullproperty- the collection field namevalue- the value to match- Returns:
- a list of data
- Since:
- jcms-6.2.0
-
scrollCollection
public static <T> org.hibernate.ScrollableResults 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.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
clazz- 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 object- Returns:
- a list of data
- Since:
- jcms-6.2.0
-
buildQueryCollection
public static <T> org.hibernate.Query 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.- Type Parameters:
T- Hibernate class corresponding to a table in the database- Parameters:
clazz- 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 object- Returns:
- a list of data
- Since:
- jcms-6.1.0
-
deleteQuery
Delete all object matching the specified parameters.Example to delete all ReaderTracker of a publication
HibernateUtil.deleteQuery(ReaderTracker.class, "publicationId", pub.getId());
- Parameters:
clazz- the Class of object to retrieve and delete, requiredproperty- a field name, requiredvalue- the value of the field to match, required- Returns:
- the number of objects deleted.
- Since:
- jcms-7.1.3
-
deleteQuery
Delete all object matching the specified parameters.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);- Parameters:
clazz- the Class of object to retrieve and delete, requiredproperties- the fields name, requiredvalues- the value of the field to match, required- Returns:
- the number of objects deleted.
- Since:
- jcms-7.1.3
-
deleteQuery
Delete all object matching the specified parameters.Example to delete all ReaderTracker of a publication
HibernateUtil.deleteQuery(ReaderTracker.class, "publicationId", pub.getId());
- Parameters:
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.- Returns:
- the number of objects deleted.
- Since:
- jcms-7.1.3
-
deleteQuery
public static int deleteQuery(Class<?> clazz, String[] properties, Object[] values, boolean cleanSession) Delete all object matching the specified parameters.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);- Parameters:
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.- Returns:
- the number of objects deleted.
- Since:
- jcms-7.1.3
-
getDBDataList
Retrieve all Objects of the specified class from the database (limited to maxResults).- Type Parameters:
T- any DB type- Parameters:
clazz- the Class of object to retrieve, required- Returns:
- a list of all object found in the database (never return null)
- Since:
- jcms-6.0
-
getDBDataList
Retrieve all Objects of the specified class from the database.- Type Parameters:
T- any DB type- Parameters:
clazz- 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).- Returns:
- a list of all object found in the database (never return null)
- Since:
- jcms-6.0
-
getDBDataList
Retrieve a List of Objects from their Class and rowId.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 argumentsclazz=Publication.classandrowIdColl={42}you would retrive42_MyType, 42_OtherTypewhich is not usually expected !
This method is only meant to work on one specific type (without subtype!)- Type Parameters:
T- any DB type- Parameters:
clazz- the Class of object to retrieve, required DO NOT use a super classrowIdColl- a collection of rowId- Returns:
- a list of all object found in the database (never return null)
- Since:
- jcms-6.1.0
-
getDBDataIterator
Retrieve all Objects of the specified class from the database.- Type Parameters:
T- any DB type- Parameters:
clazz- the Class of object to retrieve, required- Returns:
- the result iterator
- Since:
- jcms-6.0
-
getRowIdBatchSet
Convenient method to convert a Collection of id into many smaller collections, allowing batch select using methodgetDBDataList(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 requestWarning : 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!).
- Parameters:
idColl- a collection of jcmsid for DBData (e.g 42_YourType)batchSize- the size of subset to be create (defaut valueDEFAULT_BATCH_SIZEis used if specified valued is less or equal 1)- Returns:
- a Set containing subset of rowId.
- Since:
- jcms-6.1.0
-
getBatchSet
Convenient method to convert a Collection of rowId into many smaller collections, allowing batch select using methodgetDBDataList(Class, Collection).- Parameters:
idColl- a collection of rowId for DBDatabatchSize- the size of subset to be create (defaut valueDEFAULT_BATCH_SIZEis used if specified value is less or equal 1)- Returns:
- a Set containing subset of rowId.
- Since:
- jcms-7.0.2
- See Also:
-
queryCountExact
Returns the count of objects matching the exact specified class, without using polymorphism.- Parameters:
clazz- the class- Returns:
- the count of objects matching the given class.
- Since:
- jcms-9.0.3 - JCMS-5271
-
queryCount
Returns the count of objects matching the given class.- Parameters:
clazz- the class- Returns:
- the count of objects matching the given class.
- Since:
- jcms-6.0.0
-
queryCount
Returns the count of objects matching the given class with the given criteria.- Parameters:
clazz- the classproperty- a field name.value- the value of the field to match. All results are return if null.- Returns:
- the count of objects matching the given class with the given criteria.
- Since:
- jcms-6.0.0
-
queryCount
Returns the count of objects matching the given class with the given criteria.- Parameters:
clazz- the classproperties- an array of field name.values- an array of values of the field to match.- Returns:
- the count of objects matching the given class with the given criteria.
- Since:
- jcms-6.0.0
-
queryCount
Returns the count of objects matching the given class with the given criterion.- Parameters:
clazz- the classcriterion- the criterion- Returns:
- the count of objects matching the given class with the given criterion.
- Since:
- jcms-6.0.0
-
queryCount
public static int queryCount(org.hibernate.Criteria criteria) Returns the count of objects matching the given criteria.- Parameters:
criteria- the criteria- Returns:
- the count of objects matching the given criteria.
- Since:
- jcms-6.2.0
-
queryCount
public static int queryCount(org.hibernate.Criteria criteria, boolean distinct) -
queryPublication
Returns a list of publications in the database matching the given criteria.- Parameters:
pubCriteria- the PublicationCriteria (required, must not be null)- Returns:
- a list of publications, never return null.
- Throws:
IllegalArgumentException- if pubCriteria is null- Since:
- jcms-6.0.0
-
buildAndCriterion
public static org.hibernate.criterion.Criterion buildAndCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2) Returns the AND of the two criterion. Check if criterion are null.- Parameters:
c1- a criterionc2- a criterion- Returns:
- the AND of the two criterion. Check if criterion are null.
- Since:
- jcms-6.0.0
-
buildOrCriterion
public static org.hibernate.criterion.Criterion buildOrCriterion(org.hibernate.criterion.Criterion c1, org.hibernate.criterion.Criterion c2) Returns the OR of the two criterion. Check if criterion are null.- Parameters:
c1- a criterionc2- a criterion- Returns:
- the OR of the two criterion. Check if criterion are null.
- Since:
- jcms-6.0.0
-
buildCollectionCriterion
public 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.- Parameters:
clazz- the entity classproperty- the name of the collection propertyvalue- the searched value- Returns:
- a SQL restriction with the given parameters. May return null if specified clazz or field does not exist.
- Since:
- jcms-6.1.0
-
buildCollectionCriterion
public static org.hibernate.criterion.Criterion buildCollectionCriterion(Class clazz, String property, Object value, org.hibernate.type.Type valueType, boolean equality) Apply a constraint on a value of the collection of the given clazz. Warning! This method does not support polymorphism. The given clazz must be an Hibernate mapped class.- Parameters:
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)equality- if true search items with value equals to the given value else search items with value different to the given value.- Returns:
- a SQL restriction with the given parameters. May return null if specified clazz or field does not exist.
- Since:
- jcms-6.1.0
-
buildCollectionCriterion
public static org.hibernate.criterion.Criterion buildCollectionCriterion(String entityTable, String idColumn, String collectionTable, String itemIdColumn, String valueColumn, Object value, org.hibernate.type.Type valueType, boolean equality) Apply a constraint on a value of the collection of the given entity.- Parameters:
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)equality- if true search items with value equals to the given value else search items with value different to the given value.- Returns:
- a SQL restriction with the given parameters.
- Since:
- jcms-6.1.0
-
buildInCriterion
public static <T> org.hibernate.criterion.Criterion buildInCriterion(String propertyName, Collection<T> values) Returns an "in" criterion. If there are too many values, return a serie of in(...) or in (...) or in(...) or ...- Parameters:
propertyName- the name of the property to search in.values- the values- Returns:
- an "in" criterion.
- Since:
- jcms-9.0.2
-
buildInCriterion
public static <T> org.hibernate.criterion.Criterion buildInCriterion(String propertyName, Collection<T> values, int max) Returns an "in" criterion. If there are too many values, return a serie of in(...) or in (...) or in(...) or ...- Parameters:
propertyName- the name of the property to search in.values- the valuesmax- the max item per "in" clause.- Returns:
- an "in" criterion.
- Since:
- jcms-9.0.2
-
checkSQLInjection
Checks if the given strings may contains an SQL injection.- Parameters:
strings- an array of String- Returns:
- the String which contains a possible SQL injection or null if no SQL injection has been detected.
- Since:
- jcms-6.1.0
-
getObject
Retrieves the Object of the specified class and using the specified id.- Parameters:
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- Returns:
- the Object found in the database or null if no object matched the query.
- Since:
- jcms-6.0
-
getObject
Retrieves the Object of the specified class and using the specified id in the given session.- Parameters:
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- Returns:
- the Object found in the database or null if no object matched the query or if any parameter were null.
- Since:
- jcms-6.2.0
-
getDBData
Retrieves the DBData bound to the specified jcms id from the database.- Parameters:
id- the JCMS id of this data (e.g. 1234_WFNOTE)- Returns:
- the DBData found in the database or null if no object matched the query.
- Since:
- jcms-6.0
-
parseJcmsId
Returns the 2 component of the given JCMS ID.- Parameters:
id- the JCMS id- Returns:
- an array of 2 components : the rowId (Long) and the class (Class)
- Since:
- jcms-6.2.0
-
getRowId
Retrieve the row id from a DBData id- Parameters:
id- the full DBData id as returned bydbdata.getId()(e.g 42_YourType)- Returns:
- the rowId computed or null if it could not parsed
- Since:
- jcms-6.1.0
-
getData
Retrieves the Data bound to the specified jcms id from the database.- Parameters:
id- the JCMS id of this data (e.g. 1234_WFNOTE)- Returns:
- the Data found in the database or null if no object matched the query.
- Since:
- jcms-6.0.0
-
getCurrentObject
Return the current persisted state of the object with the given rowId.- Parameters:
clazz- the class of the objectrowId- the rowId of the object- Returns:
- the current persisted state of the object with the given id.
- Since:
- jcms-6.2.0
-
getCurrentDBData
Return the current persisted state of the DBData with the given id.- Parameters:
id- the JCMS id- Returns:
- the current persisted state of the DBData with the given id.
- Since:
- jcms-6.2.0
-
getCurrentData
Return the current persisted state of the Data with the given id.- Parameters:
id- the JCMS id- Returns:
- the current persisted state of the Data with the given id.
- Since:
- jcms-6.2.0
-
getDate
Return a new java.util.Date if the specified Date is a timestamp, otherwise return the date as is.- Parameters:
date- the date object to check- Returns:
- a Date object or null if specified date was null, NEVER return a Timestamp
- Since:
- jcms-8.0.0
-
dateEquals
Check if both date are equals, skipping any difference due to Timestamp implemantation.- Parameters:
date1- the first Date to comparedate2- the second Date to compare- Returns:
- true if date are equals (or both null), false otherwise
- Since:
- jcms-8.0.0
-
save
Saves or updates the specified Data in the database.- Parameters:
data- the Data to be saved or updated- Since:
- jcms-6.0
-
save
Saves or updates the specified Object in the database.- Parameters:
obj- the object to be saved or updated- Since:
- jcms-6.0
-
supportDateMillis
public static boolean supportDateMillis()Returns true if the database supports millis for date.- Returns:
- true if the database supports millis for date.
- Since:
- jcms-6.2.0
-
detectDatabaseFeatures
public static void detectDatabaseFeatures()Check the features supported by the database.You do not need to invoke this method which is being invoked once at JPlatform startup.
- Since:
- jcms-10.0.3 / JCMS-7510
-
supportFullJoin
public static boolean supportFullJoin()Returns true if the database supports full join.- Returns:
- true if the database supports full join.
- Since:
- jcms-7.0.1
-
isVarcharInBytes
public static boolean isVarcharInBytes()Returns true if the database count varchar length in bytes (i.e. varchar(255) = 255 bytes, not 255 UTF-8 chars !)- Returns:
- true if the database count varchar length in bytes (i.e. varchar(255) = 255 bytes, not 255 UTF-8 chars !)
- Since:
- jcms-8.0.0
-
getCurrentDate
Returns a new date. The millis are truncated or not according the database support of millis.- Returns:
- a new date.
- Since:
- jcms-6.2.0
-
evict
Removes this instance from the Hibernate session cache to avoid automatic persistence by dirty checking.- Parameters:
obj- the object to be removed- Since:
- jcms-6.0.0
- See Also:
-
delete
Deletes the specified object in the database.- Parameters:
data- the data to be deletedcleanSession- if true clean the session- Since:
- jcms-6.1.1
-
delete
Deletes the specified object in the database.- Parameters:
data- the data to be deleted- Since:
- jcms-6.0
-
delete
Deletes the specified object in the database.- Parameters:
id- the identifier of the DBData to be deleted- Since:
- jcms-6.0
-
clearCache
public static void clearCache() -
removeSecondLevelCacheEntry
Removes aDBDatafrom the second level cache.Synchronization is handled within the method.
- Parameters:
entityName- the id of the DBData to removerowId- the rowId of the DBData to remove- Throws:
IllegalStateException- if the cache is notStatus.STATUS_ALIVE- Since:
- jcms-7.0.0
-
removeSecondLevelCacheEntry
Removes aDBDatafrom the second level cache.- Parameters:
id- the id of the DBData to remove.- Since:
- jcms-10.0.0
-
scroll
Scroll over a class. Scroll in forward only.- Parameters:
clazz- the class to scroll over.- Returns:
- a ScrollableResults
- Since:
- jcms-6.1.0
-
scroll
public static org.hibernate.ScrollableResults scroll(Class clazz, org.hibernate.ScrollMode scrollMode) Scroll over a class with a given scroll mode.- Parameters:
clazz- the class to scroll over.scrollMode- Indicates the type of underlying database cursor to request.- Returns:
- a ScrollableResults
- Since:
- jcms-6.2.0
-
truncateVarchar
Returns the value truncated to the varchar length (i.e. 255 chars)- Parameters:
value- the value to be truncated- Returns:
- the value truncated to the varchar length (i.e. 255 chars)
- Since:
- jcms-8.0.0
-
supportClobCollectionUpdate
public static boolean supportClobCollectionUpdate()Returns true if the database supports updating collection of CLOB using a where clause as opposed to specifying a completely new set of values.- Returns:
- true if the database supports updating collection of CLOB.
- Since:
- JCMS-6908 / DEVJCMS-2961
-
updateCollection
public static <T> List<T> updateCollection(List<T> listToUpdate, List<T> newValues, boolean isLargeText) Return an updated List enforcing constraint required by Hibernate and current database- Parameters:
listToUpdate- the list being updated (null accepted)newValues- the new values that should be used in the returned List (null accepted)isLargeText- true when collection contains large text (ie. CLOB), false for any other value type- Returns:
- an udpated List : might be a List new intance containing new values, or the original listToUpdate updated with the new values, depending on circumstances. Never return null.
- Since:
- JCMS-6908 / DEVJCMS-2961
-
updateCollection
public static <T> Set<T> updateCollection(Set<T> setToUpdate, Set<T> newValues, boolean isLargeText) Return an updated Set enforcing constraint required by Hibernate and current database- Parameters:
setToUpdate- the list being updated (null accepted)newValues- the new values that should be used in the returned Set (null accepted)isLargeText- true when collection contains large text (ie. CLOB), false for any other value type- Returns:
- an udpated Set : might be a Set new intance containing new values, or the original setToUpdate updated with the new values, depending on circumstances. Never return null.
- Since:
- JCMS-6908 / DEVJCMS-2961
-
excludeFromCommit
Add or remove the specified object to internal collection of entity to be evicted right before the next commit.This method is public due to existing JCMS packages organisation, however its usage is restricted for internal use.
- Parameters:
entity- any Object to exclude/restoreexclude- true to exclude the object, false to restore default behavior- Since:
- jcms-10.0.2 / JCMS-6645
-
getCdateFromEventState
- Parameters:
state- the event state- Returns:
- the cdate contained in the event state.
- Since:
- jcms-10.0.7
-
getMdateFromEventState
- Parameters:
state- the event state- Returns:
- the mdate contained in the event state.
- Since:
- jcms-10.0.7
-
getAuthorFromEventState
- Parameters:
state- the event state- Returns:
- the author contained in the event state.
- Since:
- jcms-10.0.7
-
getDataFromEventState
public static <T extends Data> T getDataFromEventState(Object[] state, Class<T> clazz, int fieldIndex) - Parameters:
state- the event stateclazz- the class of the datafieldIndex- the index of the data in the event state- Returns:
- the data contained in the event state.
- Since:
- jcms-10.0.7
-
getObjectFromEventState
- Parameters:
state- the event stateclazz- the class of the objectfieldIndex- the index of the object in the event state- Returns:
- the object contained in the event state.
- Since:
- jcms-10.0.7
-