IDEMPIERE-3057 - improve notification from SQL Statements showing the count of records affected
This commit is contained in:
parent
fb2c89fbca
commit
9132cee7f7
|
@ -56,16 +56,17 @@ public class SQLMandatoryElementHandler extends AbstractElementHandler {
|
||||||
if (sql.endsWith(";") && !(sql.toLowerCase().endsWith("end;")))
|
if (sql.endsWith(";") && !(sql.toLowerCase().endsWith("end;")))
|
||||||
sql = sql.substring(0, sql.length() - 1);
|
sql = sql.substring(0, sql.length() - 1);
|
||||||
sql = Env.parseContext(Env.getCtx(), 0, sql, false);
|
sql = Env.parseContext(Env.getCtx(), 0, sql, false);
|
||||||
|
int count = 0;
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, "", 0);
|
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, "", 0);
|
||||||
try {
|
try {
|
||||||
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
|
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
|
||||||
if (DBType.equals("ALL")) {
|
if (DBType.equals("ALL")) {
|
||||||
int n = pstmt.executeUpdate();
|
count = pstmt.executeUpdate();
|
||||||
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory: "+ getStringValue(element, "statement") + " ReturnValue="+n);
|
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory: "+ getStringValue(element, "statement") + " ReturnValue="+count);
|
||||||
} else if (DB.isOracle() && DBType.equals("Oracle")) {
|
} else if (DB.isOracle() && DBType.equals("Oracle")) {
|
||||||
int n = pstmt.executeUpdate();
|
count = pstmt.executeUpdate();
|
||||||
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+n);
|
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+count);
|
||||||
} else if (DB.isPostgreSQL()
|
} else if (DB.isPostgreSQL()
|
||||||
&& ( DBType.equals("Postgres")
|
&& ( DBType.equals("Postgres")
|
||||||
|| DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand
|
|| DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand
|
||||||
|
@ -79,18 +80,18 @@ public class SQLMandatoryElementHandler extends AbstractElementHandler {
|
||||||
Statement stmt = null;
|
Statement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = pstmt.getConnection().createStatement();
|
stmt = pstmt.getConnection().createStatement();
|
||||||
int n = stmt.executeUpdate (sql);
|
count = stmt.executeUpdate (sql);
|
||||||
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n);
|
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Mandatory for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+count);
|
||||||
} finally {
|
} finally {
|
||||||
DB.close(stmt);
|
DB.close(stmt);
|
||||||
stmt = null;
|
stmt = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logImportDetail (ctx, impDetail, 1, "SQLMandatory",1,"Execute");
|
logImportDetail (ctx, impDetail, 1, "SQLMandatory",count,"Execute");
|
||||||
ctx.packIn.getNotifier().addSuccessLine("-> " + sql);
|
ctx.packIn.getNotifier().addSuccessLine("-> " + sql);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ctx.packIn.getNotifier().addFailureLine("SQL Mandatory failed, error (" + e.getLocalizedMessage() + "):");
|
ctx.packIn.getNotifier().addFailureLine("SQL Mandatory failed, error (" + e.getLocalizedMessage() + "):");
|
||||||
logImportDetail (ctx, impDetail, 0, "SQLMandatory",1,"Execute");
|
logImportDetail (ctx, impDetail, 0, "SQLMandatory",-1,"Execute");
|
||||||
ctx.packIn.getNotifier().addFailureLine("-> " + sql);
|
ctx.packIn.getNotifier().addFailureLine("-> " + sql);
|
||||||
log.log(Level.SEVERE,"SQLMandatory", e);
|
log.log(Level.SEVERE,"SQLMandatory", e);
|
||||||
throw new AdempiereException(e);
|
throw new AdempiereException(e);
|
||||||
|
|
|
@ -49,6 +49,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
|
||||||
sql = sql.substring(0, sql.length() - 1);
|
sql = sql.substring(0, sql.length() - 1);
|
||||||
sql=Env.parseContext(Env.getCtx(), 0, sql, false); // tbayen IDEMPIERE-2140
|
sql=Env.parseContext(Env.getCtx(), 0, sql, false); // tbayen IDEMPIERE-2140
|
||||||
Savepoint savepoint = null;
|
Savepoint savepoint = null;
|
||||||
|
int count = 0;
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
X_AD_Package_Imp_Detail impDetail = null;
|
X_AD_Package_Imp_Detail impDetail = null;
|
||||||
impDetail = createImportDetail(ctx, element.qName, "", 0);
|
impDetail = createImportDetail(ctx, element.qName, "", 0);
|
||||||
|
@ -61,11 +62,11 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
|
||||||
|
|
||||||
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
|
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
|
||||||
if (DBType.equals("ALL")) {
|
if (DBType.equals("ALL")) {
|
||||||
int n = pstmt.executeUpdate();
|
count = pstmt.executeUpdate();
|
||||||
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+n);
|
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+count);
|
||||||
} else if (DB.isOracle() == true && DBType.equals("Oracle")) {
|
} else if (DB.isOracle() == true && DBType.equals("Oracle")) {
|
||||||
int n = pstmt.executeUpdate();
|
count = pstmt.executeUpdate();
|
||||||
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+n);
|
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+count);
|
||||||
} else if (DB.isPostgreSQL()
|
} else if (DB.isPostgreSQL()
|
||||||
&& ( DBType.equals("Postgres")
|
&& ( DBType.equals("Postgres")
|
||||||
|| DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand
|
|| DBType.equals("PostgreSQL") // backward compatibility with old packages developed by hand
|
||||||
|
@ -80,14 +81,14 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
|
||||||
Statement stmt = null;
|
Statement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = pstmt.getConnection().createStatement();
|
stmt = pstmt.getConnection().createStatement();
|
||||||
int n = stmt.executeUpdate (sql);
|
count = stmt.executeUpdate (sql);
|
||||||
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n);
|
if (log.isLoggable(Level.INFO)) log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+count);
|
||||||
} finally {
|
} finally {
|
||||||
DB.close(stmt);
|
DB.close(stmt);
|
||||||
stmt = null;
|
stmt = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logImportDetail (ctx, impDetail, 1, "SQLStatement",1,"Execute");
|
logImportDetail (ctx, impDetail, 1, "SQLStatement",count,"Execute");
|
||||||
ctx.packIn.getNotifier().addSuccessLine("-> " + sql);
|
ctx.packIn.getNotifier().addSuccessLine("-> " + sql);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// rollback immediately on exception to avoid a wrong SQL stop the whole process
|
// rollback immediately on exception to avoid a wrong SQL stop the whole process
|
||||||
|
@ -105,7 +106,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler {
|
||||||
savepoint = null;
|
savepoint = null;
|
||||||
}
|
}
|
||||||
ctx.packIn.getNotifier().addFailureLine("SQL statement failed but ignored, error (" + e.getLocalizedMessage() + "): ");
|
ctx.packIn.getNotifier().addFailureLine("SQL statement failed but ignored, error (" + e.getLocalizedMessage() + "): ");
|
||||||
logImportDetail (ctx, impDetail, 0, "SQLStatement",1,"Execute");
|
logImportDetail (ctx, impDetail, 0, "SQLStatement",-1,"Execute");
|
||||||
ctx.packIn.getNotifier().addFailureLine("-> " + sql);
|
ctx.packIn.getNotifier().addFailureLine("-> " + sql);
|
||||||
log.log(Level.SEVERE,"SQLStatement", e);
|
log.log(Level.SEVERE,"SQLStatement", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue