cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kolonit...@apache.org
Subject cayenne git commit: fix tests for oracle, fix loading relationships for oracle
Date Mon, 16 Feb 2015 12:53:29 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master a9f43dbed -> 3ac0046b4


fix tests for oracle, fix loading relationships for oracle


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

Branch: refs/heads/master
Commit: 3ac0046b4bb785b04c34caebd3ed1d7cfef42e90
Parents: a9f43db
Author: kolonitsky <Alex.Kolonitsky@gmail.com>
Authored: Mon Feb 16 15:49:33 2015 +0300
Committer: kolonitsky <Alex.Kolonitsky@gmail.com>
Committed: Mon Feb 16 15:49:33 2015 +0300

----------------------------------------------------------------------
 .../org/apache/cayenne/access/DbLoader.java     |  16 +++
 .../cayenne/dba/oracle/OracleAdapter.java       |  40 ++----
 .../apache/cayenne/map/naming/ExportedKey.java  |  52 ++++++-
 .../org/apache/cayenne/access/DbLoaderIT.java   |   9 +-
 .../org/apache/cayenne/query/SQLSelectIT.java   | 136 +++++++++----------
 .../org/apache/cayenne/query/SelectQueryIT.java |   5 +-
 6 files changed, 150 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/3ac0046b/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java b/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
index 07b674c..27007e8 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DbLoader.java
@@ -43,6 +43,7 @@ import org.apache.cayenne.map.naming.LegacyNameGenerator;
 import org.apache.cayenne.map.naming.NameCheckers;
 import org.apache.cayenne.map.naming.ObjectNameGenerator;
 import org.apache.cayenne.util.EntityMergeSupport;
+import org.apache.cayenne.util.EqualsBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -527,6 +528,21 @@ public class DbLoader {
                     continue;
                 }
 
