syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [syncope] 01/02: [SYNCOPE-1392] Small reflection avoidance
Date Fri, 16 Nov 2018 11:13:15 GMT
This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit 62102ef4b777e1bc7df6def6c701d8d77a196f8a
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
AuthorDate: Fri Nov 16 08:43:31 2018 +0100

    [SYNCOPE-1392] Small reflection avoidance
---
 .../persistence/jpa/dao/AbstractAnySearchDAO.java    | 20 +++++---------------
 .../core/persistence/jpa/dao/JPAAnySearchDAO.java    |  2 --
 2 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnySearchDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnySearchDAO.java
index e09ff63..43800e2 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnySearchDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/AbstractAnySearchDAO.java
@@ -20,7 +20,6 @@ package org.apache.syncope.core.persistence.jpa.dao;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -30,7 +29,6 @@ import javax.validation.ValidationException;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.lang3.tuple.Triple;
 import org.apache.syncope.common.lib.SyncopeConstants;
@@ -55,7 +53,6 @@ import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
 import org.apache.syncope.core.persistence.api.entity.Any;
 import org.apache.syncope.core.persistence.api.entity.AnyUtils;
 import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
-import org.apache.syncope.core.persistence.api.entity.Entity;
 import org.apache.syncope.core.persistence.api.entity.EntityFactory;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
@@ -71,6 +68,8 @@ public abstract class AbstractAnySearchDAO extends AbstractDAO<Any<?>>
implement
         "serialVersionUID", "password", "securityQuestion", "securityAnswer", "token", "tokenExpireTime"
     };
 
+    protected static final String[] RELATIONSHIP_FIELDS = new String[] { "realm", "userOwner",
"groupOwner" };
+
     @Autowired
     protected RealmDAO realmDAO;
 
@@ -214,18 +213,9 @@ public abstract class AbstractAnySearchDAO extends AbstractDAO<Any<?>>
implement
         }
 
         // Deal with any fields representing relationships to other entities
-        if (Entity.class.isAssignableFrom(anyField.getType())) {
-            Method relMethod = null;
-            try {
-                relMethod = ClassUtils.getPublicMethod(anyField.getType(), "getKey", new
Class<?>[0]);
-            } catch (Exception e) {
-                LOG.error("Could not find {}#getKey", anyField.getType(), e);
-            }
-
-            if (relMethod != null && String.class.isAssignableFrom(relMethod.getReturnType()))
{
-                computed.setSchema(computed.getSchema() + "_id");
-                schema.setType(AttrSchemaType.String);
-            }
+        if (ArrayUtils.contains(RELATIONSHIP_FIELDS, computed.getSchema())) {
+            computed.setSchema(computed.getSchema() + "_id");
+            schema.setType(AttrSchemaType.String);
         }
 
         PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
index 5810207..02e2535 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
@@ -65,8 +65,6 @@ public class JPAAnySearchDAO extends AbstractAnySearchDAO {
 
     protected static final String EMPTY_QUERY = "SELECT any_id FROM user_search WHERE 1=2";
 
-    protected static final String[] RELATIONSHIP_FIELDS = new String[] { "realm", "userOwner",
"groupOwner" };
-
     private Pair<String, Set<String>> getAdminRealmsFilter(
             final Set<String> adminRealms,
             final SearchSupport svs,


Mime
View raw message