IDEMPIERE-4886 Synchronize multiple columns on ALTER (#788)
This commit is contained in:
parent
3f52286bbe
commit
1a01a70b2b
|
@ -0,0 +1,11 @@
|
|||
SET SQLBLANKLINES ON
|
||||
SET DEFINE OFF
|
||||
|
||||
-- IDEMPIERE-4886 Synchronize multiple columns on ALTER
|
||||
-- Jul 21, 2021, 7:22:56 PM CEST
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete) VALUES (200381,0,0,'Y',TO_DATE('2021-07-21 19:22:55','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-07-21 19:22:55','YYYY-MM-DD HH24:MI:SS'),100,'Date From','Starting date for a range','The Date From indicates the starting date of a range.',181,10,16,'N',10,'N','@SQL=SELECT MAX(Updated) FROM AD_PInstance WHERE AD_Process_ID=181 AND Record_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=@AD_Table_ID@)','DateFrom','Y','D',1581,'ac65ae25-b7bc-4605-9c87-fcc2604f5e1d','N','N')
|
||||
;
|
||||
|
||||
SELECT register_migration_script('202107211936_IDEMPIERE-4886.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
-- IDEMPIERE-4886 Synchronize multiple columns on ALTER
|
||||
-- Jul 21, 2021, 7:22:56 PM CEST
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete) VALUES (200381,0,0,'Y',TO_TIMESTAMP('2021-07-21 19:22:55','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-07-21 19:22:55','YYYY-MM-DD HH24:MI:SS'),100,'Date From','Starting date for a range','The Date From indicates the starting date of a range.',181,10,16,'N',10,'N','@SQL=SELECT MAX(Updated) FROM AD_PInstance WHERE AD_Process_ID=181 AND Record_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=@AD_Table_ID@)','DateFrom','Y','D',1581,'ac65ae25-b7bc-4605-9c87-fcc2604f5e1d','N','N')
|
||||
;
|
||||
|
||||
SELECT register_migration_script('202107211936_IDEMPIERE-4886.sql') FROM dual
|
||||
;
|
||||
|
|
@ -20,11 +20,15 @@ import java.math.BigDecimal;
|
|||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.util.AdempiereUserError;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
@ -45,19 +49,23 @@ public class ColumnSync extends SvrProcess
|
|||
/** The Column */
|
||||
private int p_AD_Column_ID = 0;
|
||||
|
||||
/* Date From */
|
||||
private Timestamp p_DateFrom = null;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
@Override
|
||||
protected void prepare() {
|
||||
for (ProcessInfoParameter para : getParameter()) {
|
||||
String name = para.getParameterName();
|
||||
switch (name) {
|
||||
case "DateFrom": p_DateFrom = para.getParameterAsTimestamp(); break;
|
||||
default:
|
||||
if (log.isLoggable(Level.INFO))
|
||||
log.log(Level.INFO, "Custom Parameter: " + name + "=" + para.getInfo());
|
||||
break;
|
||||
}
|
||||
}
|
||||
p_AD_Column_ID = getRecord_ID();
|
||||
} // prepare
|
||||
|
@ -72,13 +80,33 @@ public class ColumnSync extends SvrProcess
|
|||
if (log.isLoggable(Level.INFO)) log.info("C_Column_ID=" + p_AD_Column_ID);
|
||||
if (p_AD_Column_ID == 0)
|
||||
throw new AdempiereUserError("@No@ @AD_Column_ID@");
|
||||
MColumn column = new MColumn (getCtx(), p_AD_Column_ID, get_TrxName());
|
||||
if (column.get_ID() == 0)
|
||||
|
||||
MColumn columnCalled = new MColumn (getCtx(), p_AD_Column_ID, get_TrxName());
|
||||
if (columnCalled.get_ID() == 0)
|
||||
throw new AdempiereUserError("@NotFound@ @AD_Column_ID@ " + p_AD_Column_ID);
|
||||
|
||||
MTable table = new MTable(getCtx(), column.getAD_Table_ID(), get_TrxName());
|
||||
|
||||
MTable table = new MTable(getCtx(), columnCalled.getAD_Table_ID(), get_TrxName());
|
||||
if (table.get_ID() == 0)
|
||||
throw new AdempiereUserError("@NotFound@ @AD_Table_ID@ " + column.getAD_Table_ID());
|
||||
throw new AdempiereUserError("@NotFound@ @AD_Table_ID@ " + columnCalled.getAD_Table_ID());
|
||||
|
||||
String whereClause;
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
if (p_DateFrom == null) {
|
||||
whereClause = "AD_Column_ID=?";
|
||||
params.add(p_AD_Column_ID);
|
||||
} else {
|
||||
whereClause = "(AD_Column_ID=? OR (AD_Table_ID=? AND Updated>?))";
|
||||
params.add(p_AD_Column_ID);
|
||||
params.add(table.getAD_Table_ID());
|
||||
params.add(p_DateFrom);
|
||||
}
|
||||
|
||||
StringBuilder allSql = new StringBuilder();
|
||||
List<MColumn> columns = new Query(getCtx(), MColumn.Table_Name, whereClause, get_TrxName())
|
||||
.setParameters(params)
|
||||
.list();
|
||||
|
||||
for (MColumn column : columns) {
|
||||
|
||||
// Find Column in Database
|
||||
Connection conn = null;
|
||||
|
@ -182,7 +210,10 @@ public class ColumnSync extends SvrProcess
|
|||
msg.append(sql);
|
||||
throw new AdempiereUserError (msg.toString());
|
||||
}
|
||||
return sql;
|
||||
allSql.append(sql);
|
||||
if (isNoTable)
|
||||
break;
|
||||
commitEx();
|
||||
} finally {
|
||||
DB.close(rs);
|
||||
rs = null;
|
||||
|
@ -192,6 +223,8 @@ public class ColumnSync extends SvrProcess
|
|||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
return allSql.toString();
|
||||
} // doIt
|
||||
|
||||
} // ColumnSync
|
||||
|
|
Loading…
Reference in New Issue