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 Sat, 20 Sep 2003 14:24:44 GMT
arminw      2003/09/20 07:24:44

  Modified:    src/test/org/apache/ojb/broker/sequence
                        NativeIdentifierTest.java
               src/java/org/apache/ojb/broker/util/sequence
                        SequenceManagerNativeImpl.java
  Log:
  - add test case using odmg-api to store objects
  - add workaround for storing problem using odmg-api
  
  Revision  Changes    Path
  1.8       +36 -3     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NativeIdentifierTest.java	5 Aug 2003 07:21:26 -0000	1.7
  +++ NativeIdentifierTest.java	20 Sep 2003 14:24:44 -0000	1.8
  @@ -5,6 +5,7 @@
   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.MetadataManager;
   import org.apache.ojb.broker.metadata.SequenceDescriptor;
   import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
  @@ -14,6 +15,10 @@
   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.odmg.OJB;
  +import org.odmg.Implementation;
  +import org.odmg.Database;
  +import org.odmg.Transaction;
   
   import java.io.Serializable;
   import java.sql.Connection;
  @@ -82,7 +87,6 @@
           if (skipTest()) return;
           Connection con;
           Statement stmt;
  -        boolean needTableCreation = false;
   
           try
           {
  @@ -150,7 +154,6 @@
   
           Connection con;
           Statement stmt;
  -        boolean needTableCreation = false;
           PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
           try
           {
  @@ -199,6 +202,36 @@
           broker.store(obj_3);
   //        System.out.println("obj_3: "+obj_3);
           broker.commitTransaction();
  +
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        QueryByCriteria query = QueryFactory.newQuery(SMNativeObject.class, crit);
  +        int result = broker.getCount(query);
  +        assertEquals("Not all objects created", 3, result);
  +        assertNotNull(obj_1.getIdentifier());
  +    }
  +
  +    public void testSimpleInsertODMG() throws Exception
  +    {
  +        long timestamp = (long) (System.currentTimeMillis() * Math.random());
  +        String name = "testSimpleInsert_" + timestamp;
  +
  +        if (skipTest()) return;
  +
  +        SMNativeObject obj_1 = new SMNativeObject(null, name);
  +        SMNativeObject obj_2 = new SMNativeObject(null, name);
  +        SMNativeObject obj_3 = new SMNativeObject(null, name);
  +
  +        Implementation odmg = OJB.getInstance();
  +        Database db = odmg.newDatabase();
  +        db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
  +
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +        tx.lock(obj_1, Transaction.WRITE);
  +        tx.lock(obj_2, Transaction.WRITE);
  +        tx.lock(obj_3, Transaction.WRITE);
  +        tx.commit();
   
           Criteria crit = new Criteria();
           crit.addEqualTo("name", name);
  
  
  
  1.8       +9 -5      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SequenceManagerNativeImpl.java	13 Aug 2003 18:16:10 -0000	1.7
  +++ SequenceManagerNativeImpl.java	20 Sep 2003 14:24:44 -0000	1.8
  @@ -116,18 +116,18 @@
   public class SequenceManagerNativeImpl extends AbstractSequenceManager
   {
       private Log log = LogFactory.getLog(SequenceManagerNativeImpl.class);
  +
       /*
        TODO:
        1. Find a better solution for this problem
        We need this dummy field to return a negative long value
        on getUniqueLong(...) call. If we return always the same
        value, the resulting Identity object was found on cache.
  -     arminw:
  -     seems to work when always -1 was returned
   
        2. Problem is that generated oid (by Identity column)
        must not begin with 0.
        */
  +    private long tempKey = -1;
   
       public SequenceManagerNativeImpl(PersistenceBroker broker)
       {
  @@ -238,7 +238,7 @@
           else
           {
               throw new SequenceManagerException(
  -                    "Field does not support autoincrement, please check repository: " +
fd);
  +                    "No autoincrement field declared, please check repository for " + cld);
           }
           return newId;
       }
  @@ -265,6 +265,10 @@
        */
       protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
       {
  -        return -1;
  +        /*
  +        workaround for locking problems of new objects
  +        We need unique 'dummy keys' for new objects before storing
  +        */
  +        return --tempKey;
       }
   }
  
  
  

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