|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openxava.hibernate.XHibernate
public class XHibernate
Allows to work easily with hibernate inside OpenXava applications.
You can use this class in any part of your OpenXava application:
calculators, validators, actions, junit tests, etc.
To use hibernate with this class you can write something as:
Invoice invoice = new Invoice(); XHibernate.getSession().save(invoice);And no more.
Invoice invoice = new Invoice(); XHibernate.getSession().save(invoice); XHibernate.commit(); // In this way you commit and close manually. ... XHibernate.getSession().save(customer); // As session has been closed, a new one is createdPer thread configuration
XHibernate.setConfigurationFile("/hibernate1.cfg.xml");
XHibernate.getSession().save(invoice); // Using hibernate1
...
XHibernate.commit();
XHibernate.setConfigurationFile("/hibernate2.cfg.xml");
XHibernate.getSession().save(invoice); // Using hibernate2
...
XHibernate.commit();
And this change only affect to the current execution thread.
XHibernate.setDefaultSchema("COMPANY1");
XHibernate.getSession().save(invoice); // Save in INVOICE table of COMPANY1 Schema
...
XHibernate.commit();
XHibernate.setDefaultSchema("COMPANY2");
XHibernate.getSession().save(invoice); // Save in INVOICE table of COMPANY2 Schema
...
XHibernate.commit();
Also this only affect to the current thread.setSessionFactoryProperties(java.util.Properties) can be use in the same way
that setConfigurationFile(java.lang.String) and setDefaultSchema(java.lang.String).
| Constructor Summary | |
|---|---|
XHibernate()
|
|
| Method Summary | |
|---|---|
static void |
commit()
Commits changes and closes the session associated to current thread. |
static org.hibernate.Session |
createSession()
Create a new session. |
static java.lang.String |
getConfigurationFile()
By default is /hibernate.cfg.xml. |
static java.lang.String |
getDefaultSchema()
The default schema used by Hibernate in the current thread. |
static org.hibernate.Session |
getSession()
Session associated to current thread. |
static java.util.Properties |
getSessionFactoryProperties()
The properties sent to Hibernate to in order to create the SessionFactory. |
static boolean |
isCmt()
Indicate that the current thread is executing inside a CMT context. |
static void |
reset()
Reset the info associated to the current thread. |
static void |
rollback()
Rollback changes and closes the session associated to current thread. |
static void |
setCmt(boolean cmt)
Indicate that the current thread is executing inside a CMT context. |
static void |
setConfigurationFile(java.lang.String configurationFile)
By default is /hibernate.cfg.xml. |
static void |
setDefaultSchema(java.lang.String defaultSchema)
Change the default schema used by Hibernate in the current thread. |
static void |
setSessionFactoryProperties(java.util.Properties sessionFactoryProperties)
Set the properties to send to Hibernate in order to create the SessionFactory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XHibernate()
| Method Detail |
|---|
public static org.hibernate.Session getSession()
If no session exists or it's closed, then create a new one, and start a transaction.
public static org.hibernate.Session createSession()
This session is not associated with the current thread, and no transaction is started.
public static void commit()
If no session or the it is closed this method does nothing.
In most cases this method is called by OpenXava automatically,
hence the programmer that uses hibernate APIs does not need to call it.
public static void rollback()
If no session or the it is closed this method does nothing.
public static java.lang.String getConfigurationFile()
/hibernate.cfg.xml.
You must set value to this property before use any other method of this class.
The value of this properties may be different for each thread.
public static void setConfigurationFile(java.lang.String configurationFile)
/hibernate.cfg.xml. You must set value to this property before use any other method of this class. If you change this value it only take effect for the current thread.
If you sent a
null then /hibernate.cfg.xml is assumed.
public static void setCmt(boolean cmt)
CMT is Container Managed Transaction. The usual inside EJB.
public static boolean isCmt()
CMT is Container Managed Transaction. The usual inside EJB.
public static java.util.Properties getSessionFactoryProperties()
The value can be different for each execution thread.
public static void setSessionFactoryProperties(java.util.Properties sessionFactoryProperties)
This only apply to the current execution thread.
public static java.lang.String getDefaultSchema()
For example, if you use 'COMPANYA' as default schema, and you OX component
is mapping to a table named 'ISSUE' when OX and JPA engine
try to execute SQL they will use 'COMPANYA.ISSUE' as table name.
public static void setDefaultSchema(java.lang.String defaultSchema)
For example, if you use 'COMPANYA' as default schema, and you OX component
or EJB3 entity is mapping to a table named 'ISSUE' when OX and JPA engine
try to execute SQL they will use 'COMPANYA.ISSUE' as table name.
public static void reset()
After call this method XPersistence works as default,
all previous call to #setPersistenceUnit,
#setPersistenceUnitProperties or setDefaultSchema(java.lang.String)
are annulled.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||