db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/sequence SequenceManagerNativeImpl.java
Date Tue, 05 Aug 2003 07:21:26 GMT
arminw      2003/08/05 00:21:26

  Modified:    src/test/org/apache/ojb/broker/sequence
                        NativeIdentifierTest.java
               src/java/org/apache/ojb/broker/util/sequence
                        SequenceManagerNativeImpl.java
  Log:
  add more tests
  
  Revision  Changes    Path
  1.7       +119 -1    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NativeIdentifierTest.java	25 Jul 2003 17:51:59 -0000	1.6
  +++ NativeIdentifierTest.java	5 Aug 2003 07:21:26 -0000	1.7
  @@ -21,6 +21,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Collection;
   
   /**
    * Test case for {@link SequenceManagerNativeImpl}. These test check
  @@ -366,6 +367,113 @@
           assertEquals(id_2, obj_2.getIdentifier());
       }
   
  +    public void testDelete() throws Exception
  +    {
  +        if (skipTest()) return;
  +        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  +        String name = "testDelete_main_" + timestamp;
  +        String nameRef = "testDelete_reference_" + timestamp;
  +
  +        SMNativeObject obj_1 = new SMNativeObject(null, name);
  +
  +        SMNativeReference ref_1 = new SMNativeReference(null, nameRef);
  +        SMNativeReference ref_2 = new SMNativeReference(null, nameRef);
  +
  +        obj_1.addReference(ref_1);
  +        obj_1.addReference(ref_2);
  +        broker.beginTransaction();
  +        broker.store(obj_1);
  +        broker.commitTransaction();
  +        Identity oid_1 = new Identity(obj_1, broker);
  +
  +        SMNativeObject result = (SMNativeObject) broker.getObjectByIdentity(oid_1);
  +        assertNotNull(result);
  +        assertNotNull(result.getAllReferences());
  +        assertEquals(2, result.getAllReferences().size());
  +        Long fk = ((SMNativeReference) result.getAllReferences().get(0)).getFkIdentifier();
  +        assertNotNull(result.getIdentifier());
  +        assertEquals(result.getIdentifier(), fk);
  +
  +        broker.beginTransaction();
  +        broker.delete(obj_1);
  +        broker.commitTransaction();
  +
  +        result = (SMNativeObject) broker.getObjectByIdentity(oid_1);
  +        assertNull(result);
  +        Criteria crit_2 = new Criteria();
  +        crit_2.addEqualTo("refName", nameRef);
  +        QueryByCriteria query_2 = QueryFactory.newQuery(SMNativeReference.class, crit_2);
  +        int result_2 = broker.getCount(query_2);
  +        assertEquals(0, result_2);
  +    }
  +
  +    public void testDelete_2() throws Exception
  +    {
  +        if (skipTest()) return;
  +        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  +        String name = "testDelete_2_main_" + timestamp;
  +        String nameRef = "testDelete_2_reference_" + timestamp;
  +
  +        SMNativeObject obj_1 = new SMNativeObject(null, name);
  +
  +        SMNativeReference ref_1 = new SMNativeReference(null, nameRef);
  +        SMNativeReference ref_2 = new SMNativeReference(null, nameRef);
  +
  +        obj_1.addReference(ref_1);
  +        obj_1.addReference(ref_2);
  +
  +        // chaotic operations
  +        broker.beginTransaction();
  +        // System.out.println("1. "+obj_1);
  +        broker.store(obj_1);
  +        // System.out.println("2. "+obj_1);
  +        broker.delete(obj_1);
  +        // System.out.println("3. "+obj_1);
  +        broker.store(obj_1);
  +        // System.out.println("4. "+obj_1);
  +        broker.delete(obj_1);
  +        // System.out.println("5. "+obj_1);
  +        broker.store(obj_1);
  +        // System.out.println("6. "+obj_1);
  +        broker.delete(obj_1);
  +        // System.out.println("7. "+obj_1);
  +        broker.store(obj_1);
  +        // System.out.println("8. "+obj_1);
  +        broker.commitTransaction();
  +        Identity oid_1 = new Identity(obj_1, broker);
  +
  +        SMNativeObject result = (SMNativeObject) broker.getObjectByIdentity(oid_1);
  +        assertNotNull(result);
  +        assertNotNull(result.getAllReferences());
  +        assertEquals(2, result.getAllReferences().size());
  +        Long fk = ((SMNativeReference) result.getAllReferences().get(0)).getFkIdentifier();
  +        assertNotNull(result.getIdentifier());
  +        assertEquals(result.getIdentifier(), fk);
  +
  +        // we should find exactly one object
  +        Criteria c = new Criteria();
  +        c.addEqualTo("name", name);
  +        QueryByCriteria q = QueryFactory.newQuery(SMNativeObject.class, c);
  +        Collection col = broker.getCollectionByQuery(q);
  +        assertNotNull(col);
  +        assertEquals(1, col.size());
  +
  +        broker.beginTransaction();
  +        broker.delete(obj_1);
  +        broker.commitTransaction();
  +
  +        result = (SMNativeObject) broker.getObjectByIdentity(oid_1);
  +        assertNull(result);
  +        Criteria crit_2 = new Criteria();
  +        crit_2.addEqualTo("refName", nameRef);
  +        QueryByCriteria query_2 = QueryFactory.newQuery(SMNativeReference.class, crit_2);
  +        int result_2 = broker.getCount(query_2);
  +        // System.out.println("## result: "+broker.getCollectionByQuery(query_2));
  +        assertEquals(0, result_2);
  +    }
  +
  +
  +
       public static class SMNativeObject implements Serializable
       {
           private Long identifier;
  @@ -451,6 +559,16 @@
           public void setRefIdentifier(Long refIdentifier)
           {
               this.refIdentifier = refIdentifier;
  +        }
  +
  +        public Long getFkIdentifier()
  +        {
  +            return fkIdentifier;
  +        }
  +
  +        public void setFkIdentifier(Long fkIdentifier)
  +        {
  +            this.fkIdentifier = fkIdentifier;
           }
   
           public String getRefName()
  
  
  
  1.6       +16 -1     db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java
  
  Index: SequenceManagerNativeImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SequenceManagerNativeImpl.java	15 Jun 2003 12:00:03 -0000	1.5
  +++ SequenceManagerNativeImpl.java	5 Aug 2003 07:21:26 -0000	1.6
  @@ -145,6 +145,21 @@
           setFieldValue(obj, fd, new Long(newId));
       }
   
  +// patch by shivaken - do not pass tests
  +//    public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj) throws
SequenceManagerException
  +//     {
  +//         FieldDescriptor fd = cld.getAutoIncrementField();
  +//        if ((fd != null) && (isAutoIncremented(obj, fd)))
  +//        {
  +//            long newId = getLastInsert(dbAccess, cld);
  +//            setFieldValue(obj, fd, new Long(newId));
  +//        }
  +//    }
  +//
  +//    private boolean isAutoIncremented(Object obj, FieldDescriptor fd) throws SequenceManagerException
{
  +//        return fd.getPersistentField().get(obj).equals(getUniqueValue(fd));
  +//     }
  +
   
       public void setReferenceFKs(Object obj, ClassDescriptor cld) throws SequenceManagerException
       {
  
  
  

---------------------------------------------------------------------
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