From 02009bc22d7d1e2082569a9cabe24bc5f3efd7e4 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 15 Jan 2019 18:38:01 +0100 Subject: [PATCH] IDEMPIERE-3870 PackIn issue with transactions --- .../src/org/adempiere/model/GenericPO.java | 2 +- .../src/org/compiere/db/AdempiereDatabase.java | 7 +++++++ org.adempiere.base/src/org/compiere/model/MTable.java | 9 ++++++--- org.adempiere.base/src/org/compiere/util/DB.java | 4 ++-- .../src/org/compiere/db/DB_Oracle.java | 8 ++++++-- .../src/org/compiere/db/DB_PostgreSQL.java | 5 ++++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/model/GenericPO.java b/org.adempiere.base/src/org/adempiere/model/GenericPO.java index 6fd50521e6..6536c4fa92 100644 --- a/org.adempiere.base/src/org/adempiere/model/GenericPO.java +++ b/org.adempiere.base/src/org/adempiere/model/GenericPO.java @@ -93,7 +93,7 @@ public class GenericPO extends PO { PropertiesWrapper wrapper = (PropertiesWrapper)ctx; p_ctx = wrapper.source; tableName = wrapper.tableName; - tableID = MTable.getTable_ID(tableName); + tableID = MTable.getTable_ID(tableName, this.get_TrxName()); // log.info("Table_ID: "+Table_ID); POInfo poi = POInfo.getPOInfo(ctx, tableID, this.get_TrxName()); return poi; diff --git a/org.adempiere.base/src/org/compiere/db/AdempiereDatabase.java b/org.adempiere.base/src/org/compiere/db/AdempiereDatabase.java index 0451e77f6b..877ef7402b 100644 --- a/org.adempiere.base/src/org/compiere/db/AdempiereDatabase.java +++ b/org.adempiere.base/src/org/compiere/db/AdempiereDatabase.java @@ -206,6 +206,13 @@ public interface AdempiereDatabase public String TO_NUMBER (BigDecimal number, int displayType); + /** + * Return next sequence this Sequence + * @param Sequence Name + * @param Transaction + */ + public int getNextID(String Name, String trxName); + /** * Return next sequence this Sequence * @param Sequence Name diff --git a/org.adempiere.base/src/org/compiere/model/MTable.java b/org.adempiere.base/src/org/compiere/model/MTable.java index 373f74d374..55e32993bb 100644 --- a/org.adempiere.base/src/org/compiere/model/MTable.java +++ b/org.adempiere.base/src/org/compiere/model/MTable.java @@ -58,7 +58,7 @@ public class MTable extends X_AD_Table /** * */ - private static final long serialVersionUID = 7527235342324308477L; + private static final long serialVersionUID = 4974471096496488963L; public final static int MAX_OFFICIAL_ID = 999999; @@ -614,19 +614,22 @@ public class MTable extends X_AD_Table } // getSQLCreate // globalqss + public static int getTable_ID(String tableName) { + return getTable_ID(tableName, null); + } /** * Grant independence to GenerateModel from AD_Table_ID * @param String tableName * @return int retValue */ - public static int getTable_ID(String tableName) { + public static int getTable_ID(String tableName, String trxName) { int retValue = 0; String SQL = "SELECT AD_Table_ID FROM AD_Table WHERE tablename = ?"; PreparedStatement pstmt = null; ResultSet rs = null; try { - pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, trxName); pstmt.setString(1, tableName); rs = pstmt.executeQuery(); if (rs.next()) diff --git a/org.adempiere.base/src/org/compiere/util/DB.java b/org.adempiere.base/src/org/compiere/util/DB.java index 072d6696d2..3972555cb1 100644 --- a/org.adempiere.base/src/org/compiere/util/DB.java +++ b/org.adempiere.base/src/org/compiere/util/DB.java @@ -1829,11 +1829,11 @@ public final class DB if(SYSTEM_NATIVE_SEQUENCE && !adempiereSys) { - int m_sequence_id = CConnection.get().getDatabase().getNextID(TableName+"_SQ"); + int m_sequence_id = CConnection.get().getDatabase().getNextID(TableName+"_SQ", trxName); if (m_sequence_id == -1) { // try to create the sequence and try again MSequence.createTableSequence(Env.getCtx(), TableName, trxName, true); - m_sequence_id = CConnection.get().getDatabase().getNextID(TableName+"_SQ"); + m_sequence_id = CConnection.get().getDatabase().getNextID(TableName+"_SQ", trxName); } return m_sequence_id; } diff --git a/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java b/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java index df59d4f924..4588832139 100644 --- a/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java +++ b/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java @@ -1248,8 +1248,12 @@ public class DB_Oracle implements AdempiereDatabase return m_convert; } - public int getNextID(String Name) { - int m_sequence_id = DB.getSQLValueEx(null, "SELECT "+Name.toUpperCase()+".nextval FROM DUAL"); + public int getNextID(String name) { + return getNextID(name, null); + } + + public int getNextID(String name, String trxName) { + int m_sequence_id = DB.getSQLValueEx(trxName, "SELECT "+name.toUpperCase()+".nextval FROM DUAL"); return m_sequence_id; } diff --git a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java index a9f0f15f40..c0ba95ae96 100755 --- a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java +++ b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java @@ -966,8 +966,11 @@ public class DB_PostgreSQL implements AdempiereDatabase } public int getNextID(String name) { + return getNextID(name, null); + } - int m_sequence_id = DB.getSQLValueEx(null, "SELECT nextval('"+name.toLowerCase()+"')"); + public int getNextID(String name, String trxName) { + int m_sequence_id = DB.getSQLValueEx(trxName, "SELECT nextval('"+name.toLowerCase()+"')"); return m_sequence_id; }