当前位置: 首页>>代码示例>>Java>>正文


Java Schema.getTableNames方法代码示例

本文整理汇总了Java中org.apache.metamodel.schema.Schema.getTableNames方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.getTableNames方法的具体用法?Java Schema.getTableNames怎么用?Java Schema.getTableNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.metamodel.schema.Schema的用法示例。


在下文中一共展示了Schema.getTableNames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertToTable

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public Table convertToTable(final String schemaName, final String tableName) {
    final Schema schema;
    if (schemaName == null) {
        schema = getDefaultSchema();
    } else {
        schema = getSchemaByName(schemaName);
    }

    if (schema == null) {
        throw new IllegalArgumentException(
                "Schema " + schemaName + " not found. Available schema names are: " + dataContext.getSchemaNames());
    }

    final Table table;
    if (tableName == null) {
        if (schema.getTables().stream().filter(t -> t.getType() == TableType.TABLE).count() == 1) {
            table = schema.getTables().stream().filter(t -> t.getType() == TableType.TABLE).findFirst().get();
        } else {
            throw new IllegalArgumentException(
                    "No table name specified, and multiple options exist. Available table names are: "
                            + schema.getTableNames());
        }
    } else {
        table = schema.getTableByName(tableName);
    }

    if (table == null) {
        throw new IllegalArgumentException(
                "Table not found. Available table names are: " + schema.getTableNames());
    }

    return table;
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:34,代码来源:SchemaNavigator.java

示例2: printTables

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
private void printTables(final DataCleanerConfiguration configuration) {
    final String datastoreName = _arguments.getDatastoreName();
    final String schemaName = _arguments.getSchemaName();

    if (datastoreName == null) {
        System.err.println("You need to specify the datastore name!");
    } else {
        final Datastore ds = configuration.getDatastoreCatalog().getDatastore(datastoreName);
        if (ds == null) {
            System.err.println("No such datastore: " + datastoreName);
        } else {
            final DatastoreConnection con = ds.openConnection();
            final DataContext dc = con.getDataContext();
            final Schema schema;
            if (schemaName == null) {
                schema = dc.getDefaultSchema();
            } else {
                schema = dc.getSchemaByName(schemaName);
            }
            if (schema == null) {
                System.err.println("No such schema: " + schemaName);
            } else {
                final List<String> tableNames = schema.getTableNames();
                if (tableNames == null || tableNames.isEmpty()) {
                    System.err.println("No tables in schema!");
                } else {
                    write("Tables:");
                    write("-------");
                    for (final String tableName : tableNames) {
                        write(tableName);
                    }
                }
            }
            con.close();
        }
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:38,代码来源:CliRunner.java

示例3: printTables

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
private void printTables(AnalyzerBeansConfiguration configuration) {
    String datastoreName = _arguments.getDatastoreName();
    String schemaName = _arguments.getSchemaName();

    if (datastoreName == null) {
        System.err.println("You need to specify the datastore name!");
    } else {
        Datastore ds = configuration.getDatastoreCatalog().getDatastore(datastoreName);
        if (ds == null) {
            System.err.println("No such datastore: " + datastoreName);
        } else {
            DatastoreConnection con = ds.openConnection();
            DataContext dc = con.getDataContext();
            Schema schema;
            if (schemaName == null) {
                schema = dc.getDefaultSchema();
            } else {
                schema = dc.getSchemaByName(schemaName);
            }
            if (schema == null) {
                System.err.println("No such schema: " + schemaName);
            } else {
                String[] tableNames = schema.getTableNames();
                if (tableNames == null || tableNames.length == 0) {
                    System.err.println("No tables in schema!");
                } else {
                    write("Tables:");
                    write("-------");
                    for (String tableName : tableNames) {
                        write(tableName);
                    }
                }
            }
            con.close();
        }
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:38,代码来源:CliRunner.java

示例4: testTableDetection

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
@Test
public void testTableDetection() throws Exception {
    if (!isConfigured()) {
        System.err.println(getInvalidConfigurationMessage());
        return;
    }

    // Insert a node
    requestWrapper.executeCypherQuery("CREATE (n:JUnitLabel { property1: 1, property2: 2 })");

    // Adding a node, but deleting it afterwards - should not be included in
    // the schema as the table would be empty
    requestWrapper.executeCypherQuery("CREATE (n:JUnitLabelTemp { property1: 3, property2: 4 })");
    requestWrapper.executeCypherQuery("MATCH (n:JUnitLabelTemp) DELETE n;");

    Neo4jDataContext strategy = new Neo4jDataContext(getHostname(), getPort(), getUsername(), getPassword());
    Schema schema = strategy.getSchemaByName(strategy.getDefaultSchemaName());

    // Do not check the precise count, Neo4j keeps labels forever, there are
    // probably many more than you imagine...
    List<String> tableNames = schema.getTableNames();
    logger.info("Tables (labels) detected: " + tableNames);
    assertTrue(tableNames.contains("JUnitLabel"));
    assertFalse(tableNames.contains("JUnitLabelTemp"));

    Table table = schema.getTableByName("JUnitLabel");
    List<String> columnNames = table.getColumnNames();
    assertTrue(columnNames.contains("property1"));
    assertTrue(columnNames.contains("property2"));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:31,代码来源:Neo4jDataContextTest.java

示例5: testGetSchema

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testGetSchema() throws Exception {
    if (!isConfigured()) {
        System.err.println(getInvalidConfigurationMessage());
        return;
    }

    SalesforceDataContext dc = getSalesforceDataContext();

    Schema schema = dc.getDefaultSchema();

    assertEquals("Salesforce", schema.getName());

    List<String> tableNames = schema.getTableNames();

    System.out.println("All tables:\n" + Arrays.toString(tableNames.toArray()));

    Table accountTable = schema.getTableByName("Account");
    assertNotNull(accountTable);

    List<String> columnNames = accountTable.getColumnNames();
    System.out.println("Account table columns: " + Arrays.toString(columnNames.toArray()));

    Column idColumn = accountTable.getColumnByName("Id");
    Column nameColumn = accountTable.getColumnByName("Name");

    assertNotNull(idColumn);
    assertNotNull(nameColumn);

    assertEquals("Column[name=Id,columnNumber=0,type=VARCHAR,nullable=false,nativeType=id,columnSize=18]",
            idColumn.toString());
    assertEquals("id", idColumn.getNativeType());
    assertTrue(idColumn.isPrimaryKey());

    assertEquals("Column[name=Name,columnNumber=3,type=VARCHAR,nullable=false,nativeType=string,columnSize=255]",
            nameColumn.toString());
    assertEquals("string", nameColumn.getNativeType());
    assertFalse(nameColumn.isPrimaryKey());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:39,代码来源:SalesforceDataContextTest.java

示例6: testTableDetectionWithRelationships

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
@Test
public void testTableDetectionWithRelationships() throws Exception {
    if (!isConfigured()) {
        System.err.println(getInvalidConfigurationMessage());
        return;
    }

    // Insert nodes
    requestWrapper.executeCypherQuery("CREATE (n:JUnitPerson { name: 'Tomasz', age: 26})");
    requestWrapper.executeCypherQuery("CREATE (n:JUnitPerson { name: 'Philomeena', age: 18})");
    requestWrapper.executeCypherQuery("CREATE (n:JUnitBook { title: 'Introduction to algorithms'})");
    requestWrapper.executeCypherQuery("CREATE (n:JUnitBook { title: 'Rich Dad Poor Dad'})");
    requestWrapper.executeCypherQuery("MATCH (a:JUnitPerson),(b:JUnitBook)"
            + "WHERE a.name = 'Tomasz' AND b.title = 'Introduction to algorithms'"
            + "CREATE (a)-[r:HAS_READ { rating : 5 }]->(b)");
    requestWrapper.executeCypherQuery("MATCH (a:JUnitPerson),(b:JUnitBook)"
            + "WHERE a.name = 'Philomeena' AND b.title = 'Introduction to algorithms'"
            + "CREATE (a)-[r:HAS_BROWSED]->(b)");
    requestWrapper.executeCypherQuery("MATCH (a:JUnitPerson),(b:JUnitBook)"
            + "WHERE a.name = 'Philomeena' AND b.title = 'Introduction to algorithms'"
            + "CREATE (a)-[r:HAS_BROWSED]->(b)");
    requestWrapper.executeCypherQuery("MATCH (a:JUnitPerson),(b:JUnitBook)"
            + "WHERE a.name = 'Tomasz' AND b.title = 'Rich Dad Poor Dad'"
            + "CREATE (a)-[r:HAS_READ { rating : 4 }]->(b)");
    requestWrapper.executeCypherQuery("MATCH (a:JUnitPerson),(b:JUnitBook)"
            + "WHERE a.name = 'Philomeena' AND b.title = 'Rich Dad Poor Dad'"
            + "CREATE (a)-[r:HAS_READ { rating : 2 }]->(b)");

    Neo4jDataContext strategy = new Neo4jDataContext(getHostname(), getPort(), getUsername(), getPassword());
    Schema schema = strategy.getSchemaByName(strategy.getDefaultSchemaName());

    // Do not check the precise count, Neo4j keeps labels forever, there are
    // probably many more than you imagine...
    List<String> tableNames = schema.getTableNames();
    logger.info("Tables (labels) detected: " + tableNames);
    assertTrue(tableNames.contains("JUnitPerson"));
    assertTrue(tableNames.contains("JUnitBook"));

    Table tablePerson = schema.getTableByName("JUnitPerson");
    List<String> personColumnNames = tablePerson.getColumnNames();
    assertEquals("[_id, name, age, rel_HAS_READ, rel_HAS_READ#rating, rel_HAS_BROWSED]",
            personColumnNames.toString());

    Table tableBook = schema.getTableByName("JUnitBook");
    List<String> bookColumnNames = tableBook.getColumnNames();
    assertEquals("[_id, title]", bookColumnNames.toString());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:48,代码来源:Neo4jDataContextTest.java


注:本文中的org.apache.metamodel.schema.Schema.getTableNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。