IDEMPIERE-2395 - Add ad_package_uuid_map - and parameter for changelog
This commit is contained in:
parent
7ee436d5af
commit
429162c43d
|
@ -0,0 +1,15 @@
|
|||
SET SQLBLANKLINES ON
|
||||
SET DEFINE OFF
|
||||
|
||||
-- IDEMPIERE-2395
|
||||
-- Mar 19, 2019, 3:24:55 PM BRT
|
||||
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 (203300,0,0,'Y',TO_DATE('2019-03-19 15:24:31','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-19 15:24:31','YYYY-MM-DD HH24:MI:SS'),100,'IsCleanChangeLog','Clean Change Log',NULL,NULL,'Clean Change Log','D','c6e68794-2989-4a46-9151-a94a3254cf93')
|
||||
;
|
||||
|
||||
-- Mar 19, 2019, 3:25:19 PM BRT
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200269,0,0,'Y',TO_DATE('2019-03-19 15:25:18','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-19 15:25:18','YYYY-MM-DD HH24:MI:SS'),100,'Clean Change Log',200102,10,20,'N',1,'Y','N','IsCleanChangeLog','Y','D',203300,'459a7f88-ec79-47cf-9c7b-7429ac565f55','N')
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201903191533_IDEMPIERE-2395.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
-- IDEMPIERE-2395
|
||||
-- Mar 19, 2019, 3:24:55 PM BRT
|
||||
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 (203300,0,0,'Y',TO_TIMESTAMP('2019-03-19 15:24:31','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-19 15:24:31','YYYY-MM-DD HH24:MI:SS'),100,'IsCleanChangeLog','Clean Change Log',NULL,NULL,'Clean Change Log','D','c6e68794-2989-4a46-9151-a94a3254cf93')
|
||||
;
|
||||
|
||||
-- Mar 19, 2019, 3:25:19 PM BRT
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200269,0,0,'Y',TO_TIMESTAMP('2019-03-19 15:25:18','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-19 15:25:18','YYYY-MM-DD HH24:MI:SS'),100,'Clean Change Log',200102,10,20,'N',1,'Y','N','IsCleanChangeLog','Y','D',203300,'459a7f88-ec79-47cf-9c7b-7429ac565f55','N')
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201903191533_IDEMPIERE-2395.sql') FROM dual
|
||||
;
|
||||
|
|
@ -33,6 +33,7 @@ import org.compiere.model.MAttachment;
|
|||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.MTree_Base;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.model.X_AD_Package_UUID_Map;
|
||||
import org.compiere.process.ProcessInfoParameter;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.util.DB;
|
||||
|
@ -46,6 +47,8 @@ import org.compiere.util.ValueNamePair;
|
|||
public class CleanOrphanCascade extends SvrProcess
|
||||
{
|
||||
|
||||
private boolean p_IsCleanChangeLog;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
|
@ -54,8 +57,12 @@ public class CleanOrphanCascade extends SvrProcess
|
|||
for (ProcessInfoParameter para : getParameter())
|
||||
{
|
||||
String name = para.getParameterName();
|
||||
if ("IsCleanChangeLog".equals(name)) {
|
||||
p_IsCleanChangeLog = para.getParameterAsBoolean();
|
||||
} else {
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
}
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
|
@ -99,7 +106,6 @@ public class CleanOrphanCascade extends SvrProcess
|
|||
|
||||
String whereTables = ""
|
||||
+ " IsView = 'N' "
|
||||
+ "AND TableName != 'AD_ChangeLog' "
|
||||
+ "AND EXISTS (SELECT 1 "
|
||||
+ " FROM AD_Column ct "
|
||||
+ " WHERE ct.IsActive='Y' AND ct.AD_Table_ID = AD_Table.AD_Table_ID "
|
||||
|
@ -112,13 +118,18 @@ public class CleanOrphanCascade extends SvrProcess
|
|||
+ " FROM AD_Column ck "
|
||||
+ " WHERE ck.IsActive='Y' AND ck.AD_Table_ID = AD_Table.AD_Table_ID "
|
||||
+ " AND ck.ColumnName = AD_Table.TableName || '_ID')";
|
||||
if (! p_IsCleanChangeLog) {
|
||||
whereTables += " AND TableName != 'AD_ChangeLog'";
|
||||
}
|
||||
|
||||
List<MTable> tables = new Query(getCtx(), "AD_Table", whereTables, get_TrxName())
|
||||
.setOnlyActiveRecords(true)
|
||||
.setOrderBy("TableName")
|
||||
.list();
|
||||
tables.add(MTable.get(getCtx(), X_AD_Package_UUID_Map.Table_Name));
|
||||
for (MTable table : tables) {
|
||||
String tableName = table.getTableName();
|
||||
boolean isUUIDMap = X_AD_Package_UUID_Map.Table_Name.equals(tableName);
|
||||
|
||||
StringBuilder sqlRef = new StringBuilder();
|
||||
sqlRef.append("SELECT DISTINCT t.AD_Table_ID, ");
|
||||
|
@ -138,12 +149,20 @@ public class CleanOrphanCascade extends SvrProcess
|
|||
continue;
|
||||
}
|
||||
String colRef = refTable.getKeyColumns()[0];
|
||||
if (isUUIDMap) {
|
||||
colRef = MTable.getUUIDColumnName(refTable.getTableName());
|
||||
}
|
||||
|
||||
StringBuilder whereClause = new StringBuilder();
|
||||
whereClause.append("AD_Table_ID = ").append(refTableID);
|
||||
whereClause.append(" AND NOT EXISTS (SELECT ").append(colRef);
|
||||
whereClause.append(" FROM ").append(refTableName).append(" ");
|
||||
whereClause.append(" WHERE ").append(refTableName).append(".").append(colRef).append(" = ").append(tableName).append(".Record_ID)");
|
||||
whereClause.append(" WHERE ").append(refTableName).append(".").append(colRef).append(" = ").append(tableName);
|
||||
if (isUUIDMap) {
|
||||
whereClause.append(".Target_UUID)");
|
||||
} else {
|
||||
whereClause.append(".Record_ID)");
|
||||
}
|
||||
|
||||
int noDel = 0;
|
||||
if (MAttachment.Table_Name.equals(tableName)) {
|
||||
|
|
Loading…
Reference in New Issue