com.atlassian.confluence.upgrade.upgradetask
Class DataAccessUtils

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

public abstract class DataAccessUtils
extends java.lang.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 java.util.Set<java.lang.String> filterToExistingTables(java.util.Set<java.lang.String> tableNames, org.springframework.transaction.PlatformTransactionManager transactionManager, net.sf.hibernate.SessionFactory sessionFactory)
          Within a new transaction (for DB metadata retrieval), return the supplied Set of tables names filtered such that all the tables that don't exist are removed.
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 java.sql.Connection getConnection(net.sf.hibernate.Session session)
          Returns the JDBC connection for the session.
static net.sf.hibernate.dialect.Dialect getDialect()
           
static net.sf.hibernate.dialect.Dialect getDialect(ConfluenceHibernateConfig hibernateConfig)
           
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 java.lang.String getPrimaryKeyColumnName(org.springframework.transaction.PlatformTransactionManager transactionManager, net.sf.hibernate.SessionFactory sessionFactory, java.lang.String tableName)
           
static net.sf.hibernate.Session getSession(net.sf.hibernate.SessionFactory sessionFactory)
          Returns the current session or creates one if one does not exist.
static boolean isColumnPresent(java.lang.String tableName, java.lang.String columnName, org.springframework.transaction.PlatformTransactionManager transactionManager, net.sf.hibernate.SessionFactory sessionFactory, BootstrapManager bootstrapManager)
           
static boolean isTablePresent(java.lang.String tableName, org.springframework.transaction.PlatformTransactionManager transactionManager, net.sf.hibernate.SessionFactory sessionFactory)
          Within a new transaction (for the database metadata lookup) check if the named table exists in the database.
static
<T> T
withNewConnection(org.springframework.transaction.PlatformTransactionManager transactionManager, net.sf.hibernate.SessionFactory sessionFactory, com.google.common.base.Function<java.sql.Connection,T> callback)
           
 
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 java.sql.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

getDialect

public static net.sf.hibernate.dialect.Dialect getDialect()
                                                   throws org.springframework.dao.DataAccessException
Throws:
org.springframework.dao.DataAccessException

getDialect

public static net.sf.hibernate.dialect.Dialect getDialect(ConfluenceHibernateConfig hibernateConfig)
                                                   throws org.springframework.dao.DataAccessException
Throws:
org.springframework.dao.DataAccessException

filterToExistingTables

public static java.util.Set<java.lang.String> filterToExistingTables(java.util.Set<java.lang.String> tableNames,
                                                                     org.springframework.transaction.PlatformTransactionManager transactionManager,
                                                                     net.sf.hibernate.SessionFactory sessionFactory)
Within a new transaction (for DB metadata retrieval), return the supplied Set of tables names filtered such that all the tables that don't exist are removed.

Parameters:
tableNames -
transactionManager -
Returns:
a Set of table names which are found in the database.

isTablePresent

public static boolean isTablePresent(java.lang.String tableName,
                                     org.springframework.transaction.PlatformTransactionManager transactionManager,
                                     net.sf.hibernate.SessionFactory sessionFactory)
Within a new transaction (for the database metadata lookup) check if the named table exists in the database.

Parameters:
tableName -
transactionManager -
sessionFactory -
Returns:
true if it exists, otherwise false.

getPrimaryKeyColumnName

public static java.lang.String getPrimaryKeyColumnName(org.springframework.transaction.PlatformTransactionManager transactionManager,
                                                       net.sf.hibernate.SessionFactory sessionFactory,
                                                       java.lang.String tableName)

isColumnPresent

public static boolean isColumnPresent(java.lang.String tableName,
                                      java.lang.String columnName,
                                      org.springframework.transaction.PlatformTransactionManager transactionManager,
                                      net.sf.hibernate.SessionFactory sessionFactory,
                                      BootstrapManager bootstrapManager)
                               throws com.atlassian.core.exception.InfrastructureException
Throws:
com.atlassian.core.exception.InfrastructureException

withNewConnection

public static <T> T withNewConnection(org.springframework.transaction.PlatformTransactionManager transactionManager,
                                      net.sf.hibernate.SessionFactory sessionFactory,
                                      com.google.common.base.Function<java.sql.Connection,T> callback)


Copyright © 2003-2014 Atlassian. All Rights Reserved.