Search in sources :

Example 1 with OSql

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);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DBCPService(org.apache.nifi.dbcp.DBCPService) OSql(org.apache.nifi.processors.groovyx.sql.OSql) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with OSql

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
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OSql(org.apache.nifi.processors.groovyx.sql.OSql) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 OSql (org.apache.nifi.processors.groovyx.sql.OSql)2 DBCPService (org.apache.nifi.dbcp.DBCPService)1