You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/07/27 23:39:21 UTC
cvs commit: db-ojb/src/test/org/apache/ojb repository_junit_meta_seq.xml
arminw 2004/07/27 14:39:21
Modified: src/test/org/apache/ojb/broker/sequence
NativeIdentifierTest.java
src/test/org/apache/ojb repository_junit_meta_seq.xml
Log:
add new test case to show problems with FK assignment
in ODMG-api implementation (OTM too?) with Identity column
supporting sequence manager
Revision Changes Path
1.11 +420 -65 db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java
Index: NativeIdentifierTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- NativeIdentifierTest.java 11 May 2004 11:55:57 -0000 1.10
+++ NativeIdentifierTest.java 27 Jul 2004 21:39:20 -0000 1.11
@@ -1,33 +1,35 @@
package org.apache.ojb.broker.sequence;
-import junit.framework.TestCase;
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerFactory;
import org.apache.ojb.broker.TestHelper;
+import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.MetadataManager;
+import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
import org.apache.ojb.broker.metadata.SequenceDescriptor;
+import org.apache.ojb.broker.platforms.Platform;
import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
import org.apache.ojb.broker.platforms.PlatformMySQLImpl;
-import org.apache.ojb.broker.platforms.Platform;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.QueryByCriteria;
import org.apache.ojb.broker.query.QueryFactory;
import org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl;
+import org.apache.ojb.junit.PBTestCase;
import org.apache.ojb.odmg.OJB;
-import org.odmg.Implementation;
import org.odmg.Database;
+import org.odmg.Implementation;
import org.odmg.Transaction;
-import java.io.Serializable;
-import java.sql.Connection;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Collection;
-
/**
* Test case for {@link SequenceManagerNativeImpl}. These test check
* support for native identity columns. Test case only works for
@@ -36,7 +38,7 @@
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id$
*/
-public class NativeIdentifierTest extends TestCase
+public class NativeIdentifierTest extends PBTestCase
{
// Statements for MainObject table
private static final String DROP = "DROP TABLE NATIVE_MAIN_OBJECT";
@@ -59,8 +61,6 @@
private static final String DROP_REF = "DROP TABLE NATIVE_REFERENCE_OBJECT";
private static final String INSERT_DUMMY_REF = "INSERT INTO NATIVE_REFERENCE_OBJECT (NAME) VALUES ('Dummy_2')";
-
- private PersistenceBroker broker;
private Platform platform;
private Class oldSequenceManager;
@@ -81,20 +81,19 @@
return skip;
}
- protected void setUp() throws Exception
+ public void setUp() throws Exception
{
super.setUp();
-
- PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
- platform = pb.serviceConnectionManager().getSupportedPlatform();
+ platform = broker.serviceConnectionManager().getSupportedPlatform();
if (skipTest()) return;
+
+
Connection con;
Statement stmt;
-
try
{
- con = pb.serviceConnectionManager().getConnection();
+ con = broker.serviceConnectionManager().getConnection();
stmt = con.createStatement();
if(platform instanceof PlatformMySQLImpl)
{
@@ -126,34 +125,25 @@
stmt.close();
SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
- getDescriptor(pb.getPBKey()).getSequenceDescriptor();
+ getDescriptor(broker.getPBKey()).getSequenceDescriptor();
oldSequenceManager = sd.getSequenceManagerClass();
sd.setSequenceManagerClass(SequenceManagerNativeImpl.class);
}
finally
{
- if (pb != null) pb.close();
+ if (broker != null) broker.close();
}
PersistenceBrokerFactory.releaseAllInstances();
-
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
getDescriptor(broker.getPBKey()).getSequenceDescriptor();
assertEquals(SequenceManagerNativeImpl.class, sd.getSequenceManagerClass());
}
- protected void tearDown() throws Exception
+ public void tearDown() throws Exception
{
super.tearDown();
-
- try
- {
- broker.close();
- }
- catch (Exception e)
- {
- }
if (skipTest()) return;
Connection con;
@@ -184,16 +174,41 @@
SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
getDescriptor(broker.getPBKey()).getSequenceDescriptor();
assertEquals(oldSequenceManager, sd.getSequenceManagerClass());
+
+ changeAutoSetting(MainObject.class, "singleReference", true, false, false, false);
+ changeAutoSetting(MainObject.class, "allReferences", true, false, false, false);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, false, false, false);
+ changeAutoSetting(SingleReference.class, "mainObject", true, false, false, false);
broker.close();
}
- public void testSimpleInsert() throws Exception
+ public void testSimpleInsert_1() throws Exception
{
- long timestamp = (long) (System.currentTimeMillis() * Math.random());
- String name = "testSimpleInsert_" + timestamp;
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, false);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
+ doTtestSimpleInsert();
+ }
+
+ public void testSimpleInsert_2() throws Exception
+ {
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, true);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
+ doTtestSimpleInsert();
+ }
+ public void doTtestSimpleInsert() throws Exception
+ {
if (skipTest()) return;
+ long timestamp = System.currentTimeMillis();
+ String name = "testSimpleInsert_" + timestamp;
+
MainObject obj_1 = new MainObject(null, name);
MainObject obj_2 = new MainObject(null, name);
MainObject obj_3 = new MainObject(null, name);
@@ -213,15 +228,32 @@
int result = broker.getCount(query);
assertEquals("Not all objects created", 3, result);
assertNotNull(obj_1.getIdentifier());
+ assertTrue(obj_1.getIdentifier().longValue() > 0);
+ assertTrue(obj_3.getIdentifier().longValue() > 0);
}
- public void testSimpleInsertODMG() throws Exception
+ public void testSimpleInsertODMG_1() throws Exception
{
- long timestamp = (long) (System.currentTimeMillis() * Math.random());
- String name = "testSimpleInsert_" + timestamp;
+ changeAutoSetting(MainObject.class, "singleReference", true, false, false, false);
+ changeAutoSetting(MainObject.class, "allReferences", true, false, false, false);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, false, false, false);
+ changeAutoSetting(SingleReference.class, "mainObject", true, false, false, false);
+ }
+ public void testSimpleInsertODMG_2() throws Exception
+ {
+ changeAutoSetting(MainObject.class, "singleReference", true, false, false, true);
+ changeAutoSetting(MainObject.class, "allReferences", true, false, false, true);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, false, false, true);
+ changeAutoSetting(SingleReference.class, "mainObject", true, false, false, true);
+ }
+ public void doTestSimpleInsertODMG() throws Exception
+ {
if (skipTest()) return;
+ long timestamp = System.currentTimeMillis();
+ String name = "testSimpleInsert_" + timestamp;
+
MainObject obj_1 = new MainObject(null, name);
MainObject obj_2 = new MainObject(null, name);
MainObject obj_3 = new MainObject(null, name);
@@ -243,20 +275,34 @@
int result = broker.getCount(query);
assertEquals("Not all objects created", 3, result);
assertNotNull(obj_1.getIdentifier());
+ assertTrue(obj_1.getIdentifier().longValue() > 0);
+ assertTrue(obj_3.getIdentifier().longValue() > 0);
+ }
+
+ public void testReferenceInsertUpdate_1() throws Exception
+ {
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, false);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
+ doTestReferenceInsertUpdate();
}
- public void testAllInOne() throws Exception
+ public void testReferenceInsertUpdate_2() throws Exception
{
- testSimpleInsert();
- testSimpleInsert();
- testReferenceInsertUpdate();
- testReferenceInsertUpdate();
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, true);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
+ doTestReferenceInsertUpdate();
}
- public void testReferenceInsertUpdate() throws Exception
+ public void doTestReferenceInsertUpdate() throws Exception
{
if (skipTest()) return;
- long timestamp = (long) (System.currentTimeMillis() * Math.random());
+ long timestamp = System.currentTimeMillis();
String name = "testReferenceInsert_main_" + timestamp;
String nameRef = "testReferenceInsert_reference_" + timestamp;
String nameSingleRef = "testReferenceInsert_single_reference_" + timestamp;
@@ -312,6 +358,8 @@
assertNotSame(obj_1.getIdentifier(), obj_2.getIdentifier());
assertTrue(obj_1.getIdentifier().longValue() > 0);
assertTrue(obj_2.getIdentifier().longValue() > 0);
+ assertTrue(s_ref_3.getId().longValue() > 0);
+ assertTrue(ref_3.getRefIdentifier().longValue() > 0);
// get Identity objects
Identity oid_1 = new Identity(obj_1, broker);
@@ -427,10 +475,220 @@
assertEquals(id_2, obj_2.getIdentifier());
}
- public void testDelete() throws Exception
+ public void testReferenceInsertUpdateODMG() throws Exception
{
if (skipTest()) return;
- long timestamp = (long) (System.currentTimeMillis() * Math.random());
+
+ // prepare metadata for odmg-api
+ changeAutoSetting(MainObject.class, "singleReference", true, false, false, false);
+ changeAutoSetting(MainObject.class, "allReferences", true, false, false, false);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, false, false, false);
+ changeAutoSetting(SingleReference.class, "mainObject", true, false, false, false);
+
+ long timestamp = System.currentTimeMillis();
+ String name = "testReferenceInsert_main_" + timestamp;
+ String nameRef = "testReferenceInsert_reference_" + timestamp;
+ String nameSingleRef = "testReferenceInsert_single_reference_" + timestamp;
+
+ MainObject obj_1 = new MainObject(null, name);
+ MainObject obj_2 = new MainObject(null, name);
+
+ SingleReference s_ref_1 = new SingleReference(nameSingleRef);
+ SingleReference s_ref_2 = new SingleReference(nameSingleRef);
+
+ CollectionReference ref_1 = new CollectionReference(null, nameRef);
+ CollectionReference ref_2 = new CollectionReference(null, nameRef);
+ CollectionReference ref_3 = new CollectionReference(null, nameRef);
+ CollectionReference ref_4 = new CollectionReference(null, nameRef);
+ ref_1.setSingleReference(s_ref_1);
+ ref_4.setSingleReference(s_ref_2);
+
+ SingleReference s_ref_3 = new SingleReference(nameSingleRef);
+ SingleReference s_ref_4 = new SingleReference(nameSingleRef);
+
+ obj_1.addReference(ref_1);
+ obj_1.addReference(ref_2);
+ obj_1.addReference(ref_3);
+ obj_1.addReference(ref_4);
+
+ obj_1.setSingleReference(s_ref_3);
+ s_ref_3.setMainObject(obj_1);
+ obj_2.setSingleReference(s_ref_4);
+ s_ref_3.setMainObject(obj_1);
+
+ Implementation odmg = OJB.getInstance();
+ Database db = odmg.newDatabase();
+ db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
+
+ Transaction tx = odmg.newTransaction();
+ tx.begin();
+ //db.makePersistent(ref_1);
+ db.makePersistent(obj_1);
+ db.makePersistent(obj_2);
+ tx.commit();
+
+ // try to find both objects
+ Criteria crit = new Criteria();
+ crit.addEqualTo("name", name);
+ QueryByCriteria query = QueryFactory.newQuery(MainObject.class, crit);
+ int result = broker.getCount(query);
+ assertEquals("Wrong object count", 2, result);
+
+ // pk have to set and have to be different
+ assertNotNull(obj_1.getIdentifier());
+ assertNotNull(obj_2.getIdentifier());
+ assertNotSame(obj_1.getIdentifier(), obj_2.getIdentifier());
+ assertTrue(obj_1.getIdentifier().longValue() > 0);
+ assertTrue(obj_2.getIdentifier().longValue() > 0);
+ assertTrue(s_ref_3.getId().longValue() > 0);
+ assertTrue(ref_3.getRefIdentifier().longValue() > 0);
+ // check anonymous FK setting
+ Long fk = (Long) broker.getClassDescriptor(MainObject.class)
+ .getFieldDescriptorByName("refFK")
+ .getPersistentField().get(obj_1);
+ assertTrue("The assigned FK should be > 0 after store of main object, but was " + fk.longValue(), fk.longValue() > 0);
+
+ // get Identity objects
+ Identity oid_1 = new Identity(obj_1, broker);
+ Identity oid_2 = new Identity(obj_2, broker);
+ // get identifier (PK) values
+ Long id_1 = obj_1.getIdentifier();
+ Long id_2 = obj_2.getIdentifier();
+
+ broker.clearCache();
+
+ // get object with references
+ obj_1 = (MainObject) broker.getObjectByIdentity(oid_1);
+ assertNotNull(obj_1);
+ List references = obj_1.getAllReferences();
+ assertNotNull(references);
+ assertEquals("4 references expected for object: "+obj_1, 4, references.size());
+ Iterator it = references.iterator();
+ while (it.hasNext())
+ {
+ CollectionReference ref = (CollectionReference) it.next();
+ assertEquals("Main object fk expected", obj_1.getIdentifier(), ref.fkIdentifier);
+ assertTrue("We expect a positive value, identity columns have to start > 0",
+ (ref.getRefIdentifier().longValue() > 0));
+ }
+ assertNotNull(obj_1.getSingleReference());
+ obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
+ assertTrue(obj_1.getIdentifier().longValue() > 0);
+ assertTrue(obj_2.getIdentifier().longValue() > 0);
+ assertNotNull(obj_2.getSingleReference());
+ assertTrue(obj_2.getSingleReference().getId().longValue() > 0);
+ assertTrue(obj_1.getSingleReference().getId().longValue() > 0);
+ assertNotSame(obj_1.getSingleReference(), obj_2.getSingleReference());
+ broker.clearCache();
+
+ // get references only
+ Criteria crit_2 = new Criteria();
+ crit_2.addEqualTo("refName", nameRef);
+ QueryByCriteria query_2 = QueryFactory.newQuery(CollectionReference.class, crit_2);
+ int result_2 = broker.getCount(query_2);
+ assertEquals("Not all objects created", 4, result_2);
+ assertNotNull(ref_3.getRefIdentifier());
+
+ broker.clearCache();
+
+ // get second object
+ MainObject retObj = (MainObject) broker.getObjectByIdentity(oid_2);
+ List refList = retObj.getAllReferences();
+ assertNotNull(refList);
+ assertEquals("object do not have references", 0, refList.size());
+
+ // add new reference to object
+ CollectionReference ref_5 = new CollectionReference(null, nameRef);
+ CollectionReference ref_6 = new CollectionReference(null, nameRef);
+ obj_1.addReference(ref_5);
+ obj_2.addReference(ref_6);
+ broker.beginTransaction();
+ broker.store(obj_1);
+ broker.store(obj_2);
+ broker.commitTransaction();
+ assertNotNull(ref_5.getRefIdentifier());
+ assertNotNull(ref_6.getRefIdentifier());
+ assertEquals(id_1, obj_1.getIdentifier());
+ assertEquals(id_2, obj_2.getIdentifier());
+
+ obj_1 = (MainObject) broker.getObjectByIdentity(oid_1);
+ assertNotNull(obj_1);
+ references = obj_1.getAllReferences();
+ assertNotNull(references);
+ assertEquals("5 references expected for object: "+obj_1, 5, references.size());
+
+ obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
+ assertNotNull(obj_2);
+ references = obj_2.getAllReferences();
+ assertNotNull(references);
+ assertEquals("1 references expected for object: "+obj_2, 1, references.size());
+
+ assertEquals(id_1, obj_1.getIdentifier());
+ assertEquals(id_2, obj_2.getIdentifier());
+
+ // now update main objects
+ tx.begin();
+ tx.lock(obj_1, Transaction.WRITE);
+ tx.lock(obj_2, Transaction.WRITE);
+ obj_1.setName(name+"_update");
+ obj_2.setName(name+"_update");
+ tx.commit();
+
+ obj_1 = (MainObject) broker.getObjectByIdentity(oid_1);
+ obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
+
+ assertNotNull(obj_1);
+ assertNotNull(obj_2);
+ assertEquals(obj_1.getName(), name+"_update");
+ assertEquals(obj_2.getName(), name+"_update");
+ assertEquals(id_1, obj_1.getIdentifier());
+ assertEquals(id_2, obj_2.getIdentifier());
+
+ // now update reference
+ obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
+ assertNotNull(obj_2);
+ tx.begin();
+ tx.lock(obj_2, Transaction.WRITE);
+ references = obj_2.getAllReferences();
+ CollectionReference ref = (CollectionReference) references.get(0);
+ tx.lock(ref, Transaction.WRITE);
+ ref.setRefName(nameRef+"_update");
+ tx.commit();
+
+ obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
+ assertNotNull(obj_2);
+ references = obj_2.getAllReferences();
+ ref = (CollectionReference) references.get(0);
+ assertEquals(nameRef+"_update", ref.getRefName());
+ assertEquals(id_1, obj_1.getIdentifier());
+ assertEquals(id_2, obj_2.getIdentifier());
+ }
+
+ public void testDelete_1() throws Exception
+ {
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, false);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
+ doTestDelete();
+ }
+
+ public void testDelete_2() throws Exception
+ {
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, true);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
+ doTestDelete();
+ }
+
+ public void doTestDelete() throws Exception
+ {
+ if (skipTest()) return;
+
+ long timestamp = System.currentTimeMillis();
String name = "testDelete_main_" + timestamp;
String nameRef = "testDelete_reference_" + timestamp;
@@ -467,12 +725,32 @@
assertEquals(0, result_2);
}
- public void testDelete_2() throws Exception
+ public void testDeleteTwo_1() throws Exception
+ {
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, false);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, false);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, false);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, false);
+ doTestDeleteTwo();
+ }
+
+ public void testDeleteTwo_2() throws Exception
+ {
+ // prepare for PB-api test
+ changeAutoSetting(MainObject.class, "singleReference", true, true, true, true);
+ changeAutoSetting(MainObject.class, "allReferences", true, true, true, true);
+ changeAutoSetting(CollectionReference.class, "singleReference", true, true, true, true);
+ changeAutoSetting(SingleReference.class, "mainObject", true, true, true, true);
+ doTestDeleteTwo();
+ }
+
+ public void doTestDeleteTwo() throws Exception
{
if (skipTest()) return;
- long timestamp = (long) (System.currentTimeMillis() * Math.random());
- String name = "testDelete_2_main_" + timestamp;
- String nameRef = "testDelete_2_reference_" + timestamp;
+ long timestamp = System.currentTimeMillis();
+ String name = "testDeleteTwo_main_" + timestamp;
+ String nameRef = "testDeleteTwo_reference_" + timestamp;
MainObject obj_1 = new MainObject(null, name);
@@ -528,19 +806,74 @@
crit_2.addEqualTo("refName", nameRef);
QueryByCriteria query_2 = QueryFactory.newQuery(CollectionReference.class, crit_2);
int result_2 = broker.getCount(query_2);
- // System.out.println("## result: "+broker.getCollectionByQuery(query_2));
assertEquals(0, result_2);
}
+// public void XXXtestAllInOne() throws Exception
+// {
+// // sleep thread to make timestamp based tests work
+// testSimpleInsert();
+// ojbSleep();
+// ojbSleep();
+// testSimpleInsert();
+// ojbSleep();
+// ojbSleep();
+// testReferenceInsertUpdate();
+// ojbSleep();
+// ojbSleep();
+// // testReferenceInsertUpdate_2();
+// ojbSleep();
+// ojbSleep();
+// testReferenceInsertUpdate();
+// }
+ void changeAutoSetting(Class clazz, String referenceField, boolean autoRetrieve, int autoUpdate, int autoDelete, boolean useProxy)
+ {
+ ClassDescriptor cld = broker.getClassDescriptor(clazz);
+ ObjectReferenceDescriptor ref = cld.getCollectionDescriptorByName(referenceField);
+ if(ref == null) ref = cld.getObjectReferenceDescriptorByName(referenceField);
+ ref.setLazy(useProxy);
+ ref.setCascadeRetrieve(autoRetrieve);
+ ref.setCascadingStore(autoUpdate);
+ ref.setCascadingDelete(autoDelete);
+ }
+
+ void changeAutoSetting(Class clazz, String referenceField, boolean autoRetrieve, boolean autoUpdate, boolean autoDelete, boolean useProxy)
+ {
+ ClassDescriptor cld = broker.getClassDescriptor(clazz);
+ ObjectReferenceDescriptor ref = cld.getCollectionDescriptorByName(referenceField);
+ if(ref == null) ref = cld.getObjectReferenceDescriptorByName(referenceField);
+ ref.setLazy(useProxy);
+ ref.setCascadeRetrieve(autoRetrieve);
+ ref.setCascadeStore(autoUpdate);
+ ref.setCascadeDelete(autoDelete);
+ }
+
+
+ //========================================================================
+ // inner classes, used for test
+ //========================================================================
+
+ public static interface MainObjectIF extends Serializable
+ {
+ public SingleReferenceIF getSingleReference();
+ public void setSingleReference(SingleReferenceIF singleReference);
+ public List getAllReferences();
+ public void addReference(CollectionReference reference);
+ public void setAllReferences(List allReferences);
+ public Long getIdentifier();
+ public void setIdentifier(Long identifier);
+ public String getName();
+ public void setName(String name);
+ }
- public static class MainObject implements Serializable
+ public static class MainObject implements MainObjectIF
{
private Long identifier;
private String name;
private List allReferences;
// we use anonymous field for FK
- private SingleReference singleReference;
+ private SingleReferenceIF singleReference;
public MainObject()
@@ -553,12 +886,12 @@
this.name = name;
}
- public SingleReference getSingleReference()
+ public SingleReferenceIF getSingleReference()
{
return singleReference;
}
- public void setSingleReference(SingleReference singleReference)
+ public void setSingleReference(SingleReferenceIF singleReference)
{
this.singleReference = singleReference;
}
@@ -608,11 +941,21 @@
}
}
- public static class SingleReference
+ public static interface SingleReferenceIF extends Serializable
+ {
+ public MainObjectIF getMainObject();
+ public void setMainObject(MainObjectIF mainObject);
+ public Long getId();
+ public void setId(Long id);
+ public String getName();
+ public void setName(String name);
+ }
+
+ public static class SingleReference implements SingleReferenceIF
{
Long id;
String name;
- MainObject mainObject;
+ MainObjectIF mainObject;
public SingleReference()
{
@@ -625,12 +968,12 @@
// id = new Long((long)(Math.random() * Integer.MAX_VALUE));
}
- public MainObject getMainObject()
+ public MainObjectIF getMainObject()
{
return mainObject;
}
- public void setMainObject(MainObject mainObject)
+ public void setMainObject(MainObjectIF mainObject)
{
this.mainObject = mainObject;
}
@@ -656,12 +999,24 @@
}
}
- public static class CollectionReference implements Serializable
+ public static interface CollectionReferenceIF extends Serializable
+ {
+ public Long getRefIdentifier();
+ public void setRefIdentifier(Long refIdentifier);
+ public SingleReferenceIF getSingleReference();
+ public void setSingleReference(SingleReferenceIF singleReference);
+ public Long getFkIdentifier();
+ public void setFkIdentifier(Long fkIdentifier);
+ public String getRefName();
+ public void setRefName(String refName);
+ }
+
+ public static class CollectionReference implements CollectionReferenceIF
{
private Long refIdentifier;
private String refName;
private Long fkIdentifier;
- private SingleReference singleReference;
+ private SingleReferenceIF singleReference;
public CollectionReference()
{
@@ -683,12 +1038,12 @@
this.refIdentifier = refIdentifier;
}
- public SingleReference getSingleReference()
+ public SingleReferenceIF getSingleReference()
{
return singleReference;
}
- public void setSingleReference(SingleReference singleReference)
+ public void setSingleReference(SingleReferenceIF singleReference)
{
this.singleReference = singleReference;
}
1.8 +10 -10 db-ojb/src/test/org/apache/ojb/repository_junit_meta_seq.xml
Index: repository_junit_meta_seq.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_meta_seq.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- repository_junit_meta_seq.xml 4 Jun 2004 16:02:44 -0000 1.7
+++ repository_junit_meta_seq.xml 27 Jul 2004 21:39:21 -0000 1.8
@@ -543,8 +543,8 @@
class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$SingleReference"
proxy="false"
auto-retrieve="true"
- auto-update="true"
- auto-delete="true">
+ auto-update="false"
+ auto-delete="false">
<foreignkey field-ref="refFK"/>
</reference-descriptor>
@@ -552,8 +552,8 @@
name="allReferences"
element-class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$CollectionReference"
auto-retrieve="true"
- auto-update="true"
- auto-delete="true"
+ auto-update="false"
+ auto-delete="false"
>
<orderby name="refIdentifier" sort="DESC"/>
<inverse-foreignkey field-ref="fkIdentifier"/>
@@ -600,8 +600,8 @@
class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$SingleReference"
proxy="false"
auto-retrieve="true"
- auto-update="true"
- auto-delete="true">
+ auto-update="false"
+ auto-delete="false">
<foreignkey field-ref="singleRefFK"/>
</reference-descriptor>
</class-descriptor>
@@ -639,9 +639,9 @@
name="mainObject"
class-ref="org.apache.ojb.broker.sequence.NativeIdentifierTest$MainObject"
proxy="false"
- auto-retrieve="false"
- auto-update="true"
- auto-delete="true">
+ auto-retrieve="true"
+ auto-update="false"
+ auto-delete="false">
<foreignkey field-ref="refFK"/>
</reference-descriptor>
</class-descriptor>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org