|
|
|
@@ -87,15 +87,15 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
@JsonIgnore
|
|
|
|
@JsonIgnore
|
|
|
|
protected DroolsDataCompleting dataCompleting;
|
|
|
|
protected DroolsDataCompleting dataCompleting;
|
|
|
|
|
|
|
|
|
|
|
|
//QUERY NATIVA
|
|
|
|
// QUERY NATIVA
|
|
|
|
private String nativeSql;
|
|
|
|
private String nativeSql;
|
|
|
|
|
|
|
|
|
|
|
|
//CAMPO PER ALTRE SET CHE VOGLIONO ESSERE INVIATE ALLA ENTITY.
|
|
|
|
// CAMPO PER ALTRE SET CHE VOGLIONO ESSERE INVIATE ALLA ENTITY.
|
|
|
|
// USATO TIPICAMENTE PER IL CAMBIO CHIAVE DOVE SONO PASSATE LE CHIAVI NUOVE
|
|
|
|
// USATO TIPICAMENTE PER IL CAMBIO CHIAVE DOVE SONO PASSATE LE CHIAVI NUOVE
|
|
|
|
private String otherSet="";
|
|
|
|
private String otherSet = "";
|
|
|
|
|
|
|
|
|
|
|
|
//USERNAME DI CHI STA ESEGUENDO L'OPERAZIONE
|
|
|
|
// USERNAME DI CHI STA ESEGUENDO L'OPERAZIONE
|
|
|
|
protected String username="";
|
|
|
|
protected String username = "";
|
|
|
|
|
|
|
|
|
|
|
|
protected String applicationName = "";
|
|
|
|
protected String applicationName = "";
|
|
|
|
|
|
|
|
|
|
|
|
@@ -104,7 +104,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
protected String whereCond;
|
|
|
|
protected String whereCond;
|
|
|
|
|
|
|
|
|
|
|
|
private OperationType operation;
|
|
|
|
private OperationType operation;
|
|
|
|
//private long ruleExecTime = 0L;
|
|
|
|
// private long ruleExecTime = 0L;
|
|
|
|
private Boolean loadedFromDb = false;
|
|
|
|
private Boolean loadedFromDb = false;
|
|
|
|
|
|
|
|
|
|
|
|
// BOOLEANO PER L'ESECUZIONE DEI RICALCOLI
|
|
|
|
// BOOLEANO PER L'ESECUZIONE DEI RICALCOLI
|
|
|
|
@@ -138,8 +138,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
for (Field field : fiedList) {
|
|
|
|
for (Field field : fiedList) {
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.setAccessible(true);
|
|
|
|
Object child = field.get(this);
|
|
|
|
Object child = field.get(this);
|
|
|
|
if(child != null) {
|
|
|
|
if (child != null) {
|
|
|
|
if(child instanceof List) {
|
|
|
|
if (child instanceof List) {
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) child;
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) child;
|
|
|
|
List<Object> listCloned = new ArrayList<Object>();
|
|
|
|
List<Object> listCloned = new ArrayList<Object>();
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
@@ -148,8 +148,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
field.set(cloned, listCloned);
|
|
|
|
field.set(cloned, listCloned);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
((EntityInterface)child).setEntityHolder(this.getEntityHolder());
|
|
|
|
((EntityInterface) child).setEntityHolder(this.getEntityHolder());
|
|
|
|
field.set(cloned, ((EntityInterface)child).deepClone());
|
|
|
|
field.set(cloned, ((EntityInterface) child).deepClone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -158,11 +158,11 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
for (Field field : priorityList) {
|
|
|
|
for (Field field : priorityList) {
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.setAccessible(true);
|
|
|
|
Priority priority = field.getAnnotation(Priority.class);
|
|
|
|
Priority priority = field.getAnnotation(Priority.class);
|
|
|
|
if(priority!=null) {
|
|
|
|
if (priority != null) {
|
|
|
|
Object child = field.get(this);
|
|
|
|
Object child = field.get(this);
|
|
|
|
if (child instanceof List) {
|
|
|
|
if (child instanceof List) {
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) child;
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) child;
|
|
|
|
if (list.size() > 0 ) {
|
|
|
|
if (list.size() > 0) {
|
|
|
|
List<Object> listCloned = new ArrayList<Object>();
|
|
|
|
List<Object> listCloned = new ArrayList<Object>();
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
entityInterface.setEntityHolder(this.getEntityHolder());
|
|
|
|
entityInterface.setEntityHolder(this.getEntityHolder());
|
|
|
|
@@ -171,25 +171,23 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
field.set(cloned, listCloned);
|
|
|
|
field.set(cloned, listCloned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if(child != null) {
|
|
|
|
if (child != null) {
|
|
|
|
((EntityInterface)child).setEntityHolder(this.getEntityHolder());
|
|
|
|
((EntityInterface) child).setEntityHolder(this.getEntityHolder());
|
|
|
|
field.set(cloned, ((EntityInterface)child).deepClone());
|
|
|
|
field.set(cloned, ((EntityInterface) child).deepClone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*if(child != null) {
|
|
|
|
/*
|
|
|
|
if(child instanceof List) {
|
|
|
|
* if(child != null) { if(child instanceof List) {
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) child;
|
|
|
|
* List<EntityInterface> list = (List<EntityInterface>) child;
|
|
|
|
List<Object> listCloned = new ArrayList<Object>();
|
|
|
|
* List<Object> listCloned = new ArrayList<Object>(); for
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
* (EntityInterface entityInterface : list) {
|
|
|
|
entityInterface.setEntityHolder(this.getEntityHolder());
|
|
|
|
* entityInterface.setEntityHolder(this.getEntityHolder());
|
|
|
|
listCloned.add(entityInterface.deepClone());
|
|
|
|
* listCloned.add(entityInterface.deepClone()); }
|
|
|
|
}
|
|
|
|
* field.set(cloned, listCloned); } else {
|
|
|
|
field.set(cloned, listCloned);
|
|
|
|
* ((EntityInterface)child).setEntityHolder(this.getEntityHolder
|
|
|
|
} else {
|
|
|
|
* ()); field.set(cloned, ((EntityInterface)child).deepClone());
|
|
|
|
((EntityInterface)child).setEntityHolder(this.getEntityHolder());
|
|
|
|
* } }
|
|
|
|
field.set(cloned, ((EntityInterface)child).deepClone());
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -219,7 +217,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
child.trimPK();
|
|
|
|
child.trimPK();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if(childs != null) {
|
|
|
|
} else if (childs != null) {
|
|
|
|
Object object = field.get(this);
|
|
|
|
Object object = field.get(this);
|
|
|
|
if (object != null) {
|
|
|
|
if (object != null) {
|
|
|
|
if (object instanceof List) {
|
|
|
|
if (object instanceof List) {
|
|
|
|
@@ -247,9 +245,9 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getTableName(){
|
|
|
|
public String getTableName() {
|
|
|
|
Table t = getClass().getAnnotation(Table.class);
|
|
|
|
Table t = getClass().getAnnotation(Table.class);
|
|
|
|
if(t != null)
|
|
|
|
if (t != null)
|
|
|
|
return t.value();
|
|
|
|
return t.value();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
return "";
|
|
|
|
@@ -268,7 +266,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setUsername(String username) {
|
|
|
|
public void setUsername(String username) {
|
|
|
|
if(UtilityString.isNullOrEmpty(username))
|
|
|
|
if (UtilityString.isNullOrEmpty(username))
|
|
|
|
username = "";
|
|
|
|
username = "";
|
|
|
|
this.username = username;
|
|
|
|
this.username = username;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -282,14 +280,15 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setApplicationNameDB(Connection conn) throws Exception {
|
|
|
|
public void setApplicationNameDB(Connection conn) throws Exception {
|
|
|
|
if (UtilityDB.existDatabaseObject(conn, "azienda", TypeDbObject.TABLE)){
|
|
|
|
if (UtilityDB.existDatabaseObject(conn, "azienda", TypeDbObject.TABLE)) {
|
|
|
|
String sql ="SELECT application_name FROM azienda";
|
|
|
|
String sql = "SELECT application_name FROM azienda";
|
|
|
|
PreparedStatement ps = conn.prepareStatement(sql);
|
|
|
|
PreparedStatement ps = conn.prepareStatement(sql);
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
if (rs.next() ) {
|
|
|
|
if (rs.next()) {
|
|
|
|
this.applicationName = rs.getString(1);
|
|
|
|
this.applicationName = rs.getString(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rs.close();ps.close();
|
|
|
|
rs.close();
|
|
|
|
|
|
|
|
ps.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -364,7 +363,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setRecalcColumns(List<String> recalcColumns) throws Exception {
|
|
|
|
public void setRecalcColumns(List<String> recalcColumns) throws Exception {
|
|
|
|
if(recalcColumns == null || recalcColumns.isEmpty())
|
|
|
|
if (recalcColumns == null || recalcColumns.isEmpty())
|
|
|
|
this.recalcColumns = new ArrayList<String>();
|
|
|
|
this.recalcColumns = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
|
|
for (String sqlField : recalcColumns) {
|
|
|
|
for (String sqlField : recalcColumns) {
|
|
|
|
@@ -393,18 +392,18 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
public Object select(Connection connection) throws Exception {
|
|
|
|
public Object select(Connection connection) throws Exception {
|
|
|
|
String query = "";
|
|
|
|
String query = "";
|
|
|
|
if(nativeSql != null){
|
|
|
|
if (nativeSql != null) {
|
|
|
|
|
|
|
|
|
|
|
|
String columnList;
|
|
|
|
String columnList;
|
|
|
|
int sIdx = nativeSql.toUpperCase().indexOf("SELECT");
|
|
|
|
int sIdx = nativeSql.toUpperCase().indexOf("SELECT");
|
|
|
|
int fIdx = nativeSql.toUpperCase().indexOf("FROM");
|
|
|
|
int fIdx = nativeSql.toUpperCase().indexOf("FROM");
|
|
|
|
int wIdx = nativeSql.toUpperCase().indexOf("WHERE") ;
|
|
|
|
int wIdx = nativeSql.toUpperCase().indexOf("WHERE");
|
|
|
|
|
|
|
|
|
|
|
|
String fields = nativeSql.substring(sIdx + "SELECT".length(), fIdx).trim();
|
|
|
|
String fields = nativeSql.substring(sIdx + "SELECT".length(), fIdx).trim();
|
|
|
|
String table = nativeSql.substring(fIdx + "FROM".length() , wIdx).trim();
|
|
|
|
String table = nativeSql.substring(fIdx + "FROM".length(), wIdx).trim();
|
|
|
|
String where = nativeSql.substring(wIdx + "WHERE".length());
|
|
|
|
String where = nativeSql.substring(wIdx + "WHERE".length());
|
|
|
|
|
|
|
|
|
|
|
|
if("*".equals(fields)) {
|
|
|
|
if ("*".equals(fields)) {
|
|
|
|
columnList = entityHolder.getColumnList(this.getClass());
|
|
|
|
columnList = entityHolder.getColumnList(this.getClass());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
List<String> colList = new ArrayList<String>();
|
|
|
|
List<String> colList = new ArrayList<String>();
|
|
|
|
@@ -422,7 +421,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
String wherePK = entityHolder.getWherePK(this);
|
|
|
|
String wherePK = entityHolder.getWherePK(this);
|
|
|
|
String columnList = entityHolder.getColumnList(this.getClass());
|
|
|
|
String columnList = entityHolder.getColumnList(this.getClass());
|
|
|
|
if (wherePK != "")
|
|
|
|
if (wherePK != "")
|
|
|
|
query = "SELECT "+columnList+", '" + getTableName() + "' as type FROM " + getTableName() + " WHERE " + wherePK;
|
|
|
|
query = "SELECT " + columnList + ", '" + getTableName() + "' as type FROM " + getTableName() + " WHERE "
|
|
|
|
|
|
|
|
+ wherePK;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -451,7 +451,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
String json = writer.toString();
|
|
|
|
String json = writer.toString();
|
|
|
|
JsonArray array = new JsonParser().parse(json).getAsJsonArray();
|
|
|
|
JsonArray array = new JsonParser().parse(json).getAsJsonArray();
|
|
|
|
if(array.size() == 0)
|
|
|
|
if (array.size() == 0)
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
return json;
|
|
|
|
return json;
|
|
|
|
@@ -462,7 +462,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
wherePK = entityHolder.getWherePK(entity);
|
|
|
|
wherePK = entityHolder.getWherePK(entity);
|
|
|
|
|
|
|
|
|
|
|
|
String columnList = entityHolder.getColumnList(entity.getClass());
|
|
|
|
String columnList = entityHolder.getColumnList(entity.getClass());
|
|
|
|
String query = "SELECT "+columnList+" FROM " + entity.getTableName() + " WHERE " + wherePK;
|
|
|
|
String query = "SELECT " + columnList + " FROM " + entity.getTableName() + " WHERE " + wherePK;
|
|
|
|
PreparedStatement ps = connection.prepareStatement(query);
|
|
|
|
PreparedStatement ps = connection.prepareStatement(query);
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
EntityBase entityDB = mergeEntityDBToObject(rs, entity);
|
|
|
|
EntityBase entityDB = mergeEntityDBToObject(rs, entity);
|
|
|
|
@@ -470,7 +470,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
return entityDB;
|
|
|
|
return entityDB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//seleziona le righe da db di un detail
|
|
|
|
// seleziona le righe da db di un detail
|
|
|
|
public List<EntityBase> selectEntityRowList(Connection connection, EntityBase entity,
|
|
|
|
public List<EntityBase> selectEntityRowList(Connection connection, EntityBase entity,
|
|
|
|
Class<? extends EntityBase> rowClass, String tableName, Document doc) throws Exception {
|
|
|
|
Class<? extends EntityBase> rowClass, String tableName, Document doc) throws Exception {
|
|
|
|
String whereConds = UtilityXML.XML2WhereCond(doc);
|
|
|
|
String whereConds = UtilityXML.XML2WhereCond(doc);
|
|
|
|
@@ -489,7 +489,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
private List<EntityBase> selectEntityRowListInternal(Connection connection, EntityBase entity,
|
|
|
|
private List<EntityBase> selectEntityRowListInternal(Connection connection, EntityBase entity,
|
|
|
|
Class<? extends EntityBase> rowClass, String tableName, String whereConds) throws Exception {
|
|
|
|
Class<? extends EntityBase> rowClass, String tableName, String whereConds) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
if(!UtilityString.isNullOrEmpty(whereConds)) {
|
|
|
|
if (!UtilityString.isNullOrEmpty(whereConds)) {
|
|
|
|
whereConds = " AND " + whereConds;
|
|
|
|
whereConds = " AND " + whereConds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -498,7 +498,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
wherePK = entityHolder.getWherePK(entity);
|
|
|
|
wherePK = entityHolder.getWherePK(entity);
|
|
|
|
|
|
|
|
|
|
|
|
String columnList = entityHolder.getColumnList(rowClass, true);
|
|
|
|
String columnList = entityHolder.getColumnList(rowClass, true);
|
|
|
|
query = "SELECT "+columnList+" FROM " + tableName + " WHERE " + wherePK + whereConds;
|
|
|
|
query = "SELECT " + columnList + " FROM " + tableName + " WHERE " + wherePK + whereConds;
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement ps = connection.prepareStatement(query);
|
|
|
|
PreparedStatement ps = connection.prepareStatement(query);
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
@@ -507,12 +507,12 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean equalsDB(EntityBase entityCmp) throws Exception {
|
|
|
|
public boolean equalsDB(EntityBase entityCmp) throws Exception {
|
|
|
|
if(this.getClass().equals(entityCmp.getClass())) {
|
|
|
|
if (this.getClass().equals(entityCmp.getClass())) {
|
|
|
|
List<String> pks = (List<String>) entityHolder.getPkField(this.getClass());
|
|
|
|
List<String> pks = (List<String>) entityHolder.getPkField(this.getClass());
|
|
|
|
for (String pk : pks) {
|
|
|
|
for (String pk : pks) {
|
|
|
|
Field field = entityHolder.getFieldBySql(this.getClass().getSimpleName(), pk);
|
|
|
|
Field field = entityHolder.getFieldBySql(this.getClass().getSimpleName(), pk);
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.setAccessible(true);
|
|
|
|
if(!field.get(this).equals(field.get(entityCmp)))
|
|
|
|
if (!field.get(this).equals(field.get(entityCmp)))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
@@ -521,30 +521,30 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private EntityBase mergeEntityDBToObject(ResultSet rs, EntityBase entity) throws Exception {
|
|
|
|
private EntityBase mergeEntityDBToObject(ResultSet rs, EntityBase entity) throws Exception {
|
|
|
|
if(rs != null){
|
|
|
|
if (rs != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if(rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
|
|
for (int i=0;i<rsmd.getColumnCount();i++) {
|
|
|
|
for (int i = 0; i < rsmd.getColumnCount(); i++) {
|
|
|
|
String columnName = rsmd.getColumnName(i + 1);
|
|
|
|
String columnName = rsmd.getColumnName(i + 1);
|
|
|
|
Object columnValue = rs.getObject(i + 1);
|
|
|
|
Object columnValue = rs.getObject(i + 1);
|
|
|
|
|
|
|
|
|
|
|
|
Field field = entity.getClass().getDeclaredField(columnName);
|
|
|
|
Field field = entity.getClass().getDeclaredField(columnName);
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.setAccessible(true);
|
|
|
|
Object object = field.get(entity);
|
|
|
|
Object object = field.get(entity);
|
|
|
|
if(object == null && columnValue != null){
|
|
|
|
if (object == null && columnValue != null) {
|
|
|
|
if(field.isAnnotationPresent(it.integry.ems.annotation.Clob.class))
|
|
|
|
if (field.isAnnotationPresent(it.integry.ems.annotation.Clob.class))
|
|
|
|
columnValue = Base64.encodeBase64String(columnValue.toString().getBytes());
|
|
|
|
columnValue = Base64.encodeBase64String(columnValue.toString().getBytes());
|
|
|
|
field.set(entity, SqlFieldHolder.applyConvert(columnValue, field.getGenericType()));
|
|
|
|
field.set(entity, SqlFieldHolder.applyConvert(columnValue, field.getGenericType()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entity;
|
|
|
|
return entity;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if(entity.getOperation() == OperationType.SELECT_OBJECT)
|
|
|
|
if (entity.getOperation() == OperationType.SELECT_OBJECT)
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
else if(entity.getOperation() == OperationType.INSERT_OR_UPDATE)
|
|
|
|
else if (entity.getOperation() == OperationType.INSERT_OR_UPDATE)
|
|
|
|
return entity;
|
|
|
|
return entity;
|
|
|
|
else if(entity.getOperation() == OperationType.SUBSTITUTE)
|
|
|
|
else if (entity.getOperation() == OperationType.SUBSTITUTE)
|
|
|
|
return entity;
|
|
|
|
return entity;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
throw new Exception("Dati entity " + entity.getTableName() + " non trovati su DB");
|
|
|
|
throw new Exception("Dati entity " + entity.getTableName() + " non trovati su DB");
|
|
|
|
@@ -561,9 +561,9 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
Object entity = null;
|
|
|
|
Object entity = null;
|
|
|
|
String[] split = sqlField.split("\\.");
|
|
|
|
String[] split = sqlField.split("\\.");
|
|
|
|
if(split.length > 1) {
|
|
|
|
if (split.length > 1) {
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
if(f==null)
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
entity = f.get(this);
|
|
|
|
entity = f.get(this);
|
|
|
|
@@ -571,35 +571,35 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
entity = this.clone();
|
|
|
|
entity = this.clone();
|
|
|
|
|
|
|
|
|
|
|
|
if(entity instanceof List) {
|
|
|
|
if (entity instanceof List) {
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) entity;
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) entity;
|
|
|
|
List<EntityInterface> listCloned = new ArrayList<EntityInterface>();
|
|
|
|
List<EntityInterface> listCloned = new ArrayList<EntityInterface>();
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
EntityInterface entityCloned = entityInterface.clone();
|
|
|
|
EntityInterface entityCloned = entityInterface.clone();
|
|
|
|
|
|
|
|
|
|
|
|
Field f = entityCloned.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
Field f = entityCloned.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
if(f==null)
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
List<String> exclCol = (List<String>)f.get(entityCloned);
|
|
|
|
List<String> exclCol = (List<String>) f.get(entityCloned);
|
|
|
|
List<String> exclColCloned = new ArrayList<String>();
|
|
|
|
List<String> exclColCloned = new ArrayList<String>();
|
|
|
|
exclColCloned.addAll(exclCol);
|
|
|
|
exclColCloned.addAll(exclCol);
|
|
|
|
//cloning
|
|
|
|
// cloning
|
|
|
|
exclColCloned.add(sqlField);
|
|
|
|
exclColCloned.add(sqlField);
|
|
|
|
f.set(entityCloned, exclColCloned);
|
|
|
|
f.set(entityCloned, exclColCloned);
|
|
|
|
listCloned.add(entityCloned);
|
|
|
|
listCloned.add(entityCloned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
if(f==null)
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.set(this, listCloned);
|
|
|
|
f.set(this, listCloned);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Field f = entity.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
Field f = entity.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
if(f==null)
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
List<String> exclCol = (List<String>)f.get(entity);
|
|
|
|
List<String> exclCol = (List<String>) f.get(entity);
|
|
|
|
exclCol.add(sqlField);
|
|
|
|
exclCol.add(sqlField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -609,9 +609,9 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
Object entity = null;
|
|
|
|
Object entity = null;
|
|
|
|
String[] split = sqlField.trim().split("\\.");
|
|
|
|
String[] split = sqlField.trim().split("\\.");
|
|
|
|
if(split.length > 1) {
|
|
|
|
if (split.length > 1) {
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
if(f==null)
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
throw new Exception("Impossibile escludere: campo " + sqlField + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
entity = f.get(this);
|
|
|
|
entity = f.get(this);
|
|
|
|
@@ -619,10 +619,10 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
entity = this;
|
|
|
|
entity = this;
|
|
|
|
|
|
|
|
|
|
|
|
if(entity instanceof List) {
|
|
|
|
if (entity instanceof List) {
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) entity;
|
|
|
|
List<EntityInterface> list = (List<EntityInterface>) entity;
|
|
|
|
|
|
|
|
|
|
|
|
if("*".equals(sqlField) && split.length > 1) {
|
|
|
|
if ("*".equals(sqlField) && split.length > 1) {
|
|
|
|
List cloneList = (List) ((ArrayList) entity).clone();
|
|
|
|
List cloneList = (List) ((ArrayList) entity).clone();
|
|
|
|
cloneList.clear();
|
|
|
|
cloneList.clear();
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
Field f = this.getClass().getDeclaredField(UtilityString.sqlToField(split[0]));
|
|
|
|
@@ -632,32 +632,34 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
for (EntityInterface entityInterface : list) {
|
|
|
|
|
|
|
|
|
|
|
|
Field f = entityInterface.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
Field f = entityInterface.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
if(f==null)
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("Impossibile escludere: campo " + columnName + " non presente nella entity");
|
|
|
|
throw new Exception(
|
|
|
|
|
|
|
|
"Impossibile escludere: campo " + columnName + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
|
|
Field fieldToSetRecalc = entityInterface.getClass().getDeclaredField(UtilityString.sqlToField(sqlField));
|
|
|
|
Field fieldToSetRecalc = entityInterface.getClass()
|
|
|
|
if(fieldToSetRecalc != null) {
|
|
|
|
.getDeclaredField(UtilityString.sqlToField(sqlField));
|
|
|
|
|
|
|
|
if (fieldToSetRecalc != null) {
|
|
|
|
fieldToSetRecalc.setAccessible(true);
|
|
|
|
fieldToSetRecalc.setAccessible(true);
|
|
|
|
fieldToSetRecalc.set(entityInterface, null);
|
|
|
|
fieldToSetRecalc.set(entityInterface, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<String> exclCol = (List<String>)f.get(entityInterface);
|
|
|
|
List<String> exclCol = (List<String>) f.get(entityInterface);
|
|
|
|
List<String> exclColCloned = new ArrayList<String>();
|
|
|
|
List<String> exclColCloned = new ArrayList<String>();
|
|
|
|
exclColCloned.addAll(exclCol);
|
|
|
|
exclColCloned.addAll(exclCol);
|
|
|
|
//cloning
|
|
|
|
// cloning
|
|
|
|
exclColCloned.add(sqlField);
|
|
|
|
exclColCloned.add(sqlField);
|
|
|
|
f.set(entityInterface, exclColCloned);
|
|
|
|
f.set(entityInterface, exclColCloned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Field f = entity.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
Field f = entity.getClass().getSuperclass().getDeclaredField(columnName);
|
|
|
|
if(f==null)
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("Impossibile escludere: campo " + columnName + " non presente nella entity");
|
|
|
|
throw new Exception("Impossibile escludere: campo " + columnName + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
|
|
Field fieldToSetRecalc = entity.getClass().getDeclaredField(UtilityString.sqlToField(sqlField));
|
|
|
|
Field fieldToSetRecalc = entity.getClass().getDeclaredField(UtilityString.sqlToField(sqlField));
|
|
|
|
if(fieldToSetRecalc != null) {
|
|
|
|
if (fieldToSetRecalc != null) {
|
|
|
|
fieldToSetRecalc.setAccessible(true);
|
|
|
|
fieldToSetRecalc.setAccessible(true);
|
|
|
|
if (fieldToSetRecalc.getAnnotation(EntityChild.class) != null) {
|
|
|
|
if (fieldToSetRecalc.getAnnotation(EntityChild.class) != null) {
|
|
|
|
ArrayList<EntityBase> rows = new ArrayList<EntityBase>();
|
|
|
|
ArrayList<EntityBase> rows = new ArrayList<EntityBase>();
|
|
|
|
@@ -666,7 +668,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
fieldToSetRecalc.set(entity, null);
|
|
|
|
fieldToSetRecalc.set(entity, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<String> exclCol = (List<String>)f.get(entity);
|
|
|
|
List<String> exclCol = (List<String>) f.get(entity);
|
|
|
|
exclCol.add(sqlField);
|
|
|
|
exclCol.add(sqlField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -679,41 +681,44 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
private void executeManage() throws Exception {
|
|
|
|
private void executeManage() throws Exception {
|
|
|
|
managePriorityPre();
|
|
|
|
managePriorityPre();
|
|
|
|
if(getOperation() == OperationType.NO_OP) {
|
|
|
|
if (getOperation() == OperationType.NO_OP) {
|
|
|
|
// FABIO 20.1.2017: se la entity era in sincronizzazione cond altri DB ed aveva NO_OP sul master e sulle righe SUBSTITUTE
|
|
|
|
// FABIO 20.1.2017: se la entity era in sincronizzazione cond altri
|
|
|
|
// invocando manageChilds andava a cancellare le righe del detail dei database in sincronizzazione, infatti anche il
|
|
|
|
// DB ed aveva NO_OP sul master e sulle righe SUBSTITUTE
|
|
|
|
// commento dello stesso metodo più sotto era stato fatto da Sante, ma evidentemente gli era sviggito il problema su NO_OP
|
|
|
|
// invocando manageChilds andava a cancellare le righe del detail
|
|
|
|
// manageChilds();
|
|
|
|
// dei database in sincronizzazione, infatti anche il
|
|
|
|
|
|
|
|
// commento dello stesso metodo più sotto era stato fatto da Sante,
|
|
|
|
|
|
|
|
// ma evidentemente gli era sviggito il problema su NO_OP
|
|
|
|
|
|
|
|
// manageChilds();
|
|
|
|
updateChilds();
|
|
|
|
updateChilds();
|
|
|
|
} else if(getOperation() == OperationType.SUBSTITUTE){
|
|
|
|
} else if (getOperation() == OperationType.SUBSTITUTE) {
|
|
|
|
deleteChilds();
|
|
|
|
deleteChilds();
|
|
|
|
deleteEntity();
|
|
|
|
deleteEntity();
|
|
|
|
insertEntity();
|
|
|
|
insertEntity();
|
|
|
|
insertChilds();
|
|
|
|
insertChilds();
|
|
|
|
} else if(getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
} else if (getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
Boolean insertOk = false, updateOk = false;
|
|
|
|
Boolean insertOk = false, updateOk = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
insertEntity();
|
|
|
|
insertEntity();
|
|
|
|
insertOk = true;
|
|
|
|
insertOk = true;
|
|
|
|
}catch(SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
//pk violation code o index unique sql server or mysql
|
|
|
|
// pk violation code o index unique sql server or mysql
|
|
|
|
if(e.getErrorCode() == 2627 || e.getErrorCode() == 2601 || e.getErrorCode() == 1062) {
|
|
|
|
if (e.getErrorCode() == 2627 || e.getErrorCode() == 2601 || e.getErrorCode() == 1062) {
|
|
|
|
updateEntity();
|
|
|
|
updateEntity();
|
|
|
|
updateOk = true;
|
|
|
|
updateOk = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(insertOk)
|
|
|
|
if (insertOk)
|
|
|
|
insertChilds();
|
|
|
|
insertChilds();
|
|
|
|
else if(updateOk)
|
|
|
|
else if (updateOk)
|
|
|
|
updateChilds();
|
|
|
|
updateChilds();
|
|
|
|
//manageChilds();
|
|
|
|
// manageChilds();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
manage();
|
|
|
|
manage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
managePriorityPost();
|
|
|
|
managePriorityPost();
|
|
|
|
if(this.getClass().getAnnotation(Master.class) != null)
|
|
|
|
if (this.getClass().getAnnotation(Master.class) != null)
|
|
|
|
checkSyncOffline();
|
|
|
|
checkSyncOffline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -722,12 +727,13 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
+ " WHERE object_id = OBJECT_ID(N'dbo.stb_publications_detail') AND type in (N'U')";
|
|
|
|
+ " WHERE object_id = OBJECT_ID(N'dbo.stb_publications_detail') AND type in (N'U')";
|
|
|
|
PreparedStatement psExist = (PreparedStatement) connection.prepareStatement(sqlExist);
|
|
|
|
PreparedStatement psExist = (PreparedStatement) connection.prepareStatement(sqlExist);
|
|
|
|
ResultSet rsExist = psExist.executeQuery();
|
|
|
|
ResultSet rsExist = psExist.executeQuery();
|
|
|
|
if(rsExist.next()) {
|
|
|
|
if (rsExist.next()) {
|
|
|
|
//OFFLINE
|
|
|
|
// OFFLINE
|
|
|
|
logger.debug("CHECK SYNC OFFLINE ABILITATA (DB " + connection.getCatalog() + ") SU " + getTableName().toUpperCase());
|
|
|
|
logger.debug("CHECK SYNC OFFLINE ABILITATA (DB " + connection.getCatalog() + ") SU "
|
|
|
|
|
|
|
|
+ getTableName().toUpperCase());
|
|
|
|
PreparedStatement ps = (PreparedStatement) connection
|
|
|
|
PreparedStatement ps = (PreparedStatement) connection
|
|
|
|
.prepareStatement("SELECT publication_id from stb_publications_detail "
|
|
|
|
.prepareStatement("SELECT publication_id from stb_publications_detail " + "where entity_name='"
|
|
|
|
+ "where entity_name='" + getTableName().toUpperCase() + "' and syncronize='R'");
|
|
|
|
+ getTableName().toUpperCase() + "' and syncronize='R'");
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
ResultSet rs = ps.executeQuery();
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
logger.debug("SYNC OFFLINE ABILITATA SU " + getTableName().toUpperCase());
|
|
|
|
logger.debug("SYNC OFFLINE ABILITATA SU " + getTableName().toUpperCase());
|
|
|
|
@@ -742,7 +748,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void manageChilds() throws Exception {
|
|
|
|
private void manageChilds() throws Exception {
|
|
|
|
//ordinamento dei campi secondo legami di inserimento
|
|
|
|
// ordinamento dei campi secondo legami di inserimento
|
|
|
|
List<Field> fields = entityHolder.getEntityChildField(getClass());
|
|
|
|
List<Field> fields = entityHolder.getEntityChildField(getClass());
|
|
|
|
Collections.sort(fields, new EntityChildComparator());
|
|
|
|
Collections.sort(fields, new EntityChildComparator());
|
|
|
|
|
|
|
|
|
|
|
|
@@ -757,7 +763,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < chain.size(); i++) {
|
|
|
|
for (int i = 0; i < chain.size(); i++) {
|
|
|
|
EntityBase child = chain.get(i);
|
|
|
|
EntityBase child = chain.get(i);
|
|
|
|
child.manageWithParentConnection(connection, child.getOperation(), dataCompleting, entityHolder);
|
|
|
|
child.manageWithParentConnection(connection, child.getOperation(), dataCompleting,
|
|
|
|
|
|
|
|
entityHolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
EntityBase child = ((EntityBase) object);
|
|
|
|
EntityBase child = ((EntityBase) object);
|
|
|
|
@@ -793,18 +800,17 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void settingPriority(EntityBase child, OperationType operation, Boolean copyPk) throws Exception {
|
|
|
|
private void settingPriority(EntityBase child, OperationType operation, Boolean copyPk) throws Exception {
|
|
|
|
//SETTING DEGLI HOLDER
|
|
|
|
// SETTING DEGLI HOLDER
|
|
|
|
child.setEntityHolder(entityHolder);
|
|
|
|
child.setEntityHolder(entityHolder);
|
|
|
|
child.setCompletingManager(dataCompleting);
|
|
|
|
child.setCompletingManager(dataCompleting);
|
|
|
|
|
|
|
|
|
|
|
|
if(copyPk)
|
|
|
|
if (copyPk)
|
|
|
|
child.setParentPKAndImportFromParent(this);
|
|
|
|
child.setParentPKAndImportFromParent(this);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
child.setImportFromParent(this);
|
|
|
|
child.setImportFromParent(this);
|
|
|
|
///////////////////////////////////////
|
|
|
|
///////////////////////////////////////
|
|
|
|
if(child.getOperation() == OperationType.INSERT && child.select(connection) != null){
|
|
|
|
if (child.getOperation() == OperationType.INSERT && child.select(connection) != null) {
|
|
|
|
child.setOperation(OperationType.UPDATE);
|
|
|
|
child.setOperation(OperationType.UPDATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -838,7 +844,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void manageWithParentConnection(Connection connection, OperationType op, DroolsDataCompleting dataCompleting) throws Exception {
|
|
|
|
private void manageWithParentConnection(Connection connection, OperationType op,
|
|
|
|
|
|
|
|
DroolsDataCompleting dataCompleting) throws Exception {
|
|
|
|
this.connection = connection;
|
|
|
|
this.connection = connection;
|
|
|
|
this.dataCompleting = dataCompleting;
|
|
|
|
this.dataCompleting = dataCompleting;
|
|
|
|
if (getOperation() == null)
|
|
|
|
if (getOperation() == null)
|
|
|
|
@@ -847,12 +854,14 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
executeManage();
|
|
|
|
executeManage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void manageWithParentConnection(Connection connection, OperationType op, DroolsDataCompleting dataCompleting, EntityPropertyHolder propertyHolder) throws Exception {
|
|
|
|
public void manageWithParentConnection(Connection connection, OperationType op, DroolsDataCompleting dataCompleting,
|
|
|
|
|
|
|
|
EntityPropertyHolder propertyHolder) throws Exception {
|
|
|
|
this.entityHolder = propertyHolder;
|
|
|
|
this.entityHolder = propertyHolder;
|
|
|
|
manageWithParentConnection(connection, op, dataCompleting);
|
|
|
|
manageWithParentConnection(connection, op, dataCompleting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void manageWithParentConnection(Connection connection, OperationType op, DroolsDataCompleting dataCompleting, EntityPropertyHolder propertyHolder, String applicationName) throws Exception {
|
|
|
|
public void manageWithParentConnection(Connection connection, OperationType op, DroolsDataCompleting dataCompleting,
|
|
|
|
|
|
|
|
EntityPropertyHolder propertyHolder, String applicationName) throws Exception {
|
|
|
|
this.entityHolder = propertyHolder;
|
|
|
|
this.entityHolder = propertyHolder;
|
|
|
|
this.applicationName = applicationName;
|
|
|
|
this.applicationName = applicationName;
|
|
|
|
manageWithParentConnection(connection, op, dataCompleting);
|
|
|
|
manageWithParentConnection(connection, op, dataCompleting);
|
|
|
|
@@ -870,10 +879,10 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.setAccessible(true);
|
|
|
|
Object object = field.get(this);
|
|
|
|
Object object = field.get(this);
|
|
|
|
|
|
|
|
|
|
|
|
//NB: aiuta a rispettare la regola del default nel troncare la data anche se passata dall'esterno
|
|
|
|
// NB: aiuta a rispettare la regola del default nel troncare la
|
|
|
|
if(object != null && object instanceof Date &&
|
|
|
|
// data anche se passata dall'esterno
|
|
|
|
(CommonConstants.SYSDATE.equals(format) ||
|
|
|
|
if (object != null && object instanceof Date
|
|
|
|
CommonConstants.SYSDATE.equals(defaultValue))) {
|
|
|
|
&& (CommonConstants.SYSDATE.equals(format) || CommonConstants.SYSDATE.equals(defaultValue))) {
|
|
|
|
field.set(this, DateUtils.truncate(object, Calendar.DAY_OF_MONTH));
|
|
|
|
field.set(this, DateUtils.truncate(object, Calendar.DAY_OF_MONTH));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -891,21 +900,21 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
public void dataCompletingSync(Connection connection) throws Exception {
|
|
|
|
public void dataCompletingSync(Connection connection) throws Exception {
|
|
|
|
if (UtilityString.isNullOrEmpty(getNativeSql()) && getOperation() != OperationType.DELETE) {
|
|
|
|
if (UtilityString.isNullOrEmpty(getNativeSql()) && getOperation() != OperationType.DELETE) {
|
|
|
|
|
|
|
|
|
|
|
|
//controllo sui campi fired di testata
|
|
|
|
// controllo sui campi fired di testata
|
|
|
|
if(getOperation() == OperationType.INSERT || (entityHolder.getFieldToFireMap(getClass().getSimpleName()) != null &&
|
|
|
|
if (getOperation() == OperationType.INSERT
|
|
|
|
!entityHolder.getFieldToFireMap(getClass().getSimpleName()).isEmpty())) {
|
|
|
|
|| (entityHolder.getFieldToFireMap(getClass().getSimpleName()) != null
|
|
|
|
|
|
|
|
&& !entityHolder.getFieldToFireMap(getClass().getSimpleName()).isEmpty())) {
|
|
|
|
executeRecalc = true;
|
|
|
|
executeRecalc = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (getOperation() == OperationType.UPDATE ||
|
|
|
|
if (getOperation() == OperationType.UPDATE || getOperation() == OperationType.SUBSTITUTE
|
|
|
|
getOperation() == OperationType.SUBSTITUTE ||
|
|
|
|
|| getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
|
|
|
|
selectAndMergeEntity(connection, this);
|
|
|
|
selectAndMergeEntity(connection, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dataCompleting.invokeCheckRules(this, connection, username);
|
|
|
|
dataCompleting.invokeCheckRules(this, connection, username);
|
|
|
|
|
|
|
|
|
|
|
|
if(getNativeSql() == null)
|
|
|
|
if (getNativeSql() == null)
|
|
|
|
dataCompleting.complete(this, connection, username);
|
|
|
|
dataCompleting.complete(this, connection, username);
|
|
|
|
|
|
|
|
|
|
|
|
Field[] fields = getClass().getDeclaredFields();
|
|
|
|
Field[] fields = getClass().getDeclaredFields();
|
|
|
|
@@ -917,8 +926,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
if (object instanceof List) {
|
|
|
|
if (object instanceof List) {
|
|
|
|
List<EntityBase> list = ((List<EntityBase>) object);
|
|
|
|
List<EntityBase> list = ((List<EntityBase>) object);
|
|
|
|
|
|
|
|
|
|
|
|
if(!executeRecalc) {
|
|
|
|
if (!executeRecalc) {
|
|
|
|
//caricamento delle righe
|
|
|
|
// caricamento delle righe
|
|
|
|
selectChildFromDb(list);
|
|
|
|
selectChildFromDb(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -933,7 +942,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//chiamata alle regole di ricalcolo
|
|
|
|
// chiamata alle regole di ricalcolo
|
|
|
|
dataCompleting.completePostRules(this, connection, username);
|
|
|
|
dataCompleting.completePostRules(this, connection, username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -943,21 +952,21 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
public void dataCompleting(Connection connection) throws Exception {
|
|
|
|
public void dataCompleting(Connection connection) throws Exception {
|
|
|
|
if (UtilityString.isNullOrEmpty(getNativeSql()) && getOperation() != OperationType.DELETE) {
|
|
|
|
if (UtilityString.isNullOrEmpty(getNativeSql()) && getOperation() != OperationType.DELETE) {
|
|
|
|
|
|
|
|
|
|
|
|
//controllo sui campi fired di testata
|
|
|
|
// controllo sui campi fired di testata
|
|
|
|
if(getOperation() == OperationType.INSERT || (entityHolder.getFieldToFireMap(getClass().getSimpleName()) != null &&
|
|
|
|
if (getOperation() == OperationType.INSERT
|
|
|
|
!entityHolder.getFieldToFireMap(getClass().getSimpleName()).isEmpty())) {
|
|
|
|
|| (entityHolder.getFieldToFireMap(getClass().getSimpleName()) != null
|
|
|
|
|
|
|
|
&& !entityHolder.getFieldToFireMap(getClass().getSimpleName()).isEmpty())) {
|
|
|
|
executeRecalc = true;
|
|
|
|
executeRecalc = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (getOperation() == OperationType.UPDATE ||
|
|
|
|
if (getOperation() == OperationType.UPDATE || getOperation() == OperationType.SUBSTITUTE
|
|
|
|
getOperation() == OperationType.SUBSTITUTE ||
|
|
|
|
|| getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
|
|
|
|
selectAndMergeEntity(connection, this);
|
|
|
|
selectAndMergeEntity(connection, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dataCompleting.invokeCheckRules(this, connection, username);
|
|
|
|
dataCompleting.invokeCheckRules(this, connection, username);
|
|
|
|
|
|
|
|
|
|
|
|
if(getNativeSql() == null)
|
|
|
|
if (getNativeSql() == null)
|
|
|
|
dataCompleting.complete(this, connection, username);
|
|
|
|
dataCompleting.complete(this, connection, username);
|
|
|
|
|
|
|
|
|
|
|
|
Field[] fields = getClass().getDeclaredFields();
|
|
|
|
Field[] fields = getClass().getDeclaredFields();
|
|
|
|
@@ -969,8 +978,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
if (object instanceof List) {
|
|
|
|
if (object instanceof List) {
|
|
|
|
List<EntityBase> list = ((List<EntityBase>) object);
|
|
|
|
List<EntityBase> list = ((List<EntityBase>) object);
|
|
|
|
|
|
|
|
|
|
|
|
if(!executeRecalc) {
|
|
|
|
if (!executeRecalc) {
|
|
|
|
//caricamento delle righe
|
|
|
|
// caricamento delle righe
|
|
|
|
selectChildFromDb(list);
|
|
|
|
selectChildFromDb(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -985,20 +994,20 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//chiamata alle regole di ricalcolo
|
|
|
|
// chiamata alle regole di ricalcolo
|
|
|
|
dataCompleting.completePostRules(this, connection, username);
|
|
|
|
dataCompleting.completePostRules(this, connection, username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void selectChildFromDb(List<EntityBase> list) throws Exception {
|
|
|
|
private void selectChildFromDb(List<EntityBase> list) throws Exception {
|
|
|
|
//controllo sui campi fired di riga
|
|
|
|
// controllo sui campi fired di riga
|
|
|
|
for (EntityBase child : list) {
|
|
|
|
for (EntityBase child : list) {
|
|
|
|
if(entityHolder.getFieldToFireMap(child.getClass().getSimpleName()) != null &&
|
|
|
|
if (entityHolder.getFieldToFireMap(child.getClass().getSimpleName()) != null
|
|
|
|
!entityHolder.getFieldToFireMap(child.getClass().getSimpleName()).isEmpty()) {
|
|
|
|
&& !entityHolder.getFieldToFireMap(child.getClass().getSimpleName()).isEmpty()) {
|
|
|
|
if(child.getOperation() == OperationType.INSERT || child.getOperation() == OperationType.DELETE){
|
|
|
|
if (child.getOperation() == OperationType.INSERT || child.getOperation() == OperationType.DELETE) {
|
|
|
|
executeRecalc = true;
|
|
|
|
executeRecalc = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else if(child.getOperation() == OperationType.UPDATE) {
|
|
|
|
} else if (child.getOperation() == OperationType.UPDATE) {
|
|
|
|
Field[] fields = child.getClass().getDeclaredFields();
|
|
|
|
Field[] fields = child.getClass().getDeclaredFields();
|
|
|
|
for (Field field : fields) {
|
|
|
|
for (Field field : fields) {
|
|
|
|
if (field.getAnnotation(FireRecalc.class) != null) {
|
|
|
|
if (field.getAnnotation(FireRecalc.class) != null) {
|
|
|
|
@@ -1019,11 +1028,10 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
child.setParentPKAndImportFromParent(this);
|
|
|
|
child.setParentPKAndImportFromParent(this);
|
|
|
|
child.setCompletingManager(dataCompleting);
|
|
|
|
child.setCompletingManager(dataCompleting);
|
|
|
|
|
|
|
|
|
|
|
|
if(child.getOperation() != OperationType.DELETE) {
|
|
|
|
if (child.getOperation() != OperationType.DELETE) {
|
|
|
|
if(child.getNativeSql() == null) {
|
|
|
|
if (child.getNativeSql() == null) {
|
|
|
|
if (child.getOperation() == OperationType.UPDATE ||
|
|
|
|
if (child.getOperation() == OperationType.UPDATE || child.getOperation() == OperationType.SUBSTITUTE
|
|
|
|
child.getOperation() == OperationType.SUBSTITUTE ||
|
|
|
|
|| child.getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
child.getOperation() == OperationType.INSERT_OR_UPDATE) {
|
|
|
|
|
|
|
|
selectAndMergeEntity(connection, child);
|
|
|
|
selectAndMergeEntity(connection, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
child.setApplicationName(applicationName);
|
|
|
|
child.setApplicationName(applicationName);
|
|
|
|
@@ -1039,8 +1047,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
if (object instanceof List) {
|
|
|
|
if (object instanceof List) {
|
|
|
|
List<EntityBase> list = ((List<EntityBase>) object);
|
|
|
|
List<EntityBase> list = ((List<EntityBase>) object);
|
|
|
|
|
|
|
|
|
|
|
|
if(!executeRecalc) {
|
|
|
|
if (!executeRecalc) {
|
|
|
|
//caricamento delle righe
|
|
|
|
// caricamento delle righe
|
|
|
|
selectChildFromDb(list);
|
|
|
|
selectChildFromDb(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1075,17 +1083,18 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Object> mapLob = getFieldToQuery(fields, campi, valori);
|
|
|
|
Map<Integer, Object> mapLob = getFieldToQuery(fields, campi, valori);
|
|
|
|
|
|
|
|
|
|
|
|
if(!"".equals(otherSet)) {
|
|
|
|
if (!"".equals(otherSet)) {
|
|
|
|
String[] list = otherSet.split(",");
|
|
|
|
String[] list = otherSet.split(",");
|
|
|
|
for (String setCond : list) {
|
|
|
|
for (String setCond : list) {
|
|
|
|
String[] setter = setCond.split("=");
|
|
|
|
String[] setter = setCond.split("=");
|
|
|
|
if(setter.length == 2) {
|
|
|
|
if (setter.length == 2) {
|
|
|
|
Field f = entityHolder.getFieldBySql(this.getClass().getSimpleName(), setter[0].toLowerCase().trim());
|
|
|
|
Field f = entityHolder.getFieldBySql(this.getClass().getSimpleName(),
|
|
|
|
if(f==null)
|
|
|
|
setter[0].toLowerCase().trim());
|
|
|
|
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("campo " + setter[0].trim() + " non presente nella entity");
|
|
|
|
throw new Exception("campo " + setter[0].trim() + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
int idx = campi.indexOf(setter[0].toLowerCase().trim());
|
|
|
|
int idx = campi.indexOf(setter[0].toLowerCase().trim());
|
|
|
|
if(idx > -1) {
|
|
|
|
if (idx > -1) {
|
|
|
|
campi.remove(idx);
|
|
|
|
campi.remove(idx);
|
|
|
|
valori.remove(idx);
|
|
|
|
valori.remove(idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1104,9 +1113,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (campi.size()!= 0) {
|
|
|
|
if (campi.size() != 0) {
|
|
|
|
String sql = "INSERT INTO " + getTableName() + "("
|
|
|
|
String sql = "INSERT INTO " + getTableName() + "(" + StringUtils.join(campi, ",") + ") VALUES ("
|
|
|
|
+ StringUtils.join(campi, ",") + ") VALUES ("
|
|
|
|
|
|
|
|
+ StringUtils.join(valori, ",") + ")";
|
|
|
|
+ StringUtils.join(valori, ",") + ")";
|
|
|
|
if (logger.isTraceEnabled()) {
|
|
|
|
if (logger.isTraceEnabled()) {
|
|
|
|
logger.trace("QUERY: " + sql);
|
|
|
|
logger.trace("QUERY: " + sql);
|
|
|
|
@@ -1117,21 +1125,21 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
pstm.executeUpdate();
|
|
|
|
pstm.executeUpdate();
|
|
|
|
pstm.close();
|
|
|
|
pstm.close();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new Exception("Nessun campo valorizzato per la entity " + getTableName() + " (Controllare metodi get/set della entity)");
|
|
|
|
throw new Exception("Nessun campo valorizzato per la entity " + getTableName()
|
|
|
|
|
|
|
|
+ " (Controllare metodi get/set della entity)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setupBinaryParams(Map<Integer, Object> mapLob,
|
|
|
|
private void setupBinaryParams(Map<Integer, Object> mapLob, PreparedStatement pstm) throws SQLException {
|
|
|
|
PreparedStatement pstm) throws SQLException {
|
|
|
|
|
|
|
|
for (Entry<Integer, Object> entry : mapLob.entrySet()) {
|
|
|
|
for (Entry<Integer, Object> entry : mapLob.entrySet()) {
|
|
|
|
Object val = mapLob.get(entry.getKey());
|
|
|
|
Object val = mapLob.get(entry.getKey());
|
|
|
|
if(val instanceof Clob){
|
|
|
|
if (val instanceof Clob) {
|
|
|
|
if(EmsRestConstants.NULL.equals(((Clob)val).getSubString(1L, (int)((Clob)val).length())))
|
|
|
|
if (EmsRestConstants.NULL.equals(((Clob) val).getSubString(1L, (int) ((Clob) val).length())))
|
|
|
|
pstm.setNull(entry.getKey(), java.sql.Types.CLOB);
|
|
|
|
pstm.setNull(entry.getKey(), java.sql.Types.CLOB);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
pstm.setClob(entry.getKey(), (Clob) val);
|
|
|
|
pstm.setClob(entry.getKey(), (Clob) val);
|
|
|
|
} else if(val instanceof Blob){
|
|
|
|
} else if (val instanceof Blob) {
|
|
|
|
if(EmsRestConstants.NULL.equals(new String(((Blob)val).getBytes(1L, (int)((Blob)val).length()))))
|
|
|
|
if (EmsRestConstants.NULL.equals(new String(((Blob) val).getBytes(1L, (int) ((Blob) val).length()))))
|
|
|
|
pstm.setNull(entry.getKey(), java.sql.Types.BLOB);
|
|
|
|
pstm.setNull(entry.getKey(), java.sql.Types.BLOB);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
pstm.setBlob(entry.getKey(), (Blob) val);
|
|
|
|
pstm.setBlob(entry.getKey(), (Blob) val);
|
|
|
|
@@ -1154,15 +1162,16 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Object> mapLob = getFieldToUpdate(fields, campi, where);
|
|
|
|
Map<Integer, Object> mapLob = getFieldToUpdate(fields, campi, where);
|
|
|
|
|
|
|
|
|
|
|
|
if(!"".equals(otherSet)) {
|
|
|
|
if (!"".equals(otherSet)) {
|
|
|
|
List<String> pkSetList = new ArrayList<String>();
|
|
|
|
List<String> pkSetList = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
|
|
String[] list = otherSet.split(",");
|
|
|
|
String[] list = otherSet.split(",");
|
|
|
|
for (String setCond : list) {
|
|
|
|
for (String setCond : list) {
|
|
|
|
String[] setter = setCond.split("=");
|
|
|
|
String[] setter = setCond.split("=");
|
|
|
|
if(setter.length == 2) {
|
|
|
|
if (setter.length == 2) {
|
|
|
|
Field f = entityHolder.getFieldBySql(this.getClass().getSimpleName(), setter[0].toLowerCase().trim());
|
|
|
|
Field f = entityHolder.getFieldBySql(this.getClass().getSimpleName(),
|
|
|
|
if(f==null)
|
|
|
|
setter[0].toLowerCase().trim());
|
|
|
|
|
|
|
|
if (f == null)
|
|
|
|
throw new Exception("campo " + setter[0].trim() + " non presente nella entity");
|
|
|
|
throw new Exception("campo " + setter[0].trim() + " non presente nella entity");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.setAccessible(true);
|
|
|
|
if (f.getAnnotation(SqlField.class) != null) {
|
|
|
|
if (f.getAnnotation(SqlField.class) != null) {
|
|
|
|
@@ -1180,7 +1189,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
campi.addAll(pkSetList);
|
|
|
|
campi.addAll(pkSetList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(campi.size() > 0) {
|
|
|
|
if (campi.size() > 0) {
|
|
|
|
String sql = "UPDATE " + getTableName() + " SET " + StringUtils.join(campi, ",");
|
|
|
|
String sql = "UPDATE " + getTableName() + " SET " + StringUtils.join(campi, ",");
|
|
|
|
|
|
|
|
|
|
|
|
if (whereCond != null) {
|
|
|
|
if (whereCond != null) {
|
|
|
|
@@ -1208,22 +1217,22 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
Object obj = field.get(parent);
|
|
|
|
Object obj = field.get(parent);
|
|
|
|
if (obj != null && field.getAnnotation(SqlField.class) != null) {
|
|
|
|
if (obj != null && field.getAnnotation(SqlField.class) != null) {
|
|
|
|
|
|
|
|
|
|
|
|
//COPY FIELD ANNOTATED WITH @PK
|
|
|
|
// COPY FIELD ANNOTATED WITH @PK
|
|
|
|
PK pk = field.getAnnotation(PK.class);
|
|
|
|
PK pk = field.getAnnotation(PK.class);
|
|
|
|
if (pk != null) {
|
|
|
|
if (pk != null) {
|
|
|
|
String mName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
|
|
|
|
String mName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
|
|
|
|
Method m = ReflectionUtils.findMethod(getClass(), mName, obj.getClass());
|
|
|
|
Method m = ReflectionUtils.findMethod(getClass(), mName, obj.getClass());
|
|
|
|
if(m != null)
|
|
|
|
if (m != null)
|
|
|
|
m.invoke(this, obj);
|
|
|
|
m.invoke(this, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//COPY FIELD ANNOTATED WITH @ImportFromParent
|
|
|
|
// COPY FIELD ANNOTATED WITH @ImportFromParent
|
|
|
|
ImportFromParent cpFrmParent = field.getAnnotation(ImportFromParent.class);
|
|
|
|
ImportFromParent cpFrmParent = field.getAnnotation(ImportFromParent.class);
|
|
|
|
if (cpFrmParent != null) {
|
|
|
|
if (cpFrmParent != null) {
|
|
|
|
String mName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
|
|
|
|
String mName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
|
|
|
|
if(obj != null) {
|
|
|
|
if (obj != null) {
|
|
|
|
Method m = ReflectionUtils.findMethod(getClass(), mName, obj.getClass());
|
|
|
|
Method m = ReflectionUtils.findMethod(getClass(), mName, obj.getClass());
|
|
|
|
if(m != null)
|
|
|
|
if (m != null)
|
|
|
|
m.invoke(this, obj);
|
|
|
|
m.invoke(this, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1235,23 +1244,23 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
public void setImportFromParent(EntityBase parent) throws Exception {
|
|
|
|
public void setImportFromParent(EntityBase parent) throws Exception {
|
|
|
|
Field[] fields = getClass().getDeclaredFields();
|
|
|
|
Field[] fields = getClass().getDeclaredFields();
|
|
|
|
for (Field field : fields) {
|
|
|
|
for (Field field : fields) {
|
|
|
|
//field.getAnnotation(SqlField.class) != null &&
|
|
|
|
// field.getAnnotation(SqlField.class) != null &&
|
|
|
|
if (field.getAnnotation(ImportFromParent.class) != null) {
|
|
|
|
if (field.getAnnotation(ImportFromParent.class) != null) {
|
|
|
|
ImportFromParent ifp = field.getAnnotation(ImportFromParent.class);
|
|
|
|
ImportFromParent ifp = field.getAnnotation(ImportFromParent.class);
|
|
|
|
String fieldName;
|
|
|
|
String fieldName;
|
|
|
|
if(!"".equals(ifp.value()))
|
|
|
|
if (!"".equals(ifp.value()))
|
|
|
|
fieldName = ifp.value();
|
|
|
|
fieldName = ifp.value();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
fieldName = field.getName();
|
|
|
|
fieldName = field.getName();
|
|
|
|
Field fieldParent = ReflectionUtils.findField(parent.getClass(), fieldName);
|
|
|
|
Field fieldParent = ReflectionUtils.findField(parent.getClass(), fieldName);
|
|
|
|
if(fieldParent != null) {
|
|
|
|
if (fieldParent != null) {
|
|
|
|
fieldParent.setAccessible(true);
|
|
|
|
fieldParent.setAccessible(true);
|
|
|
|
Object obj = fieldParent.get(parent);
|
|
|
|
Object obj = fieldParent.get(parent);
|
|
|
|
|
|
|
|
|
|
|
|
String mName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
|
|
|
|
String mName = "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
|
|
|
|
if(obj != null){
|
|
|
|
if (obj != null) {
|
|
|
|
Method m = ReflectionUtils.findMethod(getClass(), mName, obj.getClass());
|
|
|
|
Method m = ReflectionUtils.findMethod(getClass(), mName, obj.getClass());
|
|
|
|
if(m != null)
|
|
|
|
if (m != null)
|
|
|
|
m.invoke(this, obj);
|
|
|
|
m.invoke(this, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@@ -1276,19 +1285,19 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
else
|
|
|
|
else
|
|
|
|
dato = "'" + UtilityString.escapeSpecialChar(obj) + "'";
|
|
|
|
dato = "'" + UtilityString.escapeSpecialChar(obj) + "'";
|
|
|
|
} else if (obj instanceof Date) {
|
|
|
|
} else if (obj instanceof Date) {
|
|
|
|
if(obj.equals(EmsRestConstants.DATE_NULL)) {
|
|
|
|
if (obj.equals(EmsRestConstants.DATE_NULL)) {
|
|
|
|
dato = "null";
|
|
|
|
dato = "null";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
dato = UtilityString.removeApiciStartEnd(obj);
|
|
|
|
dato = UtilityString.removeApiciStartEnd(obj);
|
|
|
|
dato = "'"+ new SimpleDateFormat(CommonConstants.DATETIME_FORMAT_YMD).format(obj)+ "'";
|
|
|
|
dato = "'" + new SimpleDateFormat(CommonConstants.DATETIME_FORMAT_YMD).format(obj) + "'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (obj instanceof Integer) {
|
|
|
|
} else if (obj instanceof Integer) {
|
|
|
|
if(obj.equals(EmsRestConstants.INTEGER_NULL)) {
|
|
|
|
if (obj.equals(EmsRestConstants.INTEGER_NULL)) {
|
|
|
|
dato = "null";
|
|
|
|
dato = "null";
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
dato = obj.toString();
|
|
|
|
dato = obj.toString();
|
|
|
|
} else if (obj instanceof BigDecimal) {
|
|
|
|
} else if (obj instanceof BigDecimal) {
|
|
|
|
if(obj.equals(EmsRestConstants.BIGDECIMAL_NULL)) {
|
|
|
|
if (obj.equals(EmsRestConstants.BIGDECIMAL_NULL)) {
|
|
|
|
dato = "null";
|
|
|
|
dato = "null";
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
dato = obj.toString();
|
|
|
|
dato = obj.toString();
|
|
|
|
@@ -1328,7 +1337,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteAllEntities(Connection conn, String where) throws Exception {
|
|
|
|
public void deleteAllEntities(Connection conn, String where) throws Exception {
|
|
|
|
if(this.getOperation() == null) {
|
|
|
|
if (this.getOperation() == null) {
|
|
|
|
this.setOperation(OperationType.DELETE);
|
|
|
|
this.setOperation(OperationType.DELETE);
|
|
|
|
this.setWhereCond(where);
|
|
|
|
this.setWhereCond(where);
|
|
|
|
this.connection = conn;
|
|
|
|
this.connection = conn;
|
|
|
|
@@ -1336,23 +1345,18 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
this.manage();
|
|
|
|
this.manage();
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
String sql = "DELETE " + getTableName();
|
|
|
|
* String sql = "DELETE " + getTableName(); if (whereCond != null) { sql
|
|
|
|
if (whereCond != null) {
|
|
|
|
* += " WHERE " + whereCond; } else { sql += " WHERE " +
|
|
|
|
sql += " WHERE " + whereCond;
|
|
|
|
* StringUtils.join(where, " AND "); }
|
|
|
|
} else {
|
|
|
|
*
|
|
|
|
sql += " WHERE " + StringUtils.join(where, " AND ");
|
|
|
|
* if (logger.isTraceEnabled()) { logger.trace("QUERY: " + sql); }
|
|
|
|
}
|
|
|
|
*
|
|
|
|
|
|
|
|
* PreparedStatement pstm = conn.prepareStatement(sql);
|
|
|
|
if (logger.isTraceEnabled()) {
|
|
|
|
* pstm.executeUpdate(); pstm.close();
|
|
|
|
logger.trace("QUERY: " + sql);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement pstm = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
pstm.executeUpdate();
|
|
|
|
|
|
|
|
pstm.close(); */
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getPkWhereCond() throws Exception{
|
|
|
|
public String getPkWhereCond() throws Exception {
|
|
|
|
Field[] fields = this.getClass().getDeclaredFields();
|
|
|
|
Field[] fields = this.getClass().getDeclaredFields();
|
|
|
|
List<String> where = getPkWhereCond(fields, this);
|
|
|
|
List<String> where = getPkWhereCond(fields, this);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1364,8 +1368,7 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getPkWhereCond(Field[] fields, EntityBase parent)
|
|
|
|
private List<String> getPkWhereCond(Field[] fields, EntityBase parent) throws IllegalAccessException {
|
|
|
|
throws IllegalAccessException {
|
|
|
|
|
|
|
|
List<String> where = new ArrayList<String>();
|
|
|
|
List<String> where = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
for (Field field : fields) {
|
|
|
|
@@ -1411,8 +1414,8 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
pstm.close();
|
|
|
|
pstm.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Integer, Object> getFieldToQuery(Field[] fields, List<String> campi,
|
|
|
|
private Map<Integer, Object> getFieldToQuery(Field[] fields, List<String> campi, List<String> valori)
|
|
|
|
List<String> valori) throws Exception {
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Object> map = new HashMap<Integer, Object>();
|
|
|
|
Map<Integer, Object> map = new HashMap<Integer, Object>();
|
|
|
|
Integer counter = 1;
|
|
|
|
Integer counter = 1;
|
|
|
|
@@ -1422,17 +1425,17 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
SqlField sqlField;
|
|
|
|
SqlField sqlField;
|
|
|
|
if (obj != null && (sqlField = field.getAnnotation(SqlField.class)) != null) {
|
|
|
|
if (obj != null && (sqlField = field.getAnnotation(SqlField.class)) != null) {
|
|
|
|
|
|
|
|
|
|
|
|
//esclusione colonne per sincronizzazione
|
|
|
|
// esclusione colonne per sincronizzazione
|
|
|
|
if(excludedColumns != null &&
|
|
|
|
if (excludedColumns != null
|
|
|
|
excludedColumns.contains(SqlFieldHolder.getSqlValue(sqlField.value(), field)))
|
|
|
|
&& excludedColumns.contains(SqlFieldHolder.getSqlValue(sqlField.value(), field)))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
if(field.getAnnotation(it.integry.ems.annotation.Clob.class) != null){
|
|
|
|
if (field.getAnnotation(it.integry.ems.annotation.Clob.class) != null) {
|
|
|
|
setupClobData(counter, map, obj);
|
|
|
|
setupClobData(counter, map, obj);
|
|
|
|
valori.add("?");
|
|
|
|
valori.add("?");
|
|
|
|
campi.add(SqlFieldHolder.getSqlValue(sqlField.value(), field));
|
|
|
|
campi.add(SqlFieldHolder.getSqlValue(sqlField.value(), field));
|
|
|
|
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
counter++;
|
|
|
|
} else if(field.getAnnotation(it.integry.ems.annotation.Blob.class) != null) {
|
|
|
|
} else if (field.getAnnotation(it.integry.ems.annotation.Blob.class) != null) {
|
|
|
|
setupBlobData(counter, map, obj);
|
|
|
|
setupBlobData(counter, map, obj);
|
|
|
|
valori.add("?");
|
|
|
|
valori.add("?");
|
|
|
|
campi.add(SqlFieldHolder.getSqlValue(sqlField.value(), field));
|
|
|
|
campi.add(SqlFieldHolder.getSqlValue(sqlField.value(), field));
|
|
|
|
@@ -1463,19 +1466,19 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
if (pk != null) {
|
|
|
|
if (pk != null) {
|
|
|
|
where.add(sqlVal + " = " + dato);
|
|
|
|
where.add(sqlVal + " = " + dato);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if(getOperation() != OperationType.INSERT) {
|
|
|
|
if (getOperation() != OperationType.INSERT) {
|
|
|
|
//esclusione colonne per sincronizzazione
|
|
|
|
// esclusione colonne per sincronizzazione
|
|
|
|
if(excludedColumns != null && (excludedColumns.contains(sqlField.value()) ||
|
|
|
|
if (excludedColumns != null && (excludedColumns.contains(sqlField.value())
|
|
|
|
excludedColumns.contains(field.getName())))
|
|
|
|
|| excludedColumns.contains(field.getName())))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(field.getAnnotation(it.integry.ems.annotation.Clob.class) != null){
|
|
|
|
if (field.getAnnotation(it.integry.ems.annotation.Clob.class) != null) {
|
|
|
|
setupClobData(counter, mapLob, obj);
|
|
|
|
setupClobData(counter, mapLob, obj);
|
|
|
|
campi.add(sqlVal + " = ?");
|
|
|
|
campi.add(sqlVal + " = ?");
|
|
|
|
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
counter++;
|
|
|
|
} else if(field.getAnnotation(it.integry.ems.annotation.Blob.class) != null) {
|
|
|
|
} else if (field.getAnnotation(it.integry.ems.annotation.Blob.class) != null) {
|
|
|
|
setupBlobData(counter, mapLob, obj);
|
|
|
|
setupBlobData(counter, mapLob, obj);
|
|
|
|
campi.add(sqlVal + " = ?");
|
|
|
|
campi.add(sqlVal + " = ?");
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1493,10 +1496,10 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
Blob blobData = connection.createBlob();
|
|
|
|
Blob blobData = connection.createBlob();
|
|
|
|
|
|
|
|
|
|
|
|
byte[] blob;
|
|
|
|
byte[] blob;
|
|
|
|
if(EmsRestConstants.NULL.equals(obj.toString()))
|
|
|
|
if (EmsRestConstants.NULL.equals(obj.toString()))
|
|
|
|
blob = obj.toString().getBytes();
|
|
|
|
blob = obj.toString().getBytes();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
//base64 conversion
|
|
|
|
// base64 conversion
|
|
|
|
blob = Base64.decodeBase64(obj.toString());
|
|
|
|
blob = Base64.decodeBase64(obj.toString());
|
|
|
|
|
|
|
|
|
|
|
|
blobData.setBytes(1, blob);
|
|
|
|
blobData.setBytes(1, blob);
|
|
|
|
@@ -1507,10 +1510,10 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
|
|
|
Clob clobData = connection.createClob();
|
|
|
|
Clob clobData = connection.createClob();
|
|
|
|
|
|
|
|
|
|
|
|
String clob;
|
|
|
|
String clob;
|
|
|
|
if(EmsRestConstants.NULL.equals(obj.toString()))
|
|
|
|
if (EmsRestConstants.NULL.equals(obj.toString()))
|
|
|
|
clob = obj.toString();
|
|
|
|
clob = obj.toString();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
//base64 conversion
|
|
|
|
// base64 conversion
|
|
|
|
clob = new String(Base64.decodeBase64(obj.toString()));
|
|
|
|
clob = new String(Base64.decodeBase64(obj.toString()));
|
|
|
|
|
|
|
|
|
|
|
|
clobData.setString(1, clob);
|
|
|
|
clobData.setString(1, clob);
|
|
|
|
|