cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kolonit...@apache.org
Subject [1/2] cayenne git commit: fix tests for PostgreSQL 1) add columnNameCaps(CapsStrategy.UPPER) for queries 2) testBLOB should not work for postgres 3) update PostgresAdapter to use non national jdbc types instead national because it is the same for postgre
Date Tue, 10 Feb 2015 19:41:17 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 3e3f0f5f6 -> e14aea35e


fix tests for PostgreSQL
1) add columnNameCaps(CapsStrategy.UPPER) for queries
2) testBLOB should not work for postgres
3) update PostgresAdapter to use non national jdbc types instead national because it is the
same for postgres but national jdbc types it doesn't support


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

Branch: refs/heads/master
Commit: a7b549a5b34422092e676d760bc6fe70468eed3c
Parents: 3e3f0f5
Author: kolonitsky <Alex.Kolonitsky@gmail.com>
Authored: Tue Feb 10 19:42:32 2015 +0300
Committer: kolonitsky <Alex.Kolonitsky@gmail.com>
Committed: Tue Feb 10 19:42:32 2015 +0300

----------------------------------------------------------------------
 .../access/HierarchicalObjectResolver.java      |  3 +-
 .../cayenne/access/PrefetchProcessorNode.java   | 35 ++++++++------------
 .../cayenne/dba/postgres/PostgresAdapter.java   | 19 +++++++++++
 .../cayenne/access/ReturnTypesMappingIT.java    |  6 ++++
 .../org/apache/cayenne/query/SQLSelectIT.java   | 12 +++----
 5 files changed, 45 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/a7b549a5/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
index 788dce5..98884cf 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
@@ -118,8 +118,7 @@ class HierarchicalObjectResolver {
                 return true;
             }
 
-            List objects = processorNode.getResolver().objectsFromDataRows(
-                    processorNode.getDataRows());
+            List<Persistent> objects = processorNode.getResolver().objectsFromDataRows(processorNode.getDataRows());
             processorNode.setObjects(objects);
 
             return true;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a7b549a5/cayenne-server/src/main/java/org/apache/cayenne/access/PrefetchProcessorNode.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/PrefetchProcessorNode.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/PrefetchProcessorNode.java
index 998a8d6..09ce0fa 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/PrefetchProcessorNode.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/PrefetchProcessorNode.java
@@ -21,15 +21,10 @@ package org.apache.cayenne.access;
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.Fault;
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.Persistent;
-import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.*;
 import org.apache.cayenne.query.PrefetchTreeNode;
 import org.apache.cayenne.reflect.ArcProperty;
 import org.apache.cayenne.reflect.ToOneProperty;
@@ -43,7 +38,7 @@ import org.apache.cayenne.util.ToStringBuilder;
 class PrefetchProcessorNode extends PrefetchTreeNode {
 
     List dataRows;
-    List objects;
+    List<Persistent> objects;
 
     ArcProperty incoming;
     ObjectResolver resolver;
@@ -133,30 +128,26 @@ class PrefetchProcessorNode extends PrefetchTreeNode {
         }
     }
 
