Package org.odmg

Examples of org.odmg.Implementation


            if(useImplicitLocking)
            {
                restore = true;
                conf.setUseImplicitLocking(false);
            }
            Implementation odmg = OJB.getInstance();
            Database db = odmg.newDatabase();
            db.open(databaseName, Database.OPEN_READ_WRITE);

            String name = "testImplicitLocking - " + System.currentTimeMillis();
            String queryString = "select sites from " + Site.class.getName() + " where name = $1";

            /* Create an object */
            Site site = new Site();
            site.setName(name);

            Transaction tx = odmg.newTransaction();
            tx.begin();
            tx.lock(site, Transaction.WRITE);
            tx.commit();

            /* Retrieve from the object created, and set the year*/
            OQLQuery query = odmg.newOQLQuery();
            query.create(queryString);
            query.bind(name);

            tx.begin();
            List result = (List) query.execute();
            assertEquals(1, result.size());
            site = (Site) result.get(0);
            assertNotNull(site);
            assertNull(site.getYear());
            tx.lock(site, Transaction.WRITE);
            site.setYear(new Integer(2003));

            tx.commit();

            /* Flush the cache, and retrieve the object again */
            query = odmg.newOQLQuery();
            query.create(queryString);
            query.bind(name);
            tx.begin();
            ((HasBroker) tx).getBroker().clearCache();
            result = (List) query.execute();
