org.pentaho.platform.repository.hibernate
Class HibernateUtil

java.lang.Object
  extended by org.pentaho.platform.repository.hibernate.HibernateUtil
All Implemented Interfaces:
IPentahoSystemEntryPoint, IPentahoSystemExitPoint

public class HibernateUtil
extends Object
implements IPentahoSystemEntryPoint, IPentahoSystemExitPoint


Method Summary
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.
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 Hibernate
static 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(ISearchable searchable, String searchTerm, int searchType)
          Searches an ISearchable object for a search term.
 void setUseNewDatasourceService(boolean useNewService)
           
 void systemEntryPoint()
          Perform operations necessary upon entry to the system.
 void systemExitPoint()
          Perform any system cleanup actions after the thread executes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setUseNewDatasourceService

public void setUseNewDatasourceService(boolean useNewService)

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 RepositoryException
Rebuild the SessionFactory with the static Configuration.

Throws:
RepositoryException

rebuildSessionFactory

public static void rebuildSessionFactory(org.hibernate.cfg.Configuration cfg)
                                  throws RepositoryException
Rebuild the SessionFactory with the given Hibernate Configuration.

Parameters:
cfg -
Throws:
RepositoryException

getSession

public static org.hibernate.Session getSession()
                                        throws 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:
RepositoryException

flushSession

public static void flushSession()
                         throws RepositoryException
Throws:
RepositoryException

closeSession

public static void closeSession()
                         throws RepositoryException
Closes the Session local to the thread.

Throws:
RepositoryException

beginTransaction

public static void beginTransaction()
                             throws RepositoryException
Start a new database transaction.

Throws:
RepositoryException

commitTransaction

public static void commitTransaction()
                              throws RepositoryException
Commit the database transaction.

Throws:
RepositoryException

rollbackTransaction

public static void rollbackTransaction()
                                throws RepositoryException
Commit the database transaction.

Throws:
RepositoryException

disconnectSession

public static org.hibernate.Session disconnectSession()
                                               throws RepositoryException
Disconnect and return Session from current Thread.

Returns:
Session the disconnected Session
Throws:
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(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 search
searchTerm - Search Term - see above for rules
searchType - 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 RepositoryException
Persists changes to the object. Object must be defined to hibernate.

Parameters:
obj - The object to make persistent
Throws:
RepositoryException

makeTransient

public static void makeTransient(Object obj)
                          throws RepositoryException
Deletes the object from Hibernate

Parameters:
obj - The object to make transient
Throws:
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()
Description copied from interface: IPentahoSystemEntryPoint
Perform operations necessary upon entry to the system.

Specified by:
systemEntryPoint in interface IPentahoSystemEntryPoint

systemExitPoint

public void systemExitPoint()
Description copied from interface: IPentahoSystemExitPoint
Perform any system cleanup actions after the thread executes.

Specified by:
systemExitPoint in interface IPentahoSystemExitPoint