public class DbUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
DbUtil.Database
Enumerates the different database engines the storage subsystem can work with.
|
Constructor and Description |
---|
DbUtil(java.util.Properties properties)
Creates a new instance of the DbUtil object.
|
Modifier and Type | Method and Description |
---|---|
void |
addClass(org.hibernate.cfg.Configuration conf,
java.lang.Class<?> clazz)
Depending on the dialect used to talk with the database this method will load the
hbm.xml file from the right source directory and load it into the configuration
|
void |
clear() |
static java.lang.String |
getDatabasePrefix(DbUtil.Database databaseType)
Obtains a short string to locate resources for each database type.
|
DbUtil.Database |
getDatabaseType()
Reads the properties of this DBconnection and sets the database subsystem
to the appropriate type.
|
static java.lang.String |
getDialect(DbUtil.Database database)
Returns the class name implementing the dialect to create
SQL statements for the specific database.
|
static java.lang.String |
getDriver(DbUtil.Database database)
Returns the driver class name associated to the database type.
|
java.lang.Throwable |
getLastException()
Returns the last error produced during the call to
getSessionFactory(RegisterExtraClasses[])
or null in case of no errors was produced. |
java.util.Properties |
getProperties()
Access to the Properties object in order to allow the pojo generation process to be tuned
|
org.hibernate.SessionFactory |
getSessionFactory(RegisterExtraClasses[] registers)
gets existing or creates a new session factory.
|
boolean |
isDatabaseAvailable()
Returns true if the database is available.
|
static void |
registerDriver(java.lang.String driver,
java.lang.String dialect)
Registers a new database.
|
void |
resetLastException()
Clear the last exception stored on this class.
|
void |
resetSessionFactory()
Clear current session factory and the last exception.
|
public DbUtil(java.util.Properties properties)
properties
- Properties object. Extra properties for the Hibernate connection to the database and tune the pojo generation processpublic void resetSessionFactory()
getSessionFactory(RegisterExtraClasses[])
will create a new one.public void resetLastException()
public org.hibernate.SessionFactory getSessionFactory(RegisterExtraClasses[] registers)
The parameter is optional (can be null), if supplied it is an array of objects that implements the RegisterExtraClasse interface and this causes the configuration object to load more classes in the data model. If on the first call this parameter is not null, next calls to this method will return the same session factory even if the parameter is null (the created session factory is stored on this class and returned immediately)
Returns null in case there are any Exceptions during the connection
to the database or creating the model. In that case, the method
getLastException()
will return the last error.
registers
- Optional parameter, can be null.resetSessionFactory()
,
getLastException()
public static void registerDriver(java.lang.String driver, java.lang.String dialect)
driver
- (java class name implementing the JDBC driver. Must be reachable in the classpath)dialect
- (java class name implementing the Hibernate Dialect. Must be in the classpath)public DbUtil.Database getDatabaseType()
public static java.lang.String getDatabasePrefix(DbUtil.Database databaseType)
public void addClass(org.hibernate.cfg.Configuration conf, java.lang.Class<?> clazz)
conf
- the confclazz
- the clazzpublic boolean isDatabaseAvailable()
getSessionFactory(RegisterExtraClasses[])
returned no errors last time it was called. Note this method
does not execute tests to ensure the database is still available
this method returns true if the first call was a successpublic java.lang.Throwable getLastException()
getSessionFactory(RegisterExtraClasses[])
or null in case of no errors was produced.public static java.lang.String getDriver(DbUtil.Database database)
database
- a value from the Database enumerationpublic static java.lang.String getDialect(DbUtil.Database database)
database
- the databasepublic java.util.Properties getProperties()
public void clear()
Copyright 2006-2015 Reporting Standard S.L., C/ Torrecilla del Puerto 1, 28043, Madrid, Espaņa