Package org.odmg

Examples of org.odmg.Database


    }

    public void testSimpleQueryDelete() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        String name = "testSimpleQueryDelete - " + System.currentTimeMillis();

        db.open(databaseName, Database.OPEN_READ_WRITE);
        Site site = new Site();
        site.setName(name);
        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(site, Transaction.WRITE);
        tx.commit();

        OQLQuery query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
        tx.begin();
        List result = (List) query.execute();
        if (result.size() == 0)
        {
            fail("Stored object not found");
        }
        tx.commit();

        tx.begin();
        db.deletePersistent(site);
        tx.commit();

        query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
View Full Code Here


            {
                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.UPGRADE);
            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

      public void testStoreRetrieveSameTxn()
      {
        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());
          }

          Person mum = new PersonImpl();
          TransactionImpl txn = (TransactionImpl)odmg.newTransaction();
          txn.begin();
          txn.lock(mum, Transaction.WRITE);
          System.out.println("locked for write: " + mum);
          Identity mumId = new Identity(mum, txn.getBroker());
          txn.commit();
          txn.begin();

          Person mum2 = (Person)txn.getObjectByIdentity(mumId);
          System.out.println("retrieved: " + mum2);
          txn.commit();
          db.close();
        }
        catch (Exception exc)
        {
          exc.printStackTrace();
          fail("caught unexpected exception: " + exc.toString());
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

        {
            databaseName = TestHelper.DEF_DATABASE_NAME;

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

            tx1 = (TransactionImpl) odmg.newTransaction();
            tx2 = (TransactionImpl) odmg.newTransaction();
            tx1.begin();
            tx2.begin();
View Full Code Here

        MainObject obj_1 = new MainObject(null, name);
        MainObject obj_2 = new MainObject(null, name);
        MainObject obj_3 = new MainObject(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);
View Full Code Here

    /**TestThreadsNLocks state transition of modification states*/
    public void testModificationStates()
    {
        // get facade instance
        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());
        }
        ModificationState oldState = StateNewClean.getInstance();
        ModificationState newState = oldState.markDirty();
        assertEquals(StateNewDirty.getInstance(), newState);

        oldState = newState;
        newState = oldState.markDirty();
        assertEquals(oldState, newState);

        // close database
        try
        {
            db.close();
        }
        catch (ODMGException ex)
        {
            fail("ODMGException: " + ex.getMessage());
        }
View Full Code Here

    public void testOdmgSession()
    {
        // get facade instance
        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());
        }
        Transaction tx = odmg.newTransaction();

        //perform transaction
        try
        {
            tx.begin();

            ProductGroup pg = new ProductGroup();
            pg.setName("PG A");
            Article example = new Article();
            example.setProductGroup(pg);
            pg.addArticle(example);
            db.makePersistent(pg);

            // modify Object after persist call is allowed
            example.setStock(333);
            example.addToStock(47);
            example.addToStock(7);
            example.addToStock(4);

            //System.out.println("now commit all changes...");
            tx.commit();
        }
        catch (Exception ex)
        {
            tx.abort();
        }

        // close database
        try
        {
            db.close();
        }
        catch (ODMGException ex)
        {
            fail("ODMGException: " + ex.getMessage());
        }
View Full Code Here

    public void testOQLQuery()
    {
        // get facade instance
        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());
        }
        Transaction tx = odmg.newTransaction();

        //perform transaction
        try
        {
            tx.begin();

            OQLQuery query = odmg.newOQLQuery();
            query.create("select anArticle from " + Article.class.getName() + " where articleId = 60");
            List results = (List) query.execute();

            Article a = (Article) results.get(0);

            // cross check with PersistenceBroker lookup
            // 1. get OID
            Article example = new Article();
            example.setArticleId(60);
            Identity oid = new Identity(example, ((TransactionImpl) tx).getBroker());
            // 2. lookup object by OID
            PersistenceBroker broker = ((TransactionImpl) tx).getBroker();
            broker.clearCache();
            Article b = (Article) broker.getObjectByIdentity(oid);

            assertEquals("should be same object", a, b);

            //System.out.println("now commit all changes...");
            tx.commit();
        }
        catch (Exception ex)
        {
            tx.abort();
            fail("ODMGException: " + ex.getMessage());
        }

        // close database
        try
        {
            db.close();
        }
        catch (ODMGException ex)
        {
            fail("ODMGException: " + ex.getMessage());
        }
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.