Return-Path: Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: (qmail 12607 invoked from network); 30 Nov 2007 18:26:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Nov 2007 18:26:45 -0000 Received: (qmail 26768 invoked by uid 500); 30 Nov 2007 18:26:33 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 26754 invoked by uid 500); 30 Nov 2007 18:26:33 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 26745 invoked by uid 99); 30 Nov 2007 18:26:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Nov 2007 10:26:32 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Nov 2007 18:26:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 10C6D1A9832; Fri, 30 Nov 2007 10:26:24 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r599892 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/access/ Date: Fri, 30 Nov 2007 18:26:23 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071130182624.10C6D1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: aadamchik Date: Fri Nov 30 10:26:20 2007 New Revision: 599892 URL: http://svn.apache.org/viewvc?rev=599892&view=rev Log: cleanup: * DataNode generics and javadocs * deprecating a method with QueryEngine as parameter in OptimisticLockingException Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/OptimisticLockException.java cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryEngine.java cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java?rev=599892&r1=599891&r2=599892&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java Fri Nov 30 10:26:20 2007 @@ -715,7 +715,9 @@ /** * Routes queries to appropriate DataNodes for execution. */ - public void performQueries(final Collection queries, final OperationObserver callback) { + public void performQueries( + final Collection queries, + final OperationObserver callback) { runInTransaction(new Transformer() { @@ -738,7 +740,7 @@ */ public QueryResponse onQuery(final ObjectContext context, final Query query) { checkStopped(); - + // transaction note: // we don't wrap this code in transaction to reduce transaction scope to // just the DB operation for better performance ... query action will start a @@ -768,7 +770,7 @@ int syncType) { checkStopped(); - + DataChannelSyncCallbackAction callbackAction = DataChannelSyncCallbackAction .getCallbackAction( getEntityResolver().getCallbackRegistry(), Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java?rev=599892&r1=599891&r2=599892&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainLegacyQueryAction.java Fri Nov 30 10:26:20 2007 @@ -38,6 +38,7 @@ * * @since 1.2 * @author Andrus Adamchik + * @deprecated since 3.0 - this class should not be public */ // TODO: andrus, 7/19/2006 - why is this public? should probably be deprecated and/or // removed. Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java?rev=599892&r1=599891&r2=599892&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java Fri Nov 30 10:26:20 2007 @@ -25,7 +25,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import javax.sql.DataSource; @@ -40,12 +39,8 @@ import org.apache.cayenne.query.Query; /** - * Describes a single physical data source. This can be a database server, LDAP server, - * etc. - *

- * For more information see Cayenne User Guide. - *

