cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [05/48] Installing Maven Failsafe Plugin
Date Sun, 02 Nov 2014 07:09:53 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java
new file mode 100644
index 0000000..af76334
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryIT.java
@@ -0,0 +1,492 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.ejbql.EJBQLCompiledExpression;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.map.EntityResolver;
+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.BigIntegerEntity;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.util.XMLEncoder;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class EJBQLQueryIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private ServerRuntime runtime;
+
+    @Inject
+    protected DataChannelInterceptor queryInterceptor;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    private TableHelper tArtist;
+    private TableHelper tPainting;
+    private TableHelper tBigIntegerEntity;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST");
+        dbHelper.deleteAll("BIGINTEGER_ENTITY");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+        tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns("PAINTING_ID", "ARTIST_ID", "PAINTING_TITLE");
+
+        tBigIntegerEntity = new TableHelper(dbHelper, "BIGINTEGER_ENTITY");
+        tBigIntegerEntity.setColumns("ID", "BIG_INTEGER_FIELD");
+    }
+
+    protected void createArtistsDataSet() throws Exception {
+        tArtist.insert(33001, "a0");
+        tArtist.insert(33002, "a1");
+        tArtist.insert(33003, "a2");
+        tArtist.insert(33004, "a3");
+        tArtist.insert(33005, "a4");
+    }
+
+    protected void createPaintingsDataSet() throws Exception {
+        tArtist.insert(33001, "a0");
+        tArtist.insert(33002, "a1");
+        tPainting.insert(33001, 33001, "title0");
+        tPainting.insert(33002, 33002, "title1");
+        tPainting.insert(33003, 33002, "%%?_title%%_");
+    }
+
+    protected void createBigIntegerEntitiesDataSet() throws Exception {
+        tBigIntegerEntity.insert(44001, new Long(744073709551715l));
+    }
+
+    public void testLongParameter() throws Exception {
+        createBigIntegerEntitiesDataSet();
+        String ejbql = "SELECT bie FROM BigIntegerEntity bie WHERE bie.bigIntegerField > ?1";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        query.setParameter(1,744073709551615l);
+        List<BigIntegerEntity> result = context.performQuery(query);
+        assertEquals(1, result.size());
+    }
+
+    public void testLongLiteral() throws Exception {
+        createBigIntegerEntitiesDataSet();
+        String ejbql = "SELECT bie FROM BigIntegerEntity bie WHERE bie.bigIntegerField > 744073709551615";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        List<BigIntegerEntity> result = context.performQuery(query);
+        assertEquals(1, result.size());
+    }
+
+    public void testParameters() {
+        String ejbql = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        query.setParameter(1, "X");
+        query.setParameter("name", "Y");
+
+        Map<String, Object> parameters = query.getNamedParameters();
+        Map<Integer, Object> parameters1 = query.getPositionalParameters();
+        assertEquals(1, parameters.size());
+        assertEquals(1, parameters1.size());
+        assertEquals("X", parameters1.get(new Integer(1)));
+        assertEquals("Y", parameters.get("name"));
+    }
+
+    public void testCacheParameters() {
+        String ejbql1 = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
+        EJBQLQuery q1 = new EJBQLQuery(ejbql1);
+        q1.setParameter(1, "X");
+        q1.setParameter("name", "Y");
+        q1.setFetchOffset(1);
+        q1.setFetchLimit(5);
+        q1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+
+        String ejbql2 = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
+        EJBQLQuery q2 = new EJBQLQuery(ejbql2);
+        q2.setParameter(1, "X");
+        q2.setParameter("name", "Y");
+        q2.setFetchOffset(1);
+        q2.setFetchLimit(5);
+        q2.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
+                .getMetaData(resolver)
+                .getCacheKey());
+    }
+
+    public void testCacheStrategy() throws Exception {
+
+        // insertValue();
+        createArtistsDataSet();
+
+        final String ejbql = "select a FROM Artist a";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+        final List<Artist> artist1 = context.performQuery(query);
+
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                List<Artist> artist2;
+                EJBQLQuery query1 = new EJBQLQuery(ejbql);
+                query1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+                artist2 = context.performQuery(query1);
+
+                assertEquals(artist1.get(0).getArtistName(), artist2
+                        .get(0)
+                        .getArtistName());
+            }
+        });
+
+    }
+
+    public void testDataRows() throws Exception {
+
+        // insertValue();
+        createArtistsDataSet();
+
+        String ejbql = "select a FROM Artist a";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        query.setFetchingDataRows(true);
+        List<?> artists = context.performQuery(query);
+
+        DataRow row = (DataRow) artists.get(0);
+        String artistName = (String) row.get("ARTIST_NAME");
+
+        Artist artist = (Artist) context.objectFromDataRow("Artist", row);
+        assertEquals(artistName, artist.getArtistName());
+    }
+
+    public void testGetExpression() {
+        String ejbql = "select a FROM Artist a";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        EJBQLCompiledExpression parsed = query.getExpression(runtime
+                .getDataDomain()
+                .getEntityResolver());
+        assertNotNull(parsed);
+        assertEquals(ejbql, parsed.getSource());
+    }
+
+    public void testGetName() {
+        String ejbql = "select a FROM Artist a";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        assertNull(query.getName());
+        query.setName("XYZ");
+        assertEquals("XYZ", query.getName());
+    }
+
+    public void testUniqueKeyEntity() {
+        // insertValue();
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+        String ejbql = "select a FROM Artist a";
+
+        EJBQLQuery q1 = new EJBQLQuery(ejbql);
+        q1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+
+        EJBQLQuery q2 = new EJBQLQuery(ejbql);
+        q2.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
+                .getMetaData(resolver)
+                .getCacheKey());
+    }
+
+    public void testGetMetadata() {
+
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+        String ejbql = "select a FROM Artist a";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        QueryMetadata md = query.getMetaData(resolver);
+
+        assertNotNull(md);
+
+        assertNotNull(md.getClassDescriptor());
+        assertSame(resolver.getClassDescriptor("Artist"), md.getClassDescriptor());
+
+        assertNotNull(md.getObjEntity());
+        assertSame(resolver.getObjEntity("Artist"), md.getObjEntity());
+
+        assertFalse(md.isFetchingDataRows());
+        assertTrue(md.isRefreshingObjects());
+        assertEquals(QueryCacheStrategy.NO_CACHE, md.getCacheStrategy());
+    }
+
+    public void testSelectRelationship() throws Exception {
+
+        // insertPaintValue();
+        createPaintingsDataSet();
+
+        String ejbql = "SELECT p.toArtist FROM Painting p";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        List<?> result = context.performQuery(query);
+
+        assertNotNull(result);
+        assertEquals(3, result.size());
+
+        assertEquals(Artist.class, result.get(0).getClass());
+
+        String ejbql2 = "SELECT p.toArtist, p FROM Painting p";
+        EJBQLQuery query2 = new EJBQLQuery(ejbql2);
+
+        List<?> result2 = context.performQuery(query2);
+
+        assertNotNull(result2);
+        assertEquals(3, result2.size());
+        assertEquals(2, ((Object[]) result2.get(0)).length);
+
+        assertEquals(Artist.class, ((Object[]) result2.get(0))[0].getClass());
+        assertEquals(Painting.class, ((Object[]) result2.get(0))[1].getClass());
+
+        String ejbql3 = "SELECT p.toArtist, p.paintingTitle FROM Painting p";
+        EJBQLQuery query3 = new EJBQLQuery(ejbql3);
+
+        List<?> result3 = context.performQuery(query3);
+
+        assertNotNull(result3);
+        assertEquals(3, result3.size());
+        assertEquals(2, ((Object[]) result3.get(0)).length);
+
+        assertEquals(Artist.class, ((Object[]) result3.get(0))[0].getClass());
+        assertEquals(String.class, ((Object[]) result3.get(0))[1].getClass());
+    }
+
+    public void testEncodeAsXML() {
+
+        String ejbql = "select a FROM Artist a";
+        String name = "Test";
+
+        StringWriter w = new StringWriter();
+        XMLEncoder e = new XMLEncoder(new PrintWriter(w));
+
+        String separator = System.getProperty("line.separator");
+
+        StringBuffer s = new StringBuffer("<query name=\"");
+        s.append(name);
+        s.append("\" factory=\"");
+        s.append("org.apache.cayenne.map.EjbqlBuilder");
+        s.append("\">");
+        s.append(separator);
+
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        if (query.getEjbqlStatement() != null) {
+            s.append("<ejbql><![CDATA[");
+            s.append(query.getEjbqlStatement());
+            s.append("]]></ejbql>");
+        }
+        s.append(separator);
+        s.append("</query>");
+        s.append(separator);
+        query.setName(name);
+        query.encodeAsXML(e);
+
+        assertEquals(w.getBuffer().toString(), s.toString());
+    }
+
+    public void testInWithMultipleStringPositionalParameters_withBrackets() throws Exception {
+        createPaintingsDataSet();
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.paintingTitle in (?1,?2,?3)");
+        query.setParameter(1,"title0");
+        query.setParameter(2,"title1");
+        query.setParameter(3,"title2");
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(2, paintings.size());
+    }
+
+    public void testInWithSingleStringPositionalParameter_withoutBrackets() throws Exception {
+        createPaintingsDataSet();
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.paintingTitle in ?1");
+        query.setParameter(1,"title0");
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(1, paintings.size());
+    }
+
+    public void testInWithSingleCollectionNamedParameter_withoutBrackets() throws Exception {
+        createPaintingsDataSet();
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in :artists");
+        query.setParameter("artists", context.performQuery(new SelectQuery<Artist>(Artist.class)));
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(3, paintings.size());
+    }
+
+    public void testInWithSingleCollectionPositionalParameter_withoutBrackets() throws Exception {
+        createPaintingsDataSet();
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in ?1");
+        query.setParameter(1,context.performQuery(new SelectQuery<Artist>(Artist.class)));
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(3, paintings.size());
+    }
+
+    public void testInWithSingleCollectionNamedParameter_withBrackets() throws Exception {
+        createPaintingsDataSet();
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in (:artists)");
+        query.setParameter("artists", context.performQuery(new SelectQuery<Artist>(Artist.class)));
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(3, paintings.size());
+    }
+
+    public void testInWithSingleCollectionPositionalParameter_withBrackets() throws Exception {
+        createPaintingsDataSet();
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in (?1)");
+        query.setParameter(1,context.performQuery(new SelectQuery<Artist>(Artist.class)));
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(3, paintings.size());
+    }
+
+    public void testNullParameter() {
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p WHERE p.toArtist=:x");
+        query.setParameter("x", null);
+        context.performQuery(query);
+    }
+
+    public void testNullNotEqualsParameter() {
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p WHERE p.toArtist<>:x");
+        query.setParameter("x", null);
+        context.performQuery(query);
+    }
+
+    public void testNullPositionalParameter() {
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p WHERE p.toArtist=?1");
+        query.setParameter(1, null);
+        context.performQuery(query);
+    }
+
+    public void testNullAndNotNullParameter() {
+        EJBQLQuery query = new EJBQLQuery(
+                "select p from Painting p WHERE p.toArtist=:x OR p.toArtist.artistName=:b");
+        query.setParameter("x", null);
+        query.setParameter("b", "Y");
+        context.performQuery(query);
+    }
+
+    public void testLikeWithExplicitEscape() throws Exception {
+        createPaintingsDataSet();
+        EJBQLQuery query = new EJBQLQuery("SELECT p FROM Painting p WHERE p.paintingTitle LIKE '|%|%?|_title|%|%|_' ESCAPE '|'");
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(1, paintings.size());
+        assertEquals("%%?_title%%_", paintings.get(0).getPaintingTitle());
+    }
+
+    public void testJoinToJoined() {
+        EJBQLQuery query = new EJBQLQuery(
+                "select g from Gallery g inner join g.paintingArray p where p.toArtist.artistName like '%a%'");
+        context.performQuery(query);
+    }
+
+    public void testJoinAndCount() {
+        EJBQLQuery query = new EJBQLQuery(
+                "select count(p) from Painting p where p.toGallery.galleryName LIKE '%a%' AND ("
+                        + "p.paintingTitle like '%a%' or "
+                        + "p.toArtist.artistName like '%a%'"
+                        + ")");
+        context.performQuery(query);
+    }
+
+    // SELECT COUNT(p) from Product p where p.vsCatalog.id = 1 and
+    // (
+    // p.displayName like '%rimadyl%'
+    // or p.manufacturer.name like '%rimadyl%'
+    // or p.description like '%rimadyl%'
+    // or p.longdescription like '%rimadyl%'
+    // or p.longdescription2 like '%rimadyl%'
+    // or p.manufacturerPartNumber like '%rimadyl%'
+    // or p.partNumber like '%rimadyl%'
+    // )
+
+    public void testRelationshipWhereClause() throws Exception {
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("a");
+        Painting p = context.newObject(Painting.class);
+        p.setPaintingTitle("p");
+        p.setToArtist(a);
+        context.commitChanges();
+
+        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist=:a");
+        query.setParameter("a", a);
+
+        List<Painting> paintings = context.performQuery(query);
+        assertEquals(1, paintings.size());
+        assertSame(p, paintings.get(0));
+    }
+
+    public void testRelationshipWhereClause2() throws Exception {
+        Expression exp = ExpressionFactory.matchExp(Painting.TO_GALLERY_PROPERTY, null);
+        EJBQLQuery query = new EJBQLQuery("select p.toArtist from Painting p where "
+                + exp.toEJBQL("p"));
+
+        context.performQuery(query);
+    }
+
+    public void testOrBrackets() throws Exception {
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("testOrBrackets");
+        context.commitChanges();
+
+        // this query is equivalent to (false and (false or true)) and
+        // should always return 0 rows
+        EJBQLQuery query = new EJBQLQuery("select a from Artist a "
+                + "where a.artistName <> a.artistName and "
+                + "(a.artistName <> a.artistName or a.artistName = a.artistName)");
+        assertEquals(context.performQuery(query).size(), 0);
+
+        // on the other hand, the following is equivalent to (false and false) or true)
+        // and
+        // should return >0 rows
+        query = new EJBQLQuery("select a from Artist a "
+                + "where a.artistName <> a.artistName and "
+                + "a.artistName <> a.artistName or a.artistName = a.artistName");
+        assertTrue(context.performQuery(query).size() > 0);
+
+        // checking brackets around not
+        query = new EJBQLQuery("select a from Artist a "
+                + "where not(a.artistName <> a.artistName and "
+                + "a.artistName <> a.artistName or a.artistName = a.artistName)");
+        assertEquals(context.performQuery(query).size(), 0);
+
+        // not is first to process
+        query = new EJBQLQuery("select a from Artist a "
+                + "where not a.artistName <> a.artistName or "
+                + "a.artistName = a.artistName");
+        assertTrue(context.performQuery(query).size() > 0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java
deleted file mode 100644
index 4d02e07..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java
+++ /dev/null
@@ -1,492 +0,0 @@
-/*****************************************************************
- *   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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cayenne.DataRow;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.ejbql.EJBQLCompiledExpression;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.map.EntityResolver;
-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.BigIntegerEntity;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.DataChannelInterceptor;
-import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.apache.cayenne.util.XMLEncoder;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class EJBQLQueryTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private ServerRuntime runtime;
-
-    @Inject
-    protected DataChannelInterceptor queryInterceptor;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    private TableHelper tArtist;
-    private TableHelper tPainting;
-    private TableHelper tBigIntegerEntity;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST");
-        dbHelper.deleteAll("BIGINTEGER_ENTITY");
-
-        tArtist = new TableHelper(dbHelper, "ARTIST");
-        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
-
-        tPainting = new TableHelper(dbHelper, "PAINTING");
-        tPainting.setColumns("PAINTING_ID", "ARTIST_ID", "PAINTING_TITLE");
-
-        tBigIntegerEntity = new TableHelper(dbHelper, "BIGINTEGER_ENTITY");
-        tBigIntegerEntity.setColumns("ID", "BIG_INTEGER_FIELD");
-    }
-
-    protected void createArtistsDataSet() throws Exception {
-        tArtist.insert(33001, "a0");
-        tArtist.insert(33002, "a1");
-        tArtist.insert(33003, "a2");
-        tArtist.insert(33004, "a3");
-        tArtist.insert(33005, "a4");
-    }
-
-    protected void createPaintingsDataSet() throws Exception {
-        tArtist.insert(33001, "a0");
-        tArtist.insert(33002, "a1");
-        tPainting.insert(33001, 33001, "title0");
-        tPainting.insert(33002, 33002, "title1");
-        tPainting.insert(33003, 33002, "%%?_title%%_");
-    }
-
-    protected void createBigIntegerEntitiesDataSet() throws Exception {
-        tBigIntegerEntity.insert(44001, new Long(744073709551715l));
-    }
-
-    public void testLongParameter() throws Exception {
-        createBigIntegerEntitiesDataSet();
-        String ejbql = "SELECT bie FROM BigIntegerEntity bie WHERE bie.bigIntegerField > ?1";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-        query.setParameter(1,744073709551615l);
-        List<BigIntegerEntity> result = context.performQuery(query);
-        assertEquals(1, result.size());
-    }
-
-    public void testLongLiteral() throws Exception {
-        createBigIntegerEntitiesDataSet();
-        String ejbql = "SELECT bie FROM BigIntegerEntity bie WHERE bie.bigIntegerField > 744073709551615";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-        List<BigIntegerEntity> result = context.performQuery(query);
-        assertEquals(1, result.size());
-    }
-
-    public void testParameters() {
-        String ejbql = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-        query.setParameter(1, "X");
-        query.setParameter("name", "Y");
-
-        Map<String, Object> parameters = query.getNamedParameters();
-        Map<Integer, Object> parameters1 = query.getPositionalParameters();
-        assertEquals(1, parameters.size());
-        assertEquals(1, parameters1.size());
-        assertEquals("X", parameters1.get(new Integer(1)));
-        assertEquals("Y", parameters.get("name"));
-    }
-
-    public void testCacheParameters() {
-        String ejbql1 = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
-        EJBQLQuery q1 = new EJBQLQuery(ejbql1);
-        q1.setParameter(1, "X");
-        q1.setParameter("name", "Y");
-        q1.setFetchOffset(1);
-        q1.setFetchLimit(5);
-        q1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        String ejbql2 = "select a FROM Artist a WHERE a.artistName = ?1 OR a.artistName = :name";
-        EJBQLQuery q2 = new EJBQLQuery(ejbql2);
-        q2.setParameter(1, "X");
-        q2.setParameter("name", "Y");
-        q2.setFetchOffset(1);
-        q2.setFetchLimit(5);
-        q2.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-
-        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
-                .getMetaData(resolver)
-                .getCacheKey());
-    }
-
-    public void testCacheStrategy() throws Exception {
-
-        // insertValue();
-        createArtistsDataSet();
-
-        final String ejbql = "select a FROM Artist a";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-        final List<Artist> artist1 = context.performQuery(query);
-
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-            public void execute() {
-                List<Artist> artist2;
-                EJBQLQuery query1 = new EJBQLQuery(ejbql);
-                query1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-                artist2 = context.performQuery(query1);
-
-                assertEquals(artist1.get(0).getArtistName(), artist2
-                        .get(0)
-                        .getArtistName());
-            }
-        });
-
-    }
-
-    public void testDataRows() throws Exception {
-
-        // insertValue();
-        createArtistsDataSet();
-
-        String ejbql = "select a FROM Artist a";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-        query.setFetchingDataRows(true);
-        List<?> artists = context.performQuery(query);
-
-        DataRow row = (DataRow) artists.get(0);
-        String artistName = (String) row.get("ARTIST_NAME");
-
-        Artist artist = (Artist) context.objectFromDataRow("Artist", row);
-        assertEquals(artistName, artist.getArtistName());
-    }
-
-    public void testGetExpression() {
-        String ejbql = "select a FROM Artist a";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-        EJBQLCompiledExpression parsed = query.getExpression(runtime
-                .getDataDomain()
-                .getEntityResolver());
-        assertNotNull(parsed);
-        assertEquals(ejbql, parsed.getSource());
-    }
-
-    public void testGetName() {
-        String ejbql = "select a FROM Artist a";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-
-        assertNull(query.getName());
-        query.setName("XYZ");
-        assertEquals("XYZ", query.getName());
-    }
-
-    public void testUniqueKeyEntity() {
-        // insertValue();
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-        String ejbql = "select a FROM Artist a";
-
-        EJBQLQuery q1 = new EJBQLQuery(ejbql);
-        q1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        EJBQLQuery q2 = new EJBQLQuery(ejbql);
-        q2.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
-                .getMetaData(resolver)
-                .getCacheKey());
-    }
-
-    public void testGetMetadata() {
-
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-        String ejbql = "select a FROM Artist a";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-        QueryMetadata md = query.getMetaData(resolver);
-
-        assertNotNull(md);
-
-        assertNotNull(md.getClassDescriptor());
-        assertSame(resolver.getClassDescriptor("Artist"), md.getClassDescriptor());
-
-        assertNotNull(md.getObjEntity());
-        assertSame(resolver.getObjEntity("Artist"), md.getObjEntity());
-
-        assertFalse(md.isFetchingDataRows());
-        assertTrue(md.isRefreshingObjects());
-        assertEquals(QueryCacheStrategy.NO_CACHE, md.getCacheStrategy());
-    }
-
-    public void testSelectRelationship() throws Exception {
-
-        // insertPaintValue();
-        createPaintingsDataSet();
-
-        String ejbql = "SELECT p.toArtist FROM Painting p";
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-
-        List<?> result = context.performQuery(query);
-
-        assertNotNull(result);
-        assertEquals(3, result.size());
-
-        assertEquals(Artist.class, result.get(0).getClass());
-
-        String ejbql2 = "SELECT p.toArtist, p FROM Painting p";
-        EJBQLQuery query2 = new EJBQLQuery(ejbql2);
-
-        List<?> result2 = context.performQuery(query2);
-
-        assertNotNull(result2);
-        assertEquals(3, result2.size());
-        assertEquals(2, ((Object[]) result2.get(0)).length);
-
-        assertEquals(Artist.class, ((Object[]) result2.get(0))[0].getClass());
-        assertEquals(Painting.class, ((Object[]) result2.get(0))[1].getClass());
-
-        String ejbql3 = "SELECT p.toArtist, p.paintingTitle FROM Painting p";
-        EJBQLQuery query3 = new EJBQLQuery(ejbql3);
-
-        List<?> result3 = context.performQuery(query3);
-
-        assertNotNull(result3);
-        assertEquals(3, result3.size());
-        assertEquals(2, ((Object[]) result3.get(0)).length);
-
-        assertEquals(Artist.class, ((Object[]) result3.get(0))[0].getClass());
-        assertEquals(String.class, ((Object[]) result3.get(0))[1].getClass());
-    }
-
-    public void testEncodeAsXML() {
-
-        String ejbql = "select a FROM Artist a";
-        String name = "Test";
-
-        StringWriter w = new StringWriter();
-        XMLEncoder e = new XMLEncoder(new PrintWriter(w));
-
-        String separator = System.getProperty("line.separator");
-
-        StringBuffer s = new StringBuffer("<query name=\"");
-        s.append(name);
-        s.append("\" factory=\"");
-        s.append("org.apache.cayenne.map.EjbqlBuilder");
-        s.append("\">");
-        s.append(separator);
-
-        EJBQLQuery query = new EJBQLQuery(ejbql);
-
-        if (query.getEjbqlStatement() != null) {
-            s.append("<ejbql><![CDATA[");
-            s.append(query.getEjbqlStatement());
-            s.append("]]></ejbql>");
-        }
-        s.append(separator);
-        s.append("</query>");
-        s.append(separator);
-        query.setName(name);
-        query.encodeAsXML(e);
-
-        assertEquals(w.getBuffer().toString(), s.toString());
-    }
-
-    public void testInWithMultipleStringPositionalParameters_withBrackets() throws Exception {
-        createPaintingsDataSet();
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.paintingTitle in (?1,?2,?3)");
-        query.setParameter(1,"title0");
-        query.setParameter(2,"title1");
-        query.setParameter(3,"title2");
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(2, paintings.size());
-    }
-
-    public void testInWithSingleStringPositionalParameter_withoutBrackets() throws Exception {
-        createPaintingsDataSet();
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.paintingTitle in ?1");
-        query.setParameter(1,"title0");
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(1, paintings.size());
-    }
-
-    public void testInWithSingleCollectionNamedParameter_withoutBrackets() throws Exception {
-        createPaintingsDataSet();
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in :artists");
-        query.setParameter("artists", context.performQuery(new SelectQuery<Artist>(Artist.class)));
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(3, paintings.size());
-    }
-
-    public void testInWithSingleCollectionPositionalParameter_withoutBrackets() throws Exception {
-        createPaintingsDataSet();
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in ?1");
-        query.setParameter(1,context.performQuery(new SelectQuery<Artist>(Artist.class)));
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(3, paintings.size());
-    }
-
-    public void testInWithSingleCollectionNamedParameter_withBrackets() throws Exception {
-        createPaintingsDataSet();
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in (:artists)");
-        query.setParameter("artists", context.performQuery(new SelectQuery<Artist>(Artist.class)));
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(3, paintings.size());
-    }
-
-    public void testInWithSingleCollectionPositionalParameter_withBrackets() throws Exception {
-        createPaintingsDataSet();
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist in (?1)");
-        query.setParameter(1,context.performQuery(new SelectQuery<Artist>(Artist.class)));
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(3, paintings.size());
-    }
-
-    public void testNullParameter() {
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p WHERE p.toArtist=:x");
-        query.setParameter("x", null);
-        context.performQuery(query);
-    }
-
-    public void testNullNotEqualsParameter() {
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p WHERE p.toArtist<>:x");
-        query.setParameter("x", null);
-        context.performQuery(query);
-    }
-
-    public void testNullPositionalParameter() {
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p WHERE p.toArtist=?1");
-        query.setParameter(1, null);
-        context.performQuery(query);
-    }
-
-    public void testNullAndNotNullParameter() {
-        EJBQLQuery query = new EJBQLQuery(
-                "select p from Painting p WHERE p.toArtist=:x OR p.toArtist.artistName=:b");
-        query.setParameter("x", null);
-        query.setParameter("b", "Y");
-        context.performQuery(query);
-    }
-
-    public void testLikeWithExplicitEscape() throws Exception {
-        createPaintingsDataSet();
-        EJBQLQuery query = new EJBQLQuery("SELECT p FROM Painting p WHERE p.paintingTitle LIKE '|%|%?|_title|%|%|_' ESCAPE '|'");
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(1, paintings.size());
-        assertEquals("%%?_title%%_", paintings.get(0).getPaintingTitle());
-    }
-
-    public void testJoinToJoined() {
-        EJBQLQuery query = new EJBQLQuery(
-                "select g from Gallery g inner join g.paintingArray p where p.toArtist.artistName like '%a%'");
-        context.performQuery(query);
-    }
-
-    public void testJoinAndCount() {
-        EJBQLQuery query = new EJBQLQuery(
-                "select count(p) from Painting p where p.toGallery.galleryName LIKE '%a%' AND ("
-                        + "p.paintingTitle like '%a%' or "
-                        + "p.toArtist.artistName like '%a%'"
-                        + ")");
-        context.performQuery(query);
-    }
-
-    // SELECT COUNT(p) from Product p where p.vsCatalog.id = 1 and
-    // (
-    // p.displayName like '%rimadyl%'
-    // or p.manufacturer.name like '%rimadyl%'
-    // or p.description like '%rimadyl%'
-    // or p.longdescription like '%rimadyl%'
-    // or p.longdescription2 like '%rimadyl%'
-    // or p.manufacturerPartNumber like '%rimadyl%'
-    // or p.partNumber like '%rimadyl%'
-    // )
-
-    public void testRelationshipWhereClause() throws Exception {
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("a");
-        Painting p = context.newObject(Painting.class);
-        p.setPaintingTitle("p");
-        p.setToArtist(a);
-        context.commitChanges();
-
-        EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist=:a");
-        query.setParameter("a", a);
-
-        List<Painting> paintings = context.performQuery(query);
-        assertEquals(1, paintings.size());
-        assertSame(p, paintings.get(0));
-    }
-
-    public void testRelationshipWhereClause2() throws Exception {
-        Expression exp = ExpressionFactory.matchExp(Painting.TO_GALLERY_PROPERTY, null);
-        EJBQLQuery query = new EJBQLQuery("select p.toArtist from Painting p where "
-                + exp.toEJBQL("p"));
-
-        context.performQuery(query);
-    }
-
-    public void testOrBrackets() throws Exception {
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("testOrBrackets");
-        context.commitChanges();
-
-        // this query is equivalent to (false and (false or true)) and
-        // should always return 0 rows
-        EJBQLQuery query = new EJBQLQuery("select a from Artist a "
-                + "where a.artistName <> a.artistName and "
-                + "(a.artistName <> a.artistName or a.artistName = a.artistName)");
-        assertEquals(context.performQuery(query).size(), 0);
-
-        // on the other hand, the following is equivalent to (false and false) or true)
-        // and
-        // should return >0 rows
-        query = new EJBQLQuery("select a from Artist a "
-                + "where a.artistName <> a.artistName and "
-                + "a.artistName <> a.artistName or a.artistName = a.artistName");
-        assertTrue(context.performQuery(query).size() > 0);
-
-        // checking brackets around not
-        query = new EJBQLQuery("select a from Artist a "
-                + "where not(a.artistName <> a.artistName and "
-                + "a.artistName <> a.artistName or a.artistName = a.artistName)");
-        assertEquals(context.performQuery(query).size(), 0);
-
-        // not is first to process
-        query = new EJBQLQuery("select a from Artist a "
-                + "where not a.artistName <> a.artistName or "
-                + "a.artistName = a.artistName");
-        assertTrue(context.performQuery(query).size() > 0);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyIT.java
new file mode 100644
index 0000000..61ec8f0
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyIT.java
@@ -0,0 +1,107 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ProcedureQueryCacheKeyIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    public void testNoCache() {
+
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+
+        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.NO_CACHE, md1.getCacheStrategy());
+        assertNull(md1.getCacheKey());
+
+        query.setName("XYZ");
+        QueryMetadata md2 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.NO_CACHE, md2.getCacheStrategy());
+        assertNull(md2.getCacheKey());
+    }
+
+    public void testLocalCache() {
+
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+
+        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
+
+        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.LOCAL_CACHE, md1.getCacheStrategy());
+        assertNotNull(md1.getCacheKey());
+    }
+
+    public void testSharedCache() {
+
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+
+        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
+
+        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
+        assertNotNull(md1.getCacheKey());
+    }
+
+    public void testNamedQuery() {
+
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+
+        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
+
+        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+        query.setName("XYZ");
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
+        assertEquals("proc:", md1.getCacheKey());
+    }
+
+    public void testCacheFetchOffsetAndLimit() {
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+        
+        ProcedureQuery q1 = new ProcedureQuery("ABC", Artist.class);
+        q1.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+        q1.setFetchOffset(5);
+        q1.setFetchLimit(3);
+        
+        ProcedureQuery q2 = new ProcedureQuery("ABC", Artist.class);
+        q2.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+        q2.setFetchOffset(5);
+        q2.setFetchLimit(3);
+        
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
+                .getMetaData(resolver)
+                .getCacheKey());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyTest.java
deleted file mode 100644
index 2e96881..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/ProcedureQueryCacheKeyTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*****************************************************************
- *   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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class ProcedureQueryCacheKeyTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    public void testNoCache() {
-
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-
-        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.NO_CACHE, md1.getCacheStrategy());
-        assertNull(md1.getCacheKey());
-
-        query.setName("XYZ");
-        QueryMetadata md2 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.NO_CACHE, md2.getCacheStrategy());
-        assertNull(md2.getCacheKey());
-    }
-
-    public void testLocalCache() {
-
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-
-        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
-
-        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.LOCAL_CACHE, md1.getCacheStrategy());
-        assertNotNull(md1.getCacheKey());
-    }
-
-    public void testSharedCache() {
-
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-
-        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
-
-        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
-        assertNotNull(md1.getCacheKey());
-    }
-
-    public void testNamedQuery() {
-
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-
-        ProcedureQuery query = new ProcedureQuery("ABC", Artist.class);
-
-        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-        query.setName("XYZ");
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
-        assertEquals("proc:", md1.getCacheKey());
-    }
-
-    public void testCacheFetchOffsetAndLimit() {
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-        
-        ProcedureQuery q1 = new ProcedureQuery("ABC", Artist.class);
-        q1.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-        q1.setFetchOffset(5);
-        q1.setFetchLimit(3);
-        
-        ProcedureQuery q2 = new ProcedureQuery("ABC", Artist.class);
-        q2.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-        q2.setFetchOffset(5);
-        q2.setFetchLimit(3);
-        
-        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
-                .getMetaData(resolver)
-                .getCacheKey());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainIT.java
new file mode 100644
index 0000000..ee23624
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainIT.java
@@ -0,0 +1,63 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class QueryChainIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    public void testSelectQuery() {
+
+        QueryChain chain = new QueryChain();
+        chain.addQuery(new SelectQuery(Artist.class));
+        chain.addQuery(new SelectQuery(Artist.class));
+
+        QueryMetadata md = chain.getMetaData(runtime.getDataDomain().getEntityResolver());
+
+        assertNotNull(md);
+        assertTrue(md.isFetchingDataRows());
+        assertNull(md.getObjEntity());
+    }
+
+    public void testSelectQueryDataRows() {
+
+        QueryChain chain = new QueryChain();
+        SelectQuery q1 = new SelectQuery(Artist.class);
+        q1.setFetchingDataRows(true);
+        chain.addQuery(q1);
+
+        SelectQuery q2 = new SelectQuery(Artist.class);
+        q2.setFetchingDataRows(true);
+        chain.addQuery(q2);
+
+        QueryMetadata md = chain.getMetaData(runtime.getDataDomain().getEntityResolver());
+
+        assertNotNull(md);
+        assertTrue(md.isFetchingDataRows());
+        assertNull(md.getObjEntity());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainTest.java
deleted file mode 100644
index 182f2a8..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/QueryChainTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*****************************************************************
- *   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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class QueryChainTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    public void testSelectQuery() {
-
-        QueryChain chain = new QueryChain();
-        chain.addQuery(new SelectQuery(Artist.class));
-        chain.addQuery(new SelectQuery(Artist.class));
-
-        QueryMetadata md = chain.getMetaData(runtime.getDataDomain().getEntityResolver());
-
-        assertNotNull(md);
-        assertTrue(md.isFetchingDataRows());
-        assertNull(md.getObjEntity());
-    }
-
-    public void testSelectQueryDataRows() {
-
-        QueryChain chain = new QueryChain();
-        SelectQuery q1 = new SelectQuery(Artist.class);
-        q1.setFetchingDataRows(true);
-        chain.addQuery(q1);
-
-        SelectQuery q2 = new SelectQuery(Artist.class);
-        q2.setFetchingDataRows(true);
-        chain.addQuery(q2);
-
-        QueryMetadata md = chain.getMetaData(runtime.getDataDomain().getEntityResolver());
-
-        assertNotNull(md);
-        assertTrue(md.isFetchingDataRows());
-        assertNull(md.getObjEntity());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/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
new file mode 100644
index 0000000..f26e066
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
@@ -0,0 +1,213 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+import org.apache.cayenne.DataRow;
+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.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SQLSelectIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+    }
+
+    protected void createArtistsDataSet() throws Exception {
+        TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH");
+
+        long dateBase = System.currentTimeMillis();
+
+        for (int i = 1; i <= 20; i++) {
+            tArtist.insert(i, "artist" + i, new java.sql.Date(dateBase + 10000 * i));
+        }
+    }
+
+    public void test_DataRows_DataMapNameRoot() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("tstmap", "SELECT * FROM ARTIST");
+        assertTrue(q1.isFetchingDataRows());
+
+        List<DataRow> result = context.select(q1);
+        assertEquals(20, result.size());
+        assertTrue(result.get(0) instanceof DataRow);
+    }
+
+    public void test_DataRows_DefaultRoot() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
+        assertTrue(q1.isFetchingDataRows());
+
+        List<DataRow> result = context.select(q1);
+        assertEquals(20, result.size());
+        assertTrue(result.get(0) instanceof DataRow);
+    }
+
+    public void test_DataRows_ClassRoot() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST");
+        assertFalse(q1.isFetchingDataRows());
+        List<Artist> result = context.select(q1);
+        assertEquals(20, result.size());
+        assertTrue(result.get(0) instanceof Artist);
+    }
+
+    public void test_DataRows_ClassRoot_Parameters() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)");
+        q1.getParameters().put("a", "artist3");
+
+        assertFalse(q1.isFetchingDataRows());
+        Artist a = context.selectOne(q1);
+        assertEquals("artist3", a.getArtistName());
+    }
+
+    public void test_DataRows_ClassRoot_Bind() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class,
+                "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a) OR ARTIST_NAME = #bind($b)");
+        q1.params("a", "artist3").params("b", "artist4");
+
+        List<Artist> result = context.select(q1);
+        assertEquals(2, result.size());
+    }
+
+    public void test_DataRows_ColumnNameCaps() throws Exception {
+
+        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST WHERE ARTIST_NAME = 'artist2'");
+        q1.upperColumnNames();
+
+        SQLTemplate r1 = (SQLTemplate) q1.getReplacementQuery(context.getEntityResolver());
+        assertEquals(CapsStrategy.UPPER, r1.getColumnNamesCapitalization());
+
+        q1.lowerColumnNames();
+        SQLTemplate r2 = (SQLTemplate) q1.getReplacementQuery(context.getEntityResolver());
+        assertEquals(CapsStrategy.LOWER, r2.getColumnNamesCapitalization());
+    }
+
+    public void test_DataRows_FetchLimit() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
+        q1.limit(5);
+
+        assertEquals(5, context.select(q1).size());
+    }
+
+    public void test_DataRows_FetchOffset() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
+        q1.offset(4);
+
+        assertEquals(16, context.select(q1).size());
+    }
+
+    public void test_Append() throws Exception {
+
+        createArtistsDataSet();
+
+        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST")
+                .append(" WHERE ARTIST_NAME = #bind($a)").params("a", "artist3");
+
+        List<Artist> result = context.select(q1);
+        assertEquals(1, result.size());
+    }
+
+    public void test_Select() throws Exception {
+
+        createArtistsDataSet();
+
+        List<Artist> result = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
+                .params("a", "artist3").select(context);
+
+        assertEquals(1, result.size());
+    }
+
+    public void test_SelectOne() throws Exception {
+
+        createArtistsDataSet();
+
+        Artist a = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
+                .params("a", "artist3").selectOne(context);
+
+        assertEquals("artist3", a.getArtistName());
+    }
+
+    public void test_SelectLong() throws Exception {
+
+        createArtistsDataSet();
+
+        long id = SQLSelect.scalarQuery(Long.class, "SELECT ARTIST_ID FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
+                .params("a", "artist3").selectOne(context);
+
+        assertEquals(3l, id);
+    }
+
+    public void test_SelectLongArray() throws Exception {
+
+        createArtistsDataSet();
+
+        List<Long> ids = SQLSelect.scalarQuery(Long.class, "SELECT ARTIST_ID FROM ARTIST ORDER BY ARTIST_ID").select(
+                context);
+
+        assertEquals(20, ids.size());
+        assertEquals(2l, ids.get(1).longValue());
+    }
+
+    public void test_SelectCount() throws Exception {
+
+        createArtistsDataSet();
+
+        int c = SQLSelect.scalarQuery(Integer.class, "SELECT #result('COUNT(*)' 'int') FROM ARTIST").selectOne(context);
+
+        assertEquals(20, c);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java
deleted file mode 100644
index 3f4317a..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*****************************************************************
- *   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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import java.util.List;
-
-import org.apache.cayenne.DataRow;
-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.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class SQLSelectTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("PAINTING_INFO");
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST_EXHIBIT");
-        dbHelper.deleteAll("ARTIST_GROUP");
-        dbHelper.deleteAll("ARTIST");
-    }
-
-    protected void createArtistsDataSet() throws Exception {
-        TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
-        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH");
-
-        long dateBase = System.currentTimeMillis();
-
-        for (int i = 1; i <= 20; i++) {
-            tArtist.insert(i, "artist" + i, new java.sql.Date(dateBase + 10000 * i));
-        }
-    }
-
-    public void test_DataRows_DataMapNameRoot() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("tstmap", "SELECT * FROM ARTIST");
-        assertTrue(q1.isFetchingDataRows());
-
-        List<DataRow> result = context.select(q1);
-        assertEquals(20, result.size());
-        assertTrue(result.get(0) instanceof DataRow);
-    }
-
-    public void test_DataRows_DefaultRoot() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
-        assertTrue(q1.isFetchingDataRows());
-
-        List<DataRow> result = context.select(q1);
-        assertEquals(20, result.size());
-        assertTrue(result.get(0) instanceof DataRow);
-    }
-
-    public void test_DataRows_ClassRoot() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST");
-        assertFalse(q1.isFetchingDataRows());
-        List<Artist> result = context.select(q1);
-        assertEquals(20, result.size());
-        assertTrue(result.get(0) instanceof Artist);
-    }
-
-    public void test_DataRows_ClassRoot_Parameters() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)");
-        q1.getParameters().put("a", "artist3");
-
-        assertFalse(q1.isFetchingDataRows());
-        Artist a = context.selectOne(q1);
-        assertEquals("artist3", a.getArtistName());
-    }
-
-    public void test_DataRows_ClassRoot_Bind() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class,
-                "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a) OR ARTIST_NAME = #bind($b)");
-        q1.params("a", "artist3").params("b", "artist4");
-
-        List<Artist> result = context.select(q1);
-        assertEquals(2, result.size());
-    }
-
-    public void test_DataRows_ColumnNameCaps() throws Exception {
-
-        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST WHERE ARTIST_NAME = 'artist2'");
-        q1.upperColumnNames();
-
-        SQLTemplate r1 = (SQLTemplate) q1.getReplacementQuery(context.getEntityResolver());
-        assertEquals(CapsStrategy.UPPER, r1.getColumnNamesCapitalization());
-
-        q1.lowerColumnNames();
-        SQLTemplate r2 = (SQLTemplate) q1.getReplacementQuery(context.getEntityResolver());
-        assertEquals(CapsStrategy.LOWER, r2.getColumnNamesCapitalization());
-    }
-
-    public void test_DataRows_FetchLimit() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
-        q1.limit(5);
-
-        assertEquals(5, context.select(q1).size());
-    }
-
-    public void test_DataRows_FetchOffset() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST");
-        q1.offset(4);
-
-        assertEquals(16, context.select(q1).size());
-    }
-
-    public void test_Append() throws Exception {
-
-        createArtistsDataSet();
-
-        SQLSelect<Artist> q1 = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST")
-                .append(" WHERE ARTIST_NAME = #bind($a)").params("a", "artist3");
-
-        List<Artist> result = context.select(q1);
-        assertEquals(1, result.size());
-    }
-
-    public void test_Select() throws Exception {
-
-        createArtistsDataSet();
-
-        List<Artist> result = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
-                .params("a", "artist3").select(context);
-
-        assertEquals(1, result.size());
-    }
-
-    public void test_SelectOne() throws Exception {
-
-        createArtistsDataSet();
-
-        Artist a = SQLSelect.query(Artist.class, "SELECT * FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
-                .params("a", "artist3").selectOne(context);
-
-        assertEquals("artist3", a.getArtistName());
-    }
-
-    public void test_SelectLong() throws Exception {
-
-        createArtistsDataSet();
-
-        long id = SQLSelect.scalarQuery(Long.class, "SELECT ARTIST_ID FROM ARTIST WHERE ARTIST_NAME = #bind($a)")
-                .params("a", "artist3").selectOne(context);
-
-        assertEquals(3l, id);
-    }
-
-    public void test_SelectLongArray() throws Exception {
-
-        createArtistsDataSet();
-
-        List<Long> ids = SQLSelect.scalarQuery(Long.class, "SELECT ARTIST_ID FROM ARTIST ORDER BY ARTIST_ID").select(
-                context);
-
-        assertEquals(20, ids.size());
-        assertEquals(2l, ids.get(1).longValue());
-    }
-
-    public void test_SelectCount() throws Exception {
-
-        createArtistsDataSet();
-
-        int c = SQLSelect.scalarQuery(Integer.class, "SELECT #result('COUNT(*)' 'int') FROM ARTIST").selectOne(context);
-
-        assertEquals(20, c);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyIT.java
new file mode 100644
index 0000000..3a8c440
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyIT.java
@@ -0,0 +1,96 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SQLTemplateCacheKeyIT extends ServerCase {
+
+    @Inject
+    private EntityResolver resolver;
+
+    public void testNoCache() {
+
+        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.NO_CACHE, md1.getCacheStrategy());
+        assertNull(md1.getCacheKey());
+
+        query.setName("XYZ");
+        QueryMetadata md2 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.NO_CACHE, md2.getCacheStrategy());
+        assertNull(md2.getCacheKey());
+    }
+
+    public void testLocalCache() {
+
+        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
+
+        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.LOCAL_CACHE, md1.getCacheStrategy());
+        assertNotNull(md1.getCacheKey());
+    }
+
+    public void testSharedCache() {
+
+        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
+
+        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
+        assertNotNull(md1.getCacheKey());
+    }
+
+    public void testNamedQuery() {
+
+        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
+
+        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+        query.setName("XYZ");
+
+        QueryMetadata md1 = query.getMetaData(resolver);
+        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
+        assertFalse("XYZ".equals(md1.getCacheKey()));
+    }
+
+    public void testCacheFetchLimitAndOffset() {
+        SQLTemplate q1 = new SQLTemplate(Artist.class, "SELECT ME");
+        q1.setFetchOffset(5);
+        q1.setFetchLimit(10);
+        q1.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+        
+        SQLTemplate q2 = new SQLTemplate(Artist.class, "SELECT ME");
+        q2.setFetchOffset(5);
+        q2.setFetchLimit(10);
+        q2.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+
+        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
+                .getMetaData(resolver)
+                .getCacheKey());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyTest.java
deleted file mode 100644
index d0f07dc..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateCacheKeyTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*****************************************************************
- *   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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class SQLTemplateCacheKeyTest extends ServerCase {
-
-    @Inject
-    private EntityResolver resolver;
-
-    public void testNoCache() {
-
-        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.NO_CACHE, md1.getCacheStrategy());
-        assertNull(md1.getCacheKey());
-
-        query.setName("XYZ");
-        QueryMetadata md2 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.NO_CACHE, md2.getCacheStrategy());
-        assertNull(md2.getCacheKey());
-    }
-
-    public void testLocalCache() {
-
-        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
-
-        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.LOCAL_CACHE, md1.getCacheStrategy());
-        assertNotNull(md1.getCacheKey());
-    }
-
-    public void testSharedCache() {
-
-        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
-
-        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
-        assertNotNull(md1.getCacheKey());
-    }
-
-    public void testNamedQuery() {
-
-        SQLTemplate query = new SQLTemplate(Artist.class, "SELECT ME");
-
-        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-        query.setName("XYZ");
-
-        QueryMetadata md1 = query.getMetaData(resolver);
-        assertEquals(QueryCacheStrategy.SHARED_CACHE, md1.getCacheStrategy());
-        assertFalse("XYZ".equals(md1.getCacheKey()));
-    }
-
-    public void testCacheFetchLimitAndOffset() {
-        SQLTemplate q1 = new SQLTemplate(Artist.class, "SELECT ME");
-        q1.setFetchOffset(5);
-        q1.setFetchLimit(10);
-        q1.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-        
-        SQLTemplate q2 = new SQLTemplate(Artist.class, "SELECT ME");
-        q2.setFetchOffset(5);
-        q2.setFetchLimit(10);
-        q2.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
-
-        assertEquals(q1.getMetaData(resolver).getCacheKey(), q2
-                .getMetaData(resolver)
-                .getCacheKey());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateIT.java
new file mode 100644
index 0000000..95d2951
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLTemplateIT.java
@@ -0,0 +1,211 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+
+package org.apache.cayenne.query;
+
+import java.util.Collections;
+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.DataRow;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.util.Util;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SQLTemplateIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+    }
+
+    public void testSQLTemplateForDataMap() {
+        DataMap testDataMap = context.getEntityResolver().getDataMap("tstmap");
+        SQLTemplate q1 = new SQLTemplate(testDataMap, "SELECT * FROM ARTIST", true);
+        List<DataRow> result = context.performQuery(q1);
+        assertEquals(0, result.size());
+    }
+
+    public void testSQLTemplateForDataMapWithInsert() {
+        DataMap testDataMap = context.getEntityResolver().getDataMap("tstmap");
+        String sql = "INSERT INTO ARTIST VALUES (15, 'Surikov', null)";
+        SQLTemplate q1 = new SQLTemplate(testDataMap, sql, true);
+        context.performNonSelectingQuery(q1);
+
+        SQLTemplate q2 = new SQLTemplate(testDataMap, "SELECT * FROM ARTIST", true);
+        List<DataRow> result = context.performQuery(q2);
+        assertEquals(1, result.size());
+    }
+
+    public void testSQLTemplateForDataMapWithInsertException() {
+        DataMap testDataMap = context.getEntityResolver().getDataMap("tstmap");
+        String sql = "INSERT INTO ARTIST VALUES (15, 'Surikov', null)";
+        SQLTemplate q1 = new SQLTemplate(testDataMap, sql, true);
+        context.performNonSelectingQuery(q1);
+
+        SQLTemplate q2 = new SQLTemplate(testDataMap, "SELECT * FROM ARTIST", false);
+        boolean gotRuntimeException = false;
+        try {
+            context.performQuery(q2);
+        } catch (CayenneRuntimeException e) {
+            gotRuntimeException = true;
+        }
+        assertTrue("If fetchingDataRows is false and ObjectEntity not set, shoulb be thrown exception",
+                gotRuntimeException);
+    }
+
+    public void testColumnNameCapitalization() {
+        SQLTemplate q1 = new SQLTemplate("E1", "SELECT");
+        assertSame(CapsStrategy.DEFAULT, q1.getColumnNamesCapitalization());
+        q1.setColumnNamesCapitalization(CapsStrategy.UPPER);
+        assertEquals(CapsStrategy.UPPER, q1.getColumnNamesCapitalization());
+    }
+
+    public void testQueryWithParameters() {
+        SQLTemplate q1 = new SQLTemplate("E1", "SELECT");
+        q1.setName("QName");
+
+        Query q2 = q1.queryWithParameters(Collections.EMPTY_MAP);
+        assertNotNull(q2);
+        assertNotSame(q1, q2);
+        assertTrue(q2 instanceof SQLTemplate);
+
+        assertNull(q2.getName());
+
+        Query q3 = q1.queryWithParameters(Collections.singletonMap("a", "b"));
+        assertNotNull(q3);
+        assertNotSame(q1, q3);
+        assertNull(q3.getName());
+        assertFalse(q1.getName().equals(q3.getName()));
+
+        Query q4 = q1.queryWithParameters(Collections.singletonMap("a", "b"));
+        assertNotNull(q4);
+        assertNotSame(q3, q4);
+        assertEquals(q3.getName(), q4.getName());
+    }
+
+    public void testSerializability() throws Exception {
+        SQLTemplate o = new SQLTemplate("Test", "DO SQL");
+        Object clone = Util.cloneViaSerialization(o);
+
+        assertTrue(clone instanceof SQLTemplate);
+        SQLTemplate c1 = (SQLTemplate) clone;
+
+        assertNotSame(o, c1);
+        assertEquals(o.getRoot(), c1.getRoot());
+        assertEquals(o.getDefaultTemplate(), c1.getDefaultTemplate());
+    }
+
+    public void testGetDefaultTemplate() {
+        SQLTemplate query = new SQLTemplate();
+        query.setDefaultTemplate("AAA # BBB");
+        assertEquals("AAA # BBB", query.getDefaultTemplate());
+    }
+
+    public void testGetTemplate() {
+        SQLTemplate query = new SQLTemplate();
+
+        // no template for key, no default template... must be null
+        assertNull(query.getTemplate("key1"));
+
+        // no template for key, must return default
+        query.setDefaultTemplate("AAA # BBB");
+        assertEquals("AAA # BBB", query.getTemplate("key1"));
+
+        // must find template
+        query.setTemplate("key1", "XYZ");
+        assertEquals("XYZ", query.getTemplate("key1"));
+
+        // add another template.. still must find
+        query.setTemplate("key2", "123");
+        assertEquals("XYZ", query.getTemplate("key1"));
+        assertEquals("123", query.getTemplate("key2"));
+    }
+
+    public void testSingleParameterSet() throws Exception {
+        SQLTemplate query = new SQLTemplate();
+
+        assertNotNull(query.getParameters());
+        assertTrue(query.getParameters().isEmpty());
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("a", "b");
+
+        query.setParameters(params);
+        assertEquals(params, query.getParameters());
+        Iterator<?> it = query.parametersIterator();
+        assertTrue(it.hasNext());
+        assertEquals(params, it.next());
+        assertFalse(it.hasNext());
+
+        query.setParameters(null);
+        assertNotNull(query.getParameters());
+        assertTrue(query.getParameters().isEmpty());
+        it = query.parametersIterator();
+        assertFalse(it.hasNext());
+    }
+
+    public void testBatchParameterSet() throws Exception {
+        SQLTemplate query = new SQLTemplate();
+
+        assertNotNull(query.getParameters());
+        assertTrue(query.getParameters().isEmpty());
+
+        Map<String, Object> params1 = new HashMap<String, Object>();
+        params1.put("a", "b");
+
+        Map<String, Object> params2 = new HashMap<String, Object>();
+        params2.put("1", "2");
+
+        query.setParameters(new Map[] { params1, params2, null });
+        assertEquals(params1, query.getParameters());
+        Iterator<?> it = query.parametersIterator();
+        assertTrue(it.hasNext());
+        assertEquals(params1, it.next());
+        assertTrue(it.hasNext());
+        assertEquals(params2, it.next());
+        assertTrue(it.hasNext());
+        assertTrue(((Map<String, Object>) it.next()).isEmpty());
+        assertFalse(it.hasNext());
+
+        query.setParameters((Map[]) null);
+        assertNotNull(query.getParameters());
+        assertTrue(query.getParameters().isEmpty());
+        it = query.parametersIterator();
+        assertFalse(it.hasNext());
+    }
+}


Mime
View raw message