2.17.2: 2011-06-17

net.sf.basedb.core
Class HibernateUtil

java.lang.Object
  extended by net.sf.basedb.core.HibernateUtil

public class HibernateUtil
extends Object

This class collects most of the functionality we need for using Hibernate.

Version:
2.0
Author:
Nicklas, Samuel
Last modified
$Date: 2010-11-04 13:40:34 +0100 (Thu, 04 Nov 2010) $

Field Summary
private static org.hibernate.cfg.Configuration cfg
          The Hibernate configuration, including all mappings.
private static DbEngine dbEngine
          Our extra database specific sql generation that is not possible by the Hibernate dialect.
private static org.hibernate.dialect.Dialect dialect
          The Hibernate database dialect in use.
private static boolean isInitialised
           
private static Logger log
          Log core events.
private static Logger logSql
          Log all batcher SQL statements.
private static org.hibernate.cfg.Mappings mappings
          The mappings related to a configuration.
private static org.hibernate.SessionFactory sf
          The single SessionFactory.
 
Constructor Summary
HibernateUtil()
           
 
Method Summary
private static void addColumn(org.hibernate.cfg.Mappings mappings, org.hibernate.mapping.Table hibernateTable, VirtualColumn column)
          Add a column to a table.
private static void addExtendedProperties(Element classTag, String className)
          Append <property> tags to the given class tag.
private static void addFilterConditions(Element classTag, String className)
          Add <filter> conditions to the given class tag.
private static void addRawDataMappings(org.hibernate.cfg.Configuration cfg)
          Generate additional mappings for the raw data types.
private static void addSqlFunctions(org.hibernate.cfg.Configuration cfg, DbEngine dbEngine)
          Add more SQL functions to HQL that are not present in a standard Hibernate installation.
private static void addStaticMappings(org.hibernate.cfg.Configuration cfg)
          Read all mapping files, which must be named Class.hbm.xml where class is the name of each class.
(package private) static void clear(org.hibernate.Session session)
          Clear the session of cached objects.
(package private) static void close(org.hibernate.Session session)
          Close a session.
(package private) static void close(org.hibernate.StatelessSession session)
          Close a statless session.
(package private) static void commit(org.hibernate.Transaction tx)
          Commit a transaction.
private static Element createFilterElement(String name, String condition)
          Create a <filter> tag using the given name and condition.
private static Element createPropertyElement(ExtendedProperty property)
          Creates a <property> tag from an extended property definition.
(package private) static org.hibernate.Query createQuery(org.hibernate.Session session, String hql)
          Create a Hibernate query.
(package private) static org.hibernate.Query createQuery(org.hibernate.StatelessSession session, String hql)
          Create a Hibernate query using a stateless session.
(package private) static org.hibernate.SQLQuery createSqlQuery(org.hibernate.Session session, String sql)
          Create a Hibernate SQL query.
(package private) static org.hibernate.SQLQuery createSqlQuery(org.hibernate.StatelessSession session, String sql)
          Create a Hibernate SQL query using a stateless session.
(package private) static void createStaticTables(boolean update, ProgressReporter progress)
          Create the all tables in the database.
(package private) static void createVirtualTable(VirtualDb db, VirtualTable table)
          Create a table in the dynamic database.
static void dbIndexes(boolean verbose, boolean silent, boolean dropIndexes, boolean updateIndexes)
          Prints a lot of useful stuff about the database to standard output.
(package private) static void deleteData(org.hibernate.Session session, BasicData data)
          Delete a data item from the database.
(package private) static void disableFilter(org.hibernate.Session session, String name)
          Disable the filter with the given name.
(package private) static
<R> R
doJdbcWork(org.hibernate.Session session, JdbcWork<R> work)
          Execute some arbitrary JDBC code using the same database connection as the Hibernate session.
(package private) static void dropVirtualTable(VirtualDb db, VirtualTable table)
          Drop a table in the dynamic database.
static void dynamicDbIndexes(boolean verbose, boolean silent, boolean dropIndexes)
          Prints a lot of useful stuff about the dynamic database to standard output.
(package private) static org.hibernate.Filter enableFilter(org.hibernate.Session session, String name)
          Enable the filter with the given name.
(package private) static void evictData(org.hibernate.Session session, BasicData data)
          Remove a data item from the internal cache of Hibernate.
