use of org.apache.nifi.processors.groovyx.sql.OSql in project nifi by apache.
the class ExecuteGroovyScript method onInitSQL.
/**
* init SQL variables from DBCP services
*/
@SuppressWarnings("unchecked")
private void onInitSQL(HashMap SQL) throws SQLException {
for (Map.Entry e : (Set<Map.Entry>) SQL.entrySet()) {
DBCPService s = (DBCPService) e.getValue();
OSql sql = new OSql(s.getConnection());
// try to set autocommit to false
try {
if (sql.getConnection().getAutoCommit()) {
sql.getConnection().setAutoCommit(false);
}
} catch (Throwable ei) {
getLogger().warn("Failed to set autocommit=false for `" + e.getKey() + "`", ei);
}
e.setValue(sql);
}
}
use of org.apache.nifi.processors.groovyx.sql.OSql in project nifi by apache.
the class ExecuteGroovyScript method onFinitSQL.
/**
* finalize SQL services. no exceptions should be thrown.
*/
@SuppressWarnings("unchecked")
private void onFinitSQL(HashMap SQL) {
for (Map.Entry e : (Set<Map.Entry>) SQL.entrySet()) {
OSql sql = (OSql) e.getValue();
try {
if (!sql.getConnection().getAutoCommit()) {
// default autocommit value in nifi
sql.getConnection().setAutoCommit(true);
}
} catch (Throwable ei) {
getLogger().warn("Failed to set autocommit=true for `" + e.getKey() + "`", ei);
}
try {
sql.close();
sql = null;
} catch (Throwable ei) {
// Nothing to do
}
}
}