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


Java Schema.getTableByName方法代码示例

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


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

示例1: getTable

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
private static Table getTable(final UpdateableDataContext dataContext, final String sheetName,
        final String[] columnNames) {
    final Schema schema = dataContext.getDefaultSchema();
    Table table = schema.getTableByName(sheetName);
    if (table == null) {
        final MutableRef<Table> tableRef = new MutableRef<>();
        dataContext.executeUpdate(callback -> {
            final TableCreationBuilder tableBuilder = callback.createTable(schema, sheetName);
            for (final String columnName : columnNames) {
                tableBuilder.withColumn(columnName);
            }
            tableRef.set(tableBuilder.execute());
        });
        table = tableRef.get();
    }
    return table;
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:18,代码来源:ExcelOutputWriterFactory.java

示例2: resolveForeignColumn

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public Column resolveForeignColumn(final DatastoreCatalog datastoreCatalog) {
    final Datastore datastore = datastoreCatalog.getDatastore(getForeignDatastoreName());
    if (datastore == null) {
        return null;
    }
    try (DatastoreConnection connection = datastore.openConnection()) {
        final DataContext dataContext = connection.getDataContext();
        final Schema schema = dataContext.getSchemaByName(getForeignSchemaName());
        if (schema == null) {
            return null;
        }
        final Table table = schema.getTableByName(getForeignTableName());
        if (table == null) {
            return null;
        }
        return table.getColumnByName(getForeignColumnName());
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:19,代码来源:ForeignKey.java

示例3: testConnectAndExplore

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testConnectAndExplore() throws Exception {
    final SasDatastore ds = new SasDatastore("my sas ds", new File("src/test/resources/sas"));
    try (DatastoreConnection con = ds.openConnection()) {
        final Schema schema = con.getSchemaNavigator().getDefaultSchema();
        assertEquals("[dummy1, dummy2, pizza]", schema.getTableNames().toString());

        final Table table = schema.getTableByName("pizza");
        assertEquals("[id, mois, prot, fat, ash, sodium, carb, cal, brand]",
                table.getColumnNames().toString());

        final Column col = table.getColumnByName("brand");

        final Query q = con.getDataContext().query().from(table).select(col).orderBy(col).toQuery();
        q.getSelectClause().setDistinct(true);

        final List<Object[]> objectArrays = con.getDataContext().executeQuery(q).toObjectArrays();
        assertEquals(10, objectArrays.size());
        assertEquals("a", objectArrays.get(0)[0]);
        assertEquals("b", objectArrays.get(1)[0]);
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:22,代码来源:SasDatastoreTest.java

示例4: resolveForeignColumn

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public Column resolveForeignColumn(DatastoreCatalog datastoreCatalog) {
    Datastore datastore = datastoreCatalog.getDatastore(getForeignDatastoreName());
    if (datastore == null) {
        return null;
    }
    try (DatastoreConnection connection = datastore.openConnection()) {
        DataContext dataContext = connection.getDataContext();
        Schema schema = dataContext.getSchemaByName(getForeignSchemaName());
        if (schema == null) {
            return null;
        }
        Table table = schema.getTableByName(getForeignTableName());
        if (table == null) {
            return null;
        }
        Column column = table.getColumnByName(getForeignColumnName());
        return column;
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:20,代码来源:ForeignKey.java

示例5: testConnectAndExplore

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testConnectAndExplore() throws Exception {
    final SasDatastore ds = new SasDatastore("my sas ds", new File("src/test/resources/sas"));
    try (final DatastoreConnection con = ds.openConnection()) {
        Schema schema = con.getSchemaNavigator().getDefaultSchema();
        assertEquals("[dummy1, dummy2, pizza]", Arrays.toString(schema.getTableNames()));

        Table table = schema.getTableByName("pizza");
        assertEquals("[id, mois, prot, fat, ash, sodium, carb, cal, brand]",
                Arrays.toString(table.getColumnNames()));

        Column col = table.getColumnByName("brand");

        Query q = con.getDataContext().query().from(table).select(col).orderBy(col).toQuery();
        q.getSelectClause().setDistinct(true);

        List<Object[]> objectArrays = con.getDataContext().executeQuery(q).toObjectArrays();
        assertEquals(10, objectArrays.size());
        assertEquals("a", objectArrays.get(0)[0]);
        assertEquals("b", objectArrays.get(1)[0]);
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:22,代码来源:SasDatastoreTest.java

示例6: testQueryUppercaseTable

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testQueryUppercaseTable() throws Exception {
	Schema schema = _dataContext.getDefaultSchema();
	Table contributorsTable = schema.getTableByName("CONTRIBUTORS");

	Query q = new Query().from(contributorsTable).select(
			contributorsTable.getColumns());

	assertEquals(
			"SELECT \"CONTRIBUTORS\".\"ID\", \"CONTRIBUTORS\".\"USERNAME\", \"CONTRIBUTORS\".\"ROLE\", \"CONTRIBUTORS\".\"COUNTRY\" FROM PUBLIC.\"CONTRIBUTORS\"",
			q.toString());

	DataSet data = _dataContext.executeQuery(q);
	TableModel tableModel = new DataSetTableModel(data);
	assertEquals(4, tableModel.getColumnCount());
	assertEquals(4, tableModel.getRowCount());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:17,代码来源:OpenOfficeDataContextTest.java

示例7: testToSerializableForm

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

示例8: testDeleteAll

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
@Test
public void testDeleteAll() throws Exception {
    final Schema schema = dataContext.getDefaultSchema();
    final CreateTable createTable = new CreateTable(schema, "testCreateTable");
    createTable.withColumn("foo").ofType(ColumnType.STRING);
    createTable.withColumn("bar").ofType(ColumnType.NUMBER);
    dataContext.executeUpdate(createTable);

    final Table table = schema.getTableByName("testCreateTable");

    dataContext.executeUpdate(new UpdateScript() {
        @Override
        public void run(UpdateCallback callback) {
            callback.insertInto(table).value("foo", "hello").value("bar", 42).execute();
            callback.insertInto(table).value("foo", "world").value("bar", 43).execute();
        }
    });

    dataContext.executeUpdate(new DeleteFrom(table));

    Row row = MetaModelHelper.executeSingleRowQuery(dataContext, dataContext.query().from(table).selectCount()
            .toQuery());
    assertEquals("Count is wrong", 0, ((Number) row.getValue(0)).intValue());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:25,代码来源:ElasticSearchRestDataContextIT.java

示例9: testMaxRowsOnly

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testMaxRowsOnly() throws Exception {
    if (!isConfigured()) {
        return;
    }
    JdbcDataContext dc = new JdbcDataContext(getConnection());
    Schema schema = dc.getDefaultSchema();
    System.out.println("Tables: " + Arrays.toString(schema.getTableNames().toArray()));

    Table countryTable = schema.getTableByName("COUNTRY");
    assertNotNull(countryTable);

    Query query = dc.query().from(countryTable).select("COUNTRYCODE").limit(200).toQuery();
    assertEquals("SELECT DB2INST1.\"COUNTRY\".\"COUNTRYCODE\" FROM DB2INST1.\"COUNTRY\" "
            + "FETCH FIRST 200 ROWS ONLY", dc.getQueryRewriter().rewriteQuery(query));

    DataSet ds = dc.executeQuery(query);
    for (int i = 0; i < 200; i++) {
        assertTrue(ds.next());
        assertEquals(1, ds.getRow().getValues().length);
    }
    assertFalse(ds.next());
    ds.close();
}
 
开发者ID:apache,项目名称:metamodel,代码行数:24,代码来源:DB2Test.java

示例10: testExecuteQuery

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testExecuteQuery() throws Exception {
    JdbcDataContext dc = new JdbcDataContext(_connection);
    Schema schema = dc.getDefaultSchema();
    Table productsTable = schema.getTableByName("PRODUCTS");
    Table factTable = schema.getTableByName("ORDERFACT");

    Query q = new Query().from(new FromItem(JoinType.INNER, productsTable.getRelationships(factTable).iterator().next())).select(
            productsTable.getColumns().get(0), factTable.getColumns().get(0));

    assertEquals(
            "SELECT \"PRODUCTS\".\"PRODUCTCODE\", \"ORDERFACT\".\"ORDERNUMBER\" FROM PUBLIC.\"PRODUCTS\" INNER JOIN PUBLIC.\"ORDERFACT\" ON \"PRODUCTS\".\"PRODUCTCODE\" = \"ORDERFACT\".\"PRODUCTCODE\"",
            q.toString());
    assertEquals(25000, dc.getFetchSizeCalculator().getFetchSize(q));

    DataSet data = dc.executeQuery(q);
    TableModel tableModel = new DataSetTableModel(data);
    assertEquals(2, tableModel.getColumnCount());
    assertEquals(2996, tableModel.getRowCount());

    assertEquals(110,
            MetaModelHelper.executeSingleRowQuery(dc, new Query().selectCount().from(productsTable)).getValue(0));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:23,代码来源:HsqldbTest.java

示例11: 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

示例12: testExploreSchema

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testExploreSchema() throws Exception {
	assertEquals("[information_schema, report.dbf]",
			dc.getSchemaNames().toString());

	Schema schema = dc.getSchemaByName("report.dbf");
	assertEquals("[Table[name=report,type=TABLE,remarks=null]]",
			schema.getTables().toString());

	Table table = schema.getTableByName("report");
	assertEquals(
			"[R_INST, R_NAME, R_TITLE, R_SUBTIT, CUS_CORP, CUS_NAME, CUS_TITL, CUS_SALU, CUS_AD1, CUS_AD2, CUS_AD3, CUS_CTY, CUS_ST, CUS_COU, CUS_ZIP, CUS_PHON, CUS_FAX, CUS_OPHN, CUS_EMAI, AUT_CORP, AUT_NAME, AUT_TITL, AUT_SALU, AUT_AD1, AUT_AD2, AUT_AD3, AUT_CTY, AUT_ST, AUT_COU, AUT_ZIP, AUT_PHON, AUT_FAX, AUT_OPHN, AUT_EMAI]",
			table.getColumnNames().toString());

	List<Column> columns = table.getColumnsOfType(ColumnType.VARCHAR);
	assertEquals("[]", columns.toString());

	columns = table.getColumnsOfType(ColumnType.CHAR);
	assertEquals(
			"[Column[name=R_INST,columnNumber=0,type=CHAR,nullable=null,nativeType=C,columnSize=4], Column[name=R_NAME,columnNumber=1,type=CHAR,nullable=null,nativeType=C,columnSize=22], Column[name=R_TITLE,columnNumber=2,type=CHAR,nullable=null,nativeType=C,columnSize=255], Column[name=R_SUBTIT,columnNumber=3,type=CHAR,nullable=null,nativeType=C,columnSize=64], Column[name=CUS_CORP,columnNumber=4,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=CUS_NAME,columnNumber=5,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=CUS_TITL,columnNumber=6,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=CUS_SALU,columnNumber=7,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=CUS_AD1,columnNumber=8,type=CHAR,nullable=null,nativeType=C,columnSize=33], Column[name=CUS_AD2,columnNumber=9,type=CHAR,nullable=null,nativeType=C,columnSize=33], Column[name=CUS_AD3,columnNumber=10,type=CHAR,nullable=null,nativeType=C,columnSize=33], Column[name=CUS_CTY,columnNumber=11,type=CHAR,nullable=null,nativeType=C,columnSize=22], Column[name=CUS_ST,columnNumber=12,type=CHAR,nullable=null,nativeType=C,columnSize=22], Column[name=CUS_COU,columnNumber=13,type=CHAR,nullable=null,nativeType=C,columnSize=22], Column[name=CUS_ZIP,columnNumber=14,type=CHAR,nullable=null,nativeType=C,columnSize=10], Column[name=CUS_PHON,columnNumber=15,type=CHAR,nullable=null,nativeType=C,columnSize=14], Column[name=CUS_FAX,columnNumber=16,type=CHAR,nullable=null,nativeType=C,columnSize=14], Column[name=CUS_OPHN,columnNumber=17,type=CHAR,nullable=null,nativeType=C,columnSize=14], Column[name=CUS_EMAI,columnNumber=18,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=AUT_CORP,columnNumber=19,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=AUT_NAME,columnNumber=20,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=AUT_TITL,columnNumber=21,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=AUT_SALU,columnNumber=22,type=CHAR,nullable=null,nativeType=C,columnSize=55], Column[name=AUT_AD1,columnNumber=23,type=CHAR,nullable=null,nativeType=C,columnSize=33], Column[name=AUT_AD2,columnNumber=24,type=CHAR,nullable=null,nativeType=C,columnSize=33], Column[name=AUT_AD3,columnNumber=25,type=CHAR,nullable=null,nativeType=C,columnSize=33], Column[name=AUT_CTY,columnNumber=26,type=CHAR,nullable=null,nativeType=C,columnSize=22], Column[name=AUT_ST,columnNumber=27,type=CHAR,nullable=null,nativeType=C,columnSize=22], Column[name=AUT_COU,columnNumber=28,type=CHAR,nullable=null,nativeType=C,columnSize=22], Column[name=AUT_ZIP,columnNumber=29,type=CHAR,nullable=null,nativeType=C,columnSize=10], Column[name=AUT_PHON,columnNumber=30,type=CHAR,nullable=null,nativeType=C,columnSize=14], Column[name=AUT_FAX,columnNumber=31,type=CHAR,nullable=null,nativeType=C,columnSize=14], Column[name=AUT_OPHN,columnNumber=32,type=CHAR,nullable=null,nativeType=C,columnSize=14], Column[name=AUT_EMAI,columnNumber=33,type=CHAR,nullable=null,nativeType=C,columnSize=55]]",
			columns.toString());
	assertEquals(columns.size(), table.getColumnCount());

	columns = table.getColumnsOfType(ColumnType.FLOAT);
	assertEquals("[]", columns.toString());

	columns = table.getColumnsOfType(ColumnType.DOUBLE);
	assertEquals("[]", columns.toString());

	columns = table.getColumnsOfType(ColumnType.DATE);
	assertEquals("[]", columns.toString());

	columns = table.getColumnsOfType(ColumnType.OTHER);
	assertEquals("[]", columns.toString());
}
 
开发者ID:datacleaner,项目名称:metamodel_extras,代码行数:35,代码来源:DbaseDataContextReportTest.java

示例13: testQuery

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testQuery() throws Exception {
	Schema schema = dc.getSchemaByName("report.dbf");
	Table table = schema.getTableByName("report");

	List<Column> columns = table.getColumns();
	Query q = new Query().select(columns).from(table);
	DataSet ds = dc.executeQuery(q);

	while (ds.next()) {
		Row row = ds.getRow();
		List<SelectItem> selectItems = row.getSelectItems();
		for (int i = 0; i < selectItems.size(); i++) {
			SelectItem selectItem = selectItems.get(i);
			Column column = columns.get(i);
			assertSame(selectItem.getColumn(), column);

			Object selectItemValue = row.getValue(selectItem);
			Object columnValue = row.getValue(column);
			assertEquals(selectItemValue, columnValue);

			assertNotNull(columnValue);

			assertTrue(columnValue instanceof Character
					|| columnValue instanceof String);
		}
	}
	ds.close();
}
 
开发者ID:datacleaner,项目名称:metamodel_extras,代码行数:29,代码来源:DbaseDataContextReportTest.java

示例14: testExploreSchema

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testExploreSchema() throws Exception {
	assertEquals("[information_schema, METER.DBF]",
			dc.getSchemaNames().toString());

	Schema schema = dc.getSchemaByName("METER.DBF");
	assertEquals("[Table[name=METER,type=TABLE,remarks=null]]",
			schema.getTables().toString());

	Table table = schema.getTableByName("METER");
	assertEquals(
			"[SCENARIO, P_INST, S_INST, A_INST, R_MULT, M_INST, G_BEG, T_BEG, G_NUM, A_NORM, F_KIND, F_TYPE, F_TOU, DATE_N, UTILCALC, DATE_D, UTIL, NAME, U_NAME, U_KIND, U_UNIT, N_UNIT, C_NAME, P_NAME, S_NAME, A_NAME, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N_COUNT]",
			table.getColumnNames().toString());

	Column column = table.getColumnByName("F_TYPE");
	assertEquals(
			"Column[name=F_TYPE,columnNumber=11,type=CHAR,nullable=null,nativeType=C,columnSize=1]",
			column.toString());

	column = table.getColumnByName("V1");
	assertEquals(
			"Column[name=V1,columnNumber=26,type=DOUBLE,nullable=null,nativeType=N,columnSize=12]",
			column.toString());

	column = table.getColumnByName("V12");
	assertEquals(
			"Column[name=V12,columnNumber=37,type=DOUBLE,nullable=null,nativeType=N,columnSize=12]",
			column.toString());

	column = table.getColumnByName("A_NAME");
	assertEquals(
			"Column[name=A_NAME,columnNumber=25,type=CHAR,nullable=null,nativeType=C,columnSize=22]",
			column.toString());
}
 
开发者ID:datacleaner,项目名称:metamodel_extras,代码行数:34,代码来源:DbaseDataContextMeterTest.java

示例15: testDeveloperTable

import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testDeveloperTable() throws Exception {
    Schema schema = dc.getDefaultSchema();
    assertEquals("developers.mdb", schema.getName());

    assertEquals("[developer, product]", schema.getTableNames().toString());

    Table table = schema.getTableByName("developer");
    assertEquals("[id, name, email, male, developer_since]", table.getColumnNames().toString());
    
    List<Column> primaryKeys = table.getPrimaryKeys();
    assertEquals("[Column[name=id,columnNumber=0,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]]", primaryKeys.toString());

    Column nameCol = table.getColumnByName("name");
    assertEquals(
            "Column[name=name,columnNumber=1,type=VARCHAR,nullable=null,nativeType=TEXT,columnSize=100]",
            nameCol.toString());

    Column maleCol = table.getColumnByName("male");
    assertEquals(
            "Column[name=male,columnNumber=3,type=BOOLEAN,nullable=null,nativeType=BOOLEAN,columnSize=1]",
            maleCol.toString());

    Column developerSinceCol = table.getColumnByName("developer_since");
    assertEquals(
            "Column[name=developer_since,columnNumber=4,type=TIMESTAMP,nullable=null,nativeType=SHORT_DATE_TIME,columnSize=8]",
            developerSinceCol.toString());

    DataSet ds = dc.executeQuery(new Query().select(nameCol, maleCol, developerSinceCol).from(table));
    while (ds.next()) {
        Row row = ds.getRow();
        assertEquals(3, row.getValues().length);
        Object value = row.getValue(0);
        assertEquals(String.class, value.getClass());
        value = row.getValue(1);
        assertEquals(Boolean.class, value.getClass());
        value = row.getValue(2);
        assertTrue(value instanceof Date);
    }
}
 
开发者ID:datacleaner,项目名称:metamodel_extras,代码行数:40,代码来源:AccessDataContextTest.java


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