db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker PersistenceBroker.java
Date Mon, 12 May 2003 18:34:02 GMT
arminw      2003/05/12 11:34:02

  Modified:    src/java/org/apache/ojb/broker/core
                        DelegatingPersistenceBroker.java
                        PersistenceBrokerAbstractImpl.java
                        PersistenceBrokerBean.java
               src/java/org/apache/ojb/broker PersistenceBroker.java
  Log:
  improvements by Lance Eason:
  9) PersistenceBrokerAbstractImpl manages firing off events during the lifecycle of a PersistenceBroker.
  There are three opportunities for performance improvements here.  First it iterates through a map every
  time an event is fired.  Since listeners are added rarely but events are fired frequently it's much better
  to construct a new array each time a listener is added and iterate through an array on event firing.
  Second, listeners are stored in a map with a Boolean indicating whether they are permanent or not.
  When the broker is released this map is iterated through and all non-permanent listeners are discarded.
  It's better to keep two separate arrays and just discard the non-permanent array rather than doing
  this iteration.  Finally, a single fireBrokerEvent method is provided which takes a PersistenceBrokerEvent.
  Internally this method does two instanceof operations to decide how to dispatch the event.
  Letting the compiler decide how to dispatch at compile time by providing overloaded signatures of
  fireBrokerEvent is more efficient.  Similar things could be done for add and removeListener, but I
  didn't bother since these will be called relatively rarely.
  
  Revision  Changes    Path
  1.2       +292 -280  db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java
  
  Index: DelegatingPersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DelegatingPersistenceBroker.java	26 Apr 2003 23:18:25 -0000	1.1
  +++ DelegatingPersistenceBroker.java	12 May 2003 18:34:02 -0000	1.2
  @@ -7,6 +7,8 @@
   import org.apache.ojb.broker.PBState;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerEvent;
  +import org.apache.ojb.broker.PBLifeCycleEvent;
  +import org.apache.ojb.broker.PBStateEvent;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.TransactionAbortedException;
   import org.apache.ojb.broker.TransactionInProgressException;
  @@ -36,284 +38,294 @@
    */
   public class DelegatingPersistenceBroker implements PersistenceBroker, PBState
   {
  -    protected PersistenceBroker broker;
  +	protected PersistenceBroker broker;
   
  -    public DelegatingPersistenceBroker(PersistenceBroker broker)
  -    {
  -        this.broker = broker;
  -    }
  -
  -    /**
  -     * All delegated method use this method to
  -     * get the wrapped broker.
  -     */
  -    private PersistenceBroker getBroker()
  -    {
  -        if (broker != null)
  -            return broker;
  -        else
  -            throw new IllegalStateException("The delegate PersistenceBroker is closed");
  -    }
  -
  -    /**
  -     * Returns only the wrapped
  -     * {@link org.apache.ojb.broker.PersistenceBroker} instance
  -     */
  -    public PersistenceBroker getDelegate()
  -    {
  -        return this.broker;
  -    }
  -
  -    public void setDelegate(PersistenceBroker broker)
  -    {
  -        this.broker = broker;
  -    }
  -
  -    /**
  -     * If my underlying {@link org.apache.ojb.broker.PersistenceBroker}
  -     * is not a {@link DelegatingPersistenceBroker}, returns it,
  -     * otherwise recursively invokes this method on my delegate.
  -     * <p>
  -     * Hence this method will return the first
  -     * delegate that is not a {@link DelegatingPersistenceBroker},
  -     * or <tt>null</tt> when no non-{@link DelegatingPersistenceBroker}
  -     * delegate can be found by transversing this chain.
  -     * <p>
  -     * This method is useful when you may have nested
  -     * {@link DelegatingPersistenceBroker}s, and you want to make
  -     * sure to obtain a "genuine" {@link org.apache.ojb.broker.PersistenceBroker}
  -     * implementaion instance.
  -     */
  -    public PersistenceBroker getInnermostDelegate()
  -    {
  -        PersistenceBroker broker = this.broker;
  -        while (broker != null && broker instanceof DelegatingPersistenceBroker)
  -        {
  -            broker = ((DelegatingPersistenceBroker) broker).getDelegate();
  -            if (this == broker)
  -            {
  -                return null;
  -            }
  -        }
  -        return broker;
  -    }
  -
  -    public boolean isClosed()
  -    {
  -        return ((PBState) getBroker()).isClosed();
  -    }
  -
  -    public void setClosed(boolean closed)
  -    {
  -        ((PBState) getBroker()).setClosed(closed);
  -    }
  -
  -    public void beginTransaction()
  -            throws TransactionInProgressException, TransactionAbortedException
  -    {
  -        getBroker().beginTransaction();
  -    }
  -
  -    public void commitTransaction()
  -            throws TransactionNotInProgressException, TransactionAbortedException
  -    {
  -        getBroker().commitTransaction();
  -    }
  -
  -    public void abortTransaction() throws TransactionNotInProgressException
  -    {
  -        getBroker().abortTransaction();
  -    }
  -
  -    public boolean isInTransaction() throws PersistenceBrokerException
  -    {
  -        return getBroker().isInTransaction();
  -    }
  -
  -    public boolean close()
  -    {
  -        return getBroker().close();
  -    }
  -
  -    public SqlGenerator serviceSqlGenerator()
  -    {
  -        return getBroker().serviceSqlGenerator();
  -    }
  -
  -    public JdbcAccess serviceJdbcAccess()
  -    {
  -        return getBroker().serviceJdbcAccess();
  -    }
  -
  -    public void delete(Object obj) throws PersistenceBrokerException
  -    {
  -        getBroker().delete(obj);
  -    }
  -
  -    public void store(Object obj) throws PersistenceBrokerException
  -    {
  -        getBroker().store(obj);
  -    }
  -
  -    public void store(Object obj,
  -                      ObjectModification modification) throws PersistenceBrokerException
  -    {
  -        getBroker().store(obj, modification);
  -    }
  -
  -    public PBKey getPBKey()
  -    {
  -        return getBroker().getPBKey();
  -    }
  -
  -    public void removeFromCache(Object obj) throws PersistenceBrokerException
  -    {
  -        getBroker().removeFromCache(obj);
  -    }
  -
  -    public void clearCache() throws PersistenceBrokerException
  -    {
  -        getBroker().clearCache();
  -    }
  -
  -    public DescriptorRepository getDescriptorRepository()
  -    {
  -        return getBroker().getDescriptorRepository();
  -    }
  -
  -    public void removeAllListeners() throws PersistenceBrokerException
  -    {
  -        getBroker().removeAllListeners();
  -    }
  -
  -    public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
  -    {
  -        getBroker().removeAllListeners(permanent);
  -    }
  -
  -    public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException
  -    {
  -        getBroker().retrieveReference(pInstance, pAttributeName);
  -    }
  -
  -    public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException
  -    {
  -        getBroker().retrieveAllReferences(pInstance);
  -    }
  -
  -    public ConnectionManagerIF serviceConnectionManager()
  -    {
  -        return getBroker().serviceConnectionManager();
  -    }
  -
  -    public StatementManagerIF serviceStatementManager()
  -    {
  -        return getBroker().serviceStatementManager();
  -    }
  -
  -    public SequenceManager serviceSequenceManager()
  -    {
  -        return getBroker().serviceSequenceManager();
  -    }
  -
  -    public BrokerHelper serviceBrokerHelper()
  -    {
  -        return getBroker().serviceBrokerHelper();
  -    }
  -
  -    public ObjectCache serviceObjectCache()
  -    {
  -        return getBroker().serviceObjectCache();
  -    }
  -
  -    public void fireBrokerEvent(PersistenceBrokerEvent event)
  -    {
  -        getBroker().fireBrokerEvent(event);
  -    }
  -
  -    public void addListener(PBListener listener) throws PersistenceBrokerException
  -    {
  -        getBroker().addListener(listener);
  -    }
  -
  -    public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException
  -    {
  -        getBroker().addListener(listener, permanent);
  -    }
  -
  -    public void removeListener(PBListener listener) throws PersistenceBrokerException
  -    {
  -    }
  -
  -    public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
  -    {
  -        return getBroker().getTopLevelClass(clazz);
  -    }
  -
  -    public boolean hasClassDescriptor(Class clazz)
  -    {
  -        return getBroker().hasClassDescriptor(clazz);
  -    }
  -
  -    public ClassDescriptor getClassDescriptor(Class clazz) throws PersistenceBrokerException
  -    {
  -        return getBroker().getClassDescriptor(clazz);
  -    }
  -
  -    public Enumeration getPKEnumerationByQuery(Class primaryKeyClass,
  -                                               Query query) throws PersistenceBrokerException
  -    {
  -        return getBroker().getPKEnumerationByQuery(primaryKeyClass, query);
  -    }
  -
  -    public Object getObjectByQuery(Query query) throws PersistenceBrokerException
  -    {
  -        return getBroker().getObjectByQuery(query);
  -    }
  -
  -    public Object getObjectByIdentity(Identity id) throws PersistenceBrokerException
  -    {
  -        return getBroker().getObjectByIdentity(id);
  -    }
  -
  -    public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
  -    {
  -        return getBroker().getReportQueryIteratorByQuery(query);
  -    }
  -
  -    public Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException
  -    {
  -        return getBroker().getIteratorByQuery(query);
  -    }
  -
  -    public ManageableCollection getCollectionByQuery(Class collectionClass, Query query)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getCollectionByQuery(collectionClass, query);
  -    }
  -
  -    public int getCount(Query query) throws PersistenceBrokerException
  -    {
  -        return getBroker().getCount(query);
  -    }
  -
  -    public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
  -    {
  -        return getBroker().getCollectionByQuery(query);
  -    }
  -
  -    public void configure(Configuration pConfig) throws ConfigurationException
  -    {
  -        getBroker().configure(pConfig);
  -    }
  -
  -    public org.odbms.Query query()
  -    {
  -        return getBroker().query();
  -    }
  -
  -    public void deleteByQuery(Query query) throws PersistenceBrokerException
  -    {
  -        getBroker().deleteByQuery(query);
  -    }
  -}
  +	public DelegatingPersistenceBroker(PersistenceBroker broker)
  +	{
  +		this.broker = broker;
  +	}
  +
  +	/**
  +	 * All delegated method use this method to
  +	 * get the wrapped broker.
  +	 */
  +	private PersistenceBroker getBroker()
  +	{
  +		if (broker != null)
  +			return broker;
  +		else
  +			throw new IllegalStateException("The delegate PersistenceBroker is closed");
  +	}
  +
  +	/**
  +	 * Returns only the wrapped
  +	 * {@link org.apache.ojb.broker.PersistenceBroker} instance
  +	 */
  +	public PersistenceBroker getDelegate()
  +	{
  +		return this.broker;
  +	}
  +
  +	public void setDelegate(PersistenceBroker broker)
  +	{
  +		this.broker = broker;
  +	}
  +
  +	/**
  +	 * If my underlying {@link org.apache.ojb.broker.PersistenceBroker}
  +	 * is not a {@link DelegatingPersistenceBroker}, returns it,
  +	 * otherwise recursively invokes this method on my delegate.
  +	 * <p>
  +	 * Hence this method will return the first
  +	 * delegate that is not a {@link DelegatingPersistenceBroker},
  +	 * or <tt>null</tt> when no non-{@link DelegatingPersistenceBroker}
  +	 * delegate can be found by transversing this chain.
  +	 * <p>
  +	 * This method is useful when you may have nested
  +	 * {@link DelegatingPersistenceBroker}s, and you want to make
  +	 * sure to obtain a "genuine" {@link org.apache.ojb.broker.PersistenceBroker}
  +	 * implementaion instance.
  +	 */
  +	public PersistenceBroker getInnermostDelegate()
  +	{
  +		PersistenceBroker broker = this.broker;
  +		while (broker != null && broker instanceof DelegatingPersistenceBroker)
  +		{
  +			broker = ((DelegatingPersistenceBroker) broker).getDelegate();
  +			if (this == broker)
  +			{
  +				return null;
  +			}
  +		}
  +		return broker;
  +	}
  +
  +	public boolean isClosed()
  +	{
  +		return ((PBState) getBroker()).isClosed();
  +	}
  +
  +	public void setClosed(boolean closed)
  +	{
  +		((PBState) getBroker()).setClosed(closed);
  +	}
  +
  +	public void beginTransaction()
  +			throws TransactionInProgressException, TransactionAbortedException
  +	{
  +		getBroker().beginTransaction();
  +	}
  +
  +	public void commitTransaction()
  +			throws TransactionNotInProgressException, TransactionAbortedException
  +	{
  +		getBroker().commitTransaction();
  +	}
  +
  +	public void abortTransaction() throws TransactionNotInProgressException
  +	{
  +		getBroker().abortTransaction();
  +	}
  +
  +	public boolean isInTransaction() throws PersistenceBrokerException
  +	{
  +		return getBroker().isInTransaction();
  +	}
  +
  +	public boolean close()
  +	{
  +		return getBroker().close();
  +	}
  +
  +	public SqlGenerator serviceSqlGenerator()
  +	{
  +		return getBroker().serviceSqlGenerator();
  +	}
  +
  +	public JdbcAccess serviceJdbcAccess()
  +	{
  +		return getBroker().serviceJdbcAccess();
  +	}
  +
  +	public void delete(Object obj) throws PersistenceBrokerException
  +	{
  +		getBroker().delete(obj);
  +	}
  +
  +	public void store(Object obj) throws PersistenceBrokerException
  +	{
  +		getBroker().store(obj);
  +	}
  +
  +	public void store(Object obj,
  +					  ObjectModification modification) throws PersistenceBrokerException
  +	{
  +		getBroker().store(obj, modification);
  +	}
  +
  +	public PBKey getPBKey()
  +	{
  +		return getBroker().getPBKey();
  +	}
  +
  +	public void removeFromCache(Object obj) throws PersistenceBrokerException
  +	{
  +		getBroker().removeFromCache(obj);
  +	}
  +
  +	public void clearCache() throws PersistenceBrokerException
  +	{
  +		getBroker().clearCache();
  +	}
  +
  +	public DescriptorRepository getDescriptorRepository()
  +	{
  +		return getBroker().getDescriptorRepository();
  +	}
  +
  +	public void removeAllListeners() throws PersistenceBrokerException
  +	{
  +		getBroker().removeAllListeners();
  +	}
  +
  +	public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
  +	{
  +		getBroker().removeAllListeners(permanent);
  +	}
  +
  +	public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException
  +	{
  +		getBroker().retrieveReference(pInstance, pAttributeName);
  +	}
  +
  +	public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException
  +	{
  +		getBroker().retrieveAllReferences(pInstance);
  +	}
  +
  +	public ConnectionManagerIF serviceConnectionManager()
  +	{
  +		return getBroker().serviceConnectionManager();
  +	}
  +
  +	public StatementManagerIF serviceStatementManager()
  +	{
  +		return getBroker().serviceStatementManager();
  +	}
  +
  +	public SequenceManager serviceSequenceManager()
  +	{
  +		return getBroker().serviceSequenceManager();
  +	}
  +
  +	public BrokerHelper serviceBrokerHelper()
  +	{
  +		return getBroker().serviceBrokerHelper();
  +	}
  +
  +	public ObjectCache serviceObjectCache()
  +	{
  +		return getBroker().serviceObjectCache();
  +	}
  +
  +	public void fireBrokerEvent(PersistenceBrokerEvent event)
  +	{
  +		getBroker().fireBrokerEvent(event);
  +	}
  +
  +	public void fireBrokerEvent(PBLifeCycleEvent event)
  +	{
  +		getBroker().fireBrokerEvent(event);
  +	}
  +    
  +	public void fireBrokerEvent(PBStateEvent event)
  +	{
  +		getBroker().fireBrokerEvent(event);
  +	}
  +    
  +	public void addListener(PBListener listener) throws PersistenceBrokerException
  +	{
  +		getBroker().addListener(listener);
  +	}
  +
  +	public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException
  +	{
  +		getBroker().addListener(listener, permanent);
  +	}
  +
  +	public void removeListener(PBListener listener) throws PersistenceBrokerException
  +	{
  +	}
  +
  +	public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
  +	{
  +		return getBroker().getTopLevelClass(clazz);
  +	}
  +
  +	public boolean hasClassDescriptor(Class clazz)
  +	{
  +		return getBroker().hasClassDescriptor(clazz);
  +	}
  +
  +	public ClassDescriptor getClassDescriptor(Class clazz) throws PersistenceBrokerException
  +	{
  +		return getBroker().getClassDescriptor(clazz);
  +	}
  +
  +	public Enumeration getPKEnumerationByQuery(Class primaryKeyClass,
  +											   Query query) throws PersistenceBrokerException
  +	{
  +		return getBroker().getPKEnumerationByQuery(primaryKeyClass, query);
  +	}
  +
  +	public Object getObjectByQuery(Query query) throws PersistenceBrokerException
  +	{
  +		return getBroker().getObjectByQuery(query);
  +	}
  +
  +	public Object getObjectByIdentity(Identity id) throws PersistenceBrokerException
  +	{
  +		return getBroker().getObjectByIdentity(id);
  +	}
  +
  +	public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
  +	{
  +		return getBroker().getReportQueryIteratorByQuery(query);
  +	}
  +
  +	public Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException
  +	{
  +		return getBroker().getIteratorByQuery(query);
  +	}
  +
  +	public ManageableCollection getCollectionByQuery(Class collectionClass, Query query)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getCollectionByQuery(collectionClass, query);
  +	}
  +
  +	public int getCount(Query query) throws PersistenceBrokerException
  +	{
  +		return getBroker().getCount(query);
  +	}
  +
  +	public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
  +	{
  +		return getBroker().getCollectionByQuery(query);
  +	}
  +
  +	public void configure(Configuration pConfig) throws ConfigurationException
  +	{
  +		getBroker().configure(pConfig);
  +	}
  +
  +	public org.odbms.Query query()
  +	{
  +		return getBroker().query();
  +	}
  +
  +	public void deleteByQuery(Query query) throws PersistenceBrokerException
  +	{
  +		getBroker().deleteByQuery(query);
  +	}
  +}
  \ No newline at end of file
  
  
  
  1.2       +192 -85   db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java
  
  Index: PersistenceBrokerAbstractImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistenceBrokerAbstractImpl.java	26 Apr 2003 23:18:25 -0000	1.1
  +++ PersistenceBrokerAbstractImpl.java	12 May 2003 18:34:02 -0000	1.2
  @@ -83,21 +83,35 @@
    */
   public abstract class PersistenceBrokerAbstractImpl implements PersistenceBroker
   {
  +	private static final PBStateListener[] NO_STATE_LISTENERS = new PBStateListener[0];
  +	private static final PBLifeCycleListener[] NO_LIFECYCLE_LISTENERS = new PBLifeCycleListener[0];
  +
       private static final Boolean TRUE = new Boolean("true");
       private static final Boolean FALSE = new Boolean("false");
  +
       /**
  -     * Map contains all temporary and permanent {@link org.apache.ojb.broker.PBStateListener}
  -     * instances as keys, values are <code>Boolean true</code> for permanent and <code>Boolean false</code>
  -     * for temporary listener.
  -     */
  -    private Map stateEventListener = newMap();
  -    /**
  -     * Map contains all temporary and permanent {@link org.apache.ojb.broker.PBLifeCycleListener}
  -     * instances as keys, values are <code>Boolean true</code> for permanent and <code>Boolean false</code>
  -     * for temporary listener.
  +     * Array containing all permanent {@link org.apache.ojb.broker.PBStateListener}
  +     * instances.
        */
  -    private Map objectEventListener = newMap();
  +    private PBStateListener[] permanentStateListeners = NO_STATE_LISTENERS;
   
  +	/**
  +	 * Array containing all temporary {@link org.apache.ojb.broker.PBStateListener}
  +	 * instances.
  +	 */
  +	private PBStateListener[] temporaryStateListeners = NO_STATE_LISTENERS;
  +
  +	/**
  +	 * Array containing all permanent {@link org.apache.ojb.broker.PBLifeCycleListener}
  +	 * instances.
  +	 */
  +	private PBLifeCycleListener[] permanentLifeCycleListeners = NO_LIFECYCLE_LISTENERS;
  +
  +	/**
  +	 * Array containing all temporary {@link org.apache.ojb.broker.PBLifeCycleListener}
  +	 * instances.
  +	 */
  +	private PBLifeCycleListener[] temporaryLifeCycleListeners = NO_LIFECYCLE_LISTENERS;
   
       /**
        * @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener listener)
  @@ -114,11 +128,50 @@
       {
           if (listener instanceof PBStateListener)
           {
  -            stateEventListener.put(listener, new Boolean(permanent));
  +        	if (permanent)
  +        	{
  +        		if (!contains(permanentStateListeners, listener))
  +        		{
  +					PBStateListener[] newListeners = new PBStateListener[permanentStateListeners.length + 1];
  +					System.arraycopy(permanentStateListeners, 0, newListeners, 0, permanentStateListeners.length);
  +					newListeners[newListeners.length - 1] = (PBStateListener) listener;
  +					permanentStateListeners = newListeners;
  +        		}
  +        	}
  +        	else
  +        	{
  +				if (!contains(temporaryStateListeners, listener))
  +				{
  +					PBStateListener[] newListeners = new PBStateListener[temporaryStateListeners.length + 1];
  +					System.arraycopy(temporaryStateListeners, 0, newListeners, 0, temporaryStateListeners.length);
  +					newListeners[newListeners.length - 1] = (PBStateListener) listener;
  +					temporaryStateListeners = newListeners;
  +				}
  +        	}
           }
  +
           if (listener instanceof PBLifeCycleListener)
           {
  -            objectEventListener.put(listener, new Boolean(permanent));
  +			if (permanent)
  +			{
  +				if (!contains(permanentLifeCycleListeners, listener))
  +				{
  +					PBLifeCycleListener[] newListeners = new PBLifeCycleListener[permanentLifeCycleListeners.length + 1];
  +					System.arraycopy(permanentLifeCycleListeners, 0, newListeners, 0, permanentLifeCycleListeners.length);
  +					newListeners[newListeners.length - 1] = (PBLifeCycleListener) listener;
  +					permanentLifeCycleListeners = newListeners;
  +				}
  +			}
  +			else
  +			{
  +				if (!contains(temporaryLifeCycleListeners, listener))
  +				{
  +					PBLifeCycleListener[] newListeners = new PBLifeCycleListener[temporaryLifeCycleListeners.length + 1];
  +					System.arraycopy(temporaryLifeCycleListeners, 0, newListeners, 0, temporaryLifeCycleListeners.length);
  +					newListeners[newListeners.length - 1] = (PBLifeCycleListener) listener;
  +					temporaryLifeCycleListeners = newListeners;
  +				}
  +			}
           }
       }
   
  @@ -129,14 +182,81 @@
       {
           if (listener instanceof PBStateListener)
           {
  -            stateEventListener.remove(listener);
  +        	if (contains(permanentStateListeners, listener))
  +        	{
  +				PBStateListener[] newListeners = new PBStateListener[permanentStateListeners.length - 1];
  +        		int pos = 0;
  +
  +        		for (int i = 0; i < permanentStateListeners.length; i++)
  +        		{
  +        			if (permanentStateListeners[i] != listener)
  +        			{
  +        				newListeners[pos++] = permanentStateListeners[i];
  +        			}
  +        		}
  +				permanentStateListeners = newListeners;
  +        	}
  +
  +			if (contains(temporaryStateListeners, listener))
  +			{
  +				PBStateListener[] newListeners = new PBStateListener[temporaryStateListeners.length - 1];
  +				int pos = 0;
  +
  +				for (int i = 0; i < temporaryStateListeners.length; i++)
  +				{
  +					if (temporaryStateListeners[i] != listener)
  +					{
  +						newListeners[pos++] = temporaryStateListeners[i];
  +					}
  +				}
  +				temporaryStateListeners = newListeners;
  +			}
           }
  +
           if (listener instanceof PBLifeCycleListener)
           {
  -            objectEventListener.remove(listener);
  -        }
  +			if (contains(permanentLifeCycleListeners, listener))
  +			{
  +				PBLifeCycleListener[] newListeners = new PBLifeCycleListener[permanentLifeCycleListeners.length - 1];
  +				int pos = 0;
  +
  +				for (int i = 0; i < permanentLifeCycleListeners.length; i++)
  +				{
  +					if (permanentLifeCycleListeners[i] != listener)
  +					{
  +						newListeners[pos++] = permanentLifeCycleListeners[i];
  +					}
  +				}
  +				permanentLifeCycleListeners = newListeners;
  +			}
  +
  +			if (contains(temporaryLifeCycleListeners, listener))
  +			{
  +				PBLifeCycleListener[] newListeners = new PBLifeCycleListener[temporaryLifeCycleListeners.length - 1];
  +				int pos = 0;
  +
  +				for (int i = 0; i < temporaryLifeCycleListeners.length; i++)
  +				{
  +					if (temporaryLifeCycleListeners[i] != listener)
  +					{
  +						newListeners[pos++] = temporaryLifeCycleListeners[i];
  +					}
  +				}
  +				temporaryLifeCycleListeners = newListeners;
  +			}
  +		}
       }
   
  +	protected boolean contains(PBListener[] listeners, PBListener listener)
  +	{
  +		for (int i = listeners.length - 1; i >= 0; i--)
  +		{
  +            if (listeners[i] == listener) return true;
  +		}
  +
  +		return false;
  +	}
  +
       /**
        * @see org.apache.ojb.broker.PersistenceBroker#removeAllListeners(boolean)
        */
  @@ -144,40 +264,13 @@
       {
           if (permanent)
           {
  -            // all listener removed
  -            stateEventListener.clear();
  -            objectEventListener.clear();
  -        }
  -        else
  -        {
  -            // we keep the permanent listener and remove the temporary
  -            Iterator it = stateEventListener.keySet().iterator();
  -            Map replace = newMap();
  -            Object obj;
  -            while (it.hasNext())
  -            {
  -                obj = it.next();
  -                if (stateEventListener.get(obj).equals(TRUE))
  -                {
  -                    replace.put(obj, TRUE);
  -                }
  -            }
  -            stateEventListener = replace;
  -
  -            // we keep the permanent listener and remove the temporary
  -            it = objectEventListener.keySet().iterator();
  -            replace = newMap();
  -            obj = null;
  -            while (it.hasNext())
  -            {
  -                obj = it.next();
  -                if (objectEventListener.get(obj).equals(TRUE))
  -                {
  -                    replace.put(obj, TRUE);
  -                }
  -            }
  -            objectEventListener = replace;
  +            // remove permanent listeners as well
  +            permanentStateListeners = NO_STATE_LISTENERS;
  +            permanentLifeCycleListeners = NO_LIFECYCLE_LISTENERS;
           }
  +
  +		temporaryStateListeners = NO_STATE_LISTENERS;
  +		temporaryLifeCycleListeners = NO_LIFECYCLE_LISTENERS;
       }
   
       /**
  @@ -190,41 +283,63 @@
   
       public void fireBrokerEvent(PersistenceBrokerEvent event)
       {
  -        if (event instanceof PBLifeCycleEvent)
  +    	if (event instanceof PBLifeCycleEvent)
  +    	{
  +    		fireBrokerEvent((PBLifeCycleEvent) event);
  +    	}
  +    	else if (event instanceof PBStateEvent)
  +		{
  +			fireBrokerEvent((PBStateEvent) event);
  +		}
  +		else
  +		{
  +			LoggerFactory.getDefaultLogger().error(
  +					PersistenceBrokerAbstractImpl.class.getName() + ": Unkown PersistenceBrokerEvent was fired " + event);
  +		}
  +    }
  +
  +	public void fireBrokerEvent(PBLifeCycleEvent event)
  +    {
  +        if (event.getPersitenceBrokerAware() != null)
           {
  -            PBLifeCycleEvent lifeCycleEvent = (PBLifeCycleEvent) event;
  +            // first we do the persistent object callback
  +            performCallBack(event);
  +        }
  +
  +        // copy array references so they can't change in the middle of iteration
  +        PBLifeCycleListener[] permanent = permanentLifeCycleListeners;
  +		PBLifeCycleListener[] temporary = temporaryLifeCycleListeners;
   
  -            if (lifeCycleEvent.getPersitenceBrokerAware() != null)
  -            {
  -                // first we do the persistent object callback
  -                performCallBack(lifeCycleEvent);
  -            }
  -            // now we notify the listeners
  -            if (!objectEventListener.isEmpty())
  -            {
  -                for (Iterator it = objectEventListener.keySet().iterator(); it.hasNext();)
  -                {
  -                    PBLifeCycleListener listener = (PBLifeCycleListener) it.next();
  -                    notifiyObjectLifeCycleListener(listener, lifeCycleEvent);
  -                }
  -            }
  -        }
  -        else if (event instanceof PBStateEvent)
  -        {
  -            for (Iterator it = stateEventListener.keySet().iterator(); it.hasNext();)
  -            {
  -                PBStateEvent stateEvent = (PBStateEvent)event;
  -                PBStateListener listener = (PBStateListener) it.next();
  -                notifiyStateListener(listener, (PBStateEvent) event);
  -            }
  +        // now we notify the listeners
  +        for (int i = permanent.length - 1; i >= 0; i--)
  +        {
  +			notifiyObjectLifeCycleListener(permanent[i], event);
           }
  -        else
  +
  +        for (int i = temporary.length - 1; i >= 0; i--)
           {
  -            LoggerFactory.getDefaultLogger().error(
  -                    PersistenceBrokerAbstractImpl.class.getName() + ": Unkown PersistenceBrokerEvent was fired " + event);
  +			notifiyObjectLifeCycleListener(temporary[i], event);
           }
       }
   
  +	public void fireBrokerEvent(PBStateEvent event)
  +    {
  +		// copy array references so they can't change in the middle of iteration
  +		PBStateListener[] permanent = permanentStateListeners;
  +		PBStateListener[] temporary = temporaryStateListeners;
  +
  +		// now we notify the listeners
  +		for (int i = permanent.length - 1; i >= 0; i--)
  +		{
  +			notifiyStateListener(permanent[i], event);
  +		}
  +
  +		for (int i = temporary.length - 1; i >= 0; i--)
  +		{
  +			notifiyStateListener(temporary[i], event);
  +		}
  +    }
  +
       private void performCallBack(PBLifeCycleEvent event)
       {
           // Check for null
  @@ -312,14 +427,6 @@
                   listener.afterDelete(lifeEvent);
                   break;
           }
  -    }
  -
  -    /**
  -     * Returns a new map instance.
  -     */
  -    private Map newMap()
  -    {
  -        return new HashMap();
       }
   
       /*
  
  
  
  1.2       +463 -451  db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerBean.java
  
  Index: PersistenceBrokerBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistenceBrokerBean.java	26 Apr 2003 23:18:25 -0000	1.1
  +++ PersistenceBrokerBean.java	12 May 2003 18:34:02 -0000	1.2
  @@ -57,7 +57,9 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PBKey;
  +import org.apache.ojb.broker.PBLifeCycleEvent;
   import org.apache.ojb.broker.PBListener;
  +import org.apache.ojb.broker.PBStateEvent;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerEvent;
   import org.apache.ojb.broker.PersistenceBrokerException;
  @@ -108,467 +110,477 @@
    * Can be used by normal EJB clients, not just the PersistenceBrokerClient
    *
    * @ejb:bean
  - * 			type="Stateless"
  - * 			name="PersistenceBrokerBean"
  - * 			jndi-name="org.apache.ojb.broker.core.PersistenceBrokerBean"
  - * 			local-jndi-name="ojb.PersistenceBrokerBean"
  - * 			view-type="both"
  - * 			transaction-type="Container"
  + *             type="Stateless"
  + *             name="PersistenceBrokerBean"
  + *             jndi-name="org.apache.ojb.broker.core.PersistenceBrokerBean"
  + *             local-jndi-name="ojb.PersistenceBrokerBean"
  + *             view-type="both"
  + *             transaction-type="Container"
    *
    * @ejb:interface
  - * 		remote-class="org.apache.ojb.broker.server.PersistenceBrokerRemote"
  - * 		local-class="org.apache.ojb.broker.server.PersistenceBrokerLocal"
  - * 		extends="javax.ejb.EJBObject, org.apache.ojb.broker.PersistenceBroker"
  + *         remote-class="org.apache.ojb.broker.server.PersistenceBrokerRemote"
  + *         local-class="org.apache.ojb.broker.server.PersistenceBrokerLocal"
  + *         extends="javax.ejb.EJBObject, org.apache.ojb.broker.PersistenceBroker"
    *
    * @ejb:home
  - * 		remote-class="org.apache.ojb.broker.server.PersistenceBrokerHome"
  - * 		local-class="org.apache.ojb.broker.server.PersistenceBrokerLocalHome"
  - * 		extends="javax.ejb.EJBHome"
  + *         remote-class="org.apache.ojb.broker.server.PersistenceBrokerHome"
  + *         local-class="org.apache.ojb.broker.server.PersistenceBrokerLocalHome"
  + *         extends="javax.ejb.EJBHome"
    *
    * @ejb:transaction
  - * 		type="Required"
  + *         type="Required"
    *
    * @ejb:env-entry
  - * 		name="ojb.repository"
  - * 		type="java.lang.String"
  - * 		value="repository.xml"
  + *         name="ojb.repository"
  + *         type="java.lang.String"
  + *         value="repository.xml"
    *
    */
   
   public class PersistenceBrokerBean implements PersistenceBroker, SessionBean
   {
  -    private Logger m_log;
  -    private SessionContext m_ctx;
  -    private String m_ojbRepository;
  -    private PBKey m_pbKey;
  -    private PersistenceBrokerFactoryIF m_pbf;
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getDescriptorRepository()
  -     */
  -    public DescriptorRepository getDescriptorRepository()
  -    {
  -        return getBroker().getDescriptorRepository();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getPBKey()
  -     */
  -    public PBKey getPBKey()
  -    {
  -        return getBroker().getPBKey();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#delete(Object)
  -     */
  -    public void delete(Object obj) throws PersistenceBrokerException
  -    {
  -        getBroker().delete(obj);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#deleteByQuery(Query)
  -     */
  -    public void deleteByQuery(Query query) throws PersistenceBrokerException
  -    {
  -        getBroker().deleteByQuery(query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#removeFromCache(Object)
  -     */
  -    public void removeFromCache(Object obj) throws PersistenceBrokerException
  -    {
  -        getBroker().removeFromCache(obj);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#clearCache()
  -     */
  -    public void clearCache() throws PersistenceBrokerException
  -    {
  -        getBroker().clearCache();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#store(Object)
  -     */
  -    public void store(Object obj) throws PersistenceBrokerException
  -    {
  -        getBroker().store(obj);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#abortTransaction()
  -     */
  -    public void abortTransaction() throws TransactionNotInProgressException
  -    {
  -        getBroker().abortTransaction();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#beginTransaction()
  -     */
  -    public void beginTransaction()
  -            throws TransactionInProgressException, TransactionAbortedException
  -    {
  -        getBroker().beginTransaction();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#commitTransaction()
  -     */
  -    public void commitTransaction()
  -            throws TransactionNotInProgressException, TransactionAbortedException
  -    {
  -        getBroker().commitTransaction();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#isInTransaction()
  -     */
  -    public boolean isInTransaction() throws PersistenceBrokerException
  -    {
  -        return getBroker().isInTransaction();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#close()
  -     */
  -    public boolean close()
  -    {
  -        return getBroker().close();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Query)
  -     */
  -    public Collection getCollectionByQuery(Query query)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getCollectionByQuery(query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getCount(Query)
  -     */
  -    public int getCount(Query query) throws PersistenceBrokerException
  -    {
  -        return getBroker().getCount(query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Class, Query)
  -     */
  -    public ManageableCollection getCollectionByQuery(
  -            Class collectionClass,
  -            Query query)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getCollectionByQuery(collectionClass, query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getIteratorByQuery(Query)
  -     */
  -    public Iterator getIteratorByQuery(Query query)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getIteratorByQuery(query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getReportQueryIteratorByQuery(Query)
  -     */
  -    public Iterator getReportQueryIteratorByQuery(Query query)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getReportQueryIteratorByQuery(query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getObjectByIdentity(Identity)
  -     */
  -    public Object getObjectByIdentity(Identity id)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getObjectByIdentity(id);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getObjectByQuery(Query)
  -     */
  -    public Object getObjectByQuery(Query query)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getObjectByQuery(query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getPKEnumerationByQuery(Class, Query)
  -     */
  -    public Enumeration getPKEnumerationByQuery(
  -            Class PrimaryKeyClass,
  -            Query query)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getPKEnumerationByQuery(PrimaryKeyClass, query);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#store(Object, ObjectModification)
  -     */
  -    public void store(Object obj, ObjectModification modification)
  -            throws PersistenceBrokerException
  -    {
  -        getBroker().store(obj, modification);
  -    }
  -
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getClassDescriptor(Class)
  -     */
  -    public ClassDescriptor getClassDescriptor(Class clazz)
  -            throws PersistenceBrokerException
  -    {
  -        return getBroker().getClassDescriptor(clazz);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#hasClassDescriptor(Class)
  -     */
  -    public boolean hasClassDescriptor(Class clazz)
  -    {
  -        return getBroker().hasClassDescriptor(clazz);
  -    }
  -
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#getTopLevelClass(Class)
  -     */
  -    public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
  -    {
  -        return getBroker().getTopLevelClass(clazz);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#serviceStatementManager()
  -     */
  -    public StatementManagerIF serviceStatementManager()
  -    {
  -        return getBroker().serviceStatementManager();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#serviceConnectionManager()
  -     */
  -    public ConnectionManagerIF serviceConnectionManager()
  -    {
  -        return getBroker().serviceConnectionManager();
  -    }
  -
  -    public JdbcAccess serviceJdbcAccess()
  -    {
  -        return getBroker().serviceJdbcAccess();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#serviceSqlGenerator()
  -     */
  -    public SqlGenerator serviceSqlGenerator()
  -    {
  -        return getBroker().serviceSqlGenerator();
  -    }
  -
  -    public SequenceManager serviceSequenceManager()
  -    {
  -        return getBroker().serviceSequenceManager();
  -    }
  -
  -    public BrokerHelper serviceBrokerHelper()
  -    {
  -        return getBroker().serviceBrokerHelper();
  -    }
  -
  -    public ObjectCache serviceObjectCache()
  -    {
  -        return getBroker().serviceObjectCache();
  -    }
  -
  -    public void fireBrokerEvent(PersistenceBrokerEvent event)
  -    {
  -        getBroker().fireBrokerEvent(event);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener)
  -     */
  -    public void addListener(PBListener listener) throws PersistenceBrokerException
  -    {
  -        getBroker().addListener(listener);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener, boolean)
  -     */
  -    public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException
  -    {
  -        getBroker().addListener(listener, permanent);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#removeListener(PBListener)
  -     */
  -    public void removeListener(PBListener listener) throws PersistenceBrokerException
  -    {
  -        getBroker().removeListener(listener);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#retrieveAllReferences(Object)
  -     */
  -    public void retrieveAllReferences(Object pInstance)
  -            throws PersistenceBrokerException
  -    {
  -        getBroker().retrieveAllReferences(pInstance);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#retrieveReference(Object, String)
  -     */
  -    public void retrieveReference(Object pInstance, String pAttributeName)
  -            throws PersistenceBrokerException
  -    {
  -        getBroker().retrieveReference(pInstance, pAttributeName);
  -    }
  -
  -    public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
  -    {
  -        getBroker().removeAllListeners(permanent);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.PersistenceBroker#removeAllListeners()
  -     */
  -    public void removeAllListeners() throws PersistenceBrokerException
  -    {
  -        getBroker().removeAllListeners();
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
  -     */
  -    public void configure(Configuration pConfig)
  -            throws ConfigurationException
  -    {
  -        getBroker().configure(pConfig);
  -    }
  -
  -    /**
  -     * @ejb:interface-method
  -     * @see org.odbms.ObjectContainer#query()
  -     */
  -    public org.odbms.Query query()
  -    {
  -        return getBroker().query();
  -    }
  -
  -    private void ojbPrepare()
  -    {
  -        if (m_log.isDebugEnabled()) m_log.info("PersistenceBrokerBean: ejbActivate was called");
  -        Context context = null;
  -        // Lookup if a environment entry for repository exists
  -        String ojbRepository = null;
  -        try
  -        {
  -            context = new InitialContext();
  -            ojbRepository = (String) context.lookup("java:comp/env/ojb.repository");
  -        }
  -        catch (NamingException e)
  -        {
  -            m_log.error("Lookup for ojb repository failed", e);
  -        }
  -        // no repository found in environment, use default one
  -        if (ojbRepository == null || ojbRepository.equals(""))
  -        {
  -            m_log.info("No enviroment entry was found, use default repository");
  -            ojbRepository = "repository.xml";
  -        }
  -        m_log.info("Use OJB repository file: " + ojbRepository);
  -        m_pbKey = new PBKey(ojbRepository);
  -
  -        // Lookup the PBF implementation
  -        try
  -        {
  -            context = new InitialContext();
  -            m_pbf = ((PBFactoryIF) context.lookup(PBFactoryIF.PBFACTORY_JNDI_NAME)).getInstance();
  -        }
  -        catch (NamingException e)
  -        {
  -            m_log.error("Lookup for PersistenceBrokerFactory failed", e);
  -            throw new PersistenceBrokerException(e);
  -        }
  -    }
  -
  -    public void ejbActivate() throws EJBException, RemoteException
  -    {
  -        m_log = LoggerFactory.getLogger(PersistenceBrokerBean.class);
  -        ojbPrepare();
  -    }
  -
  -    public void ejbPassivate() throws EJBException, RemoteException
  -    {
  -        m_log = null;
  -        m_pbf = null;
  -    }
  -
  -    public void ejbRemove() throws EJBException, RemoteException
  -    {
  -        m_ctx = null;
  -    }
  -
  -    public void setSessionContext(SessionContext sessionContext) throws EJBException, RemoteException
  -    {
  -        m_ctx = sessionContext;
  -    }
  -
  -    private PersistenceBroker getBroker()
  -    {
  -        return m_pbf.createPersistenceBroker(m_pbKey);
  -    }
  -}
  +	private Logger m_log;
  +	private SessionContext m_ctx;
  +	private String m_ojbRepository;
  +	private PBKey m_pbKey;
  +	private PersistenceBrokerFactoryIF m_pbf;
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getDescriptorRepository()
  +	 */
  +	public DescriptorRepository getDescriptorRepository()
  +	{
  +		return getBroker().getDescriptorRepository();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getPBKey()
  +	 */
  +	public PBKey getPBKey()
  +	{
  +		return getBroker().getPBKey();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#delete(Object)
  +	 */
  +	public void delete(Object obj) throws PersistenceBrokerException
  +	{
  +		getBroker().delete(obj);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#deleteByQuery(Query)
  +	 */
  +	public void deleteByQuery(Query query) throws PersistenceBrokerException
  +	{
  +		getBroker().deleteByQuery(query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#removeFromCache(Object)
  +	 */
  +	public void removeFromCache(Object obj) throws PersistenceBrokerException
  +	{
  +		getBroker().removeFromCache(obj);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#clearCache()
  +	 */
  +	public void clearCache() throws PersistenceBrokerException
  +	{
  +		getBroker().clearCache();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#store(Object)
  +	 */
  +	public void store(Object obj) throws PersistenceBrokerException
  +	{
  +		getBroker().store(obj);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#abortTransaction()
  +	 */
  +	public void abortTransaction() throws TransactionNotInProgressException
  +	{
  +		getBroker().abortTransaction();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#beginTransaction()
  +	 */
  +	public void beginTransaction()
  +			throws TransactionInProgressException, TransactionAbortedException
  +	{
  +		getBroker().beginTransaction();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#commitTransaction()
  +	 */
  +	public void commitTransaction()
  +			throws TransactionNotInProgressException, TransactionAbortedException
  +	{
  +		getBroker().commitTransaction();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#isInTransaction()
  +	 */
  +	public boolean isInTransaction() throws PersistenceBrokerException
  +	{
  +		return getBroker().isInTransaction();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#close()
  +	 */
  +	public boolean close()
  +	{
  +		return getBroker().close();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Query)
  +	 */
  +	public Collection getCollectionByQuery(Query query)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getCollectionByQuery(query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getCount(Query)
  +	 */
  +	public int getCount(Query query) throws PersistenceBrokerException
  +	{
  +		return getBroker().getCount(query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Class, Query)
  +	 */
  +	public ManageableCollection getCollectionByQuery(
  +			Class collectionClass,
  +			Query query)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getCollectionByQuery(collectionClass, query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getIteratorByQuery(Query)
  +	 */
  +	public Iterator getIteratorByQuery(Query query)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getIteratorByQuery(query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getReportQueryIteratorByQuery(Query)
  +	 */
  +	public Iterator getReportQueryIteratorByQuery(Query query)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getReportQueryIteratorByQuery(query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getObjectByIdentity(Identity)
  +	 */
  +	public Object getObjectByIdentity(Identity id)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getObjectByIdentity(id);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getObjectByQuery(Query)
  +	 */
  +	public Object getObjectByQuery(Query query)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getObjectByQuery(query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getPKEnumerationByQuery(Class, Query)
  +	 */
  +	public Enumeration getPKEnumerationByQuery(
  +			Class PrimaryKeyClass,
  +			Query query)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getPKEnumerationByQuery(PrimaryKeyClass, query);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#store(Object, ObjectModification)
  +	 */
  +	public void store(Object obj, ObjectModification modification)
  +			throws PersistenceBrokerException
  +	{
  +		getBroker().store(obj, modification);
  +	}
  +
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getClassDescriptor(Class)
  +	 */
  +	public ClassDescriptor getClassDescriptor(Class clazz)
  +			throws PersistenceBrokerException
  +	{
  +		return getBroker().getClassDescriptor(clazz);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#hasClassDescriptor(Class)
  +	 */
  +	public boolean hasClassDescriptor(Class clazz)
  +	{
  +		return getBroker().hasClassDescriptor(clazz);
  +	}
  +
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#getTopLevelClass(Class)
  +	 */
  +	public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
  +	{
  +		return getBroker().getTopLevelClass(clazz);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#serviceStatementManager()
  +	 */
  +	public StatementManagerIF serviceStatementManager()
  +	{
  +		return getBroker().serviceStatementManager();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#serviceConnectionManager()
  +	 */
  +	public ConnectionManagerIF serviceConnectionManager()
  +	{
  +		return getBroker().serviceConnectionManager();
  +	}
  +
  +	public JdbcAccess serviceJdbcAccess()
  +	{
  +		return getBroker().serviceJdbcAccess();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#serviceSqlGenerator()
  +	 */
  +	public SqlGenerator serviceSqlGenerator()
  +	{
  +		return getBroker().serviceSqlGenerator();
  +	}
  +
  +	public SequenceManager serviceSequenceManager()
  +	{
  +		return getBroker().serviceSequenceManager();
  +	}
  +
  +	public BrokerHelper serviceBrokerHelper()
  +	{
  +		return getBroker().serviceBrokerHelper();
  +	}
  +
  +	public ObjectCache serviceObjectCache()
  +	{
  +		return getBroker().serviceObjectCache();
  +	}
  +
  +	public void fireBrokerEvent(PersistenceBrokerEvent event)
  +	{
  +		getBroker().fireBrokerEvent(event);
  +	}
  +
  +	public void fireBrokerEvent(PBLifeCycleEvent event)
  +	{
  +		getBroker().fireBrokerEvent(event);
  +	}
  +    
  +	public void fireBrokerEvent(PBStateEvent event)
  +	{
  +		getBroker().fireBrokerEvent(event);
  +	}
  +    
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener)
  +	 */
  +	public void addListener(PBListener listener) throws PersistenceBrokerException
  +	{
  +		getBroker().addListener(listener);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener, boolean)
  +	 */
  +	public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException
  +	{
  +		getBroker().addListener(listener, permanent);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#removeListener(PBListener)
  +	 */
  +	public void removeListener(PBListener listener) throws PersistenceBrokerException
  +	{
  +		getBroker().removeListener(listener);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#retrieveAllReferences(Object)
  +	 */
  +	public void retrieveAllReferences(Object pInstance)
  +			throws PersistenceBrokerException
  +	{
  +		getBroker().retrieveAllReferences(pInstance);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#retrieveReference(Object, String)
  +	 */
  +	public void retrieveReference(Object pInstance, String pAttributeName)
  +			throws PersistenceBrokerException
  +	{
  +		getBroker().retrieveReference(pInstance, pAttributeName);
  +	}
  +
  +	public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
  +	{
  +		getBroker().removeAllListeners(permanent);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.PersistenceBroker#removeAllListeners()
  +	 */
  +	public void removeAllListeners() throws PersistenceBrokerException
  +	{
  +		getBroker().removeAllListeners();
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.apache.ojb.broker.util.configuration.Configurable#configure(Configuration)
  +	 */
  +	public void configure(Configuration pConfig)
  +			throws ConfigurationException
  +	{
  +		getBroker().configure(pConfig);
  +	}
  +
  +	/**
  +	 * @ejb:interface-method
  +	 * @see org.odbms.ObjectContainer#query()
  +	 */
  +	public org.odbms.Query query()
  +	{
  +		return getBroker().query();
  +	}
  +
  +	private void ojbPrepare()
  +	{
  +		if (m_log.isDebugEnabled()) m_log.info("PersistenceBrokerBean: ejbActivate was called");
  +		Context context = null;
  +		// Lookup if a environment entry for repository exists
  +		String ojbRepository = null;
  +		try
  +		{
  +			context = new InitialContext();
  +			ojbRepository = (String) context.lookup("java:comp/env/ojb.repository");
  +		}
  +		catch (NamingException e)
  +		{
  +			m_log.error("Lookup for ojb repository failed", e);
  +		}
  +		// no repository found in environment, use default one
  +		if (ojbRepository == null || ojbRepository.equals(""))
  +		{
  +			m_log.info("No enviroment entry was found, use default repository");
  +			ojbRepository = "repository.xml";
  +		}
  +		m_log.info("Use OJB repository file: " + ojbRepository);
  +		m_pbKey = new PBKey(ojbRepository);
  +
  +		// Lookup the PBF implementation
  +		try
  +		{
  +			context = new InitialContext();
  +			m_pbf = ((PBFactoryIF) context.lookup(PBFactoryIF.PBFACTORY_JNDI_NAME)).getInstance();
  +		}
  +		catch (NamingException e)
  +		{
  +			m_log.error("Lookup for PersistenceBrokerFactory failed", e);
  +			throw new PersistenceBrokerException(e);
  +		}
  +	}
  +
  +	public void ejbActivate() throws EJBException, RemoteException
  +	{
  +		m_log = LoggerFactory.getLogger(PersistenceBrokerBean.class);
  +		ojbPrepare();
  +	}
  +
  +	public void ejbPassivate() throws EJBException, RemoteException
  +	{
  +		m_log = null;
  +		m_pbf = null;
  +	}
  +
  +	public void ejbRemove() throws EJBException, RemoteException
  +	{
  +		m_ctx = null;
  +	}
  +
  +	public void setSessionContext(SessionContext sessionContext) throws EJBException, RemoteException
  +	{
  +		m_ctx = sessionContext;
  +	}
  +
  +	private PersistenceBroker getBroker()
  +	{
  +		return m_pbf.createPersistenceBroker(m_pbKey);
  +	}
  +}
  \ No newline at end of file
  
  
  
  1.24      +14 -2     db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java
  
  Index: PersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- PersistenceBroker.java	26 Apr 2003 23:18:24 -0000	1.23
  +++ PersistenceBroker.java	12 May 2003 18:34:02 -0000	1.24
  @@ -141,6 +141,18 @@
       public void fireBrokerEvent(PersistenceBrokerEvent event);
   
       /**
  +     * Performs a broker event to inform all managed
  +     * {@link PBListener} implementations.
  +     */
  +    public void fireBrokerEvent(PBLifeCycleEvent event);
  +
  +    /**
  +     * Performs a broker event to inform all managed
  +     * {@link PBListener} implementations.
  +     */
  +    public void fireBrokerEvent(PBStateEvent event);
  +
  +    /**
        * Removes all temporary listeners from this PersistenceBroker instance
        * - Handle with care!
        */
  @@ -423,4 +435,4 @@
        */
       public Enumeration getPKEnumerationByQuery(Class PrimaryKeyClass, Query query)
               throws PersistenceBrokerException;
  -}
  +}
  \ No newline at end of file
  
  
  

Mime
View raw message