/** * Create an array of index columns from a list of columns. The default sort * type is used. * * @param columns the column list * @return the index column array */ public static IndexColumn[] wrap(Column[] columns) { IndexColumn[] list = new IndexColumn[columns.length]; for (int i = 0; i < list.length; i++) { list[i] = new IndexColumn(); list[i].column = columns[i]; } return list; }
private Index addIndex(String name, ArrayList<Column> list, IndexType indexType) { Column[] cols = new Column[list.size()]; list.toArray(cols); Index index = new Index(this, name, IndexColumn.wrap(cols), indexType); indexes.add(index); return index; }
@Override protected void doPrepare() { String tableName = prepared.getTableName(); String indexName = prepared.getIndexName(); TableMate table = getTableMate(tableName); IndexColumn.mapColumns(prepared.getIndexColumns(), table); RoutingResult rr = routingHandler.doRoute(table); ObjectNode[] selectNodes = rr.getSelectNodes(); workers = New.arrayList(selectNodes.length); for (ObjectNode tableNode : selectNodes) { ObjectNode indexNode = new ObjectNode(tableNode.getShardName(), tableNode.getCatalog(), tableNode.getSchema(), indexName, tableNode.getSuffix()); UpdateWorker worker = queryHandlerFactory.createUpdateWorker(prepared, indexNode, tableNode); workers.add(worker); } }
private IndexColumn[] parseIndexColumnList() { ArrayList<IndexColumn> columns = New.arrayList(); do { IndexColumn column = new IndexColumn(); column.columnName = readColumnIdentifier(); columns.add(column); if (readIf("ASC")) { // ignore } else if (readIf("DESC")) { column.sortType = SortOrder.DESCENDING; } if (readIf("NULLS")) { if (readIf("FIRST")) { column.sortType |= SortOrder.NULLS_FIRST; } else { read("LAST"); column.sortType |= SortOrder.NULLS_LAST; } } } while (readIf(",")); read(")"); return columns.toArray(new IndexColumn[columns.size()]); }
@Override public ArrayList<Index> getIndexes() { ArrayList<Index> list = New.arrayList(1); list.add(new Index(this, null, IndexColumn.wrap(columns), IndexType.createScan())); return list; }
if (column.isAutoIncrement() && column.isPrimaryKey()) { column.setPrimaryKey(false); IndexColumn[] cols = {new IndexColumn()}; cols[0].columnName = column.getName(); AlterTableAddConstraint pk = new AlterTableAddConstraint( read("KEY"); boolean hash = readIf("HASH"); IndexColumn[] cols = {new IndexColumn()}; cols[0].columnName = column.getName(); AlterTableAddConstraint pk = new AlterTableAddConstraint( unique.setConstraintName(constraintName); unique.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_UNIQUE); IndexColumn[] cols = {new IndexColumn()}; cols[0].columnName = columnName; unique.setIndexColumns(cols); ref.setConstraintName(constraintName); ref.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL); IndexColumn[] cols = {new IndexColumn()}; cols[0].columnName = columnName; ref.setIndexColumns(cols);