Example usage for org.apache.commons.dbutils DbUtils closeQuietly

List of usage examples for org.apache.commons.dbutils DbUtils closeQuietly

Introduction

In this page you can find the example usage for org.apache.commons.dbutils DbUtils closeQuietly.

Prototype

public static void closeQuietly(Statement stmt) 

Source Link

Document

Close a Statement, avoid closing if null and hide any SQLExceptions that occur.

Usage

From source file:azkaban.executor.JdbcExecutorLoader.java

@Override
public void uploadAttachmentFile(ExecutableNode node, File file) throws ExecutorManagerException {
    Connection connection = getConnection();
    try {//from w  w  w .  j av a 2 s .  c o m
        uploadAttachmentFile(connection, node, file, defaultEncodingType);
        connection.commit();
    } catch (SQLException e) {
        throw new ExecutorManagerException("Error committing attachments ", e);
    } catch (IOException e) {
        throw new ExecutorManagerException("Error uploading attachments ", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
}

From source file:com.mirth.connect.server.controllers.tests.TestUtils.java

public static List<?> selectColumn(String query) {
    Connection connection = null;
    Statement statement = null;/*from   w  ww . j ava 2  s  .  c o  m*/
    ResultSet resultSet = null;

    try {
        connection = getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery(query);
        List<Object> col = new ArrayList<Object>();

        while (resultSet.next()) {
            col.add(resultSet.getObject(1));
        }

        return col;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(resultSet);
        DbUtils.closeQuietly(statement);
        DbUtils.closeQuietly(connection);
    }
}

From source file:azkaban.project.JdbcProjectLoader.java

@Override
public void uploadFlows(Project project, int version, Collection<Flow> flows) throws ProjectManagerException {
    // We do one at a time instead of batch... because well, the batch could be
    // large.//from www  . jav  a2s.  co  m
    logger.info("Uploading flows");
    Connection connection = getConnection();

    try {
        for (Flow flow : flows) {
            uploadFlow(connection, project, version, flow, defaultEncodingType);
        }
        connection.commit();
    } catch (IOException e) {
        throw new ProjectManagerException("Flow Upload failed.", e);
    } catch (SQLException e) {
        throw new ProjectManagerException("Flow Upload failed.", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
}

From source file:azkaban.executor.JdbcExecutorLoader.java

private Connection getConnection() throws ExecutorManagerException {
    Connection connection = null;
    try {/*w ww. ja v  a 2 s.c  o m*/
        connection = super.getDBConnection(false);
    } catch (Exception e) {
        DbUtils.closeQuietly(connection);
        throw new ExecutorManagerException("Error getting DB connection.", e);
    }
    return connection;
}

From source file:azkaban.project.JdbcProjectLoader.java

@Override
public void uploadFlow(Project project, int version, Flow flow) throws ProjectManagerException {
    logger.info("Uploading flows");
    Connection connection = getConnection();

    try {// w w  w  . j  a  va2s .  co m
        uploadFlow(connection, project, version, flow, defaultEncodingType);
        connection.commit();
    } catch (IOException e) {
        throw new ProjectManagerException("Flow Upload failed.", e);
    } catch (SQLException e) {
        throw new ProjectManagerException("Flow Upload failed commit.", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
}

From source file:com.quinsoft.zeidon.dbhandler.JdbcHandler.java

@Override
protected int executeStatement(View view, EntityDef entityDef, SqlStatement stmt) {
    String sql = stmt.getAssembledCommand();
    logSql(stmt);/*from   ww w.j  a  v a 2 s. co m*/

    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = prepareAndBind(stmt, sql, view, entityDef, stmt.commandType);

        if (stmt.commandType == SqlCommand.INSERT) {
            ps.executeUpdate();

            if (useDbGenerateKeys()) {
                generatedKeys = new ArrayList<Object>();
                ResultSet rs2 = ps.getGeneratedKeys();
                try {
                    while (rs2.next()) {
                        Integer i = rs2.getInt(1);
                        generatedKeys.add(i);
                    }
                } finally {
                    DbUtils.closeQuietly(rs2);
                }
            } else
                generatedKeys = null;

        } else if (stmt.commandType == SqlCommand.SELECT) {
            // This should be getting the count.
            rs = ps.executeQuery();
            return rs.getInt(1);
        } else {
            ps.execute();
        }
    } catch (Exception e) {
        throw ZeidonException.prependMessage(e, generateErrorMessageWithBoundAttributes(sql, entityDef, stmt));
    } finally {
        close(rs, ps);
    }

    return 0;
}

From source file:azkaban.project.JdbcProjectLoader.java

@Override
public void updateFlow(Project project, int version, Flow flow) throws ProjectManagerException {
    logger.info("Uploading flows");
    Connection connection = getConnection();

    try {/*from   w  ww . j  a  v a2  s.  c o  m*/
        QueryRunner runner = new QueryRunner();
        String json = JSONUtils.toJSON(flow.toObject());
        byte[] stringData = json.getBytes("UTF-8");
        byte[] data = stringData;

        if (defaultEncodingType == EncodingType.GZIP) {
            data = GZIPUtils.gzipBytes(stringData);
        }

        logger.info("Flow upload " + flow.getId() + " is byte size " + data.length);
        final String UPDATE_FLOW = "UPDATE project_flows SET encoding_type=?,json=? WHERE project_id=? AND version=? AND flow_id=?";
        try {
            runner.update(connection, UPDATE_FLOW, defaultEncodingType.getNumVal(), data, project.getId(),
                    version, flow.getId());
        } catch (SQLException e) {
            e.printStackTrace();
            throw new ProjectManagerException("Error inserting flow " + flow.getId(), e);
        }
        connection.commit();
    } catch (IOException e) {
        throw new ProjectManagerException("Flow Upload failed.", e);
    } catch (SQLException e) {
        throw new ProjectManagerException("Flow Upload failed commit.", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
}

From source file:io.personium.diff.App.java

private int registToWorkTable(Connection connection, Map<String, Long> idMap) {
    int expectedRows = idMap.keySet().size();
    int actualRows = 0;
    StringBuilder sql = new StringBuilder("insert into data_check.CHECK_ES(id, updated) values");
    for (int i = 0; i < expectedRows; i++) {
        if (i > 0) {
            sql.append(",");
        }/*from  w w  w.  j a va 2s  .  c  om*/
        sql.append("(?,?)");
    }

    PreparedStatement stmt = null;
    try {
        stmt = connection.prepareStatement(sql.toString());
        int index = 1;
        for (String id : idMap.keySet()) {
            stmt.setString(index++, id);
            if (idMap.get(id) == null) {
                stmt.setLong(index++, Integer.MIN_VALUE);
            } else {
                stmt.setLong(index++, idMap.get(id));
            }
        }
        actualRows = stmt.executeUpdate();
    } catch (SQLException e) {
        log.warn("Faild to registToWorkTable");
        log.info(e.getMessage());
    } finally {
        DbUtils.closeQuietly(stmt);
    }
    return actualRows;
}

From source file:azkaban.project.JdbcProjectLoader.java

@Override
public void uploadProjectProperties(Project project, List<Props> properties) throws ProjectManagerException {
    Connection connection = getConnection();

    try {/*from ww  w . j  a va 2 s. c  o  m*/
        for (Props props : properties) {
            uploadProjectProperty(connection, project, props.getSource(), props);
        }
        connection.commit();
    } catch (SQLException e) {
        throw new ProjectManagerException("Error uploading project property files", e);
    } catch (IOException e) {
        throw new ProjectManagerException("Error uploading project property files", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
}

From source file:azkaban.project.JdbcProjectLoader.java

@Override
public void uploadProjectProperty(Project project, Props props) throws ProjectManagerException {
    Connection connection = getConnection();
    try {/*from  w  ww  . jav  a 2 s .  c  o  m*/
        uploadProjectProperty(connection, project, props.getSource(), props);
        connection.commit();
    } catch (SQLException e) {
        throw new ProjectManagerException("Error uploading project property files", e);
    } catch (IOException e) {
        throw new ProjectManagerException("Error uploading project property file", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
}