to.etc.domui.hibernate.config
Class HibernateConfigurator

java.lang.Object
  extended by to.etc.domui.hibernate.config.HibernateConfigurator

public final class HibernateConfigurator
extends java.lang.Object

Helper class to help with configuring Hibernate for DomUI easily. You are not required to use this class at all; "normal" hibernate configuration works as "well" (meh), but this tries to hide lots of boilerplate needed to configure properly while only exposing that which is really needed in most cases.

Author:
Frits Jalvingh Created on Dec 30, 2010

Nested Class Summary
static class HibernateConfigurator.Mode
          Defines the database update mode (hibernate.hbm2ddl.auto).
 
Constructor Summary
HibernateConfigurator()
           
 
Method Summary
static void addClasses(java.lang.Class<?>... classes)
          Must be called before one of the "initialize" methods gets called, to register all POJO classes that need to be configured with Hibernate.
static QDataContextFactory getDataContextFactory()
          Returns the data context factory wrapping the hibernate code.
static javax.sql.DataSource getDataSource()
          Return the datasource, as configured.
static SessionFactory getSessionFactory()
          Return the Hibernate SessionFactory created by this code.
static void initialize(javax.sql.DataSource ds)
          Main worker to initialize the database layer, using Hibernate, with a user-specified core data source.
static void initialize(java.io.File poolfile, java.lang.String poolname)
          Initialize the layer using a poolid in the specified poolfile.
static void initialize(java.lang.String poolname)
          Alternate entrypoint: initialize the layer using a poolID in the default poolfile.
static Session internalGetSession(QDataContext dc)
          Unwrap the QDataContext and obtain it's Hibernate Session record.
static void registerQueryExecutor(IQueryExecutorFactory qexecutor)
          Register an alternative IQueryExecutorFactory which can execute QCriteria queries on non-hibernate classes.
static void registerQueryListener(IQueryListener ql)
          Register a DomUI IQueryListener that will be called when DomUI executes QCriteria queries.
static void schemaUpdate(HibernateConfigurator.Mode m)
          Set the "schema update" mode for Hibernate (corresponding to hbm2ddl.auto).
static void showSQL(boolean on)
          Set the "show sql" setting for hibernate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateConfigurator

public HibernateConfigurator()
Method Detail

getDataSource

@Nonnull
public static javax.sql.DataSource getDataSource()
Return the datasource, as configured.


getSessionFactory

public static SessionFactory getSessionFactory()
Return the Hibernate SessionFactory created by this code. Should not normally be used by common user code.

Returns:

internalGetSession

public static Session internalGetSession(QDataContext dc)
                                  throws java.lang.Exception
Unwrap the QDataContext and obtain it's Hibernate Session record.

Parameters:
dc -
Returns:
Throws:
java.lang.Exception

getDataContextFactory

public static QDataContextFactory getDataContextFactory()
Returns the data context factory wrapping the hibernate code.

Returns:

addClasses

public static void addClasses(java.lang.Class<?>... classes)
Must be called before one of the "initialize" methods gets called, to register all POJO classes that need to be configured with Hibernate. The classes will be added to the AnnotationConfiguration for Hibernate when initialize() is called. You can call this as many times as needed; all classes are added to a list.


showSQL

public static void showSQL(boolean on)
Set the "show sql" setting for hibernate. When called it overrides any "developer.properties" setting.

Parameters:
on -

schemaUpdate

public static void schemaUpdate(@Nonnull
                                HibernateConfigurator.Mode m)
Set the "schema update" mode for Hibernate (corresponding to hbm2ddl.auto). It defaults to NONE. When set to UPDATE Hibernate will do it's best to change the database schema in such a way that it corresponds to the annotated classes' definition.

Parameters:
m -

registerQueryListener

public static void registerQueryListener(IQueryListener ql)
Register a DomUI IQueryListener that will be called when DomUI executes QCriteria queries.

Parameters:
ql -

registerQueryExecutor

public static void registerQueryExecutor(IQueryExecutorFactory qexecutor)
Register an alternative IQueryExecutorFactory which can execute QCriteria queries on non-hibernate classes. WARNING: if you use this call all default query executors are not registered. This allows you to override them if needed. It also means that no Hibernate QCriteria code works at all if you do not add them! The default factories should be registered as follows:
 registerQueryListener(JdbcQueryExecutor.FACTORY);
 registerQueryListener(HibernateQueryExecutor.FACTORY);
 
By ordering your executors with the default ones you can control the order of acceptance for queries.

Parameters:
qexecutor -

initialize

public static void initialize(javax.sql.DataSource ds)
                       throws java.lang.Exception
Main worker to initialize the database layer, using Hibernate, with a user-specified core data source. This code also enables SQL logging when .developer.properties option hibernate.sql=true.

Parameters:
ds -
Throws:
java.lang.Exception

initialize

public static void initialize(java.lang.String poolname)
                       throws java.lang.Exception
Alternate entrypoint: initialize the layer using a poolID in the default poolfile.

Parameters:
poolname -
Throws:
java.lang.Exception

initialize

public static void initialize(java.io.File poolfile,
                              java.lang.String poolname)
                       throws java.lang.Exception
Initialize the layer using a poolid in the specified poolfile.

Parameters:
poolfile -
poolname -
Throws:
java.lang.Exception