You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/11/02 08:10:22 UTC
[34/48] Installing Maven Failsafe Plugin
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectIT.java
new file mode 100644
index 0000000..c0cd1c1
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectIT.java
@@ -0,0 +1,183 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.FaultFailureException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+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.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.UnitTestClosure;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextLocalObjectIT extends ServerCase {
+
+ @Inject
+ private DataContext context1;
+
+ @Inject
+ private DataContext context2;
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Inject
+ private DataChannelInterceptor interceptor;
+
+ @Inject
+ private ServerRuntime runtime;
+
+ private TableHelper tArtist;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+ dbHelper.deleteAll("EXHIBIT");
+ dbHelper.deleteAll("GALLERY");
+
+ tArtist = new TableHelper(dbHelper, "ARTIST");
+ tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+ }
+
+ public void testLocalObject_InCache() throws Exception {
+ tArtist.insert(456, "Bla");
+
+ final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
+ final Artist a2 = Cayenne.objectForPK(context2, Artist.class, 456);
+
+ interceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+ Artist a3 = context2.localObject(a1);
+ assertSame(a3, a2);
+ assertSame(context2, a3.getObjectContext());
+ }
+ });
+ }
+
+ public void testLocalObject_SameContext() throws Exception {
+ tArtist.insert(456, "Bla");
+
+ final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
+
+ interceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+ Artist a2 = context1.localObject(a1);
+ assertSame(a2, a1);
+ }
+ });
+ }
+
+ public void testLocalObject_NotInCache() throws Exception {
+ tArtist.insert(456, "Bla");
+
+ final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
+
+ interceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+ Artist a3 = context2.localObject(a1);
+ assertNotSame(a3, a1);
+ assertEquals(a3.getObjectId(), a1.getObjectId());
+ assertSame(context2, a3.getObjectContext());
+ }
+ });
+ }
+
+ public void testLocalObject_FFE_InvalidID() throws Exception {
+ tArtist.insert(777, "AA");
+
+ final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 777);
+
+ Artist a3 = context2.localObject(a1);
+ assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());
+
+ context1.invalidateObjects(a1);
+ tArtist.deleteAll();
+
+ assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());
+
+ try {
+ a3.getArtistName();
+
+ fail("FaultFailureException wasn't thrown on attempt to "
+ + "resolve HOLLOW object with no backing DB row");
+ }
+ catch (FaultFailureException e) {
+ // expected
+ }
+
+ }
+
+ public void testLocalObject_TempId() throws Exception {
+
+ final Artist a1 = context1.newObject(Artist.class);
+
+ interceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+
+ Artist a = context2.localObject(a1);
+ assertNotNull(a);
+ assertEquals(a1.getObjectId(), a.getObjectId());
+
+ // FFE mist be thrown on attempt to read non-existing temp ID
+ try {
+
+ a.getArtistName();
+ fail("FaultFailureException wasn't thrown on attempt to "
+ + "resolve HOLLOW object with temp id");
+ }
+ catch (FaultFailureException e) {
+ // expected
+ }
+ }
+ });
+ }
+
+ public void testLocalObject_TempId_NestedContext() throws Exception {
+
+ final Artist a1 = context1.newObject(Artist.class);
+
+ final ObjectContext nestedContext = runtime.newContext(context1);
+
+ interceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+
+ Artist a3 = nestedContext.localObject(a1);
+ assertNotSame(a3, a1);
+ assertEquals(a3.getObjectId(), a1.getObjectId());
+ assertSame(nestedContext, a3.getObjectContext());
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectTest.java
deleted file mode 100644
index 7d868b9..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextLocalObjectTest.java
+++ /dev/null
@@ -1,183 +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.access;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.FaultFailureException;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-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.DataChannelInterceptor;
-import org.apache.cayenne.unit.di.UnitTestClosure;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextLocalObjectTest extends ServerCase {
-
- @Inject
- private DataContext context1;
-
- @Inject
- private DataContext context2;
-
- @Inject
- private DBHelper dbHelper;
-
- @Inject
- private DataChannelInterceptor interceptor;
-
- @Inject
- private ServerRuntime runtime;
-
- private TableHelper tArtist;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("PAINTING_INFO");
- dbHelper.deleteAll("PAINTING");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST_GROUP");
- dbHelper.deleteAll("ARTIST");
- dbHelper.deleteAll("EXHIBIT");
- dbHelper.deleteAll("GALLERY");
-
- tArtist = new TableHelper(dbHelper, "ARTIST");
- tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
- }
-
- public void testLocalObject_InCache() throws Exception {
- tArtist.insert(456, "Bla");
-
- final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
- final Artist a2 = Cayenne.objectForPK(context2, Artist.class, 456);
-
- interceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
- public void execute() {
- Artist a3 = context2.localObject(a1);
- assertSame(a3, a2);
- assertSame(context2, a3.getObjectContext());
- }
- });
- }
-
- public void testLocalObject_SameContext() throws Exception {
- tArtist.insert(456, "Bla");
-
- final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
-
- interceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
- public void execute() {
- Artist a2 = context1.localObject(a1);
- assertSame(a2, a1);
- }
- });
- }
-
- public void testLocalObject_NotInCache() throws Exception {
- tArtist.insert(456, "Bla");
-
- final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
-
- interceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
- public void execute() {
- Artist a3 = context2.localObject(a1);
- assertNotSame(a3, a1);
- assertEquals(a3.getObjectId(), a1.getObjectId());
- assertSame(context2, a3.getObjectContext());
- }
- });
- }
-
- public void testLocalObject_FFE_InvalidID() throws Exception {
- tArtist.insert(777, "AA");
-
- final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 777);
-
- Artist a3 = context2.localObject(a1);
- assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());
-
- context1.invalidateObjects(a1);
- tArtist.deleteAll();
-
- assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());
-
- try {
- a3.getArtistName();
-
- fail("FaultFailureException wasn't thrown on attempt to "
- + "resolve HOLLOW object with no backing DB row");
- }
- catch (FaultFailureException e) {
- // expected
- }
-
- }
-
- public void testLocalObject_TempId() throws Exception {
-
- final Artist a1 = context1.newObject(Artist.class);
-
- interceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
- public void execute() {
-
- Artist a = context2.localObject(a1);
- assertNotNull(a);
- assertEquals(a1.getObjectId(), a.getObjectId());
-
- // FFE mist be thrown on attempt to read non-existing temp ID
- try {
-
- a.getArtistName();
- fail("FaultFailureException wasn't thrown on attempt to "
- + "resolve HOLLOW object with temp id");
- }
- catch (FaultFailureException e) {
- // expected
- }
- }
- });
- }
-
- public void testLocalObject_TempId_NestedContext() throws Exception {
-
- final Artist a1 = context1.newObject(Artist.class);
-
- final ObjectContext nestedContext = runtime.newContext(context1);
-
- interceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
- public void execute() {
-
- Artist a3 = nestedContext.localObject(a1);
- assertNotSame(a3, a1);
- assertEquals(a3.getObjectId(), a1.getObjectId());
- assertSame(nestedContext, a3.getObjectContext());
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java
new file mode 100644
index 0000000..88dc6a5
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java
@@ -0,0 +1,81 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.testmap.NoPkTestEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.List;
+import java.util.Map;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextNoPkIT extends ServerCase {
+
+ @Inject
+ protected ObjectContext context;
+
+ @Inject
+ protected DBHelper dbHelper;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ TableHelper noPkTestTable = new TableHelper(dbHelper, "NO_PK_TEST", "ATTRIBUTE1");
+ noPkTestTable.deleteAll();
+
+ noPkTestTable.insert(1);
+ noPkTestTable.insert(2);
+ }
+
+ public void testNoPkFetchObjects() throws Exception {
+ try {
+ List objects = context.performQuery(new SelectQuery(NoPkTestEntity.class));
+ fail("Query for entity with no primary key must have failed, instead we got "
+ + objects.size()
+ + " rows.");
+ }
+ catch (CayenneRuntimeException ex) {
+ // exception expected
+ }
+ }
+
+ public void testNoPkFetchDataRows() throws Exception {
+ SelectQuery query = new SelectQuery(NoPkTestEntity.class);
+ query.setFetchingDataRows(true);
+
+ List rows = context.performQuery(query);
+ assertNotNull(rows);
+ assertEquals(2, rows.size());
+
+ Map row1 = (Map) rows.get(0);
+ Map row2 = (Map) rows.get(1);
+
+ // assert that rows have different values
+ // (there was a bug earlier that fetched distinct rows for
+ // entities with no primary key.
+ assertTrue(!row1.get("ATTRIBUTE1").equals(row2.get("ATTRIBUTE1")));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java
deleted file mode 100644
index 8f6a906..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkTest.java
+++ /dev/null
@@ -1,81 +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.access;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.testmap.NoPkTestEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextNoPkTest extends ServerCase {
-
- @Inject
- protected ObjectContext context;
-
- @Inject
- protected DBHelper dbHelper;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- TableHelper noPkTestTable = new TableHelper(dbHelper, "NO_PK_TEST", "ATTRIBUTE1");
- noPkTestTable.deleteAll();
-
- noPkTestTable.insert(1);
- noPkTestTable.insert(2);
- }
-
- public void testNoPkFetchObjects() throws Exception {
- try {
- List objects = context.performQuery(new SelectQuery(NoPkTestEntity.class));
- fail("Query for entity with no primary key must have failed, instead we got "
- + objects.size()
- + " rows.");
- }
- catch (CayenneRuntimeException ex) {
- // exception expected
- }
- }
-
- public void testNoPkFetchDataRows() throws Exception {
- SelectQuery query = new SelectQuery(NoPkTestEntity.class);
- query.setFetchingDataRows(true);
-
- List rows = context.performQuery(query);
- assertNotNull(rows);
- assertEquals(2, rows.size());
-
- Map row1 = (Map) rows.get(0);
- Map row2 = (Map) rows.get(1);
-
- // assert that rows have different values
- // (there was a bug earlier that fetched distinct rows for
- // entities with no primary key.
- assertTrue(!row1.get("ATTRIBUTE1").equals(row2.get("ATTRIBUTE1")));
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryIT.java
new file mode 100644
index 0000000..f9536e9
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryIT.java
@@ -0,0 +1,123 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.test.jdbc.DBHelper;
+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.Collections;
+import java.util.Date;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextObjectIdQueryIT 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("PAINTING1");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+ }
+
+ public void testRefreshNullifiedValuesNew() {
+
+ Artist a = context.newObject(Artist.class);
+ a.setArtistName("X");
+ a.setDateOfBirth(new Date());
+
+ context.commitChanges();
+
+ context.performGenericQuery(new SQLTemplate(
+ Artist.class,
+ "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));
+
+ long id = Cayenne.longPKForObject(a);
+ ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
+ "Artist",
+ Artist.ARTIST_ID_PK_COLUMN,
+ id), false, ObjectIdQuery.CACHE_REFRESH);
+
+ Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
+ assertNull(a1.getDateOfBirth());
+ assertEquals("X", a1.getArtistName());
+ }
+
+ public void testNoRefreshValuesNew() {
+
+ Artist a = context.newObject(Artist.class);
+ a.setArtistName("X");
+
+ context.commitChanges();
+
+ context.performGenericQuery(new SQLTemplate(
+ Artist.class,
+ "UPDATE ARTIST SET ARTIST_NAME = 'Y'"));
+
+ long id = Cayenne.longPKForObject(a);
+ ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
+ "Artist",
+ Artist.ARTIST_ID_PK_COLUMN,
+ id), false, ObjectIdQuery.CACHE);
+
+ Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
+ assertEquals("X", a1.getArtistName());
+ }
+
+ public void testRefreshNullifiedValuesExisting() {
+
+ SQLTemplate insert = new SQLTemplate(
+ Artist.class,
+ "INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME, DATE_OF_BIRTH) VALUES (44, 'X', #bind($date 'DATE'))");
+ insert.setParameters(Collections.singletonMap("date", new Date()));
+
+ context.performGenericQuery(insert);
+
+ Artist a = Cayenne.objectForPK(context, Artist.class, 44l);
+ assertNotNull(a.getDateOfBirth());
+ assertEquals("X", a.getArtistName());
+
+ context.performGenericQuery(new SQLTemplate(
+ Artist.class,
+ "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));
+
+ ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
+ "Artist",
+ Artist.ARTIST_ID_PK_COLUMN,
+ 44l), false, ObjectIdQuery.CACHE_REFRESH);
+
+ Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
+ assertNull(a1.getDateOfBirth());
+ assertEquals("X", a1.getArtistName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryTest.java
deleted file mode 100644
index 1bf356c..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectIdQueryTest.java
+++ /dev/null
@@ -1,123 +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.access;
-
-import java.util.Collections;
-import java.util.Date;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.ObjectIdQuery;
-import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.test.jdbc.DBHelper;
-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 DataContextObjectIdQueryTest 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("PAINTING1");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST_GROUP");
- dbHelper.deleteAll("ARTIST");
- }
-
- public void testRefreshNullifiedValuesNew() {
-
- Artist a = context.newObject(Artist.class);
- a.setArtistName("X");
- a.setDateOfBirth(new Date());
-
- context.commitChanges();
-
- context.performGenericQuery(new SQLTemplate(
- Artist.class,
- "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));
-
- long id = Cayenne.longPKForObject(a);
- ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
- "Artist",
- Artist.ARTIST_ID_PK_COLUMN,
- id), false, ObjectIdQuery.CACHE_REFRESH);
-
- Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
- assertNull(a1.getDateOfBirth());
- assertEquals("X", a1.getArtistName());
- }
-
- public void testNoRefreshValuesNew() {
-
- Artist a = context.newObject(Artist.class);
- a.setArtistName("X");
-
- context.commitChanges();
-
- context.performGenericQuery(new SQLTemplate(
- Artist.class,
- "UPDATE ARTIST SET ARTIST_NAME = 'Y'"));
-
- long id = Cayenne.longPKForObject(a);
- ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
- "Artist",
- Artist.ARTIST_ID_PK_COLUMN,
- id), false, ObjectIdQuery.CACHE);
-
- Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
- assertEquals("X", a1.getArtistName());
- }
-
- public void testRefreshNullifiedValuesExisting() {
-
- SQLTemplate insert = new SQLTemplate(
- Artist.class,
- "INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME, DATE_OF_BIRTH) VALUES (44, 'X', #bind($date 'DATE'))");
- insert.setParameters(Collections.singletonMap("date", new Date()));
-
- context.performGenericQuery(insert);
-
- Artist a = Cayenne.objectForPK(context, Artist.class, 44l);
- assertNotNull(a.getDateOfBirth());
- assertEquals("X", a.getArtistName());
-
- context.performGenericQuery(new SQLTemplate(
- Artist.class,
- "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));
-
- ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
- "Artist",
- Artist.ARTIST_ID_PK_COLUMN,
- 44l), false, ObjectIdQuery.CACHE_REFRESH);
-
- Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
- assertNull(a1.getDateOfBirth());
- assertEquals("X", a1.getArtistName());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingIT.java
new file mode 100644
index 0000000..3b2f043
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingIT.java
@@ -0,0 +1,139 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+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.DataChannelInterceptor;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+import java.util.Collections;
+import java.util.Date;
+
+/**
+ * Tests objects registration in DataContext, transferring objects between contexts and
+ * such.
+ */
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextObjectTrackingIT extends ServerCase {
+
+ @Inject
+ protected DataChannelInterceptor queryInterceptor;
+
+ @Inject
+ protected DataContext context;
+
+ @Inject
+ protected DBHelper dbHelper;
+
+ @Inject
+ protected ServerRuntime runtime;
+
+ protected TableHelper tArtist;
+ protected TableHelper tPainting;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+
+ tArtist = new TableHelper(dbHelper, "ARTIST");
+ tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+ tPainting = new TableHelper(dbHelper, "PAINTING");
+ tPainting.setColumns(
+ "PAINTING_ID",
+ "ARTIST_ID",
+ "PAINTING_TITLE",
+ "ESTIMATED_PRICE").setColumnTypes(
+ Types.INTEGER,
+ Types.BIGINT,
+ Types.VARCHAR,
+ Types.DECIMAL);
+ }
+
+ protected void createArtistsDataSet() throws Exception {
+ tArtist.insert(33001, "artist1");
+ tArtist.insert(33002, "artist2");
+ tArtist.insert(33003, "artist3");
+ tArtist.insert(33004, "artist4");
+ }
+
+ protected void createMixedDataSet() throws Exception {
+ tArtist.insert(33003, "artist3");
+ tPainting.insert(33003, 33003, "P_artist3", 3000);
+ }
+
+ public void testUnregisterObject() {
+
+ DataRow row = new DataRow(10);
+ row.put("ARTIST_ID", new Integer(1));
+ row.put("ARTIST_NAME", "ArtistXYZ");
+ row.put("DATE_OF_BIRTH", new Date());
+ DataObject obj = context.objectFromDataRow(Artist.class, row);
+ ObjectId oid = obj.getObjectId();
+
+ assertEquals(PersistenceState.COMMITTED, obj.getPersistenceState());
+ assertSame(context, obj.getObjectContext());
+ assertSame(obj, context.getGraphManager().getNode(oid));
+
+ context.unregisterObjects(Collections.singletonList(obj));
+
+ assertEquals(PersistenceState.TRANSIENT, obj.getPersistenceState());
+ assertNull(obj.getObjectContext());
+ assertNull(obj.getObjectId());
+ assertNull(context.getGraphManager().getNode(oid));
+ assertNull(context.getObjectStore().getCachedSnapshot(oid));
+ }
+
+ public void testInvalidateObjects_Vararg() {
+
+ DataRow row = new DataRow(10);
+ row.put("ARTIST_ID", new Integer(1));
+ row.put("ARTIST_NAME", "ArtistXYZ");
+ row.put("DATE_OF_BIRTH", new Date());
+ DataObject obj = context.objectFromDataRow(Artist.class, row);
+ ObjectId oid = obj.getObjectId();
+
+ assertEquals(PersistenceState.COMMITTED, obj.getPersistenceState());
+ assertSame(context, obj.getObjectContext());
+ assertSame(obj, context.getGraphManager().getNode(oid));
+
+ context.invalidateObjects(obj);
+
+ assertEquals(PersistenceState.HOLLOW, obj.getPersistenceState());
+ assertSame(context, obj.getObjectContext());
+ assertSame(oid, obj.getObjectId());
+ assertNull(context.getObjectStore().getCachedSnapshot(oid));
+ assertNotNull(context.getGraphManager().getNode(oid));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingTest.java
deleted file mode 100644
index c23b324..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextObjectTrackingTest.java
+++ /dev/null
@@ -1,139 +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.access;
-
-import java.sql.Types;
-import java.util.Collections;
-import java.util.Date;
-
-import org.apache.cayenne.DataObject;
-import org.apache.cayenne.DataRow;
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-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.DataChannelInterceptor;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-/**
- * Tests objects registration in DataContext, transferring objects between contexts and
- * such.
- */
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextObjectTrackingTest extends ServerCase {
-
- @Inject
- protected DataChannelInterceptor queryInterceptor;
-
- @Inject
- protected DataContext context;
-
- @Inject
- protected DBHelper dbHelper;
-
- @Inject
- protected ServerRuntime runtime;
-
- protected TableHelper tArtist;
- protected TableHelper tPainting;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("PAINTING_INFO");
- dbHelper.deleteAll("PAINTING");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST_GROUP");
- dbHelper.deleteAll("ARTIST");
-
- tArtist = new TableHelper(dbHelper, "ARTIST");
- tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
-
- tPainting = new TableHelper(dbHelper, "PAINTING");
- tPainting.setColumns(
- "PAINTING_ID",
- "ARTIST_ID",
- "PAINTING_TITLE",
- "ESTIMATED_PRICE").setColumnTypes(
- Types.INTEGER,
- Types.BIGINT,
- Types.VARCHAR,
- Types.DECIMAL);
- }
-
- protected void createArtistsDataSet() throws Exception {
- tArtist.insert(33001, "artist1");
- tArtist.insert(33002, "artist2");
- tArtist.insert(33003, "artist3");
- tArtist.insert(33004, "artist4");
- }
-
- protected void createMixedDataSet() throws Exception {
- tArtist.insert(33003, "artist3");
- tPainting.insert(33003, 33003, "P_artist3", 3000);
- }
-
- public void testUnregisterObject() {
-
- DataRow row = new DataRow(10);
- row.put("ARTIST_ID", new Integer(1));
- row.put("ARTIST_NAME", "ArtistXYZ");
- row.put("DATE_OF_BIRTH", new Date());
- DataObject obj = context.objectFromDataRow(Artist.class, row);
- ObjectId oid = obj.getObjectId();
-
- assertEquals(PersistenceState.COMMITTED, obj.getPersistenceState());
- assertSame(context, obj.getObjectContext());
- assertSame(obj, context.getGraphManager().getNode(oid));
-
- context.unregisterObjects(Collections.singletonList(obj));
-
- assertEquals(PersistenceState.TRANSIENT, obj.getPersistenceState());
- assertNull(obj.getObjectContext());
- assertNull(obj.getObjectId());
- assertNull(context.getGraphManager().getNode(oid));
- assertNull(context.getObjectStore().getCachedSnapshot(oid));
- }
-
- public void testInvalidateObjects_Vararg() {
-
- DataRow row = new DataRow(10);
- row.put("ARTIST_ID", new Integer(1));
- row.put("ARTIST_NAME", "ArtistXYZ");
- row.put("DATE_OF_BIRTH", new Date());
- DataObject obj = context.objectFromDataRow(Artist.class, row);
- ObjectId oid = obj.getObjectId();
-
- assertEquals(PersistenceState.COMMITTED, obj.getPersistenceState());
- assertSame(context, obj.getObjectContext());
- assertSame(obj, context.getGraphManager().getNode(oid));
-
- context.invalidateObjects(obj);
-
- assertEquals(PersistenceState.HOLLOW, obj.getPersistenceState());
- assertSame(context, obj.getObjectContext());
- assertSame(oid, obj.getObjectId());
- assertNull(context.getObjectStore().getCachedSnapshot(oid));
- assertNotNull(context.getGraphManager().getNode(oid));
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingIT.java
new file mode 100644
index 0000000..9d40879
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingIT.java
@@ -0,0 +1,127 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SortOrder;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextOrderingIT 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("PAINTING1");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+ }
+
+ public void testMultipleOrdering() throws Exception {
+
+ Calendar c = Calendar.getInstance();
+
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("2");
+ a1.setDateOfBirth(c.getTime());
+
+ c.add(Calendar.DAY_OF_MONTH, -1);
+ Artist a2 = context.newObject(Artist.class);
+ a2.setArtistName("3");
+ a2.setDateOfBirth(c.getTime());
+
+ c.add(Calendar.DAY_OF_MONTH, -1);
+ Artist a3 = context.newObject(Artist.class);
+ a3.setArtistName("3");
+ a3.setDateOfBirth(c.getTime());
+
+ context.commitChanges();
+
+ SelectQuery query = new SelectQuery(Artist.class);
+ query.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.DESCENDING);
+ query.addOrdering(Artist.DATE_OF_BIRTH_PROPERTY, SortOrder.DESCENDING);
+
+ List<Artist> list = context.performQuery(query);
+ assertEquals(3, list.size());
+ assertSame(a2, list.get(0));
+ assertSame(a3, list.get(1));
+ assertSame(a1, list.get(2));
+ }
+
+ public void testMultipleOrderingInSelectClauseCAY_1074() throws Exception {
+
+ Calendar c = Calendar.getInstance();
+
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("2");
+ a1.setDateOfBirth(c.getTime());
+
+ c.add(Calendar.DAY_OF_MONTH, -1);
+ Artist a2 = context.newObject(Artist.class);
+ a2.setArtistName("3");
+ a2.setDateOfBirth(c.getTime());
+
+ c.add(Calendar.DAY_OF_MONTH, -1);
+ Artist a3 = context.newObject(Artist.class);
+ a3.setArtistName("3");
+ a3.setDateOfBirth(c.getTime());
+
+ Painting p1 = context.newObject(Painting.class);
+ p1.setEstimatedPrice(new BigDecimal(1));
+ p1.setPaintingTitle("Y");
+ a1.addToPaintingArray(p1);
+
+ Painting p2 = context.newObject(Painting.class);
+ p2.setEstimatedPrice(new BigDecimal(2));
+ p2.setPaintingTitle("X");
+ a2.addToPaintingArray(p2);
+
+ context.commitChanges();
+
+ SelectQuery query1 = new SelectQuery(Artist.class);
+
+ // per CAY-1074, adding a to-many join to expression messes up the ordering
+ query1.andQualifier(ExpressionFactory.noMatchExp(
+ Artist.PAINTING_ARRAY_PROPERTY,
+ null));
+ query1.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.DESCENDING);
+ query1.addOrdering(Artist.DATE_OF_BIRTH_PROPERTY, SortOrder.DESCENDING);
+
+ List<Artist> list1 = context.performQuery(query1);
+ assertEquals(2, list1.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java
deleted file mode 100644
index 3ac4023..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOrderingTest.java
+++ /dev/null
@@ -1,127 +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.access;
-
-import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.List;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.SortOrder;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextOrderingTest 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("PAINTING1");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST_GROUP");
- dbHelper.deleteAll("ARTIST");
- }
-
- public void testMultipleOrdering() throws Exception {
-
- Calendar c = Calendar.getInstance();
-
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("2");
- a1.setDateOfBirth(c.getTime());
-
- c.add(Calendar.DAY_OF_MONTH, -1);
- Artist a2 = context.newObject(Artist.class);
- a2.setArtistName("3");
- a2.setDateOfBirth(c.getTime());
-
- c.add(Calendar.DAY_OF_MONTH, -1);
- Artist a3 = context.newObject(Artist.class);
- a3.setArtistName("3");
- a3.setDateOfBirth(c.getTime());
-
- context.commitChanges();
-
- SelectQuery query = new SelectQuery(Artist.class);
- query.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.DESCENDING);
- query.addOrdering(Artist.DATE_OF_BIRTH_PROPERTY, SortOrder.DESCENDING);
-
- List<Artist> list = context.performQuery(query);
- assertEquals(3, list.size());
- assertSame(a2, list.get(0));
- assertSame(a3, list.get(1));
- assertSame(a1, list.get(2));
- }
-
- public void testMultipleOrderingInSelectClauseCAY_1074() throws Exception {
-
- Calendar c = Calendar.getInstance();
-
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("2");
- a1.setDateOfBirth(c.getTime());
-
- c.add(Calendar.DAY_OF_MONTH, -1);
- Artist a2 = context.newObject(Artist.class);
- a2.setArtistName("3");
- a2.setDateOfBirth(c.getTime());
-
- c.add(Calendar.DAY_OF_MONTH, -1);
- Artist a3 = context.newObject(Artist.class);
- a3.setArtistName("3");
- a3.setDateOfBirth(c.getTime());
-
- Painting p1 = context.newObject(Painting.class);
- p1.setEstimatedPrice(new BigDecimal(1));
- p1.setPaintingTitle("Y");
- a1.addToPaintingArray(p1);
-
- Painting p2 = context.newObject(Painting.class);
- p2.setEstimatedPrice(new BigDecimal(2));
- p2.setPaintingTitle("X");
- a2.addToPaintingArray(p2);
-
- context.commitChanges();
-
- SelectQuery query1 = new SelectQuery(Artist.class);
-
- // per CAY-1074, adding a to-many join to expression messes up the ordering
- query1.andQualifier(ExpressionFactory.noMatchExp(
- Artist.PAINTING_ARRAY_PROPERTY,
- null));
- query1.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.DESCENDING);
- query1.addOrdering(Artist.DATE_OF_BIRTH_PROPERTY, SortOrder.DESCENDING);
-
- List<Artist> list1 = context.performQuery(query1);
- assertEquals(2, list1.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
new file mode 100644
index 0000000..a081b86
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
@@ -0,0 +1,190 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SortOrder;
+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.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextOuterJoinsIT extends ServerCase {
+
+ @Inject
+ protected ObjectContext context;
+
+ @Inject
+ protected DBHelper dbHelper;
+
+ protected TableHelper artistHelper;
+ protected TableHelper paintingHelper;
+ protected TableHelper artgroupHelper;
+ protected TableHelper artistGroupHelper;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+
+ artistHelper = new TableHelper(dbHelper, "ARTIST", "ARTIST_ID", "ARTIST_NAME");
+ paintingHelper = new TableHelper(
+ dbHelper,
+ "PAINTING",
+ "PAINTING_ID",
+ "ARTIST_ID",
+ "PAINTING_TITLE").setColumnTypes(
+ Types.INTEGER,
+ Types.BIGINT,
+ Types.VARCHAR);
+
+ artgroupHelper = new TableHelper(dbHelper, "ARTGROUP", "GROUP_ID", "NAME");
+ artistGroupHelper = new TableHelper(
+ dbHelper,
+ "ARTIST_GROUP",
+ "GROUP_ID",
+ "ARTIST_ID");
+
+ artistGroupHelper.deleteAll();
+ dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
+ artgroupHelper.deleteAll();
+ paintingHelper.deleteAll();
+ artistHelper.deleteAll();
+ }
+
+ public void testSelectWithOuterJoinFlattened() throws Exception {
+
+ artistHelper.insert(33001, "AA1");
+ artistHelper.insert(33002, "AA2");
+ artistHelper.insert(33003, "BB1");
+ artistHelper.insert(33004, "BB2");
+
+ artgroupHelper.insert(1, "G1");
+
+ artistGroupHelper.insert(1, 33001);
+ artistGroupHelper.insert(1, 33002);
+ artistGroupHelper.insert(1, 33004);
+
+ SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
+ missingToManyQuery.andQualifier(ExpressionFactory.matchExp(
+ Artist.GROUP_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
+ null));
+ missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+ List<Artist> artists = context.performQuery(missingToManyQuery);
+ assertEquals(1, artists.size());
+ assertEquals("BB1", artists.get(0).getArtistName());
+ }
+
+ public void testSelectWithOuterJoin() throws Exception {
+
+ artistHelper.insert(33001, "AA1");
+ artistHelper.insert(33002, "AA2");
+ artistHelper.insert(33003, "BB1");
+ artistHelper.insert(33004, "BB2");
+
+ paintingHelper.insert(33001, 33001, "P1");
+ paintingHelper.insert(33002, 33002, "P2");
+
+ SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
+ missingToManyQuery.andQualifier(ExpressionFactory.matchExp(
+ Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
+ null));
+ missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+ List<Artist> artists = context.performQuery(missingToManyQuery);
+ assertEquals(2, artists.size());
+ assertEquals("BB1", artists.get(0).getArtistName());
+
+ SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
+ mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(
+ Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
+ null));
+ mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(
+ Artist.ARTIST_NAME_PROPERTY,
+ "AA1"));
+ mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+ artists = context.performQuery(mixedConditionQuery);
+ assertEquals(3, artists.size());
+ assertEquals("AA1", artists.get(0).getArtistName());
+ assertEquals("BB1", artists.get(1).getArtistName());
+ assertEquals("BB2", artists.get(2).getArtistName());
+ }
+
+ public void testSelectWithOuterJoinFromString() throws Exception {
+
+ artistHelper.insert(33001, "AA1");
+ artistHelper.insert(33002, "AA2");
+ artistHelper.insert(33003, "BB1");
+ artistHelper.insert(33004, "BB2");
+
+ paintingHelper.insert(33001, 33001, "P1");
+ paintingHelper.insert(33002, 33002, "P2");
+
+ SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
+ missingToManyQuery.andQualifier(Expression.fromString("paintingArray+ = null"));
+ missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+ List<Artist> artists = context.performQuery(missingToManyQuery);
+ assertEquals(2, artists.size());
+ assertEquals("BB1", artists.get(0).getArtistName());
+
+ SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
+ mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(
+ Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
+ null));
+ mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(
+ Artist.ARTIST_NAME_PROPERTY,
+ "AA1"));
+ mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
+
+ artists = context.performQuery(mixedConditionQuery);
+ assertEquals(3, artists.size());
+ assertEquals("AA1", artists.get(0).getArtistName());
+ assertEquals("BB1", artists.get(1).getArtistName());
+ assertEquals("BB2", artists.get(2).getArtistName());
+ }
+
+ public void testSelectWithOuterOrdering() throws Exception {
+
+ artistHelper.insert(33001, "AA1");
+ artistHelper.insert(33002, "AA2");
+
+ paintingHelper.insert(33001, 33001, "P1");
+ paintingHelper.insert(33002, 33002, "P2");
+ paintingHelper.insert(33003, null, "P3");
+
+ SelectQuery query = new SelectQuery(Painting.class);
+
+ query.addOrdering("toArtist+.artistName", SortOrder.DESCENDING);
+
+ List<Artist> paintings = context.performQuery(query);
+ assertEquals(3, paintings.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java
deleted file mode 100644
index ab7b881..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsTest.java
+++ /dev/null
@@ -1,190 +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.access;
-
-import java.util.List;
-import java.sql.Types;
-
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.map.Entity;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.SortOrder;
-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.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DataContextOuterJoinsTest extends ServerCase {
-
- @Inject
- protected ObjectContext context;
-
- @Inject
- protected DBHelper dbHelper;
-
- protected TableHelper artistHelper;
- protected TableHelper paintingHelper;
- protected TableHelper artgroupHelper;
- protected TableHelper artistGroupHelper;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
-
- artistHelper = new TableHelper(dbHelper, "ARTIST", "ARTIST_ID", "ARTIST_NAME");
- paintingHelper = new TableHelper(
- dbHelper,
- "PAINTING",
- "PAINTING_ID",
- "ARTIST_ID",
- "PAINTING_TITLE").setColumnTypes(
- Types.INTEGER,
- Types.BIGINT,
- Types.VARCHAR);
-
- artgroupHelper = new TableHelper(dbHelper, "ARTGROUP", "GROUP_ID", "NAME");
- artistGroupHelper = new TableHelper(
- dbHelper,
- "ARTIST_GROUP",
- "GROUP_ID",
- "ARTIST_ID");
-
- artistGroupHelper.deleteAll();
- dbHelper.update("ARTGROUP").set("PARENT_GROUP_ID", null, Types.INTEGER).execute();
- artgroupHelper.deleteAll();
- paintingHelper.deleteAll();
- artistHelper.deleteAll();
- }
-
- public void testSelectWithOuterJoinFlattened() throws Exception {
-
- artistHelper.insert(33001, "AA1");
- artistHelper.insert(33002, "AA2");
- artistHelper.insert(33003, "BB1");
- artistHelper.insert(33004, "BB2");
-
- artgroupHelper.insert(1, "G1");
-
- artistGroupHelper.insert(1, 33001);
- artistGroupHelper.insert(1, 33002);
- artistGroupHelper.insert(1, 33004);
-
- SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
- missingToManyQuery.andQualifier(ExpressionFactory.matchExp(
- Artist.GROUP_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
- null));
- missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
- List<Artist> artists = context.performQuery(missingToManyQuery);
- assertEquals(1, artists.size());
- assertEquals("BB1", artists.get(0).getArtistName());
- }
-
- public void testSelectWithOuterJoin() throws Exception {
-
- artistHelper.insert(33001, "AA1");
- artistHelper.insert(33002, "AA2");
- artistHelper.insert(33003, "BB1");
- artistHelper.insert(33004, "BB2");
-
- paintingHelper.insert(33001, 33001, "P1");
- paintingHelper.insert(33002, 33002, "P2");
-
- SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
- missingToManyQuery.andQualifier(ExpressionFactory.matchExp(
- Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
- null));
- missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
- List<Artist> artists = context.performQuery(missingToManyQuery);
- assertEquals(2, artists.size());
- assertEquals("BB1", artists.get(0).getArtistName());
-
- SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
- mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(
- Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
- null));
- mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(
- Artist.ARTIST_NAME_PROPERTY,
- "AA1"));
- mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
- artists = context.performQuery(mixedConditionQuery);
- assertEquals(3, artists.size());
- assertEquals("AA1", artists.get(0).getArtistName());
- assertEquals("BB1", artists.get(1).getArtistName());
- assertEquals("BB2", artists.get(2).getArtistName());
- }
-
- public void testSelectWithOuterJoinFromString() throws Exception {
-
- artistHelper.insert(33001, "AA1");
- artistHelper.insert(33002, "AA2");
- artistHelper.insert(33003, "BB1");
- artistHelper.insert(33004, "BB2");
-
- paintingHelper.insert(33001, 33001, "P1");
- paintingHelper.insert(33002, 33002, "P2");
-
- SelectQuery missingToManyQuery = new SelectQuery(Artist.class);
- missingToManyQuery.andQualifier(Expression.fromString("paintingArray+ = null"));
- missingToManyQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
- List<Artist> artists = context.performQuery(missingToManyQuery);
- assertEquals(2, artists.size());
- assertEquals("BB1", artists.get(0).getArtistName());
-
- SelectQuery mixedConditionQuery = new SelectQuery(Artist.class);
- mixedConditionQuery.andQualifier(ExpressionFactory.matchExp(
- Artist.PAINTING_ARRAY_PROPERTY + Entity.OUTER_JOIN_INDICATOR,
- null));
- mixedConditionQuery.orQualifier(ExpressionFactory.matchExp(
- Artist.ARTIST_NAME_PROPERTY,
- "AA1"));
- mixedConditionQuery.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
-
- artists = context.performQuery(mixedConditionQuery);
- assertEquals(3, artists.size());
- assertEquals("AA1", artists.get(0).getArtistName());
- assertEquals("BB1", artists.get(1).getArtistName());
- assertEquals("BB2", artists.get(2).getArtistName());
- }
-
- public void testSelectWithOuterOrdering() throws Exception {
-
- artistHelper.insert(33001, "AA1");
- artistHelper.insert(33002, "AA2");
-
- paintingHelper.insert(33001, 33001, "P1");
- paintingHelper.insert(33002, 33002, "P2");
- paintingHelper.insert(33003, null, "P3");
-
- SelectQuery query = new SelectQuery(Painting.class);
-
- query.addOrdering("toArtist+.artistName", SortOrder.DESCENDING);
-
- List<Artist> paintings = context.performQuery(query);
- assertEquals(3, paintings.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryIT.java
new file mode 100644
index 0000000..4299b02
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryIT.java
@@ -0,0 +1,93 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.QueryCacheStrategy;
+import org.apache.cayenne.query.SelectQuery;
+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 DataContextPaginatedQueryIT extends ServerCase {
+
+ @Inject
+ protected DataContext context;
+
+ @Inject
+ protected DBHelper dbHelper;
+
+ protected TableHelper tArtist;
+
+ @Override
+ public void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST");
+
+ tArtist = new TableHelper(dbHelper, "ARTIST");
+ tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+ }
+
+ protected void createArtistsDataSet() throws Exception {
+ tArtist.insert(33001, "artist1");
+ tArtist.insert(33002, "artist2");
+ tArtist.insert(33003, "artist3");
+ tArtist.insert(33004, "artist4");
+ tArtist.insert(33005, "artist5");
+ tArtist.insert(33006, "artist6");
+ tArtist.insert(33007, "artist7");
+ tArtist.insert(33008, "artist8");
+ tArtist.insert(33009, "artist9");
+ tArtist.insert(33010, "artist10");
+ }
+
+ public void testLocalCache() throws Exception {
+
+ createArtistsDataSet();
+
+ SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
+ query.addOrdering(Artist.ARTIST_NAME.asc());
+ query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+ query.setPageSize(5);
+
+ List<?> results1 = context.performQuery(query);
+ assertNotNull(results1);
+
+ List<?> results2 = context.performQuery(query);
+ assertNotNull(results2);
+ assertSame(results1, results2);
+
+ results1.get(1);
+ List<?> results3 = context.performQuery(query);
+ assertNotNull(results3);
+ assertSame(results1, results3);
+
+ results1.get(7);
+ List<?> results4 = context.performQuery(query);
+ assertNotNull(results4);
+ assertSame(results1, results4);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
deleted file mode 100644
index 2c58fa5..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPaginatedQueryTest.java
+++ /dev/null
@@ -1,93 +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.access;
-
-import java.util.List;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.QueryCacheStrategy;
-import org.apache.cayenne.query.SelectQuery;
-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 DataContextPaginatedQueryTest extends ServerCase {
-
- @Inject
- protected DataContext context;
-
- @Inject
- protected DBHelper dbHelper;
-
- protected TableHelper tArtist;
-
- @Override
- public void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("PAINTING_INFO");
- dbHelper.deleteAll("PAINTING");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST");
-
- tArtist = new TableHelper(dbHelper, "ARTIST");
- tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
- }
-
- protected void createArtistsDataSet() throws Exception {
- tArtist.insert(33001, "artist1");
- tArtist.insert(33002, "artist2");
- tArtist.insert(33003, "artist3");
- tArtist.insert(33004, "artist4");
- tArtist.insert(33005, "artist5");
- tArtist.insert(33006, "artist6");
- tArtist.insert(33007, "artist7");
- tArtist.insert(33008, "artist8");
- tArtist.insert(33009, "artist9");
- tArtist.insert(33010, "artist10");
- }
-
- public void testLocalCache() throws Exception {
-
- createArtistsDataSet();
-
- SelectQuery<Artist> query = new SelectQuery<Artist>(Artist.class);
- query.addOrdering(Artist.ARTIST_NAME.asc());
- query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
- query.setPageSize(5);
-
- List<?> results1 = context.performQuery(query);
- assertNotNull(results1);
-
- List<?> results2 = context.performQuery(query);
- assertNotNull(results2);
- assertSame(results1, results2);
-
- results1.get(1);
- List<?> results3 = context.performQuery(query);
- assertNotNull(results3);
- assertSame(results1, results3);
-
- results1.get(7);
- List<?> results4 = context.performQuery(query);
- assertNotNull(results4);
- assertSame(results1, results4);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPIIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPIIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPIIT.java
new file mode 100644
index 0000000..b6298be
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPIIT.java
@@ -0,0 +1,228 @@
+/*****************************************************************
+ * 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.access;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.query.SQLTemplate;
+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.tx.BaseTransaction;
+import org.apache.cayenne.tx.ExternalTransaction;
+import org.apache.cayenne.tx.Transaction;
+import org.apache.cayenne.unit.UnitDbAdapter;
+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 java.math.BigDecimal;
+import java.sql.Types;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DataContextPerformQueryAPIIT extends ServerCase {
+
+ @Inject
+ private DataContext context;
+
+ @Inject
+ private DataContext context2;
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Inject
+ private UnitDbAdapter accessStackAdapter;
+
+ @Inject
+ private DataChannelInterceptor queryInterceptor;
+
+ @Inject
+ private JdbcEventLogger jdbcEventLogger;
+
+ private TableHelper tArtist;
+ private TableHelper tPainting;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+ dbHelper.deleteAll("GALLERY");
+ dbHelper.deleteAll("EXHIBIT");
+
+ tArtist = new TableHelper(dbHelper, "ARTIST");
+ tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
+
+ tPainting = new TableHelper(dbHelper, "PAINTING");
+ tPainting.setColumns("PAINTING_ID", "ARTIST_ID", "PAINTING_TITLE", "ESTIMATED_PRICE").setColumnTypes(
+ Types.INTEGER, Types.BIGINT, Types.VARCHAR, Types.DECIMAL);
+ }
+
+ private void createTwoArtists() throws Exception {
+ tArtist.insert(21, "artist2");
+ tArtist.insert(201, "artist3");
+ }
+
+ private void createTwoArtistsAndTwoPaintingsDataSet() throws Exception {
+ tArtist.insert(11, "artist2");
+ tArtist.insert(101, "artist3");
+ tPainting.insert(6, 101, "p_artist3", 1000);
+ tPainting.insert(7, 11, "p_artist2", 2000);
+ }
+
+ public void testObjectQueryStringBoolean() throws Exception {
+ createTwoArtistsAndTwoPaintingsDataSet();
+
+ List<?> paintings = context.performQuery("ObjectQuery", true);
+ assertNotNull(paintings);
+ assertEquals(2, paintings.size());
+ }
+
+ public void testObjectQueryStringMapBoolean() throws Exception {
+ createTwoArtistsAndTwoPaintingsDataSet();
+
+ Artist a = Cayenne.objectForPK(context, Artist.class, 11);
+ Map<String, Artist> parameters = Collections.singletonMap("artist", a);
+
+ List<?> paintings = context2.performQuery("ObjectQuery", parameters, true);
+ assertNotNull(paintings);
+ assertEquals(1, paintings.size());
+ }
+
+ public void testProcedureQueryStringMapBoolean() throws Exception {
+
+ if (!accessStackAdapter.supportsStoredProcedures()) {
+ return;
+ }
+
+ if (!accessStackAdapter.canMakeObjectsOutOfProcedures()) {
+ return;
+ }
+
+ createTwoArtistsAndTwoPaintingsDataSet();
+
+ // fetch artist
+ Map<String, String> parameters = Collections.singletonMap("aName", "artist2");
+
+ List<?> artists;
+
+ // Sybase blows whenever a transaction wraps a SP, so turn of
+ // transactions
+ Transaction t = new ExternalTransaction(jdbcEventLogger);
+ BaseTransaction.bindThreadTransaction(t);
+ try {
+ artists = context.performQuery("ProcedureQuery", parameters, true);
+ } finally {
+ BaseTransaction.bindThreadTransaction(null);
+ t.commit();
+ }
+
+ assertNotNull(artists);
+ assertEquals(1, artists.size());
+
+ Artist artist = (Artist) artists.get(0);
+ assertEquals(11, ((Number) artist.getObjectId().getIdSnapshot().get(Artist.ARTIST_ID_PK_COLUMN)).intValue());
+ }
+
+ public void testNonSelectingQueryString() throws Exception {
+
+ int[] counts = context.performNonSelectingQuery("NonSelectingQuery");
+
+ assertNotNull(counts);
+ assertEquals(1, counts.length);
+ assertEquals(1, counts[0]);
+
+ Painting p = Cayenne.objectForPK(context, Painting.class, 512);
+ assertEquals("No Painting Like This", p.getPaintingTitle());
+ }
+
+ public void testNonSelectingQueryStringMap() throws Exception {
+
+ Map<String, Object> parameters = new HashMap<String, Object>();
+ parameters.put("id", 300);
+ parameters.put("title", "Go Figure");
+ parameters.put("price", new BigDecimal("22.01"));
+
+ int[] counts = context.performNonSelectingQuery("ParameterizedNonSelectingQuery", parameters);
+
+ assertNotNull(counts);
+ assertEquals(1, counts.length);
+ assertEquals(1, counts[0]);
+
+ Painting p = Cayenne.objectForPK(context, Painting.class, 300);
+ assertEquals("Go Figure", p.getPaintingTitle());
+ }
+
+ public void testPerfomQueryNonSelecting() throws Exception {
+
+ Artist a = context.newObject(Artist.class);
+ a.setArtistName("aa");
+ context.commitChanges();
+
+ SQLTemplate q = new SQLTemplate(Artist.class, "DELETE FROM ARTIST");
+
+ // this way of executing a query makes no sense, but it shouldn't blow
+ // either...
+ List<?> result = context.performQuery(q);
+
+ assertNotNull(result);
+ assertEquals(0, result.size());
+ }
+
+ public void testObjectQueryWithLocalCache() throws Exception {
+ createTwoArtists();
+
+ List<?> artists = context.performQuery("QueryWithLocalCache", true);
+ assertEquals(2, artists.size());
+
+ queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+ List<?> artists1 = context.performQuery("QueryWithLocalCache", false);
+ assertEquals(2, artists1.size());
+ }
+ });
+ }
+
+ public void testObjectQueryWithSharedCache() throws Exception {
+ createTwoArtists();
+
+ List<?> artists = context.performQuery("QueryWithSharedCache", true);
+ assertEquals(2, artists.size());
+
+ queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+ public void execute() {
+ List<?> artists1 = context2.performQuery("QueryWithSharedCache", false);
+ assertEquals(2, artists1.size());
+ }
+ });
+ }
+}