use of org.jooq.conf.Settings in project unipop by unipop-graph.
the class ContextManager method reloadContexts.
private void reloadContexts() throws IOException {
SQLDialect dialect = SQLDialect.valueOf(this.conf.getString("sqlDialect"));
BasicDataSource ds = new BasicDataSource();
ds.setUrl(new ObjectMapper().readValue(conf.getJSONArray("address").toString(), List.class).get(0).toString());
ds.setDriverClassName(conf.getString("driver"));
String user = conf.optString("user");
String password = conf.optString("password");
if (!user.isEmpty())
ds.setUsername(user);
if (!password.isEmpty())
ds.setPassword(password);
Settings settings = new Settings();
settings.setRenderNameStyle(RenderNameStyle.AS_IS);
Configuration conf = new DefaultConfiguration().set(ds).set(dialect).set(settings).set(new DefaultExecuteListenerProvider(new TimingExecuterListener()));
this.context = DSL.using(conf);
}
use of org.jooq.conf.Settings in project atlasdb by palantir.
the class JdbcKeyValueService method create.
public static JdbcKeyValueService create(JdbcKeyValueConfiguration config) {
JdbcDataSourceConfiguration dataSourceConfig = config.getDataSourceConfig();
SQLDialect sqlDialect = SQLDialect.valueOf(dataSourceConfig.getSqlDialect());
DataSource dataSource = dataSourceConfig.createDataSource();
Settings settings = new Settings();
settings.setRenderNameStyle(RenderNameStyle.AS_IS);
final JdbcKeyValueService kvs = new JdbcKeyValueService(settings, sqlDialect, dataSource, config.getTablePrefix(), config.getRowBatchSize(), config.getBatchSizeForReads(), config.getBatchSizeForMutations());
kvs.run((Function<DSLContext, Void>) ctx -> {
String partialSql = ctx.createTable(kvs.METADATA_TABLE).column(TABLE_NAME, VARCHAR.nullable(false)).column(METADATA, BLOB.nullable(false)).getSQL();
int endIndex = partialSql.lastIndexOf(')');
String fullSql = partialSql.substring(0, endIndex) + "," + " CONSTRAINT pk_" + kvs.METADATA_TABLE.getName() + " PRIMARY KEY (" + TABLE_NAME.getName() + ")" + partialSql.substring(endIndex);
try {
ctx.execute(fullSql);
} catch (DataAccessException e) {
kvs.handleTableCreationException(e);
}
return null;
});
return kvs;
}
use of org.jooq.conf.Settings in project collect by openforis.
the class DialectAwareJooqConfiguration method createConfiguration.
private static Configuration createConfiguration(ConnectionProvider connectionProvider) {
SQLDialect dialect = getDialect(connectionProvider);
Settings settings = new Settings();
switch(dialect) {
case SQLITE:
settings.withRenderSchema(false);
break;
case H2:
settings.setRenderNameStyle(RenderNameStyle.AS_IS);
break;
default:
}
DefaultConfiguration configuration = new DefaultConfiguration();
configuration.setConnectionProvider(connectionProvider);
configuration.setSettings(settings);
configuration.setSQLDialect(dialect);
return configuration;
}
use of org.jooq.conf.Settings in project jOOQ by jOOQ.
the class Example_3_3_PreparedStatements method run.
@Test
public void run() throws SQLException {
Connection connection = connection();
Tools.title("Distinguishing between static and prepared statements with JDBC");
// 1% of the time
try (Statement stmt = connection.createStatement()) {
stmt.execute("SELECT * FROM AUTHOR");
}
// 99% of the time
try (PreparedStatement stmt = connection.prepareStatement("SELECT * FROM AUTHOR")) {
stmt.execute();
}
Tools.title("Distinguishing between static and prepared statements with jOOQ");
// 1% of the time
System.out.println(DSL.using(connection, new Settings().withStatementType(StatementType.STATIC_STATEMENT)).fetch("SELECT * FROM AUTHOR"));
// 99% of the time
System.out.println(DSL.using(connection).fetch("SELECT * FROM AUTHOR"));
}
use of org.jooq.conf.Settings in project jOOQ by jOOQ.
the class ParserCLI method interactiveMode.
private static final void interactiveMode(DSLContext ctx, Args a) {
Scanner scan = new Scanner(System.in);
System.out.print("> ");
cliLoop: do {
String line = scan.nextLine();
// TODO: Allow reading history again using arrow keys
// https://stackoverflow.com/q/572001/521799
a.history.add(line);
// [#12543] Avoid interpreting comments as commands
boolean leadingSlash = line.matches("^/[^/*].*$");
if (a.sql == null && leadingSlash) {
if ("/q".equals(line) || "/quit".equals(line) || "/e".equals(line) || "/exit".equals(line)) {
System.out.println("Bye");
break cliLoop;
} else if ("/?".equals(line) || "/h".equals(line) || "/help".equals(line))
helpInteractive();
else if ("/d".equals(line) || "/display".equals(line))
displayArguments(a);
else {
Matcher matcher = FLAG.matcher(line);
if (matcher.find()) {
String flag = matcher.group(1);
String arg = matcher.group(2);
if (flag != null) {
if ("f".equals(flag) || "formatted".equals(flag)) {
if (arg != null)
a.formatted = Boolean.parseBoolean(arg.toLowerCase());
displayFormatted(a);
} else if ("k".equals(flag) || "keyword".equals(flag))
parseInteractive(RenderKeywordCase.class, arg, e -> {
a.keywords = e;
}, () -> displayKeywords(a));
else if ("i".equals(flag) || "identifier".equals(flag))
parseInteractive(RenderNameCase.class, arg, e -> {
a.name = e;
}, () -> displayIdentifiers(a));
else if ("Q".equals(flag) || "quoted".equals(flag))
parseInteractive(RenderQuotedNames.class, arg, e -> {
a.quoted = e;
}, () -> displayQuoted(a));
else if ("F".equals(flag) || "from-dialect".equals(flag))
parseInteractive(SQLDialect.class, arg, e -> {
a.fromDialect = e;
}, () -> displayFromDialect(a));
else if ("render-coalesce-to-empty-string-in-concat".equals(flag)) {
if (arg != null)
a.renderCoalesceToEmptyStringInConcat = Boolean.parseBoolean(arg.toLowerCase());
displayRenderCoalesceToEmptyStringInConcat(a);
} else if ("parse-date-format".equals(flag)) {
if (arg != null)
a.parseDateFormat = arg;
displayParseDateFormat(a);
} else if ("parse-ignore-comments".equals(flag)) {
if (arg != null)
a.parseIgnoreComments = Boolean.parseBoolean(arg.toLowerCase());
displayParseIgnoreComments(a);
} else if ("parse-ignore-comment-start".equals(flag)) {
if (arg != null)
a.parseIgnoreCommentStart = arg;
displayParseIgnoreCommentStart(a);
} else if ("parse-ignore-comment-stop".equals(flag)) {
if (arg != null)
a.parseIgnoreCommentStop = arg;
displayParseIgnoreCommentStop(a);
} else if ("parse-locale".equals(flag)) {
if (arg != null)
a.parseLocale = Locale.forLanguageTag(arg);
displayParseLocale(a);
} else if ("parse-name-case".equals(flag))
parseInteractive(ParseNameCase.class, arg, e -> {
a.parseNameCase = e;
}, () -> displayParseNameCase(a));
else if ("parse-named-param-prefix".equals(flag)) {
if (arg != null)
a.parseNamedParamPrefix = arg;
displayParseNamedParamPrefix(a);
} else if ("parse-retain-comments-between-queries".equals(flag)) {
if (arg != null)
a.parseRetainCommentsBetweenQueries = Boolean.parseBoolean(arg.toLowerCase());
displayParseRetainCommentsBetweenQueries(a);
} else if ("parse-set-commands".equals(flag)) {
if (arg != null)
a.parseSetCommands = Boolean.parseBoolean(arg.toLowerCase());
displayParseSetCommands(a);
} else if ("parse-timestamp-format".equals(flag)) {
if (arg != null)
a.parseTimestampFormat = arg;
displayParseTimestampFormat(a);
} else if ("parse-unknown-functions".equals(flag))
parseInteractive(ParseUnknownFunctions.class, arg, e -> {
a.parseUnknownFunctions = e;
}, () -> displayParseUnknownFunctions(a));
else if ("parse-unsupported-syntax".equals(flag))
parseInteractive(ParseUnsupportedSyntax.class, arg, e -> {
a.parseUnsupportedSyntax = e;
}, () -> displayParseUnsupportedSyntax(a));
else if ("render-optional-inner-keyword".equals(flag))
parseInteractive(RenderOptionalKeyword.class, arg, e -> {
a.renderOptionalInnerKeyword = e;
}, () -> displayRenderOptionalInnerKeyword(a));
else if ("render-optional-outer-keyword".equals(flag))
parseInteractive(RenderOptionalKeyword.class, arg, e -> {
a.renderOptionalOuterKeyword = e;
}, () -> displayRenderOptionalOuterKeyword(a));
else if ("render-optional-as-keyword-for-field-aliases".equals(flag))
parseInteractive(RenderOptionalKeyword.class, arg, e -> {
a.renderOptionalAsKeywordForFieldAliases = e;
}, () -> displayRenderOptionalAsKeywordForFieldAliases(a));
else if ("render-optional-as-keyword-for-table-aliases".equals(flag))
parseInteractive(RenderOptionalKeyword.class, arg, e -> {
a.renderOptionalAsKeywordForTableAliases = e;
}, () -> displayRenderOptionalAsKeywordForTableAliases(a));
else if ("transform-patterns".equals(flag)) {
if (arg != null)
a.transformPatterns = Boolean.parseBoolean(arg.toLowerCase());
displayTransformPatterns(a);
} else if ("transform-ansi-join-to-table-lists".equals(flag)) {
if (arg != null)
a.transformAnsiJoinToTableLists = Boolean.parseBoolean(arg.toLowerCase());
displayTransformAnsiJoinToTablesLists(a);
} else if ("transform-qualify".equals(flag))
parseInteractive(Transformation.class, arg, e -> {
a.transformQualify = e;
}, () -> displayTransformQualify(a));
else if ("transform-rownum".equals(flag))
parseInteractive(Transformation.class, arg, e -> {
a.transformRownum = e;
}, () -> displayTransformRownum(a));
else if ("transform-table-lists-to-ansi-join".equals(flag)) {
if (arg != null)
a.transformTableListsToAnsiJoin = Boolean.parseBoolean(arg.toLowerCase());
displayTransformTableListsToAnsiJoin(a);
} else if ("transform-unneeded-arithmetic".equals(flag))
parseInteractive(TransformUnneededArithmeticExpressions.class, arg, e -> {
a.transformUnneededArithmetic = e;
}, () -> {
displayTransformUnneededArithmetic(a);
});
else // [#9144] /t maintained for backwards compatibility
if ("t".equals(flag) || "T".equals(flag) || "to-dialect".equals(flag))
parseInteractive(SQLDialect.class, arg, e -> {
a.toDialect = e;
}, () -> displayToDialect(a));
}
} else {
System.out.println("Unrecognised command: " + line);
System.out.println("Type /h for help");
}
}
settings(a, ctx.settings());
ctx = ctx(a, ctx.settings());
}
if (a.sql != null || !leadingSlash) {
if (a.sql == null)
a.sql = line;
else
a.sql = a.sql + "\n" + line;
if (a.sql.trim().endsWith(";")) {
render(ctx, a);
a.sql = null;
System.out.println();
}
}
System.out.print("> ");
} while (scan.hasNextLine());
}
Aggregations