List of usage examples for org.apache.commons.dbutils QueryRunner update
private int update(Connection conn, boolean closeConn, String sql, Object... params) throws SQLException
From source file:azkaban.project.JdbcProjectLoader.java
private void cleanOlderProjectVersion(Connection connection, int projectId, int version) throws ProjectManagerException { final String UPDATE_PROJECT_VERSIONS = "UPDATE project_versions SET num_chunks=0 WHERE project_id=? AND version<?"; QueryRunner runner = new QueryRunner(); try {//from ww w. j ava 2 s .com runner.update(connection, UPDATE_PROJECT_VERSIONS, projectId, version); connection.commit(); } catch (SQLException e) { throw new ProjectManagerException( "Error updating project version chunksize " + projectId + ":" + version, e); } }
From source file:azkaban.project.JdbcProjectLoader.java
@Override public void removePermission(Project project, String name, boolean isGroup) throws ProjectManagerException { QueryRunner runner = createQueryRunner(); final String DELETE_PROJECT_PERMISSION = "DELETE FROM project_permissions WHERE project_id=? AND name=? AND isGroup=?"; try {//from w w w. j a v a 2s . c o m runner.update(DELETE_PROJECT_PERMISSION, project.getId(), name, isGroup); } catch (SQLException e) { logger.error(e); throw new ProjectManagerException( "Error deleting project " + project.getName() + " permissions for " + name, e); } if (isGroup) { project.removeGroupPermission(name); } else { project.removeUserPermission(name); } }
From source file:azkaban.project.JdbcProjectLoader.java
@Override public void removeProject(Project project, String user) throws ProjectManagerException { QueryRunner runner = createQueryRunner(); long updateTime = System.currentTimeMillis(); final String UPDATE_INACTIVE_PROJECT = "UPDATE projects SET active=false,modified_time=?,last_modified_by=? WHERE id=?"; try {/*from w w w . ja va 2 s . c om*/ runner.update(UPDATE_INACTIVE_PROJECT, updateTime, user, project.getId()); } catch (SQLException e) { logger.error(e); throw new ProjectManagerException("Error marking project " + project.getName() + " as inactive", e); } }
From source file:org.kaaproject.kaa.server.datamigration.CtlEventsMigration.java
private void updateFamilyVersionId(EventClass ec, List<EventSchemaVersion> versions, QueryRunner runner) throws SQLException { for (EventSchemaVersion esv : versions) { if (ecBelongToThisFamilyVersion(ec, esv)) { int updateCount = runner.update(this.connection, "UPDATE " + EVENT_CLASS_TABLE_NAME + " SET events_class_family_versions_id=? WHERE id=?", esv.getId(), ec.getId()); if (updateCount != 1) { System.err.println("Error: failed to update event class's reference to ECFV: " + ec); }//from w w w . j ava 2s .c om break; } } }
From source file:org.kaaproject.kaa.server.datamigration.UpdateUuidsMigration.java
/** * Change encoding of uuids from Latin1 to Base64 in relational and NoSQL databases. * *///from ww w . j ava 2 s .c o m public void transform() throws IOException, SQLException { QueryRunner run = new QueryRunner(); ResultSetHandler<List<Configuration>> rsHandler = new BeanListHandler<>(Configuration.class); List<Configuration> configs = run.query(connection, "SELECT * FROM configuration", rsHandler); for (Configuration config : configs) { JsonNode json = new ObjectMapper().readTree(config.getConfigurationBody()); JsonNode jsonEncoded = encodeUuids(json); byte[] encodedConfigurationBody = jsonEncoded.toString().getBytes(); int updates = run.update(connection, "UPDATE configuration SET configuration_body=? WHERE id=?", encodedConfigurationBody, config.getId()); if (updates != 1) { System.err.println("Error: failed to update configuration: " + config); } } if (nosql.equals(Options.DEFAULT_NO_SQL)) { MongoDatabase database = client.getDatabase(dbName); MongoCollection<Document> userConfiguration = database.getCollection("user_configuration"); FindIterable<Document> documents = userConfiguration.find(); for (Document d : documents) { String body = (String) d.get("body"); JsonNode json = new ObjectMapper().readTree(body); JsonNode jsonEncoded = encodeUuids(json); userConfiguration.updateOne(Filters.eq("_id", d.get("_id")), Filters.eq("$set", Filters.eq("body", jsonEncoded))); } } else { Session session = cluster.connect(dbName); BatchStatement batchStatement = new BatchStatement(); String tableName = "user_conf"; ResultSet results = session.execute(select().from(tableName)); for (Row row : results) { String userId = row.getString("user_id"); String appToken = row.getString("app_token"); int schemaVersion = row.getInt("schema_version"); String body = row.getString("body"); String bodyEncoded = encodeUuids(new ObjectMapper().readTree(body)).toString(); batchStatement.add(update(tableName).with(set("body", bodyEncoded)).where(eq("user_id", userId)) .and(eq("app_token", appToken)).and(eq("schema_version", schemaVersion))); } session.execute(batchStatement); session.close(); cluster.close(); } }
From source file:pe.gob.sunat.tecnologia3.arquitectura.framework.desktop.dominio.dao.sqlite.ProyectoDaoSqlite.java
private void actualizarEstado(Integer id, Integer estado) { try {/*from w w w . j a v a 2s. com*/ QueryRunner run = new QueryRunner(); int result = run.update(getConexion(), "update Proyecto set activo=? where id=?", estado, id); logger.log(Level.INFO, "id del registro que se actualizo: {0} con el estdo: {1} y con el id: {2}", new Object[] { result, estado, id }); } catch (SQLException ex) { logger.log(Level.SEVERE, null, ex); } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } }