Examples of TransactionExt


Examples of org.apache.ojb.odmg.TransactionExt

    {
        /* One possibility of storing objects is to use the current transaction
         associated with the container */
        try
        {
            TransactionExt tx = (TransactionExt) odmg.currentTransaction();
            tx.lock(object, Transaction.WRITE);
            tx.markDirty(object);
        }
        catch (LockNotGrantedException e)
        {
            log.error("Failure while storing object " + object, e);
            throw new OJBRuntimeException("Failure while storing object", e);
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

        /*
        store list of objects, then get these objects with Iterator, start
        iteration, then break
        */
        storeObjects(objectsToStore);
        TransactionExt tx = ((TransactionExt) getImplementation().currentTransaction());
        // force writing to DB
        tx.flush();
        Class searchClass = objectsToStore.get(0).getClass();
        PersistenceBroker broker = tx.getBroker();
        Query q = new QueryByCriteria(searchClass);
        // we get the iterator and step into the first found object
        Iterator it = broker.getIteratorByQuery(q);
        it.next();
        /*
 
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

    {
        /* One possibility of storing objects is to use the current transaction
         associated with the container */
        try
        {
            TransactionExt tx = (TransactionExt) odmg.currentTransaction();
            tx.lock(object, Transaction.WRITE);
            tx.markDirty(object);
        }
        catch (LockNotGrantedException e)
        {
            log.error("Failure while storing object " + object, e);
            throw new EJBException("Failure while storing object", e);
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

     * 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
    {
        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        // we don't want implicite locks when compare performance
        tx.setImplicitLocking(false);
        String sql = "select allArticles from " + PerformanceArticle.class.getName() + " where articleId=$1";
        long start = System.currentTimeMillis();
        tx.begin();
        for(int i = 0; i < articleCount; i++)
        {
            OQLQuery query = odmg.newOQLQuery();
            query.create(sql);
            query.bind(arr[i].getArticleId());
            query.execute();
        }
        tx.commit();
        long stop = System.currentTimeMillis();
        logger.info("querying " + articleCount + " Objects: " + (stop - start) + " msec");
    }
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

     * that is: a between Statement is used to select all inserted PerformanceArticles
     * and Objects are read in by fetching from the cursor (JDBC ResultSet).
     */
    protected void readArticlesByCursor() throws Exception
    {
        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        // we don't want implicite locks when compare performance
        tx.setImplicitLocking(false);
        tx.begin();
        // clear cache to read from DB
        tx.getBroker().clearCache();

        long start = System.currentTimeMillis();
        OQLQuery query = odmg.newOQLQuery();
        String sql = "select allArticles from " + PerformanceArticle.class.getName()
                + " where articleId between " + new Integer(offsetId) + " and "
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);

        TransactionExt tx = (TransactionExt) odmg.newTransaction();
        tx.begin();
        db.makePersistent(s_ref_4);
        db.makePersistent(obj_2);
        tx.commit();

        tx.begin();

        // try to find object
        Criteria crit = new Criteria();
        crit.addEqualTo("name", name);
        QueryByCriteria query = QueryFactory.newQuery(MainObject.class, crit);

        int result = tx.getBroker().getCount(query);
        assertEquals("Wrong object count", 1, result);
        // pk have to set and have to be different
        assertNotNull(obj_2.getIdentifier());
        assertTrue(obj_2.getIdentifier().longValue() > 0);
        // no collection reference set
        List references = obj_2.getAllReferences();
        assertTrue(references == null || references.size() == 0);
        // get Identity objects
        Identity oid_2 = tx.getBroker().serviceIdentity().buildIdentity(obj_2);
        // get identifier (PK) values
        Long id_2 = obj_2.getIdentifier();

        tx.getBroker().clearCache();
        obj_2 = (MainObject) tx.getBroker().getObjectByIdentity(oid_2);

        assertTrue(obj_2.getIdentifier().longValue() > 0);
        assertNotNull(obj_2.getSingleReference());
        assertTrue(obj_2.getSingleReference().getId().longValue() > 0);
        // no collection reference set
        references = obj_2.getAllReferences();
        assertTrue(references == null || references.size() == 0);

        tx.getBroker().clearCache();
        // get references only
        Criteria crit_2 = new Criteria();
        crit_2.addEqualTo("refName", nameRef);
        QueryByCriteria query_2 = QueryFactory.newQuery(CollectionReference.class, crit_2);
        int result_2 = tx.getBroker().getCount(query_2);

        assertEquals(0, result_2);

        tx.getBroker().clearCache();
        // get object
        MainObject retObj = (MainObject) tx.getBroker().getObjectByIdentity(oid_2);

        List refList = retObj.getAllReferences();
        assertNotNull(refList);
        assertEquals("object do not have references", 0, refList.size());
        tx.commit();

        // add new reference to object
        CollectionReference ref_6 = new CollectionReference(null, "###_new_" + nameRef);
        tx.begin();
        tx.lock(obj_2, Transaction.WRITE);
        obj_2.addReference(ref_6);
        tx.commit();

        references = obj_2.getAllReferences();
        assertNotNull(references);
        assertEquals("1 references expected for object: "+obj_2, 1, references.size());


        assertNotNull(ref_6.getRefIdentifier());
        // check FK setting
        Long fk = ref_6.getFkIdentifier();
        assertNotNull(fk);
        assertEquals(obj_2.getIdentifier(), fk);
        assertEquals(id_2, obj_2.getIdentifier());
        references = obj_2.getAllReferences();
        assertNotNull(references);
        assertEquals("1 references expected for object: "+obj_2, 1, references.size());
        assertNotNull(references);

        tx.begin();
        obj_2 = (MainObject) tx.getBroker().getObjectByIdentity(oid_2);
        // we don't change the main object, only add an reference, so the
        // cached version of the object isn't up to date
        tx.getBroker().retrieveAllReferences(obj_2);
        tx.commit();

        assertNotNull(obj_2);
        references = obj_2.getAllReferences();
        assertNotNull(references);
        assertEquals("Reference expected for object", 1, references.size());

        assertEquals(id_2, obj_2.getIdentifier());

        // now update main objects
        tx.begin();
        tx.lock(obj_2, Transaction.WRITE);
        obj_2.setName(name+"_update");
        tx.commit();

        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
        broker.close();

        assertNotNull(obj_2);
        assertEquals(obj_2.getName(), name+"_update");
        assertEquals(id_2, obj_2.getIdentifier());

        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
        broker.close();

        // now update reference
        assertNotNull(obj_2);
        tx.begin();
        tx.lock(obj_2, Transaction.WRITE);
        references = obj_2.getAllReferences();
        CollectionReference ref = (CollectionReference) references.get(0);
        tx.lock(ref, Transaction.WRITE);
        ref.setRefName(nameRef+"_update");
        tx.commit();

        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        obj_2 = (MainObject) broker.getObjectByIdentity(oid_2);
        assertNotNull(obj_2);
        references = obj_2.getAllReferences();
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

        /*
        store list of objects, then get these objects with Iterator, start
        iteration, then break
        */
        storeObjects(objects);
        TransactionExt tx = ((TransactionExt) odmg.currentTransaction());
        // force writing to DB
        tx.flush();
        Class searchClass = objects.get(0).getClass();
        PersistenceBroker broker = tx.getBroker();
        Query q = new QueryByCriteria(searchClass, new Criteria());
        // we get the iterator and step into the first found object
        Iterator it = broker.getIteratorByQuery(q);
        it.next();
        // now the iterator resources may not release, see what's going on
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

    {
        /* One possibility of storing objects is to use the current transaction
         associated with the container */
        try
        {
            TransactionExt tx = (TransactionExt) odmg.currentTransaction();
            tx.lock(object, Transaction.WRITE);
            tx.markDirty(object);
        }
        catch (LockNotGrantedException e)
        {
            log.error("Failure while storing object " + object, e);
            throw new OJBRuntimeException("Failure while storing object", e);
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

     * @param product The product to update in the database
     */
    public static void persistChanges(Product product)
    {
        Implementation impl = OJB.getInstance();
        TransactionExt tx  = (TransactionExt)impl.newTransaction();

        tx.begin();
        tx.markDirty(product);
        tx.commit();
    }
View Full Code Here

Examples of org.apache.ojb.odmg.TransactionExt

        When PB kernel fill DList with DListEntry, the DListEntry needs to know the current
        used PBKey, because we need to lookup the real objects when user iterates the list,
        thus we need the associated PBKey to find right PB/DB connection.
        TODO: Find a better solution
        */
        TransactionExt tx = TxManagerFactory.instance().getTransaction();
        if(tx == null)
        {
            getLog().info("Can't find running transaction to lookup current associated PBKey");
        }
        else
        {
            this.pbKey = tx.getBroker().getPBKey();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.