cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
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 GMT
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 <T extends Query> void performQueries(
+            final Collection<T> 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.
- * <p>
- * <i>For more information see <a href="../../../../../../userguide/index.html"
- * target="_top">Cayenne User Guide. </a> </i>
- * </p>
+ * 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<String, DataMap> dataMaps;
 
     TransactionDataSource readThroughDataSource;
 
@@ -74,7 +69,7 @@
      */
     public DataNode(String name) {
         this.name = name;
-        this.dataMaps = new HashMap();
+        this.dataMaps = new HashMap<String, DataMap>();
         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<DataMap> 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<DataMap> 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 <T extends Query> void performQueries(
+            Collection<T> 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);
+    <T extends Query> void performQueries(
+            Collection<T> 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);
         }
     }



Mime
View raw message