Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.ManageableCollection


        // 3. Get a list of some articles
        Transaction tx = odmg.newTransaction();

        OQLQuery query = odmg.newOQLQuery();
        ManageableCollection all = null;
        java.util.Iterator it = null;
        int i = 0;
        query.create("select effectiveness from " + org.apache.ojb.broker.Effectiveness.class.getName());

        /**
         * try doing this as part of one transaction, ODMG should figure out
         * which order to delete in.
         */
        all = (ManageableCollection) query.execute();
        // Iterator over the restricted articles objects
        it = all.ojbIterator();
        Effectiveness eff = null;
        Version ver = null;
        Contract contract = null;
        while (it.hasNext())
        {
            eff = (Effectiveness) it.next();
            ver = eff.getVersion();
            contract = ver.getContract();

            tx.begin();
            database.deletePersistent(eff);
            tx.commit();

            tx.begin();
            database.deletePersistent(ver);
            tx.commit();

            tx.begin();
            database.deletePersistent(contract);
            tx.commit();
            // keep the count
            i++;
        }
        if (i < COUNT)
            fail("Should have found at least " + COUNT + " items to delete, only found " + i);
        /**
         * run query again, should get 0 results.
         */
        query.create("select contracts from " + org.apache.ojb.broker.Contract.class.getName());
        ManageableCollection allContracts = (ManageableCollection) query.execute();
        allContracts = (ManageableCollection) query.execute();
        it = allContracts.ojbIterator();
        if (it.hasNext())
        {
            fail("all contracts should have been removed, we found one.");
        }
    }
View Full Code Here


        // 3. Get a list of some articles
        Transaction tx = odmg.newTransaction();

        OQLQuery query = odmg.newOQLQuery();
        ManageableCollection all = null;
        java.util.Iterator it = null;
        int i = 0;
        query.create("select effectiveness from " + org.apache.ojb.broker.Effectiveness.class.getName());

        /**
         * try doing this as part of one transaction, ODMG should figure out
         * which order to delete in.
         */
        all = (ManageableCollection) query.execute();
        // Iterator over the restricted articles objects
        it = all.ojbIterator();
        Effectiveness eff = null;
        Version ver = null;
        Contract contract = null;
        /**
         * should mark all these objects for delete then on commit
         * ODMG should make sure they get deleted in proper order
         */
        tx.begin();
        while (it.hasNext())
        {
            eff = (Effectiveness) it.next();
            ver = eff.getVersion();
            contract = ver.getContract();
            /**
             * should mean that version and effectivedate are cascade deleted.
             */
            database.deletePersistent(contract);
            i++;
        }
        /**
         * commit all changes.
         */
        tx.commit();
        if (i < COUNT)
            fail("Should have found at least " + COUNT + " effectiveness to delete, only found " + i);
        /**
         * run query again, should get 0 results.
         */
        query.create("select contracts from " + org.apache.ojb.broker.Contract.class.getName());
        ManageableCollection allContracts = (ManageableCollection) query.execute();
        allContracts = (ManageableCollection) query.execute();
        it = allContracts.ojbIterator();
        if (it.hasNext())
        {
            fail("all contracts should have been removed, we found one.");
        }
    }