(package private) static int executeUpdate(org.hibernate.Query query)
          Exceute an update or delete query.
(package private) static boolean exists(org.hibernate.Session session, Class clazz, int id)
          Checks if an item with the specified ID exists in the database.
private static void fixUnitSymbolColumnDefinition(Element classTag)
          Fixes the definition of the UnitSymbols.symbol column so that it is case-sensitive.
(package private) static void flush(org.hibernate.Session session)
          Flush all changed objects to the database.
(package private) static org.hibernate.mapping.PersistentClass getClassMapping(String entityName)
           
(package private) static Iterator<org.hibernate.mapping.PersistentClass> getClassMappings()
           
(package private) static org.hibernate.metadata.ClassMetadata getClassMetadata(String entityName)
           
(package private) static Connection getConnection(org.hibernate.Session session)
          Get the underlying JDBC connection from the Hibernate session.
static DbEngine getDbEngine()
          Get the database engine.
static org.hibernate.dialect.Dialect getDialect()
          Get the database dialect.
(package private) static org.hibernate.engine.Mapping getMapping()
           
(package private) static org.hibernate.Query getPredefinedQuery(org.hibernate.Session session, String name)
          Get a predefined HQL query.
(package private) static org.hibernate.Query getPredefinedQuery(org.hibernate.Session session, String name, String... replacements)
          Get a predefined HQL query.
(package private) static org.hibernate.Query getPredefinedQuery(org.hibernate.StatelessSession session, String name)
          Get a predefined HQL query using the stateless session.
(package private) static org.hibernate.Query getPredefinedSQLQuery(org.hibernate.Session session, String name, String... replacements)
          Get a predefined SQL query.
(package private) static org.hibernate.Query getPredefinedSQLQuery(org.hibernate.StatelessSession session, String name)
          Get a predefined SQL query using the stateless session.
(package private) static org.hibernate.SessionFactory getSessionFactory()
          Get the configured session factory.
(package private) static String getShortEntityName(String entityName)
          Removes the package name part of a class name and any ending 'Data'.
(package private) static void init1()
          First step of initialising this class.
(package private) static void init2()
          Second step of initialising this class.
(package private) static void initCollection(org.hibernate.Session session, BasicData data, String collectionName)
          Initialise a collection on a data object.
(package private) static boolean isEmptyDatabase()
          Check if the main database has any tables.
(package private) static
<T> T
loadData(Class<T> clazz, org.hibernate.Query query)
          Load a data item from the database using a query.
(package private) static
<T> T
loadData(org.hibernate.Session session, Class<T> clazz, int id)
          Load a data item from the database when you know the id.
(package private) static
<T> T
loadData(org.hibernate.Session session, Class<T> clazz, String entityName, int id)
          Load a data item from the database when you know the id.
(package private) static
<T> T
loadData(org.hibernate.StatelessSession session, Class<T> clazz, int id)
          Load a data item from the database using a statless session when you know the id.
(package private) static
<T> T
loadData(org.hibernate.StatelessSession session, Class<T> clazz, String entityName, int id)
          Load a data item from the database using a statless session when you know the id.
(package private) static
<T> ScrollIterator<T>
loadIterator(Class<T> clazz, org.hibernate.Query query, SessionControl sc)
          Scroll through the result of a query using an iterator.
(package private) static
<T> List<T>
loadList(Class<T> clazz, org.hibernate.Query query, SessionControl sc)
          Load a List of items from the database using a query.
(package private) static void lockData(org.hibernate.Session session, BasicData data, org.hibernate.LockOptions lockOptions)
          Reconnect a disconnected data object to the session, discarding changes that have been made while the object was disconnected.
private static void manipulateDocument(Document dom)
          Some XML files require manipulation by us before they are registered.
private static org.hibernate.mapping.Table newDynamicMapping(VirtualDb db, VirtualTable table)
          Create a new org.hibernate.mapping.Table object for the specified table.
(package private) static org.hibernate.Session newSession()
          Create a new Hibernate session.
(package private) static org.hibernate.Session newSession(org.hibernate.Interceptor interceptor)
          Create a new Hibernate session, optionally with an interceptor.
(package private) static org.hibernate.StatelessSession newStatelessSession(org.hibernate.Session session)
           
