Search in sources :

Example 61 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 62 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 63 with DSLContext

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

the class ReservedIdInfoFactoryImpl method startUp.

@Override
protected void startUp() throws Exception {
    ImmutableMetaSnapshot snapshot;
    try (SnapshotStage snapshotStage = metainfoRepository.startSnapshotStage()) {
        snapshot = snapshotStage.createImmutableSnapshot();
    }
    try (Connection connection = sqlInterface.getDbBackend().createSystemConnection()) {
        DSLContext dsl = sqlInterface.getDslContextFactory().createDslContext(connection);
        megaMap = loadRowIds(dsl, snapshot);
    }
}
Also used : SnapshotStage(com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) ImmutableMetaSnapshot(com.torodb.core.transaction.metainf.ImmutableMetaSnapshot)

Example 64 with DSLContext

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

the class AbstractReadInterface method getCollectionDidsWithFieldsInBatch.

@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
private Cursor<Integer> getCollectionDidsWithFieldsInBatch(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, Multimap<MetaField, KvValue<?>> valuesMultimap) throws SQLException {
    @SuppressWarnings("checkstyle:LineLength") Provider<Stream<Map.Entry<MetaField, Collection<KvValue<?>>>>> valuesMultimapSortedStreamProvider = () -> valuesMultimap.asMap().entrySet().stream().sorted((e1, e2) -> e1.getKey().getIdentifier().compareTo(e2.getKey().getIdentifier()));
    String statement = getReadCollectionDidsWithFieldInStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier(), valuesMultimapSortedStreamProvider.get().map(e -> new Tuple2<String, Integer>(e.getKey().getIdentifier(), e.getValue().size())));
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(statement);
        int parameterIndex = 1;
        Iterator<Map.Entry<MetaField, Collection<KvValue<?>>>> valuesMultimapSortedIterator = valuesMultimapSortedStreamProvider.get().iterator();
        while (valuesMultimapSortedIterator.hasNext()) {
            Map.Entry<MetaField, Collection<KvValue<?>>> valuesMultimapEntry = valuesMultimapSortedIterator.next();
            for (KvValue<?> value : valuesMultimapEntry.getValue()) {
                sqlHelper.setPreparedStatementValue(preparedStatement, parameterIndex, valuesMultimapEntry.getKey().getType(), value);
                parameterIndex++;
            }
        }
        return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Connection(java.sql.Connection) Provider(javax.inject.Provider) IteratorCursor(com.torodb.core.cursors.IteratorCursor) Multimap(com.google.common.collect.Multimap) Seq(org.jooq.lambda.Seq) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) TableRefFactory(com.torodb.core.TableRefFactory) KvValue(com.torodb.kvdocument.values.KvValue) Tuple2(org.jooq.lambda.tuple.Tuple2) SQLException(java.sql.SQLException) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) ResultSet(java.sql.ResultSet) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Context(com.torodb.backend.ErrorHandler.Context) Nonnull(javax.annotation.Nonnull) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Unchecked(org.jooq.lambda.Unchecked) Iterator(java.util.Iterator) Cursor(com.torodb.core.cursors.Cursor) Collection(java.util.Collection) EmptyCursor(com.torodb.core.cursors.EmptyCursor) DocPartTableFields(com.torodb.backend.tables.MetaDocPartTable.DocPartTableFields) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) TableRef(com.torodb.core.TableRef) List(java.util.List) MetaField(com.torodb.core.transaction.metainf.MetaField) Stream(java.util.stream.Stream) DocPartResult(com.torodb.core.d2r.DocPartResult) Entry(java.util.Map.Entry) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MetaField(com.torodb.core.transaction.metainf.MetaField) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Entry(java.util.Map.Entry) Tuple2(org.jooq.lambda.tuple.Tuple2) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Collection(java.util.Collection) Stream(java.util.stream.Stream) Map(java.util.Map) KvValue(com.torodb.kvdocument.values.KvValue) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 65 with DSLContext

use of org.jooq.DSLContext in project keywhiz by square.

the class DbSeedCommand method run.

@Override
protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) throws Exception {
    if (!config.getEnvironment().equals("development")) {
        throw new IllegalArgumentException("cannot call db-seed in non-development environment");
    }
    DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "db-seed-datasource");
    DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
    doImport(dslContext);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) DSLContext(org.jooq.DSLContext) DataSource(javax.sql.DataSource)

Aggregations

DSLContext (org.jooq.DSLContext)109 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)55 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)17 List (java.util.List)17 DIConfiguration (com.khartec.waltz.service.DIConfiguration)14 Collectors (java.util.stream.Collectors)14 EntityKind (com.khartec.waltz.model.EntityKind)11 ArrayList (java.util.ArrayList)9 DSL (org.jooq.impl.DSL)9 EntityReference (com.khartec.waltz.model.EntityReference)8 Timestamp (java.sql.Timestamp)8 Random (java.util.Random)8 IntStream (java.util.stream.IntStream)8 Application (com.khartec.waltz.model.application.Application)7 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)6 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)6 Field (org.jooq.Field)6 Record1 (org.jooq.Record1)6 Test (org.junit.Test)6