db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/odmg ContractVersionEffectivenessOQLTest.java
Date Tue, 22 Jul 2003 00:33:00 GMT
mattbaird    2003/07/21 17:33:00

  Modified:    src/test/org/apache/ojb/odmg
                        ContractVersionEffectivenessOQLTest.java
  Log:
  update test cases to show failure when searching on an object with a related, IS NULL object
  
  Revision  Changes    Path
  1.10      +144 -0    db-ojb/src/test/org/apache/ojb/odmg/ContractVersionEffectivenessOQLTest.java
  
  Index: ContractVersionEffectivenessOQLTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ContractVersionEffectivenessOQLTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ContractVersionEffectivenessOQLTest.java	1 Jul 2003 04:33:06 -0000	1.9
  +++ ContractVersionEffectivenessOQLTest.java	22 Jul 2003 00:33:00 -0000	1.10
  @@ -183,6 +183,150 @@
           db.close();
       }
   
  +	 public void testComplexOQL2()
  +            throws Exception
  +    {
  +        /**
  +         * 1. create the objects with specific values we'll search on later.
  +         */
  +        Implementation odmg = OJB.getInstance();
  +        Database db = odmg.newDatabase();
  +        db.open(databaseName, Database.OPEN_READ_WRITE);
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +
  +        Contract contract = new Contract();
  +        contract.setPk("C" + System.currentTimeMillis());
  +        contract.setContractValue1("version.contract.contractValue1.testComplexOQL");
  +        contract.setContractValue2(1);
  +        contract.setContractValue3("contractvalue3");
  +        contract.setContractValue4(new Timestamp(System.currentTimeMillis()));
  +        db.makePersistent(contract);
  +
  +        Version version = new Version();
  +        version.setPk("V" + System.currentTimeMillis());
  +        version.setVersionValue1("versionvalue1");
  +        version.setVersionValue2(1);
  +        version.setVersionValue3(new Timestamp(System.currentTimeMillis()));
  +        version.setContract(contract);
  +        db.makePersistent(version);
  +
  +        Effectiveness eff = new Effectiveness();
  +        eff.setPk("E" + System.currentTimeMillis());
  +        eff.setEffValue1("effValue1.testComplexOQL");
  +        eff.setEffValue2(20);
  +        eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
  +        eff.setVersion(version);
  +        db.makePersistent(eff);
  +
  +        tx.commit();
  +        /**
  +         * 2. define the complex OQL query to find the object we created
  +         */
  +        String oql = "select s from " + org.apache.ojb.broker.Effectiveness.class.getName()
+ " where " +
  +                " version.contract.contractValue1=$1 and effValue1 = $2 and " +
  +                " (effValue3 > $3 or is_undefined(effValue3)) and " +
  +                " effValue2 <= $4 and (effValue3<$5 or is_undefined(effValue3)) and
" +
  +                " is_undefined(version.contract.relatedToContract.pk)";
  +
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create(oql);
  +        query.bind("version.contract.contractValue1.testComplexOQL"); //version.contract.contractValue1=$1
  +        query.bind("effValue1.testComplexOQL"); // effValue1 = $2
  +        query.bind(new Timestamp(System.currentTimeMillis() - 5000)); // a while ago (effValue3
> $3)
  +        query.bind(new Integer(20)); // effValue2 <= $4
  +        query.bind(new Timestamp(System.currentTimeMillis() + 5000)); // a while from now
(effValue3<$5)
  +
  +        ManageableCollection all = (ManageableCollection) query.execute();
  +        java.util.Iterator it = all.ojbIterator();
  +        /**
  +         * make sure we got
  +         */
  +        int i = 0;
  +        while (it.hasNext())
  +        {
  +            it.next();
  +            i++;
  +        }
  +        if (i != 1)
  +        {
  +            fail("Should have found just one object, instead found " + i);
  +        }
  +        db.close();
  +    }
  +
  +	 public void testComplexOQL3()
  +            throws Exception
  +    {
  +        /**
  +         * 1. create the objects with specific values we'll search on later.
  +         */
  +        Implementation odmg = OJB.getInstance();
  +        Database db = odmg.newDatabase();
  +        db.open(databaseName, Database.OPEN_READ_WRITE);
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +
  +        Contract contract = new Contract();
  +        contract.setPk("C" + System.currentTimeMillis());
  +        contract.setContractValue1("version.contract.contractValue1.testComplexOQL");
  +        contract.setContractValue2(1);
  +        contract.setContractValue3("contractvalue3");
  +        contract.setContractValue4(new Timestamp(System.currentTimeMillis()));
  +        db.makePersistent(contract);
  +
  +        Version version = new Version();
  +        version.setPk("V" + System.currentTimeMillis());
  +        version.setVersionValue1("versionvalue1");
  +        version.setVersionValue2(1);
  +        version.setVersionValue3(new Timestamp(System.currentTimeMillis()));
  +        version.setContract(contract);
  +        db.makePersistent(version);
  +
  +        Effectiveness eff = new Effectiveness();
  +        eff.setPk("E" + System.currentTimeMillis());
  +        eff.setEffValue1("effValue1.testComplexOQL");
  +        eff.setEffValue2(20);
  +        eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
  +        eff.setVersion(version);
  +        db.makePersistent(eff);
  +
  +        tx.commit();
  +        /**
  +         * 2. define the complex OQL query to find the object we created
  +         */
  +        String oql = "select s from " + org.apache.ojb.broker.Effectiveness.class.getName()
+ " where " +
  +                " version.contract.contractValue1=$1 and effValue1 = $2 and " +
  +                " (effValue3 > $3 or is_undefined(effValue3)) and " +
  +                " effValue2 <= $4 and (effValue3<$5 or is_undefined(effValue3)) and
" +
  +                " is_undefined(version.contract.relatedToContract)";
  +
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create(oql);
  +        query.bind("version.contract.contractValue1.testComplexOQL"); //version.contract.contractValue1=$1
  +        query.bind("effValue1.testComplexOQL"); // effValue1 = $2
  +        query.bind(new Timestamp(System.currentTimeMillis() - 5000)); // a while ago (effValue3
> $3)
  +        query.bind(new Integer(20)); // effValue2 <= $4
  +        query.bind(new Timestamp(System.currentTimeMillis() + 5000)); // a while from now
(effValue3<$5)
  +
  +        ManageableCollection all = (ManageableCollection) query.execute();
  +        java.util.Iterator it = all.ojbIterator();
  +        /**
  +         * make sure we got
  +         */
  +        int i = 0;
  +        while (it.hasNext())
  +        {
  +            it.next();
  +            i++;
  +        }
  +        if (i != 1)
  +        {
  +            fail("Should have found just one object, instead found " + i);
  +        }
  +        db.close();
  +    }
  +
       public void testGetWithVersionCriteria()
               throws Exception
       {
  
  
  

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