(package private) static org.hibernate.Transaction newTransaction(org.hibernate.Session session)
          Create a new transaction for a session.
static String quote(String value)
          Quote a string with the default quote type for the current database engine.
(package private) static void refresh(org.hibernate.Session session, BasicData data)
          Reload the data from the database for a given entity.
(package private) static void rollback(org.hibernate.Transaction tx)
          Rollback a transaction.
(package private) static void saveData(org.hibernate.Session session, BasicData data)
          Save a new data object to the database.
(package private) static void saveData(org.hibernate.StatelessSession session, BasicData data)
          Save a new data object to the database.
private static void setConfigurationProperties(org.hibernate.cfg.Configuration cfg)
          Read database configuration properties from the base.config file and add those to the Hibernate configuration.
private static boolean tableExists(String tableName, org.hibernate.Session session)
          Check if table in the dynamic database exists.
(package private) static void testTransactions()
           
(package private) static void unload()
          Unload all settings.
(package private) static void updateData(org.hibernate.Session session, BasicData data)
          Update an existing data object in the database.
static boolean useThetaJoin(QueryType queryType)
          Check if theta joins or ANSI joins are used by the database.
(package private) static boolean virtualTableExists(VirtualDb db, VirtualTable table)
          Check if a table exists in the dynamic database or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log
Log core events.


logSql

private static final Logger logSql
Log all batcher SQL statements.


sf

private static org.hibernate.SessionFactory sf
The single SessionFactory.


cfg

private static org.hibernate.cfg.Configuration cfg
The Hibernate configuration, including all mappings.


mappings

private static org.hibernate.cfg.Mappings mappings
The mappings related to a configuration.


dialect

private static org.hibernate.dialect.Dialect dialect
The Hibernate database dialect in use.


dbEngine

private static DbEngine dbEngine
Our extra database specific sql generation that is not possible by the Hibernate dialect.


isInitialised

private static boolean isInitialised
Constructor Detail

HibernateUtil

public HibernateUtil()
Method Detail

init1

static void init1()
           throws BaseException
First step of initialising this class. This is done at startup time by the Application.start() method. In this step we load configuration settings from the 'base.config' and 'hibernate.cfg.xml' files and create the Dialect and DbEngine objects. Initialising means that we load the configuration from the properties and the xml file, read all mapping files, generate additional mappings for the ExtendableData items and raw data, and generate filters used by Query implementation.

Throws:
BaseException

init2

static void init2()
           throws BaseException
Second step of initialising this class. This is done at startup time by the Application.start() method. In this step we read all mapping files, generate additional mappings for the ExtendableData items and raw data, and generate filters used by Query implementation.

Throws:
BaseException

unload

static void unload()
Unload all settings.


setConfigurationProperties

private static void setConfigurationProperties(org.hibernate.cfg.Configuration cfg)
                                        throws BaseException
Read database configuration properties from the base.config file and add those to the Hibernate configuration.

Throws:
BaseException

addStaticMappings

private static void addStaticMappings(org.hibernate.cfg.Configuration cfg)
                               throws BaseException
Read all mapping files, which must be named Class.hbm.xml where class is the name of each class. The must be located in the same directory as the class files, and we support loading the xml files both from a jar file of from the directory.

Throws:
BaseException

manipulateDocument

private static void manipulateDocument(Document dom)
Some XML files require manipulation by us before they are registered.


addExtendedProperties

private static void addExtendedProperties(Element classTag,
                                          String className)
Append <property> tags to the given class tag.

Parameters:
classTag - An Element representing a <class> tag
className - The name of the (ExtendableData) class
Since:
2.17

createPropertyElement

private static Element createPropertyElement(ExtendedProperty property)
Creates a <property> tag from an extended property definition. This also works for raw data properties since they extend from ExtendedProperty.

Since:
2.17

addFilterConditions

private static void addFilterConditions(Element classTag,
                                        String className)
Add <filter> conditions to the given class tag.

Parameters:
classTag - An Element representing a <class> tag
className - The name of the entity class
Since:
2.17

createFilterElement

private static Element createFilterElement(String name,
                                           String condition)
Create a <filter> tag using the given name and condition.

Since:
2.17

addRawDataMappings

private static void addRawDataMappings(org.hibernate.cfg.Configuration cfg)
                                throws BaseException
Generate additional mappings for the raw data types.

