public void updateDatabase() throws SQLException, IOException { final Set<String> tables = collectAllTables(); createTables(tables); }
private void createTables(final Set<String> tables) throws SQLException, IOException { final Connection conn = this.dataSource.getConnection(); conn.setAutoCommit(false); try { for (final String table : tables) { runTableScripts(conn, table); } } finally { conn.close(); } }
private boolean getDbStatus() { try { return this.dbOperator.query("SELECT 1", rs -> true); } catch (final SQLException e) { log.error("DB Error", e); } return false; }
private boolean removeDbEntry(final String resourceId) { try { final int nAffectedRows = this.databaseOperator.update(SQL_DELETE_RESOURCE_ID, resourceId); return nAffectedRows > 0; } catch (final SQLException e) { log.error("Error while deleting DB metadata resource ID: " + resourceId, e); } return false; }
public static DatabaseOperator initTestDB() throws Exception { final AzkabanDataSource dataSource = new EmbeddedH2BasicDataSource(); final String sqlScriptsDir = new File("../azkaban-db/src/main/sql/").getCanonicalPath(); final DatabaseSetup setup = new DatabaseSetup(dataSource, sqlScriptsDir); setup.updateDatabase(); return new DatabaseOperator(new QueryRunner(dataSource)); }
@Before public void setUp() throws Exception { final AzkabanDataSource datasource = new AzDBTestUtility.EmbeddedH2BasicDataSource(); final DatabaseTransOperator operator = new DatabaseTransOperator(new QueryRunner(), datasource.getConnection()); }
private void executeTransaction(final SQLTransaction<Integer> tran) { try { this.dbOperator.transaction(tran); } catch (final SQLException ex) { handleSQLException(ex); } }
public EmbeddedH2BasicDataSource() { super(); final String url = "jdbc:h2:mem:test;IGNORECASE=TRUE"; setDriverClassName("org.h2.Driver"); setUrl(url); }
@Inject public DBMetrics(final MetricsManager metricsManager) { this.metricsManager = metricsManager; setupAllMetrics(); }
void removeActiveExecutableReference(final int execId) throws ExecutorManagerException { final String DELETE = "DELETE FROM active_executing_flows WHERE exec_id=?"; try { this.dbOperator.update(DELETE, execId); } catch (final SQLException e) { throw new ExecutorManagerException( "Error deleting active flow reference " + execId, e); } }
public static DatabaseOperator initQuartzDB() throws Exception { final AzkabanDataSource dataSource = new EmbeddedH2BasicDataSource(); final String sqlScriptsDir = new File("../azkaban-web-server/src/test/resources/") .getCanonicalPath(); final DatabaseSetup setup = new DatabaseSetup(dataSource, sqlScriptsDir); setup.updateDatabase(); return new DatabaseOperator(new QueryRunner(dataSource)); }
public int fetchNumExecutableNodes(final int projectId, final String jobId) throws ExecutorManagerException { final IntHandler intHandler = new IntHandler(); try { return this.dbOperator.query(IntHandler.NUM_JOB_EXECUTIONS, intHandler, projectId, jobId); } catch (final SQLException e) { throw new ExecutorManagerException("Error fetching num executions", e); } }
private void executeUpdate(final String query, final Object... params) { try { this.dbOperator.update(query, params); } catch (final SQLException ex) { handleSQLException(ex); } }
List<Executor> fetchActiveExecutors() throws ExecutorManagerException { try { return this.dbOperator .query(FetchExecutorHandler.FETCH_ACTIVE_EXECUTORS, new FetchExecutorHandler()); } catch (final SQLException e) { throw new ExecutorManagerException("Error fetching active executors", e); } }
boolean updateExecutableReference(final int execId, final long updateTime) throws ExecutorManagerException { final String DELETE = "UPDATE active_executing_flows set update_time=? WHERE exec_id=?"; try { // Should be 1. return this.dbOperator.update(DELETE, updateTime, execId) > 0; } catch (final SQLException e) { throw new ExecutorManagerException( "Error deleting active flow reference " + execId, e); } } }
@Test public void testInvalidQuery() throws Exception { final int res = this.dbOperator.query("select * from blah where ? = ?", this.handler, "id", 3); Assert.assertEquals(0, res); }
void removeExecutor(final String host, final int port) throws ExecutorManagerException { final String DELETE = "DELETE FROM executors WHERE host=? AND port=?"; try { final int rows = this.dbOperator.update(DELETE, host, port); if (rows == 0) { throw new ExecutorManagerException("No executor with host, port :" + "(" + host + "," + port + ")"); } } catch (final SQLException e) { throw new ExecutorManagerException("Error removing executor with host, port : " + "(" + host + "," + port + ")", e); } }
@After public void clearDB() { try { dbOperator.update("delete from execution_flows"); } catch (final SQLException e) { e.printStackTrace(); } }