Search in sources :

Example 1 with CreateDomainConstraintStep

use of org.jooq.CreateDomainConstraintStep in project jOOQ by jOOQ.

the class DefaultParseContext method parseCreateDomain.

private final DDLQuery parseCreateDomain() {
    boolean ifNotExists = parseKeywordIf("IF NOT EXISTS");
    Domain<?> domainName = parseDomainName();
    parseKeyword("AS");
    DataType<?> dataType = parseDataType();
    CreateDomainDefaultStep<?> s1 = ifNotExists ? dsl.createDomainIfNotExists(domainName).as(dataType) : dsl.createDomain(domainName).as(dataType);
    CreateDomainConstraintStep s2 = parseKeywordIf("DEFAULT") ? s1.default_((Field) parseField()) : s1;
    List<Constraint> constraints = new ArrayList<>();
    constraintLoop: for (; ; ) {
        ConstraintTypeStep constraint = parseConstraintNameSpecification();
        // TODO: NOT NULL constraints
        if (parseKeywordIf("CHECK")) {
            constraints.add(parseCheckSpecification(constraint));
            continue constraintLoop;
        } else if (constraint != null)
            throw expected("CHECK", "CONSTRAINT");
        break;
    }
    if (!constraints.isEmpty())
        s2 = s2.constraints(constraints);
    return s2;
}
Also used : ConstraintTypeStep(org.jooq.ConstraintTypeStep) GroupField(org.jooq.GroupField) TableField(org.jooq.TableField) Field(org.jooq.Field) SortField(org.jooq.SortField) SelectField(org.jooq.SelectField) CreateDomainConstraintStep(org.jooq.CreateDomainConstraintStep) Constraint(org.jooq.Constraint) ArrayList(java.util.ArrayList)

Example 2 with CreateDomainConstraintStep

use of org.jooq.CreateDomainConstraintStep in project jOOQ by jOOQ.

the class DDL method createDomain.

@SuppressWarnings({ "rawtypes", "unchecked" })
final Query createDomain(Domain<?> domain) {
    CreateDomainAsStep s1 = configuration.createDomainIfNotExists() ? ctx.createDomainIfNotExists(domain) : ctx.createDomain(domain);
    CreateDomainDefaultStep s2 = s1.as(domain.getDataType());
    CreateDomainConstraintStep s3 = domain.getDataType().defaulted() ? s2.default_(domain.getDataType().default_()) : s2;
    if (domain.getChecks().isEmpty())
        return s3;
    return s3.constraints(map(domain.getChecks(), c -> c.constraint()));
}
Also used : UniqueKey(org.jooq.UniqueKey) Arrays(java.util.Arrays) Tools.map(org.jooq.impl.Tools.map) KEY_COMP(org.jooq.impl.Comparators.KEY_COMP) Table(org.jooq.Table) SCHEMA(org.jooq.DDLFlag.SCHEMA) SEQUENCE(org.jooq.DDLFlag.SEQUENCE) CreateTableOnCommitStep(org.jooq.CreateTableOnCommitStep) Arrays.asList(java.util.Arrays.asList) Index(org.jooq.Index) DSLContext(org.jooq.DSLContext) Domain(org.jooq.Domain) COMMENT(org.jooq.DDLFlag.COMMENT) DSL.constraint(org.jooq.impl.DSL.constraint) CHECK(org.jooq.DDLFlag.CHECK) Collection(java.util.Collection) Check(org.jooq.Check) Field(org.jooq.Field) Meta(org.jooq.Meta) DOMAIN(org.jooq.DDLFlag.DOMAIN) TableType(org.jooq.TableOptions.TableType) List(java.util.List) Queries(org.jooq.Queries) CreateIndexIncludeStep(org.jooq.CreateIndexIncludeStep) Query(org.jooq.Query) TABLE(org.jooq.DDLFlag.TABLE) ForeignKey(org.jooq.ForeignKey) VIEW(org.jooq.TableOptions.TableType.VIEW) UNIQUE(org.jooq.DDLFlag.UNIQUE) Sequence(org.jooq.Sequence) ArrayList(java.util.ArrayList) CreateViewAsStep(org.jooq.CreateViewAsStep) INDEX(org.jooq.DDLFlag.INDEX) Comment(org.jooq.Comment) Schema(org.jooq.Schema) PRIMARY_KEY(org.jooq.DDLFlag.PRIMARY_KEY) FOREIGN_KEY(org.jooq.DDLFlag.FOREIGN_KEY) NAMED_COMP(org.jooq.impl.Comparators.NAMED_COMP) CreateDomainAsStep(org.jooq.CreateDomainAsStep) DDLFlag(org.jooq.DDLFlag) DDLExportConfiguration(org.jooq.DDLExportConfiguration) OnCommit(org.jooq.TableOptions.OnCommit) CreateSequenceFlagsStep(org.jooq.CreateSequenceFlagsStep) StringUtils(org.jooq.tools.StringUtils) Constraint(org.jooq.Constraint) ConstraintEnforcementStep(org.jooq.ConstraintEnforcementStep) CreateDomainConstraintStep(org.jooq.CreateDomainConstraintStep) Named(org.jooq.Named) TableOptions(org.jooq.TableOptions) CreateDomainDefaultStep(org.jooq.CreateDomainDefaultStep) Key(org.jooq.Key) CreateDomainConstraintStep(org.jooq.CreateDomainConstraintStep) CreateDomainDefaultStep(org.jooq.CreateDomainDefaultStep) CreateDomainAsStep(org.jooq.CreateDomainAsStep)

Aggregations

ArrayList (java.util.ArrayList)2 Constraint (org.jooq.Constraint)2 CreateDomainConstraintStep (org.jooq.CreateDomainConstraintStep)2 Field (org.jooq.Field)2 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 List (java.util.List)1 Check (org.jooq.Check)1 Comment (org.jooq.Comment)1 ConstraintEnforcementStep (org.jooq.ConstraintEnforcementStep)1 ConstraintTypeStep (org.jooq.ConstraintTypeStep)1 CreateDomainAsStep (org.jooq.CreateDomainAsStep)1 CreateDomainDefaultStep (org.jooq.CreateDomainDefaultStep)1 CreateIndexIncludeStep (org.jooq.CreateIndexIncludeStep)1 CreateSequenceFlagsStep (org.jooq.CreateSequenceFlagsStep)1 CreateTableOnCommitStep (org.jooq.CreateTableOnCommitStep)1 CreateViewAsStep (org.jooq.CreateViewAsStep)1 DDLExportConfiguration (org.jooq.DDLExportConfiguration)1 DDLFlag (org.jooq.DDLFlag)1