Throws:
BaseException

addSqlFunctions

private static void addSqlFunctions(org.hibernate.cfg.Configuration cfg,
                                    DbEngine dbEngine)
Add more SQL functions to HQL that are not present in a standard Hibernate installation. SQL functions are registered on the configuration with Configuration.addSqlFunction(String, SQLFunction). Note! The name of the function must be in lower-case letters, otherwise Hibernate will not be able to find it. In HQL, it is possible to use both lower-case and uppercase.

Here are the functions registered so far.

Since:
2.8

fixUnitSymbolColumnDefinition

private static void fixUnitSymbolColumnDefinition(Element classTag)
Fixes the definition of the UnitSymbols.symbol column so that it is case-sensitive. We need because some units have both milli (m) and Mega (M) as prefix (eg. mV and MV)

Since:
2.17

createStaticTables

static void createStaticTables(boolean update,
                               ProgressReporter progress)
                        throws BaseException
Create the all tables in the database. The database must exists and we recommend that it is empty to begin with.

Throws:
BaseException

isEmptyDatabase

static boolean isEmptyDatabase()
                        throws BaseException
Check if the main database has any tables.

Returns:
TRUE if there are any tables, FALSE otherwise
Throws:
BaseException

createVirtualTable

static void createVirtualTable(VirtualDb db,
                               VirtualTable table)
                        throws BaseException
Create a table in the dynamic database. The real table name is given by the VirtualTable.getTableName(VirtualDb). It is assumed that the table doesn't already exists. This can be checked by virtualTableExists(VirtualDb, VirtualTable). This method uses a separate connection to the database because some databases (ie. MySQL) can't handle transactions properly for this type of SQL statements.

This method uses classes in the org.hibernate.mapping package to define a Hibernate representation of the table and uses the Table.sqlCreateString method to generate the SQL. This should ensure that this code works with all database engines supported by Hibernate.

Parameters:
db - The virtual db item
table - Information about the table to create
Throws:
BaseException
See Also:
dropVirtualTable(VirtualDb, VirtualTable), virtualTableExists(VirtualDb, VirtualTable)

dropVirtualTable

static void dropVirtualTable(VirtualDb db,
                             VirtualTable table)
                      throws BaseException
Drop a table in the dynamic database. The real table name is given by the VirtualTable.getTableName(VirtualDb). If the table doesn't exists this method does nothing. This method uses a separate connection to the database because some databases (ie. MySQL) can't handle transactions properly for this type of SQL statements.

This method uses classes in the org.hibernate.mapping package to define a Hibernate representation of the table and uses the Table.sqlDropString method to generate the SQL. This should ensure that this code works with all database engines supported by Hibernate.

Parameters:
db - The virtual db item
table - Information about the table to drop
Throws:
BaseException
See Also:
createVirtualTable(VirtualDb, VirtualTable), virtualTableExists(VirtualDb, VirtualTable)

virtualTableExists

static boolean virtualTableExists(VirtualDb db,
                                  VirtualTable table)
Check if a table exists in the dynamic database or not. The real table name is given by the VirtualTable.getTableName(VirtualDb).

This method uses JDBC DatabaseMetaData object on a separate connection to find out if the table exists or not.

Parameters:
db - The virtual db item
table - Information about the table
See Also:
createVirtualTable(VirtualDb, VirtualTable), dropVirtualTable(VirtualDb, VirtualTable)

tableExists

private static boolean tableExists(String tableName,
                                   org.hibernate.Session session)
                            throws SQLException
Check if table in the dynamic database exists.

Parameters:
tableName - The name of the table
session - The Hibernate session
Throws:
SQLException
See Also:
virtualTableExists(VirtualDb, VirtualTable)

newDynamicMapping

private static org.hibernate.mapping.Table newDynamicMapping(VirtualDb db,
                                                             VirtualTable table)
Create a new org.hibernate.mapping.Table object for the specified table. This method is used by createVirtualTable(VirtualDb, VirtualTable) to build the mapping information Hibernate requires to generate the SQL to create the table.

Parameters:
db - The virtual db item
table - Information about the table to generate the mapping for

addColumn

private static void addColumn(org.hibernate.cfg.Mappings mappings,
                              org.hibernate.mapping.Table hibernateTable,
                              VirtualColumn column)
