Migliorie estreme su mapResultSetToList
This commit is contained in:
@@ -730,7 +730,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-symbol-solver-core</artifactId>
|
||||
<version>3.25.9</version>
|
||||
<version>3.26.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -20,6 +20,8 @@ import it.integry.ems_model.annotation.*;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -75,6 +77,8 @@ public class EntityDevelopmentService {
|
||||
CompilationUnit javaClassCompilation = new CompilationUnit();
|
||||
|
||||
javaClassCompilation.setPackageDeclaration("it.integry.ems_model.entity");
|
||||
javaClassCompilation.addImport(LogManager.class);
|
||||
javaClassCompilation.addImport(List.class);
|
||||
|
||||
String javaClassName = UtilityString.sqlToCamelCase(databaseTable.getTableName());
|
||||
javaClassName = javaClassName.substring(0, 1).toUpperCase() + javaClassName.substring(1);
|
||||
@@ -113,6 +117,17 @@ public class EntityDevelopmentService {
|
||||
serialVersionUIDField.setVariable(0, new VariableDeclarator(serialVersionUIDFieldType, "serialVersionUID",
|
||||
new LongLiteralExpr("1L")));
|
||||
|
||||
|
||||
final FieldDeclaration loggerField = javaClass.addField(Logger.class, "logger", PRIVATE, FINAL, STATIC);
|
||||
ClassOrInterfaceType loggerFieldType = loggerField.getElementType().asClassOrInterfaceType();
|
||||
loggerFieldType.setName("Logger");
|
||||
|
||||
loggerField.setVariable(0, new VariableDeclarator(loggerFieldType, "logger",
|
||||
new MethodCallExpr("LogManager.getLogger")));
|
||||
|
||||
|
||||
createEntityConstructor(javaClass);
|
||||
|
||||
List<FieldDeclaration> entityFields = new ArrayList<>();
|
||||
|
||||
for (DatabaseTableColumn databaseColumn : databaseTable.getColumns()) {
|
||||
@@ -124,10 +139,16 @@ public class EntityDevelopmentService {
|
||||
String entityChildClassName = UtilityString.sqlToCamelCase(child.getTableName());
|
||||
entityChildClassName = entityChildClassName.substring(0, 1).toUpperCase() + entityChildClassName.substring(1);
|
||||
|
||||
String variableName = entityChildClassName.substring(0, 1).toLowerCase() + entityChildClassName.substring(1);
|
||||
|
||||
final FieldDeclaration fieldDeclaration = javaClass.addField(
|
||||
"List<" + entityChildClassName + ">",
|
||||
entityChildClassName.substring(0, 1).toLowerCase() + entityChildClassName.substring(1),
|
||||
variableName,
|
||||
PRIVATE);
|
||||
|
||||
//final InitializerDeclaration initializerDeclaration = new InitializerDeclaration(false, new BlockStmt().addStatement("new ArrayList<>()"));
|
||||
|
||||
fieldDeclaration.setVariable(0, new VariableDeclarator(fieldDeclaration.getElementType(), variableName));
|
||||
entityFields.add(fieldDeclaration);
|
||||
|
||||
fieldDeclaration.addAnnotation(EntityChild.class);
|
||||
@@ -149,6 +170,17 @@ public class EntityDevelopmentService {
|
||||
return javaClassCompilation;
|
||||
}
|
||||
|
||||
private void createEntityConstructor(ClassOrInterfaceDeclaration javaClass) {
|
||||
final ConstructorDeclaration constructorDeclaration = javaClass.addConstructor(PUBLIC);
|
||||
|
||||
final BlockStmt constructorBlockStmt = constructorDeclaration.getBody();
|
||||
|
||||
constructorBlockStmt.addStatement(new MethodCallExpr("super",
|
||||
new BooleanLiteralExpr(false),
|
||||
new NameExpr("logger")));
|
||||
|
||||
}
|
||||
|
||||
private FieldDeclaration createEntityField(ClassOrInterfaceDeclaration javaClass, DatabaseTableColumn databaseColumn) throws Exception {
|
||||
final Class<?> aClass = UtilityDB.sqlTypeToJavaClass(databaseColumn.getDataType().toSqlDataType());
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ import java.util.stream.Collectors;
|
||||
public abstract class EntityBase implements Serializable, Cloneable, EntityInterface {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected final Logger logger = LogManager.getLogger();
|
||||
protected Logger logger;
|
||||
|
||||
|
||||
protected Connection connection;
|
||||
@@ -127,6 +127,10 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public EntityBase() {
|
||||
this(true, null);
|
||||
}
|
||||
|
||||
public EntityBase(boolean execInit, Logger logger) {
|
||||
JsonTypeName t = getClass().getAnnotation(JsonTypeName.class);
|
||||
|
||||
if (t != null) {
|
||||
@@ -135,20 +139,27 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
||||
this.type = null;
|
||||
}
|
||||
|
||||
List<Field> entityChildFields = getEntityHolder().getEntityChildrenFields(this.getClass());
|
||||
if(logger != null)
|
||||
this.logger = logger;
|
||||
else
|
||||
this.logger = LogManager.getLogger();
|
||||
|
||||
if (entityChildFields == null) return;
|
||||
if (execInit) {
|
||||
List<Field> entityChildFields = getEntityHolder().getEntityChildrenFields(this.getClass());
|
||||
|
||||
for (Field field : entityChildFields) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object object = field.get(this);
|
||||
if (object == null && field.getType().isAssignableFrom(List.class)) {
|
||||
object = new ArrayList();
|
||||
field.set(this, object);
|
||||
if (entityChildFields == null) return;
|
||||
|
||||
for (Field field : entityChildFields) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object object = field.get(this);
|
||||
if (object == null && field.getType().isAssignableFrom(List.class)) {
|
||||
object = new ArrayList<>();
|
||||
field.set(this, object);
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
logger.error(ex);
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
logger.error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import it.integry.ems_model.entity._enum.IBaseEnum;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -25,6 +27,8 @@ public class MtbColr extends EntityBase implements EquatableEntityInterface<MtbC
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(MtbColr.class);
|
||||
|
||||
@PK
|
||||
@SqlField(value = "data_collo", nullable = false, defaultObjectValue = CommonConstants.SYSDATE, format = CommonConstants.SYSDATE)
|
||||
private LocalDate dataCollo;
|
||||
@@ -169,7 +173,7 @@ public class MtbColr extends EntityBase implements EquatableEntityInterface<MtbC
|
||||
private MtbPartitaMag mtbPartitaMag;
|
||||
|
||||
public MtbColr() {
|
||||
super();
|
||||
super(false, logger);
|
||||
}
|
||||
|
||||
public LocalDate getDataCollo() {
|
||||
|
||||
@@ -9,16 +9,15 @@ import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityHashMap;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@@ -30,6 +29,9 @@ public class MtbColt extends EntityBase implements EquatableEntityInterface<MtbC
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(MtbColt.class);
|
||||
|
||||
@PK
|
||||
@SqlField(value = "gestione", maxLength = 1, nullable = false)
|
||||
private String gestione;
|
||||
@@ -181,13 +183,13 @@ public class MtbColt extends EntityBase implements EquatableEntityInterface<MtbC
|
||||
|
||||
@EntityChild
|
||||
@ReloadRow
|
||||
private List<MtbColr> mtbColr;
|
||||
private List<MtbColr> mtbColr = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
private List<MtbCols> mtbCols;
|
||||
private List<MtbCols> mtbCols = new ArrayList<>();
|
||||
|
||||
public MtbColt() {
|
||||
super();
|
||||
super(false, logger);
|
||||
}
|
||||
|
||||
public MtbColt(String gestione, LocalDate dataCollo, Integer numCollo, String serCollo) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import it.integry.ems_model.entity._enum.IBaseEnum;
|
||||
import it.integry.ems_model.exception.ConverterNotConfiguredException;
|
||||
import it.integry.ems_model.types.LatLng;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -153,15 +154,7 @@ public class SqlFieldHolder {
|
||||
else if (dtoType.equals(String.class) && sqlType.equals(byte[].class))
|
||||
converter = data -> Base64.encodeBase64String((byte[]) data);
|
||||
|
||||
else if (dtoType.equals(Date.class)) {
|
||||
converter = data -> {
|
||||
try {
|
||||
return UtilityString.parseDate(data.toString());
|
||||
} catch (Exception e) {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
} else if (sqlType.equals(Timestamp.class)) {
|
||||
else if (sqlType.equals(Timestamp.class)) {
|
||||
|
||||
if (dtoType.equals(Date.class))
|
||||
converter = data -> Date.from(((Timestamp) data).toInstant());
|
||||
@@ -172,7 +165,29 @@ public class SqlFieldHolder {
|
||||
else if (dtoType.equals(LocalDate.class))
|
||||
converter = data -> ((Timestamp) data).toLocalDateTime().toLocalDate();
|
||||
|
||||
} else if (dtoType.equals(LocalDate.class)) {
|
||||
}
|
||||
|
||||
else if (sqlType.equals(Date.class)) {
|
||||
if (dtoType.equals(Date.class))
|
||||
converter = data -> (Date) data;
|
||||
else if (dtoType.equals(Instant.class))
|
||||
converter = data -> ((Date) data).toInstant();
|
||||
else if (dtoType.equals(LocalDateTime.class))
|
||||
converter = data -> UtilityLocalDate.localDateTimeFromDate((Date) data);
|
||||
else if (dtoType.equals(LocalDate.class))
|
||||
converter = data -> UtilityLocalDate.localDateFromDate((Date) data);
|
||||
|
||||
}
|
||||
else if (dtoType.equals(Date.class)) {
|
||||
converter = data -> {
|
||||
try {
|
||||
return UtilityString.parseDate(data.toString());
|
||||
} catch (Exception e) {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (dtoType.equals(LocalDate.class)) {
|
||||
converter = data -> {
|
||||
try {
|
||||
return UtilityString.parseLocalDate(data.toString());
|
||||
|
||||
Reference in New Issue
Block a user