From 1fbca7a151fc35ca069a468448c9d914c284defe Mon Sep 17 00:00:00 2001 From: yurem Date: Wed, 13 Apr 2022 21:30:47 +0300 Subject: [PATCH 1/3] fix: use lower table names in inspected tables metadata --- .../jans/orm/sql/operation/impl/SqlConnectionProvider.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jans-orm/sql/src/main/java/io/jans/orm/sql/operation/impl/SqlConnectionProvider.java b/jans-orm/sql/src/main/java/io/jans/orm/sql/operation/impl/SqlConnectionProvider.java index b6423620bb6..f9e91f9dfa1 100644 --- a/jans-orm/sql/src/main/java/io/jans/orm/sql/operation/impl/SqlConnectionProvider.java +++ b/jans-orm/sql/src/main/java/io/jans/orm/sql/operation/impl/SqlConnectionProvider.java @@ -14,11 +14,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; -import java.util.Set; import org.apache.commons.dbcp2.ConnectionFactory; import org.apache.commons.dbcp2.DriverManagerConnectionFactory; @@ -246,7 +244,7 @@ private void loadTableMetaData(DatabaseMetaData databaseMetaData, Connection con tableColumns.put(columnName, columTypeName); } - tableColumnsMap.put(tableName, tableColumns); + tableColumnsMap.put(StringHelper.toLowerCase(tableName), tableColumns); } takes = System.currentTimeMillis() - takes; @@ -398,7 +396,7 @@ public SQLQueryFactory getSqlQueryFactory() { public TableMapping getTableMappingByKey(String key, String objectClass) { String tableName = objectClass; - Map columTypes = tableColumnsMap.get(tableName); + Map columTypes = tableColumnsMap.get(StringHelper.toLowerCase(tableName)); if ("_".equals(key)) { return new TableMapping("", tableName, objectClass, columTypes); } From 4967d4191abdcdbbd65e9c1a0c0aea8bc43e1c92 Mon Sep 17 00:00:00 2001 From: yurem Date: Wed, 13 Apr 2022 21:31:45 +0300 Subject: [PATCH 2/3] feat: allow to create inner beans --- .../src/main/java/io/jans/orm/impl/BaseEntryManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java b/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java index fc9625412ab..3d5efa139c9 100644 --- a/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java +++ b/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java @@ -958,7 +958,12 @@ protected List createEntities(Class entryClass, List customObjectClasses = null; try { - entry = ReflectHelper.createObjectByDefaultConstructor(entryClass); + Class declaringClass = entryClass.getDeclaringClass(); + if (declaringClass == null) { + entry = ReflectHelper.createObjectByDefaultConstructor(entryClass); + } else { + entry = (T) ReflectHelper.getConstructor(entryClass, declaringClass).newInstance((Object) null); + } } catch (Exception ex) { throw new MappingException(String.format("Entry %s should has default constructor", entryClass)); } From e82db4715d3c96d02f0705e088e07b0ffc8a1d03 Mon Sep 17 00:00:00 2001 From: yurem Date: Wed, 13 Apr 2022 21:32:55 +0300 Subject: [PATCH 3/3] feat: ignore methods with Transient annotation --- .../property/BasicPropertyAccessor.java | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/jans-orm/core/src/main/java/io/jans/orm/reflect/property/BasicPropertyAccessor.java b/jans-orm/core/src/main/java/io/jans/orm/reflect/property/BasicPropertyAccessor.java index a1e9d3cb6b3..55484e77574 100644 --- a/jans-orm/core/src/main/java/io/jans/orm/reflect/property/BasicPropertyAccessor.java +++ b/jans-orm/core/src/main/java/io/jans/orm/reflect/property/BasicPropertyAccessor.java @@ -7,6 +7,7 @@ package io.jans.orm.reflect.property; import java.beans.Introspector; +import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -153,7 +154,6 @@ private static BasicSetter getSetterOrNull(Class theClass, String propertyNam } Method method = setterMethod(theClass, propertyName); - if (method != null) { if (!ReflectHelper.isPublic(theClass, method)) { method.setAccessible(true); @@ -181,14 +181,21 @@ private static Method setterMethod(Class theClass, String propertyName) { Method[] methods = theClass.getDeclaredMethods(); Method potentialSetter = null; for (int i = 0; i < methods.length; i++) { - String methodName = methods[i].getName(); + Method method = methods[i]; + + boolean isTransient = isTransient(method); + if (isTransient) { + continue; + } - if (methods[i].getParameterTypes().length == 1 && methodName.startsWith("set")) { + String methodName = method.getName(); + + if (method.getParameterTypes().length == 1 && methodName.startsWith("set")) { String testStdMethod = Introspector.decapitalize(methodName.substring(3)); String testOldMethod = methodName.substring(3); if (testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName)) { - potentialSetter = methods[i]; - if (returnType == null || methods[i].getParameterTypes()[0].equals(returnType)) { + potentialSetter = method; + if (returnType == null || method.getParameterTypes()[0].equals(returnType)) { return potentialSetter; } } @@ -216,6 +223,16 @@ private static BasicGetter getGetterOrNull(Class theClass, String propertyNam } Method method = getterMethod(theClass, propertyName); + if (method != null) { + Annotation[] methodAnnotations = method.getAnnotations(); + if (methodAnnotations != null) { + for (Annotation methodAnnotation : methodAnnotations) { + if (methodAnnotation.annotationType().equals(java.beans.Transient.class)) { + method = null; + } + } + } + } if (method != null) { if (!ReflectHelper.isPublic(theClass, method)) { @@ -241,14 +258,21 @@ private static Method getterMethod(Class theClass, String propertyName) { for (int i = 0; i < methods.length; i++) { // only carry on if the method has no parameters if (methods[i].getParameterTypes().length == 0) { - String methodName = methods[i].getName(); + Method method = methods[i]; + + boolean isTransient = isTransient(method); + if (isTransient) { + continue; + } + + String methodName = methods[i].getName(); // try "get" if (methodName.startsWith("get")) { String testStdMethod = Introspector.decapitalize(methodName.substring(3)); String testOldMethod = methodName.substring(3); if (testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName)) { - return methods[i]; + return method; } } @@ -258,7 +282,7 @@ private static Method getterMethod(Class theClass, String propertyName) { String testStdMethod = Introspector.decapitalize(methodName.substring(2)); String testOldMethod = methodName.substring(2); if (testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName)) { - return methods[i]; + return method; } } } @@ -266,4 +290,17 @@ private static Method getterMethod(Class theClass, String propertyName) { return null; } + private static boolean isTransient(Method method) { + Annotation[] methodAnnotations = method.getAnnotations(); + if (methodAnnotations != null) { + for (Annotation methodAnnotation : methodAnnotations) { + if (methodAnnotation.annotationType().equals(java.beans.Transient.class)) { + return true; + } + } + } + + return false; + } + }