db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r452822 - /db/ojb/trunk/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java
Date Wed, 04 Oct 2006 10:11:50 GMT
Author: arminw
Date: Wed Oct  4 03:11:49 2006
New Revision: 452822

URL: http://svn.apache.org/viewvc?view=rev&rev=452822
Log:
use IdentityFactory, improve tests

Modified:
    db/ojb/trunk/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java?view=diff&rev=452822&r1=452821&r2=452822
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java Wed Oct  4 03:11:49
2006
@@ -225,7 +225,7 @@
         }
         finally
         {
-            broker.beginTransaction();
+            if(!broker.isInTransaction()) broker.beginTransaction();
             // cleanup
             stmt = broker.serviceStatementManager().getGenericStatement(false);
             stmt.executeUpdate(delete);
@@ -281,7 +281,7 @@
         }
         finally
         {
-            broker.beginTransaction();
+            if(!broker.isInTransaction()) broker.beginTransaction();
             // cleanup
             stmt = broker.serviceStatementManager().getGenericStatement(false);
             stmt.executeUpdate(delete);
@@ -675,21 +675,23 @@
         }
         broker.commitTransaction();
 
+        Criteria selectAll = new Criteria().addEqualTo("someValue", new Integer(7654321));
+        q = QueryFactory.newQuery(ObjectRepository.AAlone.class, selectAll);
+        int old = broker.getCount(q);
+
         // Insert 2 ObjectRepository.A
-        ObjectRepository.A a1 = new ObjectRepository.A();
-        ObjectRepository.A a2 = new ObjectRepository.A();
+        ObjectRepository.A a1 = new ObjectRepository.A(0, 7654321);
+        ObjectRepository.A a2 = new ObjectRepository.A(0, 7654321);
 
         broker.beginTransaction();
         broker.store(a1);
         broker.store(a2);
         broker.commitTransaction();
 
-        Criteria selectAll = null;
-
-        q = QueryFactory.newQuery(ObjectRepository.AAlone.class, selectAll);
+        // broker.clearCache();
         as = broker.getCollectionByQuery(q);
-        assertEquals("collection size", 2, as.size());
-        assertEquals("counted size", 2, broker.getCount(q));
+        assertEquals("counted size", old + 2, broker.getCount(q));
+        assertEquals("collection size", old + 2, as.size());
     }
 
     /**
@@ -943,7 +945,7 @@
         broker.commitTransaction();
         broker.clearCache();
 
-        GuidTestEntity gte1 = (GuidTestEntity) broker.getObjectByIdentity(new Identity(gte,
broker));
+        GuidTestEntity gte1 = (GuidTestEntity) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(gte));
 
         assertEquals(gte, gte1);
     }
@@ -1269,9 +1271,9 @@
     {
         // create new items for a class with autoincrement PK
         ProductGroup pg1 = new ProductGroup();
-        // Identity id1 = new Identity(pg1, broker);
+        // Identity id1 = broker.serviceIdentity().buildIdentity(pg1);
         ProductGroup pg2 = new ProductGroup();
-        // Identity id2 = new Identity(pg2, broker);
+        // Identity id2 = broker.serviceIdentity().buildIdentity(pg2);
         pg1.setName("AutoIncGroup1");
         pg2.setName("AutoIncGroup2");
         broker.beginTransaction();
@@ -1627,7 +1629,7 @@
         broker.store(p);
         broker.commitTransaction();
 
-        Identity id = new Identity(p, broker);
+        Identity id = broker.serviceIdentity().buildIdentity(p);
         Person result = (Person) broker.getObjectByIdentity(id);
         assertNotNull(result);
         assertEquals("no_2_" + timestamp, result.getFirstname());
@@ -1649,7 +1651,7 @@
         broker.commitTransaction();
 
         broker.clearCache();
-        id = new Identity(p, broker);
+        id = broker.serviceIdentity().buildIdentity(p);
         broker.clearCache();
         result = (Person) broker.getObjectByIdentity(id);
         assertNotNull(result);
@@ -1666,11 +1668,11 @@
         person.setLastname("time_" + timestamp);
 
         broker.beginTransaction();
+        broker.store(person);
         // Identity used to assign PK of object
-        Identity oid = new Identity(person, broker);
+        Identity oid = broker.serviceIdentity().buildIdentity(person);
         Person serializedPerson = (Person) SerializationUtils.clone(person);
         broker.store(person);
-        broker.store(person);
         broker.store(serializedPerson);
         broker.commitTransaction();
 
@@ -1691,7 +1693,7 @@
         person.setLastname("time_" + timestamp);
 
         broker.beginTransaction();
-        // Identity oid = new Identity(person, broker);
+        // Identity oid = broker.serviceIdentity().buildIdentity(person);
         Person serializedPerson = (Person) SerializationUtils.clone(person);
         broker.store(person);
         broker.commitTransaction();



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message