DatabaseOperator { public int update(final String updateClause, final Object... params) throws SQLException { int retryCount = 0; SQLException exception; String errorMsg = "Update failed: Reached maximum number of retries: " + AzDBUtil.MAX_RETRIES_ON_DEADLOCK; do { try { return this.queryRunner.update(updateClause, params); } catch (final SQLException ex) { exception = ex; if (this.queryRunner.getDataSource() instanceof MySQLDataSource && ex.getErrorCode() == MySQLDataSource.MYSQL_ER_LOCK_DEADLOCK) { retryCount++; logger.warn("Deadlock detected when trying to execute: " + updateClause + " with values: " + Arrays.toString(params)); try { Thread.sleep(AzDBUtil.RETRY_WAIT_TIME); } catch (final InterruptedException e) { logger.info("Sleep during DB operation retry interrupted."); } } else { errorMsg = "update failed"; break; } } } while (retryCount < AzDBUtil.MAX_RETRIES_ON_DEADLOCK); logger.error(errorMsg, exception); if (this.dbMetrics != null) { this.dbMetrics.markDBFailUpdate(); } throw exception; } @Inject  DatabaseOperator(final QueryRunner queryRunner); T query(final String baseQuery, final ResultSetHandler<T> resultHandler,
      final Object... params); T transaction(final SQLTransaction<T> operations); int update(final String updateClause, final Object... params); int[] batch(final String sqlCommand, final Object[]... params); AzkabanDataSource getDataSource();  }
@Test public void testValidUpdate() throws Exception { final int res = this.dbOperator.update("update blah set ? = ?", "1", 26); Assert.assertEquals(1, res); Assert.assertEquals(26, index_1); verify(this.queryRunner).update("update blah set ? = ?", "1", 26); }
@Test public void testInvalidUpdate() throws Exception { final int res = this.dbOperator.update("update blah set ? = ?", "3", 26); Assert.assertEquals(0, res); }