cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1576779 - in /cayenne/main/trunk/cayenne-server/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/jdbc/
Date Wed, 12 Mar 2014 15:13:52 GMT
Author: aadamchik
Date: Wed Mar 12 15:13:51 2014
New Revision: 1576779

URL: http://svn.apache.org/r1576779
Log:
CAY-1907 RowReaderFactory

hiding DataRowPostProcessor in the reader factory

Modified:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DefaultRowReaderFactory.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/RowReaderFactory.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java?rev=1576779&r1=1576778&r2=1576779&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
Wed Mar 12 15:13:51 2014
@@ -21,11 +21,13 @@ package org.apache.cayenne.access.jdbc;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryMetadata;
 import org.apache.cayenne.query.SQLAction;
@@ -69,7 +71,8 @@ public abstract class BaseSQLAction impl
 
         QueryMetadata metadata = query.getMetaData(getEntityResolver());
 
-        RowReader<?> rowReader = rowReaderFactory.createRowReader(descriptor, metadata,
null);
+        RowReader<?> rowReader = rowReaderFactory.createRowReader(descriptor, metadata,
adapter,
+                Collections.<ObjAttribute, ColumnDescriptor> emptyMap());
 
         JDBCResultIterator resultReader = new JDBCResultIterator(null, resultSet, rowReader);
 

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java?rev=1576779&r1=1576778&r2=1576779&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
Wed Mar 12 15:13:51 2014
@@ -38,6 +38,7 @@ import org.apache.cayenne.dba.TypesMappi
 import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.query.BatchQuery;
 import org.apache.cayenne.query.DeleteBatchQuery;
 import org.apache.cayenne.query.InsertBatchQuery;
@@ -286,7 +287,8 @@ public class BatchAction extends BaseSQL
         }
 
         RowReader<?> rowReader = rowReaderFactory.createRowReader(keyRowDescriptor,
-                query.getMetaData(getEntityResolver()), null);
+                query.getMetaData(getEntityResolver()), adapter,
+                Collections.<ObjAttribute, ColumnDescriptor> emptyMap());
         ResultIterator iterator = new JDBCResultIterator(null, keysRS, rowReader);
 
         observer.nextGeneratedRows(query, iterator);

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DefaultRowReaderFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DefaultRowReaderFactory.java?rev=1576779&r1=1576778&r2=1576779&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DefaultRowReaderFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/DefaultRowReaderFactory.java
Wed Mar 12 15:13:51 2014
@@ -27,8 +27,8 @@ import java.util.Map.Entry;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.jdbc.DataRowPostProcessor.ColumnOverride;
-import org.apache.cayenne.access.trans.SelectTranslator;
 import org.apache.cayenne.access.types.ExtendedType;
