• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DataContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: openDataContext

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@Override
public DataContext openDataContext(String dataSourceName) throws NoSuchDataSourceException {
    if (Strings.isNullOrEmpty(dataSourceName)) {
        throw new IllegalArgumentException("DataSource name cannot be null or empty");
    }
    final File file = getDataSourceFile(dataSourceName);
    if (!file.exists()) {
        throw new NoSuchDataSourceException(dataSourceName);
    }

    final RestDataSourceDefinition dataSource;
    try {
        dataSource = OBJECT_MAPPER.readValue(file, RestDataSourceDefinition.class);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }

    final DataContextSupplier supplier =
            new DataContextSupplier(dataSourceName, dataSource.toDataContextProperties());
    return supplier.get();
}
 
开发者ID:apache,项目名称:metamodel-membrane,代码行数:22,代码来源:FileBasedDataSourceRegistry.java


示例2: get

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public QueryResponse get(@PathVariable("tenant") String tenantId,
        @PathVariable("dataContext") String dataSourceName, @PathVariable("schema") String schemaId,
        @PathVariable("table") String tableId, @RequestParam(value = "offset", required = false) Integer offset,
        @RequestParam(value = "limit", required = false) Integer limit) {
    final TenantContext tenantContext = tenantRegistry.getTenantContext(tenantId);
    final DataContext dataContext = tenantContext.getDataSourceRegistry().openDataContext(dataSourceName);

    final DataContextTraverser traverser = new DataContextTraverser(dataContext);

    final Table table = traverser.getTable(schemaId, tableId);

    final Query query = dataContext.query().from(table).selectAll().toQuery();

    return QueryController.executeQuery(tenantContext, dataSourceName, dataContext, query, offset, limit);
}
 
开发者ID:apache,项目名称:metamodel-membrane,代码行数:18,代码来源:TableDataController.java


示例3: createQueryOptimizerRef

