|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectshared.HibernateHelper
public class HibernateHelper
Helper methods for accessing Hibernate.
| Field Summary | |
|---|---|
protected static java.lang.Exception |
lastError
The last error that was generated by Hibernate. |
protected static java.util.List<java.lang.Class> |
listClasses
The list of classes that are known to Hibernate. |
protected static org.apache.log4j.Logger |
log
Logger for reporting errors. |
protected static org.hibernate.SessionFactory |
sessionFactory
The session factory that is used by Hibernate for all access. |
| Constructor Summary | |
|---|---|
HibernateHelper()
|
|
| Method Summary | |
|---|---|
protected static boolean |
addMappings(java.util.List<java.lang.Class> list,
java.lang.Class... mappings)
Test if the class being added is already known by Hibernate. |
protected static org.hibernate.SessionFactory |
buildFactory(org.hibernate.cfg.Configuration cfg)
Build the factory. |
static void |
closeFactory()
Close the factory. |
static void |
closeFactory(org.hibernate.SessionFactory factory)
Close the factory. |
protected static void |
configureFromFile(org.hibernate.cfg.Configuration cfg)
Read from the hibernate.cfg.xml file. |
protected static org.hibernate.SessionFactory |
createFactory(java.util.Properties props,
java.util.List<java.lang.Class> list)
Create the session factory. |
static void |
createTable(java.lang.Class... mappings)
Overloaded for no properties. |
static void |
createTable(java.util.Properties props,
java.lang.Class... mappings)
Create a temporary session factory to create the tables. |
static java.lang.Object |
getFirstMatch(java.lang.Class classBean,
java.lang.String strKey,
java.lang.Object value)
Retreives the first record that has a field that matches the specified value. |
static java.lang.Object |
getFirstMatch(java.lang.Object data,
java.lang.String strKey,
java.lang.Object value)
Overload of getFirstMatch that accepts a bean object instead of a bean class. |
static java.lang.Object |
getKeyData(java.lang.Class beanClass,
long itemId)
Retrieves the bean with the specified value for the key field |
static java.lang.Exception |
getLastError()
Retrieve the last error generated by Hibernate. |
static java.util.List |
getListData(java.lang.Class classBean)
Retrieve all the records from the database. |
static java.util.List |
getListData(java.lang.Class classBean,
java.lang.String strKey,
java.lang.Object value)
Use a criteria object to retrieve records from the database. |
static void |
initSessionFactory(java.lang.Class... mappings)
Overloaded initSessionFactory for not sending props. |
static void |
initSessionFactory(java.util.Properties props,
java.lang.Class... mappings)
Initialise the session factory that Hibernate uses for all access. |
static boolean |
isSessionOpen()
Tests if the sessionFactory exists. |
static void |
removeDB(java.lang.Object obj)
Call the Hibernate method delete. |
static void |
saveDB(java.lang.Object obj)
Call the Hibernate method save. |
protected static void |
someDatabaseProcess()
A dummy method, used to test if the database is open. |
protected static void |
testConnection(org.hibernate.SessionFactory factory)
Test if the connection to the database works. |
static boolean |
testDB(javax.servlet.http.HttpServletResponse response)
Tests if a database operation will succeed on the sessionFactory. |
static void |
updateDB(java.util.List list)
Call the Hibernate method saveOrUpdate. |
static void |
updateDB(java.lang.Object obj)
Call the Hibernate method saveOrUpdate. |
static void |
writeError(javax.servlet.http.HttpServletResponse response)
Writes an error page for the last generated error |
static void |
writeError(javax.servlet.http.HttpServletResponse response,
java.lang.String title,
java.lang.Exception ex)
Writes an error message to the response. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static org.apache.log4j.Logger log
protected static java.util.List<java.lang.Class> listClasses
protected static org.hibernate.SessionFactory sessionFactory
protected static java.lang.Exception lastError
| Constructor Detail |
|---|
public HibernateHelper()
| Method Detail |
|---|
public static void initSessionFactory(java.util.Properties props,
java.lang.Class... mappings)
props - Properties for initalising Hibernatemappings - The classes that are to be mapped by Hibernatepublic static void initSessionFactory(java.lang.Class... mappings)
mappings - The list of classes that are to be mapped.
public static void createTable(java.util.Properties props,
java.lang.Class... mappings)
props - The properties to initialise Hibernatemappings - The classes to be mapped in Hibernatepublic static void createTable(java.lang.Class... mappings)
mappings - The classes to be mapped in Hibernate
protected static boolean addMappings(java.util.List<java.lang.Class> list,
java.lang.Class... mappings)
list - The list of known classesmappings - The new mappings being added
protected static org.hibernate.SessionFactory createFactory(java.util.Properties props,
java.util.List<java.lang.Class> list)
props - The properties to initialise Hibernatelist - The list of classes to be mapped in Hibernate
protected static void configureFromFile(org.hibernate.cfg.Configuration cfg)
throws java.lang.Exception
cfg - The configuration for initialising Hibernate
java.lang.Exception
protected static org.hibernate.SessionFactory buildFactory(org.hibernate.cfg.Configuration cfg)
throws java.lang.Exception
cfg - The configuration for initialising Hibernate
java.lang.Exception
protected static void testConnection(org.hibernate.SessionFactory factory)
throws java.lang.Exception
factory - The initialised session factory
java.lang.Exceptionprotected static void someDatabaseProcess()
public static void closeFactory(org.hibernate.SessionFactory factory)
factory - The initialise session factorypublic static void closeFactory()
public static java.lang.Exception getLastError()
public static void updateDB(java.lang.Object obj)
obj - The object to save to the databasepublic static void updateDB(java.util.List list)
list - The list of obejcts to save or updatepublic static void saveDB(java.lang.Object obj)
obj - The object to save to the databasepublic static void removeDB(java.lang.Object obj)
obj - The object to delete from the database
public static java.util.List getListData(java.lang.Class classBean,
java.lang.String strKey,
java.lang.Object value)
Hibernate uses transactions and sessions to access the database. Retrieves a list of beans whose field matches the given value.
classBean - The bean classstrKey - The field namevalue - The value of the field
public static java.util.List getListData(java.lang.Class classBean)
Hibernate uses transactions and sessions to access the database. Retrieves all the records from the database in a list.
classBean -
public static java.lang.Object getFirstMatch(java.lang.Class classBean,
java.lang.String strKey,
java.lang.Object value)
classBean - The bean class for the database tablestrKey - The field to searchvalue - The value to match
public static java.lang.Object getFirstMatch(java.lang.Object data,
java.lang.String strKey,
java.lang.Object value)
data - A bean object that matches the bean class for the databasestrKey - The field to searchvalue - The value to match
public static java.lang.Object getKeyData(java.lang.Class beanClass,
long itemId)
beanClass - The class for the databaseitemId - The id for the bean
public static boolean isSessionOpen()
public static boolean testDB(javax.servlet.http.HttpServletResponse response)
throws java.io.IOException,
javax.servlet.ServletException
response - Response information encapsulated in a Java object
java.io.IOException
javax.servlet.ServletException
public static void writeError(javax.servlet.http.HttpServletResponse response,
java.lang.String title,
java.lang.Exception ex)
throws java.io.IOException,
javax.servlet.ServletException
response - Response information encapsulated in a Java objecttitle - Title for the pageex - Exception that caused the error
java.io.IOException
javax.servlet.ServletException
public static void writeError(javax.servlet.http.HttpServletResponse response)
throws java.io.IOException,
javax.servlet.ServletException
response - Response information encapsulated in a Java object
java.io.IOException
javax.servlet.ServletException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||