FileDocCategorySizeDatePackage
Execution.javaAPI DocExample3732Mon Mar 31 23:10:16 BST 2003org.dasein.persist

Execution

public abstract class Execution extends Object

Fields Summary
private static HashMap
cache
public Connection
connection
public HashMap
data
public ResultSet
results
public PreparedStatement
statement
Constructors Summary
Methods Summary
public voidclose()


       
        Stack stack;

        data = null;
        synchronized( cache ) {
            if( !cache.containsKey(this.getClass()) ) {
                stack = new Stack();
                cache.put(this.getClass(), stack);
            }
            else {
                stack = (Stack)cache.get(this.getClass());
            }
        }
        synchronized( stack ) {
            stack.push(this);
        }
    
public java.util.HashMapexecute()

        return execute(true);
    
public java.util.HashMapexecute(boolean cl)

        try {
            InitialContext ctx = new InitialContext();
            DataSource ds = (DataSource)ctx.lookup(getDataSource());
            HashMap res;
            
            connection = ds.getConnection();
            statement = connection.prepareStatement(getStatement());
            res = run();
            if( cl ) {
                close();
            }
            return res;
        }
        catch( NamingException e) {
            throw new PersistenceException(e);
        }
        catch( SQLException e ) {
            throw new PersistenceException(e);
        }
        finally {
            if( results != null ) {
                try { results.close(); }
                catch( SQLException e ) { }
                results = null;
            }
            if( statement != null ) {
                try { statement.close(); }
                catch( SQLException e ) { }
                statement = null;
            }
            if( connection != null ) {
                try { connection.close(); }
                catch( SQLException e ) { }
                connection = null;
            }
            data = null;
        }
    
public java.util.HashMapexecute(java.util.HashMap d)

        data = d;
        return execute(true);
    
public java.util.HashMapexecute(java.util.HashMap d, boolean cl)

        data = d;
        return execute(cl);
    
public abstract java.lang.StringgetDataSource()

public static org.dasein.persist.ExecutiongetInstance(java.lang.Class cls)

    
         
        try {
            Stack stack;
            
            synchronized( cache ) {
                if( !cache.containsKey(cls) ) {
                    return (Execution)cls.newInstance();
                }
                else {
                    stack = (Stack)cache.get(cls);
                }
            }
            synchronized( stack ) {
                if( stack.empty() ) {
                    return (Execution)cls.newInstance();
                }
                else {
                    return (Execution)stack.pop();
                }
            }
        }
        catch( InstantiationException e ) {
            throw new RuntimeException(e.getMessage());
        }
        catch( IllegalAccessException e ) {
            throw new RuntimeException(e.getMessage());
        }
    
public abstract java.lang.StringgetStatement()

public abstract java.util.HashMaprun()

public voidsetData(java.util.HashMap data)

        this.data = data;