+import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjAttribute;
@@ -43,10 +43,11 @@ import org.apache.cayenne.reflect.ClassD
 public class DefaultRowReaderFactory implements RowReaderFactory {
 
     @Override
-    public RowReader<?> createRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata,
-            SelectTranslator translator) {
+    public RowReader<?> createRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata,
DbAdapter adapter,
+            Map<ObjAttribute, ColumnDescriptor> attributeOverrides) {
 
-        PostprocessorFactory postProcessorFactory = new PostprocessorFactory(translator,
descriptor, queryMetadata);
+        PostprocessorFactory postProcessorFactory = new PostprocessorFactory(descriptor,
queryMetadata, adapter,
+                attributeOverrides);
 
         List<Object> rsMapping = queryMetadata.getResultSetMapping();
         if (rsMapping == null) {
@@ -113,15 +114,18 @@ public class DefaultRowReaderFactory imp
     private class PostprocessorFactory {
 
         private QueryMetadata queryMetadata;
-        private SelectTranslator translator;
+        private DbAdapter adapter;
+        private Map<ObjAttribute, ColumnDescriptor> attributeOverrides;
         private RowDescriptor rowDescriptor;
 
         private boolean created;
         private DataRowPostProcessor postProcessor;
 
-        PostprocessorFactory(SelectTranslator translator, RowDescriptor rowDescriptor, QueryMetadata
queryMetadata) {
+        PostprocessorFactory(RowDescriptor rowDescriptor, QueryMetadata queryMetadata, DbAdapter
adapter,
+                Map<ObjAttribute, ColumnDescriptor> attributeOverrides) {
             this.rowDescriptor = rowDescriptor;
-            this.translator = translator;
+            this.adapter = adapter;
+            this.attributeOverrides = attributeOverrides;
             this.queryMetadata = queryMetadata;
         }
 
@@ -137,13 +141,6 @@ public class DefaultRowReaderFactory imp
 
         private DataRowPostProcessor create() {
 
-            // TODO: ugly... ideally we should care not about the translator...
-
-            if (translator == null) {
-                return null;
-            }
-
-            Map<ObjAttribute, ColumnDescriptor> attributeOverrides = translator.getAttributeOverrides();
             if (attributeOverrides.isEmpty()) {
                 return null;
             }
@@ -180,8 +177,7 @@ public class DefaultRowReaderFactory imp
                     continue;
                 }
 
-                ExtendedType converter = translator.getAdapter().getExtendedTypes()
-                        .getRegisteredType(attribute.getType());
+                ExtendedType converter = adapter.getExtendedTypes().getRegisteredType(attribute.getType());
 
                 Collection<ColumnOverride> overrides = columnOverrides.get(entity.getName());
 

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/RowReaderFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/RowReaderFactory.java?rev=1576779&r1=1576778&r2=1576779&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/RowReaderFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/RowReaderFactory.java
Wed Mar 12 15:13:51 2014
@@ -18,7 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne.access.jdbc;
 
-import org.apache.cayenne.access.trans.SelectTranslator;
+import java.util.Map;
+
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.query.QueryMetadata;
 
 /**
@@ -28,5 +31,6 @@ import org.apache.cayenne.query.QueryMet
  */
 public interface RowReaderFactory {
 
-    RowReader<?> createRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata,
SelectTranslator translator);
+    RowReader<?> createRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata,
DbAdapter adapter,
+            Map<ObjAttribute, ColumnDescriptor> attributeOverrides);
 }

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java?rev=1576779&r1=1576778&r2=1576779&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
Wed Mar 12 15:13:51 2014
@@ -199,7 +199,8 @@ public class SQLTemplateAction implement
 
         ExtendedTypeMap types = getAdapter().getExtendedTypes();
         RowDescriptorBuilder builder = configureRowDescriptorBuilder(compiled, resultSet);
-        RowReader<?> rowReader = rowReaderFactory.createRowReader(builder.getDescriptor(types),
queryMetadata, null);
+        RowReader<?> rowReader = rowReaderFactory.createRowReader(builder.getDescriptor(types),
queryMetadata, adapter,
+                Collections.<ObjAttribute, ColumnDescriptor> emptyMap());
 
         JDBCResultIterator result = new JDBCResultIterator(statement, resultSet, rowReader);
 

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java?rev=1576779&r1=1576778&r2=1576779&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
Wed Mar 12 15:13:51 2014
@@ -92,7 +92,7 @@ public class SelectAction extends BaseSQ
         RowDescriptor descriptor = new RowDescriptorBuilder().setColumns(translator.getResultColumns()).getDescriptor(
                 getAdapter().getExtendedTypes());
         
-        RowReader<?> rowReader = rowReaderFactory.createRowReader(descriptor, md, translator);
+        RowReader<?> rowReader = rowReaderFactory.createRowReader(descriptor, md, adapter,
translator.getAttributeOverrides());
 
         JDBCResultIterator workerIterator = new JDBCResultIterator(prepStmt, rs, rowReader);
 

Modified: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java?rev=1576779&r1=1576778&r2=1576779&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
Wed Mar 12 15:13:51 2014
@@ -23,11 +23,14 @@ import static org.mockito.Mockito.mock;
 
 import java.sql.Connection;
 import java.sql.Statement;
+import java.util.Collections;
 
 import junit.framework.TestCase;
 
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.query.MockQueryMetadata;
 
 import com.mockrunner.mock.jdbc.MockConnection;
@@ -41,9 +44,10 @@ public class JDBCResultIteratorTest exte
         Statement s = new MockStatement(c);
         MockResultSet rs = new MockResultSet("rs");
         rs.addColumn("a", new Object[] { "1", "2", "3" });
-        
+
         RowDescriptor descriptor = new RowDescriptorBuilder().setResultSet(rs).getDescriptor(new
ExtendedTypeMap());
-        RowReader<?> rowReader = new DefaultRowReaderFactory().createRowReader(descriptor,
new MockQueryMetadata(), null);
+        RowReader<?> rowReader = new DefaultRowReaderFactory().createRowReader(descriptor,
new MockQueryMetadata(),
+                mock(DbAdapter.class), Collections.<ObjAttribute, ColumnDescriptor>
emptyMap());
 
         JDBCResultIterator it = new JDBCResultIterator(s, rs, rowReader);
 



Mime
View raw message