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


Java Table.getColumnByName方法代码示例

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


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

示例1: convertToColumns

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
public Column[] convertToColumns(final String schemaName, final String tableName, final String[] columnNames) {
    if (columnNames == null) {
        return null;
    }

    if (columnNames.length == 0) {
        return new Column[0];
    }

    final Table table = convertToTable(schemaName, tableName);

    final Column[] columns = new Column[columnNames.length];
    for (int i = 0; i < columns.length; i++) {
        columns[i] = table.getColumnByName(columnNames[i]);
    }

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

示例2: resolveForeignColumn

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

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
public Column[] convertToColumns(String schemaName, String tableName, String[] columnNames) {
    if (columnNames == null) {
        return null;
    }

    if (columnNames.length == 0) {
        return new Column[0];
    }

    final Table table = convertToTable(schemaName, tableName);

    final Column[] columns = new Column[columnNames.length];
    for (int i = 0; i < columns.length; i++) {
        columns[i] = table.getColumnByName(columnNames[i]);
    }

    return columns;
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:19,代码来源:SchemaNavigator.java

示例5: resolveForeignColumn

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

示例6: testConnectAndExplore

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

示例7: setWhere

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
private void setWhere(WhereClauseBuilder<?> whereBuilder, Table table, List<WhereCondition> conditions) {
    for (WhereCondition condition : conditions) {
        final Column column = table.getColumnByName(condition.getColumn());
        if (column == null) {
            throw new IllegalArgumentException("No such column: " + condition.getColumn());
        }
        final OperatorType operator = toOperator(condition.getOperator());
        final FilterItem filterItem = new FilterItem(new SelectItem(column), operator, condition.getOperand());
        whereBuilder.where(filterItem);
    }
}
 
开发者ID:apache,项目名称:metamodel-membrane,代码行数:12,代码来源:TableDataController.java

示例8: getLicensedProjects

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
public static List<LicensedProject> getLicensedProjects() {
    final List<LicensedProject> result = new ArrayList<>();
    final URL url = resourceManager.getUrl("licenses/dependency-licenses.csv");
    if (url == null) {
        throw new IllegalStateException("Could not find dependencies file");
    }
    try {
        final DataContext dc = DataContextFactory.createCsvDataContext(url.openStream(), ',', '"');
        final Table table = dc.getDefaultSchema().getTable(0);
        final Column projectColumn = table.getColumnByName("Project");
        final Column websiteColumn = table.getColumnByName("Website");
        final Column licenseColumn = table.getColumnByName("License");
        final Query q = dc.query().from(table).select(table.getColumns()).orderBy(projectColumn).asc().toQuery();
        final DataSet ds = dc.executeQuery(q);
        while (ds.next()) {
            final LicensedProject licensedProject = new LicensedProject();
            final Row row = ds.getRow();
            final String licenseName = row.getValue(licenseColumn).toString();

            licensedProject.name = row.getValue(projectColumn).toString();
            licensedProject.websiteUrl = row.getValue(websiteColumn).toString();
            licensedProject.license = getLicense(licenseName);

            result.add(licensedProject);
        }

    } catch (final IOException e) {
        throw new IllegalStateException("Error occurred while reading dependencies file", e);
    }

    return result;
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:33,代码来源:AboutDialog.java

示例9: testExploreSchema

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

示例10: testDeveloperTable

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

示例11: testSerializeDeserializeDatastores

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
@Test
public void testSerializeDeserializeDatastores() {
    String csv = ConfigurationSerializer.serializeAnalyzerBeansConfigurationDataStores(analyzerBeansConfiguration);
    logger.info("Csv: " + csv);
    AnalyzerBeansConfiguration deserialized = ConfigurationSerializer.deserializeAnalyzerBeansDatastores(csv);
    for (String datastoreName : analyzerBeansConfiguration.getDatastoreCatalog().getDatastoreNames()) {
        logger.info("Datastore: " + datastoreName);
        Datastore datastore = analyzerBeansConfiguration.getDatastoreCatalog().getDatastore(datastoreName);
        Datastore deserializedDatastore = deserialized.getDatastoreCatalog().getDatastore(datastoreName);
        Assert.assertNotNull(deserializedDatastore);

        SchemaNavigator schemaNavigator = datastore.openConnection().getSchemaNavigator();
        SchemaNavigator deserializedSchemaNavigator = deserializedDatastore.openConnection().getSchemaNavigator();
        for (Schema schema : schemaNavigator.getSchemas()) {
            String schemaName = schema.getName();
            logger.info("\tSchema: " + schemaName);
            Schema deserializedSchema = deserializedSchemaNavigator.getSchemaByName(schemaName);
            Assert.assertNotNull(deserializedSchema);

            for (Table table : schema.getTables()) {
                String tableName = table.getName();
                logger.info("\t\tTable: " + tableName);
                Table deserializedTable = deserializedSchema.getTableByName(tableName);
                Assert.assertNotNull(deserializedTable);

                for (Column column : table.getColumns()) {
                    String columnName = column.getName();
                    logger.info("\t\t\tColumn: " + columnName);
                    Column deserializedColumn = deserializedTable.getColumnByName(columnName);
                    Assert.assertNotNull(deserializedColumn);
                }
            }
        }
    }
}
 
开发者ID:tomaszguzialek,项目名称:hadoop-datacleaner,代码行数:36,代码来源:ConfigurationSerializerTest.java

示例12: getColumn

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
public Column getColumn(String database, String primaryKey, String tableName){
	Schema schema = dataContext.getDefaultSchema();
	Table table = schema.getTableByName(tableName);
	Column column = table.getColumnByName(primaryKey);
	return column;
}
 
开发者ID:Iranox,项目名称:mapbench-datadistributor,代码行数:7,代码来源:TableReader.java

示例13: getDefaultMappedColumn

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
protected Column getDefaultMappedColumn(final InputColumn<?> inputColumn, final Table table) {
    // automatically select a column by name, if it exists
    return table.getColumnByName(inputColumn.getName());
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:5,代码来源:MultipleMappedColumnsPropertyWidget.java

示例14: testToAnalysisJob

import org.apache.metamodel.schema.Table; //导入方法依赖的package包/类
public void testToAnalysisJob() throws Exception {
    final Table employeeTable =
            datastore.openConnection().getDataContext().getDefaultSchema().getTableByName("EMPLOYEES");
    assertNotNull(employeeTable);

    final Column emailColumn = employeeTable.getColumnByName("EMAIL");
    analysisJobBuilder.addSourceColumns(employeeTable.getColumnByName("EMPLOYEENUMBER"),
            employeeTable.getColumnByName("FIRSTNAME"), emailColumn);

    assertTrue(analysisJobBuilder.containsSourceColumn(emailColumn));
    assertFalse(analysisJobBuilder.containsSourceColumn(null));
    assertFalse(analysisJobBuilder.containsSourceColumn(employeeTable.getColumnByName("LASTNAME")));

    final TransformerComponentBuilder<ConvertToStringTransformer> transformerJobBuilder =
            analysisJobBuilder.addTransformer(ConvertToStringTransformer.class);

    final Collection<InputColumn<?>> numberColumns = analysisJobBuilder.getAvailableInputColumns(Number.class);
    assertEquals(1, numberColumns.size());
    assertEquals("[MetaModelInputColumn[PUBLIC.EMPLOYEES.EMPLOYEENUMBER]]",
            Arrays.toString(numberColumns.toArray()));

    transformerJobBuilder.addInputColumn(numberColumns.iterator().next());
    assertTrue(transformerJobBuilder.isConfigured());

    // the AnalyzerJob has no Analyzers yet, so it is not "configured".
    assertFalse(analysisJobBuilder.isConfigured());

    final AnalyzerComponentBuilder<StringAnalyzer> analyzerJobBuilder =
            analysisJobBuilder.addAnalyzer(StringAnalyzer.class);

    final List<InputColumn<?>> stringInputColumns = analysisJobBuilder.getAvailableInputColumns(String.class);
    final Set<String> columnNames =
            stringInputColumns.stream().map(InputColumn::getName).collect(Collectors.toCollection(TreeSet::new));
    assertEquals("[EMAIL, EMPLOYEENUMBER (as string), FIRSTNAME]", columnNames.toString());

    analyzerJobBuilder.addInputColumns(stringInputColumns);
    assertTrue(analyzerJobBuilder.isConfigured());

    // now there is: source columns, configured analyzers and configured
    // transformers.
    assertTrue(analysisJobBuilder.isConfigured());

    final AnalysisJob analysisJob = analysisJobBuilder.toAnalysisJob();

    assertEquals("ImmutableAnalysisJob[sourceColumns=3,filterJobs=0,transformerJobs=1,analyzerJobs=1]",
            analysisJob.toString());

    // test hashcode and equals
    assertNotSame(analysisJobBuilder.toAnalysisJob(), analysisJob);
    assertEquals(analysisJobBuilder.toAnalysisJob(), analysisJob);
    assertEquals(analysisJobBuilder.toAnalysisJob().hashCode(), analysisJob.hashCode());

    final Collection<InputColumn<?>> sourceColumns = analysisJob.getSourceColumns();
    assertEquals(3, sourceColumns.size());

    try {
        sourceColumns.add(new MockInputColumn<>("bla", Boolean.class));
        fail("Exception expected");
    } catch (final UnsupportedOperationException e) {
        // do nothing
    }

    final Collection<TransformerJob> transformerJobs = analysisJob.getTransformerJobs();
    assertEquals(1, transformerJobs.size());

    final TransformerJob transformerJob = transformerJobs.iterator().next();
    assertEquals("ImmutableTransformerJob[name=null,transformer=Convert to string]", transformerJob.toString());

    assertEquals("[MetaModelInputColumn[PUBLIC.EMPLOYEES.EMPLOYEENUMBER]]",
            Arrays.toString(transformerJob.getInput()));

    final Collection<AnalyzerJob> analyzerJobs = analysisJob.getAnalyzerJobs();
    assertEquals(1, analyzerJobs.size());

    final AnalyzerJob analyzerJob = analyzerJobs.iterator().next();
    assertEquals("ImmutableAnalyzerJob[name=null,analyzer=String analyzer]", analyzerJob.toString());
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:78,代码来源:AnalysisJobBuilderTest.java

示例15: testProductTable

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

    Table table = schema.getTableByName("product");
    assertEquals("[id, name, version, founder_developer]", table.getColumnNames().toString());

    Column idCol = table.getColumnByName("id");
    assertEquals(
            "Column[name=id,columnNumber=0,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]",
            idCol.toString());

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

    Column versionCol = table.getColumnByName("version");
    assertEquals(
            "Column[name=version,columnNumber=2,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]",
            versionCol.toString());

    Column founderCol = table.getColumnByName("founder_developer");
    assertEquals(
            "Column[name=founder_developer,columnNumber=3,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]",
            founderCol.toString());

    DataSet ds;

    ds = dc.executeQuery(new Query().select(nameCol, versionCol, founderCol).from(table));
    assertTrue(ds.next());
    assertEquals("Anthons Algorithms", ds.getRow().getValue(nameCol).toString());
    assertEquals(11, ds.getRow().getValue(versionCol));
    assertEquals(1, ds.getRow().getValue(founderCol));
    assertTrue(ds.next());
    assertEquals("Barbaras Basic Bundle", ds.getRow().getValue(nameCol).toString());
    assertEquals(2, ds.getRow().getValue(versionCol));
    assertEquals(2, ds.getRow().getValue(founderCol));
    assertFalse(ds.next());
    ds.close();

    ds = dc.query().from(table).selectCount().execute();
    assertTrue(ds.next());
    assertEquals("Row[values=[2]]", ds.getRow().toString());
    assertFalse(ds.next());
    ds.close();
}
 
开发者ID:datacleaner,项目名称:metamodel_extras,代码行数:48,代码来源:AccessDataContextTest.java


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