Search in sources :

Example 1 with CreateIndexStep

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

the class ParserImpl method parseCreateIndex.

private static final DDLQuery parseCreateIndex(ParserContext ctx) {
    boolean ifNotExists = parseKeywordIf(ctx, "IF NOT EXISTS");
    Name indexName = parseIndexName(ctx);
    parseKeyword(ctx, "ON");
    Table<?> tableName = parseTableName(ctx);
    parse(ctx, '(');
    Field<?>[] fieldNames = Tools.fieldsByName(parseIdentifiers(ctx));
    parse(ctx, ')');
    Condition condition = parseKeywordIf(ctx, "WHERE") ? parseCondition(ctx) : null;
    CreateIndexStep s1 = ifNotExists ? ctx.dsl.createIndexIfNotExists(indexName) : ctx.dsl.createIndex(indexName);
    CreateIndexWhereStep s2 = s1.on(tableName, fieldNames);
    CreateIndexFinalStep s3 = condition != null ? s2.where(condition) : s2;
    return s3;
}
Also used : Condition(org.jooq.Condition) TableField(org.jooq.TableField) GroupField(org.jooq.GroupField) Field(org.jooq.Field) SortField(org.jooq.SortField) CreateIndexFinalStep(org.jooq.CreateIndexFinalStep) CreateIndexWhereStep(org.jooq.CreateIndexWhereStep) CreateIndexStep(org.jooq.CreateIndexStep) Name(org.jooq.Name)

Example 2 with CreateIndexStep

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

the class DefaultParseContext method parseCreateIndex.

private final DDLQuery parseCreateIndex(boolean unique) {
    boolean ifNotExists = parseKeywordIf("IF NOT EXISTS");
    Name indexName = parseIndexNameIf();
    parseUsingIndexTypeIf();
    SortField<?>[] fields = null;
    if (peek('('))
        fields = parseParenthesisedSortSpecification();
    parseKeyword("ON");
    Table<?> tableName = parseTableName();
    parseUsingIndexTypeIf();
    if (fields == null)
        fields = parseParenthesisedSortSpecification();
    parseUsingIndexTypeIf();
    Name[] include = null;
    if (parseKeywordIf("INCLUDE") || parseKeywordIf("COVERING") || parseKeywordIf("STORING")) {
        parse('(');
        include = parseIdentifiers().toArray(EMPTY_NAME);
        parse(')');
    }
    Condition condition = parseKeywordIf("WHERE") ? parseCondition() : null;
    boolean excludeNullKeys = condition == null && parseKeywordIf("EXCLUDE NULL KEYS");
    CreateIndexStep s1 = ifNotExists ? unique ? dsl.createUniqueIndexIfNotExists(indexName) : dsl.createIndexIfNotExists(indexName) : unique ? indexName == null ? dsl.createUniqueIndex() : dsl.createUniqueIndex(indexName) : indexName == null ? dsl.createIndex() : dsl.createIndex(indexName);
    CreateIndexIncludeStep s2 = s1.on(tableName, fields);
    CreateIndexWhereStep s3 = include != null ? s2.include(include) : s2;
    return condition != null ? s3.where(condition) : excludeNullKeys ? s3.excludeNullKeys() : s3;
}
Also used : Condition(org.jooq.Condition) CreateIndexIncludeStep(org.jooq.CreateIndexIncludeStep) SortField(org.jooq.SortField) CreateIndexWhereStep(org.jooq.CreateIndexWhereStep) CreateIndexStep(org.jooq.CreateIndexStep) Name(org.jooq.Name) DSL.systemName(org.jooq.impl.DSL.systemName)

Aggregations

Condition (org.jooq.Condition)2 CreateIndexStep (org.jooq.CreateIndexStep)2 CreateIndexWhereStep (org.jooq.CreateIndexWhereStep)2 Name (org.jooq.Name)2 SortField (org.jooq.SortField)2 CreateIndexFinalStep (org.jooq.CreateIndexFinalStep)1 CreateIndexIncludeStep (org.jooq.CreateIndexIncludeStep)1 Field (org.jooq.Field)1 GroupField (org.jooq.GroupField)1 TableField (org.jooq.TableField)1 DSL.systemName (org.jooq.impl.DSL.systemName)1