gdamour     2005/03/02 06:43:16

  Modified:    modules/itests/src/itest/org/openejb/test
                        AxionTestDatabase.java DerbyTestDatabase.java
                        InstantDbTestDatabase.java
                        PostgreSqlTestDatabase.java TestDatabase.java
  Added:       modules/itests/src/itest/org/openejb/test
                        AbstractTestDatabase.java
  Log:

  GERONIMO-580
  
  o add an itests test verifying the correct behavior of the implementation.
  
  GERONIMO-598
  
  o add the flush-cache-before-query optional element, which identifies if
  the transactional cache should be flushed before the execution of the
  associated finder or select operation; and
  o update the various XValuedFinder and XValuedSelect in order to flush
  the transaction cache if required.
  
  Revision  Changes    Path
  1.7       +23 -85    
openejb/modules/itests/src/itest/org/openejb/test/AxionTestDatabase.java
  
  Index: AxionTestDatabase.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/itests/src/itest/org/openejb/test/AxionTestDatabase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AxionTestDatabase.java    15 Oct 2004 06:02:48 -0000      1.6
  +++ AxionTestDatabase.java    2 Mar 2005 11:43:16 -0000       1.7
  @@ -1,16 +1,13 @@
   package org.openejb.test;
   
  -import java.rmi.RemoteException;
  -import java.util.Properties;
   import javax.naming.InitialContext;
   
   import org.openejb.test.beans.Database;
  -import org.openejb.test.beans.DatabaseHome;
   
   /**
    *
    */
  -public class AxionTestDatabase implements TestDatabase {
  +public class AxionTestDatabase extends AbstractTestDatabase {
   
       protected Database database;
       protected InitialContext initialContext;
  @@ -21,6 +18,9 @@
       private static final String CREATE_ENTITY = "CREATE TABLE entity ( id 
integer default entity_seq.nextval, first_name string, last_name string )";
       private static final String DROP_ENTITY = "DROP TABLE entity";
   
  +    private static final String CREATE_ENTITY_EXPLICIT_PK = "CREATE TABLE 
entity_explicit_pk ( id integer, first_name string, last_name string )";
  +    private static final String DROP_ENTITY_EXPLICIT_PK = "DROP TABLE 
entity_explicit_pk";
  +
       private static final String CREATE_ENTITY_SEQ = "CREATE SEQUENCE 
entity_seq";
       private static final String DROP_ENTITY_SEQ = "DROP SEQUENCE entity_seq";
   
  @@ -28,101 +28,39 @@
           System.setProperty("noBanner", "true");
       }
   
  -
       public void createEntityTable() throws java.sql.SQLException {
  -        executeStatementIgnoreErrors(DROP_ENTITY);
           executeStatementIgnoreErrors(DROP_ENTITY_SEQ);
  +        super.createEntityTable();
           executeStatement(CREATE_ENTITY_SEQ);
  -        executeStatement(CREATE_ENTITY);
       }
   
       public void dropEntityTable() throws java.sql.SQLException {
  -        executeStatement(DROP_ENTITY);
  +        super.dropEntityTable();
           executeStatement(DROP_ENTITY_SEQ);
       }
   
  +    protected String getCreateAccount() {
  +        return CREATE_ACCOUNT;
  +    }
  +
  +    protected String getDropAccount() {
  +        return DROP_ACCOUNT;
  +    }
  +
  +    protected String getCreateEntity() {
  +        return CREATE_ENTITY;
  +    }
   
  -    private void executeStatementIgnoreErrors(String command) {
  -        try {
  -            getDatabase().execute(command);
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -    }
  -
  -    private void executeStatement(String command) throws 
java.sql.SQLException {
  -        try {
  -            getDatabase().execute(command);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Cannot exectute statement: 
" + re.getMessage(), command);
  -            }
  -        }
  -    }
  -
  -    public void createAccountTable() throws java.sql.SQLException {
  -        executeStatementIgnoreErrors(DROP_ACCOUNT);
  -        executeStatement(CREATE_ACCOUNT);
  -    }
  -
  -    public void dropAccountTable() throws java.sql.SQLException {
  -        executeStatement(DROP_ACCOUNT);
  -    }
  -
  -    public void start() throws IllegalStateException {
  -        try {
  -            // @todo this is a hack that limits us to a single server 
  -//            Properties properties = 
TestManager.getServer().getContextEnvironment();
  -            Properties properties = new Properties();
  -            properties.put("test.server.class", 
"org.openejb.test.RemoteTestServer");
  -            properties.put("java.naming.factory.initial", 
"org.openejb.client.RemoteInitialContextFactory");
  -            properties.put("java.naming.provider.url", "127.0.0.1:4201");
  -            properties.put("java.naming.security.principal", "testuser");
  -            properties.put("java.naming.security.credentials", 
"testpassword");
  -            initialContext = new InitialContext(properties);
  -        } catch (Exception e) {
  -            throw new IllegalStateException("Cannot create initial context: 
" + e.getClass().getName() + " " + e.getMessage());
  -        }
  -    }
  -
  -
  -    private Database getDatabase() {
  -        if (initialContext == null) {
  -            start();
  -        }
  -        if (database == null) {
  -            database = createDatabaseObject();
  -        }
  -        return database;
  -    }
  -
  -    private Database createDatabaseObject() {
  -        Object obj = null;
  -        DatabaseHome databaseHome = null;
  -        Database database = null;
  -        try {
  -            /* Create database */
  -            obj = initialContext.lookup("client/tools/DatabaseHome");
  -            databaseHome = (DatabaseHome) 
javax.rmi.PortableRemoteObject.narrow(obj, DatabaseHome.class);
  -        } catch (Exception e) {
  -            throw (IllegalStateException)new IllegalStateException("Cannot 
find 'client/tools/DatabaseHome': "
  -                    + e.getMessage()).initCause(e);
  -        }
  -        try {
  -            database = databaseHome.create();
  -        } catch (Exception e) {
  -            throw (IllegalStateException)new IllegalStateException("Cannot 
start database: "
  -                    + e.getMessage()).initCause(e);
  -        }
  -        return database;
  +    protected String getDropEntity() {
  +        return DROP_ENTITY;
       }
   
  -    public void stop() throws IllegalStateException {
  +    protected String getCreateEntityExplictitPK() {
  +        return CREATE_ENTITY_EXPLICIT_PK;
       }
   
  -    public void init(Properties props) throws IllegalStateException {
  +    protected String getDropEntityExplicitPK() {
  +        return DROP_ENTITY_EXPLICIT_PK;
       }
   }
   
  
  
  
  1.2       +21 -101   
openejb/modules/itests/src/itest/org/openejb/test/DerbyTestDatabase.java
  
  Index: DerbyTestDatabase.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/itests/src/itest/org/openejb/test/DerbyTestDatabase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DerbyTestDatabase.java    19 Oct 2004 20:44:15 -0000      1.1
  +++ DerbyTestDatabase.java    2 Mar 2005 11:43:16 -0000       1.2
  @@ -1,125 +1,45 @@
   package org.openejb.test;
   
  -import java.rmi.RemoteException;
  -import java.util.Properties;
  -import java.sql.SQLException;
  -import javax.naming.InitialContext;
  -
  -import org.openejb.test.beans.Database;
  -import org.openejb.test.beans.DatabaseHome;
   
   /**
    *
    */
  -public class DerbyTestDatabase implements TestDatabase {
  -
  -    protected Database database;
  -    protected InitialContext initialContext;
  -
  +public class DerbyTestDatabase extends AbstractTestDatabase {
       private static final String CREATE_ACCOUNT = "CREATE TABLE account ( ssn 
VARCHAR(25), first_name VARCHAR(256), last_name VARCHAR(256), balance integer)";
       private static final String DROP_ACCOUNT = "DROP TABLE account";
   
       private static final String CREATE_ENTITY = "CREATE TABLE entity ( id 
integer GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), first_name 
VARCHAR(256), last_name VARCHAR(256) )";
       private static final String DROP_ENTITY = "DROP TABLE entity";
   
  +    private static final String CREATE_ENTITY_EXPLICIT_PK = "CREATE TABLE 
entity_explicit_pk ( id integer, first_name VARCHAR(256), last_name 
VARCHAR(256) )";
  +    private static final String DROP_ENTITY_EXPLICIT_PK = "DROP TABLE 
entity_explicit_pk";
  +    
       static {
           System.setProperty("noBanner", "true");
       }
   
  +    protected String getCreateAccount() {
  +        return CREATE_ACCOUNT;
  +    }
  +
  +    protected String getDropAccount() {
  +        return DROP_ACCOUNT;
  +    }
  +
  +    protected String getCreateEntity() {
  +        return CREATE_ENTITY;
  +    }
   
  -    public void createEntityTable() throws java.sql.SQLException {
  -        executeStatementIgnoreErrors(DROP_ENTITY);
  -        executeStatement(CREATE_ENTITY);
  -    }
  -
  -    public void dropEntityTable() throws java.sql.SQLException {
  -        executeStatement(DROP_ENTITY);
  -    }
  -
  -
  -    private void executeStatementIgnoreErrors(String command) {
  -        try {
  -            getDatabase().execute(command);
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -    }
  -
  -    private void executeStatement(String command) throws 
java.sql.SQLException {
  -        try {
  -            getDatabase().execute(command);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (SQLException)new SQLException("could not execute 
command: " + command).initCause(re.detail);
  -            } else {
  -                throw new SQLException("Cannot execute statement: " + 
re.getMessage(), command);
  -            }
  -        } catch (Throwable t) {
  -            throw (SQLException)new SQLException("could not execute command: 
" + command).initCause(t);
  -        }
  -    }
  -
  -    public void createAccountTable() throws java.sql.SQLException {
  -        executeStatementIgnoreErrors(DROP_ACCOUNT);
  -        executeStatement(CREATE_ACCOUNT);
  -    }
  -
  -    public void dropAccountTable() throws java.sql.SQLException {
  -        executeStatement(DROP_ACCOUNT);
  -    }
  -
  -    public void start() throws IllegalStateException {
  -        try {
  -            // @todo this is a hack that limits us to a single server 
  -//            Properties properties = 
TestManager.getServer().getContextEnvironment();
  -            Properties properties = new Properties();
  -            properties.put("test.server.class", 
"org.openejb.test.RemoteTestServer");
  -            properties.put("java.naming.factory.initial", 
"org.openejb.client.RemoteInitialContextFactory");
  -            properties.put("java.naming.provider.url", "127.0.0.1:4201");
  -            properties.put("java.naming.security.principal", "testuser");
  -            properties.put("java.naming.security.credentials", 
"testpassword");
  -            initialContext = new InitialContext(properties);
  -        } catch (Exception e) {
  -            throw new IllegalStateException("Cannot create initial context: 
" + e.getClass().getName() + " " + e.getMessage());
  -        }
  -    }
  -
  -
  -    private Database getDatabase() {
  -        if (initialContext == null) {
  -            start();
  -        }
  -        if (database == null) {
  -            database = createDatabaseObject();
  -        }
  -        return database;
  -    }
  -
  -    private Database createDatabaseObject() {
  -        Object obj = null;
  -        DatabaseHome databaseHome = null;
  -        Database database = null;
  -        try {
  -            /* Create database */
  -            obj = initialContext.lookup("client/tools/DatabaseHome");
  -            databaseHome = (DatabaseHome) 
javax.rmi.PortableRemoteObject.narrow(obj, DatabaseHome.class);
  -        } catch (Exception e) {
  -            throw (IllegalStateException)new IllegalStateException("Cannot 
find 'client/tools/DatabaseHome': "
  -                    + e.getMessage()).initCause(e);
  -        }
  -        try {
  -            database = databaseHome.create();
  -        } catch (Exception e) {
  -            throw (IllegalStateException)new IllegalStateException("Cannot 
start database: "
  -                    + e.getMessage()).initCause(e);
  -        }
  -        return database;
  +    protected String getDropEntity() {
  +        return DROP_ENTITY;
       }
   
  -    public void stop() throws IllegalStateException {
  +    protected String getCreateEntityExplictitPK() {
  +        return CREATE_ENTITY_EXPLICIT_PK;
       }
   
  -    public void init(Properties props) throws IllegalStateException {
  +    protected String getDropEntityExplicitPK() {
  +        return DROP_ENTITY_EXPLICIT_PK;
       }
   }
   
  
  
  
  1.2       +26 -109   
openejb/modules/itests/src/itest/org/openejb/test/InstantDbTestDatabase.java
  
  Index: InstantDbTestDatabase.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/itests/src/itest/org/openejb/test/InstantDbTestDatabase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InstantDbTestDatabase.java        8 Sep 2004 07:20:16 -0000       1.1
  +++ InstantDbTestDatabase.java        2 Mar 2005 11:43:16 -0000       1.2
  @@ -1,139 +1,56 @@
   package org.openejb.test;
   
  -import java.rmi.RemoteException;
  -import java.util.Properties;
   import javax.naming.InitialContext;
   
   import org.openejb.test.beans.Database;
  -import org.openejb.test.beans.DatabaseHome;
   
   /**
    * 
    */
  -public class InstantDbTestDatabase implements TestDatabase {
  +public class InstantDbTestDatabase extends AbstractTestDatabase {
   
       protected Database database;
       protected InitialContext initialContext;
   
  -    private static String _createAccount = "CREATE TABLE account ( ssn 
CHAR(11) PRIMARY KEY, first_name CHAR(20), last_name CHAR(20), balance INT)";
  +    private static String CREATE_ACCOUNT = "CREATE TABLE account ( ssn 
CHAR(11) PRIMARY KEY, first_name CHAR(20), last_name CHAR(20), balance INT)";
       //private static String _createAccount = "CREATE TABLE Account ( AcctID 
INT PRIMARY KEY AUTO INCREMENT,  SSN CHAR(11), first_name CHAR(20), last_name 
CHAR(20), BALANCE INT)";
  -    private static String _dropAccount = "DROP TABLE account";
  +    private static String DROP_ACCOUNT = "DROP TABLE account";
   
       //private static String _createEntity = "CREATE TABLE entity ( id INT 
PRIMARY KEY, first_name CHAR(20), last_name CHAR(20) )";
  -    private static String _createEntity = "CREATE TABLE entity ( id INT 
PRIMARY KEY AUTO INCREMENT, first_name CHAR(20), last_name CHAR(20) )";
  -    private static String _dropEntity = "DROP TABLE entity";
  +    private static String CREATE_ENTITY = "CREATE TABLE entity ( id INT 
PRIMARY KEY AUTO INCREMENT, first_name CHAR(20), last_name CHAR(20) )";
  +    private static String DROP_ENTITY = "DROP TABLE entity";
  +
  +    private static final String CREATE_ENTITY_EXPLICIT_PK = "CREATE TABLE 
entity_explicit_pk ( id INT, first_name CHAR(20), last_name CHAR(20) )";
  +    private static final String DROP_ENTITY_EXPLICIT_PK = "DROP TABLE 
entity_explicit_pk";
   
       static {
           System.setProperty("noBanner", "true");
       }
   
  +    protected String getCreateAccount() {
  +        return CREATE_ACCOUNT;
  +    }
  +
  +    protected String getDropAccount() {
  +        return DROP_ACCOUNT;
  +    }
   
  -    public void createEntityTable() throws java.sql.SQLException {
  -        try {
  -            try {
  -                getDatabase().execute(_dropEntity);
  -            } catch (Exception e) {
  -                // not concerned
  -            }
  -            getDatabase().execute(_createEntity);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Cannot create entity table: 
" + re.getMessage(), _createEntity);
  -            }
  -        }
  -    }
  -
  -    public void dropEntityTable() throws java.sql.SQLException {
  -        try {
  -            getDatabase().execute(_dropEntity);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Unable to drop entity 
table: " + re.getMessage(), _dropEntity);
  -            }
  -        }
  -    }
  -
  -
  -    public void createAccountTable() throws java.sql.SQLException {
  -        try {
  -            try {
  -                getDatabase().execute(_dropAccount);
  -            } catch (Exception e) {
  -                // not concerned
  -            }
  -            getDatabase().execute(_createAccount);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Cannot create account 
table: " + re.getMessage(), _createAccount);
  -            }
  -        }
  -    }
  -
  -    public void dropAccountTable() throws java.sql.SQLException {
  -        try {
  -            getDatabase().execute(_dropAccount);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Cannot drop account table: 
" + re.getMessage(), _dropAccount);
  -            }
  -        }
  -    }
  -
  -    public void start() throws IllegalStateException {
  -        try {
  -            Properties properties = 
TestManager.getServer().getContextEnvironment();
  -            initialContext = new InitialContext(properties);
  -        } catch (Exception e) {
  -            throw new IllegalStateException("Cannot create initial context: 
" + e.getClass().getName() + " " + e.getMessage());
  -        }
  -    }
  -
  -
  -    private Database getDatabase() {
  -        if (database == null) {
  -            database = createDatabaseObject();
  -        }
  -        return database;
  -    }
  -
  -    private Database createDatabaseObject() {
  -        Object obj = null;
  -        DatabaseHome databaseHome = null;
  -        Database database = null;
  -        try {
  -            /* Create database */
  -            obj = initialContext.lookup("client/tools/DatabaseHome");
  -            databaseHome = (DatabaseHome) 
javax.rmi.PortableRemoteObject.narrow(obj, DatabaseHome.class);
  -        } catch (Exception e) {
  -            throw new IllegalStateException("Cannot find 
'client/tools/DatabaseHome': "
  -                    + e.getClass().getName()
  -                    + " "
  -                    + e.getMessage());
  -        }
  -        try {
  -            database = databaseHome.create();
  -        } catch (Exception e) {
  -            throw new IllegalStateException("Cannot start database: "
  -                    + e.getClass().getName()
  -                    + " "
  -                    + e.getMessage());
  -        }
  -        return database;
  +    protected String getCreateEntity() {
  +        return CREATE_ENTITY;
       }
   
  -    public void stop() throws IllegalStateException {
  +    protected String getDropEntity() {
  +        return DROP_ENTITY;
       }
   
  -    public void init(Properties props) throws IllegalStateException {
  +    protected String getCreateEntityExplictitPK() {
  +        return CREATE_ENTITY_EXPLICIT_PK;
       }
  +
  +    protected String getDropEntityExplicitPK() {
  +        return DROP_ENTITY_EXPLICIT_PK;
  +    }
  +
   }
   
       
  
  
  
  1.2       +47 -102   
openejb/modules/itests/src/itest/org/openejb/test/PostgreSqlTestDatabase.java
  
  Index: PostgreSqlTestDatabase.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/itests/src/itest/org/openejb/test/PostgreSqlTestDatabase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PostgreSqlTestDatabase.java       8 Sep 2004 07:20:16 -0000       1.1
  +++ PostgreSqlTestDatabase.java       2 Mar 2005 11:43:16 -0000       1.2
  @@ -1,140 +1,85 @@
   package org.openejb.test;
   
  -import java.rmi.RemoteException;
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
  -import java.util.Properties;
  +
   import javax.naming.InitialContext;
   
   import org.openejb.test.beans.Database;
  -import org.openejb.test.beans.DatabaseHome;
   
   /**
    * 
    */
  -public class PostgreSqlTestDatabase implements TestDatabase {
  +public class PostgreSqlTestDatabase extends AbstractTestDatabase {
   
       protected Database database;
       protected InitialContext initialContext;
   
   
  -    private static String _createAccount = "CREATE TABLE account ( ssn 
CHAR(11), first_name CHAR(20), last_name CHAR(20), balance INT, Constraint 
\"account_pkey\" Primary Key (\"ssn\"))";
  -    private static String _dropAccount = "DROP TABLE account";
  +    private static String CREATE_ACCOUNT = "CREATE TABLE account ( ssn 
CHAR(11), first_name CHAR(20), last_name CHAR(20), balance INT, Constraint 
\"account_pkey\" Primary Key (\"ssn\"))";
  +    private static String DROP_ACCOUNT = "DROP TABLE account";
  +    
  +    private static String CREATE_ACCOUNT_SEQ = "CREATE SEQUENCE 
account_id_seq";
  +    private static String DROP_ACCOUNT_SEQ = "DROP SEQUENCE account_id_seq";
  +    
       //private static String _createEntity  = "CREATE TABLE entity ( id INT 
NOT NULL, first_name CHAR(20), last_name CHAR(20), Constraint \"entity_pkey\" 
Primary Key (\"id\") )";
  -    private static String _createEntity = "CREATE TABLE entity ( id INT 
DEFAULT nextval('entity_id_seq') , first_name CHAR(20), last_name CHAR(20), 
Constraint \"entity_pkey\" Primary Key (\"id\") )";
  -    private static String _dropEntity = "DROP TABLE entity";
  +    private static String CREATE_ENTITY = "CREATE TABLE entity ( id INT 
DEFAULT nextval('entity_id_seq') , first_name CHAR(20), last_name CHAR(20), 
Constraint \"entity_pkey\" Primary Key (\"id\") )";
  +    private static String DROP_ENTITY = "DROP TABLE entity";
  +
  +    private static final String CREATE_ENTITY_SEQ = "CREATE SEQUENCE 
entity_id_seq";
  +    private static final String DROP_ENTITY_SEQ = "DROP SEQUENCE 
entity_id_seq";
  +
  +    private static final String CREATE_ENTITY_EXPLICIT_PK = "CREATE TABLE 
entity_explicit_pk ( id INT, first_name CHAR(20), last_name CHAR(20) )";
  +    private static final String DROP_ENTITY_EXPLICIT_PK = "DROP TABLE 
entity_explicit_pk";
   
       public void createEntityTable() throws java.sql.SQLException {
  -        try {
  -            database.execute("DROP SEQUENCE entity_id_seq");
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -        try {
  -            database.execute(_dropEntity);
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -        try {
  -            database.execute("CREATE SEQUENCE entity_id_seq");
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -        try {
  -            database.execute(_createEntity);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Cannot create entity table: 
" + re.getMessage(), _createEntity);
  -            }
  -        }
  +        executeStatementIgnoreErrors(DROP_ENTITY_SEQ);
  +        super.createEntityTable();
  +        executeStatement(CREATE_ENTITY_SEQ);
       }
   
       public void dropEntityTable() throws java.sql.SQLException {
  -        try {
  -            database.execute("DROP SEQUENCE entity_id_seq");
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -        try {
  -            database.execute(_dropEntity);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Unable to drop entity 
table: " + re.getMessage(), _dropEntity);
  -            }
  -        }
  +        super.dropEntityTable();
  +        executeStatement(DROP_ENTITY_SEQ);
       }
   
  +    public void createAccountTable() throws SQLException {
  +        executeStatement(DROP_ACCOUNT_SEQ);
  +        super.createAccountTable();
  +        executeStatement(CREATE_ACCOUNT_SEQ);
  +    }
   
  -    public void createAccountTable() throws java.sql.SQLException {
  -        try {
  -            database.execute("DROP SEQUENCE account_id_seq");
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -        try {
  -            database.execute("DROP TABLE account");
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -        try {
  -            database.execute("CREATE SEQUENCE account_id_seq");
  -        } catch (Exception e) {
  -            // not concerned
  -        }
  -        try {
  -            database.execute(_createAccount);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Cannot create account 
table: " + re.getMessage(), _createAccount);
  -            }
  -        }
  +    public void dropAccountTable() throws SQLException {
  +        super.dropAccountTable();
  +        executeStatement(DROP_ENTITY_SEQ);
  +    }
  +    
  +    protected String getCreateAccount() {
  +        return CREATE_ACCOUNT;
       }
   
  -    public void dropAccountTable() throws java.sql.SQLException {
  -        try {
  -            try {
  -                database.execute("DROP SEQUENCE account_id_seq");
  -            } catch (Exception e) {
  -                // not concerned
  -            }
  -            database.execute(_dropAccount);
  -        } catch (RemoteException re) {
  -            if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
  -                throw (java.sql.SQLException) re.detail;
  -            } else {
  -                throw new java.sql.SQLException("Cannot drop account table: 
" + re.getMessage(), _dropAccount);
  -            }
  -        }
  +    protected String getDropAccount() {
  +        return DROP_ACCOUNT;
       }
   
  -    public void start() throws IllegalStateException {
  -        try {
  -            Properties properties = 
TestManager.getServer().getContextEnvironment();
  -            initialContext = new InitialContext(properties);
  -    
  -            /* Create database */
  -            Object obj = initialContext.lookup("client/tools/DatabaseHome");
  -            DatabaseHome databaseHome = (DatabaseHome) 
javax.rmi.PortableRemoteObject.narrow(obj, DatabaseHome.class);
  -            database = databaseHome.create();
  -        } catch (Exception e) {
  -            throw new IllegalStateException("Cannot start database: " + 
e.getClass().getName() + " " + e.getMessage());
  -        }
  +    protected String getCreateEntity() {
  +        return CREATE_ENTITY;
  +    }
  +
  +    protected String getDropEntity() {
  +        return DROP_ENTITY;
       }
   
  -    public void stop() throws IllegalStateException {
  +    protected String getCreateEntityExplictitPK() {
  +        return CREATE_ENTITY_EXPLICIT_PK;
       }
   
  -    public void init(Properties props) throws IllegalStateException {
  +    protected String getDropEntityExplicitPK() {
  +        return DROP_ENTITY_EXPLICIT_PK;
       }
   
       public static void main(String[] args) {
  @@ -183,7 +128,7 @@
   
           System.out.println("Creating entity table.");
           try {
  -            stmt.execute(_createEntity);
  +            stmt.execute(CREATE_ENTITY);
           } catch (SQLException e) {
               System.out.println("Couldn't create the entity table");
               e.printStackTrace();
  @@ -218,7 +163,7 @@
   
           System.out.println("Dropping the entity table.");
           try {
  -            stmt.execute(_dropEntity);
  +            stmt.execute(DROP_ENTITY);
           } catch (SQLException e) {
               System.out.println("Couldn't drop the entity table");
               e.printStackTrace();
  
  
  
  1.2       +4 -0      
openejb/modules/itests/src/itest/org/openejb/test/TestDatabase.java
  
  Index: TestDatabase.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/itests/src/itest/org/openejb/test/TestDatabase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestDatabase.java 8 Sep 2004 07:20:16 -0000       1.1
  +++ TestDatabase.java 2 Mar 2005 11:43:16 -0000       1.2
  @@ -11,6 +11,10 @@
   
       public void dropEntityTable() throws java.sql.SQLException;
   
  +    public void createEntityExplicitePKTable() throws java.sql.SQLException;
  +    
  +    public void dropEntityExplicitePKTable() throws java.sql.SQLException;
  +
       public void createAccountTable() throws java.sql.SQLException;
   
       public void dropAccountTable() throws java.sql.SQLException;
  
  
  
  1.1                  
openejb/modules/itests/src/itest/org/openejb/test/AbstractTestDatabase.java
  
  Index: AbstractTestDatabase.java
  ===================================================================
  package org.openejb.test;
  
  import java.rmi.RemoteException;
  import java.util.Properties;
  import javax.naming.InitialContext;
  
  import org.openejb.test.beans.Database;
  import org.openejb.test.beans.DatabaseHome;
  
  /**
   *
   */
  public abstract class AbstractTestDatabase implements TestDatabase {
  
      protected Database database;
      protected InitialContext initialContext;
  
      protected abstract String getCreateAccount();
      protected abstract String getDropAccount();
  
      protected abstract String getCreateEntity();
      protected abstract String getDropEntity();
  
      protected abstract String getCreateEntityExplictitPK();
      protected abstract String getDropEntityExplicitPK();
  
      public void createEntityTable() throws java.sql.SQLException {
          executeStatementIgnoreErrors(getDropEntity());
          executeStatement(getCreateEntity());
      }
  
      public void dropEntityTable() throws java.sql.SQLException {
          executeStatement(getDropEntity());
      }
  
      public void createEntityExplicitePKTable() throws java.sql.SQLException {
          executeStatementIgnoreErrors(getDropEntityExplicitPK());
          executeStatement(getCreateEntityExplictitPK());
      }
  
      public void dropEntityExplicitePKTable() throws java.sql.SQLException {
          executeStatement(getDropEntityExplicitPK());
      }
  
      protected void executeStatementIgnoreErrors(String command) {
          try {
              getDatabase().execute(command);
          } catch (Exception e) {
              // not concerned
          }
      }
  
      protected void executeStatement(String command) throws 
java.sql.SQLException {
          try {
              getDatabase().execute(command);
          } catch (RemoteException re) {
              if (re.detail != null && re.detail instanceof 
java.sql.SQLException) {
                  throw (java.sql.SQLException) re.detail;
              } else {
                  throw new java.sql.SQLException("Cannot exectute statement: " 
+ re.getMessage(), command);
              }
          }
      }
  
      public void createAccountTable() throws java.sql.SQLException {
          executeStatementIgnoreErrors(getDropAccount());
          executeStatement(getCreateAccount());
      }
  
      public void dropAccountTable() throws java.sql.SQLException {
          executeStatement(getDropAccount());
      }
  
      public void start() throws IllegalStateException {
          try {
              // @todo this is a hack that limits us to a single server 
  //            Properties properties = 
TestManager.getServer().getContextEnvironment();
              Properties properties = new Properties();
              properties.put("test.server.class", 
"org.openejb.test.RemoteTestServer");
              properties.put("java.naming.factory.initial", 
"org.openejb.client.RemoteInitialContextFactory");
              properties.put("java.naming.provider.url", "127.0.0.1:4201");
              properties.put("java.naming.security.principal", "testuser");
              properties.put("java.naming.security.credentials", 
"testpassword");
              initialContext = new InitialContext(properties);
          } catch (Exception e) {
              throw new IllegalStateException("Cannot create initial context: " 
+ e.getClass().getName() + " " + e.getMessage());
          }
      }
  
  
      private Database getDatabase() {
          if (initialContext == null) {
              start();
          }
          if (database == null) {
              database = createDatabaseObject();
          }
          return database;
      }
  
      private Database createDatabaseObject() {
          Object obj = null;
          DatabaseHome databaseHome = null;
          Database database = null;
          try {
              /* Create database */
              obj = initialContext.lookup("client/tools/DatabaseHome");
              databaseHome = (DatabaseHome) 
javax.rmi.PortableRemoteObject.narrow(obj, DatabaseHome.class);
          } catch (Exception e) {
              throw (IllegalStateException)new IllegalStateException("Cannot 
find 'client/tools/DatabaseHome': "
                      + e.getMessage()).initCause(e);
          }
          try {
              database = databaseHome.create();
          } catch (Exception e) {
              throw (IllegalStateException)new IllegalStateException("Cannot 
start database: "
                      + e.getMessage()).initCause(e);
          }
          return database;
      }
  
      public void stop() throws IllegalStateException {
      }
  
      public void init(Properties props) throws IllegalStateException {
      }
  }
  
  
  
  
  
  

Reply via email to