Search in sources :

Example 26 with DSLContext

use of org.jooq.DSLContext in project jOOQ by jOOQ.

the class AbstractRoutine method executeSelectFromPOSTGRES.

private final int executeSelectFromPOSTGRES() {
    DSLContext create = create(configuration);
    List<Field<?>> fields = new ArrayList<Field<?>>();
    if (returnParameter != null)
        fields.add(DSL.field(DSL.name(getName()), returnParameter.getDataType()));
    for (Parameter<?> p : outParameters) fields.add(DSL.field(DSL.name(p.getName()), p.getDataType()));
    Result<?> result = create.select(fields).from("{0}", asField()).fetch();
    int i = 0;
    if (returnParameter != null)
        outValues.put(returnParameter, returnParameter.getDataType().convert(result.getValue(0, i++)));
    for (Parameter<?> p : outParameters) outValues.put(p, p.getDataType().convert(result.getValue(0, i++)));
    return 0;
}
Also used : Field(org.jooq.Field) UDTField(org.jooq.UDTField) ArrayList(java.util.ArrayList) DSLContext(org.jooq.DSLContext)

Example 27 with DSLContext

use of org.jooq.DSLContext in project jOOQ by jOOQ.

the class AbstractRoutine method executeSelectFromHSQLDB.

private final int executeSelectFromHSQLDB() {
    DSLContext create = create(configuration);
    Result<?> result = create.selectFrom(table(asField())).fetch();
    outValues.put(returnParameter, result);
    return 0;
}
Also used : DSLContext(org.jooq.DSLContext)

Example 28 with DSLContext

use of org.jooq.DSLContext in project jOOQ by jOOQ.

the class MockArray method getResultSet0.

@SuppressWarnings("unchecked")
private ResultSet getResultSet0(T[] a) {
    DSLContext create = DSL.using(dialect);
    Field<Long> index = field(name("INDEX"), Long.class);
    Field<T> value = (Field<T>) field(name("VALUE"), type.getComponentType());
    Result<Record2<Long, T>> result = create.newResult(index, value);
    for (int i = 0; i < a.length; i++) {
        Record2<Long, T> record = create.newRecord(index, value);
        record.setValue(index, i + 1L);
        record.setValue(value, a[i]);
        result.add(record);
    }
    return new MockResultSet(result);
}
Also used : Field(org.jooq.Field) DSLContext(org.jooq.DSLContext) Record2(org.jooq.Record2)

Example 29 with DSLContext

use of org.jooq.DSLContext 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 30 with DSLContext

use of org.jooq.DSLContext 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)

Aggregations

DSLContext (org.jooq.DSLContext)47 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)17 Test (org.junit.Test)8 Timestamp (java.sql.Timestamp)6 ArrayList (java.util.ArrayList)5 Field (org.jooq.Field)5 Listener (org.spongepowered.api.event.Listener)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 JooqContainer (com.intel.mtwilson.jooq.util.JooqContainer)3 Record (org.jooq.Record)3 Settings (org.jooq.conf.Settings)3 Context (com.torodb.backend.ErrorHandler.Context)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 UUID (java.util.UUID)2 DataSource (javax.sql.DataSource)2 Record1 (org.jooq.Record1)2 SelectQuery (org.jooq.SelectQuery)2 TableField (org.jooq.TableField)2