[#6307] Add code generation support for indexes (including Oracle impl)
This commit is contained in:
parent
d9a917f4de
commit
8c656754de
@ -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<IndexColumnDefinition> 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<Definition> getDefinitionPath() {
|
||||
List<Definition> result = new ArrayList<Definition>();
|
||||
|
||||
switch (getDialect().family()) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
result.addAll(getSchema().getDefinitionPath());
|
||||
}
|
||||
|
||||
result.add(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDefinition getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IndexColumnDefinition> getIndexColumns() {
|
||||
if (indexColumns == null) {
|
||||
indexColumns = getIndexColumns0();
|
||||
}
|
||||
|
||||
return indexColumns;
|
||||
}
|
||||
|
||||
protected abstract List<IndexColumnDefinition> getIndexColumns0();
|
||||
|
||||
@Override
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
}
|
||||
}
|
||||
@ -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<IndexDefinition>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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<IndexDefinition> {
|
||||
|
||||
/**
|
||||
* The column position in the index.
|
||||
*/
|
||||
int getPosition();
|
||||
|
||||
/**
|
||||
* The <code>ASC</code> or <code>DESC</code> sort order
|
||||
*/
|
||||
SortOrder getSortOrder();
|
||||
|
||||
/**
|
||||
* The table column definition that this index column definition is backed
|
||||
* by.
|
||||
* <p>
|
||||
* This may be a virtual and/or invisible column, e.g. in case this index is
|
||||
* a function-based index.
|
||||
*/
|
||||
ColumnDefinition getColumn();
|
||||
}
|
||||
60
jOOQ-meta/src/main/java/org/jooq/util/IndexDefinition.java
Normal file
60
jOOQ-meta/src/main/java/org/jooq/util/IndexDefinition.java
Normal file
@ -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<IndexColumnDefinition> getIndexColumns();
|
||||
|
||||
/**
|
||||
* Whether this is a unique index.
|
||||
*/
|
||||
boolean isUnique();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user