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


Java Schema.getTable方法代码示例

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


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

示例1: testExecuteQueryBeforeLoadingSchema

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
/**
 * Tests that you can execute a query on a ExcelDataContext even though the
 * schema has not yet been (explicitly) loaded.
 */
public void testExecuteQueryBeforeLoadingSchema() throws Exception {
    // first use one DataContext to retreive the schema/table/column objects
    ExcelDataContext dc1 = new ExcelDataContext(copyOf("src/test/resources/Spreadsheet2007.xlsx"));
    Schema schema = dc1.getDefaultSchema();
    Table table = schema.getTable(0);
    Column column = table.getColumn(0);

    // query another DataContext using the schemas of the one above
    ExcelDataContext dc2 = new ExcelDataContext(copyOf("src/test/resources/Spreadsheet2007.xlsx"));
    DataSet ds = dc2.executeQuery(new Query().from(table).select(column));

    // previously we would crash at this point!

    assertNotNull(ds);
    ds.close();
}
 
开发者ID:apache,项目名称:metamodel,代码行数:21,代码来源:ExcelDataContextTest.java

示例2: testGetTextContent

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testGetTextContent() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setIgnoringComments(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(new File("src/test/resources/xml_input_simple.xml"));
    Element rootElement = document.getDocumentElement();
    Element[] childElements = XmlDomDataContext.getChildElements(rootElement);
    assertEquals("w00p", XmlDomDataContext.getTextContent(childElements[0]));
    assertNull(XmlDomDataContext.getTextContent(childElements[1]));
    assertNull(XmlDomDataContext.getTextContent(childElements[2]));
    assertNull(XmlDomDataContext.getTextContent(rootElement));

    XmlDomDataContext strategy = new XmlDomDataContext("foobarSchema", document, true);
    Schema schema = strategy.getSchemaByName("foobarSchema");
    assertEquals("Schema[name=foobarSchema]", schema.toString());
    assertEquals("[Table[name=child,type=TABLE,remarks=null]]", Arrays.toString(schema.getTables().toArray()));
    Table table = schema.getTable(0);
    assertEquals(
            "[Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=Auto-generated primary key,columnSize=null], "
                    + "Column[name=child,columnNumber=1,type=STRING,nullable=true,nativeType=XML Text,columnSize=null]]",
            Arrays.toString(table.getColumns().toArray()));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:23,代码来源:XmlDomDataContextTest.java

示例3: testGetDatastoreConnection

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testGetDatastoreConnection() throws Exception {
    final FixedWidthDatastore ds = new FixedWidthDatastore("example datastore",
            "src/test/resources/employees-fixed-width.txt", "UTF-8", 19, false, false, false);

    try (DatastoreConnection con = ds.openConnection()) {
        final Schema schema = con.getDataContext().getDefaultSchema();
        assertEquals("resources", schema.getName());

        final Table table = schema.getTable(0);
        assertEquals("employees-fixed-width.txt", table.getName());

        assertEquals("[name, email]", table.getColumnNames().toString());
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:15,代码来源:FixedWidthDatastoreTest.java

示例4: getPreviewTable

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

示例5: testErrorHandlingToTempFile

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testErrorHandlingToTempFile() throws Exception {
    final InsertIntoTableAnalyzer insertIntoTable = new InsertIntoTableAnalyzer();
    insertIntoTable.datastore = jdbcDatastore;
    insertIntoTable.tableName = "test_table";
    insertIntoTable.columnNames = new String[] { "foo", "bar" };
    insertIntoTable.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    insertIntoTable._componentContext = EasyMock.createMock(ComponentContext.class);

    final InputColumn<Object> col1 = new MockInputColumn<>("in1", Object.class);
    final InputColumn<Object> col2 = new MockInputColumn<>("in2", Object.class);

    insertIntoTable.values = new InputColumn[] { col1, col2 };

    insertIntoTable.validate();
    insertIntoTable.init();

    // a valid row
    insertIntoTable.run(new MockInputRow().put(col1, "hello world").put(col2, 123), 1);

    // null values - should be accepted
    insertIntoTable.run(new MockInputRow().put(col1, null).put(col2, null), 1);

    // invalid types, they should be automatically converted
    insertIntoTable.run(new MockInputRow().put(col1, 123).put(col2, "123"), 1);

    // invalid and unconvertable types!
    insertIntoTable.run(new MockInputRow().put(col2, "hey I am a string in a number field"), 1);

    // another valid row (after the failing one)
    insertIntoTable.run(new MockInputRow().put(col1, "foo bar").put(col2, 3123), 1);

    final WriteDataResult result = insertIntoTable.getResult();

    // assertions about succes rows
    assertEquals(4, result.getWrittenRowCount());
    assertEquals(jdbcDatastore, result.getDatastore(null));
    final Table table = result.getPreviewTable(jdbcDatastore);
    assertEquals("TEST_TABLE", table.getName());

    // make assertions about error rows
    assertEquals(1, result.getErrorRowCount());
    final FileDatastore errorDatastore = result.getErrorDatastore();
    assertNotNull(errorDatastore);

    final DatastoreConnection errorCon = errorDatastore.openConnection();
    final Schema errorSchema = errorCon.getDataContext().getDefaultSchema();
    assertEquals(1, errorSchema.getTables().stream().filter(t -> t.getType() == TableType.TABLE).count());
    final Table errorTable = errorSchema.getTable(0);
    assertEquals("[foo, bar, insert_into_table_error_message]", errorTable.getColumnNames().toString());
    final DataSet ds = errorCon.getDataContext().query().from(errorTable).select("foo").and("bar")
            .and("insert_into_table_error_message").execute();
    assertTrue(ds.next());
    assertEquals("Row[values=[, hey I am a string in a number field, "
            + "Could not convert hey I am a string in a number field to number]]", ds.getRow().toString());
    assertFalse(ds.next());
    errorCon.close();

    final String filename = errorDatastore.getFilename();
    assertEquals("4 inserts executed\n" + " - WARNING! 1 record failed, written to file: " + filename,
            result.toString());
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:62,代码来源:InsertIntoTableAnalyzerTest.java

示例6: testUpdateCSV

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testUpdateCSV() throws Exception {
    final File file = new File("target/example_updated.csv");
    FileHelper.copy(new File("src/test/resources/example_updated.csv"), file);

    final CsvDatastore datastore = new CsvDatastore("example", file.getPath(), null, ',', "UTF8");
    final UpdateableDatastoreConnection connection = datastore.openConnection();
    final DataContext dataContext = connection.getDataContext();
    final Schema schema = dataContext.getDefaultSchema();
    final Table table = schema.getTable(0);

    final UpdateTableAnalyzer updateTableAnalyzer = new UpdateTableAnalyzer();
    updateTableAnalyzer.datastore = datastore;
    updateTableAnalyzer.schemaName = schema.getName();
    updateTableAnalyzer.tableName = table.getName();
    updateTableAnalyzer.columnNames = new String[] { "name" };
    updateTableAnalyzer.conditionColumnNames = new String[] { "id" };
    updateTableAnalyzer.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    updateTableAnalyzer._componentContext = EasyMock.createMock(ComponentContext.class);

    final InputColumn<Object> inputId = new MockInputColumn<>("id", Object.class);
    final InputColumn<Object> inputNewName = new MockInputColumn<>("new_name", Object.class);
    updateTableAnalyzer.values = new InputColumn[] { inputNewName };
    updateTableAnalyzer.conditionValues = new InputColumn[] { inputId };

    updateTableAnalyzer.validate();
    updateTableAnalyzer.init();

    updateTableAnalyzer.run(new MockInputRow().put(inputId, 1).put(inputNewName, "foo"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, "2").put(inputNewName, "bar"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, 3).put(inputNewName, "baz"), 1);

    final WriteDataResult result = updateTableAnalyzer.getResult();
    assertEquals(0, result.getErrorRowCount());
    assertEquals(0, result.getWrittenRowCount());
    assertEquals(3, result.getUpdatesCount());

    final DataSet dataSet = dataContext.query().from(table).select("id", "name").execute();
    assertTrue(dataSet.next());
    assertEquals("Row[values=[4, hans]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[5, manuel]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[6, ankit]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[1, foo]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[2, bar]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[3, baz]]", dataSet.getRow().toString());
    assertFalse(dataSet.next());

    connection.close();
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:54,代码来源:UpdateTableAnalyzerTest.java

示例7: testUpdateCSV

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testUpdateCSV() throws Exception {
    final File file = new File("target/example_updated.csv");
    FileHelper.copy(new File("src/test/resources/example_updated.csv"), file);

    final CsvDatastore datastore = new CsvDatastore("example", file.getPath(), null, ',', "UTF8");
    final UpdateableDatastoreConnection connection = datastore.openConnection();
    final DataContext dataContext = connection.getDataContext();
    final Schema schema = dataContext.getDefaultSchema();
    final Table table = schema.getTable(0);

    final UpdateTableAnalyzer updateTableAnalyzer = new UpdateTableAnalyzer();
    updateTableAnalyzer.datastore = datastore;
    updateTableAnalyzer.schemaName = schema.getName();
    updateTableAnalyzer.tableName = table.getName();
    updateTableAnalyzer.columnNames = new String[] { "name" };
    updateTableAnalyzer.conditionColumnNames = new String[] { "id" };
    updateTableAnalyzer.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    updateTableAnalyzer._componentContext = EasyMock.createMock(ComponentContext.class);

    InputColumn<Object> inputId = new MockInputColumn<Object>("id", Object.class);
    InputColumn<Object> inputNewName = new MockInputColumn<Object>("new_name", Object.class);
    updateTableAnalyzer.values = new InputColumn[] { inputNewName };
    updateTableAnalyzer.conditionValues = new InputColumn[] { inputId };

    updateTableAnalyzer.validate();
    updateTableAnalyzer.init();

    updateTableAnalyzer.run(new MockInputRow().put(inputId, 1).put(inputNewName, "foo"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, "2").put(inputNewName, "bar"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, 3).put(inputNewName, "baz"), 1);

    WriteDataResult result = updateTableAnalyzer.getResult();
    assertEquals(0, result.getErrorRowCount());
    assertEquals(0, result.getWrittenRowCount());
    assertEquals(3, result.getUpdatesCount());

    DataSet dataSet = dataContext.query().from(table).select("id", "name").execute();
    assertTrue(dataSet.next());
    assertEquals("Row[values=[4, hans]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[5, manuel]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[6, ankit]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[1, foo]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[2, bar]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[3, baz]]", dataSet.getRow().toString());
    assertFalse(dataSet.next());

    connection.close();
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:54,代码来源:UpdateTableAnalyzerTest.java

示例8: testJoinSameTableNames

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testJoinSameTableNames() throws Exception {
	DataContext dc1 = new MockDataContext("schema", "table", "dc1");
	DataContext dc2 = new MockDataContext("schema", "table", "dc2");

	DataContext composite = new CompositeDataContext(dc1, dc2);

	assertEquals("[schema]",
			Arrays.toString(composite.getSchemaNames().toArray()));

	Schema schema = composite.getDefaultSchema();
	assertEquals(4, schema.getTableCount());
	assertEquals("[table, an_empty_table, table, an_empty_table]", Arrays.toString(schema.getTableNames().toArray()));
	assertTrue(schema instanceof CompositeSchema);
       Table table1 = schema.getTable(0);
       Table table2 = schema.getTable(2);
       assertNotSame(table1, table2);

	Query q = composite
			.query()
			.from(table1)
			.leftJoin(table2)
			.on(table1.getColumnByName("foo"),
					table2.getColumnByName("foo"))
			.select(table1.getColumnByName("foo"),
					table2.getColumnByName("foo"),
					table1.getColumnByName("bar"),
					table2.getColumnByName("baz")).toQuery();
	assertEquals(
			"SELECT table.foo, table.foo, table.bar, table.baz "
					+ "FROM schema.table LEFT JOIN schema.table ON table.foo = table.foo",
			q.toSql());

	DataSet ds = composite.executeQuery(q);
	assertTrue(ds.next());
	assertEquals("Row[values=[1, 1, hello, world]]", ds.getRow().toString());
	assertTrue(ds.next());
	assertEquals("Row[values=[2, 2, dc1, world]]", ds.getRow().toString());
	assertTrue(ds.next());
	assertEquals("Row[values=[3, 3, hi, dc2]]", ds.getRow().toString());
	assertTrue(ds.next());
	assertEquals("Row[values=[4, 4, yo, world]]", ds.getRow().toString());
	assertFalse(ds.next());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:44,代码来源:CompositeDataContextTest.java


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