FileDocCategorySizeDatePackage
JDBCTransactionImpl.javaAPI DocExample3509Thu Aug 24 21:10:22 BST 2000com.imaginary.lwp.jdbc

JDBCTransactionImpl

public class JDBCTransactionImpl extends com.imaginary.lwp.Transaction implements JDBCTransaction
Implements the Transaction interface for support of JDBC transactions.
Last modified $Date: 1999/11/07 19:32:31 $
version
$Revision: 1.1 $
author
George Reese (borg@imaginary.com)

Fields Summary
private Connection
connection
Constructors Summary
public JDBCTransactionImpl()
Constructs a new transaction.


             
      
        super();
    
Methods Summary
public voidcommit()
Sends a commit to the connection currently in use.

throws
com.imaginary.lwp.TransactionException the commit failed

        try {
            if( connection == null ) {
                return;
            }
            if(  connection.isClosed() ) {
                throw new TransactionException("Invalid transactional state.");
            }
            connection.commit();
            connection.close();
            connection = null;
        }
        catch( SQLException e ) {
            throw new TransactionException("Database error: " +
                                           e.getMessage());
        }
    
public java.sql.ConnectiongetConnection()
Provides a JDBC Connection object to the persistence handler implementing a persistence for a business object. This method finds the connection by loading a DataSource from a JNDI directory and asking the data source for the connection. The data source name should be provided in the imaginary.lwp.dataSouceName system property.

return
the JDBC Connection
throws
java.sql.SQLException an error occurred creating the connection from the data source

        if( connection == null ) {
            connection = getJDBCConnection();
            try {
                connection.setAutoCommit(false);
            }
            catch( SQLException e ) {
            }
        }
        return connection;
    
public static java.sql.ConnectiongetJDBCConnection()

        String url = System.getProperty("imaginary.lwp.jdbcURL");
        String uid = System.getProperty("imaginary.lwp.user");
        String pw = System.getProperty("imaginary.lwp.password");
        Properties p = new Properties();
        
        if( uid != null ) {
            p.put("user", uid);
        }
        if( pw != null ) {
            p.put("password", pw);
        }
        return DriverManager.getConnection(url, p);
    
public voidrollback()
Tells the current connection to rollback.

        try {
            if( connection == null ) {
                return;
            }
            if(  connection.isClosed() ) {
                throw new NullPointerException();
            }
            connection.rollback();
            connection.close();
            connection = null;
        }
        catch( SQLException e ) {
           e.printStackTrace();
        }