List of usage examples for org.apache.commons.dbutils QueryRunner update
public int update(String sql, Object... params) throws SQLException
From source file:net.gcolin.simplerepo.search.SearchController.java
public void rebuild() throws IOException { if (running) { return;//from w w w.j a va 2 s.c o m } running = true; configManager.setCurrentAction(REBUILD + "initialize"); nb = 0; try { final QueryRunner run = new QueryRunner(); try { Connection connection = null; try { connection = datasource.getConnection(); connection.setAutoCommit(false); run.update(connection, "delete from artifacttype"); run.update(connection, "delete from artifactversion"); run.update(connection, "delete from artifact"); run.update(connection, "update artifactindex set artifact=1,version=1"); 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); } for (final Repository repository : configManager.getConfiguration().getRepositories()) { File repo = new File(configManager.getRoot(), repository.getName()); if (repo.exists()) { Files.walkFileTree(repo.toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { nb++; if (nb % 20 == 0) { configManager.setCurrentAction(REBUILD + " " + nb + " files"); } if (file.toString().endsWith(".pom")) { Model model = readPom(file.toFile()); add(repository, file.toFile(), model); } return FileVisitResult.CONTINUE; } }); } } } finally { running = false; configManager.setCurrentAction(null); } }
From source file:hermes.store.schema.DefaultJDBCAdapter.java
private void executeStatements(Connection connection, String[] statements) throws SQLException { final StringBuffer message = new StringBuffer(); ProgressMonitor progressMonitor = null; if (HermesBrowser.getBrowser() != null) { progressMonitor = new ProgressMonitor(HermesBrowser.getBrowser(), "Initialising message stores... ", "Connecting...", 0, statements.length); progressMonitor.setMillisToDecideToPopup(100); progressMonitor.setMillisToPopup(400); }/*from w w w . j av a 2s . c o m*/ final QueryRunner runner = new QueryRunner(); for (int i = 0; i < statements.length; i++) { try { log.debug("executing: " + statements[i]); if (progressMonitor != null) { progressMonitor.setProgress(statements.length); progressMonitor.setNote("Executing statement " + i + " of " + statements.length); } runner.update(connection, statements[i]); } catch (SQLException ex) { log.error(ex.getMessage()); } } }
From source file:azkaban.executor.JdbcExecutorLoaderTest.java
@After public void clearDB() { if (!testDBExists) { return;/*from w w w .ja va 2 s . co m*/ } DataSource dataSource = DataSourceUtils.getMySQLDataSource(host, port, database, user, password, numConnections); Connection connection = null; try { connection = dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } QueryRunner runner = new QueryRunner(); try { runner.update(connection, "DELETE FROM active_executing_flows"); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } try { runner.update(connection, "DELETE FROM execution_flows"); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } try { runner.update(connection, "DELETE FROM execution_jobs"); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } try { runner.update(connection, "DELETE FROM execution_logs"); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } try { runner.update(connection, "DELETE FROM executors"); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } try { runner.update(connection, "DELETE FROM executor_events"); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } DbUtils.closeQuietly(connection); }
From source file:com.neu.controller.AdditionSuccessController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { //throw new UnsupportedOperationException("Not yet implemented"); int result = 0; DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource"); ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(); int count = (Integer) (session.getAttribute("count")); try {// ww w.j a v a 2 s . c o m QueryRunner run = new QueryRunner(ds); ResultSetHandler<Books> books = new BeanHandler<Books>(Books.class); for (int i = 1; i <= count; i++) { String isbnField = "isbn" + i; String titleField = "title" + i; String authorField = "author" + i; String priceField = "price" + i; String isbn = request.getParameter(isbnField).replaceAll("<|>|@|;|,|=|}|$|&", ""); String title = request.getParameter(titleField).replaceAll("<|>|@|;|,|=|}|$|&", ""); String author = request.getParameter(authorField).replaceAll("<|>|@|;|,|=|}|$|&", ""); float price = Float .parseFloat(request.getParameter(priceField).replaceAll("<|>|@|;|,|=|}|$|&", "")); Object[] params = new Object[4]; params[0] = isbn; params[1] = title; params[2] = author; params[3] = price; result = run.update("Insert into books(isbn,title,authors,price) values(?,?,?,?)", params); } } catch (Exception ex) { System.out.println("Details Not Added In DB!! " + ex.getMessage()); } if (result > 0) { mv.setViewName("success"); } else { mv.setViewName("error"); } return mv; }
From source file:io.stallion.dataAccess.db.DB.java
/** * Delete the object from the database.// w w w . j av a 2s. c o m * * @param obj */ public void delete(Model obj) { Schema schema = getSchemaForModelClass(obj.getClass()); String sql = "DELETE FROM " + schema.getName() + " WHERE id=?"; QueryRunner runner = new QueryRunner(dataSource); try { runner.update(sql, obj.getId()); } catch (SQLException e) { throw new RuntimeException(e); } obj.setDeleted(true); }
From source file:io.stallion.dataAccess.db.DB.java
/** * Insert the object into the database.//from ww w . j a va 2 s. com * * @param obj * @return */ public Model insert(Model obj) { Schema schema = getSchemaForModelClass(obj.getClass()); if (obj.getId() == null) { obj.setId(dal().getTickets().nextId()); } String sql = "INSERT INTO `" + schema.getName() + "` (id "; List args = new ArrayList<>(); args.add(obj.getId()); for (Col col : schema.getColumns()) { if (col.getInsertable()) { sql += ", `" + col.getName() + "` "; } } sql += ") VALUES(?"; for (Col col : schema.getColumns()) { if (col.getInsertable()) { sql += ", ?"; Object arg = PropertyUtils.getPropertyOrMappedValue(obj, col.getPropertyName()); if (arg == null && col.getDefaultValue() != null) { arg = col.getDefaultValue(); PropertyUtils.setProperty(obj, col.getPropertyName(), arg); } arg = convertColumnArg(obj, col, arg); args.add(arg); } } sql += ") "; QueryRunner runner = new QueryRunner(dataSource); try { runner.update(sql, args.toArray()); } catch (SQLException e) { throw new RuntimeException(e); } return obj; }
From source file:io.stallion.dataAccess.db.DB.java
/** * Update the object//w w w . jav a 2 s . c om * * @param obj * @return rows affected */ public int update(Model obj) { Schema schema = getSchemaForModelClass(obj.getClass()); String sql = "UPDATE `" + schema.getName() + "` SET "; List args = new ArrayList<>(); for (Col col : schema.getColumns()) { if (col.getUpdateable()) { sql += "`" + col.getName() + "`" + "=?, "; Object arg = PropertyUtils.getPropertyOrMappedValue(obj, col.getPropertyName()); arg = convertColumnArg(obj, col, arg); args.add(arg); } } sql = StringUtils.strip(sql.trim(), ","); sql += " WHERE id=?"; args.add(obj.getId()); QueryRunner run = new QueryRunner(dataSource); int affected = 0; try { affected = run.update(sql, args.toArray()); } catch (SQLException e) { throw new RuntimeException(e); } return affected; }
From source file:io.stallion.dataAccess.db.DB.java
/** * Update only the passed in key values/*from w w w . j a va2s . c om*/ * * @param obj * @return rows affected */ public int update(Model obj, Map<String, Object> values) { if (values.size() == 0) { return 0; } Schema schema = getSchemaForModelClass(obj.getClass()); String sql = "UPDATE `" + schema.getName() + "` SET "; List args = new ArrayList<>(); for (Col col : schema.getColumns()) { if (col.getUpdateable() && values.containsKey(col.getPropertyName())) { sql += "`" + col.getName() + "`" + "=?, "; Object arg = values.get(col.getPropertyName()); arg = convertColumnArg(obj, col, arg); args.add(arg); } } if (args.size() == 0) { return 0; } sql = StringUtils.strip(sql.trim(), ","); sql += " WHERE id=?"; args.add(obj.getId()); QueryRunner run = new QueryRunner(dataSource); int affected = 0; try { affected = run.update(sql, args.toArray()); } catch (SQLException e) { throw new RuntimeException(e); } return affected; }
From source file:azkaban.executor.JdbcExecutorLoader.java
@Override public void removeActiveExecutableReference(int execid) throws ExecutorManagerException { final String DELETE = "DELETE FROM active_executing_flows WHERE exec_id=?"; QueryRunner runner = createQueryRunner(); try {/*from ww w . j a v a 2s .co m*/ runner.update(DELETE, execid); } catch (SQLException e) { throw new ExecutorManagerException("Error deleting active flow reference " + execid, e); } }
From source file:azkaban.executor.JdbcExecutorLoader.java
/** * * {@inheritDoc}//ww w .ja v a 2 s . co m * @see azkaban.executor.ExecutorLoader#unassignExecutor(int) */ @Override public void unassignExecutor(int executionId) throws ExecutorManagerException { final String UPDATE = "UPDATE execution_flows SET executor_id=NULL where exec_id=?"; QueryRunner runner = createQueryRunner(); try { int rows = runner.update(UPDATE, executionId); if (rows == 0) { throw new ExecutorManagerException( String.format("Failed to unassign executor for execution : %d ", executionId)); } } catch (SQLException e) { throw new ExecutorManagerException("Error updating execution id " + executionId, e); } }