Package org.odmg

Examples of org.odmg.Database


     * The lookup is done one by one, that is: a primary key based lookup is used.
     */
    protected void readArticles() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        long start = System.currentTimeMillis();
        db.open(databaseName, Database.OPEN_READ_ONLY);
        Transaction tx = odmg.newTransaction();
        tx.begin();
        for (int i = 0; i < articleCount; i++)
        {
            OQLQuery query = odmg.newOQLQuery();
            String sql = "select allArticles from " + PerformanceArticle.class.getName() + " where articleId=" + i;
            query.create(sql);
            query.execute();
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        db.close();
        logger.info("querying " + articleCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here


        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker.clearCache();
        broker.close();

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        OQLQuery query = odmg.newOQLQuery();
        String sql = "select allArticles from " + PerformanceArticle.class.getName() + " where articleId between " + new Integer(offsetId) + " and " + new Integer(offsetId + articleCount);
        query.create(sql);
        long start = System.currentTimeMillis();
        ManageableCollection collection = (ManageableCollection) query.execute();
        Iterator iter = collection.ojbIterator();
        int fetchCount = 0;
        while (iter.hasNext())
        {
            fetchCount++;
            PerformanceArticle a = (PerformanceArticle) iter.next();
        }
        long stop = System.currentTimeMillis();
        db.close();
        logger.info("fetching " + fetchCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

     * All objects are modified and changes are written to the RDBMS with an UPDATE.
     */
    protected void updateExistingArticles() 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();
        // update all objects
        for (int i = 0; i < articleCount; i++)
View Full Code Here

     * test getting all (make sure basic operation is still functional)
     */
    public void testGetProjectionAttribute() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        try
        {
            createData(db, odmg);

            // 3. Get a list of some articles
View Full Code Here

     * test that we can create 2 objects that have a bidirectional association in ODMG API
     */
    public void testCreateWithUpdate() throws ODMGException
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();
        long currentTime = System.currentTimeMillis();

        BidirectionalAssociationObjectA a = new BidirectionalAssociationObjectA();
        a.setPk("A" + currentTime);
        BidirectionalAssociationObjectB b = new BidirectionalAssociationObjectB();
        b.setPk("B" + currentTime);

        tx.begin();
        db.makePersistent(a);
        db.makePersistent(b);
        tx.commit();

        tx.begin();
        tx.lock(a, Transaction.WRITE);
        tx.lock(b, Transaction.WRITE);
View Full Code Here

     * @throws ODMGException
     */
    public void NOTWORKINGtestCreateWithoutUpdate() throws ODMGException
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();
        long currentTime = System.currentTimeMillis();
        BidirectionalAssociationObjectA a = new BidirectionalAssociationObjectA();
        a.setPk("A" + currentTime);
        BidirectionalAssociationObjectB b = new BidirectionalAssociationObjectB();
        b.setPk("B" + currentTime);

        tx.begin();
        b.setRelatedA(a);
        a.setRelatedB(b);
        db.makePersistent(a);
        db.makePersistent(b);
        tx.commit();

        /**
         * now make sure they are in db, A first, then B
         */
 
View Full Code Here

         */
        testDeleteA();
        testDeleteB();
        testCreateWithUpdate();
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        OQLQuery query = odmg.newOQLQuery();
        int i = 0;
        query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
View Full Code Here

         */
        testDeleteA();
        testDeleteB();
        testCreateWithUpdate();
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        OQLQuery query = odmg.newOQLQuery();
        int i = 0;
        query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
View Full Code Here

         * create at least one A/B
         */
        testCreateWithUpdate();

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        OQLQuery query = odmg.newOQLQuery();
        query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
        ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();

        while (it.hasNext())
        {
            a = (BidirectionalAssociationObjectA)it.next();
            b = a.getRelatedB();
            if (b != null)
            {
                tx.lock(b, Transaction.WRITE);
                b.setRelatedA(null);   // break relationship to avoid ri violation
            }
            db.deletePersistent(a);
        }

        tx.commit();
    }
View Full Code Here

        /**
         * create at least one A/B
         */
        testCreateWithUpdate();
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        OQLQuery query = odmg.newOQLQuery();
        query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
        ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();

        while (it.hasNext())
        {
            b = (BidirectionalAssociationObjectB)it.next();
            a = b.getRelatedA();
            if (a != null)
            {
                tx.lock(a, Transaction.WRITE);
                a.setRelatedB(null);    // break relationship to avoid ri violation
            }
            db.deletePersistent(b);
        }

        tx.commit();
    }
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.