import org.apache.metamodel.DataContext; //导入依赖的package包/类
private LazyRef<RowProcessingQueryOptimizer> createQueryOptimizerRef() {
    return new LazyRef<RowProcessingQueryOptimizer>() {
        @Override
        protected RowProcessingQueryOptimizer fetch() {
            final Datastore datastore = getAnalysisJob().getDatastore();
            try (DatastoreConnection con = datastore.openConnection()) {
                final DataContext dataContext = con.getDataContext();

                final Column[] columnArray = _physicalColumns.toArray(new Column[_physicalColumns.size()]);
                final Query baseQuery = dataContext.query().from(getTable()).select(columnArray).toQuery();

                logger.debug("Base query for row processing: {}", baseQuery);

                // try to optimize

                return new RowProcessingQueryOptimizerImpl(datastore, getConsumersSorted(), baseQuery);
            } catch (final RuntimeException e) {
                logger.error("Failed to build query optimizer! {}", e.getMessage(), e);
                throw e;
            }
        }
    };
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:24,代码来源:SourceTableRowProcessingPublisher.java


示例4: resolveForeignColumn

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


示例5: createDatastoreConnection

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@Override
protected UsageAwareDatastoreConnection<DataContext> createDatastoreConnection() {
    final FixedWidthConfiguration configuration = getConfiguration();
    final Resource resource = _resourceRef.get();
    final DataContext dataContext;
    if (resource == null) {
        logger.warn("Resource was not available, a local file reference will be created with path: {}", _filename);
        dataContext = DataContextFactory.createFixedWidthDataContext(new File(_filename), configuration);
    } else {
        dataContext = DataContextFactory.createFixedWidthDataContext(resource, configuration);
    }
    return new DatastoreConnectionImpl<>(dataContext, this);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:14,代码来源:FixedWidthDatastore.java


示例6: loadIntoMemory

import org.apache.metamodel.DataContext; //导入依赖的package包/类
public SimpleDictionary loadIntoMemory(final DatastoreConnection datastoreConnection) {
    final DataContext dataContext = datastoreConnection.getDataContext();
    final Column column = getColumn(datastoreConnection);

    final Query query = dataContext.query().from(column.getTable()).select(column).toQuery();
    if (datastoreConnection.getDatastore().getPerformanceCharacteristics().isQueryOptimizationPreferred()) {
        query.getSelectClause().setDistinct(true);
    }

    final Set<String> values = new HashSet<>();

    try (DataSet dataSet = dataContext.executeQuery(query)) {
        while (dataSet.next()) {
            final Object value = dataSet.getRow().getValue(0);
            if (value != null) {
                values.add(value.toString());
            }
        }
    }

    return new SimpleDictionary(getName(), values);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:23,代码来源:DatastoreDictionary.java


示例7: actionPerformed

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@Override
public void actionPerformed(final ActionEvent e) {
    List<Column> columns = _columns;
    if (_columns == null) {
        final List<Column> cols = new ArrayList<>();
        for (final InputColumn<?> col : _inputColumns) {
            if (col.isPhysicalColumn()) {
                cols.add(col.getPhysicalColumn());
            }
        }
        columns = cols;
    }

    if (columns.isEmpty()) {
        throw new IllegalStateException("No columns found - could not determine which columns to query");
    }

    try (DatastoreConnection con = _datastore.openConnection()) {
        final DataContext dc = con.getDataContext();
        final Query q = dc.query().from(columns.get(0).getTable()).select(columns).toQuery();

        final DataSetWindow window = new DataSetWindow(q, dc, PAGE_SIZE, _windowContext);
        window.open();
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:26,代码来源:PreviewSourceDataActionListener.java


示例8: DataSetWindow

import org.apache.metamodel.DataContext; //导入依赖的package包/类
public DataSetWindow(final Query query, final DataContext dataContext, final int pageSize,
        final WindowContext windowContext) {
    super(windowContext);
    _table = new DCTable();
    _query = query;
    _pageSize = pageSize;
    _title = "DataSet: " + _query.toSql();
    _tableModelCallable = () -> {
        final DataSet dataSet = dataContext.executeQuery(_query);
        return new DataSetTableModel(dataSet);
    };
    _previousPageButton = WidgetFactory.createDefaultButton("Previous page", IconUtils.ACTION_BACK);
    _previousPageButton.setEnabled(false);
    _nextPageButton = WidgetFactory.createDefaultButton("Next page", IconUtils.ACTION_FORWARD);
    _nextPageButton.setHorizontalTextPosition(SwingConstants.LEFT);
    _nextPageButton.setEnabled(false);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:18,代码来源:DataSetWindow.java


示例9: getPreviewData

import org.apache.metamodel.DataContext; //导入依赖的package包/类
private DataSet getPreviewData(final String filename) {
    if (!isPreviewDataAvailable()) {
        logger.info("Not displaying preview table because isPreviewDataAvailable() returned false");
        return null;
    }

    final D datastore = getPreviewDatastore(filename);
    try (DatastoreConnection con = datastore.openConnection()) {
        final DataContext dc = con.getDataContext();
        final Table table = getPreviewTable(dc);

        List<Column> columns = table.getColumns();
        if (columns.size() > getPreviewColumns()) {
            // include max 10 columns
            columns = columns.stream().limit(getPreviewColumns()).collect(Collectors.toList());
        }
        final Query q = dc.query().from(table).select(columns).toQuery();
        q.setMaxRows(7);

        return dc.executeQuery(q);
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:23,代码来源:AbstractFileBasedDatastoreDialog.java


示例10: testFullScenario

import org.apache.metamodel.DataContext; //导入依赖的package包/类
public void testFullScenario() throws Exception {
    final OutputWriterScenarioHelper scenarioHelper = new OutputWriterScenarioHelper();

    final String filename = "target/test-output/csv-file1.txt";
    final OutputWriter writer = CsvOutputWriterFactory.getWriter(filename, scenarioHelper.getColumns());

    scenarioHelper.writeExampleData(writer);
    writer.close();

    final DataContext dc = DataContextFactory.createCsvDataContext(new File(filename));
    final Table table = dc.getDefaultSchema().getTable(0);
    final Query q = dc.query().from(table).select(table.getColumns()).toQuery();
    final DataSet dataSet = dc.executeQuery(q);

    scenarioHelper.performAssertions(dataSet, false);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:17,代码来源:CsvOutputWriterFactoryTest.java


示例11: createQueryOptimizerRef

import org.apache.metamodel.DataContext; //导入依赖的package包/类
private LazyRef<RowProcessingQueryOptimizer> createQueryOptimizerRef() {
    return new LazyRef<RowProcessingQueryOptimizer>() {
        @Override
        protected RowProcessingQueryOptimizer fetch() {
            final Datastore datastore = _publishers.getDatastore();
            try (final DatastoreConnection con = datastore.openConnection()) {
                final DataContext dataContext = con.getDataContext();

                final Column[] columnArray = _physicalColumns.toArray(new Column[_physicalColumns.size()]);
                final Query baseQuery = dataContext.query().from(_table).select(columnArray).toQuery();

                logger.debug("Base query for row processing: {}", baseQuery);

                final List<RowProcessingConsumer> sortedConsumers = sortConsumers(_consumers);

                final RowProcessingQueryOptimizer optimizer = new RowProcessingQueryOptimizer(datastore,
                        sortedConsumers, baseQuery);
                return optimizer;
            } catch (RuntimeException e) {
                logger.error("Failed to build query optimizer! {}", e.getMessage(), e);
                throw e;
            }
        }
    };
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:26,代码来源:RowProcessingPublisher.java


示例12: resolveForeignColumn

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


示例13: createDatastoreConnection

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@Override
protected UsageAwareDatastoreConnection<DataContext> createDatastoreConnection() {
	final File file = new File(_filename);
	assert file.exists();

	final FixedWidthConfiguration configuration;
	if (_fixedValueWidth == -1) {
		configuration = new FixedWidthConfiguration(_headerLineNumber, _encoding, _valueWidths, _failOnInconsistencies);
	} else {
		configuration = new FixedWidthConfiguration(_headerLineNumber, _encoding, _fixedValueWidth,
				_failOnInconsistencies);
	}

	DataContext dataContext = DataContextFactory.createFixedWidthDataContext(file, configuration);
	return new DatastoreConnectionImpl<DataContext>(dataContext, this);
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:17,代码来源:FixedWidthDatastore.java


示例14: getValues

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@Override
public Collection<String> getValues() {
    try (final DatastoreConnection con = _datastore.openConnection()) {
        final DataContext dataContext = con.getDataContext();

        final Query q = dataContext.query().from(_column.getTable()).select(_column).toQuery();
        q.selectDistinct();

        try (final DataSet dataSet = dataContext.executeQuery(q)) {
            final List<String> values = new ArrayList<String>();
            while (dataSet.next()) {
                final Row row = dataSet.getRow();
                
                Object value = row.getValue(0);
                if (value != null) {
                    value = value.toString();
                }
                values.add((String) value);
            }
            return values;
        }
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:24,代码来源:DatastoreReferenceValues.java


示例15: addTypeConverterInternally

import org.apache.metamodel.DataContext; //导入依赖的package包/类
private static InterceptableDataContext addTypeConverterInternally(final DataContext dc, Column column,
        TypeConverter<?, ?> converter) {
    if (column == null) {
        throw new IllegalArgumentException("Column cannot be null");
    }

    InterceptableDataContext interceptable = Interceptors.intercept(dc);
    DataContext delegate = interceptable.getDelegate();

    boolean interceptDataSets = true;

    if (delegate instanceof HasReadTypeConverters) {
        // some DataContexts implement the HasTypeConverters interface,
        // which is preferred when available
        HasReadTypeConverters hasTypeConverter = (HasReadTypeConverters) delegate;
        hasTypeConverter.addConverter(column, converter);

        interceptDataSets = false;
    }

    addTypeConverterInterceptors(interceptable, column, converter, interceptDataSets);
    return interceptable;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:24,代码来源:Converters.java


示例16: addTypeConvertersInternally

import org.apache.metamodel.DataContext; //导入依赖的package包/类
private static InterceptableDataContext addTypeConvertersInternally(final DataContext dc,
        Map<Column, TypeConverter<?, ?>> converters) {
    if (converters == null) {
        throw new IllegalArgumentException("Converters cannot be null");
    }

    InterceptableDataContext interceptable = Interceptors.intercept(dc);

    Set<Entry<Column, TypeConverter<?, ?>>> entries = converters.entrySet();
    for (Entry<Column, TypeConverter<?, ?>> entry : entries) {
        Column column = entry.getKey();
        TypeConverter<?, ?> converter = entry.getValue();
        interceptable = addTypeConverterInternally(interceptable, column, converter);
    }

    return interceptable;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:18,代码来源:Converters.java


示例17: createDataContext

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@Override
public DataContext createDataContext(DataContextFactoryParameters params) {
    SimpleTableDef[] tableDefs = params.getTableDefs();
    if (tableDefs == null || tableDefs.length == 0) {
        throw new IllegalArgumentException("Cannot create PojoDataContext with no tableDefs specified");
    }
    
    TableDataProvider<?>[] tableDataProviders = new ArrayTableDataProvider[tableDefs.length];
    for (int i = 0; i < tableDataProviders.length; i++) {
        ArrayTableDataProvider tableDataProvider = new ArrayTableDataProvider(tableDefs[i], new ArrayList<Object[]>());
        tableDataProviders[i] = tableDataProvider;
    }
    
    String databaseName = params.getDatabaseName();
    if (databaseName != null && !databaseName.isEmpty()) {
        return new PojoDataContext(databaseName, tableDataProviders);
    }
    return new PojoDataContext(Arrays.asList(tableDataProviders));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:20,代码来源:PojoDataContextFactoryBeanDelegate.java


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


示例19: testNonConvertedQuery

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@SuppressWarnings("resource")
public void testNonConvertedQuery() throws Exception {
    MockUpdateableDataContext source = new MockUpdateableDataContext();
    Column fooColumn = source.getColumnByQualifiedLabel("schema.table.foo");
    assertNotNull(fooColumn);

    Map<Column, TypeConverter<?, ?>> converters = new HashMap<Column, TypeConverter<?, ?>>();
    converters.put(fooColumn, new StringToIntegerConverter());
    DataContext converted = Converters.addTypeConverter(source, fooColumn, new StringToIntegerConverter());

    // only select "bar" which is not converted
    Table table = converted.getDefaultSchema().getTableByName("table");
    Query query = converted.query().from(table).select("bar").toQuery();
    assertEquals("SELECT table.bar FROM schema.table", query.toSql());

    DataSet ds = converted.executeQuery(query);
    while (ds instanceof WrappingDataSet) {
        ds = ((WrappingDataSet) ds).getWrappedDataSet();
    }
    ds.close();
    assertEquals(InMemoryDataSet.class, ds.getClass());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:23,代码来源:ConvertedDataSetInterceptorTest.java


示例20: create

import org.apache.metamodel.DataContext; //导入依赖的package包/类
@Override
public DataContext create(DataContextProperties properties, ResourceFactoryRegistry resourceFactoryRegistry)
        throws UnsupportedDataContextPropertiesException, ConnectionException {

    final Resource resource = resourceFactoryRegistry.createResource(properties.getResourceProperties());

    final int columnNameLineNumber =
            getInt(properties.getColumnNameLineNumber(), ExcelConfiguration.DEFAULT_COLUMN_NAME_LINE);
    final Boolean skipEmptyLines = getBoolean(properties.isSkipEmptyLines(), true);
    final Boolean skipEmptyColumns = getBoolean(properties.isSkipEmptyColumns(), false);

    final ColumnNamingStrategy columnNamingStrategy;
    if (properties.getTableDefs() == null) {
        columnNamingStrategy = null;
    } else {
        final SimpleTableDef firstTable = properties.getTableDefs()[0];
        final String[] columnNames = firstTable.getColumnNames();
        columnNamingStrategy = new CustomColumnNamingStrategy(columnNames);
    }

    final ExcelConfiguration configuration =
            new ExcelConfiguration(columnNameLineNumber, columnNamingStrategy, skipEmptyLines, skipEmptyColumns);
    return new ExcelDataContext(resource, configuration);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:25,代码来源:ExcelDataContextFactory.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectHistogramElement类代码示例发布时间:2022-05-22
下一篇:
Java Constraints类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap