IDEMPIERE-3350 Accounting Processor GL postings to "secondary" schema unreliable. Use savepoint to avoid rollback of doc workflow transaction.

This commit is contained in:
Heng Sin Low 2017-06-23 16:11:17 +08:00
parent 2ac53ef2fd
commit b4990515b0
1 changed files with 29 additions and 4 deletions

View File

@ -19,6 +19,7 @@ package org.compiere.acct;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.List;
@ -286,8 +287,10 @@ public class DocManager {
Trx trx = Trx.get(trxName, true);
String error = null;
Savepoint savepoint = null;
try
{
savepoint = localTrxName == null ? trx.setSavepoint(null) : null;
String status = "";
for(MAcctSchema as : ass)
{
@ -298,12 +301,18 @@ public class DocManager {
status = doc.getPostStatus();
if (error != null && error.trim().length() > 0)
{
if (savepoint != null)
trx.rollback(savepoint);
else
trx.rollback();
return error;
}
}
else
{
if (savepoint != null)
trx.rollback(savepoint);
else
trx.rollback();
return "NoDoc";
}
@ -319,22 +328,38 @@ public class DocManager {
if (localTrxName != null) {
if (trx != null)
trx.rollback();
} else if (trx != null && savepoint != null) {
trx.rollback(savepoint);
savepoint = null;
}
if (dbError != null)
error = dbError.getValue();
else
error = "SaveError";
}
if (localTrxName != null) {
if (trx != null)
if (savepoint != null)
{
try
{
trx.releaseSavepoint(savepoint);
} catch (SQLException e1) {}
savepoint = null;
}
if (localTrxName != null && error == null) {
if (trx != null) {
trx.commit();
}
}
}
catch (Exception e)
{
if (localTrxName != null) {
if (trx != null)
trx.rollback();
} else if (trx != null && savepoint != null) {
try {
trx.rollback(savepoint);
} catch (SQLException e1) {}
}
if (e instanceof RuntimeException)
throw (RuntimeException) e;