+                if (!new EqualsBuilder()
+                        .append(pkEntity.getCatalog(), key.pkCatalog)
+                        .append(pkEntity.getSchema(), key.pkSchema)
+                        .append(fkEntity.getCatalog(), key.fkCatalog)
+                        .append(fkEntity.getSchema(), key.fkSchema)
+                        .isEquals()) {
+
+                    LOGGER.info("Skip relation: '" + key + "' because it related to objects
from other catalog/schema");
+                    LOGGER.info("     relation primary key: '" + key.pkCatalog + "." + key.pkSchema
+ "'");
+                    LOGGER.info("       primary key entity: '" + pkEntity.getCatalog() +
"." + pkEntity.getSchema() + "'");
+                    LOGGER.info("     relation foreign key: '" + key.fkCatalog + "." + key.fkSchema
+ "'");
+                    LOGGER.info("       foreign key entity: '" + fkEntity.getCatalog() +
"." + fkEntity.getSchema() + "'");
+                    continue;
+                }
+
                 // forwardRelationship is a reference from table with primary key
                 DbRelationship forwardRelationship = new DbRelationship(generateName(pkEntity,
key, true));
                 forwardRelationship.setSourceEntity(pkEntity);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3ac0046b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
index f810753..50d621c 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
@@ -71,6 +71,7 @@ public class OracleAdapter extends JdbcAdapter {
     public static final String ORACLE_FLOAT = "FLOAT";
     public static final String ORACLE_BLOB = "BLOB";
     public static final String ORACLE_CLOB = "CLOB";
+    public static final String ORACLE_NCLOB = "NCLOB";
 
     public static final String TRIM_FUNCTION = "RTRIM";
     public static final String NEW_CLOB_FUNCTION = "EMPTY_CLOB()";
@@ -220,12 +221,8 @@ public class OracleAdapter extends JdbcAdapter {
      */
     @Override
     public Collection<String> dropTableStatements(DbEntity table) {
-        QuotingStrategy context = getQuotingStrategy();
-        StringBuffer buf = new StringBuffer("DROP TABLE ");
-        buf.append(context.quotedFullyQualifiedName(table));
-
-        buf.append(" CASCADE CONSTRAINTS");
-        return Collections.singleton(buf.toString());
+        return Collections.singleton("DROP TABLE " + getQuotingStrategy().quotedFullyQualifiedName(table)
+                + " CASCADE CONSTRAINTS");
     }
 
     @Override
@@ -253,40 +250,25 @@ public class OracleAdapter extends JdbcAdapter {
      * and has non-positive precision it is converted to INTEGER.
      */
     @Override
-    public DbAttribute buildAttribute(
-            String name,
-            String typeName,
-            int type,
-            int size,
-            int scale,
-            boolean allowNulls) {
-
-        DbAttribute attr = super.buildAttribute(
-                name,
-                typeName,
-                type,
-                size,
-                scale,
-                allowNulls);
+    public DbAttribute buildAttribute(String name, String typeName, int type, int size, int
scale, boolean allowNulls) {
+        DbAttribute attr = super.buildAttribute(name, typeName, type, size, scale, allowNulls);
 
         if (type == Types.DECIMAL && scale <= 0) {
             attr.setType(Types.INTEGER);
             attr.setScale(-1);
-        }
-        else if (type == Types.OTHER) {
+        } else if (type == Types.OTHER) {
             // in this case we need to guess the attribute type
             // based on its string value
             if (ORACLE_FLOAT.equals(typeName)) {
                 attr.setType(Types.FLOAT);
-            }
-            else if (ORACLE_BLOB.equals(typeName)) {
+            } else if (ORACLE_BLOB.equals(typeName)) {
                 attr.setType(Types.BLOB);
-            }
-            else if (ORACLE_CLOB.equals(typeName)) {
+            } else if (ORACLE_CLOB.equals(typeName)) {
                 attr.setType(Types.CLOB);
+            } else if (ORACLE_NCLOB.equals(typeName)) {
+                attr.setType(Types.NCLOB);
             }
-        }
-        else if (type == Types.DATE) {
+        } else if (type == Types.DATE) {
             // Oracle DATE can store JDBC TIMESTAMP
             if ("DATE".equals(typeName)) {
                 attr.setType(Types.TIMESTAMP);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3ac0046b/cayenne-server/src/main/java/org/apache/cayenne/map/naming/ExportedKey.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/naming/ExportedKey.java b/cayenne-server/src/main/java/org/apache/cayenne/map/naming/ExportedKey.java
index ab8229f..9a415d8 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/naming/ExportedKey.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/naming/ExportedKey.java
@@ -44,6 +44,9 @@ import java.sql.SQLException;
  * 
  */
 public class ExportedKey implements Comparable {
+
+    public final String pkCatalog;
+    public final String pkSchema;
     /**
      * Name of source table
      */
@@ -54,6 +57,8 @@ public class ExportedKey implements Comparable {
      */
     public final String pkColumn;
 
+    public final String fkCatalog;
+    public final String fkSchema;
     /**
      * Name of destination table
      */
@@ -79,9 +84,18 @@ public class ExportedKey implements Comparable {
 
     public ExportedKey(String pkTable, String pkColumn, String pkName,
                        String fkTable, String fkColumn, String fkName, short keySeq) {
+        this(null, null, pkTable, pkColumn, pkName, null, null, fkTable, fkColumn, fkName,
keySeq);
+    }
+
+    public ExportedKey(String pkCatalog, String pkSchema, String pkTable, String pkColumn,
String pkName,
+                       String fkCatalog, String fkSchema, String fkTable, String fkColumn,
String fkName, short keySeq) {
+       this.pkCatalog  = pkCatalog;
+       this.pkSchema  = pkSchema;
        this.pkTable  = pkTable;
        this.pkColumn = pkColumn;
        this.pkName   = pkName;
+       this.fkCatalog  = fkCatalog;
+       this.fkSchema  = fkSchema;
        this.fkTable  = fkTable;
        this.fkColumn = fkColumn;
        this.fkName   = fkName;
@@ -97,16 +111,37 @@ public class ExportedKey implements Comparable {
      */
     public static ExportedKey extractData(ResultSet rs) throws SQLException {
         return new ExportedKey(
+                rs.getString("PKTABLE_CAT"),
+                rs.getString("PKTABLE_SCHEM"),
                 rs.getString("PKTABLE_NAME"),
                 rs.getString("PKCOLUMN_NAME"),
                 rs.getString("PK_NAME"),
+                rs.getString("FKTABLE_CAT"),
+                rs.getString("FKTABLE_SCHEM"),
                 rs.getString("FKTABLE_NAME"),
                 rs.getString("FKCOLUMN_NAME"),
                 rs.getString("FK_NAME"),
                 rs.getShort("KEY_SEQ")
         );
     }
-    
+
+
+    public String getPkCatalog() {
+        return pkCatalog;
+    }
+
+    public String getPkSchema() {
+        return pkSchema;
+    }
+
+    public String getFkCatalog() {
+        return fkCatalog;
+    }
+
+    public String getFkSchema() {
+        return fkSchema;
+    }
+
     /**
      * @return source table name
      */
@@ -167,8 +202,12 @@ public class ExportedKey implements Comparable {
         }
         ExportedKey rhs = (ExportedKey) obj;
         return new EqualsBuilder()
+                .append(this.pkCatalog, rhs.pkCatalog)
+                .append(this.pkSchema, rhs.pkSchema)
                 .append(this.pkTable, rhs.pkTable)
                 .append(this.pkColumn, rhs.pkColumn)
+                .append(this.fkCatalog, rhs.fkCatalog)
+                .append(this.fkSchema, rhs.fkSchema)
                 .append(this.fkTable, rhs.fkTable)
                 .append(this.fkColumn, rhs.fkColumn)
                 .append(this.fkName, rhs.fkName)
@@ -180,8 +219,12 @@ public class ExportedKey implements Comparable {
     @Override
     public int hashCode() {
         return new HashCodeBuilder()
+                .append(pkCatalog)
+                .append(pkSchema)
                 .append(pkTable)
                 .append(pkColumn)
+                .append(fkCatalog)
+                .append(fkSchema)
                 .append(fkTable)
                 .append(fkColumn)
                 .append(fkName)
@@ -201,8 +244,12 @@ public class ExportedKey implements Comparable {
 
         ExportedKey rhs = (ExportedKey) obj;
         return new CompareToBuilder()
+                .append(pkCatalog, rhs.pkCatalog)
+                .append(pkSchema, rhs.pkSchema)
                 .append(pkTable, rhs.pkTable)
                 .append(pkName, rhs.pkName)
+                .append(fkCatalog, rhs.fkCatalog)
+                .append(fkSchema, rhs.fkSchema)
                 .append(fkTable, rhs.fkTable)
                 .append(fkName, rhs.fkName)
                 .append(keySeq, rhs.keySeq)
@@ -217,6 +264,7 @@ public class ExportedKey implements Comparable {
     }
 
     public String getStrKey() {
-        return pkTable + "." + pkColumn + " <- " + fkTable + "." + fkColumn;
+        return pkCatalog + "." + pkSchema + "." + pkTable + "." + pkColumn
+                + " <- " + fkCatalog + "." + fkSchema + "." + fkTable + "." + fkColumn;
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3ac0046b/cayenne-server/src/test/java/org/apache/cayenne/access/DbLoaderIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DbLoaderIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DbLoaderIT.java
index 206c3aa..a9fccc4 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DbLoaderIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DbLoaderIT.java
@@ -41,10 +41,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.sql.Types;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import static org.junit.Assert.*;
 
@@ -243,8 +240,8 @@ public class DbLoaderIT extends ServerCase {
         assertFalse(a.isGenerated());
 
         if (adapter.supportsGeneratedKeys()) {
-            DbEntity bag = getDbEntity(map, "BAG");
-            DbAttribute id = bag.getAttribute("ID");
+            DbEntity bag = getDbEntity(map, "GENERATED_COLUMN_TEST");
+            DbAttribute id = bag.getAttribute("GENERATED_COLUMN");
             assertTrue(id.isPrimaryKey());
             assertTrue(id.isGenerated());
         }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3ac0046b/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 5f05546..155eff4 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
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.sql.Date;
+import java.sql.Types;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,7 +32,7 @@ import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
@@ -48,28 +48,28 @@ public class SQLSelectIT extends ServerCase {
 	@Inject
 	private DBHelper dbHelper;
 
-	private TableHelper tArtist;
+	private TableHelper tPainting;
 
 	@Before
 	public void before() {
-		tArtist = new TableHelper(dbHelper, "ARTIST").setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH");
-	}
-
-	protected void createArtistsDataSet() throws Exception {
-
-		long dateBase = System.currentTimeMillis();
 
-		for (int i = 1; i <= 20; i++) {
-			tArtist.insert(i, "artist" + i, new java.sql.Date(dateBase + 10000 * i));
-		}
+		tPainting = new TableHelper(dbHelper, "PAINTING")
+                .setColumns("PAINTING_ID", "PAINTING_TITLE", "ESTIMATED_PRICE")
+                .setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.DECIMAL);
 	}
 
+    protected void createArtistsDataSet() throws Exception {
+        for (int i = 1; i <= 20; i++) {
+            tPainting.insert(i, "painting" + i, 10000. * i);
+        }
+    }
+
 	@Test
 	public void test_DataRows_DataMapNameRoot() throws Exception {
 
 		createArtistsDataSet();
 
-		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("testmap", "SELECT * FROM ARTIST");
+		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("testmap", "SELECT * FROM PAINTING");
 		assertTrue(q1.isFetchingDataRows());
 
 		List<DataRow> result = context.select(q1);
@@ -82,7 +82,7 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
+		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM PAINTING");
 		assertTrue(q1.isFetchingDataRows());
 
 		List<DataRow> result = context.select(q1);
@@ -95,11 +95,11 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST").columnNameCaps(CapsStrategy.UPPER);
+		SQLSelect<Painting> q1 = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING").columnNameCaps(CapsStrategy.UPPER);
 		assertFalse(q1.isFetchingDataRows());
-		List<Artist> result = context.select(q1);
+		List<Painting> result = context.select(q1);
 		assertEquals(20, result.size());
-		assertTrue(result.get(0) instanceof Artist);
+		assertTrue(result.get(0) instanceof Painting);
 	}
 
 	@Test
@@ -107,12 +107,12 @@ 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").columnNameCaps(CapsStrategy.UPPER);
+		SQLSelect<Painting> q1 = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING
WHERE PAINTING_TITLE = #bind($a)");
+		q1.params("a", "painting3").columnNameCaps(CapsStrategy.UPPER);
 
 		assertFalse(q1.isFetchingDataRows());
-		Artist a = context.selectOne(q1);
-		assertEquals("artist3", a.getArtistName());
+        Painting a = context.selectOne(q1);
+		assertEquals("painting3", a.getPaintingTitle());
 	}
 
 	@Test
@@ -120,18 +120,18 @@ 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)").columnNameCaps(CapsStrategy.UPPER);
-		q1.params("a", "artist3").params("b", "artist4");
+		SQLSelect<Painting> q1 = SQLSelect.query(Painting.class,
+				"SELECT * FROM PAINTING WHERE PAINTING_TITLE = #bind($a) OR PAINTING_TITLE = #bind($b)").columnNameCaps(CapsStrategy.UPPER);
+		q1.params("a", "painting3").params("b", "painting4");
 
-		List<Artist> result = context.select(q1);
+		List<Painting> result = context.select(q1);
 		assertEquals(2, result.size());
 	}
 
 	@Test
 	public void test_DataRows_ColumnNameCaps() throws Exception {
 
-		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST WHERE ARTIST_NAME
= 'artist2'");
+		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM PAINTING WHERE PAINTING_TITLE
= 'painting2'");
 		q1.upperColumnNames();
 
 		SQLTemplate r1 = (SQLTemplate) q1.getReplacementQuery(context.getEntityResolver());
@@ -147,7 +147,7 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
+		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM PAINTING");
 		q1.limit(5);
 
 		assertEquals(5, context.select(q1).size());
@@ -158,7 +158,7 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
+		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM PAINTING");
 		q1.offset(4);
 
 		assertEquals(16, context.select(q1).size());
@@ -169,10 +169,10 @@ 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").columnNameCaps(CapsStrategy.UPPER);
+		SQLSelect<Painting> q1 = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING")
+				.append(" WHERE PAINTING_TITLE = #bind($a)").params("a", "painting3").columnNameCaps(CapsStrategy.UPPER);
 
-		List<Artist> result = context.select(q1);
+		List<Painting> result = context.select(q1);
 		assertEquals(1, result.size());
 	}
 
@@ -181,8 +181,8 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		List<Artist> result = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME
= #bind($a)")
-				.params("a", "artist3").columnNameCaps(CapsStrategy.UPPER).select(context);
+		List<Painting> result = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING WHERE
PAINTING_TITLE = #bind($a)")
+				.params("a", "painting3").columnNameCaps(CapsStrategy.UPPER).select(context);
 
 		assertEquals(1, result.size());
 	}
@@ -192,10 +192,10 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		Artist a = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
-				.params("a", "artist3").columnNameCaps(CapsStrategy.UPPER).selectOne(context);
+        Painting a = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING WHERE PAINTING_TITLE
= #bind($a)")
+				.params("a", "painting3").columnNameCaps(CapsStrategy.UPPER).selectOne(context);
 
-		assertEquals("artist3", a.getArtistName());
+		assertEquals("painting3", a.getPaintingTitle());
 	}
 
 	@Test
@@ -203,8 +203,8 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		long id = SQLSelect.scalarQuery(Long.class, "SELECT ARTIST_ID FROM ARTIST WHERE ARTIST_NAME
= #bind($a)")
-				.params("a", "artist3").selectOne(context);
+		long id = SQLSelect.scalarQuery(Integer.class, "SELECT PAINTING_ID FROM PAINTING WHERE
PAINTING_TITLE = #bind($a)")
+				.params("a", "painting3").selectOne(context);
 
 		assertEquals(3l, id);
 	}
@@ -214,11 +214,11 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		List<Long> ids = SQLSelect.scalarQuery(Long.class, "SELECT ARTIST_ID FROM ARTIST
ORDER BY ARTIST_ID").select(
+		List<Integer> ids = SQLSelect.scalarQuery(Integer.class, "SELECT PAINTING_ID FROM
PAINTING ORDER BY PAINTING_ID").select(
 				context);
 
 		assertEquals(20, ids.size());
-		assertEquals(2l, ids.get(1).longValue());
+		assertEquals(2l, ids.get(1).intValue());
 	}
 
 	@Test
@@ -226,7 +226,7 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		int c = SQLSelect.scalarQuery(Integer.class, "SELECT #result('COUNT(*)' 'int') FROM ARTIST").selectOne(context);
+		int c = SQLSelect.scalarQuery(Integer.class, "SELECT #result('COUNT(*)' 'int') FROM PAINTING").selectOne(context);
 
 		assertEquals(20, c);
 	}
@@ -236,10 +236,10 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		Long id = SQLSelect.scalarQuery(Long.class, "SELECT ARTIST_ID FROM ARTIST WHERE ARTIST_NAME
= #bind($a)")
-				.paramsArray("artist3").selectOne(context);
+        Integer id = SQLSelect.scalarQuery(Integer.class, "SELECT PAINTING_ID FROM PAINTING
WHERE PAINTING_TITLE = #bind($a)")
+				.paramsArray("painting3").selectOne(context);
 
-		assertEquals(3l, id.longValue());
+		assertEquals(3l, id.intValue());
 	}
 
 	@Test
@@ -247,30 +247,28 @@ public class SQLSelectIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		List<Long> ids = SQLSelect
-				.scalarQuery(Long.class,
-						"SELECT ARTIST_ID FROM ARTIST WHERE ARTIST_NAME = #bind($a) OR ARTIST_NAME = #bind($b)
ORDER BY ARTIST_ID")
-				.paramsArray("artist3", "artist2").select(context);
+		List<Integer> ids = SQLSelect
+				.scalarQuery(Integer.class,
+						"SELECT PAINTING_ID FROM PAINTING WHERE PAINTING_TITLE = #bind($a) OR PAINTING_TITLE
= #bind($b) ORDER BY PAINTING_ID")
+				.paramsArray("painting3", "painting2").select(context);
 
-		assertEquals(2l, ids.get(0).longValue());
-		assertEquals(3l, ids.get(1).longValue());
+		assertEquals(2l, ids.get(0).intValue());
+		assertEquals(3l, ids.get(1).intValue());
 	}
 
 	@Test
 	public void test_ParamsArray_Multiple_OptionalChunks() throws Exception {
 
-		Date dob = new java.sql.Date(System.currentTimeMillis());
-
-		tArtist.insert(1, "artist1", dob);
-		tArtist.insert(2, "artist2", null);
+		tPainting.insert(1, "painting1", 1.0);
+		tPainting.insert(2, "painting2", null);
 
-		List<Long> ids = SQLSelect
+		List<Integer> ids = SQLSelect
 				.scalarQuery(
-						Long.class,
-						"SELECT ARTIST_ID FROM ARTIST #chain('OR' 'WHERE') "
-								+ "#chunk($a) DATE_OF_BIRTH #bindEqual($a) #end "
-								+ "#chunk($b) ARTIST_NAME #bindEqual($b) #end #end ORDER BY ARTIST_ID")
-				.paramsArray(null, "artist1").select(context);
+						Integer.class,
+						"SELECT PAINTING_ID FROM PAINTING #chain('OR' 'WHERE') "
+								+ "#chunk($a) ESTIMATED_PRICE #bindEqual($a) #end "
+								+ "#chunk($b) PAINTING_TITLE #bindEqual($b) #end #end ORDER BY PAINTING_ID")
+				.paramsArray(null, "painting1").select(context);
 
 		assertEquals(1, ids.size());
 		assertEquals(1l, ids.get(0).longValue());
@@ -279,21 +277,19 @@ public class SQLSelectIT extends ServerCase {
 	@Test
 	public void test_Params_Multiple_OptionalChunks() throws Exception {
 
-		Date dob = new java.sql.Date(System.currentTimeMillis());
-
-		tArtist.insert(1, "artist1", dob);
-		tArtist.insert(2, "artist2", null);
+		tPainting.insert(1, "painting1", 1.0);
+		tPainting.insert(2, "painting2", null);
 
 		Map<String, Object> params = new HashMap<String, Object>();
 		params.put("a", null);
-		params.put("b", "artist1");
+		params.put("b", "painting1");
 
-		List<Long> ids = SQLSelect
+		List<Integer> ids = SQLSelect
 				.scalarQuery(
-						Long.class,
-						"SELECT ARTIST_ID FROM ARTIST #chain('OR' 'WHERE') "
-								+ "#chunk($a) DATE_OF_BIRTH #bindEqual($a) #end "
-								+ "#chunk($b) ARTIST_NAME #bindEqual($b) #end #end ORDER BY ARTIST_ID").params(params)
+                        Integer.class,
+						"SELECT PAINTING_ID FROM PAINTING #chain('OR' 'WHERE') "
+								+ "#chunk($a) ESTIMATED_PRICE #bindEqual($a) #end "
+								+ "#chunk($b) PAINTING_TITLE #bindEqual($b) #end #end ORDER BY PAINTING_ID").params(params)
 				.select(context);
 
 		assertEquals(1, ids.size());

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3ac0046b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
index 7911419..9becc33 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryIT.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
+import java.sql.Types;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -70,7 +71,9 @@ public class SelectQueryIT extends ServerCase {
 
 	@Before
 	public void before() {
-		this.tArtist = new TableHelper(dbHelper, "ARTIST").setColumns("ARTIST_ID", "ARTIST_NAME",
"DATE_OF_BIRTH");
+		this.tArtist = new TableHelper(dbHelper, "ARTIST")
+                .setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH")
+                .setColumnTypes(Types.BIGINT, Types.CHAR, Types.DATE);
 	}
 
 	protected void createArtistsDataSet() throws Exception {


Mime
View raw message