+ * An abstraction of a single physical data storage. This is usually a database server, + * but can potentially be some other storage type like an LDAP server, etc. * * @author Andrus Adamchik */ @@ -58,7 +53,7 @@ protected String dataSourceFactory; protected EntityResolver entityResolver; protected EntitySorter entitySorter; - protected Map dataMaps; + protected Map dataMaps; TransactionDataSource readThroughDataSource; @@ -74,7 +69,7 @@ */ public DataNode(String name) { this.name = name; - this.dataMaps = new HashMap(); + this.dataMaps = new HashMap(); this.readThroughDataSource = new TransactionDataSource(); // since 1.2 we always implement entity sorting, regardless of the underlying DB @@ -120,14 +115,12 @@ /** * Returns an unmodifiable collection of DataMaps handled by this DataNode. */ - public Collection getDataMaps() { + public Collection getDataMaps() { return Collections.unmodifiableCollection(dataMaps.values()); } - public void setDataMaps(Collection dataMaps) { - Iterator it = dataMaps.iterator(); - while (it.hasNext()) { - DataMap map = (DataMap) it.next(); + public void setDataMaps(Collection dataMaps) { + for (DataMap map : dataMaps) { this.dataMaps.put(map.getName(), map); } @@ -144,7 +137,7 @@ } public void removeDataMap(String mapName) { - DataMap map = (DataMap) dataMaps.remove(mapName); + DataMap map = dataMaps.remove(mapName); if (map != null) { entitySorter.setDataMaps(getDataMaps()); } @@ -188,7 +181,9 @@ * * @since 1.1 */ - public void performQueries(Collection queries, OperationObserver callback) { + public void performQueries( + Collection queries, + OperationObserver callback) { int listSize = queries.size(); if (listSize == 0) { @@ -227,9 +222,8 @@ try { DataNodeQueryAction queryRunner = new DataNodeQueryAction(this, callback); - Iterator it = queries.iterator(); - while (it.hasNext()) { - Query nextQuery = (Query) it.next(); + + for (Query nextQuery : queries) { // catch exceptions for each individual query try { Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/OptimisticLockException.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/OptimisticLockException.java?rev=599892&r1=599891&r2=599892&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/OptimisticLockException.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/OptimisticLockException.java Fri Nov 30 10:26:20 2007 @@ -25,6 +25,8 @@ import java.util.Map; import org.apache.cayenne.CayenneRuntimeException; +import org.apache.cayenne.DataObjectUtils; +import org.apache.cayenne.ObjectContext; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.ExpressionFactory; import org.apache.cayenne.map.DbAttribute; @@ -65,17 +67,39 @@ /** * Retrieves fresh snapshot for the failed row. Null row indicates that it was * deleted. + * + * @since 3.0 + */ + public Map getFreshSnapshot(ObjectContext context) { + + Expression qualifier = null; + for (DbAttribute attribute : rootEntity.getPrimaryKeys()) { + Expression attributeQualifier = ExpressionFactory.matchDbExp(attribute + .getName(), qualifierSnapshot.get(attribute.getName())); + + qualifier = (qualifier != null) + ? qualifier.andExp(attributeQualifier) + : attributeQualifier; + } + + SelectQuery query = new SelectQuery(rootEntity, qualifier); + query.setFetchingDataRows(true); + return (Map) DataObjectUtils.objectForQuery(context, query); + } + + /** + * Retrieves fresh snapshot for the failed row. Null row indicates that it was + * deleted. + * + * @deprecated since 3.0 use {@link #getFreshSnapshot(ObjectContext)} instead. */ - // TODO: andrus, 5/30/2006 - use DataChannel instead of QE as a parameter after 1.2 public Map getFreshSnapshot(QueryEngine engine) { // extract PK from the qualifierSnapshot and fetch a row // for PK, ignoring other locking attributes... Expression qualifier = null; - Iterator it = rootEntity.getPrimaryKeys().iterator(); - while (it.hasNext()) { - DbAttribute attribute = (DbAttribute) it.next(); + for (DbAttribute attribute : rootEntity.getPrimaryKeys()) { Expression attributeQualifier = ExpressionFactory.matchDbExp(attribute .getName(), qualifierSnapshot.get(attribute.getName())); Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryEngine.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryEngine.java?rev=599892&r1=599891&r2=599892&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryEngine.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryEngine.java Fri Nov 30 10:26:20 2007 @@ -22,6 +22,7 @@ import java.util.Collection; import org.apache.cayenne.map.EntityResolver; +import org.apache.cayenne.query.Query; /** * Defines methods used to run Cayenne queries. @@ -34,13 +35,15 @@ * Executes a list of queries wrapping them in its own transaction. Results of * execution are passed to {@link OperationObserver}object via its callback methods. * - * @since 1.1 The signiture has changed from List to Collection. + * @since 1.1 The signature has changed from List to Collection. */ - public void performQueries(Collection queries, OperationObserver resultConsumer); + void performQueries( + Collection queries, + OperationObserver resultConsumer); /** * Returns a resolver for this query engine that is capable of resolving between * classes, entity names, and obj/db entities */ - public EntityResolver getEntityResolver(); + EntityResolver getEntityResolver(); } Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java?rev=599892&r1=599891&r2=599892&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java Fri Nov 30 10:26:20 2007 @@ -383,7 +383,7 @@ fail("Optimistic lock failure expected."); } catch (OptimisticLockException ex) { - Map freshFailedRow = ex.getFreshSnapshot(context.getParentDataDomain()); + Map freshFailedRow = ex.getFreshSnapshot(context); assertNotNull(freshFailedRow); assertEquals("LockTest1Updated", freshFailedRow.get("NAME")); } @@ -409,7 +409,7 @@ fail("Optimistic lock failure expected."); } catch (OptimisticLockException ex) { - Map freshFailedRow = ex.getFreshSnapshot(context.getParentDataDomain()); + Map freshFailedRow = ex.getFreshSnapshot(context); assertNull(freshFailedRow); } }