View Full Code Here


    /**
       * store an object and then retrieve it by id.
       */
      public void testStoreRetrieveSameTxn() throws Exception
      {
          Implementation odmg = OJB.getInstance();
          Database db = odmg.newDatabase();
          //open database
          try
          {
            db.open(databaseName, Database.OPEN_READ_WRITE);
          }
          catch (ODMGException ex)
          {
            fail("ODMGException: " + ex.getMessage());
          }
          String name = "testStoreRetrieveSameTxn_" + System.currentTimeMillis();
          Person mum = new PersonImpl();
          mum.setFirstname(name);

          TransactionExt txn = (TransactionExt)odmg.newTransaction();
          txn.begin();
          txn.lock(mum, Transaction.WRITE);
          // System.out.println("locked for write: " + mum);
          txn.commit();

View Full Code Here

    public void testRetrieveNonExistent()
  {
    try
    {
      Implementation odmg = OJB.getInstance();
      Database db = odmg.newDatabase();
      //open database
      try
      {
        db.open(databaseName, Database.OPEN_READ_WRITE);
      }
      catch (ODMGException ex)
      {
        fail("ODMGException: " + ex.getMessage());
      }
      // construct an id that does not exist in the database
      Identity id = new Identity(PersonImpl.class, Person.class,  new Integer[]{new Integer(-1)});
      TransactionImpl txn = (TransactionImpl)odmg.newTransaction();
      txn.begin();
      txn.getObjectByIdentity(id);
      txn.abort();
    }
    catch (Exception exc)
View Full Code Here

  public void testRetrieveOutsideTxn()
  {
    try
    {
      Implementation odmg = OJB.getInstance();
      Database db = odmg.newDatabase();
      //open database
      try
      {
        db.open(databaseName, Database.OPEN_READ_WRITE);
      }
      catch (ODMGException ex)
      {
        fail("ODMGException: " + ex.getMessage());
      }
      // construct an id that does not exist in the database
      Identity id = new Identity(Person.class, Person.class, new Integer[]{new Integer(-1)});
      TransactionImpl txn = (TransactionImpl)odmg.newTransaction();
      try
      {
        txn.getObjectByIdentity(id);
        fail("expected TransactionNotInProgressException not thrown");
      }
View Full Code Here

        if (whichTest == 2 || whichTest == 3)
        {
//        log.info("Init ODMG-API");
            PerformanceArticle art2 = createArticle(1001);
            Implementation ojb = OJB.getInstance();
            Database db = ojb.newDatabase();
            db.open(databaseName, Database.OPEN_READ_WRITE);
            Transaction tx = ojb.newTransaction();
            tx.begin();
            tx.lock(art2, Transaction.WRITE);
            tx.commit();

            tx.begin();
View Full Code Here

    {
        // create a unique name:
        final String name = "testAdding_" + System.currentTimeMillis();

        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        db.open(databaseName, Database.OPEN_READ_WRITE);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        // create DList and bound by name
        DList list = odmg.newDList();
        db.bind(list, name);
        tx.commit();
        tx = odmg.newTransaction();
        tx.begin();
        Object obj = db.lookup(name);
        tx.commit();
        assertNotNull("binded DList not found", obj);

        tx = odmg.newTransaction();
        tx.begin();
        // add objects to list
        for (int i = 0; i < 5; i++)
        {
            DListObject a = createObject(name);
            list.add(a);
        }
        tx.commit();

        // check current list
        Iterator iter = list.iterator();
        while (iter.hasNext())
        {
            DListObject a = (DListObject) iter.next();
            assertNotNull(a);
        }

        tx = odmg.newTransaction();
        tx.begin();
        ((TransactionExt) odmg.currentTransaction()).getBroker().clearCache();

        // lookup list and check entries
        DList lookedUp = (DList) db.lookup(name);
        assertNotNull("binded DList not found", lookedUp);

        //System.out.println("sequence of items in lookedup list:");
        iter = lookedUp.iterator();
        Iterator iter1 = list.iterator();
        while (iter.hasNext())
        {
            DListObject a = (DListObject) iter.next();
            DListObject b = (DListObject) iter1.next();
            assertNotNull(a);
            assertNotNull(b);
            assertEquals(a.getId(), b.getId());
        }
        tx.commit();

        // add new entries to list
        tx.begin();
        for (int i = 0; i < 3; i++)
        {
            DListObject a = createObject(name + "_new_entry");
            list.add(a);
        }
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        ((TransactionExt) odmg.currentTransaction()).getBroker().clearCache();
        lookedUp = (DList) db.lookup(name);
        iter = lookedUp.iterator();
        iter1 = list.iterator();
        assertEquals("Wrong number of DListEntry found", 8, list.size());
        while (iter.hasNext())
View Full Code Here

    {
        // create a unique name:
        final String name = "testReadAndStore_" + System.currentTimeMillis();

        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        db.open(databaseName, Database.OPEN_READ_WRITE);

        // create test objects
        Transaction tx = odmg.newTransaction();
        tx.begin();
        // add objects to list
        for (int i = 0; i < 5; i++)
        {
            tx.lock(createObject(name), Transaction.WRITE);
        }
        tx.commit();

        tx.begin();
        // query test objects
        OQLQuery q = odmg.newOQLQuery();
        q.create("select all from "+DListObject.class.getName()+" where name=$1");
        q.bind(name);
        Collection ret = (Collection) q.execute();
        // check result list size
        assertEquals(5, ret.size());
View Full Code Here

    {
        // create a unique name:
        final String name = "testAdding_" + System.currentTimeMillis();

        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        db.open(databaseName, Database.OPEN_READ_WRITE);
        // get DList and fill with objects
        DList list = odmg.newDList();
        Transaction tx = odmg.newTransaction();
        tx.begin();
        for (int i = 0; i < 5; i++)
        {
            DListObject a = createObject(name);
            list.add(a);
        }
        // bind the new list
        db.bind(list, name);
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        Object obj = db.lookup(name);
        tx.commit();
        assertNotNull("binded DList not found", obj);

        // iterate list
        Iterator iter = list.iterator();
        while (iter.hasNext())
        {
            DListObject a = (DListObject) iter.next();
            assertNotNull(a);
        }
        assertEquals(5, list.size());

        tx = odmg.newTransaction();
        tx.begin();
        ((TransactionExt) odmg.currentTransaction()).getBroker().clearCache();
        DList lookedUp = (DList) db.lookup(name);
        tx.commit();
        assertNotNull("binded DList not found", lookedUp);

        //System.out.println("sequence of items in lookedup list:");
View Full Code Here

    {
        // create a unique name:
        String name = "testRemoving_" + System.currentTimeMillis();

        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();

        tx.begin();
        DList list = odmg.newDList();
        // bind the list to the name:
        db.bind(list, name);

        for (int i = 0; i < 5; i++)
        {
            DListObject a = createObject(name);
            list.add(a);
        }
        assertEquals(5, list.size());
        tx.commit();

        // delete two items
        tx = odmg.newTransaction();
        tx.begin();
        ((HasBroker) odmg.currentTransaction()).getBroker().clearCache();
        DList lookedUp = (DList) db.lookup(name);
        assertNotNull("database lookup does not find the named DList", lookedUp);
        assertEquals("Wrong number of list entries", 5, lookedUp.size());
        lookedUp.remove(2);
        lookedUp.remove(1);
        tx.commit();

        // check if deletion was successful
        tx = odmg.newTransaction();
        tx.begin();
        ((HasBroker) odmg.currentTransaction()).getBroker().clearCache();
        lookedUp = (DList) db.lookup(name);
        tx.commit();

        assertEquals(3, lookedUp.size());
    }
View Full Code Here

    {
        // create a unique name:
        String name = "testAddingWithIndex_" + System.currentTimeMillis();

        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();

        tx.begin();
        DList list = odmg.newDList();
        db.bind(list, name);
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        for (int i = 0; i < 5; i++)
        {
            DListObject a = createObject(name);
            list.add(a);
        }

        list.add(2, createObject(name+"_pos2"));
        list.add(0, createObject(name+"_pos0"));
        list.add(7, createObject(name+"_pos7"));
        tx.commit();

        tx.begin();
        ((TransactionImpl) tx).getBroker().clearCache();
        // System.out.println("list: " + list);
        // System.out.println("lookup list: " + db.lookup(name));
        tx.commit();

        //System.out.println("sequence of items in list:");
        Iterator iter = list.iterator();
        DListObject a;
        while (iter.hasNext())
        {
            a = (DListObject) iter.next();
            assertNotNull(a);
            //System.out.print(a.getArticleId() + ", ");
        }


        tx = odmg.newTransaction();
        tx.begin();
        ((TransactionImpl) tx).getBroker().clearCache();
        DList lookedUp = (DList) db.lookup(name);
        // System.out.println("lookup list: " + lookedUp);
        assertNotNull("database lookup does not find DList", lookedUp);
View Full Code Here

TOP

Related Classes of org.odmg.Implementation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.