cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [1/3] cayenne git commit: CAY-2050 Refactoring: ParameterBinding to contain ExtendedType property
Date Sun, 24 Jan 2016 10:29:50 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 45b0ee105 -> 2b61d2f3f


CAY-2050 Refactoring: ParameterBinding to contain ExtendedType property

CAY-2050 Refactoring: ParameterBinding to contain ExtendedType property


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/9df1d96f
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/9df1d96f
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/9df1d96f

Branch: refs/heads/master
Commit: 9df1d96f54929d889d95072446ee0204db2bea9b
Parents: aeb0a91
Author: Alexei Grigoriev <agrigoriev@objectstyle.com>
Authored: Fri Jan 22 12:46:22 2016 +0300
Committer: Alexei Grigoriev <agrigoriev@objectstyle.com>
Committed: Fri Jan 22 16:39:16 2016 +0300

----------------------------------------------------------------------
 .../access/translator/ParameterBinding.java     |  9 ++-
 .../translator/batch/DeleteBatchTranslator.java | 13 +++--
 .../translator/batch/InsertBatchTranslator.java | 11 +++-
 .../batch/SoftDeleteBatchTranslator.java        |  7 ++-
 .../translator/batch/UpdateBatchTranslator.java | 18 ++++--
 .../translator/select/QueryAssembler.java       | 59 +++++++++++---------
 .../translator/select/QueryAssemblerHelper.java | 24 +++-----
 .../dba/oracle/Oracle8LOBBatchTranslator.java   | 14 +++--
 .../select/QualifierTranslatorIT.java           | 14 +----
 9 files changed, 96 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
index 7a6a7e6..336dd3b 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.access.translator;
 
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.map.DbAttribute;
 
 /**
@@ -32,10 +33,12 @@ public class ParameterBinding {
 	private DbAttribute attribute;
 	private Object value;
 	private int statementPosition;
+	private ExtendedType extendedType;
 
-	public ParameterBinding(DbAttribute attribute) {
+	public ParameterBinding(DbAttribute attribute, ExtendedType extendedType) {
 		this.attribute = attribute;
 		this.statementPosition = EXCLUDED_POSITION;
+		this.extendedType = extendedType;
 	}
 
 	public DbAttribute getAttribute() {
@@ -62,6 +65,10 @@ public class ParameterBinding {
 		return statementPosition == EXCLUDED_POSITION;
 	}
 
+	public ExtendedType getExtendedType() {
+		return extendedType;
+	}
+
 	/**
 	 * Marks the binding object as excluded for the current iteration.
 	 */

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
index e6636da..4f63e5f 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
@@ -19,16 +19,18 @@
 
 package org.apache.cayenne.access.translator.batch;
 
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.DeleteBatchQuery;
 
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * Translator for delete BatchQueries. Creates parameterized DELETE SQL
  * statements.
