[jOOQ/jOOQ#8528] Support CREATE TABLE inline index specifications

The parser already supports this, so it is just a matter of exposing the
indexes through the `Meta` API (`Table#getIndexes()`).
This commit is contained in:
Knut Wannheden 2019-09-18 15:44:08 +02:00
parent 78ae663c92
commit 2d0a638597
3 changed files with 24 additions and 0 deletions

View File

@ -187,6 +187,7 @@ final class CreateTableImpl extends AbstractRowCountQuery implements
final List<Field<?>> $columnFields() { return columnFields; }
final List<DataType<?>> $columnTypes() { return columnTypes; }
final List<Constraint> $constraints() { return constraints; }
final List<Index> $indexes() { return indexes; }
final boolean $ifNotExists() { return ifNotExists; }
final Comment $comment() { return comment; }

View File

@ -51,12 +51,14 @@ import org.jooq.Configuration;
import org.jooq.Constraint;
import org.jooq.DataType;
import org.jooq.Field;
import org.jooq.Index;
import org.jooq.Meta;
import org.jooq.Name;
import org.jooq.Name.Quoted;
import org.jooq.Query;
import org.jooq.Record;
import org.jooq.Schema;
import org.jooq.SortField;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.UniqueKey;
@ -137,6 +139,11 @@ final class DDLInterpreter {
else
// XXX log warning?
;
for (Index index : query.$indexes())
if (index instanceof IndexImpl) {
IndexImpl impl = (IndexImpl) index;
t.index(impl.getUnqualifiedName(), impl.$fields(), impl.$unique());
}
}
private final void accept0(AlterTableImpl query) {
@ -281,6 +288,7 @@ final class DDLInterpreter {
private UniqueKey<Record> primaryKey;
private List<UniqueKey<Record>> keys;
private List<Index> indexes;
MutableTable(Name name, MutableSchema schema, Comment comment) {
super(normalize(name), schema, null, null, comment);
@ -306,6 +314,13 @@ final class DDLInterpreter {
}
}
void index(Name name, SortField<?>[] indexFields, boolean unique) {
// XXX copy fields?
if (indexes == null)
indexes = new ArrayList<>();
indexes.add(Internal.createIndex(normalize(name).first(), this, indexFields, unique));
}
private final TableField<?, ?>[] copiedFields(Field<?>[] input) {
TableField<?, ?>[] result = new TableField[input.length];
for (int i = 0; i < input.length; i++)
@ -331,6 +346,11 @@ final class DDLInterpreter {
result.addAll(keys);
return Collections.unmodifiableList(result);
}
@Override
public List<Index> getIndexes() {
return indexes == null ? Collections.emptyList() : Collections.unmodifiableList(indexes);
}
}
}

View File

@ -95,6 +95,9 @@ class IndexImpl extends AbstractNamed implements Index {
this.unique = unique;
}
final SortField<?>[] $fields() { return fields; }
final boolean $unique() { return unique; }
@Override
public final void accept(Context<?> ctx) {
if (NO_SUPPORT_INDEX_QUALIFICATION.contains(ctx.family()))