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


Java DataContext.getDefaultSchema方法代码示例

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


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

示例1: testConvertTableDefs

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testConvertTableDefs() throws Exception {
    final DataContextFactoryBean factoryBean = new DataContextFactoryBean();
    factoryBean.setType("POJO");
    factoryBean.setDatabaseName("my db");
    factoryBean.setTableDefinitions("hello world (greeting VARCHAR, who VARCHAR); foo (bar INTEGER, baz DATE);");

    final DataContext dataContext = factoryBean.getObject();
    assertTrue(dataContext instanceof PojoDataContext);

    Schema schema = dataContext.getDefaultSchema();
    assertEquals("my db", schema.getName());
    assertEquals("[foo, hello world]", Arrays.toString(schema.getTableNames().toArray()));

    assertEquals(
            "[Column[name=greeting,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                    + "Column[name=who,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
            Arrays.toString(schema.getTableByName("hello world").getColumns().toArray()));

    assertEquals("[Column[name=bar,columnNumber=0,type=INTEGER,nullable=true,nativeType=null,columnSize=null], "
            + "Column[name=baz,columnNumber=1,type=DATE,nullable=true,nativeType=null,columnSize=null]]",
            Arrays.toString(schema.getTableByName("foo").getColumns().toArray()));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:23,代码来源:PojoDataContextFactoryBeanDelegateTest.java

示例2: testMissingValues

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testMissingValues() throws Exception {
    File file = copyOf("src/test/resources/xls_missing_values.xls");
    DataContext dc = new ExcelDataContext(file);
    Schema schema = dc.getDefaultSchema();
    assertEquals(2, schema.getTableCount());

    Table table = schema.getTables().get(0);
    assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
            + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
            + "Column[name=c,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
            + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
            Arrays.toString(table.getColumns().toArray()));

    Query q = new Query().select(table.getColumns()).from(table);
    DataSet ds = dc.executeQuery(q);
    assertTrue(ds.next());
    assertEquals("[1, 2, 3, null]", Arrays.toString(ds.getRow().getValues()));
    assertTrue(ds.next());
    assertEquals("[5, null, 7, 8]", Arrays.toString(ds.getRow().getValues()));
    assertTrue(ds.next());
    assertEquals("[9, 10, 11, 12]", Arrays.toString(ds.getRow().getValues()));
    assertFalse(ds.next());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:24,代码来源:ExcelDataContextTest.java

示例3: testMissingColumnHeader

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testMissingColumnHeader() throws Exception {
    File file = copyOf("src/test/resources/xls_missing_column_header.xls");
    DataContext dc = new ExcelDataContext(file);
    Schema schema = dc.getDefaultSchema();
    assertEquals(2, schema.getTableCount());

    Table table = schema.getTables().get(0);
    assertEquals("[Column[name=a,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
            + "Column[name=b,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
            + "Column[name=A,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
            + "Column[name=d,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
            Arrays.toString(table.getColumns().toArray()));

    Query q = new Query().select(table.getColumns()).from(table);
    DataSet ds = dc.executeQuery(q);
    assertTrue(ds.next());
    assertEquals("[1, 2, 3, 4]", Arrays.toString(ds.getRow().getValues()));
    assertTrue(ds.next());
    assertEquals("[5, 6, 7, 8]", Arrays.toString(ds.getRow().getValues()));
    assertTrue(ds.next());
    assertEquals("[9, 10, 11, 12]", Arrays.toString(ds.getRow().getValues()));
    assertFalse(ds.next());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:24,代码来源:ExcelDataContextTest.java

示例4: testTicket99defect

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testTicket99defect() throws Exception {
    File file = copyOf("src/test/resources/ticket_199_inventory.xls");
    DataContext dc = new ExcelDataContext(file);
    Schema schema = dc.getDefaultSchema();
    assertEquals(
            "[Table[name=Sheet1,type=TABLE,remarks=null], Table[name=Sheet2,type=TABLE,remarks=null], Table[name=Sheet3,type=TABLE,remarks=null]]",
            Arrays.toString(schema.getTables().toArray()));

    assertEquals(0, schema.getTableByName("Sheet2").getColumnCount());
    assertEquals(0, schema.getTableByName("Sheet3").getColumnCount());

    Table table = schema.getTableByName("Sheet1");
    assertEquals(

            "[Column[name=Pkg No.,columnNumber=0,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                    + "Column[name=Description,columnNumber=1,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                    + "Column[name=Room,columnNumber=2,type=VARCHAR,nullable=true,nativeType=null,columnSize=null], "
                    + "Column[name=Level,columnNumber=3,type=VARCHAR,nullable=true,nativeType=null,columnSize=null]]",
            Arrays.toString(table.getColumns().toArray()));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:21,代码来源:ExcelDataContextTest.java

示例5: testToSerializableForm

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testToSerializableForm() throws Exception {
	Connection connection = getTestDbConnection();
	DataContext dataContext = new JdbcDataContext(connection);
	Schema schema = dataContext.getDefaultSchema();
	schema = ((JdbcSchema) schema).toSerializableForm();
	connection.close();

	Table table = schema.getTableByName("CUSTOMERS");
	assertEquals(
			"[CUSTOMERNUMBER, CUSTOMERNAME, CONTACTLASTNAME, CONTACTFIRSTNAME, PHONE, ADDRESSLINE1, ADDRESSLINE2, CITY, STATE, POSTALCODE, COUNTRY, SALESREPEMPLOYEENUMBER, CREDITLIMIT]",
			Arrays.toString(table.getColumnNames().toArray()));

	assertEquals(
			"[Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]]",
			Arrays.toString(schema.getRelationships().toArray()));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:17,代码来源:JdbcSchemaTest.java

示例6: testGetSchemaNames

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testGetSchemaNames() throws Exception {
    if (!isConfigured()) {
        return;
    }
    DataContext dc = new JdbcDataContext(getConnection());
    String[] schemaNames = dc.getSchemaNames().toArray(new String[dc.getSchemas().size()]);

    String concatSchemas = Arrays.toString(schemaNames);

    // In order to allow the database to be used for other purposes than
    // this integration test, we will not make an exact assertion as to
    // which schema names exist, but just assert that HR and the default
    // oracle schemas exist.
    assertTrue(concatSchemas.indexOf("foobar_schema_that_does_not_exist") == -1);
    assertTrue(concatSchemas.indexOf("HR") != -1);
    assertTrue(concatSchemas.indexOf("SYSTEM") != -1);
    assertTrue(concatSchemas.indexOf("XDB") != -1);
    assertTrue(schemaNames.length > 8);

    Schema schema = dc.getDefaultSchema();
    assertEquals("HR", schema.getName());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:23,代码来源:OracleTest.java

示例7: testSplitJoinQuery

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testSplitJoinQuery() throws Exception {
	Connection con = getTestDbConnection();
	DataContext dc = new JdbcDataContext(con);
	Schema schema = dc.getDefaultSchema();
	Table productsTable = schema.getTableByName("PRODUCTS");
	Relationship relationship = productsTable.getRelationships().iterator().next();
	assertEquals(
			"Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]",
			relationship.toString());

	Query q = new Query().from(new FromItem(JoinType.LEFT, relationship))
			.select(relationship.getForeignColumns())
			.select(relationship.getPrimaryColumns());
	assertEquals(
			"SELECT _ORDERFACT_._PRODUCTCODE_, _PRODUCTS_._PRODUCTCODE_ FROM PUBLIC._PRODUCTS_ LEFT JOIN PUBLIC._ORDERFACT_ ON _PRODUCTS_._PRODUCTCODE_ = _ORDERFACT_._PRODUCTCODE_",
			q.toString().replace('\"', '_'));

	QuerySplitter qs = new QuerySplitter(dc, q);
	assertEquals(2997, qs.getRowCount());

	List<Query> splitQueries = qs.setMaxRows(1500).splitQuery();
	assertSameCount(dc, qs, splitQueries);
	assertEquals(3, splitQueries.size());
	assertEquals("[1415, 902, 680]",
			Arrays.toString(getCounts(dc, splitQueries)));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:27,代码来源:QuerySplitterTest.java

示例8: testAutoflattenTicket229

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testAutoflattenTicket229() throws Exception {
    DataContext dc = new XmlDomDataContext(new File("src/test/resources/xml_input_ticket_229.xml"));
    Schema schema = dc.getDefaultSchema();
    assertNotNull(schema);

    assertEquals("[VirtualBox, Machine, Machine_ExtraData_ExtraDataItem, Machine_Hardware_Boot_Order, "
            + "Machine_Hardware_Display, Machine_Hardware_RemoteDisplay, Machine_Hardware_BIOS_Logo, "
            + "Machine_Hardware_DVDDrive, Machine_Hardware_USBController, Machine_Hardware_SATAController, "
            + "Machine_Hardware_Network_Adapter, Machine_Hardware_UART_Port, Machine_Hardware_LPT_Port, "
            + "Machine_Hardware_AudioAdapter, Machine_Hardware_SharedFolders_SharedFolder, "
            + "Machine_Hardware_Guest, Machine_HardDiskAttachments_HardDiskAttachment]",
            Arrays.toString(schema.getTableNames().toArray()));
    assertEquals(
            "[id, OSType, lastStateChange, name, uuid, enabled, enabled, RAMSize, enabled, enabled, mode, value, "
                    + "enabled, type, enabled, mode]",
            Arrays.toString(schema.getTableByName("Machine").getColumnNames().toArray()));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:18,代码来源:XmlDomDataContextTest.java

示例9: testGetFromInputStream

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testGetFromInputStream() throws Exception {
    DataContext dc = null;

    // repeat this step a few times to test temp-file creation, see Ticket
    // #437
    for (int i = 0; i < 5; i++) {
        File file = new File("src/test/resources/tickets.csv");
        FileInputStream inputStream = new FileInputStream(file);
        dc = new CsvDataContext(inputStream, new CsvConfiguration());
    }

    Schema schema = dc.getDefaultSchema();
    String name = schema.getTable(0).getName();
    assertTrue(name.startsWith("metamodel"));
    assertTrue(name.endsWith("csv"));

    // Test two seperate reads to ensure that the temp file is working
    // properly and persistent.
    doTicketFileTests(dc);
    doTicketFileTests(dc);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:22,代码来源:CsvDataContextTest.java

示例10: put

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.PUT)
@ResponseBody
public GetDatasourceResponse put(@PathVariable("tenant") String tenantId,
        @PathVariable("datasource") String dataSourceId,
        @RequestParam(value = "validate", required = false) Boolean validate,
        @Valid @RequestBody RestDataSourceDefinition dataSourceDefinition) {

    final Map<String, Object> map = new HashMap<>();
    map.putAll(dataSourceDefinition.getProperties());
    map.put(DataContextPropertiesImpl.PROPERTY_DATA_CONTEXT_TYPE, dataSourceDefinition.getType());

    final DataContextProperties properties = new DataContextPropertiesImpl(map);

    final DataSourceRegistry dataSourceRegistry = tenantRegistry.getTenantContext(tenantId).getDataSourceRegistry();
    if (validate != null && validate.booleanValue()) {
        // validate the data source by opening it and ensuring that a basic call such as getDefaultSchema() works.
        try {
            final DataContext dataContext = dataSourceRegistry.openDataContext(properties);
            dataContext.getDefaultSchema();
        } catch (Exception e) {
            logger.warn("Failed validation for PUT datasource '{}/{}'", tenantId, dataSourceId, e);
            throw new InvalidDataSourceException(e);
        }
    }

    final String dataSourceIdentifier = dataSourceRegistry.registerDataSource(dataSourceId, properties);

    logger.info("{}/{} - Created data source", tenantId, dataSourceIdentifier);

    return get(tenantId, dataSourceIdentifier);
}
 
开发者ID:apache,项目名称:metamodel-membrane,代码行数:32,代码来源:DataSourceController.java

示例11: getPreviewTable

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
protected Table getPreviewTable(final DataContext dc) {
    final Schema schema = dc.getDefaultSchema();
    if (schema.getTableCount() == 0) {
        return null;
    }
    return schema.getTable(0);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:8,代码来源:AbstractResourceBasedDatastoreDialog.java

示例12: printTables

import org.apache.metamodel.DataContext; //导入方法依赖的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

示例13: printTables

import org.apache.metamodel.DataContext; //导入方法依赖的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

示例14: testGetDefaultSchema

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testGetDefaultSchema() throws Exception {
    Connection con = getTestDbConnection();
    DataContext dc = new JdbcDataContext(con);
    Schema schema = dc.getDefaultSchema();
    assertEquals("PUBLIC", schema.getName());
    con.close();
}
 
开发者ID:apache,项目名称:metamodel,代码行数:8,代码来源:JdbcDataContextTest.java

示例15: testQualifiedLabel

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testQualifiedLabel() throws Exception {
    DataContext dc = new JdbcDataContext(_connection);
    Schema schema = dc.getDefaultSchema();
    Table wikiTable = schema.getTableByName("WIKI");
    assertEquals("wiki", wikiTable.getQualifiedLabel());
    Column nameColumn = wikiTable.getColumnByName("name");
    assertEquals("wiki.name", nameColumn.getQualifiedLabel());

    assertEquals(
            "Column[name=name,columnNumber=0,type=VARCHAR,nullable=true,nativeType=TEXT,columnSize=2000000000]",
            dc.getColumnByQualifiedLabel("wiki.name").toString());
    assertEquals("Table[name=wiki,type=TABLE,remarks=null]", dc.getTableByQualifiedLabel("WIKI").toString());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:14,代码来源:SqliteTest.java


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