public abstract class HibernateFactory
extends java.lang.Object
Abstract methods define what the subclass must implement to determine what is specific to that Factory's instance.
| Modifier | Constructor and Description |
|---|---|
protected |
HibernateFactory() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addConfigurator(Configurator c)
Register a class with HibernateFactory, to give the registered class a
chance to modify the Hibernate configuration before creating the
SessionFactory.
|
static byte[] |
blobToByteArray(java.sql.Blob fromBlob)
utility to convert blob to byte array
|
static java.sql.Blob |
byteArrayToBlob(byte[] data)
Convert a byte[] array to a Blob object.
|
static void |
closeSession()
Closes the Hibernate Session stored in ThreadLocal storage.
|
static void |
closeSessionFactory()
Close the sessionFactory
|
static void |
commitTransaction()
Commit the transaction for the current session.
|
static void |
createSessionFactory()
Create a SessionFactory, loading the hbm.xml files from the default
location (com.redhat.rhn.domain).
|
static void |
createSessionFactory(java.lang.String[] additionalLocation)
Create a SessionFactory, loading the hbm.xml files from alternate
location
|
protected static void |
executeCallableMode(java.lang.String name,
java.lang.String mode,
java.util.Map params) |
protected static DataResult |
executeSelectMode(java.lang.String name,
java.lang.String mode,
java.util.Map params) |
static java.lang.String |
getBlobContents(java.lang.Object blob)
Get the String version of an object corresponding to a BLOB column
Handles both the byte[] and the Blob cases
|
static java.lang.String |
getByteArrayContents(byte[] barr)
Get the String version of the byte array contents
used to return the string representation of byte arrays constructed from blobs
|
protected abstract org.apache.log4j.Logger |
getLogger()
Get the Logger for the derived class so log messages show up on the
correct class
|
java.lang.Object |
getObject(java.lang.Class clazz,
java.io.Serializable id)
Return the persistent instance of the given entity class with the given
identifier, or null if there is no such persistent instance.
|
static org.hibernate.Session |
getSession()
Returns the Hibernate session stored in ThreadLocal storage.
|
static void |
initialize()
Initialize the underlying db layer
|
static boolean |
inTransaction()
Is transaction pending for thread?
|
static boolean |
isClosed()
Is the factory closed
|
static boolean |
isInitialized()
Returns the current initialization status
|
protected java.util.List |
listObjectsByNamedQuery(java.lang.String qryName,
java.util.Map qryParams)
Using a named query, find all the objects matching the criteria within.
|
protected java.util.List |
listObjectsByNamedQuery(java.lang.String qryName,
java.util.Map qryParams,
boolean cacheable)
Using a named query, find all the objects matching the criteria within.
|
protected java.util.List |
listObjectsByNamedQuery(java.lang.String qryName,
java.util.Map qryParams,
java.util.Collection col,
java.lang.String colLabel)
Using a named query, find all the objects matching the criteria within.
|
protected java.lang.Object |
lockObject(java.lang.Class clazz,
java.io.Serializable id)
Return a locked persistent instance of the given entity class with
the given identifier, or null if there is no such persistent instance.
|
protected java.lang.Object |
lookupObjectByNamedQuery(java.lang.String qryName,
java.util.Map qryParams)
Finds a single instance of a persistent object given a named query.
|
protected java.lang.Object |
lookupObjectByNamedQuery(java.lang.String qryName,
java.util.Map qryParams,
boolean cacheable)
Finds a single instance of a persistent object given a named query.
|
static java.lang.Object |
reload(java.lang.Object obj)
Util to reload an object using Hibernate
|
protected int |
removeObject(java.lang.Object toRemove)
Remove a Session from the DB
|
static void |
rollbackTransaction()
Roll the transaction for the current session back.
|
protected void |
saveObject(java.lang.Object toSave)
Saves the given object to the database using Hibernate.
|
protected void |
saveObject(java.lang.Object toSave,
boolean saveOrUpdate)
Saves the given object to the database using Hibernate.
|
static byte[] |
stringToByteArray(java.lang.String data)
Convert a String to a byte[] object.
|
public static void addConfigurator(Configurator c)
c - Configurator to override Hibernate configuration.public static void closeSessionFactory()
public static boolean isClosed()
public static void createSessionFactory()
public static void createSessionFactory(java.lang.String[] additionalLocation)
additionalLocation - Alternate location for hbm.xml filesprotected abstract org.apache.log4j.Logger getLogger()
protected java.lang.Object lookupObjectByNamedQuery(java.lang.String qryName,
java.util.Map qryParams)
qryName - The name of the query used to find the persistent object.
It should be formulated to ensure a single object is returned or an error
will occur.qryParams - Map of named bind parameters whose keys are Strings. The
map can also be null.protected java.lang.Object lookupObjectByNamedQuery(java.lang.String qryName,
java.util.Map qryParams,
boolean cacheable)
qryName - The name of the query used to find the persistent object.
It should be formulated to ensure a single object is returned or an error
will occur.qryParams - Map of named bind parameters whose keys are Strings. The
map can also be null.cacheable - if we should cache the results of this objectprotected java.util.List listObjectsByNamedQuery(java.lang.String qryName,
java.util.Map qryParams)
qryName - Named query to use to find a list of objects.qryParams - Map of named bind parameters whose keys are Strings. The
map can also be null.protected java.util.List listObjectsByNamedQuery(java.lang.String qryName,
java.util.Map qryParams,
java.util.Collection col,
java.lang.String colLabel)
qryName - Named query to use to find a list of objects.qryParams - Map of named bind parameters whose keys are Strings. The
map can also be null.col - the collection to use as an inclausecolLabel - the label the collection will haveprotected java.util.List listObjectsByNamedQuery(java.lang.String qryName,
java.util.Map qryParams,
boolean cacheable)
qryName - Named query to use to find a list of objects.qryParams - Map of named bind parameters whose keys are Strings. The
map can also be null.cacheable - if we should cache the results of this queryprotected void saveObject(java.lang.Object toSave,
boolean saveOrUpdate)
toSave - Object to be persisted.saveOrUpdate - true if saveOrUpdate should be called, false if
save() is to be called directly.protected void saveObject(java.lang.Object toSave)
toSave - Object to be persisted.protected int removeObject(java.lang.Object toRemove)
toRemove - Object to be removed.public static org.hibernate.Session getSession()
public static void commitTransaction()
throws org.hibernate.HibernateException
rollbackTransaction()can only be called once per session.org.hibernate.HibernateException - if the commit failspublic static void rollbackTransaction()
throws org.hibernate.HibernateException
commitTransaction()can only be called once per session.org.hibernate.HibernateException - if the commit failspublic static boolean inTransaction()
public static void closeSession()
public java.lang.Object getObject(java.lang.Class clazz,
java.io.Serializable id)
clazz - a persistent classid - an identifierprotected java.lang.Object lockObject(java.lang.Class clazz,
java.io.Serializable id)
clazz - a persistent classid - an identifierpublic static java.lang.Object reload(java.lang.Object obj)
throws org.hibernate.HibernateException
obj - to be reloadedorg.hibernate.HibernateException - if something bad happens.public static byte[] blobToByteArray(java.sql.Blob fromBlob)
fromBlob - blob to convertpublic static java.lang.String getByteArrayContents(byte[] barr)
barr - byte array to convert to Stringpublic static java.lang.String getBlobContents(java.lang.Object blob)
blob - the blob to handlepublic static java.sql.Blob byteArrayToBlob(byte[] data)
data - array to convert to a Blobpublic static byte[] stringToByteArray(java.lang.String data)
data - string to convert to a Blobpublic static void initialize()
public static boolean isInitialized()
protected static DataResult executeSelectMode(java.lang.String name, java.lang.String mode, java.util.Map params)
protected static void executeCallableMode(java.lang.String name,
java.lang.String mode,
java.util.Map params)