use of com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey in project dble by actiontech.
the class MetaHelper method initTableMeta.
public static StructureMeta.TableMeta initTableMeta(String table, SQLCreateTableStatement createStatement, long timeStamp) {
StructureMeta.TableMeta.Builder tmBuilder = StructureMeta.TableMeta.newBuilder();
tmBuilder.setTableName(table);
tmBuilder.setVersion(timeStamp);
Set<String> indexNames = new HashSet<>();
for (SQLTableElement tableElement : createStatement.getTableElementList()) {
if (tableElement instanceof SQLColumnDefinition) {
SQLColumnDefinition column = (SQLColumnDefinition) tableElement;
StructureMeta.ColumnMeta.Builder cmBuilder = makeColumnMeta(tmBuilder, column, indexNames);
if (cmBuilder.getAutoIncre()) {
tmBuilder.setAiColPos(tmBuilder.getColumnsCount());
}
tmBuilder.addColumns(cmBuilder.build());
} else if (tableElement instanceof MySqlPrimaryKey) {
MySqlPrimaryKey primaryKey = (MySqlPrimaryKey) tableElement;
tmBuilder.setPrimary(makeIndexMeta(PRIMARY, IndexType.PRI, primaryKey.getColumns()));
} else if (tableElement instanceof MySqlUnique) {
MySqlUnique unique = (MySqlUnique) tableElement;
String indexName = genIndexName(unique.getName(), unique.getColumns(), indexNames);
tmBuilder.addUniIndex(makeIndexMeta(indexName, IndexType.UNI, unique.getColumns()));
} else if (tableElement instanceof MySqlTableIndex) {
MySqlTableIndex index = (MySqlTableIndex) tableElement;
String indexName = genIndexName(index.getName(), index.getColumns(), indexNames);
tmBuilder.addIndex(makeIndexMeta(indexName, IndexType.MUL, index.getColumns()));
} else if (tableElement instanceof MySqlKey) {
MySqlKey index = (MySqlKey) tableElement;
String indexName = genIndexName(index.getIndexName(), index.getColumns(), indexNames);
tmBuilder.addIndex(makeIndexMeta(indexName, IndexType.MUL, index.getColumns()));
} else {
// ignore
}
}
return tmBuilder.build();
}
Aggregations