com.xpn.xwiki.store
Class XWikiHibernateBaseStore

java.lang.Object
  extended by com.xpn.xwiki.store.XWikiHibernateBaseStore
Direct Known Subclasses:
XWikiHibernateAttachmentStore, XWikiHibernateStore

public class XWikiHibernateBaseStore
extends java.lang.Object

Created by IntelliJ IDEA. User: ludovic Date: 10 mars 2006 Time: 14:04:13 To change this template use File | Settings | File Templates.


Nested Class Summary
 class XWikiHibernateBaseStore.ConnectionMonitor
           
 
Field Summary
private  org.hibernate.cfg.Configuration configuration
           
private  java.util.Map connections
           
private  java.lang.String hibpath
           
private  java.net.URL hiburl
           
private static org.apache.commons.logging.Log log
           
private  int nbConnections
           
private  org.hibernate.SessionFactory sessionFactory
           
 
Constructor Summary
XWikiHibernateBaseStore(java.lang.String hibpath)
          Initialize the storage engine with a specific path This is used for tests.
XWikiHibernateBaseStore(XWiki xwiki, XWikiContext context)
          THis allows to initialize our storage engine.
 
Method Summary
private  void addConnection(java.sql.Connection connection, XWikiContext context)
          Adding a connection to the Monitor module
 boolean beginTransaction(boolean withTransaction, XWikiContext context)
          Begins a transaction
 boolean beginTransaction(org.hibernate.SessionFactory sfactory, boolean withTransaction, XWikiContext context)
          Begins a transaction with a specific SessionFactory
 boolean beginTransaction(org.hibernate.SessionFactory sfactory, XWikiContext context)
          Begins a transaction with a specific SessionFactory
 boolean beginTransaction(XWikiContext context)
          Begins a transaction
 void checkHibernate(XWikiContext context)
          Initializes hibernate and calls updateSchema if necessary
 void cleanUp(XWikiContext context)
          Cleanup all sessions Used at the shutdown time
private  void closeSession(org.hibernate.Session session)
          Closes the hibernate session
 void endTransaction(XWikiContext context, boolean commit)
          Ends a transaction
 void endTransaction(XWikiContext context, boolean commit, boolean withTransaction)
          Ends a transaction
 org.hibernate.cfg.Configuration getConfiguration()
           
 java.util.Collection getConnections()
           
 java.net.URL getHibUrl()
          Get's the hibernate config path as an URL
 int getNbConnections()
           
 java.lang.String getPath()
          Allows to get the current hibernate config file path
 java.lang.String[] getSchemaUpdateScript(org.hibernate.cfg.Configuration config, XWikiContext context)
          This function gets the schema update scripts generated by comparing the current database woth the current hibernate mapping config.
 org.hibernate.Session getSession(XWikiContext context)
          This get's the current session.
 org.hibernate.SessionFactory getSessionFactory()
           
 org.hibernate.Transaction getTransaction(XWikiContext context)
          Allows to get the current transaction from the context This is set in beginTransaction
private  void initHibernate()
          Allows to init the hibernate configuration
protected  boolean isVirtual(XWikiContext context)
          Checks if this xwiki setup is virtual meaning if multiple wikis can be accessed using the same database pool
protected  org.hibernate.cfg.Configuration makeMapping(java.lang.String className, java.lang.String custommapping1)
           
protected  java.lang.String makeMapping(java.lang.String entityName, java.lang.String tableName, java.lang.String custommapping1)
           
