|
@@ -29,7 +29,8 @@ public class DatabaseMapper {
|
|
|
// Recup valeur dans le resultat
|
|
|
Object value = rs.getObject(field.getAnnotation(DbField.class).value());
|
|
|
// Si lien avec une autre entité
|
|
|
- if(value != null && field.isAnnotationPresent(DbLink.class)) {
|
|
|
+ String link = DatabaseUtils.getDbLink(field);
|
|
|
+ if(value != null && link != null) {
|
|
|
DatabaseUtils.checkIfPersistable(field);
|
|
|
Long otherId = (Long) value;
|
|
|
if(otherId == 0) {
|
|
@@ -38,7 +39,7 @@ public class DatabaseMapper {
|
|
|
String[] split = field.getType().getName().split("\\.");
|
|
|
String className = split[split.length - 1];
|
|
|
// Chargement de la class Table qui gère l'entité
|
|
|
- Class<?> clazz = Class.forName(field.getAnnotation(DbLink.class).value() + "." + className + "Table");
|
|
|
+ Class<?> clazz = Class.forName(link + "." + className + "Table");
|
|
|
DatabaseTable table = (DatabaseTable) clazz.getMethod("getInstance").invoke(null);
|
|
|
value = table.getById(otherId);
|
|
|
}
|
|
@@ -67,23 +68,24 @@ public class DatabaseMapper {
|
|
|
continue;
|
|
|
}
|
|
|
// Recup valeur dans le resultat
|
|
|
- Object val = rs.getObject(field.getAnnotation(DbField.class).value());
|
|
|
+ Object value = rs.getObject(field.getAnnotation(DbField.class).value());
|
|
|
// Si lien avec une autre entité
|
|
|
- if(val != null && field.isAnnotationPresent(DbLink.class)) {
|
|
|
+ String link = DatabaseUtils.getDbLink(field);
|
|
|
+ if(value != null && link != null) {
|
|
|
DatabaseUtils.checkIfPersistable(field);
|
|
|
- Long otherId = (Long) val;
|
|
|
+ Long otherId = (Long) value;
|
|
|
if(otherId == 0) {
|
|
|
- val = null;
|
|
|
+ value = null;
|
|
|
} else {
|
|
|
String[] split = field.getType().getName().split("\\.");
|
|
|
String className = split[split.length - 1];
|
|
|
// Chargement de la class Table qui gère l'entité
|
|
|
- Class<?> clazz = Class.forName(field.getAnnotation(DbLink.class).value() + "." + className + "Table");
|
|
|
+ Class<?> clazz = Class.forName(link + "." + className + "Table");
|
|
|
DatabaseTable table = (DatabaseTable) clazz.getMethod("getInstance").invoke(null);
|
|
|
- val = table.getById(otherId);
|
|
|
+ value = table.getById(otherId);
|
|
|
}
|
|
|
}
|
|
|
- field.set(obj, val);
|
|
|
+ field.set(obj, value);
|
|
|
}
|
|
|
list.add(obj);
|
|
|
}
|