Migliorate logiche di Apply Default delle Entity
This commit is contained in:
@@ -60,7 +60,6 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.sql.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
@@ -1183,32 +1182,28 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
||||
|
||||
@Override
|
||||
public void applyDefault(String fieldName) throws IllegalAccessException, IOException {
|
||||
List<Field> fields = getEntityHolder().getFields(this.getClass());
|
||||
List<EntityHierarchy.Field> fields = getEntityHolder().getEntityFields(this.getClass(),
|
||||
x -> (fieldName == null || x.getFieldName().equalsIgnoreCase(fieldName)) && x.isSqlField());
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(fieldName)) {
|
||||
fields = fields.stream()
|
||||
.filter(x -> x.getName().equalsIgnoreCase(fieldName))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
for (Field field : fields) {
|
||||
SqlField sqlField = field.getAnnotation(SqlField.class);
|
||||
if (sqlField != null) {
|
||||
String defaultValue = sqlField.defaultObjectValue();
|
||||
String format = sqlField.format();
|
||||
field.setAccessible(true);
|
||||
Object object = field.get(this);
|
||||
for (EntityHierarchy.Field entityHierarchyField : fields) {
|
||||
Field field = entityHierarchyField.getField();
|
||||
SqlField sqlField = entityHierarchyField.getSqlField();
|
||||
|
||||
// NB: aiuta a rispettare la regola del default nel troncare la
|
||||
// data anche se passata dall'esterno
|
||||
if (object instanceof Date && (CommonConstants.SYSDATE.equals(format) || CommonConstants.SYSDATE.equals(defaultValue))) {
|
||||
field.set(this, DateUtils.truncate(object, Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
String defaultValue = sqlField.defaultObjectValue();
|
||||
String format = sqlField.format();
|
||||
field.setAccessible(true);
|
||||
Object object = field.get(this);
|
||||
|
||||
if (object == null && !"".equals(defaultValue)) {
|
||||
object = UtilityString.stringToObject(defaultValue, field.getType());
|
||||
field.set(this, object);
|
||||
}
|
||||
// NB: aiuta a rispettare la regola del default nel troncare la
|
||||
// data anche se passata dall'esterno
|
||||
if (object instanceof Date && (CommonConstants.SYSDATE.equals(format) || CommonConstants.SYSDATE.equals(defaultValue))) {
|
||||
field.set(this, DateUtils.truncate(object, Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
if (object == null && !defaultValue.isEmpty()) {
|
||||
object = UtilityString.stringToObject(defaultValue, field.getType());
|
||||
field.set(this, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2016,15 +2011,6 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
||||
Object prevValue = entityHierachyfield.isPrimaryKey() ? SqlFieldHolder.getSqlValueFieldAsString(originalObject, sqlField.trimSpaces()) : null;
|
||||
|
||||
if (entityHierachyfield.isSqlField()) {
|
||||
defaultValue = sqlField.defaultObjectValue();
|
||||
|
||||
SimpleDateFormat sdf = null;
|
||||
if (CommonConstants.SYSDATE.equals(defaultValue)) sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
else if (CommonConstants.TIMESTAMP.equals(defaultValue))
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
if (sdf != null) defaultValue = sdf.format(new Date());
|
||||
|
||||
maxValueLength = sqlField.maxLength();
|
||||
nullableValue = sqlField.nullable();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user