-    private final void clearNullRelationships(List parentObjects) {
-        Iterator it = parentObjects.iterator();
-        while (it.hasNext()) {
-            Object object = it.next();
+    private void clearNullRelationships(List parentObjects) {
+        for (Object object : parentObjects) {
             if (incoming.readPropertyDirectly(object) instanceof Fault) {
                 incoming.writePropertyDirectly(object, null, null);
             }
         }
     }
 
-    private final void connectToNodeParents(List parentObjects) {
+    private void connectToNodeParents(List parentObjects) {
 
-        Iterator it = parentObjects.iterator();
-        while (it.hasNext()) {
-            Persistent object = (Persistent) it.next();
+        for (Object parentObject : parentObjects) {
+            Persistent object = (Persistent) parentObject;
             List related = (List) partitionByParent.get(object);
             connect(object, related);
         }
     }
 
-    private final void connectToFaultedParents() {
-        Iterator it = partitionByParent.entrySet().iterator();
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
+    private void connectToFaultedParents() {
+        for (Object o : partitionByParent.entrySet()) {
+            Map.Entry entry = (Map.Entry) o;
 
             Persistent object = (Persistent) entry.getKey();
             List related = (List) entry.getValue();
@@ -164,7 +155,7 @@ class PrefetchProcessorNode extends PrefetchTreeNode {
         }
     }
 
-    private final void connect(Persistent object, List related) {
+    private void connect(Persistent object, List related) {
         if (incoming.getRelationship().isToMany()) {
             ValueHolder toManyList = (ValueHolder) incoming.readProperty(object);
 
@@ -183,7 +174,7 @@ class PrefetchProcessorNode extends PrefetchTreeNode {
         return dataRows;
     }
 
-    List getObjects() {
+    List<Persistent> getObjects() {
         return objects;
     }
 
@@ -207,7 +198,7 @@ class PrefetchProcessorNode extends PrefetchTreeNode {
         this.dataRows = dataRows;
     }
 
-    void setObjects(List objects) {
+    void setObjects(List<Persistent> objects) {
         this.objects = objects;
     }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a7b549a5/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
index 6ffe746..36ecba2 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.dba.postgres;
 
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.sql.Types;
 import java.util.Collection;
 import java.util.Collections;
@@ -116,6 +118,23 @@ public class PostgresAdapter extends JdbcAdapter {
         return super.buildAttribute(name, typeName, type, size, scale, allowNulls);
     }
 
+    @Override
+    public void bindParameter(PreparedStatement statement, Object object, int pos, int sqlType,
int scale) throws SQLException, Exception {
+        super.bindParameter(statement, object, pos, mapNTypes(sqlType), scale);
+    }
+
+    private int mapNTypes(int sqlType) {
+        switch (sqlType) {
+            case Types.NCHAR : return Types.CHAR;
+            case Types.NCLOB : return Types.CLOB;
+            case Types.NVARCHAR : return Types.VARCHAR;
+            case Types.LONGNVARCHAR : return Types.LONGVARCHAR;
+
+            default:
+                return sqlType;
+        }
+    }
+
     /**
      * Customizes table creating procedure for PostgreSQL. One difference with
      * generic implementation is that "bytea" type has no explicit length unlike

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a7b549a5/cayenne-server/src/test/java/org/apache/cayenne/access/ReturnTypesMappingIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/ReturnTypesMappingIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/ReturnTypesMappingIT.java
index 16ddb00..b5d7b95 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/ReturnTypesMappingIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/ReturnTypesMappingIT.java
@@ -25,6 +25,7 @@ import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.testdo.return_types.ReturnTypesMap1;
 import org.apache.cayenne.testdo.return_types.ReturnTypesMap2;
 import org.apache.cayenne.testdo.return_types.ReturnTypesMapLobs1;
+import org.apache.cayenne.unit.PostgresUnitDbAdapter;
 import org.apache.cayenne.unit.UnitDbAdapter;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
@@ -40,6 +41,8 @@ import java.util.Date;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeThat;
+import static org.junit.Assume.assumeTrue;
 
 /**
  * Test Types mapping for selected columns
@@ -167,6 +170,9 @@ public class ReturnTypesMappingIT extends ServerCase {
 
     @Test
     public void testBLOB() throws Exception {
+        assumeTrue("In postresql blob_column has OID type, but in JAVA it converts into long
not into byte.",
+                !(unitDbAdapter instanceof PostgresUnitDbAdapter));
+
         if (unitDbAdapter.supportsLobs()) {
             String columnName = "BLOB_COLUMN";
             ReturnTypesMap2 test = context.newObject(ReturnTypesMap2.class);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a7b549a5/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
index 0ff7d34..5f05546 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
@@ -95,7 +95,7 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST");
+		SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST").columnNameCaps(CapsStrategy.UPPER);
 		assertFalse(q1.isFetchingDataRows());
 		List<Artist> result = context.select(q1);
 		assertEquals(20, result.size());
@@ -108,7 +108,7 @@ public class SQLSelectIT extends ServerCase {
 		createArtistsDataSet();
 
 		SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE
ARTIST_NAME = #bind($a)");
-		q1.params("a", "artist3");
+		q1.params("a", "artist3").columnNameCaps(CapsStrategy.UPPER);
 
 		assertFalse(q1.isFetchingDataRows());
 		Artist a = context.selectOne(q1);
@@ -121,7 +121,7 @@ public class SQLSelectIT extends ServerCase {
 		createArtistsDataSet();
 
 		SQLSelect<Artist> q1 = SQLSelect.query(Artist.class,
-				"SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a) OR ARTIST_NAME = #bind($b)");
+				"SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a) OR ARTIST_NAME = #bind($b)").columnNameCaps(CapsStrategy.UPPER);
 		q1.params("a", "artist3").params("b", "artist4");
 
 		List<Artist> result = context.select(q1);
@@ -170,7 +170,7 @@ public class SQLSelectIT extends ServerCase {
 		createArtistsDataSet();
 
 		SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST")
-				.append(" WHERE ARTIST_NAME = #bind($a)").params("a", "artist3");
+				.append(" WHERE ARTIST_NAME = #bind($a)").params("a", "artist3").columnNameCaps(CapsStrategy.UPPER);
 
 		List<Artist> result = context.select(q1);
 		assertEquals(1, result.size());
@@ -182,7 +182,7 @@ public class SQLSelectIT extends ServerCase {
 		createArtistsDataSet();
 
 		List<Artist> result = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME
= #bind($a)")
-				.params("a", "artist3").select(context);
+				.params("a", "artist3").columnNameCaps(CapsStrategy.UPPER).select(context);
 
 		assertEquals(1, result.size());
 	}
@@ -193,7 +193,7 @@ public class SQLSelectIT extends ServerCase {
 		createArtistsDataSet();
 
 		Artist a = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
-				.params("a", "artist3").selectOne(context);
+				.params("a", "artist3").columnNameCaps(CapsStrategy.UPPER).selectOne(context);
 
 		assertEquals("artist3", a.getArtistName());
 	}


Mime
View raw message