Package org.odmg

Examples of org.odmg.Database


        protected void readFarAwaysByCursor() throws Exception
        {
            long start = System.currentTimeMillis();
            int farAway_id = arrFarAway[0].getId();

            Database db = ojb.newDatabase();
            db.open(databaseNameFarAway, Database.OPEN_READ_WRITE);
            Transaction tx = ojb.newTransaction();
            tx.begin();
            OQLQuery query = ojb.newOQLQuery();
            String sql = "select allFarAways from " + FarAwayClass.class.getName() +
                    " where name = \"" + PRE_NAME + threadName + "\"";
            query.create(sql);
            DList allFarAways = (DList) query.execute();
            tx.commit();
            Iterator iter = allFarAways.iterator();
            int fetchCount = 0;
            while (iter.hasNext())
            {
                fetchCount++;
                FarAwayClass a = (FarAwayClass) iter.next();
            }
            db.close();
            long stop = System.currentTimeMillis();
            times[2] = times[2] + (stop - start);
        }
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
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:");
        iter = lookedUp.iterator();
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);
        assertEquals(8, lookedUp.size());
        iter = lookedUp.iterator();
        while (iter.hasNext())
View Full Code Here

    public void testDBag() throws Exception
    {
        String name = "testDBag_" + 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();
        DBag bag1 = odmg.newDBag();
        DBag bag2 = odmg.newDBag();
        DListObject a, b, c, d, e;
View Full Code Here

        String name = "testDSet_" + System.currentTimeMillis();
        String set_1 = "set_1_" + System.currentTimeMillis();
        String set_2 = "set_2_" + 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();

        DListObject a, b, c, d, e;
        a = createObject(name);
        b = createObject(name);
        c = createObject(name);
        d = createObject(name);
        e = createObject(name);

        DSet set1 = odmg.newDSet();
        DSet set2 = odmg.newDSet();

        set1.add(a);
        set1.add(b);
        set1.add(c);

        set2.add(b);
        set2.add(c);
        set2.add(d);
        set2.add(e);

        db.bind(set1, set_1);
        db.bind(set2, set_2);
        tx.commit();

        // low lookup both sets
        tx = odmg.newTransaction();
        tx.begin();
        ((HasBroker) tx).getBroker().clearCache();
        DSet set1a = (DSet) db.lookup(set_1);
        DSet set2a = (DSet) db.lookup(set_2);

        // check looked up sets
        assertTrue(set1a.containsAll(set1));
        assertTrue(set2a.containsAll(set2));
View Full Code Here

     * deletes all PerformanceArticle created by <code>insertNewArticles</code>.
     */
    protected void deleteArticles() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();
        long start = System.currentTimeMillis();
        tx.begin();
        for (int i = 0; i < articleCount; i++)
        {
            db.deletePersistent(arr[i]);
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        db.close();
        logger.info("deleting " + articleCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

     */
    protected void insertNewArticles() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();
        long start = System.currentTimeMillis();
        tx.begin();
        for (int i = 0; i < articleCount; i++)
        {
            db.makePersistent(arr[i]);
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        db.close();
        logger.info("inserting " + articleCount + " Objects: " + (stop - start) + " msec");
    }
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.