IDEMPIERE-5613 Make filling of _UU column optional (#1719)

* IDEMPIERE-5613 Make filling of _UU column optional

* - clear _UU when column is made inactive

* - Add parameter IsClearUUID
- Fix issue with buffer log not being flushed
This commit is contained in:
Carlos Ruiz 2023-03-14 13:20:57 +01:00 committed by GitHub
parent b188775e9a
commit 4c77efecb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 7 deletions

View File

@ -0,0 +1,14 @@
-- IDEMPIERE-5613 Make filling of _UU column optional
SELECT register_migration_script('202303131848_IDEMPIERE-5613.sql') FROM dual;
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Mar 13, 2023, 6:48:00 PM CET
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,Help,PrintName,EntityType,AD_Element_UU) VALUES (203792,0,0,'Y',TO_TIMESTAMP('2023-03-13 18:46:14','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-13 18:46:14','YYYY-MM-DD HH24:MI:SS'),100,'IsClearUUID','Clear UUID','Clear UUID when column is inactive',NULL,'Clear UUID','D','69bb1e9c-14f1-4e4a-a43e-4417875c0de3')
;
-- Mar 13, 2023, 6:48:13 PM CET
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete,DateRangeOption,IsShowNegateButton) VALUES (200432,0,0,'Y',TO_TIMESTAMP('2023-03-13 18:48:12','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-13 18:48:12','YYYY-MM-DD HH24:MI:SS'),100,'Clear UUID','Clear UUID when column is inactive',53252,30,20,'N',1,'Y','N','IsClearUUID','Y','D',203792,'ef8c4d7e-8ee4-4911-a6e5-4d1d8989e4be','N','N','D','N')
;

View File

@ -0,0 +1,11 @@
-- IDEMPIERE-5613 Make filling of _UU column optional
SELECT register_migration_script('202303131848_IDEMPIERE-5613.sql') FROM dual;
-- Mar 13, 2023, 6:48:00 PM CET
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,Help,PrintName,EntityType,AD_Element_UU) VALUES (203792,0,0,'Y',TO_TIMESTAMP('2023-03-13 18:46:14','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-13 18:46:14','YYYY-MM-DD HH24:MI:SS'),100,'IsClearUUID','Clear UUID','Clear UUID when column is inactive',NULL,'Clear UUID','D','69bb1e9c-14f1-4e4a-a43e-4417875c0de3')
;
-- Mar 13, 2023, 6:48:13 PM CET
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted,IsAutocomplete,DateRangeOption,IsShowNegateButton) VALUES (200432,0,0,'Y',TO_TIMESTAMP('2023-03-13 18:48:12','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-13 18:48:12','YYYY-MM-DD HH24:MI:SS'),100,'Clear UUID','Clear UUID when column is inactive',53252,30,20,'N',1,'Y','N','IsClearUUID','Y','D',203792,'ef8c4d7e-8ee4-4911-a6e5-4d1d8989e4be','N','N','D','N')
;

View File

@ -55,6 +55,8 @@ public class UUIDGenerator extends SvrProcess {
private boolean isFillUUID = false; private boolean isFillUUID = false;
private boolean isClearUUID = false;
/** Logger */ /** Logger */
private static final CLogger log = CLogger.getCLogger(UUIDGenerator.class); private static final CLogger log = CLogger.getCLogger(UUIDGenerator.class);
@ -70,6 +72,8 @@ public class UUIDGenerator extends SvrProcess {
tableName = param.getParameter().toString(); tableName = param.getParameter().toString();
else if (param.getParameterName().equals("IsFillUUID")) else if (param.getParameterName().equals("IsFillUUID"))
isFillUUID = param.getParameterAsBoolean(); isFillUUID = param.getParameterAsBoolean();
else if (param.getParameterName().equals("IsClearUUID"))
isClearUUID = param.getParameterAsBoolean();
else else
MProcessPara.validateUnknownParameter(getProcessInfo().getAD_Process_ID(), param); MProcessPara.validateUnknownParameter(getProcessInfo().getAD_Process_ID(), param);
} }
@ -129,19 +133,35 @@ public class UUIDGenerator extends SvrProcess {
//update db //update db
if (isFillUUID) { if (isFillUUID) {
// COMMENT NEXT LINE ON RELEASE WORK
String msg = updateUUID(mColumn, null); String msg = updateUUID(mColumn, null);
if (! Util.isEmpty(msg)) { if (! Util.isEmpty(msg)) {
addBufferLog(0, null, null, msg, 0, 0); addBufferLog(0, null, null, msg, 0, 0);
} }
} }
} else { } else {
if (isFillUUID) { MColumn column = MColumn.get(AD_Column_ID);
MColumn mColumn = MColumn.get(getCtx(), AD_Column_ID); if (column.isActive()) {
// COMMENT NEXT LINE ON RELEASE WORK if (isFillUUID) {
String msg = updateUUID(mColumn, null); MColumn mColumn = MColumn.get(getCtx(), AD_Column_ID);
if (! Util.isEmpty(msg)) { String msg = updateUUID(mColumn, null);
addBufferLog(0, null, null, msg, 0, 0); if (! Util.isEmpty(msg)) {
addBufferLog(0, null, null, msg, 0, 0);
}
}
} else {
if (isClearUUID) {
StringBuilder sqlclear = new StringBuilder("UPDATE ")
.append(cTableName)
.append(" SET ")
.append(columnName)
.append("=NULL WHERE ")
.append(columnName)
.append(" IS NOT NULL");
int cnt = DB.executeUpdateEx(sqlclear.toString(), get_TrxName());
if (cnt > 0) {
String msg = cnt + " UUID cleared from table " + cTableName;
addBufferLog(0, null, null, msg, 0, 0);
}
} }
} }
} }

View File

@ -282,6 +282,9 @@ public abstract class SvrProcess implements ProcessCall
success = false; success = false;
if (success) { if (success) {
// if the connection has not been used, then the buffer log is never flushed
// f.e. when the process uses local transactions like UUIDGenerator
m_trx.getConnection();
m_trx.addTrxEventListener(new TrxEventListener() { m_trx.addTrxEventListener(new TrxEventListener() {
@Override @Override
public void afterRollback(Trx trx, boolean success) { public void afterRollback(Trx trx, boolean success) {