Search in sources :

Example 1 with DatabaseObject

use of com.mysql.cj.xdevapi.DatabaseObject in project aws-mysql-jdbc by awslabs.

the class SchemaTest method testListTables.

@Test
public void testListTables() {
    String collName = "test_list_tables_collection";
    String tableName = "test_list_tables_table";
    String viewName = "test_list_tables_view";
    try {
        dropCollection(collName);
        sqlUpdate("drop view if exists " + viewName);
        sqlUpdate("drop table if exists " + tableName);
        Collection coll = this.schema.createCollection(collName);
        sqlUpdate("create table " + tableName + "(name varchar(32), age int, role int)");
        sqlUpdate("create view " + viewName + " as select name, age from " + tableName);
        Table table = this.schema.getTable(tableName);
        Table view = this.schema.getTable(viewName);
        List<DatabaseObject> tables = new ArrayList<>();
        tables.addAll(this.schema.getTables());
        assertFalse(tables.contains(coll));
        assertTrue(tables.contains(table));
        assertTrue(tables.contains(view));
        tables = new ArrayList<>();
        tables.addAll(this.schema.getTables("%tables_t%"));
        assertFalse(tables.contains(coll));
        assertTrue(tables.contains(table));
        assertFalse(tables.contains(view));
    } finally {
        dropCollection(collName);
        sqlUpdate("drop view if exists " + viewName);
        sqlUpdate("drop table if exists " + tableName);
    }
}
Also used : Table(com.mysql.cj.xdevapi.Table) ArrayList(java.util.ArrayList) Collection(com.mysql.cj.xdevapi.Collection) DatabaseObject(com.mysql.cj.xdevapi.DatabaseObject) Test(org.junit.jupiter.api.Test)

Aggregations

Collection (com.mysql.cj.xdevapi.Collection)1 DatabaseObject (com.mysql.cj.xdevapi.DatabaseObject)1 Table (com.mysql.cj.xdevapi.Table)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1