use of org.jooq.Support in project jOOQ by jOOQ.
the class SQLDialectChecker method createSourceVisitor.
@Override
protected SourceVisitor<Void, Void> createSourceVisitor() {
return new SourceVisitor<Void, Void>(getChecker()) {
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
try {
ExecutableElement elementFromUse = elementFromUse(node);
Support support = elementFromUse.getAnnotation(Support.class);
// all jOOQ API method calls will type check.
if (support != null && support.value().length > 0) {
Element enclosing = elementFromDeclaration(enclosingMethod(getPath(root, node)));
EnumSet<SQLDialect> supported = EnumSet.copyOf(asList(support.value()));
EnumSet<SQLDialect> allowed = EnumSet.noneOf(SQLDialect.class);
EnumSet<SQLDialect> required = EnumSet.noneOf(SQLDialect.class);
boolean evaluateRequire = true;
while (enclosing != null) {
Allow allow = enclosing.getAnnotation(Allow.class);
if (allow != null)
allowed.addAll(asList(allow.value()));
if (evaluateRequire) {
Require require = enclosing.getAnnotation(Require.class);
if (require != null) {
evaluateRequire = false;
required.clear();
required.addAll(asList(require.value()));
}
}
enclosing = enclosing.getEnclosingElement();
}
if (allowed.isEmpty())
error(node, "No jOOQ API usage is allowed at current scope. Use @Allow.");
if (required.isEmpty())
error(node, "No jOOQ API usage is allowed at current scope due to conflicting @Require specification.");
boolean allowedFail = true;
allowedLoop: for (SQLDialect a : allowed) {
for (SQLDialect s : supported) {
if (a.supports(s)) {
allowedFail = false;
break allowedLoop;
}
}
}
if (allowedFail)
error(node, "The allowed dialects in scope " + allowed + " do not include any of the supported dialects: " + supported);
boolean requiredFail = false;
requiredLoop: for (SQLDialect r : required) {
for (SQLDialect s : supported) if (r.supports(s))
continue requiredLoop;
requiredFail = true;
break requiredLoop;
}
if (requiredFail)
error(node, "Not all of the required dialects " + required + " from the current scope are supported " + supported);
}
} catch (final Exception e) {
print(new Printer() {
@Override
public void print(PrintWriter t) {
e.printStackTrace(t);
}
});
}
return super.visitMethodInvocation(node, p);
}
};
}
use of org.jooq.Support in project jOOQ by jOOQ.
the class DSL method sequenceByName.
/**
* Create a qualified sequence, given its sequence name.
* <p>
* This constructs a sequence reference given the sequence's qualified name.
* jOOQ will render the sequence name according to your
* {@link Settings#getRenderNameStyle()} settings. Choose
* {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL
* injection.
* <p>
* Example: <code><pre>
* // This sequence...
* sequenceByName("MY_SCHEMA", "MY_SEQUENCE");
*
* // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
* [MY_SCHEMA].[MY_SEQUENCE]
* </pre></code>
*
* @param qualifiedName The various parts making up your sequence's
* reference name.
* @param type The type of the returned field
* @return A sequence referenced by <code>sequenceName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #sequence(Name, DataType)} instead
*/
@Deprecated
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
public static <T extends Number> Sequence<T> sequenceByName(DataType<T> type, String... qualifiedName) {
if (qualifiedName == null)
throw new NullPointerException();
if (qualifiedName.length < 1 || qualifiedName.length > 2)
throw new IllegalArgumentException("Must provide a qualified name of length 1 or 2 : " + name(qualifiedName));
String name = qualifiedName[qualifiedName.length - 1];
Schema schema = qualifiedName.length == 2 ? schemaByName(qualifiedName[0]) : null;
return new SequenceImpl<T>(name, schema, type);
}
use of org.jooq.Support in project jOOQ by jOOQ.
the class DSL method sequence.
/**
* Create a qualified sequence, given its sequence name.
* <p>
* This constructs a sequence reference given the sequence's qualified name.
* jOOQ will render the sequence name according to your
* {@link Settings#getRenderNameStyle()} settings. Choose
* {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL
* injection.
* <p>
* Example: <code><pre>
* // This sequence...
* sequence(name("MY_SCHEMA", "MY_SEQUENCE"));
*
* // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
* [MY_SCHEMA].[MY_SEQUENCE]
* </pre></code>
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
public static <T extends Number> Sequence<T> sequence(Name name, DataType<T> type) {
if (name == null)
throw new NullPointerException();
if (name.getName().length < 1 || name.getName().length > 2)
throw new IllegalArgumentException("Must provide a qualified name of length 1 or 2 : " + name);
String n = name.getName()[name.getName().length - 1];
Schema s = name.getName().length == 2 ? schema(name(name.getName()[0])) : null;
return new SequenceImpl<T>(n, s, type);
}
Aggregations