[#4919] Add support for CREATE INDEX .. WHERE in SQL Server (filtered indexes)

This commit is contained in:
lukaseder 2016-05-16 14:18:08 +02:00
parent 729033bb08
commit 640b6f5cb6
3 changed files with 194 additions and 6 deletions

View File

@ -70,11 +70,11 @@ public interface CreateIndexStep {
* Specify the table and column expressions on which to create an index.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
CreateIndexFinalStep on(Table<?> table, Field<?>... fields);
CreateIndexWhereStep on(Table<?> table, Field<?>... fields);
/**
* Specify the table and column expressions on which to create an index.
*/
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
CreateIndexFinalStep on(String tableName, String... fieldNames);
CreateIndexWhereStep on(String tableName, String... fieldNames);
}

View File

@ -0,0 +1,137 @@
/**
* Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq;
// ...
import java.util.Collection;
import org.jooq.impl.DSL;
/**
* A {@link Query} that can create indexes.
*
* @author Lukas Eder
*/
public interface CreateIndexWhereStep extends CreateIndexFinalStep {
}

View File

@ -54,14 +54,18 @@ import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.name;
import static org.jooq.impl.DSL.table;
import java.util.Collection;
import org.jooq.Clause;
import org.jooq.Condition;
import org.jooq.Configuration;
import org.jooq.Context;
import org.jooq.CreateIndexFinalStep;
import org.jooq.CreateIndexStep;
import org.jooq.CreateIndexWhereStep;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.QueryPart;
import org.jooq.SQL;
import org.jooq.Table;
/**
@ -71,7 +75,7 @@ final class CreateIndexImpl extends AbstractQuery implements
// Cascading interface implementations for CREATE INDEX behaviour
CreateIndexStep,
CreateIndexFinalStep {
CreateIndexWhereStep {
/**
* Generated UID
@ -85,6 +89,9 @@ final class CreateIndexImpl extends AbstractQuery implements
private Table<?> table;
private Field<?>[] fields;
CreateIndexImpl(Configuration configuration, Name index, boolean unique, boolean ifNotExists) {
super(configuration);
@ -98,7 +105,7 @@ final class CreateIndexImpl extends AbstractQuery implements
// ------------------------------------------------------------------------
@Override
public final CreateIndexFinalStep on(Table<?> t, Field<?>... f) {
public final CreateIndexImpl on(Table<?> t, Field<?>... f) {
this.table = t;
this.fields = f;
@ -106,7 +113,7 @@ final class CreateIndexImpl extends AbstractQuery implements
}
@Override
public final CreateIndexFinalStep on(String tableName, String... fieldNames) {
public final CreateIndexImpl on(String tableName, String... fieldNames) {
Field<?>[] f = new Field[fieldNames.length];
for (int i = 0; i < f.length; i++)
@ -115,6 +122,45 @@ final class CreateIndexImpl extends AbstractQuery implements
return on(table(name(tableName)), f);
}
// ------------------------------------------------------------------------
// XXX: QueryPart API
// ------------------------------------------------------------------------
@ -160,6 +206,11 @@ final class CreateIndexImpl extends AbstractQuery implements
.visit(new QueryPartList<QueryPart>(fields))
.qualify(true)
.sql(')');
}
@Override