Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.PersistenceBroker


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


            Article example = new Article();
            example.setArticleId(30);
            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();
View Full Code Here

    public void YYYtestBrokerCrash()
    {
        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        PersistenceBroker broker = null;
        ClassDescriptor cld = null;
        String tablename = null;

        //open database
        try
        {
            db.open(databaseName, Database.OPEN_READ_WRITE);
        }
        catch (ODMGException ex)
        {
            fail("ODMGException: " + ex.getMessage());
        }
        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();

            // retrieve an Article
            OQLQuery query = odmg.newOQLQuery();
            query.create("select anArticle from " + Article.class.getName() + " where articleId = $678");
            query.bind(new Integer(30));
            List results = (List) query.execute();
            Article a = (Article) results.get(0);

            // manipulate metadata
            broker = ((TransactionImpl) tx).getBroker();
            cld = broker.getClassDescriptor(Article.class);
            tablename = cld.getFullTableName();
            cld.setTableName("ELVIS");
            broker.getDescriptorRepository().setClassDescriptor(cld);

            //broker will crash as metadata is corrupt
            a.addToStock(5);
            tx.commit();
            fail("Can commit tx with corrupt metadata");
        }
        catch (Throwable t)
        {
            //ignore
        }
        finally
        {
            cld.setTableName(tablename);
            broker.getDescriptorRepository().setClassDescriptor(cld);
        }

    }
View Full Code Here

        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
        ctx.setRollbackOnly();
        throw new EJBException("Set rollback only");
    }
View Full Code Here

     * for given class, using the PB-api within
     * ODMG - this may change in further versions.
     */
    public int getCount(Class target)
    {
        PersistenceBroker broker = ((HasBroker) odmg.currentTransaction()).getBroker();
        int result = broker.getCount(new QueryByCriteria(target, null));
        return result;
    }
View Full Code Here

     * Return the count of all objects found
     * for given class.
     */
    public int getCount(Class target)
    {
        PersistenceBroker broker = getBroker();
        int result;
        try
        {
            result = broker.getCount(new QueryByCriteria(target, null));
        }
        finally
        {
            if (broker != null) broker.close();
        }
        return result;
    }
View Full Code Here

    /**
     * Return all objects for the given class.
     */
    public Collection getAllObjects(Class target)
    {
        PersistenceBroker broker = getBroker();
        Collection result;
        try
        {
            Query q = new QueryByCriteria(target, null);
            result = broker.getCollectionByQuery(q);
        }
        finally
        {
            if (broker != null) broker.close();
        }
        return result;
    }
View Full Code Here

    /**
     * Store an object.
     */
    public Object storeObject(Object object)
    {
        PersistenceBroker broker = getBroker();
        try
        {
            broker.store(object);
        }
        finally
        {
            if (broker != null) broker.close();
        }
        return object;
    }
View Full Code Here

    /**
     * Delete an object.
     */
    public void deleteObject(Object object)
    {
        PersistenceBroker broker = null;
        try
        {
            broker = getBroker();
            broker.delete(object);
        }
        finally
        {
            if (broker != null) broker.close();
        }
    }
View Full Code Here

    /**
     * Store a collection of objects.
     */
    public Collection storeObjects(Collection objects)
    {
        PersistenceBroker broker = null;
        Collection stored;
        try
        {
            broker = getBroker();
            stored = this.storeObjects(broker, objects);
        }
        finally
        {
            if (broker != null) broker.close();
        }
        return stored;
    }
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.PersistenceBroker

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.