Add a column to a table. This method is used by newDynamicMapping(VirtualDb, VirtualTable) to build the mapping information Hibernate requires to generate the SQL to create the table.

Parameters:
hibernateTable - The org.hibernate.mapping.Table object that holds the mapping for the table
column - The column to add to the table

newSession

static org.hibernate.Session newSession()
                                 throws BaseException
Create a new Hibernate session.

Throws:
BaseException

newSession

static org.hibernate.Session newSession(org.hibernate.Interceptor interceptor)
                                 throws BaseException
Create a new Hibernate session, optionally with an interceptor.

Throws:
BaseException
Since:
2.13

newStatelessSession

static org.hibernate.StatelessSession newStatelessSession(org.hibernate.Session session)
                                                   throws BaseException
Throws:
BaseException

newTransaction

static org.hibernate.Transaction newTransaction(org.hibernate.Session session)
                                         throws BaseException
Create a new transaction for a session. If a transaction has already been created for the session, that one is returned.

Throws:
BaseException

getConnection

static Connection getConnection(org.hibernate.Session session)
Get the underlying JDBC connection from the Hibernate session. Hibernate 3.3 have implemented a partial replacement for the Session.connection() method that can be used if the connection or any derived object such as a PreparedStatement or ResultSet is not needed after the connection has been used. Such code should use doJdbcWork(Session, JdbcWork) instead.

Other code may continue using this method until the Hibernate team develops a full replacement. See http://forum.hibernate.org/viewtopic.php?t=974518

Since:
2.4
See Also:
doJdbcWork(Session, JdbcWork)

getSessionFactory

static org.hibernate.SessionFactory getSessionFactory()
Get the configured session factory.

Since:
2.15

doJdbcWork

static <R> R doJdbcWork(org.hibernate.Session session,
                        JdbcWork<R> work)
             throws SQLException
Execute some arbitrary JDBC code using the same database connection as the Hibernate session. This method should be used instead of getConnection(Session) wherever possible.

Parameters:
session - The Hibernate session to use
work - The work implementation
Returns:
Determined by the work implementation
Throws:
SQLException - In case there is an SQL error
Since:
2.9

commit

static void commit(org.hibernate.Transaction tx)
            throws BaseException
Commit a transaction.

Throws:
BaseException

rollback

static void rollback(org.hibernate.Transaction tx)
              throws BaseException
Rollback a transaction.

Throws:
BaseException

close

static void close(org.hibernate.Session session)
Close a session.


close

static void close(org.hibernate.StatelessSession session)
Close a statless session.


flush

static void flush(org.hibernate.Session session)
           throws BaseException
Flush all changed objects to the database.

Throws:
BaseException
See Also:
clear(Session)

clear

static void clear(org.hibernate.Session session)
           throws BaseException
Clear the session of cached objects. Changes that has not been written to the database are lost.

Throws:
BaseException
See Also:
flush(Session)

saveData

static void saveData(org.hibernate.Session session,
                     BasicData data)
              throws BaseException
Save a new data object to the database.

Throws:
BaseException

saveData

static void saveData(org.hibernate.StatelessSession session,
                     BasicData data)
              throws BaseException
Save a new data object to the database.

Throws:
BaseException

updateData

static void updateData(org.hibernate.Session session,
                       BasicData data)
                throws BaseException
Update an existing data object in the database.

Throws:
BaseException

lockData

static void lockData(org.hibernate.Session session,
                     BasicData data,
                     org.hibernate.LockOptions lockOptions)
              throws BaseException
Reconnect a disconnected data object to the session, discarding changes that have been made while the object was disconnected. This method is most useful with lockOptions = LockOptions.NONE if the logged in user only has read permission to the object.

Throws:
BaseException
See Also:
DbControl.reattachItem(BasicItem, boolean)

loadData

static <T> T loadData(org.hibernate.Session session,
                      Class<T> clazz,
                      int id)
           throws BaseException
Load a data item from the database when you know the id.

Parameters:
session - The Hibernate session which is connected to the database
clazz - An object of this class is returned with the data
id - The id of the item to load
Throws:
BaseException

loadData

static <T> T loadData(org.hibernate.Session session,
                      Class<T> clazz,
                      String entityName,
                      int id)
           throws BaseException
Load a data item from the database when you know the id.

