Class HibernateUtil
- java.lang.Object
-
- org.pentaho.platform.repository.hibernate.HibernateUtil
-
- All Implemented Interfaces:
org.pentaho.platform.api.engine.IPentahoSystemEntryPoint
,org.pentaho.platform.api.engine.IPentahoSystemExitPoint
public class HibernateUtil extends Object implements org.pentaho.platform.api.engine.IPentahoSystemEntryPoint, org.pentaho.platform.api.engine.IPentahoSystemExitPoint
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
beginTransaction()
Start a new database transaction.static void
clear()
static void
closeSession()
Closes the Session local to the thread.static void
commitTransaction()
Commit the database transaction.static org.hibernate.Session
disconnectSession()
Disconnect and return Session from current Thread.static void
evict(Object obj)
Evicts the object from the Hibernate cache.static void
flushSession()
static org.hibernate.cfg.Configuration
getConfiguration()
Returns the original Hibernate configuration.static org.hibernate.Session
getSession()
Retrieves the current Session local to the thread.static org.hibernate.SessionFactory
getSessionFactory()
Returns the SessionFactory used for this static class.protected static boolean
initialize()
static boolean
isOracleDialect()
HACK This method is necessary to determine whether code should execute based on Oracle in use as the RDBMS repository for the platform.static void
makePersistent(Object obj)
Persists changes to the object.static void
makeTransient(Object obj)
Deletes the object from Hibernatestatic void
rebuildSessionFactory()
Rebuild the SessionFactory with the static Configuration.static void
rebuildSessionFactory(org.hibernate.cfg.Configuration cfg)
Rebuild the SessionFactory with the given Hibernate Configuration.static void
registerInterceptor(org.hibernate.Interceptor interceptor)
Register a Hibernate interceptor with the current thread.static void
rollbackTransaction()
Commit the database transaction.static List
searchForTerm(org.pentaho.platform.api.repository.ISearchable searchable, String searchTerm, int searchType)
Searches an ISearchable object for a search term.void
setUseNewDatasourceService(boolean useNewService)
void
systemEntryPoint()
void
systemExitPoint()
-
-
-
Method Detail
-
setUseNewDatasourceService
public void setUseNewDatasourceService(boolean useNewService)
-
initialize
protected static boolean initialize()
-
getSessionFactory
public static org.hibernate.SessionFactory getSessionFactory()
Returns the SessionFactory used for this static class.- Returns:
- SessionFactory
-
getConfiguration
public static org.hibernate.cfg.Configuration getConfiguration()
Returns the original Hibernate configuration.- Returns:
- Configuration
-
rebuildSessionFactory
public static void rebuildSessionFactory() throws org.pentaho.platform.api.repository.RepositoryException
Rebuild the SessionFactory with the static Configuration.- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
rebuildSessionFactory
public static void rebuildSessionFactory(org.hibernate.cfg.Configuration cfg) throws org.pentaho.platform.api.repository.RepositoryException
Rebuild the SessionFactory with the given Hibernate Configuration.- Parameters:
cfg
-- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
getSession
public static org.hibernate.Session getSession() throws org.pentaho.platform.api.repository.RepositoryException
Retrieves the current Session local to the thread. If no Session is open, opens a new Session for the running thread.- Returns:
- Session
- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
flushSession
public static void flushSession() throws org.pentaho.platform.api.repository.RepositoryException
- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
closeSession
public static void closeSession() throws org.pentaho.platform.api.repository.RepositoryException
Closes the Session local to the thread.- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
beginTransaction
public static void beginTransaction() throws org.pentaho.platform.api.repository.RepositoryException
Start a new database transaction.- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
commitTransaction
public static void commitTransaction() throws org.pentaho.platform.api.repository.RepositoryException
Commit the database transaction.- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
rollbackTransaction
public static void rollbackTransaction() throws org.pentaho.platform.api.repository.RepositoryException
Commit the database transaction.- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
disconnectSession
public static org.hibernate.Session disconnectSession() throws org.pentaho.platform.api.repository.RepositoryException
Disconnect and return Session from current Thread.- Returns:
- Session the disconnected Session
- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
registerInterceptor
public static void registerInterceptor(org.hibernate.Interceptor interceptor)
Register a Hibernate interceptor with the current thread.Every Session opened is opened with this interceptor after registration. Has no effect if the current Session of the thread is already open, effective on next close()/getSession().
-
searchForTerm
public static List searchForTerm(org.pentaho.platform.api.repository.ISearchable searchable, String searchTerm, int searchType)
Searches an ISearchable object for a search term. The search rules are as follows: If the searchType is ISearchable.SEARCH_TYPE_PHRASE, then the fields in the table are searched for the exact phrase given. If the searchType is ISearchable.SEARCH_TYPE_WORDS_AND or ..._OR, then the following happens: a- Each word in the searchTerm is extracted and put into a list of search terms. b- Each search term is surrounded by the SQL wildcard '%'. So each search term becomes %term%. c- A dynamic query is generated searching each of the columns for each search term d- The searchType is used to determine the connector between each search term. e- The AND will match only if all of the terms appear in a specific column - cross-column searching using ..._AND will NOT work. In other words, if your search term is "East Sales", and your search type is ..._AND, a row will be returned if one of the columns contains East and the same column contains Sales. A row will NOT be returned if one column only contains East, and another column only contains Sales. This type of functionality could be obtained using a view that concatenates all of the searchable columns together into one large column, but this would be costly and database-specific.- Parameters:
searchable
- ISearchable to searchsearchTerm
- Search Term - see above for rulessearchType
- One of: ISearchable.SEARCH_TYPE_PHRASE,ISearchable.SEARCH_TYPE_WORDS_AND, ISearchable.SEARCH_TYPE_WORDS_OR- Returns:
- A list of objects from Hibernate that met the conditions specified.
-
clear
public static void clear()
-
makePersistent
public static void makePersistent(Object obj) throws org.pentaho.platform.api.repository.RepositoryException
Persists changes to the object. Object must be defined to hibernate.- Parameters:
obj
- The object to make persistent- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
makeTransient
public static void makeTransient(Object obj) throws org.pentaho.platform.api.repository.RepositoryException
Deletes the object from Hibernate- Parameters:
obj
- The object to make transient- Throws:
org.pentaho.platform.api.repository.RepositoryException
-
isOracleDialect
public static boolean isOracleDialect()
HACK This method is necessary to determine whether code should execute based on Oracle in use as the RDBMS repository for the platform. Helps us work around Oracle JDBC driver bugs.- Returns:
- true if Hibernate dialect for oracle is in use.
-
evict
public static void evict(Object obj)
Evicts the object from the Hibernate cache. Call this if you don't believe you'll need this object in the cache. This is also good to call if you're doing semi-mass updates.- Parameters:
obj
-
-
systemEntryPoint
public void systemEntryPoint()
- Specified by:
systemEntryPoint
in interfaceorg.pentaho.platform.api.engine.IPentahoSystemEntryPoint
-
systemExitPoint
public void systemExitPoint()
- Specified by:
systemExitPoint
in interfaceorg.pentaho.platform.api.engine.IPentahoSystemExitPoint
-
-