use of org.jooq.Query in project jOOQ by jOOQ.
the class DDLDatabase method load.
private void load(DSLContext ctx, Source source) {
Reader r = null;
try {
Scanner s = new Scanner(r = source.reader()).useDelimiter("\\A");
Queries queries = ctx.parser().parse(s.hasNext() ? s.next() : "");
for (Query query : queries) {
repeat: for (; ; ) {
try {
if (logExecutedQueries)
log.info(query);
if (logExecutedQueries && logExecutionResults)
if (query instanceof ResultQuery)
log.info("\n" + ((ResultQuery<?>) query).fetch());
else
log.info("Update count: " + query.execute());
else
// [#10008] Execute all queries. Could have FOR UPDATE or other side effects
query.execute();
break repeat;
} catch (DataAccessException e) {
// [#7039] Auto create missing schemas. We're using the
if (Integer.toString(ErrorCode.SCHEMA_NOT_FOUND_1).equals(e.sqlState())) {
SQLException cause = e.getCause(SQLException.class);
if (cause != null) {
Matcher m = P_NAME.matcher(cause.getMessage());
if (m.find()) {
Query createSchema = ctx.createSchemaIfNotExists(name(m.group(1)));
createSchema.execute();
log.info(createSchema);
continue repeat;
}
}
}
throw e;
}
}
}
} catch (DataAccessException e) {
// [#9138] Make users aware of the new parse ignore comment syntax
log.error("DDLDatabase Error", "Your SQL string could not be parsed or interpreted. This may have a variety of reasons, including:\n" + "- The jOOQ parser doesn't understand your SQL\n" + "- The jOOQ DDL simulation logic (translating to H2) cannot simulate your SQL\n" + "\n" + "If you think this is a bug or a feature worth requesting, please report it here: https://github.com/jOOQ/jOOQ/issues/new/choose\n" + "\n" + "As a workaround, you can use the Settings.parseIgnoreComments syntax documented here:\n" + "https://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings/settings-parser/");
throw e;
} finally {
JDBCUtils.safeClose(r);
}
}
use of org.jooq.Query in project jOOQ by jOOQ.
the class DDL method createDomain.
@SuppressWarnings({ "rawtypes", "unchecked" })
final Query createDomain(Domain<?> domain) {
CreateDomainAsStep s1 = configuration.createDomainIfNotExists() ? ctx.createDomainIfNotExists(domain) : ctx.createDomain(domain);
CreateDomainDefaultStep s2 = s1.as(domain.getDataType());
CreateDomainConstraintStep s3 = domain.getDataType().defaulted() ? s2.default_(domain.getDataType().default_()) : s2;
if (domain.getChecks().isEmpty())
return s3;
return s3.constraints(map(domain.getChecks(), c -> c.constraint()));
}
use of org.jooq.Query in project jOOQ by jOOQ.
the class DDL method createTableOrView.
final List<Query> createTableOrView(Table<?> table, Collection<? extends Constraint> constraints) {
boolean temporary = table.getTableType() == TableType.TEMPORARY;
boolean view = table.getTableType().isView();
OnCommit onCommit = table.getOptions().onCommit();
if (view) {
List<Query> result = new ArrayList<>();
result.add(applyAs((configuration.createViewIfNotExists() ? ctx.createViewIfNotExists(table, table.fields()) : configuration.createOrReplaceView() ? ctx.createOrReplaceView(table, table.fields()) : ctx.createView(table, table.fields())), table.getOptions()));
if (!constraints.isEmpty() && configuration.includeConstraintsOnViews())
result.addAll(alterTableAddConstraints(table));
return result;
}
CreateTableOnCommitStep s0 = (configuration.createTableIfNotExists() ? temporary ? ctx.createTemporaryTableIfNotExists(table) : ctx.createTableIfNotExists(table) : temporary ? ctx.createTemporaryTable(table) : ctx.createTable(table)).columns(sortIf(asList(table.fields()), !configuration.respectColumnOrder())).constraints(constraints);
if (temporary && onCommit != null) {
switch(onCommit) {
case DELETE_ROWS:
return asList(s0.onCommitDeleteRows());
case PRESERVE_ROWS:
return asList(s0.onCommitPreserveRows());
case DROP:
return asList(s0.onCommitDrop());
default:
throw new IllegalStateException("Unsupported flag: " + onCommit);
}
}
return asList(s0);
}
use of org.jooq.Query in project Almura by AlmuraDev.
the class ServerStoreManager method handleDelistSellingItems.
public void handleDelistSellingItems(final Player player, final String id, final List<Integer> recNos) {
checkNotNull(player);
checkNotNull(id);
checkNotNull(recNos);
checkState(!recNos.isEmpty());
if (!player.hasPermission(Almura.ID + ".store.admin")) {
this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Store"), Text.of("You do not have permission " + "to unlist items!"), 5);
return;
}
final Store store = this.getStore(id).orElse(null);
if (store == null) {
this.logger.error("Player '{}' attempted to de-list selling items for store '{}' but the server has no knowledge of it. Syncing " + "store registry...", player.getName(), id);
this.syncStoreRegistryTo(player);
return;
}
final List<SellingItem> sellingItems = store.getSellingItems();
if (sellingItems.isEmpty()) {
this.logger.error("Player '{}' attempted to de-list selling items for store '{}' but the server knows of no " + " buying items for it. This could be a de-sync or an exploit.", player.getName(), store.getId());
this.network.sendTo(player, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, sellingItems));
return;
}
final List<Integer> copyRecNos = Lists.newArrayList(recNos);
final Iterator<Integer> iter = copyRecNos.iterator();
while (iter.hasNext()) {
final Integer recNo = iter.next();
final SellingItem found = sellingItems.stream().filter(v -> v.getRecord() == recNo).findAny().orElse(null);
if (found == null) {
this.logger.error("Player '{}' attempted to de-list selling item '{}' for store '{}' but the server knows of no knowledge of it. " + "This could be a de-sync or an exploit. Discarding...", player.getName(), recNo, store.getId());
iter.remove();
}
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final List<Query> toUpdate = new ArrayList<>();
for (final Integer recNo : recNos) {
toUpdate.add(StoreQueries.createUpdateSellingItemIsHidden(recNo, true).build(context));
}
context.batch(toUpdate).execute();
final Results results = StoreQueries.createFetchSellingItemsAndDataFor(store.getId(), false).build(context).fetchMany();
final List<SellingItem> finalSellingItems = new ArrayList<>();
results.forEach(result -> finalSellingItems.addAll(this.parseSellingItemsFrom(result)));
this.scheduler.createTaskBuilder().execute(() -> {
store.putSellingItems(finalSellingItems);
this.network.sendToAll(new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, finalSellingItems));
}).submit(this.container);
} catch (final SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
use of org.jooq.Query in project collect by openforis.
the class JooqRelationalSchemaCreator method createRelationalSchema.
@Override
public void createRelationalSchema(RelationalSchema schema, Connection conn) throws CollectRdbException {
CollectDSLContext dsl = new CollectDSLContext(conn);
for (Table<?> table : schema.getTables()) {
org.jooq.Table<Record> jooqTable = jooqTable(schema, table, !dsl.isSchemaLess());
CreateTableAsStep<Record> createTableStep = dsl.createTable(jooqTable);
Query createTableFinalQuery = (Query) createTableStep;
for (Column<?> column : table.getColumns()) {
DataType<?> dataType = dsl.getDataType(column.getType().getJavaType());
Integer length = column.getLength();
if (length != null) {
dataType.length(length);
}
createTableFinalQuery = createTableStep.column(column.getName(), dataType);
}
createTableFinalQuery.execute();
}
createDataTableViews(schema, conn);
}
Aggregations