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