Java Code Examples for com.alibaba.fastsql.sql.ast.statement.SQLCreateTableStatement

The following examples show how to use com.alibaba.fastsql.sql.ast.statement.SQLCreateTableStatement. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Mycat2   Source File: CreateTableSQLHandler.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void makeTask(SQLCreateTableStatement ast, Map<String, Set<String>> sqlAndDatasoureMap, DataNode shardingBackend) {
    String targetName = shardingBackend.getTargetName();
    SQLCreateTableStatement entry = ast.clone();
    entry.setIfNotExiists(true);
    entry.setTableName(shardingBackend.getTable());//设置库名 表名顺序不能乱
    entry.setSchema(shardingBackend.getSchema());
    if (!shardingBackend.getTable().equals(entry.getTableName())) {
        throw new AssertionError();
    }
    if (!shardingBackend.getSchema().equals(entry.getSchema())) {
        throw new AssertionError();
    }

    String sql = entry.toString();
    Set<String> set = sqlAndDatasoureMap.computeIfAbsent(sql, s -> new HashSet<>());
    set.addAll(getDatasource(targetName));
}
 
Example 2
Source Project: canal   Source File: MemoryTableMeta.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TableMeta find(String schema, String table) {
    List<String> keys = Arrays.asList(schema, table);
    TableMeta tableMeta = tableMetas.get(keys);
    if (tableMeta == null) {
        synchronized (this) {
            tableMeta = tableMetas.get(keys);
            if (tableMeta == null) {
                Schema schemaRep = repository.findSchema(schema);
                if (schemaRep == null) {
                    return null;
                }
                SchemaObject data = schemaRep.findTable(table);
                if (data == null) {
                    return null;
                }
                SQLStatement statement = data.getStatement();
                if (statement == null) {
                    return null;
                }
                if (statement instanceof SQLCreateTableStatement) {
                    tableMeta = parse((SQLCreateTableStatement) statement);
                }
                if (tableMeta != null) {
                    if (table != null) {
                        tableMeta.setTable(table);
                    }
                    if (schema != null) {
                        tableMeta.setSchema(schema);
                    }

                    tableMetas.put(keys, tableMeta);
                }
            }
        }
    }

    return tableMeta;
}
 
Example 3
Source Project: canal   Source File: MemoryTableMeta.java    License: Apache License 2.0 5 votes vote down vote up
private TableMeta parse(SQLCreateTableStatement statement) {
    int size = statement.getTableElementList().size();
    if (size > 0) {
        TableMeta tableMeta = new TableMeta();
        for (int i = 0; i < size; ++i) {
            SQLTableElement element = statement.getTableElementList().get(i);
            processTableElement(element, tableMeta);
        }
        return tableMeta;
    }

    return null;
}