use of org.jooq.conf.Settings in project jOOQ by jOOQ.
the class DAOImpl method records.
private /* non-final */
List<R> records(Collection<P> objects, boolean forUpdate) {
List<R> result = new ArrayList<>(objects.size());
Field<?>[] pk = pk();
DSLContext ctx;
// [#7731] Create a Record -> POJO mapping to allow for reusing the below
// derived Configuration for improved reflection caching.
IdentityHashMap<R, Object> mapping = !FALSE.equals(settings().isReturnRecordToPojo()) ? new IdentityHashMap<>() : null;
// are copied back to the relevant POJO using the RecordListener SPI
if (mapping != null) {
Consumer<? super RecordContext> end = c -> {
Record record = c.record();
// TODO: [#2536] Use mapper()
if (record != null)
record.into(mapping.get(record));
};
ctx = configuration().deriveAppending(onStoreEnd(end).onInsertEnd(end).onUpdateEnd(end).onDeleteEnd(end)).dsl();
} else
ctx = ctx();
for (P object : objects) {
R record = ctx.newRecord(table, object);
if (mapping != null)
mapping.put(record, object);
if (forUpdate && pk != null)
for (Field<?> field : pk) record.changed(field, false);
Tools.resetChangedOnNotNull(record);
result.add(record);
}
return result;
}
use of org.jooq.conf.Settings in project jOOQ by jOOQ.
the class ParserCLI method main.
public static final void main(String... args) throws Exception {
CLIUtil.main("https://www.jooq.org/doc/latest/manual/sql-building/sql-parser/sql-parser-cli/", () -> {
Args a;
Settings settings = new Settings();
DSLContext ctx;
a = parse(args);
settings(a, settings);
ctx = ctx(a, settings);
if (a.interactive || args == null || args.length == 0) {
interactiveMode(ctx, a);
} else if (a.done) {
} else if (a.toDialect == null || a.sql == null) {
System.out.println("Mandatory arguments: -T and -s. Use -h for help");
throw new RuntimeException();
} else
render(ctx, a);
});
}
use of org.jooq.conf.Settings in project jOOQ by jOOQ.
the class DiffCLI method main.
public static final void main(String... args) throws Exception {
CLIUtil.main("https://www.jooq.org/doc/latest/manual/sql-building/schema-diff-cli/", () -> {
Args a;
Settings settings = new Settings();
DSLContext ctx;
a = parse(args);
settings(a, settings);
ctx = ctx(a, settings);
if (a.done) {
} else if (a.toDialect == null || a.sql1 == null || a.sql2 == null) {
System.out.println("Mandatory arguments: -T and -1, -2. Use -h for help");
throw new RuntimeException();
} else
render(ctx, a);
});
}
use of org.jooq.conf.Settings in project jOOQ by jOOQ.
the class Example_4_2_Settings method run.
@Test
public void run() {
Select<?> select = DSL.select().from(AUTHOR).where(AUTHOR.ID.eq(3));
Tools.title("A couple of settings at work - Formatting");
out.println(using(H2, new Settings().withRenderFormatted(false)).render(select));
out.println(using(H2, new Settings().withRenderFormatted(true)).render(select));
Tools.title("A couple of settings at work - Schema");
out.println(using(H2, new Settings().withRenderSchema(false)).render(select));
out.println(using(H2, new Settings().withRenderSchema(true)).render(select));
Tools.title("A couple of settings at work - Name case");
out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.AS_IS)).render(select));
out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.UPPER)).render(select));
out.println(using(H2, new Settings().withRenderNameCase(RenderNameCase.LOWER)).render(select));
Tools.title("A couple of settings at work - Name quoting");
out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.ALWAYS)).render(select));
out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.EXPLICIT_DEFAULT_QUOTED)).render(select));
out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.EXPLICIT_DEFAULT_UNQUOTED)).render(select));
out.println(using(H2, new Settings().withRenderQuotedNames(RenderQuotedNames.NEVER)).render(select));
Tools.title("A couple of settings at work - Keyword case");
out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.AS_IS)).render(select));
out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.LOWER)).render(select));
out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.UPPER)).render(select));
out.println(using(H2, new Settings().withRenderKeywordCase(RenderKeywordCase.PASCAL)).render(select));
Tools.title("A couple of settings at work - Mapping");
out.println(using(H2, new Settings().withRenderMapping(new RenderMapping().withSchemata(new MappedSchema().withInput("PUBLIC").withOutput("test").withTables(new MappedTable().withInput("AUTHOR").withOutput("test-author"))))).render(select));
}
use of org.jooq.conf.Settings in project jOOQ by jOOQ.
the class Example_2_2_OptimisticLocking method run.
@Test
public void run() throws SQLException {
Connection connection = connection();
DSLContext dsl = DSL.using(connection, new Settings().withExecuteWithOptimisticLocking(true));
try {
Tools.title("Applying optimistic locking");
BookRecord book1 = dsl.selectFrom(BOOK).where(BOOK.ID.eq(1)).fetchOne();
BookRecord book2 = dsl.selectFrom(BOOK).where(BOOK.ID.eq(1)).fetchOne();
book1.setTitle("New Title");
book1.store();
book2.setTitle("Another Title");
book2.store();
} catch (DataChangedException expected) {
expected.printStackTrace();
} finally // Don't store the changes
{
connection.rollback();
}
}
Aggregations