com.jaeksoft.pojodbc
Class Transaction

java.lang.Object
  extended by com.jaeksoft.pojodbc.Transaction

public class Transaction
extends java.lang.Object

Represents a new database transaction. Currently, a transaction represents a database connection. Further implementation could share same connection.

Transaction automatically closed every Query used.

That source code is our recommended way to use it. You have close the transaction in a finally statement to be sure that the database connection will be released.

 Transaction transaction = null;
 try {
        transaction = connectionManager.getNewTransaction(false,
                        javax.sql.Connection.TRANSACTION_READ_COMMITTED);
        // ... do everything you need ...
 } finally {
        if (transaction != null)
                transaction.close();
 }
 
 

Author:
ekeller

Constructor Summary
Transaction(java.sql.Connection cnx, boolean autoCommit, int transactionIsolation)
           
 
Method Summary
 void close()
          Close all queries and the transaction.
 void commit()
          Usual JDBC/SQL transaction commit
 Query prepare(java.lang.String sql)
          Create a new Query
 Query prepare(java.lang.String sql, int resultSetType, int resultSetConcurency)
          Create a new Query with standard JDBC properties.
 Query prepareWithKeys(java.lang.String sql)
          Create a new Query with autogeneratedkey flag
 void rollback()
          Usual JDBC/SQL transaction rollback
 int update(java.lang.String sql)
          A convenient way to directly execute an INSERT/UPDATE/DELETE SQL statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Transaction

public Transaction(java.sql.Connection cnx,
                   boolean autoCommit,
                   int transactionIsolation)
            throws java.sql.SQLException
Throws:
java.sql.SQLException
Method Detail

close

public void close()
Close all queries and the transaction. No commit or rollback are performed.


rollback

public void rollback()
              throws java.sql.SQLException
Usual JDBC/SQL transaction rollback

Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Usual JDBC/SQL transaction commit

Throws:
java.sql.SQLException

prepare

public Query prepare(java.lang.String sql)
              throws java.sql.SQLException
Create a new Query

Parameters:
sql - The native SQL query
Returns:
a new Query instance
Throws:
java.sql.SQLException

prepareWithKeys

public Query prepareWithKeys(java.lang.String sql)
                      throws java.sql.SQLException
Create a new Query with autogeneratedkey flag

Parameters:
sql - The native SQL query
Returns:
a new Query instance
Throws:
java.sql.SQLException

prepare

public Query prepare(java.lang.String sql,
                     int resultSetType,
                     int resultSetConcurency)
              throws java.sql.SQLException
Create a new Query with standard JDBC properties.

ResultSetType and ResultSetConcureny are JDBC standard parameters like ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE, ...

Parameters:
sql - The native SQL query
resultSetType - A standard JDBC ResultSet type
resultSetConcurency - A standard JDBC Result concurency property
Returns:
a new Query instance
Throws:
java.sql.SQLException

update

public int update(java.lang.String sql)
           throws java.sql.SQLException
A convenient way to directly execute an INSERT/UPDATE/DELETE SQL statement.

Parameters:
sql - The native SQL query
Returns:
the row count
Throws:
java.sql.SQLException