Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 75334 invoked from network); 7 May 2005 16:03:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 May 2005 16:03:02 -0000 Received: (qmail 41011 invoked by uid 500); 7 May 2005 16:05:58 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 40816 invoked by uid 500); 7 May 2005 16:05:56 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 40799 invoked by uid 500); 7 May 2005 16:05:56 -0000 Received: (qmail 40794 invoked by uid 99); 7 May 2005 16:05:56 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sat, 07 May 2005 09:05:55 -0700 Received: (qmail 75321 invoked by uid 1510); 7 May 2005 16:02:58 -0000 Date: 7 May 2005 16:02:58 -0000 Message-ID: <20050507160258.75320.qmail@minotaur.apache.org> From: arminw@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/test/org/apache/ojb repository_junit.xml repository_junit_inheritance.xml repository_junit_odmg.xml X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N arminw 2005/05/07 09:02:57 Modified: src/schema Tag: OJB_1_0_RELEASE ojbtest-schema.xml src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE InheritanceMultipleTableTest.java src/test/org/apache/ojb/junit Tag: OJB_1_0_RELEASE ODMGTestCase.java PBTestCase.java src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE M2NTest.java ObjectImageTest.java src/test/org/apache/ojb Tag: OJB_1_0_RELEASE repository_junit.xml repository_junit_inheritance.xml repository_junit_odmg.xml Log: add new tests Revision Changes Path No revision No revision 1.80.2.21 +19 -1 db-ojb/src/schema/ojbtest-schema.xml Index: ojbtest-schema.xml =================================================================== RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v retrieving revision 1.80.2.20 retrieving revision 1.80.2.21 diff -u -r1.80.2.20 -r1.80.2.21 --- ojbtest-schema.xml 6 May 2005 18:30:17 -0000 1.80.2.20 +++ ojbtest-schema.xml 7 May 2005 16:02:57 -0000 1.80.2.21 @@ -950,7 +950,25 @@ + + + + + +
+ + + + +
+ + + + +
+ + No revision No revision 1.7.2.7 +424 -1 db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java Index: InheritanceMultipleTableTest.java =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java,v retrieving revision 1.7.2.6 retrieving revision 1.7.2.7 diff -u -r1.7.2.6 -r1.7.2.7 --- InheritanceMultipleTableTest.java 22 Apr 2005 18:11:57 -0000 1.7.2.6 +++ InheritanceMultipleTableTest.java 7 May 2005 16:02:57 -0000 1.7.2.7 @@ -31,6 +31,115 @@ junit.textui.TestRunner.main(new String[]{InheritanceMultipleTableTest.class.getName()}); } + public void testWithoutJavaInheritance_1() + { + String name = "testWithoutJavaInheritance_1" + System.currentTimeMillis(); + Dog dog = new Dog(name, 35, 4); + broker.beginTransaction(); + broker.store(dog); + broker.commitTransaction(); + + broker.clearCache(); + Criteria crit = new Criteria(); + crit.addEqualTo("name", name); + Query q = QueryFactory.newQuery(Dog.class, crit); + Collection result = broker.getCollectionByQuery(q); + assertNotNull(result); + assertEquals(1, result.size()); + Dog newDog = (Dog) result.iterator().next(); + assertTrue(dog.equals(newDog)); + + broker.beginTransaction(); + newDog.setWeight(1000); + newDog.setLegs(10); + broker.store(newDog); + broker.commitTransaction(); + + broker.clearCache(); + result = broker.getCollectionByQuery(q); + assertNotNull(result); + assertEquals(1, result.size()); + Dog newDog2 = (Dog) result.iterator().next(); + assertTrue(newDog.equals(newDog2)); + + broker.beginTransaction(); + broker.delete(dog); + broker.commitTransaction(); + } + + public void testJavaInheritance() + { + String name = "testWithoutJavaInheritance_tmp" + System.currentTimeMillis(); + Animal animal = new Animal(name, 55); + Food f1 = new Food(name + "fruit1"); + Food f2 = new Food(name + "fruit2"); + animal.addFood(f1); + animal.addFood(f2); + // animal.setParent(animal); + + broker.beginTransaction(); + broker.store(animal); + broker.commitTransaction(); + Identity oid = broker.serviceIdentity().buildIdentity(animal); + + broker.clearCache(); + Animal newAnimal = (Animal) broker.getObjectByIdentity(oid); + assertTrue(animal.equals(newAnimal)); + + Criteria crit = new Criteria(); + crit.addEqualTo("name", name); + Query q = QueryFactory.newQuery(Animal.class, crit); + Collection result = broker.getCollectionByQuery(q); + assertNotNull(result); + assertEquals(1, result.size()); + newAnimal = (Animal) result.iterator().next(); + assertTrue(animal.equals(newAnimal)); + } + + public void testWithoutJavaInheritance_2() + { + String name = "testWithoutJavaInheritance_2" + System.currentTimeMillis(); + Dog dog = new Dog(name, 35, 4); + Animal parent = new Animal(name + "_parent", 55); + Food f1 = new Food(name + "fruit1"); + Food f2 = new Food(name + "fruit2"); + dog.addFood(f1); + dog.addFood(f2); + dog.setParent(parent); + + broker.beginTransaction(); + broker.store(dog); + broker.commitTransaction(); + + broker.clearCache(); + Criteria crit = new Criteria(); + crit.addEqualTo("name", name); + Query q = QueryFactory.newQuery(Dog.class, crit); + Collection result = broker.getCollectionByQuery(q); + assertNotNull(result); + assertEquals(1, result.size()); + Dog newDog = (Dog) result.iterator().next(); + assertTrue(dog.equals(newDog)); + + broker.beginTransaction(); + newDog.setWeight(1000); + newDog.setLegs(10); + newDog.addFood(new Food(name + "_new")); + broker.store(newDog); + broker.commitTransaction(); + + broker.clearCache(); + result = broker.getCollectionByQuery(q); + assertNotNull(result); + assertEquals(1, result.size()); + Dog newDog2 = (Dog) result.iterator().next(); + assertTrue(newDog.equals(newDog2)); + + broker.beginTransaction(); + broker.delete(dog); + broker.commitTransaction(); + } + public void testInheritancedObjectsInCollectionReferences() { if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple joined tables only" + @@ -171,6 +280,7 @@ Shareholder new_shareholder = (Shareholder) broker.getObjectByIdentity(oid_shareholder); assertNotNull(new_shareholder); + assertTrue(shareholder.equals(new_shareholder)); Criteria c = new Criteria(); c.addEqualTo("name", shareholder.getName()); @@ -937,6 +1047,7 @@ .append(getId(), em.getId()) .append(getId_2(), em.getId_2()) .append(getName(), em.getName()) + .append(getAddress(), em.getAddress()) .isEquals(); } @@ -979,6 +1090,24 @@ { this.street = street; } + + public boolean equals(Object obj) + { + if (!(obj instanceof Address)) + { + return false; + } + Address adr = (Address) obj; + return new EqualsBuilder() + .append(getId(), adr.getId()) + .append(getStreet(), adr.getStreet()) + .isEquals(); + } + + public String toString() + { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Address.class); + } } public static interface AddressIF extends Serializable @@ -1099,4 +1228,298 @@ return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Consortium.class); } } + + public static class Entity + { + private Integer id; + private String name; + + public Entity() + { + } + + public Entity(String name) + { + this.name = name; + } + + public boolean equals(Object obj) + { + if (!(obj instanceof Entity)) + { + return false; + } + Entity other = (Entity) obj; + return new EqualsBuilder() + .append(getId(), other.getId()) + .append(getName(), other.getName()) + .isEquals(); + } + + public Integer getId() + { + return id; + } + + public void setId(Integer id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + } + + public static class Animal + { + private Integer id; + private int weight; + private String name; + private Animal parent; + private List foods = new ArrayList(); + + public Animal() + { + } + + public Animal(String name, int weight) + { + this.name = name; + this.weight = weight; + } + + public boolean equals(Object obj) + { + if (!(obj instanceof Animal)) + { + return false; + } + Animal other = (Animal) obj; + return new EqualsBuilder() + .append(getId(), other.getId()) + .append(getName(), other.getName()) + .append(getWeight(), other.getWeight()) + .append(getParent(), other.getParent()) + .append(getFoods(), other.getFoods()) + .isEquals(); + } + + public String toString() + { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Entity.class); + } + + public Integer getId() + { + return id; + } + + public void setId(Integer id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public int getWeight() + { + return weight; + } + + public void setWeight(int weight) + { + this.weight = weight; + } + + public Animal getParent() + { + return parent; + } + + public void setParent(Animal parent) + { + this.parent = parent; + } + + public void addFood(Food food) + { + foods.add(food); + } + + public List getFoods() + { + return foods; + } + + public void setFoods(List foods) + { + this.foods = foods; + } + } + + public static class Dog + { + private Integer id; + private int legs; + + // these fields should be mapped to a super table + private String name; + private int weight; + private Animal parent; + private List foods = new ArrayList(); + + public Dog() + { + } + + public Dog(String name, int weight, int legs) + { + this.name = name; + this.weight = weight; + this.legs = legs; + } + + public boolean equals(Object obj) + { + if (!(obj instanceof Dog)) + { + return false; + } + Dog other = (Dog) obj; + return new EqualsBuilder() + .append(getId(), other.getId()) + .append(getName(), other.getName()) + .append(getLegs(), other.getLegs()) + .append(getWeight(), other.getWeight()) + .append(getParent(), other.getParent()) + .append(getFoods(), other.getFoods()) + .isEquals(); + } + + public String toString() + { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Dog.class); + } + + public Integer getId() + { + return id; + } + + public void setId(Integer id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public int getWeight() + { + return weight; + } + + public void setWeight(int weight) + { + this.weight = weight; + } + + public int getLegs() + { + return legs; + } + + public void setLegs(int legs) + { + this.legs = legs; + } + + public Animal getParent() + { + return parent; + } + + public void setParent(Animal parent) + { + this.parent = parent; + } + + public void addFood(Food food) + { + this.foods.add(food); + } + + public List getFoods() + { + return foods; + } + + public void setFoods(List foods) + { + this.foods = foods; + } + } + + public static class Food extends Entity + { + private Integer fkAnimal; + + public Food() + { + } + + public boolean equals(Object obj) + { + if (!(obj instanceof Food)) + { + return false; + } + Food other = (Food) obj; + return new EqualsBuilder() + .append(getFkAnimal(), other.getFkAnimal()) + .isEquals() && super.equals(obj); + } + + public String toString() + { + return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE, false, Food.class); + } + + public Food(String name) + { + super(name); + } + + public Integer getFkAnimal() + { + return fkAnimal; + } + + public void setFkAnimal(Integer fkAnimal) + { + this.fkAnimal = fkAnimal; + } + } } No revision No revision 1.1.2.2 +3 -3 db-ojb/src/test/org/apache/ojb/junit/ODMGTestCase.java Index: ODMGTestCase.java =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/junit/ODMGTestCase.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- ODMGTestCase.java 4 Dec 2004 14:01:08 -0000 1.1.2.1 +++ ODMGTestCase.java 7 May 2005 16:02:57 -0000 1.1.2.2 @@ -1,9 +1,9 @@ package org.apache.ojb.junit; import org.apache.ojb.broker.TestHelper; +import org.apache.ojb.odmg.ImplementationExt; import org.apache.ojb.odmg.OJB; import org.odmg.Database; -import org.odmg.Implementation; import org.odmg.Transaction; /** @@ -14,7 +14,7 @@ */ public class ODMGTestCase extends OJBTestCase { - public Implementation odmg; + public ImplementationExt odmg; public Database database; public ODMGTestCase() 1.3.2.3 +9 -3 db-ojb/src/test/org/apache/ojb/junit/PBTestCase.java Index: PBTestCase.java =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/junit/PBTestCase.java,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -u -r1.3.2.2 -r1.3.2.3 --- PBTestCase.java 2 Mar 2005 15:57:26 -0000 1.3.2.2 +++ PBTestCase.java 7 May 2005 16:02:57 -0000 1.3.2.3 @@ -53,11 +53,17 @@ public void tearDown() throws Exception { - super.tearDown(); if(broker != null) { - broker.close(); + try + { + broker.close(); + } + catch(Exception ignore) + { + } } + super.tearDown(); } /** No revision No revision 1.3.2.3 +282 -7 db-ojb/src/test/org/apache/ojb/odmg/M2NTest.java Index: M2NTest.java =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/M2NTest.java,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -u -r1.3.2.2 -r1.3.2.3 --- M2NTest.java 18 Mar 2005 19:22:30 -0000 1.3.2.2 +++ M2NTest.java 7 May 2005 16:02:57 -0000 1.3.2.3 @@ -3,12 +3,19 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.ojb.broker.ManageableCollection; import org.apache.ojb.broker.PersistenceBroker; import org.apache.ojb.broker.PersistenceBrokerException; import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor; +import org.apache.ojb.broker.query.Criteria; +import org.apache.ojb.broker.query.Query; +import org.apache.ojb.broker.query.QueryFactory; import org.apache.ojb.junit.ODMGTestCase; import org.odmg.OQLQuery; import org.odmg.QueryException; @@ -17,7 +24,7 @@ /** * Test m:n relation handling with the odmg-api. The mandatory auto-update/auto-delete * setting are 'false' in that case equals to 'LINK'. - * + *

* TODO: we need more tests doing delete/update operations on M:N relations * * @author Armin Waibel @@ -28,17 +35,135 @@ static final int NONE = ObjectReferenceDescriptor.CASCADE_NONE; static final int LINK = ObjectReferenceDescriptor.CASCADE_LINK; static final int OBJECT = ObjectReferenceDescriptor.CASCADE_OBJECT; + boolean oldImpliciteWriteLock; public static void main(String[] args) { - junit.textui.TestRunner.main(new String[] {M2NTest.class.getName()}); + junit.textui.TestRunner.main(new String[]{M2NTest.class.getName()}); + } + + protected void setUp() throws Exception + { + super.setUp(); + oldImpliciteWriteLock = odmg.isImpliciteWriteLocks(); } protected void tearDown() throws Exception { + odmg.setImpliciteWriteLocks(oldImpliciteWriteLock); super.tearDown(); } + public void testOnetoNViaIndirectionTable() throws Exception + { + String name = "testOnetoNViaIndirectionTable_" + System.currentTimeMillis(); + int opId = (int) (Math.random() * Integer.MAX_VALUE); + String cId = "m2n_" + opId; + + // explicit set false + odmg.setImpliciteWriteLocks(false); + + // Make a profile and County + TransactionExt tx = (TransactionExt) odmg.newTransaction(); + tx.begin(); + OfficeProfile profile = new OfficeProfileImpl(); + profile.setId(opId); + County c = new County(); + c.setName(name); + c.setId(cId); + odmg.getDatabase(null).makePersistent(profile); + odmg.getDatabase(null).makePersistent(c); + tx.commit(); + + tx.begin(); + PersistenceBroker pb = tx.getBroker(); + pb.clearCache(); + // use PB-api to lookup object + Criteria crit = new Criteria(); + crit.addLike("name", name); + Query q = QueryFactory.newQuery(County.class, crit); + County county = (County) pb.getObjectByQuery(q); + tx.commit(); + + // Add a county to it + tx = (TransactionExt) odmg.newTransaction(); + tx.begin(); + tx.lock(profile, Transaction.WRITE); + tx.lock(county, Transaction.READ); + // add already persisted County object + profile.addCounty(county); + // add a new County object + County c2 = new County(); + c2.setId(cId + "_new"); + c2.setName(name + "_new"); + profile.addCounty(c2); + tx.commit(); + + tx.begin(); + OQLQuery query = odmg.newOQLQuery(); + query.create("select all from " + OfficeProfile.class.getName() + " where id=$1"); + query.bind(new Integer(opId)); + List result = (List) query.execute(); + assertEquals(1, result.size()); + tx.commit(); + OfficeProfile newProfile = (OfficeProfile) result.get(0); + assertTrue(profile.equals(newProfile)); + + tx.begin(); + tx.lock(newProfile, Transaction.WRITE); + List counties = newProfile.getCounties(); + for(int i = 0; i < counties.size(); i++) + { + County tmp = (County) counties.get(i); + tmp.setName(tmp.getName() + "_updated"); + } + tx.commit(); + + tx.begin(); + query = odmg.newOQLQuery(); + query.create("select all from " + County.class.getName() + " where name like $1"); + query.bind(name + "%"); + result = (List) query.execute(); + assertEquals(2, result.size()); + tx.commit(); + for(int i = 0; i < counties.size(); i++) + { + County tmp = (County) counties.get(i); + assertTrue(StringUtils.contains(tmp.getName(), "_updated")); + } + + tx.begin(); + tx.lock(newProfile, Transaction.WRITE); + counties = newProfile.getCounties(); + // this only remove the indirection table entry + County removed = (County) counties.remove(0); + // update the "unlinked" object + removed.setName(removed.getName() + "_unlinked"); + tx.commit(); + + tx.begin(); + query = odmg.newOQLQuery(); + query.create("select all from " + County.class.getName() + " where name=$1"); + query.bind(removed.getName()); + result = (List) query.execute(); + assertEquals(1, result.size()); + tx.commit(); + + tx.begin(); + tx.setCascadingDelete(OfficeProfileImpl.class, true); + database.deletePersistent(newProfile); + tx.commit(); + + tx.begin(); + query = odmg.newOQLQuery(); + query.create("select all from " + County.class.getName() + " where name like $1"); + query.bind(name + "%"); + result = (List) query.execute(); + // expect to find the unlinked County object + assertEquals(1, result.size()); + tx.commit(); + } + public void testStore() throws Exception { // arminw: fixed @@ -167,7 +292,7 @@ Collection resultMovie = (Collection) queryMovie.execute(); assertEquals(3, resultMovie.size()); Iterator it = resultMovie.iterator(); - boolean matchActors = false; + boolean matchActors = false; while(it.hasNext()) { Movie m = (Movie) it.next(); @@ -183,7 +308,7 @@ Collection resultActor = (Collection) queryActor.execute(); assertEquals(3, resultActor.size()); it = resultActor.iterator(); - boolean matchMovies = false; + boolean matchMovies = false; while(it.hasNext()) { Actor a = (Actor) it.next(); @@ -241,7 +366,7 @@ Collection resultMovie = (Collection) queryMovie.execute(); assertEquals(3, resultMovie.size()); it = resultMovie.iterator(); - boolean matchActors = false; + boolean matchActors = false; while(it.hasNext()) { Movie m = (Movie) it.next(); @@ -256,7 +381,7 @@ Collection resultActor = (Collection) queryActor.execute(); assertEquals(3, resultActor.size()); it = resultActor.iterator(); - boolean matchMovies = false; + boolean matchMovies = false; while(it.hasNext()) { Actor a = (Actor) it.next(); @@ -588,12 +713,19 @@ public static interface MovieManageableCollection extends ManageableCollection { public Iterator iterator(); + public int size(); + public boolean isEmpty(); + public void clear(); + public boolean add(Movie movie); + public boolean remove(Movie movie); + public boolean contains(Movie movie); + public Movie get(int index); } @@ -734,9 +866,11 @@ public void setActors(Collection actors); public Integer getIdInt2(); + public Integer getIdInt(); public void setIdInt2(Integer id2Int); + public void setIdInt(Integer idInt); public String getIdStr(); @@ -905,4 +1039,145 @@ return ToStringBuilder.reflectionToString(this).toString(); } } + + + + public static class County + { + private String id; + private String name; + + public County() + { + } + + /** + * Compares the given objects on the basis of their + * toString() methods. Returns false + * if the given object is not of type County. + */ + public boolean equals(Object obj) + { + if(!(obj instanceof County)) + { + return false; + } + County other = (County) obj; + return new EqualsBuilder().append(getId(), other.getId()) + .append(getName(), other.getName()) + .isEquals(); + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + } + + public static interface OfficeProfile + { + public int getId(); + public void setId(int officeId); + public void setName(String name); + public String getName(); + public List getCounties(); + public void setCounties(List list); + public void clearCounties(); + public void addCounty(County county); + public void removeCounty(County county); + } + + public static class OfficeProfileImpl implements OfficeProfile + { + private int id; + private String name; + private List counties; + + public OfficeProfileImpl() + { + } + + public boolean equals(Object obj) + { + if(!(obj instanceof OfficeProfile)) + { + return false; + } + OfficeProfile other = (OfficeProfile) obj; + return new EqualsBuilder().append(getId(), other.getId()) + .append(getName(), other.getName()) + .append(getCounties(), other.getCounties()) + .isEquals(); + } + + public int getId() + { + return id; + } + + public void setId(int officeId) + { + id = officeId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public List getCounties() + { + return counties; + } + + public void setCounties(List list) + { + counties = list; + } + + public void clearCounties() + { + if(counties != null) + { + counties.clear(); + } + } + + public void addCounty(County county) + { + if(counties == null) + { + counties = new LinkedList(); + } + counties.add(county); + } + + public void removeCounty(County county) + { + if(counties != null) + { + counties.remove(county); + } + } + } } 1.1.2.5 +101 -1 db-ojb/src/test/org/apache/ojb/odmg/ObjectImageTest.java Index: ObjectImageTest.java =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ObjectImageTest.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- ObjectImageTest.java 14 Apr 2005 17:48:43 -0000 1.1.2.4 +++ ObjectImageTest.java 7 May 2005 16:02:57 -0000 1.1.2.5 @@ -49,6 +49,79 @@ */ public class ObjectImageTest extends ODMGTestCase { + public void testAddPersistentObjectTo1toN() throws Exception + { + String name = "testAddPersistentObjectOnNSide_" + System.currentTimeMillis(); + Review review = new Review(name); + TransactionExt tx = (TransactionExt) odmg.newTransaction(); + tx.begin(); + database.makePersistent(review); + tx.commit(); + + Integer versionReview = review.getVersion(); + + Date date = new Date(); + byte[] cover = new byte[]{2,3,4,5,6,7,8,9}; + Book book = new Book(name, date, cover); + tx = (TransactionExt) odmg.newTransaction(); + tx.begin(); + // tx.lock(review, Transaction.WRITE); + database.makePersistent(book); + book.addReview(review); + tx.commit(); + + // the Review object has to be linked + assertEquals("expect that this object was updated", versionReview.intValue() + 1, review.getVersion().intValue()); + + tx.begin(); + tx.getBroker().clearCache(); + OQLQuery query = odmg.newOQLQuery(); + query.create("select books from " + Book.class.getName() + " where title like $1"); + query.bind(name); + Collection result = (Collection) query.execute(); + assertEquals(1, result.size()); + Book b = (Book) result.iterator().next(); + assertNotNull(b.getReviews()); + assertEquals(1, b.getReviews().size()); + tx.commit(); + } + + public void testAddPersistentObjectToMtoN() throws Exception + { + String name = "testAddPersistentObjectOnNSide_" + System.currentTimeMillis(); + Author author = new Author(name, null); + TransactionExt tx = (TransactionExt) odmg.newTransaction(); + tx.begin(); + database.makePersistent(author); + tx.commit(); + + Integer versionReview = author.getVersion(); + + Date date = new Date(); + byte[] cover = new byte[]{2,3,4,5,6,7,8,9}; + Book book = new Book(name, date, cover); + tx = (TransactionExt) odmg.newTransaction(); + tx.begin(); + database.makePersistent(book); + book.addAuthor(author); + author.addBook(book); + tx.commit(); + + // the Review object has to be linked + assertEquals("expect that this object wasn't updated", versionReview.intValue(), author.getVersion().intValue()); + + tx.begin(); + tx.getBroker().clearCache(); + OQLQuery query = odmg.newOQLQuery(); + query.create("select books from " + Book.class.getName() + " where title like $1"); + query.bind(name); + Collection result = (Collection) query.execute(); + assertEquals(1, result.size()); + Book b = (Book) result.iterator().next(); + assertNotNull(b.getAuthors()); + assertEquals(1, b.getAuthors().size()); + tx.commit(); + } /** * only lock object, no changes made @@ -1355,6 +1428,24 @@ this.cover = cover; } + public void addAuthor(Author author) + { + if(authors == null) + { + authors = new ArrayList(); + } + authors.add(author); + } + + public void addReview(Review review) + { + if(reviews == null) + { + reviews = new ArrayList(); + } + reviews.add(review); + } + public Integer getId() { return id; @@ -1453,6 +1544,15 @@ this.books = books; } + public void addBook(Book book) + { + if(books == null) + { + books = new ArrayList(); + } + books.add(book); + } + public Integer getId() { return id; No revision No revision 1.112.2.14 +5 -18 db-ojb/src/test/org/apache/ojb/repository_junit.xml Index: repository_junit.xml =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v retrieving revision 1.112.2.13 retrieving revision 1.112.2.14 diff -u -r1.112.2.13 -r1.112.2.14 --- repository_junit.xml 26 Apr 2005 22:03:17 -0000 1.112.2.13 +++ repository_junit.xml 7 May 2005 16:02:57 -0000 1.112.2.14 @@ -694,11 +694,7 @@ jdbc-type="INTEGER" /> - + @@ -730,10 +726,7 @@ /> + class-ref="org.apache.ojb.broker.ObjectRepository$F"> @@ -757,10 +750,7 @@ /> + class-ref="org.apache.ojb.broker.ObjectRepository$E"> @@ -784,10 +774,7 @@ /> + class-ref="org.apache.ojb.broker.ObjectRepository$F1"> 1.1.2.4 +115 -10 db-ojb/src/test/org/apache/ojb/Attic/repository_junit_inheritance.xml Index: repository_junit_inheritance.xml =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/Attic/repository_junit_inheritance.xml,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- repository_junit_inheritance.xml 26 Apr 2005 01:51:00 -0000 1.1.2.3 +++ repository_junit_inheritance.xml 7 May 2005 16:02:57 -0000 1.1.2.4 @@ -21,6 +21,25 @@ "super" references --> + + + + + + @@ -78,7 +97,6 @@ column="NAME" jdbc-type="VARCHAR" /> - @@ -180,9 +195,6 @@ @@ -228,9 +240,6 @@ @@ -288,6 +297,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.13.2.10 +64 -42 db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml Index: repository_junit_odmg.xml =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml,v retrieving revision 1.13.2.9 retrieving revision 1.13.2.10 diff -u -r1.13.2.9 -r1.13.2.10 --- repository_junit_odmg.xml 22 Apr 2005 16:42:22 -0000 1.13.2.9 +++ repository_junit_odmg.xml 7 May 2005 16:02:57 -0000 1.13.2.10 @@ -1291,6 +1291,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1359,18 +1416,6 @@ column="DEPARTMENT" jdbc-type="VARCHAR" /> - - - - + class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Employee"> + + - - - - - + class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Executive"> + +