UUID Generator / IDEMPIERE-868
This commit is contained in:
parent
f2017776e5
commit
eb661f8a64
|
@ -0,0 +1,20 @@
|
|||
-- Apr 24, 2013 3:12:21 PM COT
|
||||
-- UUID Generator
|
||||
UPDATE AD_Role_OrgAccess SET AD_Role_OrgAccess_UU='fcc1cd49-542c-4647-8572-966a7d05a4dd',Updated=TO_DATE('2013-04-24 15:12:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Role_ID=50004 AND AD_Org_ID=0
|
||||
;
|
||||
|
||||
-- Apr 24, 2013 3:12:21 PM COT
|
||||
UPDATE AD_Role_OrgAccess SET AD_Role_OrgAccess_UU='4f0274ce-7551-48d0-ab52-98a5aed37787',Updated=TO_DATE('2013-04-24 15:12:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Role_ID=50004 AND AD_Org_ID=11
|
||||
;
|
||||
|
||||
-- Apr 24, 2013 3:12:21 PM COT
|
||||
UPDATE AD_Role_OrgAccess SET AD_Role_OrgAccess_UU='26832dd7-5711-4e8f-a1c6-5b4a049f3726',Updated=TO_DATE('2013-04-24 15:12:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Role_ID=50004 AND AD_Org_ID=12
|
||||
;
|
||||
|
||||
-- Apr 24, 2013 3:12:58 PM COT
|
||||
UPDATE AD_Message SET AD_Message_UU='07252108-a99a-4746-873a-6dceed406b0c' WHERE AD_Message_ID=20001
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201304241518_UUIDGen.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
-- Apr 24, 2013 3:12:21 PM COT
|
||||
-- UUID Generator
|
||||
UPDATE AD_Role_OrgAccess SET AD_Role_OrgAccess_UU='fcc1cd49-542c-4647-8572-966a7d05a4dd',Updated=TO_TIMESTAMP('2013-04-24 15:12:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Role_ID=50004 AND AD_Org_ID=0
|
||||
;
|
||||
|
||||
-- Apr 24, 2013 3:12:21 PM COT
|
||||
UPDATE AD_Role_OrgAccess SET AD_Role_OrgAccess_UU='4f0274ce-7551-48d0-ab52-98a5aed37787',Updated=TO_TIMESTAMP('2013-04-24 15:12:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Role_ID=50004 AND AD_Org_ID=11
|
||||
;
|
||||
|
||||
-- Apr 24, 2013 3:12:21 PM COT
|
||||
UPDATE AD_Role_OrgAccess SET AD_Role_OrgAccess_UU='26832dd7-5711-4e8f-a1c6-5b4a049f3726',Updated=TO_TIMESTAMP('2013-04-24 15:12:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Role_ID=50004 AND AD_Org_ID=12
|
||||
;
|
||||
|
||||
-- Apr 24, 2013 3:12:58 PM COT
|
||||
UPDATE AD_Message SET AD_Message_UU='07252108-a99a-4746-873a-6dceed406b0c' WHERE AD_Message_ID=20001
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201304241518_UUIDGen.sql') FROM dual
|
||||
;
|
||||
|
|
@ -58,18 +58,16 @@ public class UUIDGenerator extends SvrProcess {
|
|||
*/
|
||||
@Override
|
||||
protected void prepare() {
|
||||
ProcessInfoParameter[] parameters = getProcessInfo().getParameter();
|
||||
if (parameters == null || parameters.length == 0)
|
||||
return;
|
||||
for(ProcessInfoParameter param : parameters) {
|
||||
if (param.getParameterName().equals("TableName")) {
|
||||
for(ProcessInfoParameter param : getParameter()) {
|
||||
if (param.getParameter() == null)
|
||||
;
|
||||
else if (param.getParameterName().equals("TableName"))
|
||||
tableName = param.getParameter().toString();
|
||||
break;
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + param.getParameterName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.compiere.process.SvrProcess#doIt()
|
||||
*/
|
||||
|
@ -81,15 +79,12 @@ public class UUIDGenerator extends SvrProcess {
|
|||
tableName = tableName.trim();
|
||||
if (!tableName.endsWith("%"))
|
||||
tableName = tableName + "%";
|
||||
StringBuilder sql = new StringBuilder("SELECT AD_Table_ID, TableName FROM AD_Table WHERE TableName like ? AND IsView = 'N' AND IsActive='Y'");
|
||||
if (DB.isOracle()) {
|
||||
sql.append(" ESCAPE '\' ");
|
||||
}
|
||||
String sql = "SELECT AD_Table_ID, TableName FROM AD_Table WHERE TableName LIKE ? AND IsView = 'N' AND IsActive='Y'";
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
int count = 0;
|
||||
try {
|
||||
stmt = DB.prepareStatement(sql.toString(), null);
|
||||
stmt = DB.prepareStatement(sql, null);
|
||||
stmt.setString(1, tableName);
|
||||
rs = stmt.executeQuery();
|
||||
while(rs.next()) {
|
||||
|
@ -122,12 +117,27 @@ public class UUIDGenerator extends SvrProcess {
|
|||
mColumn.setName(columnName);
|
||||
mColumn.setVersion(Env.ONE);
|
||||
mColumn.saveEx();
|
||||
AD_Column_ID = mColumn.getAD_Column_ID();
|
||||
|
||||
syncColumn(mColumn);
|
||||
|
||||
//update db
|
||||
// COMMENT NEXT LINE ON RELEASE WORK
|
||||
updateUUID(mColumn, null);
|
||||
}
|
||||
|
||||
/*
|
||||
// RELEASE WORK CODE
|
||||
// following code could be used potentially to fill empty values on UU columns if they are already created
|
||||
int cnt = DB.getSQLValue(null, "SELECT COUNT(1) FROM " + cTableName + " WHERE " + columnName + " IS NULL");
|
||||
if (cnt > 0) {
|
||||
addLog (0, null, null, cTableName);
|
||||
//update db
|
||||
updateAllUUID(MColumn.get(getCtx(), AD_Column_ID));
|
||||
}
|
||||
// END RELEASE WORK CODE
|
||||
*/
|
||||
|
||||
}
|
||||
} finally {
|
||||
DB.close(rs,stmt);
|
||||
|
@ -322,4 +332,68 @@ public class UUIDGenerator extends SvrProcess {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// RELEASE WORK CODE
|
||||
public static void updateAllUUID(MColumn column) {
|
||||
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");
|
||||
StringBuffer sql = new StringBuffer("SELECT ");
|
||||
String keyColumn = null;
|
||||
|
||||
// second script - just generate for tables with _ID primary key
|
||||
//if (AD_Column_ID > 0)
|
||||
// return;
|
||||
|
||||
if (AD_Column_ID > 0) {
|
||||
keyColumn = table.getTableName()+"_ID";
|
||||
} else if (DB.isOracle()) {
|
||||
keyColumn = "rowid";
|
||||
} else if (DB.isPostgreSQL()) {
|
||||
keyColumn = "ctid";
|
||||
}
|
||||
// keyColumn = "*";
|
||||
sql.append(keyColumn).append(",").append(table.getTableName()).append(".* FROM ").append(table.getTableName());
|
||||
sql.append(" WHERE ").append(column.getColumnName()).append(" IS NULL ");
|
||||
String updateSQL = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Trx trx = null;
|
||||
try {
|
||||
trx = Trx.get(Trx.createTrxName("UUIDGen"), true);
|
||||
trx.start();
|
||||
stmt = DB.prepareStatement(sql.toString(), trx.getTrxName());
|
||||
stmt.setFetchSize(100);
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
if (AD_Column_ID > 0) {
|
||||
int recordId = rs.getInt(1);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
updateSQL = "UPDATE "+table.getTableName()+" SET "+column.getColumnName()+"='" + uuid.toString() + "' WHERE "+keyColumn+"="+recordId;
|
||||
DB.executeUpdateEx(updateSQL,null);
|
||||
} else {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
// String rowId = rs.getString(1);
|
||||
// DB.executeUpdateEx(updateSQL+"'"+rowId+"'",new Object[]{uuid.toString()},null);
|
||||
PO po = table.getPO(rs, null);
|
||||
if (po.get_KeyColumns().length > 0) {
|
||||
po.set_ValueOfColumn(column.getColumnName(), uuid.toString());
|
||||
po.saveEx();
|
||||
}
|
||||
}
|
||||
}
|
||||
trx.commit();
|
||||
} catch (SQLException e) {
|
||||
if (trx != null)
|
||||
trx.rollback();
|
||||
throw new DBException(e);
|
||||
} finally {
|
||||
DB.close(rs, stmt);
|
||||
if (trx != null)
|
||||
trx.close();
|
||||
}
|
||||
}
|
||||
// END RELEASE WORK CODE
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue