org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException Java Examples
The following examples show how to use
org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestShardDao.java From presto with Apache License 2.0 | 6 votes |
@Test public void testExternalBatches() { assertFalse(dao.externalBatchExists("foo")); assertFalse(dao.externalBatchExists("bar")); dao.insertExternalBatch("foo"); assertTrue(dao.externalBatchExists("foo")); assertFalse(dao.externalBatchExists("bar")); try { dao.insertExternalBatch("foo"); fail("expected exception"); } catch (UnableToExecuteStatementException e) { assertInstanceOf(e.getCause(), SQLException.class); assertTrue(((SQLException) e.getCause()).getSQLState().startsWith("23")); } }
Example #2
Source File: BasicDatabaseStoreManager.java From digdag with Apache License 2.0 | 6 votes |
public <T> T catchConflict(NewResourceAction<T> function, String messageFormat, Object... messageParameters) throws ResourceConflictException { try { return function.call(); } catch (UnableToExecuteStatementException ex) { if (ex.getCause() instanceof SQLException) { SQLException sqlEx = (SQLException) ex.getCause(); if (isConflictException(sqlEx)) { throw new ResourceConflictException("Resource already exists: " + String.format(messageFormat, messageParameters)); } } throw ex; } }
Example #3
Source File: BasicDatabaseStoreManager.java From digdag with Apache License 2.0 | 6 votes |
public <T> T catchForeignKeyNotFound(NewResourceAction<T> function, String messageFormat, Object... messageParameters) throws ResourceNotFoundException, ResourceConflictException { try { return function.call(); } catch (UnableToExecuteStatementException ex) { if (ex.getCause() instanceof SQLException) { SQLException sqlEx = (SQLException) ex.getCause(); if (isForeignKeyException(sqlEx)) { throw new ResourceNotFoundException("Resource not found: " + String.format(messageFormat, messageParameters)); } } throw ex; } }
Example #4
Source File: PostgresStorage.java From cassandra-reaper with Apache License 2.0 | 5 votes |
private boolean takeLead(UUID leaderId, Duration ttl) { if (null != jdbi) { try (Handle h = jdbi.open()) { try { int rowsInserted = getPostgresStorage(h).insertLeaderEntry( leaderId, reaperInstanceId, AppContext.REAPER_INSTANCE_ADDRESS ); if (rowsInserted == 1) { // insert should modify exactly 1 row return true; } } catch (UnableToExecuteStatementException e) { if (JdbiExceptionUtil.isDuplicateKeyError(e)) { // if it's a duplicate key error, then try to update it int rowsUpdated = getPostgresStorage(h).updateLeaderEntry( leaderId, reaperInstanceId, AppContext.REAPER_INSTANCE_ADDRESS, getExpirationTime(ttl) ); if (rowsUpdated == 1) { // if row updated, took ownership from an expired leader LOG.debug("Took lead from expired entry for segment {}", leaderId); return true; } } return false; } } } LOG.warn("Unknown error occurred while taking lead on segment {}", leaderId); return false; }
Example #5
Source File: SqlExtractorTest.java From pocket-etl with Apache License 2.0 | 4 votes |
@Test(expected = UnableToExecuteStatementException.class) public void openThrowsUnableToExecuteStatementExceptionIfQueryThrowsSqlException() throws Exception { when(mockPreparedStatement.execute()).thenThrow(new SQLException()); getBasicDTOSqlExtractor(); }
Example #6
Source File: JdbiExceptionUtil.java From cassandra-reaper with Apache License 2.0 | 4 votes |
public static boolean isDuplicateKeyError(UnableToExecuteStatementException exc) { if (exc.getCause() instanceof PSQLException) { return ((PSQLException) exc.getCause()).getSQLState().equals(DUPLICATE_KEY_CODE); } return false; }