Package org.odmg

Examples of org.odmg.Database


            {
                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();
            assertEquals(1, result.size());
            site = (Site) result.get(0);
            assertNotNull(site);
            assertNotNull("year should not be null", site.getYear());
            tx.commit();

            db.close();
        }
        finally
        {
            // reset configuration
            if(restore)
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();

          txn.begin();
          txn.getBroker().clearCache();
          Identity mumId = txn.getBroker().serviceIdentity().buildIdentity(mum);
          Person mum2 = (Person)txn.getBroker().getObjectByIdentity(mumId);
          // System.out.println("retrieved: " + mum2);
          txn.commit();
          db.close();
          assertNotNull(mum2);
          assertEquals(name, mum2.getFirstname());
      }
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());
      }
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());
      }
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();
            db.deletePersistent(art2);
            tx.commit();
            db.close();
//        log.info("End init performance test");
        }
    }
View Full Code Here

        }

        protected void deleteArticles() throws Exception
        {
            long start = System.currentTimeMillis();
            Database db = ojb.newDatabase();
            db.open(databaseName, Database.OPEN_READ_WRITE);
            for (int i = 0; i < arr.length; i++)
            {
                Transaction tx = ojb.newTransaction();
                tx.begin();
                db.deletePersistent(arr[i]);
                tx.commit();
            }
            db.close();
            long stop = System.currentTimeMillis();
            times[3] = times[3] + (stop - start);
        }
View Full Code Here

        }

        protected void deleteFarAways() throws Exception
        {
            long start = System.currentTimeMillis();
            Database db = ojb.newDatabase();
            db.open(databaseNameFarAway, Database.OPEN_READ_WRITE);
            for (int i = 0; i < arr.length; i++)
            {
                Transaction tx = ojb.newTransaction();
                tx.begin();
                db.deletePersistent(arrFarAway[i]);
                tx.commit();
            }
            db.close();
            long stop = System.currentTimeMillis();
            times[3] = times[3] + (stop - start);
        }
View Full Code Here

        }

        protected void insertNewArticles() throws Exception
        {
            long start = System.currentTimeMillis();
            Database db = ojb.newDatabase();
            db.open(databaseName, Database.OPEN_READ_WRITE);
            for (int i = 0; i < arr.length; i++)
            {
                Transaction tx = ojb.newTransaction();
                tx.begin();
                tx.lock(arr[i], Transaction.WRITE);
                tx.commit();
            }
            db.close();
            long stop = System.currentTimeMillis();
            times[1] = times[1] + (stop - start);
        }
View Full Code Here

        }

        protected void insertNewFarAways() throws Exception
        {
            long start = System.currentTimeMillis();
            Database db = ojb.newDatabase();
            db.open(databaseNameFarAway, Database.OPEN_READ_WRITE);
            for (int i = 0; i < arr.length; i++)
            {
                Transaction tx = ojb.newTransaction();
                tx.begin();
                tx.lock(arrFarAway[i], Transaction.WRITE);
                tx.commit();
            }
            db.close();
            long stop = System.currentTimeMillis();
            times[1] = times[1] + (stop - start);
        }
View Full Code Here

        protected void readArticlesByCursor() throws Exception
        {
            long start = System.currentTimeMillis();
            int artId = arr[0].articleId;

            Database db = ojb.newDatabase();
            db.open(databaseName, Database.OPEN_READ_WRITE);

            Transaction tx = ojb.newTransaction();
            tx.begin();
            OQLQuery query = ojb.newOQLQuery();
            String sql = "select allArticles from " + PerformanceArticle.class.getName() +
                    " where articleName = \"" + PRE_NAME + threadName + "\"";
            query.create(sql);
            DList allProducts = (DList) query.execute();
            tx.commit();

            Iterator iter = allProducts.iterator();
            int fetchCount = 0;
            while (iter.hasNext())
            {
                fetchCount++;
                PerformanceArticle a = (PerformanceArticle) iter.next();
            }
            db.close();
            long stop = System.currentTimeMillis();
            times[2] = times[2] + (stop - start);
        }
View Full Code Here

TOP

Related Classes of org.odmg.Database

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.