[#3480] Add XXXContext.dialect() and XXXContext.family() for convenience

This commit is contained in:
Lukas Eder 2014-07-30 10:02:53 +02:00
parent 5bbe2fc026
commit a6c563c66e
12 changed files with 175 additions and 0 deletions

View File

@ -67,6 +67,22 @@ public interface Context<C extends Context<C>> {
*/
Configuration configuration();
/**
* The {@link SQLDialect} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect()</code>.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect().family()</code>.
*/
SQLDialect family();
/**
* Get all custom data from this <code>Context</code>.
* <p>

View File

@ -68,6 +68,22 @@ public interface DAO<R extends TableRecord<R>, P, T> {
*/
Configuration configuration();
/**
* The {@link SQLDialect} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect()</code>.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect().family()</code>.
*/
SQLDialect family();
/**
* Expose the {@link RecordMapper} that is used internally by this
* <code>DAO</code> to map from records of type <code>R</code> to POJOs of

View File

@ -123,6 +123,22 @@ public interface DSLContext {
*/
Configuration configuration();
/**
* The {@link SQLDialect} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect()</code>.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect().family()</code>.
*/
SQLDialect family();
/**
* Map a schema to another one.
* <p>

View File

@ -115,6 +115,22 @@ public interface ExecuteContext {
*/
Configuration configuration();
/**
* The {@link SQLDialect} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect()</code>.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect().family()</code>.
*/
SQLDialect family();
/**
* The connection to be used in this execute context.
* <p>

View File

@ -105,6 +105,22 @@ public interface RecordContext {
*/
Configuration configuration();
/**
* The {@link SQLDialect} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect()</code>.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect().family()</code>.
*/
SQLDialect family();
/**
* The type of database interaction that is being executed.
* <p>

View File

@ -53,6 +53,22 @@ public interface TransactionContext {
*/
Configuration configuration();
/**
* The {@link SQLDialect} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect()</code>.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect().family()</code>.
*/
SQLDialect family();
/**
* A user-defined transaction object, possibly obtained from
* {@link TransactionProvider#begin(TransactionContext)}.

View File

@ -94,6 +94,22 @@ public interface VisitContext {
*/
Configuration configuration();
/**
* The {@link SQLDialect} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect()</code>.
*/
SQLDialect dialect();
/**
* The {@link SQLDialect#family()} wrapped by this context.
* <p>
* This method is a convenient way of accessing
* <code>configuration().dialect().family()</code>.
*/
SQLDialect family();
/**
* The most recent clause that was encountered through
* {@link Context#start(Clause)}.

View File

@ -245,6 +245,16 @@ abstract class AbstractContext<C extends Context<C>> implements Context<C> {
return AbstractContext.this.configuration();
}
@Override
public final SQLDialect dialect() {
return Utils.configuration(configuration()).dialect();
}
@Override
public final SQLDialect family() {
return dialect().family();
}
@Override
public final Clause clause() {
return visitClauses.peekLast();
@ -306,6 +316,16 @@ abstract class AbstractContext<C extends Context<C>> implements Context<C> {
return configuration;
}
@Override
public final SQLDialect dialect() {
return Utils.configuration(configuration()).dialect();
}
@Override
public final SQLDialect family() {
return dialect().family();
}
@Override
public final Map<Object, Object> data() {
return data;

View File

@ -280,6 +280,16 @@ public class DefaultDSLContext implements DSLContext, Serializable {
return configuration;
}
@Override
public SQLDialect dialect() {
return Utils.configuration(configuration()).dialect();
}
@Override
public SQLDialect family() {
return dialect().family();
}
@Override
public Schema map(Schema schema) {
return Utils.getMappedSchema(configuration, schema);

View File

@ -65,6 +65,7 @@ import org.jooq.Record;
import org.jooq.Result;
import org.jooq.ResultQuery;
import org.jooq.Routine;
import org.jooq.SQLDialect;
import org.jooq.Truncate;
import org.jooq.Update;
import org.jooq.tools.jdbc.JDBCUtils;
@ -410,6 +411,16 @@ class DefaultExecuteContext implements ExecuteContext {
return configuration;
}
@Override
public final SQLDialect dialect() {
return Utils.configuration(configuration()).dialect();
}
@Override
public final SQLDialect family() {
return dialect().family();
}
@Override
public final void connectionProvider(ConnectionProvider provider) {
this.connectionProvider = provider;

View File

@ -48,6 +48,7 @@ import org.jooq.ExecuteType;
import org.jooq.Record;
import org.jooq.RecordContext;
import org.jooq.RecordType;
import org.jooq.SQLDialect;
/**
* A default implementation for {@link RecordContext}.
@ -89,6 +90,16 @@ class DefaultRecordContext implements RecordContext {
return configuration;
}
@Override
public final SQLDialect dialect() {
return Utils.configuration(configuration()).dialect();
}
@Override
public final SQLDialect family() {
return dialect().family();
}
@Override
public final ExecuteType type() {
return type;

View File

@ -41,6 +41,7 @@
package org.jooq.impl;
import org.jooq.Configuration;
import org.jooq.SQLDialect;
import org.jooq.Transaction;
import org.jooq.TransactionContext;
@ -62,6 +63,16 @@ class DefaultTransactionContext implements TransactionContext {
return configuration;
}
@Override
public final SQLDialect dialect() {
return Utils.configuration(configuration()).dialect();
}
@Override
public final SQLDialect family() {
return dialect().family();
}
@Override
public final Transaction transaction() {
return transaction;