use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.
the class Table method getIndexForColumn.
/**
* Get the index that has the given column as the first element. This method
* returns null if no matching index is found.
*
* @param column the column
* @return the index or null
*/
public Index getIndexForColumn(Column column) {
ArrayList<Index> indexes = getIndexes();
if (indexes != null) {
for (int i = 1, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
int idx = index.getColumnIndex(column);
if (idx == 0) {
return index;
}
}
}
return null;
}
use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.
the class Table method dropSingleColumnConstraintsAndIndexes.
/**
* Check that this column is not referenced by a multi-column constraint or
* multi-column index. If it is, an exception is thrown. Single-column
* references and indexes are dropped.
*
* @param session the session
* @param col the column
* @throws DbException if the column is referenced by multi-column
* constraints or indexes
*/
public void dropSingleColumnConstraintsAndIndexes(Session session, Column col) {
ArrayList<Index> indexesToDrop = New.arrayList();
ArrayList<Index> indexes = getIndexes();
if (indexes != null) {
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
if (index.getColumnIndex(col) < 0) {
continue;
}
if (index.getColumns().length == 1) {
indexesToDrop.add(index);
} else {
throw DbException.get(ErrorCode.COLUMN_IS_REFERENCED_1, index.getSQL());
}
}
}
for (Index i : indexesToDrop) {
// constraint
if (getIndexes().contains(i)) {
session.getDatabase().removeSchemaObject(session, i);
}
}
}
use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.
the class Table method getChildren.
@Override
public ArrayList<DbObject> getChildren() {
ArrayList<DbObject> children = New.arrayList();
ArrayList<Index> indexes = getIndexes();
if (indexes != null) {
children.addAll(indexes);
}
if (sequences != null) {
children.addAll(sequences);
}
ArrayList<Right> rights = database.getAllRights();
for (Right right : rights) {
if (right.getGrantedTable() == this) {
children.add(right);
}
}
return children;
}
use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.
the class Aggregate method getColumnIndex.
private Index getColumnIndex() {
if (on instanceof ExpressionColumn) {
ExpressionColumn col = (ExpressionColumn) on;
Column column = col.getColumn();
TableFilter filter = col.getTableFilter();
if (filter != null) {
Table table = filter.getTable();
Index index = table.getIndexForColumn(column);
return index;
}
}
return null;
}
use of com.wplatform.ddal.dbobject.index.Index in project jdbc-shards by wplatform.
the class SelectExecutor method scanLevelValidation.
private void scanLevelValidation(TableFilter filter) {
Table test = filter.getTable();
if (!(test instanceof Table)) {
return;
}
TableMate table = castTableMate(test);
table.check();
Index index = filter.getIndex();
int scanLevel = table.getScanLevel();
switch(scanLevel) {
case TableConfig.SCANLEVEL_UNLIMITED:
break;
case TableConfig.SCANLEVEL_FILTER:
if (filter.getFilterCondition() == null) {
throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "filter", "filter");
}
break;
case TableConfig.SCANLEVEL_ANYINDEX:
if (index.getIndexType().isScan()) {
throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "anyIndex", "index");
}
break;
case TableConfig.SCANLEVEL_UNIQUEINDEX:
if (!index.getIndexType().isUnique()) {
throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "uniqueIndex", "unique index");
}
break;
case TableConfig.SCANLEVEL_SHARDINGKEY:
if (!index.getIndexType().isShardingKey()) {
throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "shardingKey", "sharding key");
}
break;
default:
throw DbException.throwInternalError("error table scan level " + scanLevel);
}
}
Aggregations