diff --git a/jOOQ-meta/src/main/java/org/jooq/util/AbstractIndexDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/AbstractIndexDefinition.java new file mode 100644 index 0000000000..e30f8a82ee --- /dev/null +++ b/jOOQ-meta/src/main/java/org/jooq/util/AbstractIndexDefinition.java @@ -0,0 +1,95 @@ +/* + * 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.util; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Lukas Eder + */ +public abstract class AbstractIndexDefinition extends AbstractDefinition implements IndexDefinition { + + private final TableDefinition table; + private final boolean unique; + private List indexColumns; + + public AbstractIndexDefinition(SchemaDefinition schema, String name, TableDefinition table, boolean unique) { + super(schema.getDatabase(), schema, name, ""); + + this.table = table; + this.unique = unique; + } + + @Override + public List getDefinitionPath() { + List result = new ArrayList(); + + switch (getDialect().family()) { + + + + + + + default: + result.addAll(getSchema().getDefinitionPath()); + } + + result.add(this); + return result; + } + + @Override + public TableDefinition getTable() { + return table; + } + + @Override + public List getIndexColumns() { + if (indexColumns == null) { + indexColumns = getIndexColumns0(); + } + + return indexColumns; + } + + protected abstract List getIndexColumns0(); + + @Override + public boolean isUnique() { + return unique; + } +} diff --git a/jOOQ-meta/src/main/java/org/jooq/util/DefaultIndexColumnDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/DefaultIndexColumnDefinition.java new file mode 100644 index 0000000000..cf28896204 --- /dev/null +++ b/jOOQ-meta/src/main/java/org/jooq/util/DefaultIndexColumnDefinition.java @@ -0,0 +1,82 @@ +/* + * 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.util; + +import org.jooq.SortOrder; + +/** + * @author Lukas Eder + */ +public class DefaultIndexColumnDefinition + extends AbstractTypedElementDefinition + implements IndexColumnDefinition { + + private final ColumnDefinition column; + private final SortOrder sortOrder; + private final int position; + + public DefaultIndexColumnDefinition(IndexDefinition container, ColumnDefinition column, SortOrder sortOrder, int position) { + super(container, column.getInputName(), position, column.getDefinedType(), ""); + + this.column = column; + this.sortOrder = sortOrder; + this.position = position; + } + + @Override + public DataTypeDefinition getType() { + return getColumn().getType(); + } + + @Override + public DataTypeDefinition getDefinedType() { + return getColumn().getDefinedType(); + } + + @Override + public int getPosition() { + return position; + } + + @Override + public SortOrder getSortOrder() { + return sortOrder; + } + + @Override + public ColumnDefinition getColumn() { + return column; + } +} diff --git a/jOOQ-meta/src/main/java/org/jooq/util/IndexColumnDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/IndexColumnDefinition.java new file mode 100644 index 0000000000..250ec03a97 --- /dev/null +++ b/jOOQ-meta/src/main/java/org/jooq/util/IndexColumnDefinition.java @@ -0,0 +1,65 @@ +/* + * 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.util; + +import org.jooq.SortOrder; + +/** + * An interface defining a column of an index. + * + * @author Lukas Eder + */ +public interface IndexColumnDefinition extends TypedElementDefinition { + + /** + * The column position in the index. + */ + int getPosition(); + + /** + * The ASC or DESC sort order + */ + SortOrder getSortOrder(); + + /** + * The table column definition that this index column definition is backed + * by. + *

+ * This may be a virtual and/or invisible column, e.g. in case this index is + * a function-based index. + */ + ColumnDefinition getColumn(); +} diff --git a/jOOQ-meta/src/main/java/org/jooq/util/IndexDefinition.java b/jOOQ-meta/src/main/java/org/jooq/util/IndexDefinition.java new file mode 100644 index 0000000000..6996882601 --- /dev/null +++ b/jOOQ-meta/src/main/java/org/jooq/util/IndexDefinition.java @@ -0,0 +1,60 @@ +/* + * 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.util; + +import java.util.List; + +/** + * An object holding information about an index. + * + * @author Lukas Eder + */ +public interface IndexDefinition extends Definition { + + /** + * The table holding this index. + */ + TableDefinition getTable(); + + /** + * The list of columns making up the index. + */ + List getIndexColumns(); + + /** + * Whether this is a unique index. + */ + boolean isUnique(); +}