Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 87861 invoked from network); 26 Sep 2006 12:17:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Sep 2006 12:17:23 -0000 Received: (qmail 7830 invoked by uid 500); 26 Sep 2006 12:17:23 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 7692 invoked by uid 500); 26 Sep 2006 12:17:23 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 7681 invoked by uid 500); 26 Sep 2006 12:17:23 -0000 Received: (qmail 7678 invoked by uid 99); 26 Sep 2006 12:17:23 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Sep 2006 05:17:23 -0700 Authentication-Results: idunn.apache.osuosl.org smtp.mail=arminw@apache.org; spf=permerror X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received-SPF: error (idunn.apache.osuosl.org: domain apache.org from 140.211.166.113 cause and error) Received: from [140.211.166.113] ([140.211.166.113:63734] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 02/40-10462-25A19154 for ; Tue, 26 Sep 2006 05:17:22 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id BBBD61A981A; Tue, 26 Sep 2006 05:17:20 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: ojb-commits@db.apache.org From: arminw@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060926121720.BBBD61A981A@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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