IDEMPIERE-3785 Fix potential duplicate key / documento and lock on Oracle

This commit is contained in:
Silvano Trinchero 2018-09-11 12:37:50 +02:00
parent 9132cee7f7
commit 93fcc43ee5
1 changed files with 20 additions and 3 deletions

View File

@ -123,7 +123,11 @@ public class MSequence extends X_AD_Sequence
+ "FROM AD_Sequence " + "FROM AD_Sequence "
+ "WHERE Name=?" + "WHERE Name=?"
+ " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' "; + " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' ";
if(adempiereSys)
selectSQL += " FOR UPDATE OF CurrentNextSys";
else
selectSQL += " FOR UPDATE OF CurrentNext";
} }
if (!DB.isOracle() && !DB.isPostgreSQL()) if (!DB.isOracle() && !DB.isPostgreSQL())
selectSQL = DB.getDatabase().convertStatement(selectSQL); selectSQL = DB.getDatabase().convertStatement(selectSQL);
@ -365,14 +369,27 @@ public class MSequence extends X_AD_Sequence
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' " + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "
+ "ORDER BY s.AD_Client_ID DESC"; + "ORDER BY s.AD_Client_ID DESC";
} }
if (DB.isPostgreSQL()) if (DB.isOracle() == false)
{ {
if ( ( isStartNewYear || isUseOrgLevel ) && !adempiereSys ) { if ( isStartNewYear || isUseOrgLevel ) {
selectSQL = selectSQL + " FOR UPDATE OF y"; selectSQL = selectSQL + " FOR UPDATE OF y";
} else { } else {
selectSQL = selectSQL + " FOR UPDATE OF s"; selectSQL = selectSQL + " FOR UPDATE OF s";
} }
} }
else
{
if (isStartNewYear || isUseOrgLevel) {
selectSQL = selectSQL + " FOR UPDATE OF y.";
} else {
selectSQL = selectSQL + " FOR UPDATE OF s.";
}
if(adempiereSys)
selectSQL = selectSQL + "CurrentNextSys";
else
selectSQL = selectSQL + "CurrentNext";
}
if (!DB.isOracle() && !DB.isPostgreSQL()) if (!DB.isOracle() && !DB.isPostgreSQL())
selectSQL = DB.getDatabase().convertStatement(selectSQL); selectSQL = DB.getDatabase().convertStatement(selectSQL);
Connection conn = null; Connection conn = null;