Search in sources :

Example 26 with DataAccessException

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);
    }
}
Also used : DataAccessException(org.jooq.exception.DataAccessException) SQLException(java.sql.SQLException) DataAccessException(org.jooq.exception.DataAccessException)

Example 27 with DataAccessException

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) DataAccessException(org.jooq.exception.DataAccessException)

Example 28 with DataAccessException

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) DataAccessException(org.jooq.exception.DataAccessException)

Example 29 with DataAccessException

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();
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DataAccessException(org.jooq.exception.DataAccessException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 30 with DataAccessException

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);
}
Also used : Secret(keywhiz.api.model.Secret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) Group(keywhiz.api.model.Group) ConflictException(keywhiz.service.exceptions.ConflictException) HashMap(java.util.HashMap) Event(keywhiz.log.Event) SecretController(keywhiz.service.daos.SecretController) DataAccessException(org.jooq.exception.DataAccessException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

DataAccessException (org.jooq.exception.DataAccessException)34 SQLException (java.sql.SQLException)14 Test (org.junit.Test)5 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)4 Timed (com.codahale.metrics.annotation.Timed)4 Connection (java.sql.Connection)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Event (keywhiz.log.Event)4 SecretController (keywhiz.service.daos.SecretController)4 ConflictException (keywhiz.service.exceptions.ConflictException)4 IOException (java.io.IOException)3 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)3 HashMap (java.util.HashMap)3 Response (javax.ws.rs.core.Response)3 SanitizedSecret (keywhiz.api.model.SanitizedSecret)3 Secret (keywhiz.api.model.Secret)3 StringReader (java.io.StringReader)2 URI (java.net.URI)2 Savepoint (java.sql.Savepoint)2