Search in sources :

Example 11 with DataAccessException

use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.

the class DefaultDSLContext method fetchLazy.

@Override
public Cursor<Record> fetchLazy(ResultSet rs, DataType<?>... types) {
    try {
        Field<?>[] fields = new Field[types.length];
        ResultSetMetaData meta = rs.getMetaData();
        int columns = meta.getColumnCount();
        for (int i = 0; i < types.length && i < columns; i++) {
            fields[i] = field(meta.getColumnLabel(i + 1), types[i]);
        }
        return fetchLazy(rs, fields);
    } catch (SQLException e) {
        throw new DataAccessException("Error while accessing ResultSet meta data", e);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) TableField(org.jooq.TableField) Field(org.jooq.Field) SelectField(org.jooq.SelectField) SQLException(java.sql.SQLException) DataAccessException(org.jooq.exception.DataAccessException)

Example 12 with DataAccessException

use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.

the class ConstraintImpl method accept.

@Override
public final void accept(Context<?> ctx) {
    if (ctx.data(DATA_CONSTRAINT_REFERENCE) != null) {
        if (name == null)
            throw new DataAccessException("Cannot ALTER or DROP CONSTRAINT without name");
        ctx.visit(name);
    } else {
        boolean qualify = ctx.qualify();
        if (name != null)
            ctx.keyword("constraint").sql(' ').visit(name).formatIndentStart().formatSeparator();
        if (unique != null) {
            ctx.keyword("unique").sql(" (").qualify(false).visit(new QueryPartList<Field<?>>(unique)).qualify(qualify).sql(')');
        } else if (primaryKey != null) {
            ctx.keyword("primary key").sql(" (").qualify(false).visit(new QueryPartList<Field<?>>(primaryKey)).qualify(qualify).sql(')');
        } else if (foreignKey != null) {
            ctx.keyword("foreign key").sql(" (").qualify(false).visit(new QueryPartList<Field<?>>(foreignKey)).qualify(qualify).sql(')').formatSeparator().keyword("references").sql(' ').visit(referencesTable).sql(" (").qualify(false).visit(new QueryPartList<Field<?>>(references)).qualify(qualify).sql(')');
            if (onDelete != null)
                ctx.sql(' ').keyword("on delete").sql(' ').keyword(onDelete.sql);
            if (onUpdate != null)
                ctx.sql(' ').keyword("on update").sql(' ').keyword(onUpdate.sql);
        } else if (check != null) {
            ctx.keyword("check").sql(" (").qualify(false).visit(check).qualify(qualify).sql(')');
        }
        ctx.formatIndentEnd();
    }
}
Also used : Field(org.jooq.Field) DataAccessException(org.jooq.exception.DataAccessException)

Example 13 with DataAccessException

use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.

the class Val method accept.

// ------------------------------------------------------------------------
// XXX: Field API
// ------------------------------------------------------------------------
@Override
public void accept(Context<?> ctx) {
    if (ctx instanceof RenderContext) {
        ParamType paramType = ctx.paramType();
        if (isInline(ctx))
            ctx.paramType(ParamType.INLINED);
        try {
            getBinding().sql(new DefaultBindingSQLContext<T>(ctx.configuration(), ctx.data(), (RenderContext) ctx, value, getBindVariable(ctx)));
        } catch (SQLException e) {
            throw new DataAccessException("Error while generating SQL for Binding", e);
        }
        ctx.paramType(paramType);
    } else {
        // [#1302] Bind value only if it was not explicitly forced to be inlined
        if (!isInline(ctx)) {
            ctx.bindValue(value, this);
        }
    }
}
Also used : RenderContext(org.jooq.RenderContext) SQLException(java.sql.SQLException) ParamType(org.jooq.conf.ParamType) DataAccessException(org.jooq.exception.DataAccessException)

Example 14 with DataAccessException

use of org.jooq.exception.DataAccessException in project zipkin by openzipkin.

the class SchemaTest method hasDependencies_missing.

@Test
public void hasDependencies_missing() throws SQLException {
    SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("SQL [select count(*) from `zipkin_dependencies`]; Table 'zipkin.zipkin_dependencies' doesn't exist\n" + "  Query is : select count(*) from `zipkin_dependencies`", "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.hasPreAggregatedDependencies).isFalse();
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DataAccessException(org.jooq.exception.DataAccessException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 15 with DataAccessException

use of org.jooq.exception.DataAccessException in project zipkin by openzipkin.

the class SchemaTest method hasIpv6_falseWhenKnownSQLState.

@Test
public void hasIpv6_falseWhenKnownSQLState() throws SQLException {
    SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("Unknown column 'zipkin_annotations.endpoint_ipv6' in 'field list'", "42S22", 1054);
    // 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) Test(org.junit.Test)

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