Example usage for org.apache.commons.dbutils QueryRunner update

List of usage examples for org.apache.commons.dbutils QueryRunner update

Introduction

In this page you can find the example usage for org.apache.commons.dbutils QueryRunner update.

Prototype

public int update(Connection conn, String sql, Object... params) throws SQLException 

Source Link

Document

Execute an SQL INSERT, UPDATE, or DELETE query.

Usage

From source file:com.versatus.jwebshield.securitylock.SecurityLockService.java

public boolean resetLock(int userId, String ip) throws SQLException {

    QueryRunner run = new QueryRunner();
    Connection conn = dbHelper.getConnection();

    logger.info("resetting lock for IP " + ip);
    int r = run.update(conn, resetLockSql, new Object[] { ip });

    logger.debug("checkAccountLock: reset response=" + r);

    return r > 0;
}

From source file:hermes.store.schema.DefaultJDBCAdapter.java

public void createStore(Connection connection, String storeId) throws SQLException {
    try {//from  w w  w .  ja v a 2  s.co  m
        final QueryRunner runner = new QueryRunner();

        runner.update(connection, "insert into storeInfo values ( ? )", new Object[] { storeId });
    } catch (SQLException ex) {
        log.debug("swallowing " + ex.getMessage());
    }

}

From source file:hermes.store.schema.DefaultJDBCAdapter.java

public void remove(Connection connection, String storeId, String destination)
        throws SQLException, JMSException {
    final QueryRunner runner = new QueryRunner();

    if (runner.update(connection,
            "delete from messages where messageid in (select messageid from stores where storeid=? and destination=?)",
            new Object[] { storeId, destination }) > 0) {
        runner.update(connection, "delete from stores where storeid=? and destination=?",
                new Object[] { storeId, destination });
    }//from  w  ww  .ja v a 2s.  c  o  m
}

From source file:hermes.store.schema.DefaultJDBCAdapter.java

public void remove(Connection connection, String storeId, Message message) throws SQLException, JMSException {
    final QueryRunner runner = new QueryRunner();

    if (runner.update(connection, "delete from stores where storeid=? and messageid=?",
            new Object[] { storeId, message.getJMSMessageID() }) > 0) {
        runner.update(connection, "delete from messages where messageid=?",
                new Object[] { message.getJMSMessageID() });
    } else {/*www  . j  a  v  a 2 s  . c om*/
        throw new SQLException("No message id=" + message.getJMSMessageID() + " exists in store=" + storeId);
    }
}

From source file:hermes.store.schema.DefaultJDBCAdapter.java

public void insert(Connection connection, String storeId, Message message) throws SQLException, JMSException {
    final String destinationName = message.getJMSDestination() == null ? "default"
            : JMSUtils.getDestinationName(message.getJMSDestination());
    final Domain domain = message.getJMSDestination() == null ? Domain.QUEUE
            : Domain.getDomain(message.getJMSDestination());
    final String messageAsXMLString = xmlHelper.toXML(message);
    final InputStream messageAsXML = new StringInputStream(messageAsXMLString);
    final String messageId = getNextMessageId(storeId);

    ///*from w ww . j  a  va 2  s.  c o m*/
    // DBUtils does not seem to correctly deal with CLOBS, so we have to use
    // normal JDBC...
    //
    // runner.update(connection, "insert into messages values (?, ?)", new
    // Object[] { message.getJMSMessageID(), messageAsXML });

    final PreparedStatement pstmt = connection.prepareStatement("insert into messages values (?, ?)");

    pstmt.setString(1, messageId);
    pstmt.setAsciiStream(2, messageAsXML, messageAsXMLString.length());

    pstmt.execute();
    pstmt.close();

    final QueryRunner runner = new QueryRunner();

    runner.update(connection, "insert into stores values (?, ?, ?, ?)",
            new Object[] { storeId, destinationName, domain.getId(), messageId });
}

From source file:azkaban.trigger.JdbcTriggerLoader.java

private synchronized void addTrigger(Connection connection, Trigger t, EncodingType encType)
        throws TriggerLoaderException {

    QueryRunner runner = new QueryRunner();

    long id;/*w  w  w .  j  a va  2s  . c  o m*/

    try {
        runner.update(connection, ADD_TRIGGER, DateTime.now().getMillis());
        connection.commit();
        id = runner.query(connection, LastInsertID.LAST_INSERT_ID, new LastInsertID());

        if (id == -1L) {
            logger.error("trigger id is not properly created.");
            throw new TriggerLoaderException("trigger id is not properly created.");
        }

        t.setTriggerId((int) id);
        updateTrigger(t);
        logger.info("uploaded trigger " + t.getDescription());
    } catch (SQLException e) {
        throw new TriggerLoaderException("Error creating trigger.", e);
    }

}

