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; }
private void addExecutorHelper(final String host, final int port) throws ExecutorManagerException { final String INSERT = "INSERT INTO executors (host, port) values (?,?)"; try { this.dbOperator.update(INSERT, host, port); } catch (final SQLException e) { throw new ExecutorManagerException(String.format("Error adding %s:%d ", host, port), e); } }
int removeExecutionLogsByTime(final long millis) throws ExecutorManagerException { final String DELETE_BY_TIME = "DELETE FROM execution_logs WHERE upload_time < ?"; try { return this.dbOperator.update(DELETE_BY_TIME, millis); } catch (final SQLException e) { logger.error("delete execution logs failed", e); throw new ExecutorManagerException( "Error deleting old execution_logs before " + millis, e); } }
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 void postExecutorEvent(final Executor executor, final EventType type, final String user, final String message) throws ExecutorManagerException { final String INSERT_PROJECT_EVENTS = "INSERT INTO executor_events (executor_id, event_type, event_time, username, message) values (?,?,?,?,?)"; try { this.dbOperator.update(INSERT_PROJECT_EVENTS, executor.getId(), type.getNumVal(), new Date(), user, message); } catch (final SQLException e) { throw new ExecutorManagerException("Failed to post executor event", e); } }
@After public void clearDB() { try { dbOperator.update("delete from execution_logs"); } catch (final SQLException e) { e.printStackTrace(); } }
@After public void clearDB() { try { dbOperator.update("DELETE FROM triggers"); } catch (final SQLException e) { e.printStackTrace(); return; } } }
@After public void clearDB() { try { dbOperator.update("delete from execution_flows"); } catch (final SQLException e) { e.printStackTrace(); } }
void addActiveExecutableReference(final ExecutionReference reference) throws ExecutorManagerException { final String INSERT = "INSERT INTO active_executing_flows " + "(exec_id, update_time) values (?,?)"; try { this.dbOperator.update(INSERT, reference.getExecId(), reference.getUpdateTime()); } catch (final SQLException e) { throw new ExecutorManagerException( "Error updating active flow reference " + reference.getExecId(), e); } }
@Before public void setUp() throws Exception { this.databaseOperator = mock(DatabaseOperator.class); this.storage = mock(Storage.class); when(this.databaseOperator.query( eq(StorageCleaner.SQL_FETCH_PVR), anyObject(), eq(TEST_PROJECT_ID))) .thenReturn(Arrays.asList("14/14-9.zip", "14/14-8.zip", "14/14-7.zip")); when(this.storage.delete("14/14-8.zip")).thenReturn(true); when(this.storage.delete("14/14-7.zip")).thenReturn(false); when(this.databaseOperator.update(any(), anyVararg())).thenReturn(1); }
@Test public void testInvalidUpdate() throws Exception { final int res = this.dbOperator.update("update blah set ? = ?", "3", 26); // 0 row is affected Assert.assertEquals(0, res); } }
@Test public void testValidUpdate() throws Exception { final int res = this.dbOperator.update("update blah set ? = ?", "1", 26); // 1 row is affected Assert.assertEquals(1, res); Assert.assertEquals(26, index_1); verify(this.queryRunner).update("update blah set ? = ?", "1", 26); }