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


Java DataContext类代码示例

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


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


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