use of org.jooq.SQLDialect in project jOOQ by jOOQ.
the class SelectQueryImpl method accept.
@Override
public final void accept(Context<?> context) {
SQLDialect dialect = context.dialect();
SQLDialect family = context.family();
// [#2791] TODO: Instead of explicitly manipulating these data() objects, future versions
// of jOOQ should implement a push / pop semantics to clearly delimit such scope.
Object renderTrailingLimit = context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
Object localDataMap = context.data(DATA_LOCALLY_SCOPED_DATA_MAP);
try {
if (renderTrailingLimit != null)
context.data().remove(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
context.data(DATA_LOCALLY_SCOPED_DATA_MAP, new HashMap<Object, Object>());
if (into != null && context.data(DATA_OMIT_INTO_CLAUSE) == null && asList(CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE).contains(family)) {
context.data(DATA_OMIT_INTO_CLAUSE, true);
context.visit(DSL.createTable(into).as(this));
context.data().remove(DATA_OMIT_INTO_CLAUSE);
return;
}
if (with != null)
context.visit(with).formatSeparator();
pushWindow(context);
Boolean wrapDerivedTables = (Boolean) context.data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES);
if (TRUE.equals(wrapDerivedTables)) {
context.sql('(').formatIndentStart().formatNewLine().data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES, null);
}
switch(dialect) {
// By default, render the dialect's limit clause
default:
{
toSQLReferenceLimitDefault(context);
break;
}
}
// [#1296] FOR UPDATE is emulated in some dialects using ResultSet.CONCUR_UPDATABLE
if (forUpdate && !asList(CUBRID).contains(family)) {
context.formatSeparator().keyword("for update");
if (!forUpdateOf.isEmpty()) {
// [#4151] Some databases don't allow for qualifying column
// names here. Copy also to TableList
boolean unqualified = asList(DERBY, FIREBIRD, H2, HSQLDB).contains(context.family());
boolean qualify = context.qualify();
if (unqualified)
context.qualify(false);
context.sql(' ').keyword("of").sql(' ').visit(forUpdateOf);
if (unqualified)
context.qualify(qualify);
} else if (!forUpdateOfTables.isEmpty()) {
context.sql(' ').keyword("of").sql(' ');
switch(family) {
case DERBY:
{
forUpdateOfTables.toSQLFields(context);
break;
}
// Render the OF [table-names] clause
default:
Tools.tableNames(context, forUpdateOfTables);
break;
}
}
// FOR UPDATE semantics, we should use FOR UPDATE WITH LOCK
if (family == FIREBIRD) {
context.sql(' ').keyword("with lock");
}
if (forUpdateMode != null) {
context.sql(' ');
context.keyword(forUpdateMode.toSQL());
if (forUpdateMode == ForUpdateMode.WAIT) {
context.sql(' ');
context.sql(forUpdateWait);
}
}
} else if (forShare) {
switch(dialect) {
// MySQL has a non-standard implementation for the "FOR SHARE" clause
case MARIADB:
case MYSQL:
context.formatSeparator().keyword("lock in share mode");
break;
// Postgres is known to implement the "FOR SHARE" clause like this
default:
context.formatSeparator().keyword("for share");
break;
}
}
// end-of-query clauses are appended to the end of a query
if (!StringUtils.isBlank(option)) {
context.formatSeparator().sql(option);
}
if (TRUE.equals(wrapDerivedTables)) {
context.formatIndentEnd().formatNewLine().sql(')').data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES, true);
}
} finally {
context.data(DATA_LOCALLY_SCOPED_DATA_MAP, localDataMap);
if (renderTrailingLimit != null)
context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE, renderTrailingLimit);
}
}
use of org.jooq.SQLDialect in project jOOQ by jOOQ.
the class RowSubqueryCondition method delegate.
private final QueryPartInternal delegate(Context<?> ctx) {
final Configuration configuration = ctx.configuration();
final RenderContext render = ctx instanceof RenderContext ? (RenderContext) ctx : null;
SQLDialect family = configuration.dialect().family();
// [#3505] TODO: Emulate this where it is not supported
if (rightQuantified != null) {
return new Native();
} else // predicates with row value expressions and subqueries:
if (asList(H2, HSQLDB, MARIADB, MYSQL, POSTGRES).contains(family)) {
return new Native();
} else // [#2395] All other configurations have to be emulated
{
String table = render == null ? "t" : render.nextAlias();
List<String> names = new ArrayList<String>();
for (int i = 0; i < left.size(); i++) {
names.add(table + "_" + i);
}
Field<?>[] fields = new Field[names.size()];
for (int i = 0; i < fields.length; i++) {
fields[i] = field(name(table, names.get(i)));
}
Condition condition;
switch(comparator) {
case GREATER:
condition = ((RowN) left).gt(row(fields));
break;
case GREATER_OR_EQUAL:
condition = ((RowN) left).ge(row(fields));
break;
case LESS:
condition = ((RowN) left).lt(row(fields));
break;
case LESS_OR_EQUAL:
condition = ((RowN) left).le(row(fields));
break;
case IN:
case EQUALS:
case NOT_IN:
case NOT_EQUALS:
default:
condition = ((RowN) left).eq(row(fields));
break;
}
Select<Record> subselect = select().from(right.asTable(table, names.toArray(EMPTY_STRING))).where(condition);
switch(comparator) {
case NOT_IN:
case NOT_EQUALS:
return (QueryPartInternal) notExists(subselect);
default:
return (QueryPartInternal) exists(subselect);
}
}
}
use of org.jooq.SQLDialect in project OpenAttestation by OpenAttestation.
the class TagJdbi method jooq.
/**
* CODE QUALITY: All usage of this method should be in the following form:
* <pre>
* try(JooqContainer jc = TagJdbi.jooq()) {
* DSLContext jooq = jc.getDslContext();
* // code
* }
* </pre>
*
* This ensures the jooq database connection is automatically released
* at the end of the block (either closed or returned to the pool)
*
* @return
* @throws SQLException
* @throws IOException
*/
public static JooqContainer jooq() throws SQLException, IOException {
// omits the schema name from generated sql ; when we connect to the database we already specify a schema so this settings avoid
// redundancy in the sql and allows the administrator to change the database name without breaking the application
Settings settings = new Settings().withRenderSchema(false).withRenderNameStyle(RenderNameStyle.LOWER);
SQLDialect dbDialect = getSqlDialect();
// throws SQLException; Note that the DSLContext doesn't close the connection. We'll have to do that ourselves.
Connection connection = TagJdbi.getDataSource().getConnection();
DSLContext jooq = DSL.using(connection, dbDialect, settings);
return new JooqContainer(jooq, connection);
}
use of org.jooq.SQLDialect in project spring-boot by spring-projects.
the class JooqPropertiesTests method determineSqlDialectNoCheckIfDialectIsSet.
@Test
void determineSqlDialectNoCheckIfDialectIsSet() throws SQLException {
JooqProperties properties = load("spring.jooq.sql-dialect=postgres");
DataSource dataSource = mockStandaloneDataSource();
SQLDialect sqlDialect = properties.determineSqlDialect(dataSource);
assertThat(sqlDialect).isEqualTo(SQLDialect.POSTGRES);
then(dataSource).should(never()).getConnection();
}
use of org.jooq.SQLDialect in project spring-boot by spring-projects.
the class JooqPropertiesTests method determineSqlDialectWithKnownUrl.
@Test
void determineSqlDialectWithKnownUrl() {
JooqProperties properties = load();
SQLDialect sqlDialect = properties.determineSqlDialect(mockDataSource("jdbc:h2:mem:testdb"));
assertThat(sqlDialect).isEqualTo(SQLDialect.H2);
}
Aggregations