From source file:azkaban.migration.scheduler.JdbcScheduleLoader.java

@Override
public void removeSchedule(Schedule s) throws ScheduleManagerException {
    logger.info("Removing schedule " + s.getScheduleName() + " from db.");

    QueryRunner runner = new QueryRunner(dataSource);

    try {//from  ww  w  .j a  v a  2 s  . c  o m
        int removes = runner.update(REMOVE_SCHEDULE_BY_KEY, s.getProjectId(), s.getFlowName());
        if (removes == 0) {
            throw new ScheduleManagerException("No schedule has been removed.");
        }
    } catch (SQLException e) {
        logger.error(REMOVE_SCHEDULE_BY_KEY + " failed.");
        throw new ScheduleManagerException("Remove schedule " + s.getScheduleName() + " from db failed. ", e);
    }
}

From source file:hermes.store.schema.DefaultJDBCAdapter.java

public void remove(Connection connection, String storeId) throws SQLException {
    final QueryRunner runner = new QueryRunner();

    for (final String statment : statements.getRemoveStoreStatements()) {
        runner.update(connection, statment, new Object[] { storeId });
    }//  w  ww  . j  a  va2  s  .c om
}

From source file:com.versatus.jwebshield.securitylock.SecurityLockService.java

public SecurityLock processSecurityLock(int userId, String ip) throws SecurityLockException {
    QueryRunner run = new QueryRunner();
    Connection conn = null;/* w  w  w  .jav a2s  .c o m*/
    SecurityLock al = null;

    List<Object> params = new ArrayList<Object>(3);

    try {
        conn = dbHelper.getConnection();

        al = checkSecurityLock(userId, ip);

        logger.debug("lockAccount: TriesToLock=" + getTriesToLock());

        int r = 0;

        if (al.getTryCounter() >= getTriesToLock() && !al.isLock()) {
            params.add(true);
            params.add(userId);
            params.add(ip);
            r = run.update(conn, setlockSql, params.toArray());
        } else {
            params.add(userId);
            params.add(ip);
            // params.add(false);
            r = run.update(conn, insertlockSql, params.toArray());
        }

        al = checkSecurityLock(userId, ip);

        logger.debug("lockAccount: response=" + r);

    } catch (SQLException e) {
        logger.error("lockAccount", e);
        logger.debug("lockAccount: ErrorCode=", e.getErrorCode());
        throw new SecurityLockException("Unable to access security lock database", e);
    } finally {

        try {
            DbUtils.close(conn);
        } catch (SQLException e) {
            // ignore
        }
    }
    return al;
}

From source file:net.gcolin.simplerepo.search.SearchController.java

public void add(final Repository repository, File pomFile, Model model) throws IOException {
    SearchResult result = buildResult(repository.getName(), pomFile, model);
    try {/*from  w  ww .j a  v  a 2s  . c  om*/
        Connection connection = null;
        try {
            connection = datasource.getConnection();
            connection.setAutoCommit(false);
            QueryRunner run = new QueryRunner();
            Long artifactIdx = run.query(connection, "select id from artifact where groupId=? and artifactId=?",
                    getLong, result.getGroupId(), result.getArtifactId());
            if (artifactIdx == null) {
                artifactIdx = run.query(connection, "select artifact from artifactindex", getLong);
                run.update(connection, "update artifactindex set artifact=?", artifactIdx + 1);
                run.update(connection, "insert into artifact (id,groupId,artifactId) VALUES (?,?,?)",
                        artifactIdx, result.getGroupId(), result.getArtifactId());
            }
            Long versionId = run.query(connection, "select version from artifactindex", getLong);
            run.update(connection, "update artifactindex set version=?", versionId + 1);
            run.update(connection,
                    "insert into artifactversion(artifact_id,id,version,reponame) VALUES (?,?,?,?)",
                    artifactIdx, versionId, result.getVersion(), result.getRepoName());
            for (ResultType res : result.getTypes()) {
                run.update(connection,
                        "insert into artifacttype(version_id,packaging,classifier) VALUES (?,?,?)", versionId,
                        res.getName(), res.getClassifier());
            }
            connection.commit();
        } catch (SQLException ex) {
            connection.rollback();
            throw ex;
        } finally {
            DbUtils.close(connection);
        }
    } catch (SQLException ex) {
        logger.log(Level.SEVERE, null, ex);
        throw new IOException(ex);
    }
}