cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: 2094 SelectById query doesn't work from ROP client with protostuff
Date Fri, 24 Mar 2017 08:51:15 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 663e9ec19 -> 873314765


2094 SelectById query doesn't work from ROP client with protostuff


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

Branch: refs/heads/master
Commit: 873314765ccf3daf70f98d5ceb3aa1d1661e2fe9
Parents: 663e9ec
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Fri Mar 24 11:25:54 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Fri Mar 24 11:25:54 2017 +0300

----------------------------------------------------------------------
 .../cayenne/remote/service/LocalConnection.java |  3 +-
 .../cayenne/query/ClientObjectSelectIT.java     | 17 +++++++----
 .../org/apache/cayenne/map/EntityResolver.java  | 31 ++++++++++++++++++++
 .../apache/cayenne/query/BaseQueryMetadata.java | 15 +---------
 .../org/apache/cayenne/query/SelectById.java    | 12 ++++----
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 6 files changed, 52 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/87331476/cayenne-client/src/main/java/org/apache/cayenne/remote/service/LocalConnection.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/remote/service/LocalConnection.java
b/cayenne-client/src/main/java/org/apache/cayenne/remote/service/LocalConnection.java
index db9c2fb..65bceec 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/remote/service/LocalConnection.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/remote/service/LocalConnection.java
@@ -109,8 +109,7 @@ public class LocalConnection extends BaseConnection {
                     break;
 
                 case JAVA_SERIALIZATION:
-                    processedMessage = (ClientMessage) Util
-                            .cloneViaSerialization(message);
+                    processedMessage = Util.cloneViaSerialization(message);
                     break;
 
                 default:

http://git-wip-us.apache.org/repos/asf/cayenne/blob/87331476/cayenne-client/src/test/java/org/apache/cayenne/query/ClientObjectSelectIT.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/query/ClientObjectSelectIT.java
b/cayenne-client/src/test/java/org/apache/cayenne/query/ClientObjectSelectIT.java
index e328dd6..9cb6cee 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/query/ClientObjectSelectIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/query/ClientObjectSelectIT.java
@@ -65,8 +65,8 @@ public class ClientObjectSelectIT extends ClientCase {
 
     @Test
     public void testSelect() throws Exception{
-        List<ClientMtTable1> list = ObjectSelect.query(ClientMtTable1.class).
-                select(context);
+        List<ClientMtTable1> list = ObjectSelect.query(ClientMtTable1.class)
+                .select(context);
 
         assertNotNull(list);
         assertEquals(20, list.size());
@@ -74,7 +74,7 @@ public class ClientObjectSelectIT extends ClientCase {
 
     @Test
     public void testCacheSelect() throws Exception{
-        final ObjectSelect objectSelect = ObjectSelect.query(ClientMtTable1.class).
+        final ObjectSelect<ClientMtTable1> objectSelect = ObjectSelect.query(ClientMtTable1.class).
                 cacheStrategy(QueryCacheStrategy.SHARED_CACHE);
 
         final List<ClientMtTable1> list1 = objectSelect.select(context);
@@ -105,7 +105,7 @@ public class ClientObjectSelectIT extends ClientCase {
 
     @Test
     public void testCacheLimitSelect() throws Exception {
-        final ObjectSelect objectSelect = ObjectSelect.query(ClientMtTable1.class)
+        final ObjectSelect<ClientMtTable1> objectSelect = ObjectSelect.query(ClientMtTable1.class)
                 .cacheStrategy(QueryCacheStrategy.SHARED_CACHE)
                 .offset(5)
                 .limit(10);
@@ -126,7 +126,7 @@ public class ClientObjectSelectIT extends ClientCase {
 
     @Test
     public void testPageSelect() throws Exception{
-        final ObjectSelect objectSelect = ObjectSelect.query(ClientMtTable1.class)
+        final ObjectSelect<ClientMtTable1> objectSelect = ObjectSelect.query(ClientMtTable1.class)
                 .pageSize(5);
 
         final List<ClientMtTable1> list = objectSelect.select(context);
@@ -146,4 +146,11 @@ public class ClientObjectSelectIT extends ClientCase {
         assertEquals(1, count);
     }
 
+    @Test
+    public void testCAY_2094() {
+        ClientMtTable1 clientMtTable1 = SelectById.query(ClientMtTable1.class, 1).selectOne(context);
+        assertNotNull(clientMtTable1);
+        assertEquals(1, clientMtTable1.getObjectId().getIdSnapshot().get("TABLE1_ID"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/87331476/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
index f11c5d4..e7f93d8 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
@@ -500,6 +500,37 @@ public class EntityResolver implements MappingNamespace, Serializable
{
     }
 
     /**
+     * <p>
+     * Looks in the DataMap's that this object was created with for the
+     * ObjEntity that maps to the services the specified class, with option to
+     * fallback to search by name with client resolver in case entity not found.
+     * </p>
+     * <p>
+     * This method can be used where entity class can be received from client.
+     * </p>
+     *
+     * @param entityClass entity class to search
+     * @param lookupClientResolver flag to fallback to client resolver
+     * @return the required ObjEntity or null if there is none that matches the
+     *         specifier
+     *
+     * @since 4.0
+     */
+    public ObjEntity getObjEntity(Class<?> entityClass, boolean lookupClientResolver)
{
+        ObjEntity entity = getObjEntity(entityClass);
+        if(entity != null || !lookupClientResolver) {
+            return entity;
+        }
+
+        EntityResolver clientResolver = getClientEntityResolver();
+        if (clientResolver != this) {
+            ObjEntity clientEntity = clientResolver.getObjEntity(entityClass);
+            entity = clientEntity == null ? null : getObjEntity(clientEntity.getName());
+        }
+        return entity;
+    }
+
+    /**
      * @deprecated since 4.0, use {@link #getObjEntity(Class)}.
      */
     public ObjEntity lookupObjEntity(Class<?> entityClass) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/87331476/cayenne-server/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
b/cayenne-server/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
index 92b7835..bc13719 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
@@ -104,20 +104,7 @@ class BaseQueryMetadata implements QueryMetadata, XMLSerializable, Serializable
 
 			if (root != null) {
 				if (root instanceof Class<?>) {
-					entity = resolver.getObjEntity((Class<?>) root);
-					if (entity == null) { // entity not found, try to resolve it
-											// with
-						// client resolver
-						EntityResolver clientResolver = resolver.getClientEntityResolver();
-						if (clientResolver != resolver) {
-							ObjEntity clientEntity = clientResolver.getObjEntity((Class<?>) root);
-
-							if (clientEntity != null) {
-								entity = resolver.getObjEntity(clientEntity.getName());
-							}
-						}
-					}
-
+					entity = resolver.getObjEntity((Class<?>) root, true);
 					if (entity != null) {
 						this.dbEntity = entity.getDbEntity();
 						this.dataMap = entity.getDataMap();

http://git-wip-us.apache.org/repos/asf/cayenne/blob/87331476/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
index ea9bfdc..b6e8c58 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
@@ -60,7 +60,7 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 	PrefetchTreeNode prefetches;
 
 	public static <T> SelectById<T> query(Class<T> entityType, Object id)
{
-		SelectById<T> q = new SelectById<T>();
+		SelectById<T> q = new SelectById<>();
 
 		q.entityType = entityType;
 		q.singleId = id;
@@ -70,7 +70,7 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 	}
 
 	public static <T> SelectById<T> query(Class<T> entityType, Map<String,
?> id) {
-		SelectById<T> q = new SelectById<T>();
+		SelectById<T> q = new SelectById<>();
 
 		q.entityType = entityType;
 		q.mapId = id;
@@ -82,7 +82,7 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 	public static <T> SelectById<T> query(Class<T> entityType, ObjectId id)
{
 		checkObjectId(id);
 
-		SelectById<T> q = new SelectById<T>();
+		SelectById<T> q = new SelectById<>();
 
 		q.entityName = id.getEntityName();
 		q.mapId = id.getIdSnapshot();
@@ -146,7 +146,7 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 
 	@Override
 	public void iterate(ObjectContext context, ResultIteratorCallback<T> callback) {
-		context.iterate((Select<T>) this, callback);
+		context.iterate(this, callback);
 	}
 
 	@Override
@@ -288,7 +288,7 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 		ObjEntity entity = resolveEntity(resolver);
 		Map<String, ?> id = resolveId(entity);
 
-		SelectQuery<Object> query = new SelectQuery<Object>();
+		SelectQuery<Object> query = new SelectQuery<>();
 		query.setRoot(entity);
 		query.setFetchingDataRows(fetchingDataRows);
 		query.setQualifier(matchAllDbExp(id, Expression.EQUAL_TO));
@@ -328,6 +328,6 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 			throw new CayenneRuntimeException("Misconfigured query. Either entityName or entityType
must be set");
 		}
 
-		return entityName != null ? resolver.getObjEntity(entityName) : resolver.getObjEntity(entityType);
+		return entityName != null ? resolver.getObjEntity(entityName) : resolver.getObjEntity(entityType,
true);
 	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/87331476/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 48618a8..4be4483 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -28,6 +28,7 @@ CAY-2272 ColumnSelect: methods to manually control DISTINCT clause
 
 Bug Fixes:
 
+CAY-2094 SelectById query doesn't work from ROP client
 CAY-2240 Modeler: issue with cursor rendering for EJBQL query
 CAY-2243 ObjectContext.getGraphManager().unregisterObject() inconsistencies
 CAY-2256 Cannot Save/Insert an Object With null Flattened (complex) toOne Relationship (see
also CAY-2146)


Mime
View raw message