View Full Code Here

        OQLQuery query = odmg.newOQLQuery();
        String sql = "select effectiveness from " + Effectiveness.class.getName();
        query.create(sql);

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

        // Iterator over the restricted articles objects
        java.util.Iterator it = allEffectiveness.ojbIterator();
        int i = 0;
        while (it.hasNext())
        {
            Effectiveness value = (Effectiveness) it.next();
            /**
 
View Full Code Here

        OQLQuery query = odmg.newOQLQuery();
        String sql = "select version from " + org.apache.ojb.broker.Version.class.getName() + " where pk=$1";
        query.create(sql);
        query.bind("version1");
        tx.begin();
        ManageableCollection results = (ManageableCollection) query.execute();
        // Iterator over the restricted articles objects
        java.util.Iterator it = results.ojbIterator();
        Version ver1 = null;
        while (it.hasNext())
        {
            ver1 = (Version) it.next();
            if (!ver1.getContract().getPk().equals(contract2.getPk()))
            {
                fail(ver1.getPk() + " should have pointed to contract2 instead it pointed to: " + ver1.getContract().getPk());
            }
        }
        tx.commit();

        OQLQuery query2 = odmg.newOQLQuery();
        String sql2 = "select version from " + org.apache.ojb.broker.Version.class.getName() + " where pk=$1";
        query2.create(sql2);
        query2.bind("version2");
        tx.begin();
        results = (ManageableCollection) query2.execute();
        // Iterator over the restricted articles objects
        java.util.Iterator it2 = results.ojbIterator();
        Version ver2 = null;
        while (it2.hasNext())
        {
            ver2 = (Version) it2.next();
            if (!ver2.getContract().getPk().equals(contract.getPk()))
View Full Code Here

            throws ClassNotPersistenceCapableException, PersistenceBrokerException
    {
        if (log.isDebugEnabled()) log.debug("getCollectionByQuery (" + collectionClass + ", " + itemClass + ", " + query + ")");

        ClassDescriptor cld = pb.getClassDescriptor(itemClass);
        ManageableCollection result = null;
        OJBIterator iter = null;
        int fullSize = -1;
        int size = 0;

        final boolean isRetrievalTasksCreated = batchRetrieval && m_retrievalTasks == null;
        if (isRetrievalTasksCreated)
        {
            // Maps ReferenceDescriptors to HashSets of owners
            m_retrievalTasks = new HashMap();
        }

        // ==> enable materialization cache
        pb.getInternalCache().enableMaterializationCache();
        try
        {
            result = (ManageableCollection) collectionClass.newInstance();
           
            // now iterate over all elements and add them to the new collection
            // lifecycle events are disabled
            iter = pb.getIteratorFromQuery(query, cld);
            iter.disableLifeCycleEvents();

            // BRJ : get fullSizefor Query
            // to be removed when Query.fullSize is removed
            if (iter instanceof PagingIterator)
            {
                fullSize = iter.fullSize();
            }

            while (iter.hasNext())
            {
                Object candidate = iter.next();

                /**
                 * MBAIRD
                 * candidate CAN be null in the case of materializing from an iterator based
                 * on a query for a class that is mapped to a table that has other classes
                 * mapped to that table as well, but aren't extents.
                 */
                if (candidate != null)
                {
                    IndirectionHandler handler = ProxyHelper.getIndirectionHandler(candidate);

                    if ((handler != null) || itemClass.isAssignableFrom(candidate.getClass()))
                    {
                        result.ojbAdd(candidate);

                        // BRJ: count added objects
                        // to be removed when Query.fullSize is removed
                        size++;
                    }
                    else
                    {
                        //warn the user
                        log.warn("Candidate object ["+candidate
                                    +"] class ["+candidate.getClass().getName()
                                    +"] is not a subtype of ["+itemClass.getName()
                                    +"] or any type of proxy. NOT INCLUDED in result collection");
                    }
                    if (prefetchProxies && (handler != null)
                            && (cld.getProxyPrefetchingLimit() > 0)
                            && addRetrievalTask(candidate, this))
                    {
                        new PBMaterializationListener(candidate, m_retrievalTasks,
                                this, cld.getProxyPrefetchingLimit());
                    }
                }
            }

            if (isRetrievalTasksCreated)
            {
                // turn off auto prefetching for related proxies
                final Class saveClassToPrefetch = classToPrefetch;
                classToPrefetch = null;
                try
                {
                    performRetrievalTasks();
                }
                finally
                {
                    classToPrefetch = saveClassToPrefetch;
                }
            }

            // BRJ: fire LifeCycleEvents after execution of RetrievalTasks
            // to ensure objects are fully materialized
            Iterator resultIter = result.ojbIterator();
            while (resultIter.hasNext())
            {
                Object obj = resultIter.next();
                afterLookupEvent.setTarget(obj);
                pb.fireBrokerEvent(afterLookupEvent);
View Full Code Here

     * @return ManageableCollection
     * @throws PersistenceBrokerException
     */
    public ManageableCollection getCollectionByQuery(Class collectionClass, Query query, boolean lazy) throws PersistenceBrokerException
    {
        ManageableCollection result;

        try
        {
            // BRJ: return empty Collection  for null query
            if (query == null)
View Full Code Here

                        }
                        value = result;
                    }
                    else
                    {
                        ManageableCollection result = getCollectionByQuery(collectionClass, fkQuery, lazyLoad);
                        collectionField.set(obj, result);
                        value = result;
                    }

                    if (prefetchProxies && (m_retrievalTasks != null)
View Full Code Here

                    Array.set(result, j, list.get(j));
                }
            }
            else
            {
                ManageableCollection col = createCollection(cds, collectionClass);

                for (Iterator it2 = list.iterator(); it2.hasNext();)
                {
                    col.ojbAdd(it2.next());
                }
                result = col;
            }

            Object value = field.get(owner);
View Full Code Here

            throws ClassNotPersistenceCapableException, PersistenceBrokerException
    {
        if (log.isDebugEnabled()) log.debug("getCollectionByQuery (" + collectionClass + ", " + itemClass + ", " + query + ")");

        ClassDescriptor cld = pb.getClassDescriptor(itemClass);
        ManageableCollection result = null;
        OJBIterator iter = null;
        boolean isRetrievalTasksCreated = (batchRetrieval && (m_retrievalTasks == null));
        int fullSize = -1;
        int size = 0;

        if (isRetrievalTasksCreated)
        {
            // Maps ReferenceDescriptors to HashSets of owners
            m_retrievalTasks = new HashMap();
        }

        try
        {
            result = (ManageableCollection) collectionClass.newInstance();
            // now iterate over all elements and add them to the new collection
            iter = pb.getIteratorFromQuery(query, cld);

            // BRJ : get fullSizefor Query
            // to be removed when Query.fullSize is removed
            if (iter instanceof PagingIterator)
            {
                fullSize = iter.fullSize();
            }

            while (iter.hasNext())
            {
                Object candidate = iter.next();

                /**
                 * MBAIRD
                 * candidate CAN be null in the case of materializing from an iterator based
                 * on a query for a class that is mapped to a table that has other classes
                 * mapped to that table as well, but aren't extents.
                 */
                if (candidate != null)
                {
                    IndirectionHandler handler = ProxyHelper.getIndirectionHandler(candidate);

                    if ((handler != null)
                            || itemClass.isAssignableFrom(candidate.getClass()))
                    {
                        result.ojbAdd(candidate);

                        // BRJ: count added objects
                        // to be removed when Query.fullSize is removed
                        size++;
                    }
View Full Code Here

     * @return ManageableCollection
     * @throws PersistenceBrokerException
     */
    public ManageableCollection getCollectionByQuery(Class collectionClass, Query query, boolean lazy) throws PersistenceBrokerException
    {
        ManageableCollection result;

        try
        {
            // BRJ: return empty Collection  for null query
            if (query == null)
View Full Code Here

TOP

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

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.