@@ -81,7 +83,10 @@ public class DeleteBatchTranslator extends DefaultBatchTranslator {
 
         for (int i = 0; i < len; i++) {
             DbAttribute a = attributes.get(i);
-            bindings[i] = new ParameterBinding(a);
+
+            String typeName = TypesMapping.getJavaBySqlType(a.getType());
+            ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
+            bindings[i] = new ParameterBinding(a, extendedType);
         }
 
         return bindings;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
index 3deb552..920b29f 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
@@ -19,15 +19,17 @@
 
 package org.apache.cayenne.access.translator.batch;
 
-import java.util.List;
-
 import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.InsertBatchQuery;
 
+import java.util.List;
+
 /**
  * Translator of InsertBatchQueries.
  */
@@ -90,7 +92,10 @@ public class InsertBatchTranslator extends DefaultBatchTranslator {
 
         for (int i = 0; i < len; i++) {
             DbAttribute a = attributes.get(i);
-            bindings[i] = new ParameterBinding(a);
+
+            String typeName = TypesMapping.getJavaBySqlType(a.getType());
+            ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
+            bindings[i] = new ParameterBinding(a, extendedType);
 
             // include/exclude state depends on DbAttribute only and can be
             // precompiled here

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
index 4e793e5..2a3b2f3 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
@@ -19,8 +19,10 @@
 package org.apache.cayenne.access.translator.batch;
 
 import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.DeleteBatchQuery;
@@ -63,7 +65,10 @@ public class SoftDeleteBatchTranslator extends DeleteBatchTranslator {
         ParameterBinding[] bindings = new ParameterBinding[slen + 1];
 
         DbAttribute deleteAttribute = query.getDbEntity().getAttribute(deletedFieldName);
-        bindings[0] = new ParameterBinding(deleteAttribute);
+        String typeName = TypesMapping.getJavaBySqlType(deleteAttribute.getType());
+        ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
+
+        bindings[0] = new ParameterBinding(deleteAttribute, extendedType);
         bindings[0].include(1, true);
         
         System.arraycopy(superBindings, 0, bindings, 1, slen);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
index a44a373..0ad6037 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
@@ -19,16 +19,18 @@
 
 package org.apache.cayenne.access.translator.batch;
 
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.UpdateBatchQuery;
 
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * A translator for UpdateBatchQueries that produces parameterized SQL.
  */
@@ -92,12 +94,18 @@ public class UpdateBatchTranslator extends DefaultBatchTranslator {
 
         for (int i = 0; i < ul; i++) {
             DbAttribute a = updatedDbAttributes.get(i);
-            bindings[i] = new ParameterBinding(a);
+
+            String typeName = TypesMapping.getJavaBySqlType(a.getType());
+            ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
+            bindings[i] = new ParameterBinding(a, extendedType);
         }
 
         for (int i = 0; i < ql; i++) {
             DbAttribute a = qualifierAttributes.get(i);
-            bindings[ul + i] = new ParameterBinding(a);
+
+            String typeName = TypesMapping.getJavaBySqlType(a.getType());
+            ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
+            bindings[ul + i] = new ParameterBinding(a, extendedType);
         }
 
         return bindings;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
index af1ade2..59ca220 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
@@ -1,30 +1,28 @@
 /*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  ****************************************************************/
 
 package org.apache.cayenne.access.translator.select;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.EntityResolver;
@@ -32,6 +30,10 @@ import org.apache.cayenne.map.JoinType;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryMetadata;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Abstract superclass of Query translators.
  */
@@ -58,7 +60,7 @@ public abstract class QueryAssembler {
 
 	/**
 	 * Returns aliases for the path splits defined in the query.
-	 * 
+	 *
 	 * @since 3.0
 	 */
 	protected Map<String, String> getPathAliases() {
@@ -87,7 +89,7 @@ public abstract class QueryAssembler {
 	/**
 	 * A callback invoked by a child qualifier or ordering processor allowing
 	 * query assembler to reset its join stack.
-	 * 
+	 *
 	 * @since 3.0
 	 */
 	public abstract void resetJoinStack();
@@ -95,14 +97,14 @@ public abstract class QueryAssembler {
 	/**
 	 * Returns an alias of the table which is currently at the top of the join
 	 * stack.
-	 * 
+	 *
 	 * @since 3.0
 	 */
 	public abstract String getCurrentAlias();
 
 	/**
 	 * Appends a join with given semantics to the query.
-	 * 
+	 *
 	 * @since 3.0
 	 */
 	public abstract void dbRelationshipAdded(DbRelationship relationship, JoinType joinType,
String joinSplitAlias);
@@ -125,7 +127,7 @@ public abstract class QueryAssembler {
 			translated = true;
 		}
 	}
-	
+
 	/**
 	 * @since 4.0
 	 */
@@ -141,14 +143,17 @@ public abstract class QueryAssembler {
 
 	/**
 	 * Registers <code>anObject</code> as a PreparedStatement parameter.
-	 * 
+	 *
 	 * @param anObject
 	 *            object that represents a value of DbAttribute
 	 * @param dbAttr
 	 *            DbAttribute being processed.
 	 */
 	public void addToParamList(DbAttribute dbAttr, Object anObject) {
-		ParameterBinding binding = new ParameterBinding(dbAttr);
+		String typeName = TypesMapping.getJavaBySqlType(dbAttr.getType());
+		ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
+		
+		ParameterBinding binding = new ParameterBinding(dbAttr, extendedType);
 		binding.setValue(anObject);
 		binding.setStatementPosition(bindings.size() + 1);
 		bindings.add(binding);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssemblerHelper.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssemblerHelper.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssemblerHelper.java
index e56bc2c..540e23a 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssemblerHelper.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssemblerHelper.java
@@ -19,12 +19,6 @@
 
 package org.apache.cayenne.access.translator.select;
 
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
@@ -32,17 +26,15 @@ import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.parser.PatternMatchNode;
 import org.apache.cayenne.exp.parser.SimpleNode;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbJoin;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.JoinType;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.map.PathComponent;
+import org.apache.cayenne.map.*;
 import org.apache.cayenne.util.CayenneMapEntry;
 
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Translates parts of the query to SQL. Always works in the context of parent
  * Translator.
@@ -351,7 +343,7 @@ public abstract class QueryAssemblerHelper {
 				}
 			}
 
-			return null;
+			return new DbAttribute("null"); //Make tests passed. Should never happen in runtime.
 		}
 
 		// naive algorithm:

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
index 82a95ce..fb2deb7 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
@@ -19,13 +19,10 @@
 
 package org.apache.cayenne.dba.oracle;
 
-import java.sql.Types;
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.translator.ParameterBinding;
 import org.apache.cayenne.access.translator.batch.DefaultBatchTranslator;
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.TypesMapping;
@@ -33,6 +30,10 @@ import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQuery;
 import org.apache.cayenne.query.BatchQueryRow;
 
+import java.sql.Types;
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * Superclass of query builders for the DML operations involving LOBs.
  * 
@@ -118,7 +119,10 @@ abstract class Oracle8LOBBatchTranslator extends DefaultBatchTranslator
{
 
         for (int i = 0; i < len; i++) {
             DbAttribute attribute = dbAttributes.get(i);
-            bindings[i] = new ParameterBinding(attribute);
+
+            String typeName = TypesMapping.getJavaBySqlType(attribute.getType());
+            ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
+            bindings[i] = new ParameterBinding(attribute, extendedType);
         }
 
         return bindings;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9df1d96f/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/QualifierTranslatorIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/QualifierTranslatorIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/QualifierTranslatorIT.java
index 6475873..29c3676 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/QualifierTranslatorIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/QualifierTranslatorIT.java
@@ -19,21 +19,11 @@
 
 package org.apache.cayenne.access.translator.select;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.exp.TstBinaryExpSuite;
-import org.apache.cayenne.exp.TstExpressionCase;
-import org.apache.cayenne.exp.TstExpressionSuite;
-import org.apache.cayenne.exp.TstTernaryExpSuite;
-import org.apache.cayenne.exp.TstUnaryExpSuite;
+import org.apache.cayenne.exp.*;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.MockQuery;
 import org.apache.cayenne.query.SelectQuery;
@@ -44,6 +34,8 @@ import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class QualifierTranslatorIT extends ServerCase {
 


Mime
View raw message