[#5311] Add DSL.constraint() to create an unnamed (system named) constraint

This commit is contained in:
lukaseder 2016-05-29 07:37:44 +02:00
parent 3660202e48
commit be3372dfa8
2 changed files with 22 additions and 5 deletions

View File

@ -84,6 +84,7 @@ import org.jooq.Context;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.Table;
import org.jooq.exception.DataAccessException;
/**
* @author Lukas Eder
@ -139,6 +140,10 @@ implements
private Action onUpdate;
private Condition check;
ConstraintImpl() {
this(null);
}
ConstraintImpl(Name name) {
this.name = name;
}
@ -151,16 +156,20 @@ implements
@Override
public final void accept(Context<?> ctx) {
if (ctx.data(DATA_CONSTRAINT_REFERENCE) != null) {
if (name == null)
throw new DataAccessException("Cannot ALTER or DROP CONSTRAINT without name");
ctx.visit(name);
}
else {
boolean qualify = ctx.qualify();
ctx.keyword("constraint")
.sql(' ')
.visit(name)
.formatIndentStart()
.formatSeparator();
if (name != null)
ctx.keyword("constraint")
.sql(' ')
.visit(name)
.formatIndentStart()
.formatSeparator();
if (unique != null) {
ctx.keyword("unique")

View File

@ -4780,6 +4780,14 @@ public class DSL {
// XXX DDL Clauses
// -------------------------------------------------------------------------
/**
* Create an unnamed (system named) <code>CONSTRAINT</code> specification.
*/
@Support
public static ConstraintTypeStep constraint() {
return new ConstraintImpl();
}
/**
* Create a <code>CONSTRAINT</code> specification.
*/