use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.
the class DefaultConnectionProvider method rollback.
/**
* Convenience method to access {@link Connection#rollback(Savepoint)}.
*/
public final void rollback(Savepoint savepoint) throws DataAccessException {
try {
log.debug("rollback to savepoint");
connection.rollback(savepoint);
} catch (Exception e) {
throw new DataAccessException("Cannot rollback transaction", e);
}
}
use of org.jooq.exception.DataAccessException in project zipkin by openzipkin.
the class HasIpv6 method test.
static boolean test(DataSource datasource, DSLContexts context) {
try (Connection conn = datasource.getConnection()) {
DSLContext dsl = context.get(conn);
dsl.select(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV6).from(ZIPKIN_ANNOTATIONS).limit(1).fetchAny();
return true;
} catch (DataAccessException e) {
if (e.sqlState().equals("42S22")) {
LOG.warning("zipkin_annotations.ipv6 doesn't exist, so Endpoint.ipv6 is not supported. " + "Execute: alter table zipkin_annotations add `endpoint_ipv6` BINARY(16)");
return false;
}
problemReading(e);
} catch (SQLException | RuntimeException e) {
problemReading(e);
}
return false;
}
use of org.jooq.exception.DataAccessException in project zipkin by openzipkin.
the class HasTraceIdHigh method test.
static boolean test(DataSource datasource, DSLContexts context) {
try (Connection conn = datasource.getConnection()) {
DSLContext dsl = context.get(conn);
dsl.select(ZIPKIN_SPANS.TRACE_ID_HIGH).from(ZIPKIN_SPANS).limit(1).fetchAny();
return true;
} catch (DataAccessException e) {
if (e.sqlState().equals("42S22")) {
LOG.warning(MESSAGE);
return false;
}
problemReading(e);
} catch (SQLException | RuntimeException e) {
problemReading(e);
}
return false;
}
use of org.jooq.exception.DataAccessException in project zipkin by openzipkin.
the class SchemaTest method hasIpv6_falseWhenUnknownSQLState.
/**
* This returns false instead of failing when the SQLState code doesn't imply the column is
* missing. This is to prevent zipkin from crashing due to scenarios we haven't thought up, yet.
* The root error goes into the log in this case.
*/
@Test
public void hasIpv6_falseWhenUnknownSQLState() throws SQLException {
SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("java.sql.SQLSyntaxErrorException: Table 'zipkin.zipkin_annotations' doesn't exist", "42S02", 1146);
DataSource dataSource = mock(DataSource.class);
// cheats to lower mock count: this exception is really thrown during execution of the query
when(dataSource.getConnection()).thenThrow(new DataAccessException(sqlException.getMessage(), sqlException));
assertThat(schema.hasIpv6).isFalse();
}
use of org.jooq.exception.DataAccessException in project keywhiz by square.
the class AutomationSecretResource method createSecret.
/**
* Create secret
*
* @excludeParams automationClient
* @param request JSON request to formulate the secret
*
* @description Creates a secret with the name, content, and metadata from a valid secret request
* @responseMessage 200 Successfully created secret
* @responseMessage 409 Secret with given name already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public AutomationSecretResponse createSecret(@Auth AutomationClient automationClient, @Valid CreateSecretRequest request) {
SecretController.SecretBuilder builder = secretController.builder(request.name, request.content, automationClient.getName(), request.expiry).withDescription(nullToEmpty(request.description));
if (request.metadata != null) {
builder.withMetadata(request.metadata);
}
Secret secret;
try {
secret = builder.create();
} catch (DataAccessException e) {
logger.info(format("Cannot create secret %s", request.name), e);
throw new ConflictException(format("Cannot create secret %s.", request.name));
}
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(secret));
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
if (request.description != null) {
extraInfo.put("description", request.description);
}
if (request.metadata != null) {
extraInfo.put("metadata", request.metadata.toString());
}
extraInfo.put("expiry", Long.toString(request.expiry));
auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_CREATE, automationClient.getName(), request.name, extraInfo));
return AutomationSecretResponse.fromSecret(secret, groups);
}
Aggregations