You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2006/12/12 05:17:33 UTC
svn commit: r486009 [2/2] - in /incubator/openejb/trunk/openejb3: ./
container/openejb-core/
container/openejb-core/src/main/java/org/apache/openejb/core/cmp/
container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/
container/openejb-core/...
Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/HsqldbTestDatabase.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/HsqldbTestDatabase.java?view=auto&rev=486009
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/HsqldbTestDatabase.java (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/HsqldbTestDatabase.java Mon Dec 11 20:17:31 2006
@@ -0,0 +1,165 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.test;
+
+import org.apache.openejb.test.beans.Database;
+import org.apache.openejb.test.beans.DatabaseHome;
+
+import javax.naming.InitialContext;
+import java.rmi.RemoteException;
+import java.util.Properties;
+
+public class HsqldbTestDatabase implements TestDatabase{
+
+ protected Database database;
+ protected InitialContext initialContext;
+
+ private static String _createAccount = "CREATE TABLE account ( ssn VARCHAR(25), first_name VARCHAR(256), last_name VARCHAR(256), balance integer)";
+
+ private static String _dropAccount = "DROP TABLE account";
+
+ private static String _createEntity = "CREATE TABLE entity ( id IDENTITY, first_name VARCHAR(256), last_name VARCHAR(256) )";
+
+ private static String _dropEntity = "DROP TABLE entity";
+
+ // OneToOne
+ private static final String CREATE_ONE_TO_ONE_A = "CREATE TABLE OneToOneA(A1 INTEGER, A2 VARCHAR(50))";
+ private static final String DROP_ONE_TO_ONE_A = "DROP TABLE OneToOneA";
+ private static final String CREATE_ONE_TO_ONE_B = "CREATE TABLE OneToOneB(B1 INTEGER, B2 VARCHAR(50), B3 INTEGER, B4 VARCHAR(50), FKA1 INTEGER)";
+ private static final String DROP_ONE_TO_ONE_B = "DROP TABLE OneToOneB";
+
+ // CmrMapping
+ private static final String CREATE_ONE_OWNING = "CREATE TABLE oneowning (col_id INTEGER, col_field1 INTEGER)";
+ private static final String DROP_ONE_OWNING = "DROP TABLE oneowning";
+ private static final String CREATE_ONE_INVERSE = "CREATE TABLE oneinverse (col_id INTEGER)";
+ private static final String DROP_ONE_INVERSE = "DROP TABLE oneinverse";
+ private static final String CREATE_MANY_OWNING = "CREATE TABLE manyowning (col_id INTEGER, col_field1 INTEGER)";
+ private static final String DROP_MANY_OWNING = "DROP TABLE manyowning";
+
+ static{
+ System.setProperty("noBanner", "true");
+ }
+
+
+ public void createEntityTable() throws java.sql.SQLException {
+ createTable(_createEntity, _dropEntity);
+ createTable(CREATE_ONE_TO_ONE_A, DROP_ONE_TO_ONE_A);
+ createTable(CREATE_ONE_TO_ONE_B, DROP_ONE_TO_ONE_B);
+ createTable(CREATE_ONE_OWNING, DROP_ONE_OWNING);
+ createTable(CREATE_ONE_INVERSE, DROP_ONE_INVERSE);
+ createTable(CREATE_MANY_OWNING, DROP_MANY_OWNING);
+ }
+
+ public void dropEntityTable() throws java.sql.SQLException {
+ dropTable(_dropEntity);
+ dropTable(DROP_ONE_TO_ONE_A);
+ dropTable(DROP_ONE_TO_ONE_B);
+ dropTable(DROP_ONE_OWNING);
+ dropTable(DROP_ONE_INVERSE);
+ dropTable(DROP_MANY_OWNING);
+ }
+
+ private void createTable(String create, String drop) throws java.sql.SQLException {
+ try{
+ try{
+ database.execute(drop);
+ } catch (Exception e){
+ // not concerned
+ }
+ database.execute(create);
+ } 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 table: "+re.getMessage(), create);
+ }
+ }
+ }
+
+ private void dropTable(String drop) throws java.sql.SQLException {
+ try {
+ database.execute(drop);
+ } 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 table: "+re.getMessage(), drop);
+ }
+ }
+ }
+
+ public void createAccountTable() throws java.sql.SQLException {
+ try{
+ try{
+ database.execute(_dropAccount);
+ } catch (Exception e){
+ // not concerned
+ }
+ 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 java.sql.SQLException {
+ try {
+ 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);
+ }
+ }
+ }
+
+ public void start() throws IllegalStateException {
+ try {
+ Properties properties = TestManager.getServer().getContextEnvironment();
+ initialContext = new InitialContext(properties);
+ } catch (Exception e){
+ throw (IllegalStateException) new IllegalStateException("Cannot create initial context: "+e.getClass().getName()+" "+e.getMessage()).initCause(e);
+ }
+
+ Object obj =null;
+ DatabaseHome databaseHome =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());
+ }
+ }
+
+
+ public void stop() throws IllegalStateException {
+ }
+
+ public void init(Properties props) throws IllegalStateException {
+ }
+}
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2TestSuite.java?view=diff&rev=486009&r1=486008&r2=486009
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2TestSuite.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp2/Cmp2TestSuite.java Mon Dec 11 20:17:31 2006
@@ -41,7 +41,7 @@
//TODO:0:this.addTest(new Cmp2AllowedOperationsTests());
this.addTest(new Cmp2JndiEncTests());
this.addTest(new Cmp2RmiIiopTests());
-// this.addTest(new CmrTestSuite());
+ this.addTest(new CmrTestSuite());
}
public static junit.framework.Test suite() {
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/CmrTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/CmrTestSuite.java?view=diff&rev=486009&r1=486008&r2=486009
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/CmrTestSuite.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/CmrTestSuite.java Mon Dec 11 20:17:31 2006
@@ -36,28 +36,28 @@
// this.addTest(new CmrMappingTests());
}
- public static junit.framework.Test suite() {
- return new Cmp2TestSuite();
- }
+// public static junit.framework.Test suite() {
+// return new CmrTestSuite();
+// }
- /**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- */
- protected void setUp() throws Exception {
- Properties props = TestManager.getServer().getContextEnvironment();
- props.put(Context.SECURITY_PRINCIPAL, "ENTITY_TEST_CLIENT");
- props.put(Context.SECURITY_CREDENTIALS, "ENTITY_TEST_CLIENT");
- new InitialContext(props);
+// /**
+// * Sets up the fixture, for example, open a network connection.
+// * This method is called before a test is executed.
+// */
+// protected void setUp() throws Exception {
+// Properties props = TestManager.getServer().getContextEnvironment();
+// props.put(Context.SECURITY_PRINCIPAL, "ENTITY_TEST_CLIENT");
+// props.put(Context.SECURITY_CREDENTIALS, "ENTITY_TEST_CLIENT");
+// new InitialContext(props);
+//
+// TestManager.getDatabase().createEntityTable();
+// }
- TestManager.getDatabase().createEntityTable();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- TestManager.getDatabase().dropEntityTable();
- }
+// /**
+// * Tears down the fixture, for example, close a network connection.
+// * This method is called after a test is executed.
+// */
+// protected void tearDown() throws Exception {
+// TestManager.getDatabase().dropEntityTable();
+// }
}
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java?view=diff&rev=486009&r1=486008&r2=486009
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java Mon Dec 11 20:17:31 2006
@@ -19,8 +19,9 @@
import java.sql.Connection;
import java.sql.ResultSet;
-import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
import org.apache.openejb.test.entity.cmr.onetoone.ALocalHome;
@@ -28,6 +29,10 @@
import org.apache.openejb.test.entity.cmr.onetoone.BLocalHome;
import org.apache.openejb.test.entity.cmr.onetoone.BLocal;
+import javax.ejb.FinderException;
+import javax.ejb.CreateException;
+import javax.sql.DataSource;
+
/**
*
* @version $Revision: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
@@ -47,35 +52,13 @@
ahome = (ALocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/AHomeLocal");
bhome = (BLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/BHomeLocal");
-
- Connection connection = ds.getConnection();
- try {
- buildDBSchema(connection);
- } finally {
- connection.close();
- }
}
public void test00_AGetBExistingAB() throws Exception {
+ resetDB();
beginTransaction();
try {
- ALocal a = ahome.findByPrimaryKey(new Integer(1));
- BLocal b = bhome.findByPrimaryKey(new Integer(11));
- assertEquals(new Integer(11), b.getField1());
- assertEquals("value11", b.getField2());
- a.setB(b);
- b = a.getB();
- assertEquals(new Integer(11), b.getField1());
- assertEquals("value11", b.getField2());
- } finally {
- completeTransaction();
- }
- }
-
- public void test99_AGetBExistingAB() throws Exception {
- beginTransaction();
- try {
- ALocal a = ahome.findByPrimaryKey(new Integer(1));
+ ALocal a = findA(1);
BLocal b = a.getB();
assertNotNull(b);
assertEquals(new Integer(11), b.getField1());
@@ -86,9 +69,10 @@
}
public void test01_BGetAExistingAB() throws Exception {
+ resetDB();
beginTransaction();
try {
- BLocal b = bhome.findByPrimaryKey(new Integer(11));
+ BLocal b = findB(11);
ALocal a = b.getA();
assertNotNull(a);
assertEquals(new Integer(1), a.getField1());
@@ -98,217 +82,105 @@
}
}
- private void assertStateDropExisting() throws Exception {
- Connection c = ds.getConnection();
- Statement s = c.createStatement();
- ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB WHERE fka1 = 1");
- assertTrue(rs.next());
- assertEquals(0, rs.getInt(1));
- rs.close();
- s.close();
- c.close();
- }
-
- /**
- * TODO Disabled due to an Axion bug. It has been tested with another
- * DB DataSource successfully.
- */
- public void Xtest02_ASetBDropExisting() throws Exception {
+ public void test02_ASetBDropExisting() throws Exception {
+ resetDB();
beginTransaction();
try {
- ALocal a = ahome.findByPrimaryKey(new Integer(1));
+ ALocal a = findA(1);
a.setB(null);
} finally {
completeTransaction();
}
- assertStateDropExisting();
+ assertUnlinked(1);
}
- /**
- * TODO Disabled due to an Axion bug. It has been tested with another
- * DB DataSource successfully.
- */
- public void Xtest03_BSetADropExisting() throws Exception {
+ public void test03_BSetADropExisting() throws Exception {
+ resetDB();
beginTransaction();
try {
- BLocal b = bhome.findByPrimaryKey(new Integer(11));
+ BLocal b = findB(11);
b.setA(null);
} finally {
completeTransaction();
}
- assertStateDropExisting();
- }
-
- private void prepareNewAB() throws Exception {
- a = ahome.create(new Integer(2));
- a.setField2("value2");
- b = bhome.create(new Integer(22));
- b.setField2("value22");
- }
-
- private void assertStateNewAB() throws Exception {
- Connection c = ds.getConnection();
- Statement s = c.createStatement();
- ResultSet rs = s.executeQuery("SELECT a2 FROM OneToOneA WHERE a1 = 2");
- assertTrue(rs.next());
- assertEquals("value2", rs.getString(1));
- rs.close();
-
- rs = s.executeQuery("SELECT b1, b2 FROM OneToOneB WHERE fka1 = 2");
- assertTrue(rs.next());
- assertEquals(22, rs.getInt(1));
- assertEquals("value22", rs.getString(2));
- rs.close();
- s.close();
- c.close();
+ assertUnlinked(1);
}
public void test04_ASetBNewAB() throws Exception {
+ resetDB();
beginTransaction();
try {
- prepareNewAB();
+ a = findA(2);
+ b = createB(22);
a.setB(b);
} finally {
completeTransaction();
}
- assertStateNewAB();
+ assertLinked(2, 22);
}
public void test05_BSetANewAB() throws Exception {
+ resetDB();
beginTransaction();
try {
- prepareNewAB();
+ a = findA(2);
+ b = createB(22);
b.setA(a);
} finally {
completeTransaction();
}
- assertStateNewAB();
- }
-
- private void prepareExistingBNewA() throws Exception {
- a = ahome.create(new Integer(2));
- a.setField2("value2");
- b = bhome.findByPrimaryKey(new Integer(11));
- }
-
- private void assertStateExistingBNewA() throws Exception {
- Connection c = ds.getConnection();
- Statement s = c.createStatement();
- ResultSet rs = s.executeQuery("SELECT a2 FROM OneToOneA WHERE a1 = 2");
- assertTrue(rs.next());
- assertEquals("value2", rs.getString(1));
- rs.close();
-
- rs = s.executeQuery("SELECT b1, b2 FROM OneToOneB WHERE fka1 = 2");
- assertTrue(rs.next());
- assertEquals(11, rs.getInt(1));
- assertEquals("value11", rs.getString(2));
- rs.close();
- s.close();
- c.close();
+ assertLinked(2, 22);
}
public void test06_ASetBExistingBNewA() throws Exception {
+ resetDB();
beginTransaction();
try {
- prepareExistingBNewA();
+ a = findA(2);
+ b = findB(11);
a.setB(b);
} finally {
completeTransaction();
}
- assertStateExistingBNewA();
+ assertLinked(2, 11);
}
public void test07_BSetAExistingBNewA() throws Exception {
+ resetDB();
beginTransaction();
try {
- prepareExistingBNewA();
+ a = createA(2);
+ b = findB(11);
b.setA(a);
} finally {
completeTransaction();
}
-
- assertStateExistingBNewA();
+ assertLinked(2, 11);
}
- private void prepareExistingANewB() throws Exception {
- a = ahome.findByPrimaryKey(new Integer(1));
- b = bhome.create(new Integer(22));
- b.setField2("value22");
- }
-
- private void assertStateExistingANewB() throws Exception {
- Connection c = ds.getConnection();
- Statement s = c.createStatement();
- ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB WHERE fka1 = 1");
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- rs.close();
-
- rs = s.executeQuery("SELECT b1, b2 FROM OneToOneB WHERE fka1 = 1");
- assertTrue(rs.next());
- assertEquals(22, rs.getInt(1));
- assertEquals("value22", rs.getString(2));
- rs.close();
- s.close();
- c.close();
- }
-
- /**
- * TODO Disabled due to an Axion bug. It has been tested with another
- * DB DataSource successfully.
- */
- public void Xtest08_ASetBExistingANewB() throws Exception {
- beginTransaction();
- try {
- // The following PrepareStatement does not set to null fka
-// PreparedStatement ps = null;
-// ps = c.prepareStatement("UPDATE B SET value = CASE WHEN ? THEN ? ELSE value END, fka = CASE WHEN ? THEN ? ELSE fka END WHERE b1 = ?");
-// ps.setBoolean(1, false);
-// ps.setString(2, "");
-// ps.setBoolean(3, true);
-// ps.setNull(4);
-// ps.setInt(5, 1);
-// ps.execute();
-
- prepareExistingANewB();
- a.setB(b);
- } finally {
- completeTransaction();
- }
-
- assertStateExistingANewB();
- }
-
- /**
- * TODO Disabled due to an Axion bug. It has been tested with another
- * DB DataSource successfully.
- */
- public void Xtest09_BSetAExistingANewB() throws Exception {
+ public void test09_BSetAExistingANewB() throws Exception {
+ resetDB();
beginTransaction();
try {
- prepareExistingANewB();
+ a = findA(1);
+ b = createB(22);
b.setA(a);
} finally {
completeTransaction();
}
-
- assertStateExistingANewB();
+ assertLinked(1, 22);
}
- /**
- * TODO Disabled due to an Axion bug. It has been tested with another
- * DB DataSource successfully.
- */
- public void Xtest10_RemoveRelationships() throws Exception {
+ public void test10_RemoveRelationships() throws Exception {
+ resetDB();
beginTransaction();
try {
- ALocal a = ahome.findByPrimaryKey(new Integer(1));
+ ALocal a = findA(1);
a.remove();
} finally {
completeTransaction();
@@ -319,19 +191,20 @@
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
- rs.close();
+ close(rs);
rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB WHERE fka1 = 1");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
- rs.close();
- s.close();
- c.close();
+ close(rs);
+ close(s);
+ close(c);
}
public void test11_CascadeDelete() throws Exception {
+ resetDB();
beginTransaction();
try {
- BLocal b = bhome.findByPrimaryKey(new Integer(11));
+ BLocal b = findB(11);
b.remove();
} finally {
completeTransaction();
@@ -342,15 +215,17 @@
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneA WHERE A1 = 1");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
- rs.close();
- s.close();
- c.close();
+ close(rs);
+ close(s);
+ close(c);
}
- public void test12_CMPMappedToForeignKeyColumn() throws Exception {
+ // todo enable these when field to fk is implemented
+ public void Xtest12_CMPMappedToForeignKeyColumn() throws Exception {
+ resetDB();
beginTransaction();
try {
- BLocal b = bhome.findByPrimaryKey(new Integer(11));
+ BLocal b = findB(11);
Integer field3 = b.getField3();
assertEquals(b.getA().getPrimaryKey(), field3);
@@ -359,10 +234,12 @@
}
}
- public void test13_SetCMPMappedToForeignKeyColumn() throws Exception {
+ // todo enable these when field to fk is implemented
+ public void Xtest13_SetCMPMappedToForeignKeyColumn() throws Exception {
+ resetDB();
beginTransaction();
try {
- BLocal b = bhome.findByPrimaryKey(new Integer(11));
+ BLocal b = findB(11);
b.setField3(new Integer(2));
@@ -374,27 +251,132 @@
}
}
+ private ALocal createA(int aPk) throws CreateException {
+ ALocal a = ahome.create(new Integer(aPk));
+ a.setField2("value" + aPk);
+ return a;
+ }
+
+ private ALocal findA(int aPk) throws FinderException {
+ return ahome.findByPrimaryKey(new Integer(aPk));
+ }
+
+ private BLocal createB(int bPk) throws CreateException {
+ BLocal b = bhome.create(new Integer(bPk));
+ b.setField2("value" + bPk);
+ return b;
+ }
+ private BLocal findB(int bPk) throws FinderException {
+ return bhome.findByPrimaryKey(new Integer(bPk));
+ }
+
+
+ private void assertLinked(int aPk, int bPk) throws Exception {
+ Connection c = ds.getConnection();
+ Statement s = c.createStatement();
+ ResultSet rs = s.executeQuery("SELECT a2 FROM OneToOneA WHERE a1 = " + aPk);
+ assertTrue(rs.next());
+ assertEquals("value" + aPk, rs.getString("a2"));
+ close(rs);
+
+ rs = s.executeQuery("SELECT b1, b2 FROM OneToOneB WHERE fka1 = " + aPk);
+ assertTrue(rs.next());
+ assertEquals(bPk, rs.getInt("b1"));
+ assertEquals("value" + bPk, rs.getString("b2"));
+ close(rs);
+ close(s);
+ close(c);
+ }
+
+ private void assertUnlinked(int aPk) throws Exception {
+ Connection c = ds.getConnection();
+ Statement s = c.createStatement();
+ ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB WHERE fka1 = " + aPk);
+ assertTrue(rs.next());
+ assertEquals(0, rs.getInt(1));
+ close(rs);
+ close(s);
+ close(c);
+ }
+
+
+ private void resetDB() throws Exception {
+ Connection connection = ds.getConnection();
+ try {
+ buildDBSchema(connection);
+ } finally {
+ close(connection);
+ }
+ }
+
protected void buildDBSchema(Connection c) throws Exception {
Statement s = c.createStatement();
-// try {
-// s.execute("DROP TABLE A");
-// } catch (SQLException e) {
-// // ignore
-// }
-// try {
-// s.execute("DROP TABLE B");
-// } catch (SQLException e) {
-// // ignore
-// }
-//
-// s.execute("CREATE TABLE A(A1 INTEGER, A2 VARCHAR(50))");
-// s.execute("CREATE TABLE B(B1 INTEGER, B2 VARCHAR(50), FKA1 INTEGER)");
+
+ s.execute("DELETE FROM OneToOneA");
+ s.execute("DELETE FROM OneToOneB");
s.execute("INSERT INTO OneToOneA(A1, A2) VALUES(1, 'value1')");
s.execute("INSERT INTO OneToOneA(A1, A2) VALUES(2, 'value2')");
s.execute("INSERT INTO OneToOneB(B1, B2, FKA1) VALUES(11, 'value11', 1)");
- s.close();
- c.close();
+ close(s);
+ close(c);
+ }
+
+ protected void dump() throws Exception {
+ dumpTable(ds, "OneToOneA");
+ dumpTable(ds, "OneToOneB");
+ }
+
+ private static void dumpTable(DataSource ds, String table) throws SQLException {
+ Connection connection = null;
+ Statement statement = null;
+ ResultSet resultSet = null;
+ try {
+ connection = ds.getConnection();
+ statement = connection.createStatement();
+ resultSet = statement.executeQuery("SELECT * FROM " + table);
+ ResultSetMetaData setMetaData = resultSet.getMetaData();
+ int columnCount = setMetaData.getColumnCount();
+ while(resultSet.next()) {
+ StringBuilder row = new StringBuilder();
+ for (int i = 1; i <= columnCount; i++) {
+ if (i > 1) {
+ row.append(", ");
+ }
+ String name = setMetaData.getColumnName(i);
+ Object value = resultSet.getObject(i);
+ row.append(name).append("=").append(value);
+ }
+ System.out.println(row);
+ }
+ } finally {
+ close(resultSet);
+ close(statement);
+ close(connection);
+ }
+ }
+
+ private static void close(ResultSet resultSet) {
+ if (resultSet == null) return;
+ try {
+ resultSet.close();
+ } catch (SQLException e) {
+ }
+ }
+
+ private static void close(Statement statement) {
+ if (statement == null) return;
+ try {
+ statement.close();
+ } catch (SQLException e) {
+ }
}
+ private static void close(Connection connection) {
+ if (connection == null) return;
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ }
+ }
}
Modified: incubator/openejb/trunk/openejb3/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/pom.xml?view=diff&rev=486009&r1=486008&r2=486009
==============================================================================
--- incubator/openejb/trunk/openejb3/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/pom.xml Mon Dec 11 20:17:31 2006
@@ -355,6 +355,11 @@
<version>1.0.4</version>
</dependency>
<dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ </dependency>
+ <dependency>
<groupId>idb</groupId>
<artifactId>idb</artifactId>
<version>3.26</version>
@@ -529,10 +534,10 @@
<groupId>regexp</groupId>
<artifactId>regexp</artifactId>
</exclusion>
- <exclusion>
- <groupId>hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- </exclusion>
+ <!--<exclusion>-->
+ <!--<groupId>hsqldb</groupId>-->
+ <!--<artifactId>hsqldb</artifactId>-->
+ <!--</exclusion>-->
</exclusions>
</dependency>
<dependency>
Modified: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/RemoteiTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/RemoteiTest.java?view=diff&rev=486009&r1=486008&r2=486009
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/RemoteiTest.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/test/java/org/apache/openejb/RemoteiTest.java Mon Dec 11 20:17:31 2006
@@ -43,8 +43,8 @@
protected void setUp() throws Exception {
System.setProperty("openejb.test.server", EjbTestServer.class.getName());
- System.setProperty("openejb.test.database", org.apache.openejb.test.DerbyTestDatabase.class.getName());
-// System.setProperty("openejb.test.database", org.apache.openejb.test.InstantDbTestDatabase.class.getName());
+// System.setProperty("openejb.test.database", org.apache.openejb.test.DerbyTestDatabase.class.getName());
+ System.setProperty("openejb.test.database", org.apache.openejb.test.HsqldbTestDatabase.class.getName());
TestManager.init(null);
TestManager.start();
}
Modified: incubator/openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java?view=diff&rev=486009&r1=486008&r2=486009
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-http/src/test/java/org/apache/openejb/server/httpd/HttpEjbServerTest.java Mon Dec 11 20:17:31 2006
@@ -43,8 +43,8 @@
protected void setUp() throws Exception {
System.setProperty("openejb.test.server", HttpEjbTestServer.class.getName());
- System.setProperty("openejb.test.database", org.apache.openejb.test.DerbyTestDatabase.class.getName());
-// System.setProperty("openejb.test.database", org.apache.openejb.test.InstantDbTestDatabase.class.getName());
+// System.setProperty("openejb.test.database", org.apache.openejb.test.DerbyTestDatabase.class.getName());
+ System.setProperty("openejb.test.database", org.apache.openejb.test.HsqldbTestDatabase.class.getName());
TestManager.init(null);
TestManager.start();
}