From 133c0450ae0054c11b21899fc9506a9d562d0891 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 22 Jun 2012 17:53:14 +0800 Subject: [PATCH] IDEMPIERE-303 AD_TreeNodeMM_UU is null after create one new menu item --- .../org/adempiere/process/UUIDGenerator.java | 29 ++++++++++++++----- .../src/org/compiere/model/PO.java | 6 ++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/process/UUIDGenerator.java b/org.adempiere.base/src/org/adempiere/process/UUIDGenerator.java index 2a62be3354..115ba9e56d 100644 --- a/org.adempiere.base/src/org/adempiere/process/UUIDGenerator.java +++ b/org.adempiere.base/src/org/adempiere/process/UUIDGenerator.java @@ -121,7 +121,7 @@ public class UUIDGenerator extends SvrProcess { syncColumn(mColumn); //update db - updateUUID(mColumn); + updateUUID(mColumn, null); } } } finally { @@ -130,7 +130,7 @@ public class UUIDGenerator extends SvrProcess { return count + " table altered"; } - public static void updateUUID(MColumn column) { + public static void updateUUID(MColumn column, String trxName) { 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 "); @@ -160,12 +160,18 @@ public class UUIDGenerator extends SvrProcess { } updateSQL = updateSQL.substring(0, updateSQL.length() - " AND ".length()); } + + boolean localTrx = false; PreparedStatement stmt = null; ResultSet rs = null; - Trx trx = null; - try { + Trx trx = trxName != null ? Trx.get(trxName, false) : null; + if (trx == null) { trx = Trx.get(Trx.createTrxName(), true); - trx.start(); + localTrx = true; + } + try { + if (localTrx) + trx.start(); stmt = DB.prepareStatement(sql.toString(), trx.getTrxName()); stmt.setFetchSize(100); rs = stmt.executeQuery(); @@ -174,7 +180,7 @@ public class UUIDGenerator extends SvrProcess { int recordId = rs.getInt(1); if (recordId > MTable.MAX_OFFICIAL_ID) { UUID uuid = UUID.randomUUID(); - DB.executeUpdateEx(updateSQL,new Object[]{uuid.toString(), recordId},null); + DB.executeUpdateEx(updateSQL,new Object[]{uuid.toString(), recordId}, trx.getTrxName()); } } else { UUID uuid = UUID.randomUUID(); @@ -183,15 +189,22 @@ public class UUIDGenerator extends SvrProcess { for (String s : compositeKeys) { params.add(rs.getObject(s)); } - DB.executeUpdateEx(updateSQL,params.toArray(),null); + DB.executeUpdateEx(updateSQL,params.toArray(),trx.getTrxName()); } } + if (localTrx) { + trx.commit(true); + } } catch (SQLException e) { + if (localTrx) { + trx.rollback(); + } throw new DBException(e); } finally { DB.close(rs, stmt); - if (trx != null) + if (localTrx) { trx.close(); + } } } diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index 26ec875680..9d2c2cfbfc 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -3365,7 +3365,7 @@ public abstract class PO int no = DB.executeUpdate(sql.toString(), m_trxName); if (uuidColumnId > 0 && !uuidFunction) { MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName()); - UUIDGenerator.updateUUID(column); + UUIDGenerator.updateUUID(column, get_TrxName()); } log.fine("#" + no); return no > 0; @@ -3548,7 +3548,7 @@ public abstract class PO //fall back to the slow java client update code if (uuidColumnId > 0 && !uuidFunction) { MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName()); - UUIDGenerator.updateUUID(column); + UUIDGenerator.updateUUID(column, get_TrxName()); } return no > 0; } // insert_Accounting @@ -3626,7 +3626,7 @@ public abstract class PO if (uuidColumnId > 0 && !uuidFunction ) { MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName()); - UUIDGenerator.updateUUID(column); + UUIDGenerator.updateUUID(column, get_TrxName()); } return no > 0; } // insert_Tree