db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r450015 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Date Tue, 26 Sep 2006 12:17:20 GMT
Author: arminw
Date: Tue Sep 26 05:17:20 2006
New Revision: 450015

URL: http://svn.apache.org/viewvc?view=rev&rev=450015
Log:
add support for configurable collection implementation classes used for 1:n, m:n references
and query results
use IdentityHashSet to manage deleted, current stored objects

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java?view=diff&rev=450015&r1=450014&r2=450015
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Tue Sep 26 05:17:20 2006
@@ -22,7 +22,6 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.SystemUtils;
@@ -34,15 +33,13 @@
 import org.apache.ojb.broker.OptimisticLockException;
 import org.apache.ojb.broker.PBKey;
 import org.apache.ojb.broker.PBState;
+import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.TransactionAbortedException;
 import org.apache.ojb.broker.TransactionInProgressException;
 import org.apache.ojb.broker.TransactionNotInProgressException;
 import org.apache.ojb.broker.TransientObjectException;
-import org.apache.ojb.broker.PersistenceBrokerInternal;
-import org.apache.ojb.broker.PersistenceBroker;
-import org.apache.ojb.broker.lob.LobHelper;
-import org.apache.ojb.broker.lob.LobHelperImpl;
 import org.apache.ojb.broker.accesslayer.ChainingIterator;
 import org.apache.ojb.broker.accesslayer.ConnectionManagerFactory;
 import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
@@ -66,6 +63,8 @@
 import org.apache.ojb.broker.core.proxy.IndirectionHandler;
 import org.apache.ojb.broker.core.proxy.ProxyFactory;
 import org.apache.ojb.broker.core.proxy.VirtualProxy;
+import org.apache.ojb.broker.lob.LobHelper;
+import org.apache.ojb.broker.lob.LobHelperImpl;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
 import org.apache.ojb.broker.metadata.CollectionDescriptor;
@@ -78,9 +77,9 @@
 import org.apache.ojb.broker.query.QueryByIdentity;
 import org.apache.ojb.broker.query.QueryBySQL;
 import org.apache.ojb.broker.util.BrokerHelper;
-import org.apache.ojb.broker.util.IdentityArrayList;
-import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.broker.util.ClassHelper;
+import org.apache.ojb.broker.util.IdentityHashSet;
+import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.broker.util.configuration.Configuration;
 import org.apache.ojb.broker.util.configuration.ConfigurationException;
 import org.apache.ojb.broker.util.logging.Logger;
@@ -151,6 +150,7 @@
     private ProxyFactory proxyFactory;
     private LobHelper lobHelper;
     private PBKey pbKey;
+    private CollectionTypes collectionTypes;
 
     /**
      * List of objects being stored now, allows to avoid infinite
@@ -162,7 +162,7 @@
     with user implemented equals/hashCode methods of persistence capable objects
     (e.g. objects are equals but PK fields not)
     */
-    private IdentityArrayList nowStoring = new IdentityArrayList();
+    private Collection nowStoring = new IdentityHashSet();
 
     /**
      * Lists for object registration during delete operations.
@@ -177,13 +177,13 @@
     with user implemented equals/hashCode methods of persistence capable objects
     (e.g. objects are equals but PK fields not)
     */
-    private IdentityArrayList markedForDelete = new IdentityArrayList();
+    private Collection markedForDelete = new IdentityHashSet();
 
     /**
      * Used for performance optimization of method
      * {@link #checkRefreshRelationships(Object, org.apache.ojb.broker.Identity, org.apache.ojb.broker.metadata.ClassDescriptor)}
      */
-    private IdentityArrayList skipRefreshRelationship = new IdentityArrayList();
+    private Collection skipRefreshRelationship = new IdentityHashSet();
 
     /**
      * The set of identities of all deleted objects during current transaction
@@ -197,7 +197,7 @@
     the broker does UPDATE. Due the the following set of deleted OIDs
     the broker will know that it should do INSERT.
     */
-    private Set deletedDuringTransaction = new HashSet();
+    private Collection deletedDuringTransaction = new HashSet();
 
     /**
      * Constructor used by {@link PersistenceBrokerFactoryIF} implementation.
@@ -229,11 +229,14 @@
         referencesBroker = new QueryReferenceBroker(this);
         relationshipPrefetcherFactory = new RelationshipPrefetcherFactory(this);
         proxyFactory = AbstractProxyFactory.getProxyFactory();
+        collectionTypes = new CollectionTypes();
     }
 
     public void configure(Configuration pConfig) throws ConfigurationException
     {
         super.configure(pConfig);
+        // pass through config instance
+        collectionTypes.configure(pConfig);
         brokerLeakDetection = pConfig.getBoolean("BrokerLeakDetection", false);
         Class lobHelperClass = pConfig.getClass("LobHelperClass", LobHelperImpl.class);
         Class identityFactoryClass = pConfig.getClass("IdentityFactoryClass", IdentityFactoryImpl.class);
@@ -250,6 +253,11 @@
         }
     }
 
+    public CollectionTypes getCollectionTypes()
+    {
+        return collectionTypes;
+    }
+
     public LobHelper serviceLobHelper()
     {
         return lobHelper;
@@ -546,22 +554,7 @@
      */
     public void delete(Object obj, boolean ignoreReferences) throws PersistenceBrokerException
     {
-        if(isTxCheck() && !isInTransaction())
-        {
-            if(logger.isEnabledFor(Logger.ERROR))
-            {
-                String msg = "No running PB-tx found. Please, only delete objects in context
of a PB-transaction" +
-                    " to avoid side-effects - e.g. when rollback of complex objects.";
-                try
-                {
-                    throw new Exception("** Delete object without active PersistenceBroker
transaction **");
-                }
-                catch(Exception e)
-                {
-                    logger.error(msg, e);
-                }
-            }
-        }
+        doTxCheck();
         try
         {
             doDelete(obj, ignoreReferences);
@@ -941,22 +934,9 @@
         }
 
         //************************************************
+        // check for runnin tx
+        doTxCheck();
         // now store it:
-        if(isTxCheck() && !isInTransaction())
-        {
-            if(logger.isEnabledFor(Logger.ERROR))
-            {
-                try
-                {
-                    throw new Exception("** Try to store object without active PersistenceBroker
transaction **");
-                }
-                catch(Exception e)
-                {
-                    logger.error("No running tx found, please only store in context of an
PB-transaction" +
-                    ", to avoid side-effects - e.g. when rollback of complex objects", e);
-                }
-            }
-        }
         // Invoke events on PersistenceBrokerAware instances and listeners
         if (insert)
         {
@@ -1589,7 +1569,7 @@
      */
     public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
     {
-        return referencesBroker.getCollectionByQuery(query, false);
+        return (Collection) referencesBroker.getCollectionByQuery(collectionTypes.getQuery(),
query, false);
     }
 
     /**
@@ -2308,7 +2288,7 @@
      */
     private void refreshRegistrationLists()
     {
-        if(nowStoring.size() > 0) nowStoring = new IdentityArrayList();
+        if(nowStoring.size() > 0) nowStoring.clear();
         if(deletedDuringTransaction.size() > 0) deletedDuringTransaction.clear();
         /*
         arminw:
@@ -2373,6 +2353,29 @@
         catch (Exception ex)
         {
             throw new PersistenceBrokerException("Unable to create proxy using class:"+baseClassForProxy.getName(),
ex);
+        }
+    }
+
+    /**
+     * Check if store/delete operation is allowed.
+     */
+    protected void doTxCheck()
+    {
+        if(isTxCheck() && !isInTransaction())
+        {
+            if(logger.isEnabledFor(Logger.ERROR))
+            {
+                String msg = "No running PB-tx found. Please, only insert/update/delete objects
in context" +
+                        " of a PB-transaction to avoid side-effects - e.g. when rollback
of complex objects.";
+                try
+                {
+                    throw new Exception("** Insert/Update/Delete object without active PersistenceBroker
transaction **");
+                }
+                catch(Exception e)
+                {
+                    logger.error(msg, e);
+                }
+            }
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message