com.atlassian.confluence.upgrade.upgradetask
Class DataAccessUtils

java.lang.Object
  extended by com.atlassian.confluence.upgrade.upgradetask.DataAccessUtils

public abstract class DataAccessUtils
extends Object

Provides access to several underlying Hibernate and JDBC data access objects, which are commonly used in database-related upgrade tasks.

Since:
3.5

Method Summary
static void flush(net.sf.hibernate.Session session)
          Flushes the session.
static void flushAndClear(net.sf.hibernate.Session session)
          Flushes and clears the session.
static Connection getConnection(net.sf.hibernate.Session session)
          Returns the JDBC connection for the session.
static org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate(net.sf.hibernate.Session session)
          Returns a JDBC template for the provided Hibernate session.
static org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate(net.sf.hibernate.SessionFactory sessionFactory)
          Returns a JDBC template for the active Hibernate session.
static net.sf.hibernate.Session getSession(net.sf.hibernate.SessionFactory sessionFactory)
          Returns the current session or creates one if one does not exist.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSession

public static net.sf.hibernate.Session getSession(net.sf.hibernate.SessionFactory sessionFactory)
Returns the current session or creates one if one does not exist.

See Also:
SessionFactoryUtils.getSession(net.sf.hibernate.SessionFactory, boolean)

flush

public static void flush(net.sf.hibernate.Session session)
                  throws org.springframework.dao.DataAccessException
Flushes the session. That is, checks for any updates on attached Hibernate objects and issues the required SQL to the database server. All the objects attached to the session remain attached and in memory.

This does not commit anything by itself, but relies on the surrounding transaction to commit the changes.

Throws:
org.springframework.dao.DataAccessException - if the connection cannot be retrieved

flushAndClear

public static void flushAndClear(net.sf.hibernate.Session session)
                          throws org.springframework.dao.DataAccessException
Flushes and clears the session. That is, checks for any updates on attached Hibernate objects and issues the required SQL to the database server, then clears all the objects from the Hibernate session.

This does not commit anything by itself, but relies on the surrounding transaction to commit or roll back the changes.

Use this method if you are processing a large number of Hibernate objects and want to make sure that ones which are already processed are not kept in memory.

Throws:
org.springframework.dao.DataAccessException - if the connection cannot be retrieved

getJdbcTemplate

public static org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate(net.sf.hibernate.Session session)
Returns a JDBC template for the provided Hibernate session. The JDBC template participates in the same transaction as the session.


getJdbcTemplate

public static org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate(net.sf.hibernate.SessionFactory sessionFactory)
Returns a JDBC template for the active Hibernate session. Creates a new session if one does not exist.

See Also:
getSession(SessionFactory), getJdbcTemplate(Session)

getConnection

public static Connection getConnection(net.sf.hibernate.Session session)
                                throws org.springframework.dao.DataAccessException
Returns the JDBC connection for the session. Statements created and executed on this connection will typically share the same transaction as the session.

Throws:
org.springframework.dao.DataAccessException - if the connection cannot be retrieved


Copyright © 2003-2012 Atlassian. All Rights Reserved.