private  void removeConnection(java.sql.Connection connection)
          Remove a connection to the Monitor module
 void setConfiguration(org.hibernate.cfg.Configuration configuration)
           
 void setDatabase(org.hibernate.Session session, XWikiContext context)
          Virtual Wikis Allows to switch database connection
 void setHibUrl(java.net.URL hiburl)
          Set the hibernate config path as an URL
 void setNbConnections(int nbConnections)
           
 void setPath(java.lang.String hibpath)
          Allows to set the current hibernate config file path
 void setSession(org.hibernate.Session session, XWikiContext context)
          Allows to set the current session in the context This is set in beginTransaction
 void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
           
 void setTransaction(org.hibernate.Transaction transaction, XWikiContext context)
          Allows to set the current transaction This is set in beginTransaction
 void shutdownHibernate(XWikiContext context)
          Allows to shut down the hibernate configuration Closing all pools and connections
 void updateSchema(BaseClass bclass, XWikiContext context)
          Custom Mapping This function update the schema based on the dynamic custom mapping provided by the class
 void updateSchema(java.lang.String[] createSQL, XWikiContext context)
          Runs the update script on the current database
 void updateSchema(XWikiContext context)
          Allows to update the schema to match the hibernate mapping
 void updateSchema(XWikiContext context, boolean force)
          Allows to update the schema to match the hibernate mapping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

connections

private java.util.Map connections

nbConnections

private int nbConnections

sessionFactory

private org.hibernate.SessionFactory sessionFactory

configuration

private org.hibernate.cfg.Configuration configuration

hibpath

private java.lang.String hibpath

hiburl

private java.net.URL hiburl
Constructor Detail

XWikiHibernateBaseStore

public XWikiHibernateBaseStore(XWiki xwiki,
                               XWikiContext context)
THis allows to initialize our storage engine. The hibernate config file path is taken from xwiki.cfg or directly in the WEB-INF directory.

Parameters:
xwiki -
context -

XWikiHibernateBaseStore

public XWikiHibernateBaseStore(java.lang.String hibpath)
Initialize the storage engine with a specific path This is used for tests.

Parameters:
hibpath -
Method Detail

getPath

public java.lang.String getPath()
Allows to get the current hibernate config file path

Returns:

setPath

public void setPath(java.lang.String hibpath)
Allows to set the current hibernate config file path

Parameters:
hibpath -

getHibUrl

public java.net.URL getHibUrl()
Get's the hibernate config path as an URL

Returns:

setHibUrl

public void setHibUrl(java.net.URL hiburl)
Set the hibernate config path as an URL

Parameters:
hiburl -

initHibernate

private void initHibernate()
                    throws org.hibernate.HibernateException
Allows to init the hibernate configuration

Throws:
org.hibernate.HibernateException

getSession

public org.hibernate.Session getSession(XWikiContext context)
This get's the current session. This is set in beginTransaction

Parameters:
context -
Returns:

setSession

public void setSession(org.hibernate.Session session,
                       XWikiContext context)
Allows to set the current session in the context This is set in beginTransaction

Parameters:
session -
context -

getTransaction

public org.hibernate.Transaction getTransaction(XWikiContext context)
Allows to get the current transaction from the context This is set in beginTransaction

Parameters:
context -
Returns:

setTransaction

public void setTransaction(org.hibernate.Transaction transaction,
                           XWikiContext context)
Allows to set the current transaction This is set in beginTransaction

Parameters:
transaction -
context -

shutdownHibernate

public void shutdownHibernate(XWikiContext context)
                       throws org.hibernate.HibernateException
Allows to shut down the hibernate configuration Closing all pools and connections

Parameters:
context -
Throws:
org.hibernate.HibernateException

updateSchema

public void updateSchema(XWikiContext context)
                  throws org.hibernate.HibernateException
Allows to update the schema to match the hibernate mapping

Parameters:
context -
Throws:
org.hibernate.HibernateException

updateSchema

public void updateSchema(XWikiContext context,
                         boolean force)
                  throws org.hibernate.HibernateException
Allows to update the schema to match the hibernate mapping

Parameters:
context -
force - defines wether or not to force the update despite the xwiki.cfg settings
Throws:
org.hibernate.HibernateException

getSchemaUpdateScript

public java.lang.String[] getSchemaUpdateScript(org.hibernate.cfg.Configuration config,
                                                XWikiContext context)
                                         throws org.hibernate.HibernateException
This function gets the schema update scripts generated by comparing the current database woth the current hibernate mapping config.