Parameters:
session - The Hibernate session which is connected to the database
clazz - An object of this class is returned with the data
entityName - The entity name of the item
id - The id of the item to load
Throws:
BaseException
Since:
2.15

refresh

static void refresh(org.hibernate.Session session,
                    BasicData data)
Reload the data from the database for a given entity.

Parameters:
session - The Hibernate session which is connected to the database
data - The entity to reload
Since:
2.4

exists

static boolean exists(org.hibernate.Session session,
                      Class clazz,
                      int id)
Checks if an item with the specified ID exists in the database.

Parameters:
session - The Hibernate session which is connected to the database
clazz - The type of the item
id - The ID of the item
Returns:
TRUE if the item exists in the database, FALSE otherwise
Since:
2.4

loadData

static <T> T loadData(org.hibernate.StatelessSession session,
                      Class<T> clazz,
                      int id)
           throws BaseException
Load a data item from the database using a statless session when you know the id.

Parameters:
session - The Hibernate stateless session which is connected to the database
clazz - An object of this class is returned with the data
id - The id of the item to load
Throws:
BaseException

loadData

static <T> T loadData(org.hibernate.StatelessSession session,
                      Class<T> clazz,
                      String entityName,
                      int id)
           throws BaseException
Load a data item from the database using a statless session when you know the id.

Parameters:
session - The Hibernate stateless session which is connected to the database
clazz - An object of this class is returned with the data
entityName - The entity name of the item
id - The id of the item to load
Throws:
BaseException

loadData

static <T> T loadData(Class<T> clazz,
                      org.hibernate.Query query)
           throws BaseException
Load a data item from the database using a query. If the query returns more than one item, only the first is returned.

Parameters:
clazz - An object of this class is returned with the data
query - A Query object which should select one item of the specified class
Throws:
BaseException

executeUpdate

static int executeUpdate(org.hibernate.Query query)
                  throws BaseException
Exceute an update or delete query.

Parameters:
query - A Query object which is executed using the Query.executeUpdate() method
Returns:
The number of affected items
Throws:
BaseException

initCollection

static void initCollection(org.hibernate.Session session,
                           BasicData data,
                           String collectionName)
                    throws BaseException
Initialise a collection on a data object. This method is useful if you plan to detach an item.

Throws:
BaseException
See Also:
DbControl.detachItem(BasicItem)

deleteData

static void deleteData(org.hibernate.Session session,
                       BasicData data)
                throws BaseException
Delete a data item from the database. If the ID doesn't exist in the database this metod does nothing.

Throws:
BaseException

evictData

static void evictData(org.hibernate.Session session,
                      BasicData data)
               throws BaseException
Remove a data item from the internal cache of Hibernate. This also means that changes to the object will not be saved to the database unless it is reconnected again.

Throws:
BaseException
See Also:
updateData(Session, BasicData), lockData(Session, BasicData, LockOptions)

createQuery

static org.hibernate.Query createQuery(org.hibernate.Session session,
                                       String hql)
                                throws BaseException
Create a Hibernate query.

Throws:
BaseException

createQuery

static org.hibernate.Query createQuery(org.hibernate.StatelessSession session,
                                       String hql)
                                throws BaseException
Create a Hibernate query using a stateless session.

Throws:
BaseException

createSqlQuery

static org.hibernate.SQLQuery createSqlQuery(org.hibernate.Session session,
                                             String sql)
                                      throws BaseException
Create a Hibernate SQL query.

Throws:
BaseException

createSqlQuery

static org.hibernate.SQLQuery createSqlQuery(org.hibernate.StatelessSession session,
                                             String sql)
                                      throws BaseException
Create a Hibernate SQL query using a stateless session.

Throws:
BaseException

enableFilter

static org.hibernate.Filter enableFilter(org.hibernate.Session session,
                                         String name)
                                  throws BaseException
Enable the filter with the given name.

Throws:
BaseException

disableFilter

static void disableFilter(org.hibernate.Session session,
                          String name)
                   throws BaseException
Disable the filter with the given name.

Throws:
BaseException

loadList

static <T> List<T> loadList(Class<T> clazz,
                            org.hibernate.Query query,
                            SessionControl sc)
                 throws BaseException
Load a List of items from the database using a query.

