List of usage examples for org.apache.commons.dbutils QueryRunner update
public int update(Connection conn, String sql, Object... params) throws SQLException
From source file:org.rti.zcore.dar.utils.DatabaseUtils.java
/** * @param conn//from ww w . j a v a 2 s. c o m * @param sql * @param params * @return * @throws Exception */ public static int update(Connection conn, java.lang.String sql, java.lang.Object[] params) throws java.lang.Exception { QueryRunner run = new QueryRunner(); int result = run.update(conn, sql, params); return result; }
From source file:org.rti.zcore.dar.utils.DatabaseUtils.java
public static void save(Connection conn, String sql, java.lang.Object[] values) throws ServletException, SQLException { //DataSource dataSource = null; //dataSource = DatabaseUtils.getZEPRSDataSource(); //Connection conn = dataSource.getConnection(); // conn.setAutoCommit(true); QueryRunner run = new QueryRunner(); // First do the insert run.update(conn, sql, values); }
From source file:org.sonar.server.db.migrations.v36.ViolationConverter.java
private void convert(List<Map<String, Object>> rows, Long[] violationIds) throws SQLException { Connection readConnection = null; Connection writeConnection = null; try {/*from ww w. j a v a 2s.com*/ readConnection = db.getDataSource().getConnection(); writeConnection = db.getDataSource().getConnection(); writeConnection.setAutoCommit(false); List<Object[]> allParams = Lists.newArrayList(); List<Map<String, Object>> allComments = Lists.newArrayList(); QueryRunner runner = new QueryRunner(); for (Map<String, Object> row : rows) { Long componentId = (Long) row.get(PROJECT_ID); if (componentId == null) { continue; } String issueKey = UUID.randomUUID().toString(); String status, severity, reporter = null; boolean manualSeverity; Object createdAt = Objects.firstNonNull(row.get(CREATED_AT), ONE_YEAR_AGO); Object updatedAt; Long reviewId = (Long) row.get(REVIEW_ID); if (reviewId == null) { // violation without review status = STATUS_OPEN; manualSeverity = false; severity = (String) row.get(SEVERITY); updatedAt = createdAt; } else { // violation + review String reviewStatus = (String) row.get(REVIEW_STATUS); status = (STATUS_OPEN.equals(reviewStatus) ? STATUS_CONFIRMED : reviewStatus); manualSeverity = Objects.firstNonNull((Boolean) row.get(REVIEW_MANUAL_SEVERITY), false); severity = (String) row.get(REVIEW_SEVERITY); updatedAt = Objects.firstNonNull(row.get(REVIEW_UPDATED_AT), ONE_YEAR_AGO); if ((Boolean) row.get(REVIEW_MANUAL_VIOLATION)) { reporter = referentials.userLogin((Long) row.get(REVIEW_REPORTER_ID)); } List<Map<String, Object>> comments = runner.query(readConnection, ReviewCommentsHandler.SQL + reviewId, new ReviewCommentsHandler()); for (Map<String, Object> comment : comments) { comment.put(ISSUE_KEY, issueKey); allComments.add(comment); } } Object[] params = new Object[20]; params[0] = issueKey; params[1] = componentId; params[2] = row.get(ROOT_PROJECT_ID); params[3] = row.get(RULE_ID); params[4] = severity; params[5] = manualSeverity; params[6] = row.get(MESSAGE); params[7] = row.get(LINE); params[8] = row.get(COST); params[9] = status; params[10] = row.get(REVIEW_RESOLUTION); params[11] = row.get(CHECKSUM); params[12] = reporter; params[13] = referentials.userLogin((Long) row.get(REVIEW_ASSIGNEE_ID)); params[14] = referentials.actionPlan((Long) row.get(PLAN_ID)); params[15] = row.get(REVIEW_DATA); params[16] = createdAt; params[17] = updatedAt; params[18] = createdAt; params[19] = updatedAt; allParams.add(params); } runner.batch(writeConnection, SQL_INSERT_ISSUE, allParams.toArray(new Object[allParams.size()][])); insertComments(writeConnection, allComments); runner.update(writeConnection, SQL_DELETE_RULE_FAILURES, violationIds); writeConnection.commit(); progress.increment(rows.size()); } finally { DbUtils.closeQuietly(readConnection); DbUtils.closeQuietly(writeConnection); } }