Search in sources :

Example 1 with AlterDomainRenameConstraintStep

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

the class DefaultParseContext method parseAlterDomain.

private final DDLQuery parseAlterDomain() {
    boolean ifExists = parseKeywordIf("IF EXISTS");
    Domain<?> domainName = parseDomainName();
    AlterDomainStep s1 = ifExists ? dsl.alterDomainIfExists(domainName) : dsl.alterDomain(domainName);
    if (parseKeywordIf("ADD")) {
        ConstraintTypeStep constraint = parseConstraintNameSpecification();
        // TODO: NOT NULL constraints
        if (parseKeywordIf("CHECK"))
            return s1.add(parseCheckSpecification(constraint));
        else
            throw expected("CHECK", "CONSTRAINT");
    } else if (parseKeywordIf("DROP CONSTRAINT")) {
        boolean ifConstraintExists = parseKeywordIf("IF EXISTS");
        Constraint constraint = constraint(parseIdentifier());
        AlterDomainDropConstraintCascadeStep s2 = ifConstraintExists ? s1.dropConstraintIfExists(constraint) : s1.dropConstraint(constraint);
        return parseKeywordIf("CASCADE") ? s2.cascade() : parseKeywordIf("RESTRICT") ? s2.restrict() : s2;
    } else if (parseKeywordIf("RENAME")) {
        if (parseKeywordIf("TO") || parseKeywordIf("AS")) {
            return s1.renameTo(parseDomainName());
        } else if (parseKeywordIf("CONSTRAINT")) {
            boolean ifConstraintExists = parseKeywordIf("IF EXISTS");
            Constraint oldName = constraint(parseIdentifier());
            AlterDomainRenameConstraintStep s2 = ifConstraintExists ? s1.renameConstraintIfExists(oldName) : s1.renameConstraint(oldName);
            parseKeyword("AS", "TO");
            return s2.to(constraint(parseIdentifier()));
        } else
            throw expected("CONSTRAINT", "TO", "AS");
    } else if (parseKeywordIf("SET DEFAULT"))
        return s1.setDefault(parseField());
    else if (parseKeywordIf("DROP DEFAULT"))
        return s1.dropDefault();
    else if (parseKeywordIf("SET NOT NULL"))
        return s1.setNotNull();
    else if (parseKeywordIf("DROP NOT NULL"))
        return s1.dropNotNull();
    else if (parseKeywordIf("OWNER TO")) {
        parseUser();
        return IGNORE;
    } else
        throw expected("ADD", "DROP", "RENAME", "SET", "OWNER TO");
}
Also used : ConstraintTypeStep(org.jooq.ConstraintTypeStep) AlterDomainRenameConstraintStep(org.jooq.AlterDomainRenameConstraintStep) Constraint(org.jooq.Constraint) AlterDomainStep(org.jooq.AlterDomainStep) AlterDomainDropConstraintCascadeStep(org.jooq.AlterDomainDropConstraintCascadeStep)

Aggregations

AlterDomainDropConstraintCascadeStep (org.jooq.AlterDomainDropConstraintCascadeStep)1 AlterDomainRenameConstraintStep (org.jooq.AlterDomainRenameConstraintStep)1 AlterDomainStep (org.jooq.AlterDomainStep)1 Constraint (org.jooq.Constraint)1 ConstraintTypeStep (org.jooq.ConstraintTypeStep)1