Index: cpactf/src/test/ddl/org/castor/cpa/test/test30/create-mysql.sql =================================================================== --- cpactf/src/test/ddl/org/castor/cpa/test/test30/create-mysql.sql (revision 0) +++ cpactf/src/test/ddl/org/castor/cpa/test/test30/create-mysql.sql (revision 0) @@ -0,0 +1,88 @@ +DROP TABLE IF EXISTS test30_entity; + +CREATE TABLE test30_entity ( + id int not null, + value1 varchar(200) not null, + value2 varchar(200) +); + +CREATE UNIQUE INDEX test30_entity_pk on test30_entity ( id ); + +DROP TABLE IF EXISTS test30_extends; + +CREATE TABLE test30_extends ( + id int not null, + value3 varchar(200) null, + value4 varchar(200) null +); + +CREATE UNIQUE INDEX test30_extends_pk on test30_extends ( id ); + + +DROP TABLE IF EXISTS test30_call; + +CREATE TABLE test30_call ( + id int not null, + value1 varchar(200) not null, + value2 varchar(200) null +); + +CREATE UNIQUE INDEX test30_call_pk on test30_call ( id ); + + +DROP TABLE IF EXISTS test30_group; + +CREATE TABLE test30_group ( + id numeric(10,0) not null, + value1 varchar(200) not null +); + +CREATE UNIQUE INDEX test30_group_pk on test30_group ( id ); + +DROP TABLE IF EXISTS test30_persistent; + +CREATE TABLE test30_persistent ( + id integer not null, + ctime datetime not null, + mtime datetime null, + value1 varchar(200) not null, + parent_id integer null, + group_id numeric(10,0) not null +); + +CREATE UNIQUE INDEX test30_persistent_pk on test30_persistent ( id ); + + +DROP TABLE IF EXISTS test30_related; + +CREATE TABLE test30_related ( + id integer not null, + persist_id integer not null +); + +CREATE UNIQUE INDEX test30_related_pk on test30_related ( id ); + +DROP TABLE IF EXISTS test30_extends1; + +CREATE TABLE test30_extends1 ( + ident integer not null, + ext integer not null +); + +CREATE UNIQUE INDEX test30_extends1_pk on test30_extends1 ( ident ); + + +DROP TABLE IF EXISTS test30_extends2; + +CREATE TABLE test30_extends2 ( + id integer not null, + ext integer not null +); + +CREATE UNIQUE INDEX test30_extends2_pk on test30_extends2 ( id ); + +DROP TABLE IF EXISTS test30_nq_entity; +CREATE TABLE test30_nq_entity ( + id integer not null primary key, + name varchar(200) not null +); \ No newline at end of file Index: cpactf/src/test/ddl/org/castor/cpa/test/test30/create-mysql.sql =================================================================== --- cpactf/src/test/ddl/org/castor/cpa/test/test30/create-mysql.sql (revision 0) +++ cpactf/src/test/ddl/org/castor/cpa/test/test30/create-mysql.sql (revision 0) @@ -0,0 +1,88 @@ +DROP TABLE IF EXISTS test30_entity; + +CREATE TABLE test30_entity ( + id int not null, + value1 varchar(200) not null, + value2 varchar(200) +); + +CREATE UNIQUE INDEX test30_entity_pk on test30_entity ( id ); + +DROP TABLE IF EXISTS test30_extends; + +CREATE TABLE test30_extends ( + id int not null, + value3 varchar(200) null, + value4 varchar(200) null +); + +CREATE UNIQUE INDEX test30_extends_pk on test30_extends ( id ); + + +DROP TABLE IF EXISTS test30_call; + +CREATE TABLE test30_call ( + id int not null, + value1 varchar(200) not null, + value2 varchar(200) null +); + +CREATE UNIQUE INDEX test30_call_pk on test30_call ( id ); + + +DROP TABLE IF EXISTS test30_group; + +CREATE TABLE test30_group ( + id numeric(10,0) not null, + value1 varchar(200) not null +); + +CREATE UNIQUE INDEX test30_group_pk on test30_group ( id ); + +DROP TABLE IF EXISTS test30_persistent; + +CREATE TABLE test30_persistent ( + id integer not null, + ctime datetime not null, + mtime datetime null, + value1 varchar(200) not null, + parent_id integer null, + group_id numeric(10,0) not null +); + +CREATE UNIQUE INDEX test30_persistent_pk on test30_persistent ( id ); + + +DROP TABLE IF EXISTS test30_related; + +CREATE TABLE test30_related ( + id integer not null, + persist_id integer not null +); + +CREATE UNIQUE INDEX test30_related_pk on test30_related ( id ); + +DROP TABLE IF EXISTS test30_extends1; + +CREATE TABLE test30_extends1 ( + ident integer not null, + ext integer not null +); + +CREATE UNIQUE INDEX test30_extends1_pk on test30_extends1 ( ident ); + + +DROP TABLE IF EXISTS test30_extends2; + +CREATE TABLE test30_extends2 ( + id integer not null, + ext integer not null +); + +CREATE UNIQUE INDEX test30_extends2_pk on test30_extends2 ( id ); + +DROP TABLE IF EXISTS test30_nq_entity; +CREATE TABLE test30_nq_entity ( + id integer not null primary key, + name varchar(200) not null +); \ No newline at end of file Index: cpactf/src/test/java/org/castor/cpa/test/test30/Test30.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/Test30.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/Test30.java (revision 0) @@ -0,0 +1,461 @@ +package org.castor.cpa.test.test30; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.Statement; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.castor.cpa.test.framework.CPATestCase; +import org.castor.cpa.test.framework.xml.types.DatabaseEngineType; +import org.exolab.castor.jdo.Database; +import org.exolab.castor.jdo.OQLQuery; +import org.exolab.castor.jdo.PersistenceException; +import org.exolab.castor.jdo.QueryResults; + + +public final class Test30 extends CPATestCase { + private static final Log LOG = LogFactory.getLog(Test30.class); + + private static final String DBNAME = "test30"; + + private static final int MIN_ID = 10; + private static final int MAX_ID = 29; + private static final int MIN_EXTENDS_ID = 30; + private static final int MAX_EXTENDS_ID = 49; + private Database _db; + private OQLQuery query; + + public boolean include(final DatabaseEngineType engine) { + return (engine == DatabaseEngineType.MYSQL); + } + + public void setUp() throws Exception { + _db = getJDOManager(DBNAME).getDatabase(); + LOG.info("Test30 Started"); + } + + public void tearDown() throws PersistenceException { + if (_db.isActive()) { _db.rollback(); } + _db.close(); + LOG.info("Test30 complete"); + } + + public static Test suite() { + TestSuite suite = new TestSuite(Test30.class.getName()); + + suite.addTest(new Test30("populateDatabase")); + suite.addTest(new Test30("testBasicSelect1")); + suite.addTest(new Test30("testBasicSelect2")); + suite.addTest(new Test30("testBasicSelect3")); + suite.addTest(new Test30("testBasicSelect4")); + suite.addTest(new Test30("testBasicSelect5")); + suite.addTest(new Test30("testBasicSelect6")); + suite.addTest(new Test30("testBasicSelect7")); + suite.addTest(new Test30("testBasicSelect8")); + suite.addTest(new Test30("testBasicSelect9")); + suite.addTest(new Test30("testBasicSelect10")); + suite.addTest(new Test30("testBasicSelect11")); + suite.addTest(new Test30("testBasicSelect12")); + suite.addTest(new Test30("testBasicSelect13")); + suite.addTest(new Test30("testBasicSelect14")); + suite.addTest(new Test30("testBasicSelect15")); + suite.addTest(new Test30("testBasicSelect16")); + suite.addTest(new Test30("testBasicSelect17")); + suite.addTest(new Test30("testBasicSelect18")); + suite.addTest(new Test30("testBasicSelect19")); + suite.addTest(new Test30("testBasicSelect20")); + suite.addTest(new Test30("populateDatabaseExtends")); + suite.addTest(new Test30("testSelectCountFunc1")); + suite.addTest(new Test30("testSelectCountFunc2")); + suite.addTest(new Test30("testSelectCountFunc3")); + return suite; + } + public Test30(final String name) { + super(name); + } + + /***************************************************************** + * This method will truncate everything from the database and then + * repopulate it. It needs to be generic enough to work across databases + * so I would prefer to use straight JDBC calls. + *********************************************************************/ + public void populateDatabase() throws Exception { + _db.begin(); + Connection connection = _db.getJdbcConnection(); + Statement statement = connection.createStatement(); + statement.execute("delete from test30_extends"); + + connection = _db.getJdbcConnection(); + statement = connection.createStatement(); + statement.execute("delete from test30_entity"); + _db.commit(); + + _db.begin(); + for (int i = MIN_ID; i <= MAX_ID; ++i) { + Entity obj = new Entity(); + obj.setId(i); + obj.setValue1(Entity.DEFAULT_VALUE_1 + " " + Integer.toString(i)); + _db.create(obj); + } + _db.commit(); + + _db.begin(); + connection = _db.getJdbcConnection(); + statement = connection.createStatement(); + statement.execute("delete from test30_group"); + _db.commit(); + + _db.begin(); + GroupEntity group = new GroupEntity(); + _db.create(group); + _db.commit(); + } + + /* + * Test many different variations of the basic SELECT statement. + */ + public void testBasicSelect1() throws Exception { + _db.begin(); + // fetch all available data + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x"); + tryQuery(query, MAX_ID - MIN_ID + 1); + _db.commit(); + } + public void testBasicSelect2() throws Exception { + _db.begin(); +// query only one object, expecting one + assertTrue("internal error: MIN_ID<=15 && MAX_ID>=15", + (MIN_ID <= 15) && (MAX_ID >= 15)); + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=15"); + assertTrue("internal error", MIN_ID > 1); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect3() throws Exception { + _db.begin(); +// query only one object, expecting none + assertTrue("internal error: MIN_ID>1", MIN_ID > 1); + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=1"); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect4() throws Exception { + _db.begin(); + // query using bind variable parameter, find one object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=$1"); + query.bind(MIN_ID); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect5() throws Exception { + _db.begin(); +// query using bind variable parameter, find nothing + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=$1"); + query.bind(MIN_ID - 1); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect6() throws Exception { + _db.begin(); +// query using comparison between bind variable parameter and constant, + // find all objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where $(int)1 = 1000"); + query.bind(1000); + tryQuery(query, MAX_ID + 1 - MIN_ID); + _db.commit(); + } + public void testBasicSelect7() throws Exception { + _db.begin(); +// query using comparison between bind variable parameter and constant, + // find no objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where $(int)1 = 1000"); + query.bind(2000); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect8() throws Exception { + _db.begin(); +// query using 1 bind variable parameters in two places + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id>$1 and id<$2"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID - 2); + _db.commit(); + } + public void testBasicSelect9() throws Exception { + _db.begin(); +// query using 1 bind variable parameter, find all but the first and last object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id>$1 and id<$2"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID - 2); + _db.commit(); + } + public void testBasicSelect10() throws Exception { + _db.begin(); +// query using 2 bind variable parameters, find all but the first and last object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id<$2 and id>$1"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID - 2); + _db.commit(); + } + public void testBasicSelect11() throws Exception { + _db.begin(); +// query using "BETWEEN" operator, finding all records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id between $1 and $2"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID); + _db.commit(); + } + public void testBasicSelect12() throws Exception { + _db.begin(); +// query using "BETWEEN" operator, finding no records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id between $2 and $1"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect13() throws Exception { + _db.begin(); +// query using string constants containing a question mark in the WHERE clause, + // finding all records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where \"abc123?äöü\" = \"abc123?äöü\""); + tryQuery(query, MAX_ID + 1 - MIN_ID); + _db.commit(); + } + public void testBasicSelect14() throws Exception { + _db.begin(); +// query using string constants containing a question mark in the WHERE clause, + // finding no records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where \"abc\" = \"?123\""); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect15() throws Exception { + _db.begin(); +// query using "IN" operator + assertTrue("internal error: MIN_ID<=15 && MAX_ID>=18", + (MIN_ID <= 15) && (MAX_ID >= 15)); + assertTrue("internal error: MIN_ID>5", MIN_ID > 5); + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id in list(5, 15, 18)"); + tryQuery(query, 2); + _db.commit(); + } + public void testBasicSelect16() throws Exception { + _db.begin(); + // query using "IN" operator and bind variables, find all objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id in list($1, $2, $3)"); + query.bind(MIN_ID); + query.bind((MIN_ID + MAX_ID) / 2); + query.bind(MAX_ID); + tryQuery(query, 3); + _db.commit(); + } + public void testBasicSelect17() throws Exception { + _db.begin(); +// query using "IN" operator and bind variables, find some objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id in list($1, $2)"); + query.bind(MIN_ID); + query.bind(MAX_ID + 5); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect18() throws Exception { + _db.begin(); +// query using "IN" operator and string values, find one object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where value1 in list(\"XXX\", \"one 21\", 'A')"); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect19() throws Exception { + _db.begin(); + query = _db.getOQLQuery( + "CALL SQL " + + "select id, value1 " + + "from test30_group entity " + + "where entity.id >= $1 and entity.id <= $1 " + + " AS " + GroupEntity.class.getName()); + query.bind(GroupEntity.DEFAULT_ID); + QueryResults res = query.execute(); + + assertTrue(res.hasMore()); + GroupEntity obj = (GroupEntity) res.next(); + assertEquals(GroupEntity.DEFAULT_ID, obj.getId()); + assertEquals(GroupEntity.DEFAULT_VALUE, obj.getValue1()); + + assertFalse (res.hasMore()); + + _db.commit(); + } + public void testBasicSelect20() throws Exception { + _db.begin(); + query = _db.getOQLQuery( + "CALL SQL " + + "select id, value1 " + + "from test30_group entity " + + "where entity.id >= $1 and entity.id <= $1 and " + + "entity.value1 = $2 " + + " AS " + GroupEntity.class.getName()); + query.bind(GroupEntity.DEFAULT_ID); + query.bind(GroupEntity.DEFAULT_VALUE); + QueryResults res = query.execute(); + + assertTrue(res.hasMore()); + GroupEntity obj = (GroupEntity) res.next(); + assertEquals(GroupEntity.DEFAULT_ID, obj.getId()); + assertEquals(GroupEntity.DEFAULT_VALUE, obj.getValue1()); + + assertFalse (res.hasMore()); + + _db.commit(); + } + + public void populateDatabaseExtends() throws Exception { + _db.begin(); + Connection connection = _db.getJdbcConnection(); + Statement statement = connection.createStatement(); + statement.execute("delete from test30_extends"); + + connection = _db.getJdbcConnection(); + statement = connection.createStatement(); + statement.execute("delete from test30_entity"); + _db.commit(); + + _db.begin(); + for (int i = MIN_ID; i <= MAX_ID; ++i) { + Entity obj = new Entity(); + obj.setId(i); + obj.setValue1(Entity.DEFAULT_VALUE_1 + " " + Integer.toString(i)); + _db.create(obj); + } + _db.commit(); + + _db.begin(); + for (int i = MIN_EXTENDS_ID; i <= MAX_EXTENDS_ID; ++i) { + ExtendsEntity ext = new ExtendsEntity(); + ext.setId(i); + ext.setValue1(Entity.DEFAULT_VALUE_1 + " " + Integer.toString(i)); + _db.create(ext); + } + _db.commit(); + + } + + /* + * Test SQL functions (e.g. count(), max(), first(), last(), avg(), etc.). + */ + public void testSelectCountFunc1() throws Exception { + _db.begin(); + + // obtain number of TestObject instances + OQLQuery query = _db.getOQLQuery( + "SELECT count(x.id) FROM " + Entity.class.getName() + " x"); + tryFunctionQuery(query, 40); + _db.commit(); + } + public void testSelectCountFunc2() throws Exception { + _db.begin(); + + // obtain distinct number of TestObject instances + query = _db.getOQLQuery( + "SELECT count(distinct x.id) FROM " + Entity.class.getName() + " x"); + tryFunctionQuery(query, 40); + _db.commit(); + } + public void testSelectCountFunc3() throws Exception { + _db.begin(); + + // obtain number of TestObjectExtends instances + query = _db.getOQLQuery( + "SELECT count(x.id) FROM " + ExtendsEntity.class.getName() + " x"); + tryFunctionQuery(query, 20); + _db.commit(); + } + + + + + + /* + * test received result set + */ + public void tryQuery(final OQLQuery query, final int countExpected) + throws PersistenceException { + QueryResults res = query.execute(); + int count = 0; + + try { + while (res.hasMore()) { + Entity obj = (Entity) res.next(); + + String val = Entity.DEFAULT_VALUE_1 + " " + Integer.toString(obj.getId()); + assertEquals("value1", val, obj.getValue1()); + assertEquals("value2", Entity.DEFAULT_VALUE_2, obj.getValue2()); + + ++count; + } + } finally { + res.close(); + } + + assertEquals("number of objects found", countExpected, count); + } + /* + * test received result set + */ + public void tryFunctionQuery(final OQLQuery query, final int countExpected) + throws PersistenceException { + QueryResults res = query.execute(); + long functionValue = 0; + + try { + if (res.hasMore()) { + Object obj = res.next(); + if (obj instanceof Long) { + functionValue = ((Long) obj).longValue(); + } else if (obj instanceof BigDecimal) { + functionValue = ((BigDecimal) obj).longValue(); + } else if (obj instanceof Integer) { + functionValue = ((Integer) obj).longValue(); + } + } + } finally { + res.close(); + } + assertEquals("number of objects found", countExpected, functionValue); + } + +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity.java (revision 0) @@ -0,0 +1,70 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class ExtendsEntity extends Entity { + public static final int DEFAULT_ID = 4; + public static final String DEFAULT_VALUE_3 = "three"; + public static final String DEFAULT_VALUE_4 = "four"; + + private String _value3; + private String _value4; + + public ExtendsEntity() { + super(); + setId(DEFAULT_ID); + _value3 = DEFAULT_VALUE_3; + _value4 = DEFAULT_VALUE_4; + } + + public void setValue3(final String value3) { _value3 = value3; } + public String getValue3() { return _value3; } + + public void setValue4(final String value4) { _value4 = value4; } + public String getValue4() { return _value4; } + + public String toString() { + return getId() + " / " + getValue1() + " / " + + getValue2() + "/" + getValue3() + "/" + getValue4(); + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/CallEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/CallEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/CallEntity.java (revision 0) @@ -0,0 +1,81 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class CallEntity { + public static final String DEFAULT_VALUE = "one"; + + private static int _idcount = 0; + + private int _id; + private String _value1; + private String _value2; + + public CallEntity() { + _value1 = DEFAULT_VALUE; + synchronized (DEFAULT_VALUE) { + _id = _idcount; + _value2 = String.valueOf(_idcount); + _idcount++; + } + } + + public void setId(final int id) { _id = id; } + public int getId() { return _id; } + + + public void setValue1(final String value1) { _value1 = value1; } + public String getValue1() { return _value1; } + + + public void setValue2(final String value2) { _value2 = value2; } + public String getValue2() { return _value2; } + + public int getIntValue2() { + return Integer.valueOf(_value2).intValue(); + } + + public String toString() { + return _id + " / " + _value1 + " / " + _value2; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity1.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity1.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity1.java (revision 0) @@ -0,0 +1,66 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +import java.util.ArrayList; +import java.util.Collection; + +public class ExtendsEntity1 extends PersistentEntity { + /** SerialVersionUID */ + private static final long serialVersionUID = -5458281563382200756L; + + private int _ext; + private Collection _list = new ArrayList(); + + public ExtendsEntity1() { super(); } + + public final void setExt(final int ext) { _ext = ext; } + public final int getExt() { return _ext; } + + public final Collection getList() { return _list; } + public final void setList(final Collection list) { _list = list; } + + public String toString() { + return super.toString() + " / " + _ext; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/GroupEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/GroupEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/GroupEntity.java (revision 0) @@ -0,0 +1,66 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class GroupEntity { + public static final int DEFAULT_ID = 4; + public static final String DEFAULT_VALUE = "group"; + + private int _id; + private String _value; + + public GroupEntity() { + _id = DEFAULT_ID; + _value = DEFAULT_VALUE; + } + + public void setId(final int id) { _id = id; } + public int getId() { return _id; } + + public void setValue1(final String value) { _value = value; } + public String getValue1() { return _value; } + + public String toString() { + return _id + " / " + _value; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity2.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity2.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity2.java (revision 0) @@ -0,0 +1,59 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class ExtendsEntity2 extends PersistentEntity { + /** SerialVersionUID */ + private static final long serialVersionUID = -4810221474022258639L; + + private int _ext; + + public ExtendsEntity2() { super(); } + + public void setExt(final int ext) { _ext = ext; } + public int getExt() { return _ext; } + + public String toString() { + return super.toString() + " / " + _ext; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/NQEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/NQEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/NQEntity.java (revision 0) @@ -0,0 +1,34 @@ +package org.castor.cpa.test.test30; + +public final class NQEntity { + private Integer _id; + private String _name; + + public NQEntity(){ + } + + public NQEntity(Integer id){ + _id = id; + } + + public NQEntity(Integer id, String name){ + _id = id; + _name = name; + } + + public Integer getId() { + return _id; + } + + public void setId(final Integer id) { + _id = id; + } + + public String getName() { + return _name; + } + + public void setName(final String name) { + _name = name; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/Entity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/Entity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/Entity.java (revision 0) @@ -0,0 +1,72 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public class Entity { + public static final int DEFAULT_ID = 3; + public static final String DEFAULT_VALUE_1 = "one"; + public static final String DEFAULT_VALUE_2 = "two"; + + private int _id; + private String _value1; + private String _value2; + + public Entity() { + _id = DEFAULT_ID; + _value1 = DEFAULT_VALUE_1; + _value2 = DEFAULT_VALUE_2; + } + + public final void setId(final int id) { _id = id; } + public final int getId() { return _id; } + + public final void setValue1(final String value1) { _value1 = value1; } + public final String getValue1() { return _value1; } + + public final void setValue2(final String value2) { _value2 = value2; } + public final String getValue2() { return _value2; } + + public String toString() { + return _id + " / " + _value1 + " / " + _value2; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/PersistentEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/PersistentEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/PersistentEntity.java (revision 0) @@ -0,0 +1,244 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +import java.io.Serializable; +import java.util.Date; +import java.util.Enumeration; +import java.util.Vector; + +import org.exolab.castor.jdo.Database; +import org.exolab.castor.jdo.Persistent; +import org.exolab.castor.jdo.Query; +import org.exolab.castor.jdo.QueryResults; +import org.exolab.castor.jdo.TimeStampable; +import org.exolab.castor.mapping.AccessMode; + +public class PersistentEntity implements Persistent, TimeStampable, Serializable { + /** SerialVersionUID */ + private static final long serialVersionUID = 861059599755591225L; + + public static final int DEFAULT_ID = 7; + public static final String DEFAULT_VALUE = "persistent"; + + private int _id; + private String _value; + private Date _creationTime; + private Date _modificationTime; + private Integer _parentId; + private PersistentEntity _parent; + private Vector _children; + private Vector _origChildren; + private GroupEntity _group; + private RelatedEntity _related; + private RelatedEntity _origRelated; + + private transient Database _db; + private long _timeStamp; + + public PersistentEntity() { + this(DEFAULT_ID); + } + + public PersistentEntity(final int id) { + _id = id; + _value = DEFAULT_VALUE; + _children = new Vector(); + } + + public final void setId(final int id) { _id = id; } + public final int getId() { return _id; } + + public final void setParentId(final Integer parentId) { _parentId = parentId; } + public final Integer getParentId() { return _parentId; } + + public final void setValue1(final String value) { _value = value; } + public final String getValue1() { return _value; } + + public final void setCreationTime(final Date creationTime) { + _creationTime = creationTime; + } + public final Date getCreationTime() { return _creationTime; } + + public final void setModificationTime(final Date modificationTime) { + _modificationTime = modificationTime; + } + public final Date getModificationTime() { return _modificationTime; } + + public final void setParent(final PersistentEntity parent) { + _parent = parent; + _parentId = (_parent == null) ? null : new Integer(_parent._id); + } + public final PersistentEntity getParent() { return _parent; } + + public final void addChild(final PersistentEntity child) { + _children.addElement(child); + child.setParent(this); + child.setGroup(_group); + } + public final Vector getChildren() { return _children; } + public final PersistentEntity findChild(final int id) { + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + PersistentEntity child = (PersistentEntity) en.nextElement(); + if (child.getId() == id) { return child; } + } + return null; + } + + public final void setGroup(final GroupEntity group) { + if (_group == group) { return; } + _group = group; + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + PersistentEntity child = (PersistentEntity) en.nextElement(); + child.setGroup(_group); + } + } + public final GroupEntity getGroup() { return _group; } + + public final void setRelated(final RelatedEntity related) { + _related = related; + if (related != null) { related.setPersistent(this); } + } + public final RelatedEntity getRelated() { return _related; } + + public final void jdoPersistent(final Database db) { _db = db; } + public final void jdoTransient() { _db = null; } + public final Class jdoLoad(final AccessMode accessMode) throws Exception { + if (_parentId != null) { + _parent = (PersistentEntity) _db.load( + PersistentEntity.class, _parentId, accessMode); + } + + Query qry = _db.getOQLQuery("SELECT p FROM " + PersistentEntity.class.getName() + + " p WHERE parentId=$1"); + qry.bind(_id); + QueryResults res = qry.execute(); + while (res.hasMore()) { _children.addElement(res.next()); } + _origChildren = (Vector) _children.clone(); + _origRelated = _related; + return null; + } + public final void jdoStore(final boolean modified) throws Exception { + if (modified) { _modificationTime = new Date(); } + + PersistentEntity child; + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + child = (PersistentEntity) en.nextElement(); + if (!vectorContainsChild(_origChildren, child)) { + _db.create(child); + } + } + for (Enumeration en = _origChildren.elements(); en.hasMoreElements();) { + child = (PersistentEntity) en.nextElement(); + if (!vectorContainsChild(_children, child)) { + _db.remove(child); + } + } + if ((_origRelated == null) && (_related != null)) { + _db.create(_related); + } + if ((_origRelated != null) && (_related == null)) { + _db.remove(_origRelated); + } + _origRelated = _related; + } + public final void jdoUpdate() throws Exception { + for (Enumeration en = _origChildren.elements(); en.hasMoreElements();) { + _db.update(en.nextElement()); + } + if (_origRelated != null) { + _db.update(_origRelated); + } + } + public final void jdoBeforeCreate(final Database db) throws Exception { + if (_group == null) { + throw new Exception("Incorrect object state: group is not set in " + this); + } + Object grp; + try { + grp = db.load(GroupEntity.class, new Integer(_group.getId())); + } catch (Exception ex) { + grp = null; + } + if (grp == null) { db.create(_group); } + _creationTime = new Date(); + } + public final void jdoAfterCreate() throws Exception { + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + _db.create(en.nextElement()); + } + _origChildren = (Vector) _children.clone(); + if (_related != null) { _db.create(_related); } + _origRelated = _related; + } + public final void jdoBeforeRemove() throws Exception { + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + _db.remove(en.nextElement()); + } + if (_related != null) { _db.remove(_related); } + } + public final void jdoAfterRemove() throws Exception { } + public final long jdoGetTimeStamp() { return _timeStamp; } + + public final void jdoSetTimeStamp(final long timeStamp) { _timeStamp = timeStamp; } + + private boolean vectorContainsChild(final Vector v, final PersistentEntity child) { + for (Enumeration en = v.elements(); en.hasMoreElements();) { + PersistentEntity ch = (PersistentEntity) en.nextElement(); + if (ch.getId() == child.getId()) { return true; } + } + return false; + } + + public String toString() { + String children = ""; + + for (int i = 0; i < _children.size(); ++i) { + if (i > 0) { children = children + ", "; } + children = children + _children.elementAt(i).toString(); + } + return _id + " / " + _value + " / " + _modificationTime + " (" + + _parentId + ":" + ((_group != null) ? new Integer(_group.getId()) : null) + + ") { " + children + " }"; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/RelatedEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/RelatedEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/RelatedEntity.java (revision 0) @@ -0,0 +1,74 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +import org.exolab.castor.jdo.TimeStampable; + +public final class RelatedEntity implements TimeStampable, java.io.Serializable { + /** SerialVersionUID */ + private static final long serialVersionUID = -6408619974569022386L; + + public static final int DEFAULT_ID = 5; + + private int _id; + private PersistentEntity _persistent; + private long _timeStamp; + + public RelatedEntity() { this(DEFAULT_ID); } + public RelatedEntity(final int id) { _id = id; } + + public void setId(final int id) { _id = id; } + public int getId() { return _id; } + + public void setPersistent(final PersistentEntity persistent) { + _persistent = persistent; + } + public PersistentEntity getPersistent() { return _persistent; } + + public long jdoGetTimeStamp() { return _timeStamp; } + public void jdoSetTimeStamp(final long timeStamp) { _timeStamp = timeStamp; } + + public String toString() { + return _id + " / " + ((_persistent == null) ? 0 : _persistent.getId()); + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/CallEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/CallEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/CallEntity.java (revision 0) @@ -0,0 +1,81 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class CallEntity { + public static final String DEFAULT_VALUE = "one"; + + private static int _idcount = 0; + + private int _id; + private String _value1; + private String _value2; + + public CallEntity() { + _value1 = DEFAULT_VALUE; + synchronized (DEFAULT_VALUE) { + _id = _idcount; + _value2 = String.valueOf(_idcount); + _idcount++; + } + } + + public void setId(final int id) { _id = id; } + public int getId() { return _id; } + + + public void setValue1(final String value1) { _value1 = value1; } + public String getValue1() { return _value1; } + + + public void setValue2(final String value2) { _value2 = value2; } + public String getValue2() { return _value2; } + + public int getIntValue2() { + return Integer.valueOf(_value2).intValue(); + } + + public String toString() { + return _id + " / " + _value1 + " / " + _value2; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/Entity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/Entity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/Entity.java (revision 0) @@ -0,0 +1,72 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public class Entity { + public static final int DEFAULT_ID = 3; + public static final String DEFAULT_VALUE_1 = "one"; + public static final String DEFAULT_VALUE_2 = "two"; + + private int _id; + private String _value1; + private String _value2; + + public Entity() { + _id = DEFAULT_ID; + _value1 = DEFAULT_VALUE_1; + _value2 = DEFAULT_VALUE_2; + } + + public final void setId(final int id) { _id = id; } + public final int getId() { return _id; } + + public final void setValue1(final String value1) { _value1 = value1; } + public final String getValue1() { return _value1; } + + public final void setValue2(final String value2) { _value2 = value2; } + public final String getValue2() { return _value2; } + + public String toString() { + return _id + " / " + _value1 + " / " + _value2; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity.java (revision 0) @@ -0,0 +1,70 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class ExtendsEntity extends Entity { + public static final int DEFAULT_ID = 4; + public static final String DEFAULT_VALUE_3 = "three"; + public static final String DEFAULT_VALUE_4 = "four"; + + private String _value3; + private String _value4; + + public ExtendsEntity() { + super(); + setId(DEFAULT_ID); + _value3 = DEFAULT_VALUE_3; + _value4 = DEFAULT_VALUE_4; + } + + public void setValue3(final String value3) { _value3 = value3; } + public String getValue3() { return _value3; } + + public void setValue4(final String value4) { _value4 = value4; } + public String getValue4() { return _value4; } + + public String toString() { + return getId() + " / " + getValue1() + " / " + + getValue2() + "/" + getValue3() + "/" + getValue4(); + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity1.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity1.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity1.java (revision 0) @@ -0,0 +1,66 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +import java.util.ArrayList; +import java.util.Collection; + +public class ExtendsEntity1 extends PersistentEntity { + /** SerialVersionUID */ + private static final long serialVersionUID = -5458281563382200756L; + + private int _ext; + private Collection _list = new ArrayList(); + + public ExtendsEntity1() { super(); } + + public final void setExt(final int ext) { _ext = ext; } + public final int getExt() { return _ext; } + + public final Collection getList() { return _list; } + public final void setList(final Collection list) { _list = list; } + + public String toString() { + return super.toString() + " / " + _ext; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity2.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity2.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/ExtendsEntity2.java (revision 0) @@ -0,0 +1,59 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class ExtendsEntity2 extends PersistentEntity { + /** SerialVersionUID */ + private static final long serialVersionUID = -4810221474022258639L; + + private int _ext; + + public ExtendsEntity2() { super(); } + + public void setExt(final int ext) { _ext = ext; } + public int getExt() { return _ext; } + + public String toString() { + return super.toString() + " / " + _ext; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/GroupEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/GroupEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/GroupEntity.java (revision 0) @@ -0,0 +1,66 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +public final class GroupEntity { + public static final int DEFAULT_ID = 4; + public static final String DEFAULT_VALUE = "group"; + + private int _id; + private String _value; + + public GroupEntity() { + _id = DEFAULT_ID; + _value = DEFAULT_VALUE; + } + + public void setId(final int id) { _id = id; } + public int getId() { return _id; } + + public void setValue1(final String value) { _value = value; } + public String getValue1() { return _value; } + + public String toString() { + return _id + " / " + _value; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/NQEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/NQEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/NQEntity.java (revision 0) @@ -0,0 +1,34 @@ +package org.castor.cpa.test.test30; + +public final class NQEntity { + private Integer _id; + private String _name; + + public NQEntity(){ + } + + public NQEntity(Integer id){ + _id = id; + } + + public NQEntity(Integer id, String name){ + _id = id; + _name = name; + } + + public Integer getId() { + return _id; + } + + public void setId(final Integer id) { + _id = id; + } + + public String getName() { + return _name; + } + + public void setName(final String name) { + _name = name; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/PersistentEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/PersistentEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/PersistentEntity.java (revision 0) @@ -0,0 +1,244 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +import java.io.Serializable; +import java.util.Date; +import java.util.Enumeration; +import java.util.Vector; + +import org.exolab.castor.jdo.Database; +import org.exolab.castor.jdo.Persistent; +import org.exolab.castor.jdo.Query; +import org.exolab.castor.jdo.QueryResults; +import org.exolab.castor.jdo.TimeStampable; +import org.exolab.castor.mapping.AccessMode; + +public class PersistentEntity implements Persistent, TimeStampable, Serializable { + /** SerialVersionUID */ + private static final long serialVersionUID = 861059599755591225L; + + public static final int DEFAULT_ID = 7; + public static final String DEFAULT_VALUE = "persistent"; + + private int _id; + private String _value; + private Date _creationTime; + private Date _modificationTime; + private Integer _parentId; + private PersistentEntity _parent; + private Vector _children; + private Vector _origChildren; + private GroupEntity _group; + private RelatedEntity _related; + private RelatedEntity _origRelated; + + private transient Database _db; + private long _timeStamp; + + public PersistentEntity() { + this(DEFAULT_ID); + } + + public PersistentEntity(final int id) { + _id = id; + _value = DEFAULT_VALUE; + _children = new Vector(); + } + + public final void setId(final int id) { _id = id; } + public final int getId() { return _id; } + + public final void setParentId(final Integer parentId) { _parentId = parentId; } + public final Integer getParentId() { return _parentId; } + + public final void setValue1(final String value) { _value = value; } + public final String getValue1() { return _value; } + + public final void setCreationTime(final Date creationTime) { + _creationTime = creationTime; + } + public final Date getCreationTime() { return _creationTime; } + + public final void setModificationTime(final Date modificationTime) { + _modificationTime = modificationTime; + } + public final Date getModificationTime() { return _modificationTime; } + + public final void setParent(final PersistentEntity parent) { + _parent = parent; + _parentId = (_parent == null) ? null : new Integer(_parent._id); + } + public final PersistentEntity getParent() { return _parent; } + + public final void addChild(final PersistentEntity child) { + _children.addElement(child); + child.setParent(this); + child.setGroup(_group); + } + public final Vector getChildren() { return _children; } + public final PersistentEntity findChild(final int id) { + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + PersistentEntity child = (PersistentEntity) en.nextElement(); + if (child.getId() == id) { return child; } + } + return null; + } + + public final void setGroup(final GroupEntity group) { + if (_group == group) { return; } + _group = group; + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + PersistentEntity child = (PersistentEntity) en.nextElement(); + child.setGroup(_group); + } + } + public final GroupEntity getGroup() { return _group; } + + public final void setRelated(final RelatedEntity related) { + _related = related; + if (related != null) { related.setPersistent(this); } + } + public final RelatedEntity getRelated() { return _related; } + + public final void jdoPersistent(final Database db) { _db = db; } + public final void jdoTransient() { _db = null; } + public final Class jdoLoad(final AccessMode accessMode) throws Exception { + if (_parentId != null) { + _parent = (PersistentEntity) _db.load( + PersistentEntity.class, _parentId, accessMode); + } + + Query qry = _db.getOQLQuery("SELECT p FROM " + PersistentEntity.class.getName() + + " p WHERE parentId=$1"); + qry.bind(_id); + QueryResults res = qry.execute(); + while (res.hasMore()) { _children.addElement(res.next()); } + _origChildren = (Vector) _children.clone(); + _origRelated = _related; + return null; + } + public final void jdoStore(final boolean modified) throws Exception { + if (modified) { _modificationTime = new Date(); } + + PersistentEntity child; + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + child = (PersistentEntity) en.nextElement(); + if (!vectorContainsChild(_origChildren, child)) { + _db.create(child); + } + } + for (Enumeration en = _origChildren.elements(); en.hasMoreElements();) { + child = (PersistentEntity) en.nextElement(); + if (!vectorContainsChild(_children, child)) { + _db.remove(child); + } + } + if ((_origRelated == null) && (_related != null)) { + _db.create(_related); + } + if ((_origRelated != null) && (_related == null)) { + _db.remove(_origRelated); + } + _origRelated = _related; + } + public final void jdoUpdate() throws Exception { + for (Enumeration en = _origChildren.elements(); en.hasMoreElements();) { + _db.update(en.nextElement()); + } + if (_origRelated != null) { + _db.update(_origRelated); + } + } + public final void jdoBeforeCreate(final Database db) throws Exception { + if (_group == null) { + throw new Exception("Incorrect object state: group is not set in " + this); + } + Object grp; + try { + grp = db.load(GroupEntity.class, new Integer(_group.getId())); + } catch (Exception ex) { + grp = null; + } + if (grp == null) { db.create(_group); } + _creationTime = new Date(); + } + public final void jdoAfterCreate() throws Exception { + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + _db.create(en.nextElement()); + } + _origChildren = (Vector) _children.clone(); + if (_related != null) { _db.create(_related); } + _origRelated = _related; + } + public final void jdoBeforeRemove() throws Exception { + for (Enumeration en = _children.elements(); en.hasMoreElements();) { + _db.remove(en.nextElement()); + } + if (_related != null) { _db.remove(_related); } + } + public final void jdoAfterRemove() throws Exception { } + public final long jdoGetTimeStamp() { return _timeStamp; } + + public final void jdoSetTimeStamp(final long timeStamp) { _timeStamp = timeStamp; } + + private boolean vectorContainsChild(final Vector v, final PersistentEntity child) { + for (Enumeration en = v.elements(); en.hasMoreElements();) { + PersistentEntity ch = (PersistentEntity) en.nextElement(); + if (ch.getId() == child.getId()) { return true; } + } + return false; + } + + public String toString() { + String children = ""; + + for (int i = 0; i < _children.size(); ++i) { + if (i > 0) { children = children + ", "; } + children = children + _children.elementAt(i).toString(); + } + return _id + " / " + _value + " / " + _modificationTime + " (" + + _parentId + ":" + ((_group != null) ? new Integer(_group.getId()) : null) + + ") { " + children + " }"; + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/RelatedEntity.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/RelatedEntity.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/RelatedEntity.java (revision 0) @@ -0,0 +1,74 @@ +/** + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Intalio, Inc. For written permission, + * please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" + * nor may "Exolab" appear in their names without prior written + * permission of Intalio, Inc. Exolab is a registered + * trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project + * (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. + */ +package org.castor.cpa.test.test30; + +import org.exolab.castor.jdo.TimeStampable; + +public final class RelatedEntity implements TimeStampable, java.io.Serializable { + /** SerialVersionUID */ + private static final long serialVersionUID = -6408619974569022386L; + + public static final int DEFAULT_ID = 5; + + private int _id; + private PersistentEntity _persistent; + private long _timeStamp; + + public RelatedEntity() { this(DEFAULT_ID); } + public RelatedEntity(final int id) { _id = id; } + + public void setId(final int id) { _id = id; } + public int getId() { return _id; } + + public void setPersistent(final PersistentEntity persistent) { + _persistent = persistent; + } + public PersistentEntity getPersistent() { return _persistent; } + + public long jdoGetTimeStamp() { return _timeStamp; } + public void jdoSetTimeStamp(final long timeStamp) { _timeStamp = timeStamp; } + + public String toString() { + return _id + " / " + ((_persistent == null) ? 0 : _persistent.getId()); + } +} Index: cpactf/src/test/java/org/castor/cpa/test/test30/Test30.java =================================================================== --- cpactf/src/test/java/org/castor/cpa/test/test30/Test30.java (revision 0) +++ cpactf/src/test/java/org/castor/cpa/test/test30/Test30.java (revision 0) @@ -0,0 +1,461 @@ +package org.castor.cpa.test.test30; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.Statement; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.castor.cpa.test.framework.CPATestCase; +import org.castor.cpa.test.framework.xml.types.DatabaseEngineType; +import org.exolab.castor.jdo.Database; +import org.exolab.castor.jdo.OQLQuery; +import org.exolab.castor.jdo.PersistenceException; +import org.exolab.castor.jdo.QueryResults; + + +public final class Test30 extends CPATestCase { + private static final Log LOG = LogFactory.getLog(Test30.class); + + private static final String DBNAME = "test30"; + + private static final int MIN_ID = 10; + private static final int MAX_ID = 29; + private static final int MIN_EXTENDS_ID = 30; + private static final int MAX_EXTENDS_ID = 49; + private Database _db; + private OQLQuery query; + + public boolean include(final DatabaseEngineType engine) { + return (engine == DatabaseEngineType.MYSQL); + } + + public void setUp() throws Exception { + _db = getJDOManager(DBNAME).getDatabase(); + LOG.info("Test30 Started"); + } + + public void tearDown() throws PersistenceException { + if (_db.isActive()) { _db.rollback(); } + _db.close(); + LOG.info("Test30 complete"); + } + + public static Test suite() { + TestSuite suite = new TestSuite(Test30.class.getName()); + + suite.addTest(new Test30("populateDatabase")); + suite.addTest(new Test30("testBasicSelect1")); + suite.addTest(new Test30("testBasicSelect2")); + suite.addTest(new Test30("testBasicSelect3")); + suite.addTest(new Test30("testBasicSelect4")); + suite.addTest(new Test30("testBasicSelect5")); + suite.addTest(new Test30("testBasicSelect6")); + suite.addTest(new Test30("testBasicSelect7")); + suite.addTest(new Test30("testBasicSelect8")); + suite.addTest(new Test30("testBasicSelect9")); + suite.addTest(new Test30("testBasicSelect10")); + suite.addTest(new Test30("testBasicSelect11")); + suite.addTest(new Test30("testBasicSelect12")); + suite.addTest(new Test30("testBasicSelect13")); + suite.addTest(new Test30("testBasicSelect14")); + suite.addTest(new Test30("testBasicSelect15")); + suite.addTest(new Test30("testBasicSelect16")); + suite.addTest(new Test30("testBasicSelect17")); + suite.addTest(new Test30("testBasicSelect18")); + suite.addTest(new Test30("testBasicSelect19")); + suite.addTest(new Test30("testBasicSelect20")); + suite.addTest(new Test30("populateDatabaseExtends")); + suite.addTest(new Test30("testSelectCountFunc1")); + suite.addTest(new Test30("testSelectCountFunc2")); + suite.addTest(new Test30("testSelectCountFunc3")); + return suite; + } + public Test30(final String name) { + super(name); + } + + /***************************************************************** + * This method will truncate everything from the database and then + * repopulate it. It needs to be generic enough to work across databases + * so I would prefer to use straight JDBC calls. + *********************************************************************/ + public void populateDatabase() throws Exception { + _db.begin(); + Connection connection = _db.getJdbcConnection(); + Statement statement = connection.createStatement(); + statement.execute("delete from test30_extends"); + + connection = _db.getJdbcConnection(); + statement = connection.createStatement(); + statement.execute("delete from test30_entity"); + _db.commit(); + + _db.begin(); + for (int i = MIN_ID; i <= MAX_ID; ++i) { + Entity obj = new Entity(); + obj.setId(i); + obj.setValue1(Entity.DEFAULT_VALUE_1 + " " + Integer.toString(i)); + _db.create(obj); + } + _db.commit(); + + _db.begin(); + connection = _db.getJdbcConnection(); + statement = connection.createStatement(); + statement.execute("delete from test30_group"); + _db.commit(); + + _db.begin(); + GroupEntity group = new GroupEntity(); + _db.create(group); + _db.commit(); + } + + /* + * Test many different variations of the basic SELECT statement. + */ + public void testBasicSelect1() throws Exception { + _db.begin(); + // fetch all available data + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x"); + tryQuery(query, MAX_ID - MIN_ID + 1); + _db.commit(); + } + public void testBasicSelect2() throws Exception { + _db.begin(); +// query only one object, expecting one + assertTrue("internal error: MIN_ID<=15 && MAX_ID>=15", + (MIN_ID <= 15) && (MAX_ID >= 15)); + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=15"); + assertTrue("internal error", MIN_ID > 1); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect3() throws Exception { + _db.begin(); +// query only one object, expecting none + assertTrue("internal error: MIN_ID>1", MIN_ID > 1); + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=1"); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect4() throws Exception { + _db.begin(); + // query using bind variable parameter, find one object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=$1"); + query.bind(MIN_ID); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect5() throws Exception { + _db.begin(); +// query using bind variable parameter, find nothing + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id=$1"); + query.bind(MIN_ID - 1); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect6() throws Exception { + _db.begin(); +// query using comparison between bind variable parameter and constant, + // find all objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where $(int)1 = 1000"); + query.bind(1000); + tryQuery(query, MAX_ID + 1 - MIN_ID); + _db.commit(); + } + public void testBasicSelect7() throws Exception { + _db.begin(); +// query using comparison between bind variable parameter and constant, + // find no objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where $(int)1 = 1000"); + query.bind(2000); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect8() throws Exception { + _db.begin(); +// query using 1 bind variable parameters in two places + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id>$1 and id<$2"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID - 2); + _db.commit(); + } + public void testBasicSelect9() throws Exception { + _db.begin(); +// query using 1 bind variable parameter, find all but the first and last object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id>$1 and id<$2"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID - 2); + _db.commit(); + } + public void testBasicSelect10() throws Exception { + _db.begin(); +// query using 2 bind variable parameters, find all but the first and last object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + " x where id<$2 and id>$1"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID - 2); + _db.commit(); + } + public void testBasicSelect11() throws Exception { + _db.begin(); +// query using "BETWEEN" operator, finding all records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id between $1 and $2"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, MAX_ID + 1 - MIN_ID); + _db.commit(); + } + public void testBasicSelect12() throws Exception { + _db.begin(); +// query using "BETWEEN" operator, finding no records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id between $2 and $1"); + query.bind(MIN_ID); + query.bind(MAX_ID); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect13() throws Exception { + _db.begin(); +// query using string constants containing a question mark in the WHERE clause, + // finding all records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where \"abc123?äöü\" = \"abc123?äöü\""); + tryQuery(query, MAX_ID + 1 - MIN_ID); + _db.commit(); + } + public void testBasicSelect14() throws Exception { + _db.begin(); +// query using string constants containing a question mark in the WHERE clause, + // finding no records + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where \"abc\" = \"?123\""); + tryQuery(query, 0); + _db.commit(); + } + public void testBasicSelect15() throws Exception { + _db.begin(); +// query using "IN" operator + assertTrue("internal error: MIN_ID<=15 && MAX_ID>=18", + (MIN_ID <= 15) && (MAX_ID >= 15)); + assertTrue("internal error: MIN_ID>5", MIN_ID > 5); + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id in list(5, 15, 18)"); + tryQuery(query, 2); + _db.commit(); + } + public void testBasicSelect16() throws Exception { + _db.begin(); + // query using "IN" operator and bind variables, find all objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id in list($1, $2, $3)"); + query.bind(MIN_ID); + query.bind((MIN_ID + MAX_ID) / 2); + query.bind(MAX_ID); + tryQuery(query, 3); + _db.commit(); + } + public void testBasicSelect17() throws Exception { + _db.begin(); +// query using "IN" operator and bind variables, find some objects + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where id in list($1, $2)"); + query.bind(MIN_ID); + query.bind(MAX_ID + 5); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect18() throws Exception { + _db.begin(); +// query using "IN" operator and string values, find one object + query = _db.getOQLQuery( + "select x from " + Entity.class.getName() + + " x where value1 in list(\"XXX\", \"one 21\", 'A')"); + tryQuery(query, 1); + _db.commit(); + } + public void testBasicSelect19() throws Exception { + _db.begin(); + query = _db.getOQLQuery( + "CALL SQL " + + "select id, value1 " + + "from test30_group entity " + + "where entity.id >= $1 and entity.id <= $1 " + + " AS " + GroupEntity.class.getName()); + query.bind(GroupEntity.DEFAULT_ID); + QueryResults res = query.execute(); + + assertTrue(res.hasMore()); + GroupEntity obj = (GroupEntity) res.next(); + assertEquals(GroupEntity.DEFAULT_ID, obj.getId()); + assertEquals(GroupEntity.DEFAULT_VALUE, obj.getValue1()); + + assertFalse (res.hasMore()); + + _db.commit(); + } + public void testBasicSelect20() throws Exception { + _db.begin(); + query = _db.getOQLQuery( + "CALL SQL " + + "select id, value1 " + + "from test30_group entity " + + "where entity.id >= $1 and entity.id <= $1 and " + + "entity.value1 = $2 " + + " AS " + GroupEntity.class.getName()); + query.bind(GroupEntity.DEFAULT_ID); + query.bind(GroupEntity.DEFAULT_VALUE); + QueryResults res = query.execute(); + + assertTrue(res.hasMore()); + GroupEntity obj = (GroupEntity) res.next(); + assertEquals(GroupEntity.DEFAULT_ID, obj.getId()); + assertEquals(GroupEntity.DEFAULT_VALUE, obj.getValue1()); + + assertFalse (res.hasMore()); + + _db.commit(); + } + + public void populateDatabaseExtends() throws Exception { + _db.begin(); + Connection connection = _db.getJdbcConnection(); + Statement statement = connection.createStatement(); + statement.execute("delete from test30_extends"); + + connection = _db.getJdbcConnection(); + statement = connection.createStatement(); + statement.execute("delete from test30_entity"); + _db.commit(); + + _db.begin(); + for (int i = MIN_ID; i <= MAX_ID; ++i) { + Entity obj = new Entity(); + obj.setId(i); + obj.setValue1(Entity.DEFAULT_VALUE_1 + " " + Integer.toString(i)); + _db.create(obj); + } + _db.commit(); + + _db.begin(); + for (int i = MIN_EXTENDS_ID; i <= MAX_EXTENDS_ID; ++i) { + ExtendsEntity ext = new ExtendsEntity(); + ext.setId(i); + ext.setValue1(Entity.DEFAULT_VALUE_1 + " " + Integer.toString(i)); + _db.create(ext); + } + _db.commit(); + + } + + /* + * Test SQL functions (e.g. count(), max(), first(), last(), avg(), etc.). + */ + public void testSelectCountFunc1() throws Exception { + _db.begin(); + + // obtain number of TestObject instances + OQLQuery query = _db.getOQLQuery( + "SELECT count(x.id) FROM " + Entity.class.getName() + " x"); + tryFunctionQuery(query, 40); + _db.commit(); + } + public void testSelectCountFunc2() throws Exception { + _db.begin(); + + // obtain distinct number of TestObject instances + query = _db.getOQLQuery( + "SELECT count(distinct x.id) FROM " + Entity.class.getName() + " x"); + tryFunctionQuery(query, 40); + _db.commit(); + } + public void testSelectCountFunc3() throws Exception { + _db.begin(); + + // obtain number of TestObjectExtends instances + query = _db.getOQLQuery( + "SELECT count(x.id) FROM " + ExtendsEntity.class.getName() + " x"); + tryFunctionQuery(query, 20); + _db.commit(); + } + + + + + + /* + * test received result set + */ + public void tryQuery(final OQLQuery query, final int countExpected) + throws PersistenceException { + QueryResults res = query.execute(); + int count = 0; + + try { + while (res.hasMore()) { + Entity obj = (Entity) res.next(); + + String val = Entity.DEFAULT_VALUE_1 + " " + Integer.toString(obj.getId()); + assertEquals("value1", val, obj.getValue1()); + assertEquals("value2", Entity.DEFAULT_VALUE_2, obj.getValue2()); + + ++count; + } + } finally { + res.close(); + } + + assertEquals("number of objects found", countExpected, count); + } + /* + * test received result set + */ + public void tryFunctionQuery(final OQLQuery query, final int countExpected) + throws PersistenceException { + QueryResults res = query.execute(); + long functionValue = 0; + + try { + if (res.hasMore()) { + Object obj = res.next(); + if (obj instanceof Long) { + functionValue = ((Long) obj).longValue(); + } else if (obj instanceof BigDecimal) { + functionValue = ((BigDecimal) obj).longValue(); + } else if (obj instanceof Integer) { + functionValue = ((Integer) obj).longValue(); + } + } + } finally { + res.close(); + } + assertEquals("number of objects found", countExpected, functionValue); + } + +} Index: cpactf/src/test/resources/cpactf-conf.xml =================================================================== --- cpactf/src/test/resources/cpactf-conf.xml (revision 7588) +++ cpactf/src/test/resources/cpactf-conf.xml (working copy) @@ -1,51 +1,57 @@ - - Mapping configuration for test356 - - - - - Mapping configuration for test881 - - - - - Mapping configuration for test954 - - - - - Mapping configuration for test972 - - - - - Mapping configuration for test1002 - - - - - Mapping configuration for test1158 - - - - - Mapping configuration for test1355 - - - - - Mapping configuration for test1379 - - - - - Mapping configuration for test2177 - - - + + + Mapping configuration for test30 + + + + + Mapping configuration for test356 + + + + Mapping configuration for test881 + + + + Mapping configuration for test954 + + + + + Mapping configuration for test972 + + + + + Mapping configuration for test1002 + + + + + Mapping configuration for test1158 + + + + + Mapping configuration for test1355 + + + + + Mapping configuration for test1379 + + + + + Mapping configuration for test2177 + + + + + Database configuration for DB2 - - Database configuration for MySQL - - - - - - - + + Database configuration for MySQL + + + + + + + Database configuration for MySQL @@ -148,7 +154,7 @@ - + Database configuration for Progress Index: cpactf/src/test/resources/org/castor/cpa/test/test30/mapping.xml =================================================================== --- cpactf/src/test/resources/org/castor/cpa/test/test30/mapping.xml (revision 0) +++ cpactf/src/test/resources/org/castor/cpa/test/test30/mapping.xml (revision 0) @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Named query entity + + + SELECT e FROM org.castor.cpa.test.test30.NQEntity e + + + SELECT e FROM EntityTwo entity + + + SELECT e FROM org.castor.cpa.test.test30.NQEntity e WHERE e.id=$1 + + + SELECT e FROM org.castor.cpa.test.test30.NQEntity e + + + + + + + + + + Index: cpactf/src/test/resources/org/castor/cpa/test/test30/mapping.xml =================================================================== --- cpactf/src/test/resources/org/castor/cpa/test/test30/mapping.xml (revision 0) +++ cpactf/src/test/resources/org/castor/cpa/test/test30/mapping.xml (revision 0) @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Named query entity + + + SELECT e FROM org.castor.cpa.test.test30.NQEntity e + + + SELECT e FROM EntityTwo entity + + + SELECT e FROM org.castor.cpa.test.test30.NQEntity e WHERE e.id=$1 + + + SELECT e FROM org.castor.cpa.test.test30.NQEntity e + + + + + + + + + +