Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.PersistenceBrokerInternal


    public static PersistenceBrokerInternal currentPersistenceBroker(PBKey key)
            throws PBFactoryException, PersistenceBrokerException
    {
        HashMap map = (HashMap) currentBrokerMap.get();
        WeakHashMap set;
        PersistenceBrokerInternal broker = null;

        if(map == null)
        {
            return null;
        }

        set = (WeakHashMap) map.get(key);
        if(set == null)
        {
            return null;
        }

        // seek for an open broker, preferably in transaction
        for(Iterator it = set.keySet().iterator(); it.hasNext();)
        {
            PersistenceBrokerInternal tmp = (PersistenceBrokerInternal) it.next();
            if(tmp == null || tmp.isClosed())
            {
                it.remove();
                continue;
            }
            broker = tmp;
            if(tmp.isInTransaction())
            {
                break; // the best choice found
            }
        }
        return broker;
View Full Code Here


     * @throws PBFactoryException
     */
    public PersistenceBrokerInternal createPersistenceBroker(PBKey pbKey) throws PBFactoryException
    {
        if (log.isDebugEnabled()) log.debug("Obtain broker from pool, used PBKey is " + pbKey);
        PersistenceBrokerInternal broker = null;

        /*
        try to find a valid PBKey, if given key does not full match
        */
        pbKey = BrokerHelper.crossCheckPBKey(pbKey);

        try
        {
            /*
            get a pooled PB instance, the pool is reponsible to create new
            PB instances if not found in pool
            */
            broker = ((PersistenceBrokerInternal) brokerPool.borrowObject(pbKey));
            /*
            now warp pooled PB instance with a handle to avoid PB corruption
            of closed PB instances.
            */
            broker = wrapRequestedBrokerInstance(broker);

        }
        catch (Exception e)
        {
            try
            {
                // if something going wrong, tryto close broker
                if(broker != null) broker.close();
            }
            catch (Exception ignore)
            {
                //ignore it
            }
View Full Code Here

                    ", already created persistence broker instances: " + instanceCount);
            // useful for testing
            ++this.instanceCount;
        }

        PersistenceBrokerInternal instance = null;
        Class[] types = {PBKey.class, PersistenceBrokerFactoryIF.class};
        Object[] args = {key, this};
        try
        {
            instance = (PersistenceBrokerInternal) ClassHelper.newInstance(implementationClass, types, args);
View Full Code Here

     *
     * @return a PersistenceBroker
     */
    protected TemporaryBrokerWrapper getBroker() throws PBFactoryException
    {
        PersistenceBrokerInternal broker;
        boolean needsClose = false;

        if (getBrokerKey() == null)
        {
            /*
            arminw:
            if no PBKey is set we throw an exception, because we don't
            know which PB (connection) should be used.
            */
            throw new OJBRuntimeException("Can't find associated PBKey. Need PBKey to obtain a valid" +
                                          "PersistenceBroker instance from intern resources.");
        }
        // first try to use the current threaded broker to avoid blocking
        broker = PersistenceBrokerThreadMapping.currentPersistenceBroker(getBrokerKey());
        // current broker not found, create a intern new one
        if ((broker == null) || broker.isClosed())
        {
            broker = (PersistenceBrokerInternal) PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
            /** Specifies whether we obtained a fresh broker which we have to close after we used it */
            needsClose = true;
        }
View Full Code Here

TOP

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

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.