IDEMPIERE-1176 Cannot generate UUIDs on migrated database
This commit is contained in:
parent
eef3b475b9
commit
b68a7730ea
|
@ -0,0 +1,20 @@
|
||||||
|
-- Jul 15, 2013 3:50:50 PM COT
|
||||||
|
-- IDEMPIERE-1176 Cannot generate UUIDs on migrated database
|
||||||
|
INSERT INTO AD_Element (ColumnName,AD_Element_ID,Name,PrintName,AD_Element_UU,Created,Updated,AD_Org_ID,CreatedBy,UpdatedBy,IsActive,AD_Client_ID,EntityType) VALUES ('IsFillUUID',202570,'Fill UUID','Fill UUID','512112d3-bf9b-49a3-a354-90c710d52c6f',TO_DATE('2013-07-15 15:50:49','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2013-07-15 15:50:49','YYYY-MM-DD HH24:MI:SS'),0,100,100,'Y',0,'D')
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Jul 15, 2013 3:50:50 PM COT
|
||||||
|
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Help,PO_Description,PO_Help,Name,Description,PrintName,PO_Name,PO_PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Element_Trl_UU ) SELECT l.AD_Language,t.AD_Element_ID, t.Help,t.PO_Description,t.PO_Help,t.Name,t.Description,t.PrintName,t.PO_Name,t.PO_PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=202570 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Jul 15, 2013 3:51:35 PM COT
|
||||||
|
INSERT INTO AD_Process_Para (IsRange,AD_Element_ID,AD_Process_Para_ID,AD_Process_Para_UU,AD_Process_ID,AD_Reference_ID,IsMandatory,EntityType,Name,ColumnName,FieldLength,IsCentrallyMaintained,SeqNo,DefaultValue,IsActive,UpdatedBy,Updated,CreatedBy,Created,AD_Org_ID,IsEncrypted,AD_Client_ID) VALUES ('N',202570,200068,'ecd91936-ca2c-4262-87c1-4861c8b00663',53252,20,'Y','D','Fill UUID','IsFillUUID',10,'Y',20,'Y','Y',100,TO_DATE('2013-07-15 15:51:34','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2013-07-15 15:51:34','YYYY-MM-DD HH24:MI:SS'),0,'N',0)
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Jul 15, 2013 3:51:35 PM COT
|
||||||
|
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Help,Name,Description, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Process_Para_Trl_UU ) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Help,t.Name,t.Description, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=200068 AND NOT EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_Para_ID=t.AD_Process_Para_ID)
|
||||||
|
;
|
||||||
|
|
||||||
|
SELECT register_migration_script('201307151553_IDEMPIERE-1176.sql') FROM dual
|
||||||
|
;
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
-- Jul 15, 2013 3:50:50 PM COT
|
||||||
|
-- IDEMPIERE-1176 Cannot generate UUIDs on migrated database
|
||||||
|
INSERT INTO AD_Element (ColumnName,AD_Element_ID,Name,PrintName,AD_Element_UU,Created,Updated,AD_Org_ID,CreatedBy,UpdatedBy,IsActive,AD_Client_ID,EntityType) VALUES ('IsFillUUID',202570,'Fill UUID','Fill UUID','512112d3-bf9b-49a3-a354-90c710d52c6f',TO_TIMESTAMP('2013-07-15 15:50:49','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2013-07-15 15:50:49','YYYY-MM-DD HH24:MI:SS'),0,100,100,'Y',0,'D')
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Jul 15, 2013 3:50:50 PM COT
|
||||||
|
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Help,PO_Description,PO_Help,Name,Description,PrintName,PO_Name,PO_PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Element_Trl_UU ) SELECT l.AD_Language,t.AD_Element_ID, t.Help,t.PO_Description,t.PO_Help,t.Name,t.Description,t.PrintName,t.PO_Name,t.PO_PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=202570 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Jul 15, 2013 3:51:35 PM COT
|
||||||
|
INSERT INTO AD_Process_Para (IsRange,AD_Element_ID,AD_Process_Para_ID,AD_Process_Para_UU,AD_Process_ID,AD_Reference_ID,IsMandatory,EntityType,Name,ColumnName,FieldLength,IsCentrallyMaintained,SeqNo,DefaultValue,IsActive,UpdatedBy,Updated,CreatedBy,Created,AD_Org_ID,IsEncrypted,AD_Client_ID) VALUES ('N',202570,200068,'ecd91936-ca2c-4262-87c1-4861c8b00663',53252,20,'Y','D','Fill UUID','IsFillUUID',10,'Y',20,'Y','Y',100,TO_TIMESTAMP('2013-07-15 15:51:34','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2013-07-15 15:51:34','YYYY-MM-DD HH24:MI:SS'),0,'N',0)
|
||||||
|
;
|
||||||
|
|
||||||
|
-- Jul 15, 2013 3:51:35 PM COT
|
||||||
|
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Help,Name,Description, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Process_Para_Trl_UU ) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Help,t.Name,t.Description, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=200068 AND NOT EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Process_Para_ID=t.AD_Process_Para_ID)
|
||||||
|
;
|
||||||
|
|
||||||
|
SELECT register_migration_script('201307151553_IDEMPIERE-1176.sql') FROM dual
|
||||||
|
;
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -50,6 +49,8 @@ public class UUIDGenerator extends SvrProcess {
|
||||||
|
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
|
private boolean isFillUUID = false;
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger.getCLogger(UUIDGenerator.class);
|
private static CLogger log = CLogger.getCLogger(UUIDGenerator.class);
|
||||||
|
|
||||||
|
@ -63,6 +64,8 @@ public class UUIDGenerator extends SvrProcess {
|
||||||
;
|
;
|
||||||
else if (param.getParameterName().equals("TableName"))
|
else if (param.getParameterName().equals("TableName"))
|
||||||
tableName = param.getParameter().toString();
|
tableName = param.getParameter().toString();
|
||||||
|
else if (param.getParameterName().equals("IsFillUUID"))
|
||||||
|
isFillUUID = param.getParameterAsBoolean();
|
||||||
else
|
else
|
||||||
log.log(Level.SEVERE, "Unknown Parameter: " + param.getParameterName());
|
log.log(Level.SEVERE, "Unknown Parameter: " + param.getParameterName());
|
||||||
}
|
}
|
||||||
|
@ -79,7 +82,7 @@ public class UUIDGenerator extends SvrProcess {
|
||||||
tableName = tableName.trim();
|
tableName = tableName.trim();
|
||||||
if (!tableName.endsWith("%"))
|
if (!tableName.endsWith("%"))
|
||||||
tableName = tableName + "%";
|
tableName = tableName + "%";
|
||||||
String sql = "SELECT AD_Table_ID, TableName FROM AD_Table WHERE TableName LIKE ? AND IsView = 'N' AND IsActive='Y'";
|
String sql = "SELECT AD_Table_ID, TableName FROM AD_Table WHERE TableName LIKE ? AND IsView = 'N' AND IsActive='Y' ORDER BY TableName";
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -122,8 +125,16 @@ public class UUIDGenerator extends SvrProcess {
|
||||||
syncColumn(mColumn);
|
syncColumn(mColumn);
|
||||||
|
|
||||||
//update db
|
//update db
|
||||||
// COMMENT NEXT LINE ON RELEASE WORK
|
if (isFillUUID) {
|
||||||
updateUUID(mColumn, null);
|
// COMMENT NEXT LINE ON RELEASE WORK
|
||||||
|
updateUUID(mColumn, null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isFillUUID) {
|
||||||
|
MColumn mColumn = MColumn.get(getCtx(), AD_Column_ID);
|
||||||
|
// COMMENT NEXT LINE ON RELEASE WORK
|
||||||
|
updateUUID(mColumn, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -148,16 +159,21 @@ public class UUIDGenerator extends SvrProcess {
|
||||||
|
|
||||||
public static void updateUUID(MColumn column, String trxName) {
|
public static void updateUUID(MColumn column, String trxName) {
|
||||||
MTable table = (MTable) column.getAD_Table();
|
MTable table = (MTable) column.getAD_Table();
|
||||||
int AD_Column_ID = DB.getSQLValue(null, "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=? AND ColumnName=?", table.getAD_Table_ID(), table.getTableName()+"_ID");
|
if (table.getTableName().startsWith("T_")) {
|
||||||
|
// don't update UUID for temporary tables
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int AD_Column_ID = 0;
|
||||||
StringBuilder sql = new StringBuilder("SELECT ");
|
StringBuilder sql = new StringBuilder("SELECT ");
|
||||||
String keyColumn = null;
|
String keyColumn = null;
|
||||||
List<String> compositeKeys = null;
|
String[] compositeKeys = table.getKeyColumns();
|
||||||
if (AD_Column_ID > 0) {
|
if (compositeKeys == null || compositeKeys.length == 1) {
|
||||||
keyColumn = table.getTableName()+"_ID";
|
keyColumn = compositeKeys[0];
|
||||||
} else {
|
AD_Column_ID = table.getColumn(keyColumn).getAD_Column_ID();
|
||||||
compositeKeys = Arrays.asList(table.getKeyColumns());
|
compositeKeys = null;
|
||||||
}
|
}
|
||||||
if ((compositeKeys == null || compositeKeys.size() == 0) && keyColumn == null) {
|
if ((compositeKeys == null || compositeKeys.length == 0) && keyColumn == null) {
|
||||||
|
// TODO: Update using rowid for oracle or ctid for postgresql
|
||||||
log.warning("Cannot update orphan table " + table.getTableName() + " (not ID neither parents)");
|
log.warning("Cannot update orphan table " + table.getTableName() + " (not ID neither parents)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue