com.vaadin.data.util.sqlcontainer.query
Class AbstractTransactionalQuery

java.lang.Object
  extended by com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
FreeformQuery, TableQuery

public abstract class AbstractTransactionalQuery
extends java.lang.Object
implements java.io.Serializable

Common base class for database query classes that handle connections and transactions.

Since:
6.8.9
Author:
Vaadin Ltd
See Also:
Serialized Form

Method Summary
 void beginTransaction()
          Reserves a connection with auto-commit off if no transaction is in progress.
 void commit()
          Commits (if not in auto-commit mode) and releases the active connection.
protected  void ensureTransaction()
          Check that a transaction is active.
protected  java.sql.Connection getConnection()
          Returns the currently active connection, reserves and returns a new connection if no active connection.
protected  boolean isInTransaction()
           
protected  void releaseConnection(java.sql.Connection conn, java.sql.Statement statement, java.sql.ResultSet rs)
          Closes a statement and a resultset, then releases the connection if it is not part of an active transaction.
 void rollback()
          Rolls back and releases the active connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

beginTransaction

public void beginTransaction()
                      throws java.lang.UnsupportedOperationException,
                             java.sql.SQLException
Reserves a connection with auto-commit off if no transaction is in progress.

Throws:
java.lang.IllegalStateException - if a transaction is already open
java.sql.SQLException - if a connection could not be obtained or configured
java.lang.UnsupportedOperationException

commit

public void commit()
            throws java.lang.UnsupportedOperationException,
                   java.sql.SQLException
Commits (if not in auto-commit mode) and releases the active connection.

Throws:
java.sql.SQLException - if not in a transaction managed by this query
java.lang.UnsupportedOperationException

rollback

public void rollback()
              throws java.lang.UnsupportedOperationException,
                     java.sql.SQLException
Rolls back and releases the active connection.

Throws:
java.sql.SQLException - if not in a transaction managed by this query
java.lang.UnsupportedOperationException

ensureTransaction

protected void ensureTransaction()
                          throws java.sql.SQLException
Check that a transaction is active.

Throws:
java.sql.SQLException - if no active transaction

releaseConnection

protected void releaseConnection(java.sql.Connection conn,
                                 java.sql.Statement statement,
                                 java.sql.ResultSet rs)
                          throws java.sql.SQLException
Closes a statement and a resultset, then releases the connection if it is not part of an active transaction. A failure in closing one of the parameters does not prevent closing the rest. If the statement is a PreparedStatement, its parameters are cleared prior to closing the statement. Although JDBC specification does state that closing a statement closes its result set and closing a connection closes statements and result sets, this method does try to close the result set and statement explicitly whenever not null. This can guard against bugs in certain JDBC drivers and reduce leaks in case e.g. closing the result set succeeds but closing the statement or connection fails.

Parameters:
conn - the connection to release
statement - the statement to close, may be null to skip closing
rs - the result set to close, may be null to skip closing
Throws:
java.sql.SQLException - if closing the result set or the statement fails

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Returns the currently active connection, reserves and returns a new connection if no active connection.

Returns:
previously active or newly reserved connection
Throws:
java.sql.SQLException

isInTransaction

protected boolean isInTransaction()


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.