From d56ad8b90d69cba881d5902004dfe72311acbcca Mon Sep 17 00:00:00 2001 From: wcekan Date: Thu, 11 Mar 2021 20:50:23 -0500 Subject: [PATCH] make one scan --- .../java/com/yahoo/elide/core/EntityBinding.java | 12 +++++++++++- .../core/datastore/inmemory/HashMapDataStore.java | 15 +-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java index ab35dac888..51de22288c 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java @@ -240,6 +240,16 @@ public List getAllFields() { */ private void bindEntityFields(Class cls, String type, Collection fieldOrMethodList) { for (AccessibleObject fieldOrMethod : fieldOrMethodList) { + // Special handling for Eclipse. Load missing annotations + if (fieldOrMethod.getAnnotations().length == 0 && fieldOrMethod instanceof Method) { + Method m = (Method) fieldOrMethod; + try { + fieldOrMethod = m.getDeclaringClass().getMethod(m.getName(), m.getParameterTypes()); + } catch (NoSuchMethodException | SecurityException e) { + // Not expected, leave alone + } + } + bindTriggerIfPresent(OnCreatePreSecurity.class, fieldOrMethod); bindTriggerIfPresent(OnDeletePreSecurity.class, fieldOrMethod); bindTriggerIfPresent(OnUpdatePreSecurity.class, fieldOrMethod); @@ -390,7 +400,7 @@ private void bindRelation(AccessibleObject fieldOrMethod, String fieldName, Clas relationshipsDeque.push(fieldName); fieldsToValues.put(fieldName, fieldOrMethod); - fieldsToTypes.put(fieldName, fieldType); + fieldsToTypes.put(fieldName, fieldType == null ? Void.class : fieldType); } private void bindAttr(AccessibleObject fieldOrMethod, String fieldName, Class fieldType) { diff --git a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java index a8e37d846e..e0a275eec2 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapDataStore.java @@ -25,8 +25,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; -import javax.persistence.Entity; - /** * Simple in-memory only database. */ @@ -44,18 +42,7 @@ public HashMapDataStore(Set beanPackages) { this.beanPackages = beanPackages; for (Package beanPackage : beanPackages) { - ClassScanner.getAnnotatedClasses(beanPackage, Include.class).stream() - .filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName())) - .filter(modelClass -> dictionary.getFirstAnnotation(modelClass, - Arrays.asList(Include.class, Exclude.class)) instanceof Include) - .forEach(modelClass -> dataStore.put(modelClass, - Collections.synchronizedMap(new LinkedHashMap<>()))); - } - - for (Package beanPackage : beanPackages) { - ClassScanner.getAnnotatedClasses(beanPackage, Entity.class).stream() - .filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName())) - .filter(modelClass -> !dataStore.containsKey(modelClass)) + ClassScanner.getAllClasses(beanPackage.getName()).stream() .filter(modelClass -> dictionary.getFirstAnnotation(modelClass, Arrays.asList(Include.class, Exclude.class)) instanceof Include) .forEach(modelClass -> dataStore.put(modelClass,