DATACMNS-1079 - Polishing.

Refactored all the checks done to check if ClassGeneratingPropertyAccessorFactory works into separate methods, so the body of isSupported becomes nice and readable.

Original pull request: #224.
This commit is contained in:
Jens Schauder
2017-06-02 09:56:39 +02:00
committed by Mark Paluch
parent 59f52a9e35
commit 497dc08a7c

View File

@@ -101,15 +101,12 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
Assert.notNull(entity, "PersistentEntity must not be null!");
try {
Evil.getClassLoaderMethod(entity);
} catch (Exception o_O) {
return false;
}
return isClassLoaderDefineClassAccessible(entity) //
&& isTypeInjectable(entity) //
&& arePropertyHashCodesUnique(entity);
}
if (entity.getType().getClassLoader() == null || entity.getType().getPackage().getName().startsWith("java")) {
return false;
}
private boolean arePropertyHashCodesUnique(PersistentEntity<?, ?> entity) {
final Set<Integer> hashCodes = new HashSet<>();
final AtomicInteger propertyCount = new AtomicInteger();
@@ -132,6 +129,20 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert
return hashCodes.size() == propertyCount.get();
}
private static boolean isTypeInjectable(PersistentEntity<?, ?> entity) {
return entity.getType().getClassLoader() != null && !entity.getType().getPackage().getName().startsWith("java");
}
private static boolean isClassLoaderDefineClassAccessible(PersistentEntity<?, ?> entity) {
try {
Evil.getClassLoaderMethod(entity);
} catch (Exception o_O) {
return false;
}
return true;
}
/**
* @param entity must not be {@literal null}.
* @return