Package org.odmg

Examples of org.odmg.Implementation


    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;
        a = createObject(name);
        b = createObject(name);
        c = createObject(name);
        d = createObject(name);
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);
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]);
View Full Code Here

     * The number of objects to create is defined by <code>articleCount</code>.

     */
    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]);
View Full Code Here

     * been inserted by <code>insertNewArticles()</code>.
     * 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();
View Full Code Here

        // clear the cache
        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();
View Full Code Here

     * updates all PerformanceArticles inserted by <code>insertNewArticles()</code>.
     * 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
            Transaction tx = odmg.newTransaction();
            tx.begin();

            OQLQuery query = odmg.newOQLQuery();
            String sql = "select aPerson.firstname, aPerson.lastname from " + org.apache.ojb.broker.Person.class.getName();
            query.create(sql);

            ManageableCollection result = (ManageableCollection) query.execute();

            // Iterator over the restricted articles objects
            java.util.Iterator it = result.ojbIterator();
            int i = 0;
            while (it.hasNext())
            {
                Object[] res = (Object[]) it.next();
                String firstname = (String) res[0];
                String lastname = (String) res[1];
               
                i++;
            }
            if (i < COUNT)
                fail("Should have found at least " + COUNT + " items");

            OQLQuery query1 = odmg.newOQLQuery();
            query1.create("select distinct anArticle.productGroup.groupId from " + Article.class.getName());
            List result1 = (List) query1.execute();
            for (it = result1.iterator(); it.hasNext(); )
            {
                it.next();
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);
        a.setRelatedB(b);
        b.setRelatedA(a);
        tx.commit();

         /**
         * now make sure they are in db, A first, then B
         */
        tx.begin();
        OQLQuery query = odmg.newOQLQuery();
        int i = 0;
        query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName() + " where pk=$1");
        query.bind("A"+currentTime);
        ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();
        while (it.hasNext())
        {
            i++;
            a = (BidirectionalAssociationObjectA) it.next();
            if (a.getRelatedB() == null)
                fail("a should have had a related b");
        }
        if (i > 1)
            fail("should have found only one bidirectionalAssociationObjectA, instead found: " + i);

        query = odmg.newOQLQuery();
        i = 0;
        query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName() + " where pk=$1");
        query.bind("B"+currentTime);
        all = (ManageableCollection) query.execute();
        it = all.ojbIterator();
View Full Code Here

     * this test doesn't work as OJB won't do the insert then execute the update.
     * @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
         */
        tx.begin();
        OQLQuery query = odmg.newOQLQuery();
        int i = 0;
        query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName() + " where pk=$1");
        query.bind("A"+currentTime);
         ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();
        while (it.hasNext())
        {
            i++;
            it.next();
        }
        if (i > 1)
            fail("should have found only one bidirectionalAssociationObjectA, instead found: " + i);

        query = odmg.newOQLQuery();
        i = 0;
        query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName() + " where pk=$1");
        query.bind("B"+currentTime);
        all = (ManageableCollection) query.execute();
        it = all.ojbIterator();
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.