Java Code Examples for com.alibaba.fastsql.sql.repository.SchemaObject

The following examples show how to use com.alibaba.fastsql.sql.repository.SchemaObject. 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: canal-1.1.3   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 2
Source Project: canal-1.1.3   Source File: MemoryTableMeta.java    License: Apache License 2.0 5 votes vote down vote up
public Map<String, String> snapshot() {
    Map<String, String> schemaDdls = new HashMap<String, String>();
    for (Schema schema : repository.getSchemas()) {
        StringBuffer data = new StringBuffer(4 * 1024);
        for (String table : schema.showTables()) {
            SchemaObject schemaObject = schema.findTable(table);
            schemaObject.getStatement().output(data);
            data.append("; \n");
        }
        schemaDdls.put(schema.getName(), data.toString());
    }

    return schemaDdls;
}
 
Example 3
Source Project: canal-1.1.3   Source File: FastsqlSchemaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() throws FileNotFoundException, IOException {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql = "create table quniya4(name varchar(255) null,value varchar(255) null,id int not null,constraint quniya4_pk primary key (id));"
                 + "alter table quniya4 modify id int not null first;";
    repository.console(sql);

    repository.setDefaultSchema("test");
    SchemaObject table = repository.findTable("quniya4");
    System.out.println(table.getStatement().toString());
}
 
Example 4
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 5
Source Project: canal   Source File: MemoryTableMeta.java    License: Apache License 2.0 5 votes vote down vote up
public Map<String, String> snapshot() {
    Map<String, String> schemaDdls = new HashMap<String, String>();
    for (Schema schema : repository.getSchemas()) {
        StringBuffer data = new StringBuffer(4 * 1024);
        for (String table : schema.showTables()) {
            SchemaObject schemaObject = schema.findTable(table);
            schemaObject.getStatement().output(data);
            data.append("; \n");
        }
        schemaDdls.put(schema.getName(), data.toString());
    }

    return schemaDdls;
}
 
Example 6
Source Project: canal   Source File: FastsqlSchemaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() throws FileNotFoundException, IOException {
    SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
    String sql = "create table quniya4(name varchar(255) null,value varchar(255) null,id int not null,constraint quniya4_pk primary key (id));"
                 + "alter table quniya4 modify id int not null first;";
    repository.console(sql);

    repository.setDefaultSchema("test");
    SchemaObject table = repository.findTable("quniya4");
    System.out.println(table.getStatement().toString());
}