Parameters:
clazz - The list should contain objects of this class
query - The query to execute
sc - A optional SessionControl that is automatically protected from timeouts during the time the query is running
Throws:
BaseException

loadIterator

static <T> ScrollIterator<T> loadIterator(Class<T> clazz,
                                          org.hibernate.Query query,
                                          SessionControl sc)
                               throws BaseException
Scroll through the result of a query using an iterator.

Parameters:
clazz - The iterator returns objects of this class
query - The query to execute
sc - A optional SessionControl that is automatically protected from timeouts during the time the query is running
Throws:
BaseException

getPredefinedQuery

static org.hibernate.Query getPredefinedQuery(org.hibernate.Session session,
                                              String name)
                                       throws BaseException
Get a predefined HQL query.

Throws:
BaseException
See Also:
PredefinedQuery

getPredefinedQuery

static org.hibernate.Query getPredefinedQuery(org.hibernate.Session session,
                                              String name,
                                              String... replacements)
                                       throws BaseException
Get a predefined HQL query.

Parameters:
replacements - In the SQL string we look for {1}, {2}, ... and replace this with the contents of the string array
Throws:
BaseException
See Also:
PredefinedQuery

getPredefinedQuery

static org.hibernate.Query getPredefinedQuery(org.hibernate.StatelessSession session,
                                              String name)
                                       throws BaseException
Get a predefined HQL query using the stateless session.

Throws:
BaseException
See Also:
PredefinedQuery

getPredefinedSQLQuery

static org.hibernate.Query getPredefinedSQLQuery(org.hibernate.Session session,
                                                 String name,
                                                 String... replacements)
                                          throws BaseException
Get a predefined SQL query.

Throws:
BaseException
See Also:
PredefinedQuery

getPredefinedSQLQuery

static org.hibernate.Query getPredefinedSQLQuery(org.hibernate.StatelessSession session,
                                                 String name)
                                          throws BaseException
Get a predefined SQL query using the stateless session.

Throws:
BaseException
See Also:
PredefinedQuery

getClassMappings

static Iterator<org.hibernate.mapping.PersistentClass> getClassMappings()

getClassMapping

static org.hibernate.mapping.PersistentClass getClassMapping(String entityName)

getClassMetadata

static org.hibernate.metadata.ClassMetadata getClassMetadata(String entityName)

getMapping

static org.hibernate.engine.Mapping getMapping()

getDialect

public static org.hibernate.dialect.Dialect getDialect()
Get the database dialect.


getDbEngine

public static DbEngine getDbEngine()
Get the database engine.


useThetaJoin

public static boolean useThetaJoin(QueryType queryType)
Check if theta joins or ANSI joins are used by the database.

Parameters:
queryType - Query type to be checked.
Returns:
TRUE if theta joins are used, FALSE if ANSI joins are used.

quote

public static String quote(String value)
Quote a string with the default quote type for the current database engine. Ie. with MySQL: value --> `value`, and with any ANSI-compatible database: value --> "value". This method uses the Dialect.openQuote and Dialect.closeQuote methods of the currently installed Hibernate dialect.

Parameters:
value - The value to quote
Returns:
The quoted value
See Also:
getDialect()

getShortEntityName

static String getShortEntityName(String entityName)
Removes the package name part of a class name and any ending 'Data'.


testTransactions

static void testTransactions()
                      throws BaseException
Throws:
BaseException

dynamicDbIndexes

public static void dynamicDbIndexes(boolean verbose,
                                    boolean silent,
                                    boolean dropIndexes)
Prints a lot of useful stuff about the dynamic database to standard output. For each table the output includes information about columns, indexes, primary keys and foreign keys as found in the current database.

Parameters:
verbose - If true, lots of information will be printed
silent - If true, no information will be printed
dropIndexes - If true, all indexes will be dropped

dbIndexes

public static void dbIndexes(boolean verbose,
                             boolean silent,
                             boolean dropIndexes,
                             boolean updateIndexes)
Prints a lot of useful stuff about the database to standard output. For each table the output includes information about columns, indexes, primary keys and foreign keys as found in the Hibernate mapping information and in the current database.

Parameters:
verbose - If true, lots of information will be printed
silent - If true, no information will be printed
dropIndexes - If true, all indexes will be dropped
updateIndexes - If true, indexes that doesn't already exist will be created

2.17.2: 2011-06-17