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);
}
}
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();
}
}
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);
}
}
}
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();
}
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();
}
Aggregations