Repository: cayenne Updated Branches: refs/heads/master bf97267a0 -> eec08b7ef
Cleanup warnings Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/eec08b7e Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/eec08b7e Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/eec08b7e Branch: refs/heads/master Commit: eec08b7effe3f5a88150597d4412d3056913822a Parents: bf97267 Author: Nikita Timofeev <stari...@gmail.com> Authored: Tue Dec 12 15:51:27 2017 +0300 Committer: Nikita Timofeev <stari...@gmail.com> Committed: Tue Dec 12 15:51:27 2017 +0300 ---------------------------------------------------------------------- .../CayenneContextMapRelationshipIT.java | 8 +- .../unit/di/client/ClientCaseProperties.java | 2 +- .../commitlog/CommitLogModuleExtender.java | 2 - .../value/DefaultValueDecryptor.java | 1 + .../cayenne/lifecycle/id/StringIdQueryTest.java | 16 +- .../org/apache/cayenne/access/DataContext.java | 4 +- .../cayenne/access/IncrementalFaultList.java | 5 +- .../apache/cayenne/graph/ChildDiffLoader.java | 2 +- .../org/apache/cayenne/query/SelectQuery.java | 14 +- .../cayenne/remote/IncrementalSelectQuery.java | 1 + .../cayenne/access/DataContextNoPkIT.java | 13 +- .../access/DataContextQueryCachingIT.java | 7 +- .../org/apache/cayenne/access/EmbeddingIT.java | 9 +- .../apache/cayenne/access/JointPrefetchIT.java | 339 +++++++------------ .../SimpleIdIncrementalFaultListDataRowsIT.java | 5 +- .../configuration/web/WebConfiguration.java | 13 +- .../apache/cayenne/wocompat/EOQueryTest.java | 7 +- 17 files changed, 179 insertions(+), 269 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipIT.java ---------------------------------------------------------------------- diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipIT.java index a7273fc..ce3b59f 100644 --- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipIT.java +++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipIT.java @@ -80,9 +80,9 @@ public class CayenneContextMapRelationshipIT extends ClientCase { assertNotNull(targets); assertEquals(3, targets.size()); - assertNotNull(targets.get(new Integer(1))); - assertNotNull(targets.get(new Integer(2))); - assertNotNull(targets.get(new Integer(3))); + assertNotNull(targets.get(1)); + assertNotNull(targets.get(2)); + assertNotNull(targets.get(3)); } @Test @@ -111,7 +111,7 @@ public class CayenneContextMapRelationshipIT extends ClientCase { assertEquals(4, o1.getTargets().size()); int newId = Cayenne.intPKForObject(newTarget); - assertSame(newTarget, o1.getTargets().get(new Integer(newId))); + assertSame(newTarget, o1.getTargets().get(newId)); assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState()); assertEquals(PersistenceState.COMMITTED, newTarget.getPersistenceState()); http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-client/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java ---------------------------------------------------------------------- diff --git a/cayenne-client/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java b/cayenne-client/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java index d782dc3..57f4f9d 100644 --- a/cayenne-client/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java +++ b/cayenne-client/src/test/java/org/apache/cayenne/unit/di/client/ClientCaseProperties.java @@ -26,7 +26,7 @@ public class ClientCaseProperties { protected Map<String, String> runtimeProperties; Map<String, String> getRuntimeProperties() { - return runtimeProperties != null ? runtimeProperties : Collections.EMPTY_MAP; + return runtimeProperties != null ? runtimeProperties : Collections.emptyMap(); } void setRuntimeProperties(Map<String, String> runtimeProperties) { http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-commitlog/src/main/java/org/apache/cayenne/commitlog/CommitLogModuleExtender.java ---------------------------------------------------------------------- diff --git a/cayenne-commitlog/src/main/java/org/apache/cayenne/commitlog/CommitLogModuleExtender.java b/cayenne-commitlog/src/main/java/org/apache/cayenne/commitlog/CommitLogModuleExtender.java index 9794016..558dcba 100644 --- a/cayenne-commitlog/src/main/java/org/apache/cayenne/commitlog/CommitLogModuleExtender.java +++ b/cayenne-commitlog/src/main/java/org/apache/cayenne/commitlog/CommitLogModuleExtender.java @@ -111,8 +111,6 @@ public class CommitLogModuleExtender { // types have to be added one-by-one for (Class<? extends CommitLogListener> type : listenerTypes) { - // TODO: temp hack - need to bind each type before adding to collection... - binder.bind(type).to((Class) type); listeners.add(type); } http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueDecryptor.java ---------------------------------------------------------------------- diff --git a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueDecryptor.java b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueDecryptor.java index 4a7e087..a513cfd 100644 --- a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueDecryptor.java +++ b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueDecryptor.java @@ -48,6 +48,7 @@ class DefaultValueDecryptor implements ValueDecryptor { @Override public Object decrypt(BytesDecryptor bytesDecryptor, Object value) { + @SuppressWarnings("unchecked") byte[] bytes = preConverter.toBytes(value); // 'defaultKey' is likely to be ignored by the BytesDecryptor, as the http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/id/StringIdQueryTest.java ---------------------------------------------------------------------- diff --git a/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/id/StringIdQueryTest.java b/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/id/StringIdQueryTest.java index a54964e..669a0ad 100644 --- a/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/id/StringIdQueryTest.java +++ b/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/id/StringIdQueryTest.java @@ -38,20 +38,19 @@ import static org.junit.Assert.assertTrue; public class StringIdQueryTest { private ServerRuntime runtime; - private DBHelper dbHelper; private TableHelper e1Helper; private TableHelper e2Helper; @Before - public void setUp() throws Exception { + public void setUp() { runtime = ServerRuntime.builder().addConfig("cayenne-lifecycle.xml").build(); - dbHelper = new DBHelper(runtime.getDataSource("lifecycle-db")); + DBHelper dbHelper = new DBHelper(runtime.getDataSource("lifecycle-db")); e1Helper = new TableHelper(dbHelper, "E1", "ID"); e2Helper = new TableHelper(dbHelper, "E2", "ID"); } @After - public void tearDown() throws Exception { + public void tearDown() { runtime.shutdown(); } @@ -83,7 +82,7 @@ public class StringIdQueryTest { assertEquals(1, response.size()); assertEquals(2, response.firstList().size()); - Set<Number> ids = new HashSet<Number>(); + Set<Number> ids = new HashSet<>(); DataRow r1 = (DataRow) response.firstList().get(0); ids.add((Number) r1.get("ID")); @@ -91,8 +90,8 @@ public class StringIdQueryTest { DataRow r2 = (DataRow) response.firstList().get(1); ids.add((Number) r2.get("ID")); - assertTrue(ids.contains(3l)); - assertTrue(ids.contains(4l)); + assertTrue(ids.contains(3L)); + assertTrue(ids.contains(4L)); } @Test @@ -107,9 +106,10 @@ public class StringIdQueryTest { QueryResponse response = runtime.newContext().performGenericQuery(query); assertEquals(2, response.size()); - Set<String> ids = new HashSet<String>(); + Set<String> ids = new HashSet<>(); while (response.next()) { + @SuppressWarnings("unchecked") List<DataRow> list = (List<DataRow>) response.currentList(); for (DataRow row : list) { ids.add(row.getEntityName() + ":" + row.get("ID")); http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java b/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java index f0b580d..27460d2 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java @@ -863,7 +863,7 @@ public class DataContext extends BaseContext { Transaction tx = getTransactionFactory().createTransaction(); BaseTransaction.bindThreadTransaction(tx); - ResultIterator result; + ResultIterator<?> result; try { result = internalPerformIteratedQuery(query); } catch (Exception e) { @@ -889,7 +889,7 @@ public class DataContext extends BaseContext { } } - return new TransactionResultIteratorDecorator(result, tx); + return new TransactionResultIteratorDecorator<>(result, tx); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java b/cayenne-server/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java index 0611514..2d2cca0 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java @@ -118,7 +118,7 @@ public class IncrementalFaultList<E> implements List<E>, Serializable { // create an internal query, it is a partial replica of // the original query and will serve as a value holder for // various parameters - this.internalQuery = new SelectQuery<Object>(rootEntity); + this.internalQuery = new SelectQuery<>(rootEntity); this.internalQuery.setFetchingDataRows(metadata.isFetchingDataRows()); this.internalQuery.setPrefetchTree(metadata.getPrefetchTree()); @@ -265,8 +265,7 @@ public class IncrementalFaultList<E> implements List<E>, Serializable { } SelectQuery<Object> createSelectQuery(List<Expression> expressions) { - SelectQuery<Object> query = new SelectQuery<>(rootEntity, - ExpressionFactory.joinExp(Expression.OR, expressions)); + SelectQuery<Object> query = new SelectQuery<>(rootEntity, ExpressionFactory.joinExp(Expression.OR, expressions)); query.setFetchingDataRows(internalQuery.isFetchingDataRows()); if (!query.isFetchingDataRows()) { http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/main/java/org/apache/cayenne/graph/ChildDiffLoader.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/graph/ChildDiffLoader.java b/cayenne-server/src/main/java/org/apache/cayenne/graph/ChildDiffLoader.java index 2bfc307..4777fd3 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/graph/ChildDiffLoader.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/graph/ChildDiffLoader.java @@ -102,7 +102,7 @@ public class ChildDiffLoader implements GraphChangeHandler { throw new IllegalArgumentException("Entity not mapped with Cayenne: " + id); } - Persistent dataObject = null; + Persistent dataObject; try { dataObject = (Persistent) entity.getJavaClass().newInstance(); } catch (Exception ex) { http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java index da8b83d..405ef2b 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java @@ -89,7 +89,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, * @since 4.0 */ public static <T> SelectQuery<T> query(Class<T> rootClass) { - return new SelectQuery<T>(rootClass); + return new SelectQuery<>(rootClass); } /** @@ -104,7 +104,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, * @since 4.0 */ public static <T> SelectQuery<T> query(Class<T> rootClass, Expression qualifier) { - return new SelectQuery<T>(rootClass, qualifier); + return new SelectQuery<>(rootClass, qualifier); } /** @@ -121,7 +121,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, * @since 4.0 */ public static <T> SelectQuery<T> query(Class<T> rootClass, Expression qualifier, List<? extends Ordering> orderings) { - return new SelectQuery<T>(rootClass, qualifier, orderings); + return new SelectQuery<>(rootClass, qualifier, orderings); } /** @@ -129,7 +129,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, */ public static SelectQuery<DataRow> dataRowQuery(Class<?> rootClass) { // create a query replica that would fetch DataRows - SelectQuery<DataRow> query = new SelectQuery<DataRow>(); + SelectQuery<DataRow> query = new SelectQuery<>(); query.setRoot(rootClass); query.metaData.setFetchingDataRows(true); @@ -347,7 +347,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, @Override public void iterate(ObjectContext context, ResultIteratorCallback<T> callback) { - context.iterate((Select<T>) this, callback); + context.iterate(this, callback); } @Override @@ -451,7 +451,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, */ public SelectQuery<T> queryWithParameters(Map<String, ?> parameters, boolean pruneMissing) { // create a query replica - SelectQuery<T> query = new SelectQuery<T>(); + SelectQuery<T> query = new SelectQuery<>(); query.setDistinct(distinct); query.metaData.copyFromInfo(this.metaData); @@ -522,7 +522,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, * Returns a list of orderings used by this query. */ public List<Ordering> getOrderings() { - return (orderings != null) ? orderings : Collections.<Ordering> emptyList(); + return (orderings != null) ? orderings : Collections.emptyList(); } /** http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java b/cayenne-server/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java index daca4f8..9b6f563 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java @@ -232,6 +232,7 @@ class IncrementalSelectQuery<T> extends SelectQuery<T> { query.setDistinct(distinct); } + @SuppressWarnings("deprecation") @Override public void setFetchingDataRows(boolean flag) { query.setFetchingDataRows(flag); http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/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 index 1fc1cc3..e2a2e1c 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java @@ -20,6 +20,7 @@ package org.apache.cayenne.access; import org.apache.cayenne.CayenneRuntimeException; +import org.apache.cayenne.DataRow; import org.apache.cayenne.ObjectContext; import org.apache.cayenne.di.Inject; import org.apache.cayenne.query.SelectQuery; @@ -33,7 +34,6 @@ import org.junit.Before; import org.junit.Test; import java.util.List; -import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -61,7 +61,7 @@ public class DataContextNoPkIT extends ServerCase { @Test public void testNoPkFetchObjects() throws Exception { try { - List objects = context.performQuery(new SelectQuery(NoPkTestEntity.class)); + 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."); @@ -73,15 +73,14 @@ public class DataContextNoPkIT extends ServerCase { @Test public void testNoPkFetchDataRows() throws Exception { - SelectQuery query = new SelectQuery(NoPkTestEntity.class); - query.setFetchingDataRows(true); + SelectQuery<DataRow> query = SelectQuery.dataRowQuery(NoPkTestEntity.class); - List rows = context.performQuery(query); + List<DataRow> rows = query.select(context); assertNotNull(rows); assertEquals(2, rows.size()); - Map row1 = (Map) rows.get(0); - Map row2 = (Map) rows.get(1); + DataRow row1 = rows.get(0); + DataRow row2 = rows.get(1); // assert that rows have different values // (there was a bug earlier that fetched distinct rows for http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java index bc44e44..64f0832 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java @@ -102,8 +102,7 @@ public class DataContextQueryCachingIT extends ServerCase { @Test public void testLocalCacheDataRowsRefresh() throws Exception { - SelectQuery<Artist> select = new SelectQuery<>(Artist.class); - select.setFetchingDataRows(true); + SelectQuery<DataRow> select = SelectQuery.dataRowQuery(Artist.class); select.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE); MockDataNode engine = MockDataNode.interceptNode(domain, getNode()); @@ -142,8 +141,7 @@ public class DataContextQueryCachingIT extends ServerCase { @Test public void testSharedCacheDataRowsRefresh() throws Exception { - SelectQuery<Artist> select = new SelectQuery<>(Artist.class); - select.setFetchingDataRows(true); + SelectQuery<DataRow> select = SelectQuery.dataRowQuery(Artist.class); select.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE); MockDataNode engine = MockDataNode.interceptNode(domain, getNode()); @@ -185,7 +183,6 @@ public class DataContextQueryCachingIT extends ServerCase { public void testLocalCacheDataObjectsRefresh() throws Exception { SelectQuery<Artist> select = new SelectQuery<>(Artist.class); - select.setFetchingDataRows(false); select.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE); MockDataNode engine = MockDataNode.interceptNode(domain, getNode()); http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java index 1486d33..9675a0c 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java @@ -71,7 +71,7 @@ public class EmbeddingIT extends ServerCase { public void testSelect() throws Exception { createSelectDataSet(); - SelectQuery query = new SelectQuery(EmbedEntity1.class); + SelectQuery query = new SelectQuery<>(EmbedEntity1.class); query.addOrdering(EmbedEntity1.NAME.asc()); List<?> results = context.performQuery(query); @@ -139,7 +139,7 @@ public class EmbeddingIT extends ServerCase { public void testUpdateEmbeddedProperties() throws Exception { createUpdateDataSet(); - SelectQuery query = new SelectQuery(EmbedEntity1.class); + SelectQuery query = new SelectQuery<>(EmbedEntity1.class); query.addOrdering(EmbedEntity1.NAME.asc()); List<?> results = context.performQuery(query); @@ -151,8 +151,7 @@ public class EmbeddingIT extends ServerCase { assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState()); context.commitChanges(); - SelectQuery query1 = new SelectQuery(EmbedEntity1.class); - query1.setFetchingDataRows(true); + SelectQuery<DataRow> query1 = SelectQuery.dataRowQuery(EmbedEntity1.class); DataRow row = (DataRow) Cayenne.objectForQuery(context, query1); assertNotNull(row); assertEquals("x1", row.get("EMBEDDED10")); @@ -162,7 +161,7 @@ public class EmbeddingIT extends ServerCase { public void testUpdateEmbedded() throws Exception { createUpdateDataSet(); - SelectQuery query = new SelectQuery(EmbedEntity1.class); + SelectQuery query = new SelectQuery<>(EmbedEntity1.class); query.addOrdering(EmbedEntity1.NAME.asc()); List<?> results = context.performQuery(query); http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java index f86f5a5..87689b5 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java @@ -23,7 +23,6 @@ import org.apache.cayenne.DataObject; import org.apache.cayenne.DataRow; import org.apache.cayenne.ObjectId; import org.apache.cayenne.PersistenceState; -import org.apache.cayenne.Persistent; import org.apache.cayenne.ValueHolder; import org.apache.cayenne.configuration.server.ServerRuntime; import org.apache.cayenne.di.Inject; @@ -39,7 +38,6 @@ import org.apache.cayenne.testdo.testmap.Artist; import org.apache.cayenne.testdo.testmap.Gallery; 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.CayenneProjects; import org.apache.cayenne.unit.di.server.ServerCase; import org.apache.cayenne.unit.di.server.UseServerRuntime; @@ -50,7 +48,6 @@ import java.sql.Date; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -95,18 +92,7 @@ public class JointPrefetchIT extends ServerCase { "GALLERY_ID"); } - protected void createJointPrefetchDataSet1() throws Exception { - tGallery.insert(33001, "G1"); - tGallery.insert(33002, "G2"); - tArtist.insert(33001, "artist1"); - tArtist.insert(33002, "artist2"); - tArtist.insert(33003, "artist3"); - tPainting.insert(33001, "P_artist11", 33001, 1000, 33001); - tPainting.insert(33002, "P_artist12", 33001, 2000, 33001); - tPainting.insert(33003, "P_artist21", 33002, 3000, 33002); - } - - protected void createJointPrefetchDataSet2() throws Exception { + protected void createJointPrefetchDataSet() throws Exception { tGallery.insert(33001, "G1"); tGallery.insert(33002, "G2"); tArtist.insert(33001, "artist1"); @@ -119,59 +105,49 @@ public class JointPrefetchIT extends ServerCase { @Test public void testJointPrefetch_ToOne_FetchLimit() throws Exception { - createJointPrefetchDataSet1(); + createJointPrefetchDataSet(); - SelectQuery q = new SelectQuery(Painting.class); + SelectQuery<Painting> q = new SelectQuery<>(Painting.class); q.setFetchLimit(2); q.setFetchOffset(0); q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING); q.addPrefetch(Painting.TO_ARTIST.joint()); - final List<?> objects = context.performQuery(q); + final List<Painting> objects = q.select(context); - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { + queryInterceptor.runWithQueriesBlocked(() -> { + assertEquals(2, objects.size()); - public void execute() { - assertEquals(2, objects.size()); - - Iterator<?> it = objects.iterator(); - while (it.hasNext()) { - Painting p = (Painting) it.next(); - Artist target = p.getToArtist(); - assertNotNull(target); - assertEquals(PersistenceState.COMMITTED, target.getPersistenceState()); - } + for (Painting p : objects) { + Artist target = p.getToArtist(); + assertNotNull(target); + assertEquals(PersistenceState.COMMITTED, target.getPersistenceState()); } }); } @Test public void testJointPrefetch_ToMany_FetchLimit() throws Exception { - createJointPrefetchDataSet1(); + createJointPrefetchDataSet(); - SelectQuery q = new SelectQuery(Artist.class); + SelectQuery<Artist> q = new SelectQuery<>(Artist.class); q.setFetchLimit(2); q.setFetchOffset(0); q.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING); q.addPrefetch(Artist.PAINTING_ARRAY.joint()); - final List<?> objects = context.performQuery(q); + final List<Artist> objects = q.select(context); - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { + queryInterceptor.runWithQueriesBlocked(() -> { + // herein lies the limitation of prefetching combined with fetch limit - + // we got fewer artists than we wanted + assertEquals(1, objects.size()); - public void execute() { - // herein lies the limitation of prefetching combined with fetch limit - - // we got fewer artists than we wanted - assertEquals(1, objects.size()); - - Iterator<?> it = objects.iterator(); - while (it.hasNext()) { - Artist a = (Artist) it.next(); - List<Painting> targets = a.getPaintingArray(); - assertNotNull(targets); - for (Painting p : targets) { - assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); - } + for (Artist a : objects) { + List<Painting> targets = a.getPaintingArray(); + assertNotNull(targets); + for (Painting p : targets) { + assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); } } }); @@ -179,56 +155,39 @@ public class JointPrefetchIT extends ServerCase { @Test public void testJointPrefetchDataRows() throws Exception { - createJointPrefetchDataSet1(); + createJointPrefetchDataSet(); // query with to-many joint prefetches - SelectQuery q = new SelectQuery(Painting.class); + SelectQuery<DataRow> q = SelectQuery.dataRowQuery(Painting.class); q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING); - q.setFetchingDataRows(true); q.addPrefetch(Painting.TO_ARTIST.joint()); - final List<?> rows = context.performQuery(q); - - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { - - public void execute() { - assertEquals(3, rows.size()); - - // row should contain columns from both entities minus those duplicated in - // a - // join... - - int rowWidth = context - .getEntityResolver() - .getDbEntity("ARTIST") - .getAttributes() - .size() - + context - .getEntityResolver() - .getDbEntity("PAINTING") - .getAttributes() - .size(); - Iterator<?> it = rows.iterator(); - while (it.hasNext()) { - DataRow row = (DataRow) it.next(); - assertEquals("" + row, rowWidth, row.size()); - - // assert columns presence - assertTrue(row + "", row.containsKey("PAINTING_ID")); - assertTrue(row + "", row.containsKey("ARTIST_ID")); - assertTrue(row + "", row.containsKey("GALLERY_ID")); - assertTrue(row + "", row.containsKey("PAINTING_TITLE")); - assertTrue(row + "", row.containsKey("ESTIMATED_PRICE")); - assertTrue(row + "", row.containsKey("toArtist.ARTIST_NAME")); - assertTrue(row + "", row.containsKey("toArtist.DATE_OF_BIRTH")); - } + final List<DataRow> rows = q.select(context); + + queryInterceptor.runWithQueriesBlocked(() -> { + assertEquals(3, rows.size()); + + // row should contain columns from both entities minus those duplicated in a join... + int rowWidth = context.getEntityResolver().getDbEntity("ARTIST").getAttributes().size() + + context.getEntityResolver().getDbEntity("PAINTING").getAttributes().size(); + for (DataRow row : rows) { + assertEquals("" + row, rowWidth, row.size()); + + // assert columns presence + assertTrue(row + "", row.containsKey("PAINTING_ID")); + assertTrue(row + "", row.containsKey("ARTIST_ID")); + assertTrue(row + "", row.containsKey("GALLERY_ID")); + assertTrue(row + "", row.containsKey("PAINTING_TITLE")); + assertTrue(row + "", row.containsKey("ESTIMATED_PRICE")); + assertTrue(row + "", row.containsKey("toArtist.ARTIST_NAME")); + assertTrue(row + "", row.containsKey("toArtist.DATE_OF_BIRTH")); } }); } @Test public void testJointPrefetchSQLTemplate() throws Exception { - createJointPrefetchDataSet1(); + createJointPrefetchDataSet(); // correctly naming columns is the key.. SQLTemplate q = new SQLTemplate( @@ -247,31 +206,24 @@ public class JointPrefetchIT extends ServerCase { q.addPrefetch(Artist.PAINTING_ARRAY.joint()); q.setFetchingDataRows(false); - final List<?> objects = context.performQuery(q); + @SuppressWarnings("unchecked") + final List<Artist> objects = (List<Artist>)context.performQuery(q); - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { + queryInterceptor.runWithQueriesBlocked(() -> { + // without OUTER join we will get fewer objects... + assertEquals(2, objects.size()); - public void execute() { - // without OUTER join we will get fewer objects... - assertEquals(2, objects.size()); + for (Artist a : objects) { + List<Painting> list = a.getPaintingArray(); - Iterator<?> it = objects.iterator(); - while (it.hasNext()) { - Artist a = (Artist) it.next(); - List<?> list = a.getPaintingArray(); - - assertNotNull(list); - assertFalse(((ValueHolder) list).isFault()); - assertTrue(list.size() > 0); - - Iterator<?> children = list.iterator(); - while (children.hasNext()) { - Painting p = (Painting) children.next(); - assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); + assertNotNull(list); + assertFalse(((ValueHolder) list).isFault()); + assertTrue(list.size() > 0); - // make sure properties are not null.. - assertNotNull(p.getPaintingTitle()); - } + for (Painting p : list) { + assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); + // make sure properties are not null.. + assertNotNull(p.getPaintingTitle()); } } }); @@ -279,27 +231,21 @@ public class JointPrefetchIT extends ServerCase { @Test public void testJointPrefetchToOne() throws Exception { - createJointPrefetchDataSet1(); + createJointPrefetchDataSet(); // query with to-many joint prefetches - SelectQuery q = new SelectQuery(Painting.class); + SelectQuery<Painting> q = new SelectQuery<>(Painting.class); q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING); q.addPrefetch(Painting.TO_ARTIST.joint()); - final List<?> objects = context.performQuery(q); - - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { - - public void execute() { - assertEquals(3, objects.size()); + final List<Painting> objects = q.select(context); - Iterator<?> it = objects.iterator(); - while (it.hasNext()) { - Painting p = (Painting) it.next(); - Artist target = p.getToArtist(); - assertNotNull(target); - assertEquals(PersistenceState.COMMITTED, target.getPersistenceState()); - } + queryInterceptor.runWithQueriesBlocked(() -> { + assertEquals(3, objects.size()); + for (Painting p : objects) { + Artist target = p.getToArtist(); + assertNotNull(target); + assertEquals(PersistenceState.COMMITTED, target.getPersistenceState()); } }); } @@ -308,7 +254,7 @@ public class JointPrefetchIT extends ServerCase { * Tests that joined entities can have non-standard type mappings. */ @Test - public void testJointPrefetchDataTypes() throws Exception { + public void testJointPrefetchDataTypes() { // prepare... can't load from XML, as it doesn't yet support dates.. SQLTemplate artistSQL = new SQLTemplate( Artist.class, @@ -326,7 +272,7 @@ public class JointPrefetchIT extends ServerCase { context.performNonSelectingQuery(paintingSQL); // test - SelectQuery q = new SelectQuery(Painting.class); + SelectQuery<Painting> q = new SelectQuery<>(Painting.class); q.addPrefetch(Painting.TO_ARTIST.joint()); ObjEntity artistE = context.getEntityResolver().getObjEntity("Artist"); @@ -334,60 +280,45 @@ public class JointPrefetchIT extends ServerCase { assertEquals("java.util.Date", dateOfBirth.getType()); dateOfBirth.setType("java.sql.Date"); try { - final List<?> objects = context.performQuery(q); - - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { - - public void execute() { - assertEquals(1, objects.size()); - - Iterator<?> it = objects.iterator(); - while (it.hasNext()) { - Painting p = (Painting) it.next(); - Artist a = p.getToArtist(); - assertNotNull(a); - assertNotNull(a.getDateOfBirth()); - assertTrue(a.getDateOfBirth().getClass().getName(), Date.class - .isAssignableFrom(a.getDateOfBirth().getClass())); - } + final List<Painting> objects = q.select(context); + + queryInterceptor.runWithQueriesBlocked(() -> { + assertEquals(1, objects.size()); + for (Painting p : objects) { + Artist a = p.getToArtist(); + assertNotNull(a); + assertNotNull(a.getDateOfBirth()); + assertTrue(a.getDateOfBirth().getClass().getName(), Date.class.isAssignableFrom(a.getDateOfBirth().getClass())); } }); - } - finally { + } finally { dateOfBirth.setType("java.util.Date"); } } @Test public void testJointPrefetchToMany() throws Exception { - createJointPrefetchDataSet1(); + createJointPrefetchDataSet(); // query with to-many joint prefetches - SelectQuery q = new SelectQuery(Artist.class); + SelectQuery<Artist> q = new SelectQuery<>(Artist.class); q.addPrefetch(Artist.PAINTING_ARRAY.joint()); - final List<?> objects = context.performQuery(q); - - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { + final List<Artist> objects = q.select(context); - public void execute() { - assertEquals(3, objects.size()); + queryInterceptor.runWithQueriesBlocked(() -> { + assertEquals(3, objects.size()); - Iterator<?> it = objects.iterator(); - while (it.hasNext()) { - Artist a = (Artist) it.next(); - List<?> list = a.getPaintingArray(); + for (Artist a : objects) { + List<Painting> list = a.getPaintingArray(); - assertNotNull(list); - assertFalse(((ValueHolder) list).isFault()); + assertNotNull(list); + assertFalse(((ValueHolder) list).isFault()); - Iterator<?> children = list.iterator(); - while (children.hasNext()) { - Painting p = (Painting) children.next(); - assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); - // make sure properties are not null.. - assertNotNull(p.getPaintingTitle()); - } + for (Painting p : list) { + assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); + // make sure properties are not null.. + assertNotNull(p.getPaintingTitle()); } } }); @@ -395,46 +326,41 @@ public class JointPrefetchIT extends ServerCase { @Test public void testJointPrefetchToManyNonConflictingQualifier() throws Exception { - createJointPrefetchDataSet1(); + createJointPrefetchDataSet(); // query with to-many joint prefetches and qualifier that doesn't match // prefetch.... Expression qualifier = Artist.ARTIST_NAME.eq("artist1"); - SelectQuery q = new SelectQuery(Artist.class, qualifier); + SelectQuery<Artist> q = new SelectQuery<>(Artist.class, qualifier); q.addPrefetch(Artist.PAINTING_ARRAY.joint()); - final List<?> objects = context.performQuery(q); - - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { - - public void execute() { - assertEquals(1, objects.size()); + final List<Artist> objects = q.select(context); - Artist a = (Artist) objects.get(0); - List<?> list = a.getPaintingArray(); + queryInterceptor.runWithQueriesBlocked(() -> { + assertEquals(1, objects.size()); - assertNotNull(list); - assertFalse(((ValueHolder) list).isFault()); - assertEquals(2, list.size()); + Artist a = objects.get(0); + List<Painting> list = a.getPaintingArray(); - Iterator<?> children = list.iterator(); - while (children.hasNext()) { - Painting p = (Painting) children.next(); - assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); - // make sure properties are not null.. - assertNotNull(p.getPaintingTitle()); - } + assertNotNull(list); + assertFalse(((ValueHolder) list).isFault()); + assertEquals(2, list.size()); - // assert no duplicates - Set s = new HashSet(list); - assertEquals(s.size(), list.size()); + for (Painting p : list) { + assertEquals(PersistenceState.COMMITTED, p.getPersistenceState()); + // make sure properties are not null.. + assertNotNull(p.getPaintingTitle()); } + + // assert no duplicates + Set<Painting> s = new HashSet<>(list); + assertEquals(s.size(), list.size()); }); } @Test public void testJointPrefetchMultiStep() throws Exception { - createJointPrefetchDataSet2(); + createJointPrefetchDataSet(); // query with to-many joint prefetches SelectQuery<Artist> q = new SelectQuery<>(Artist.class); @@ -443,41 +369,36 @@ public class JointPrefetchIT extends ServerCase { final DataContext context = this.context; // make sure phantomly prefetched objects are not deallocated - context.getObjectStore().objectMap = new HashMap<Object, Persistent>(); + context.getObjectStore().objectMap = new HashMap<>(); // sanity check... DataObject g1 = (DataObject) context.getGraphManager().getNode( new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001)); assertNull(g1); - final List<?> objects = context.performQuery(q); - - queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { - - public void execute() { - assertEquals(3, objects.size()); + final List<Artist> objects = q.select(context); - Iterator<?> it = objects.iterator(); - while (it.hasNext()) { - Artist a = (Artist) it.next(); - ValueHolder list = (ValueHolder) a.getPaintingArray(); + queryInterceptor.runWithQueriesBlocked(() -> { + assertEquals(3, objects.size()); - assertNotNull(list); + for (Artist a : objects) { + ValueHolder list = (ValueHolder) a.getPaintingArray(); - // intermediate relationship is not fetched... - assertTrue(list.isFault()); - } + assertNotNull(list); - // however both galleries must be in memory... - DataObject g1 = (DataObject) context.getGraphManager().getNode( - new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001)); - assertNotNull(g1); - assertEquals(PersistenceState.COMMITTED, g1.getPersistenceState()); - DataObject g2 = (DataObject) context.getGraphManager().getNode( - new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33002)); - assertNotNull(g2); - assertEquals(PersistenceState.COMMITTED, g2.getPersistenceState()); + // intermediate relationship is not fetched... + assertTrue(list.isFault()); } + + // however both galleries must be in memory... + DataObject g11 = (DataObject) context.getGraphManager().getNode( + new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001)); + assertNotNull(g11); + assertEquals(PersistenceState.COMMITTED, g11.getPersistenceState()); + DataObject g2 = (DataObject) context.getGraphManager().getNode( + new ObjectId("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33002)); + assertNotNull(g2); + assertEquals(PersistenceState.COMMITTED, g2.getPersistenceState()); }); } } http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java ---------------------------------------------------------------------- diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java index ab24a6f..919a9c5 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java @@ -65,12 +65,11 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase { tArtist.setColumns("ARTIST_ID", "ARTIST_NAME"); createArtistsDataSet(); - SelectQuery q = new SelectQuery("Artist"); + SelectQuery q = SelectQuery.dataRowQuery(Artist.class); q.setPageSize(6); - q.setFetchingDataRows(true); q.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING); - list = new SimpleIdIncrementalFaultList<Object>(context, q, 10000); + list = new SimpleIdIncrementalFaultList<>(context, q, 10000); } protected void createArtistsDataSet() throws Exception { http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java ---------------------------------------------------------------------- diff --git a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java index f349ac7..6874e55 100644 --- a/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java +++ b/cayenne-web/src/main/java/org/apache/cayenne/configuration/web/WebConfiguration.java @@ -134,14 +134,9 @@ public class WebConfiguration { Module module; try { module = (Module) Util.getJavaClass(moduleName).newInstance(); - } - catch (Exception e) { - String message = String - .format( - "Error instantiating custom DI module '%s' by filter '%s': %s", - moduleName, - getClass().getName(), - e.getMessage()); + } catch (Exception e) { + String message = String.format("Error instantiating custom DI module '%s' by filter '%s': %s", + moduleName, getClass().getName(), e.getMessage()); throw new ServletException(message, e); } @@ -160,7 +155,7 @@ public class WebConfiguration { Enumeration<?> en = configuration.getInitParameterNames(); if (!en.hasMoreElements()) { - return Collections.EMPTY_MAP; + return Collections.emptyMap(); } Map<String, String> parameters = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/cayenne/blob/eec08b7e/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/EOQueryTest.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/EOQueryTest.java b/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/EOQueryTest.java index 8dcea27..a4d25a4 100644 --- a/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/EOQueryTest.java +++ b/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/EOQueryTest.java @@ -43,14 +43,15 @@ public class EOQueryTest { EOModelProcessor processor = new EOModelProcessor(); DataMap map = processor.loadEOModel(url); - Map fspecMap = (Map) PropertyListSerialization.propertyListFromStream(getClass() + @SuppressWarnings("unchecked") + Map<String, ?> fspecMap = (Map<String, ?>) PropertyListSerialization.propertyListFromStream(getClass() .getClassLoader() .getResourceAsStream("wotests/fetchspec.eomodeld/Entity1.fspec")); assertNotNull(fspecMap); assertNotNull(fspecMap.get("E1FS1")); - EOQuery query = new EOQuery(map.getObjEntity("Entity1"), (Map) fspecMap - .get("E1FS1")); + @SuppressWarnings("unchecked") + EOQuery query = new EOQuery(map.getObjEntity("Entity1"), (Map<String, ?>) fspecMap.get("E1FS1")); assertNotNull(query.getQualifier()); assertEquals(