Parameters:
config -
context -
Returns:
Throws:
org.hibernate.HibernateException

updateSchema

public void updateSchema(java.lang.String[] createSQL,
                         XWikiContext context)
Runs the update script on the current database

Parameters:
createSQL -
context -

updateSchema

public void updateSchema(BaseClass bclass,
                         XWikiContext context)
                  throws XWikiException
Custom Mapping This function update the schema based on the dynamic custom mapping provided by the class

Parameters:
bclass -
context -
Throws:
XWikiException

checkHibernate

public void checkHibernate(XWikiContext context)
                    throws org.hibernate.HibernateException
Initializes hibernate and calls updateSchema if necessary

Parameters:
context -
Throws:
org.hibernate.HibernateException

isVirtual

protected boolean isVirtual(XWikiContext context)
Checks if this xwiki setup is virtual meaning if multiple wikis can be accessed using the same database pool

Parameters:
context -
Returns:

setDatabase

public void setDatabase(org.hibernate.Session session,
                        XWikiContext context)
                 throws XWikiException
Virtual Wikis Allows to switch database connection

Parameters:
session -
context -
Throws:
XWikiException

beginTransaction

public boolean beginTransaction(XWikiContext context)
                         throws XWikiException
Begins a transaction

Parameters:
context -
Returns:
Throws:
XWikiException

beginTransaction

public boolean beginTransaction(boolean withTransaction,
                                XWikiContext context)
                         throws XWikiException
Begins a transaction

Parameters:
withTransaction -
context -
Returns:
Throws:
XWikiException

beginTransaction

public boolean beginTransaction(org.hibernate.SessionFactory sfactory,
                                XWikiContext context)
                         throws XWikiException
Begins a transaction with a specific SessionFactory

Parameters:
sfactory -
context -
Returns:
Throws:
XWikiException

beginTransaction

public boolean beginTransaction(org.hibernate.SessionFactory sfactory,
                                boolean withTransaction,
                                XWikiContext context)
                         throws org.hibernate.HibernateException,
                                XWikiException
Begins a transaction with a specific SessionFactory

Parameters:
sfactory -
withTransaction -
context -
Returns:
Throws:
org.hibernate.HibernateException
XWikiException

addConnection

private void addConnection(java.sql.Connection connection,
                           XWikiContext context)
Adding a connection to the Monitor module

Parameters:
connection -
context -

removeConnection

private void removeConnection(java.sql.Connection connection)
Remove a connection to the Monitor module

Parameters:
connection -

endTransaction

public void endTransaction(XWikiContext context,
                           boolean commit)
Ends a transaction

Parameters:
context -
commit - should we commit or not

endTransaction

public void endTransaction(XWikiContext context,
                           boolean commit,
                           boolean withTransaction)
                    throws org.hibernate.HibernateException
Ends a transaction

Parameters:
context -
commit - should we commit or not
withTransaction -
Throws:
org.hibernate.HibernateException

closeSession

private void closeSession(org.hibernate.Session session)
                   throws org.hibernate.HibernateException
Closes the hibernate session

Parameters:
session -
Throws:
org.hibernate.HibernateException

cleanUp

public void cleanUp(XWikiContext context)
Cleanup all sessions Used at the shutdown time

Parameters:
context -

getSessionFactory

public org.hibernate.SessionFactory getSessionFactory()

setSessionFactory

public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)

getConfiguration

public org.hibernate.cfg.Configuration getConfiguration()

setConfiguration

public void setConfiguration(org.hibernate.cfg.Configuration configuration)

getConnections

public java.util.Collection getConnections()

getNbConnections

public int getNbConnections()

setNbConnections

public void setNbConnections(int nbConnections)

makeMapping

protected org.hibernate.cfg.Configuration makeMapping(java.lang.String className,
                                                      java.lang.String custommapping1)

makeMapping

protected java.lang.String makeMapping(java.lang.String entityName,
                                       java.lang.String tableName,
                                       java.lang.String custommapping1)


Copyright 2003 Ludovic Dubost