Class AbstractTransactionalQuery
- java.lang.Object
-
- com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
FreeformQuery
,TableQuery
public abstract class AbstractTransactionalQuery extends Object implements 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 Connection
getConnection()
Returns the currently active connection, reserves and returns a new connection if no active connection.protected boolean
isInTransaction()
protected void
releaseConnection(Connection conn, Statement statement, 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.
-
-
-
Method Detail
-
beginTransaction
public void beginTransaction() throws UnsupportedOperationException, SQLException
Reserves a connection with auto-commit off if no transaction is in progress.- Throws:
IllegalStateException
- if a transaction is already openSQLException
- if a connection could not be obtained or configuredUnsupportedOperationException
-
commit
public void commit() throws UnsupportedOperationException, SQLException
Commits (if not in auto-commit mode) and releases the active connection.- Throws:
SQLException
- if not in a transaction managed by this queryUnsupportedOperationException
-
rollback
public void rollback() throws UnsupportedOperationException, SQLException
Rolls back and releases the active connection.- Throws:
SQLException
- if not in a transaction managed by this queryUnsupportedOperationException
-
ensureTransaction
protected void ensureTransaction() throws SQLException
Check that a transaction is active.- Throws:
SQLException
- if no active transaction
-
releaseConnection
protected void releaseConnection(Connection conn, Statement statement, ResultSet rs) throws 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 aPreparedStatement
, 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 releasestatement
- the statement to close, may be null to skip closingrs
- the result set to close, may be null to skip closing- Throws:
SQLException
- if closing the result set or the statement fails
-
getConnection
protected Connection getConnection() throws SQLException
Returns the currently active connection, reserves and returns a new connection if no active connection.- Returns:
- previously active or newly reserved connection
- Throws:
SQLException
-
isInTransaction
protected boolean isInTransaction()
-
-