• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MutableColumn类的典型用法和代码示例

java 2次浏览

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

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

示例1: testDelegateOnPhysicalColumn

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testDelegateOnPhysicalColumn() throws Exception {
    final Column col1 = new MutableColumn("foo");
    final InputColumn<?> inputColumn1 = new MetaModelInputColumn(col1);

    final Column col2 = new MutableColumn("bar");
    final InputColumn<?> inputColumn2 = new MetaModelInputColumn(col2);

    final SelectItem[] selectItems = new SelectItem[] { new SelectItem(col1), new SelectItem(col2) };
    final Object[] values = new Object[] { 1234, 4567 };
    final DataSetHeader header = new SimpleDataSetHeader(selectItems);
    final TransformedInputRow row =
            new TransformedInputRow(new MetaModelInputRow(0, new DefaultRow(header, values)), 1);

    assertEquals(1234, row.getValue(inputColumn1));
    assertEquals(4567, row.getValue(inputColumn2));
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:17,
代码来源:TransformedInputRowTest.java

示例2: testAutoMapPartialMatches

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testAutoMapPartialMatches() throws Exception {
    final Datastore datastore = TestHelper.createSampleDatabaseDatastore("testdb");

    final SourceColumnMapping columnMapping =
            new SourceColumnMapping("PUBLIC.EMPLOYEES.FIRSTNAME", "foo.bar.col1", "PUBLIC.EMPLOYEES.LASTNAME",
                    "foo.bar.col2");

    columnMapping.setColumn("foo.bar.col1", new MutableColumn("col1"));
    assertFalse(columnMapping.isSatisfied());
    assertEquals("[PUBLIC.EMPLOYEES.FIRSTNAME, PUBLIC.EMPLOYEES.LASTNAME, foo.bar.col2]",
            columnMapping.getUnmappedPaths().toString());

    columnMapping.autoMap(datastore);
    assertFalse(columnMapping.isSatisfied());
    assertEquals("[foo.bar.col2]", columnMapping.getUnmappedPaths().toString());

    columnMapping.setColumn("foo.bar.col2", new MutableColumn("col2"));
    assertTrue(columnMapping.isSatisfied());
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:20,
代码来源:SourceColumnMappingTest.java

示例3: setValue

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Override
protected void setValue(final String value) {
    if (value == null) {
        _comboBox.setSelectedItem(null);
        return;
    }

    if (_comboBox.getTable() == null) {
        final MutableTable placeholderTable = new MutableTable("table");
        placeholderTable.addColumn(new MutableColumn(value, placeholderTable));
        _comboBox.setModel(placeholderTable);
    }

    _comboBox.setSelectedItem(value);

    fireValueChanged(value);
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:18,
代码来源:SingleColumnNamePropertyWidget.java

示例4: testSetTableAndThenSelectAll

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testSetTableAndThenSelectAll() throws Exception {
    final MutableTable table = new MutableTable();
    table.addColumn(new MutableColumn("source1").setTable(table));
    table.addColumn(new MutableColumn("source3").setTable(table));
    table.addColumn(new MutableColumn("foo").setTable(table));
    table.addColumn(new MutableColumn("bar").setTable(table));
    propertyWidget.setTable(table);

    propertyWidget.selectAll();

    final InputColumn<?>[] value = propertyWidget.getValue();
    assertEquals(4, value.length);

    final Map<InputColumn<?>, SourceColumnComboBox> mappedColumnComboBoxes =
            propertyWidget.getMappedColumnComboBoxes();
    for (final SourceColumnComboBox comboBox : mappedColumnComboBoxes.values()) {
        assertTrue(comboBox.isVisible());
    }
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:20,
代码来源:MultipleMappedColumnsPropertyWidgetTest.java

示例5: testInitializeReordered

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testInitializeReordered() throws Exception {
    final DataCleanerConfiguration configuration = new DataCleanerConfigurationImpl();

    try (AnalysisJobBuilder ajb = new AnalysisJobBuilder(configuration)) {
        ajb.addSourceColumn(new MutableColumn("foo", ColumnType.VARCHAR));
        ajb.addSourceColumn(new MutableColumn("bar", ColumnType.VARCHAR));
        ajb.addSourceColumn(new MutableColumn("baz", ColumnType.NVARCHAR));

        final AnalyzerComponentBuilder<StringAnalyzer> beanJobBuilder = ajb.addAnalyzer(StringAnalyzer.class);
        final ConfiguredPropertyDescriptor property =
                beanJobBuilder.getDescriptor().getConfiguredPropertiesForInput().iterator().next();

        // initialize with "baz" + "foo"
        final MultipleInputColumnsPropertyWidget widget =
                new MultipleInputColumnsPropertyWidget(beanJobBuilder, property);
        final InputColumn<?>[] value =
                new InputColumn[] { ajb.getSourceColumnByName("baz"), ajb.getSourceColumnByName("foo") };
        widget.initialize(value);

        assertEquals("baz,foo,bar", getAvailableCheckBoxValues(widget));
        assertEquals("[MetaModelInputColumn[baz], MetaModelInputColumn[foo]]", Arrays.toString(widget.getValue()));
    }
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:24,
代码来源:MultipleInputColumnsPropertyWidgetTest.java

示例6: testGetOutputColumns

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testGetOutputColumns() throws Exception {
    final InputColumn<?> col = new MetaModelInputColumn(new MutableColumn("name"));

    @SuppressWarnings("unchecked") final InputColumn<String> castColumn = (InputColumn<String>) col;
    TokenizerTransformer transformer = new TokenizerTransformer(castColumn, 2);

    final OutputColumns oc = transformer.getOutputColumns();

    assertEquals(2, oc.getColumnCount());
    assertEquals("name (token 1)", oc.getColumnName(0));
    assertEquals("name (token 2)", oc.getColumnName(1));

    transformer = new TokenizerTransformer(castColumn, 1);
    assertEquals("OutputColumns[name (token 1)]", transformer.getOutputColumns().toString());

    transformer = new TokenizerTransformer(castColumn, 0);
    try {
        transformer.getOutputColumns();
        fail("Exception expected");
    } catch (final IllegalArgumentException e) {
        assertEquals("Column names length must be 1 or greater", e.getMessage());
    }
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:24,
代码来源:TokenizerTransformerTest.java

示例7: testTransformToRows

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testTransformToRows() throws Exception {
    final InputColumn<?> col = new MetaModelInputColumn(new MutableColumn("name"));

    @SuppressWarnings("unchecked") final TokenizerTransformer transformer =
            new TokenizerTransformer((InputColumn<String>) col, 1);
    transformer.tokenTarget = TokenTarget.ROWS;
    final OutputRowCollector collectorMock = EasyMock.createMock(OutputRowCollector.class);
    transformer.outputRowCollector = collectorMock;

    assertEquals(1, transformer.getOutputColumns().getColumnCount());
    assertEquals("name (token)", transformer.getOutputColumns().getColumnName(0));

    collectorMock.putValues("Hello");
    collectorMock.putValues("world");

    EasyMock.replay(collectorMock);

    final String[] result = transformer.transform(new MockInputRow().put(col, "Hello world"));
    assertNull(result);

    EasyMock.verify(collectorMock);
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:23,
代码来源:TokenizerTransformerTest.java

示例8: shouldReturnAStringTypeForLiteralColumn

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Test
public void shouldReturnAStringTypeForLiteralColumn() {
    final Column literalColumn = new MutableColumn("foo", ColumnType.CHAR);

    Object result = TypeConverter.convertType("bla", literalColumn);
    assertTrue(result instanceof String);
    assertEquals("bla", result);

    result = TypeConverter.convertType(24, literalColumn);
    assertTrue(result instanceof String);
    assertEquals("24", result);

    result = TypeConverter.convertType(24.3d, literalColumn);
    assertTrue(result instanceof String);
    assertEquals("24.3", result);

    result = TypeConverter.convertType(dateValue, literalColumn);
    assertTrue(result instanceof String);
    assertEquals(dateValue.toString(), result);

}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:22,
代码来源:TypeConverterTest.java

示例9: testGetValueCountMetric

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Test
public void testGetValueCountMetric() {
    final ValueDistributionAnalyzer vd =
            new ValueDistributionAnalyzer(new MetaModelInputColumn(new MutableColumn("col")), true);
    vd.runInternal(new MockInputRow(), "hello", 1);
    vd.runInternal(new MockInputRow(), "world", 1);
    vd.runInternal(new MockInputRow(), "foobar", 2);
    vd.runInternal(new MockInputRow(), "world", 1);
    vd.runInternal(new MockInputRow(), "hello", 3);
    vd.runInternal(new MockInputRow(), null, 1);
    vd.runInternal(new MockInputRow(), null, 3);

    final ValueCountingAnalyzerResult result = vd.getResult();

    final AnalyzerDescriptor<?> desc = Descriptors.ofAnalyzer(ValueDistributionAnalyzer.class);

    final MetricDescriptor metric = desc.getResultMetric("Value count");
    final Collection<String> suggestions = metric.getMetricParameterSuggestions(result);
    assertEquals("[hello, foobar, world]", suggestions.toString());

    assertEquals(4, metric.getValue(result, new MetricParameters("hello")));
    assertEquals(2, metric.getValue(result, new MetricParameters("world")));
    assertEquals(6, metric.getValue(result, new MetricParameters("IN [hello,world]")));
    assertEquals(8, metric.getValue(result, new MetricParameters("NOT IN [foobar,world]")));
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:26,
代码来源:ValueDistributionAnalyzerTest.java

示例10: testGetValueDistribution

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Test
public void testGetValueDistribution() {
    final ValueDistributionAnalyzer vd =
            new ValueDistributionAnalyzer(new MetaModelInputColumn(new MutableColumn("col")), true);

    vd.runInternal(new MockInputRow(), "hello", 1);
    vd.runInternal(new MockInputRow(), "hello", 1);
    vd.runInternal(new MockInputRow(), "world", 3);

    final ValueCountingAnalyzerResult result = vd.getResult();

    final ValueCountList topValues = ((SingleValueDistributionResult) result).getTopValues();
    assertEquals(2, topValues.getActualSize());
    assertEquals("[world->3]", topValues.getValueCounts().get(0).toString());
    assertEquals("[hello->2]", topValues.getValueCounts().get(1).toString());

    assertEquals(0, result.getNullCount());
    assertEquals(0, result.getUniqueCount().intValue());

    final String[] resultLines = result.toString().split("\n");
    assertEquals(3, resultLines.length);
    assertEquals("Value distribution for: col", resultLines[0]);
    assertEquals(" - world: 3", resultLines[1]);
    assertEquals(" - hello: 2", resultLines[2]);
}
 

开发者ID:datacleaner,
项目名称:DataCleaner,
代码行数:26,
代码来源:ValueDistributionAnalyzerTest.java

示例11: testAutoMapPartialMatches

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testAutoMapPartialMatches() throws Exception {
	Datastore datastore = TestHelper.createSampleDatabaseDatastore("testdb");

	SourceColumnMapping columnMapping = new SourceColumnMapping("PUBLIC.EMPLOYEES.FIRSTNAME", "foo.bar.col1",
			"PUBLIC.EMPLOYEES.LASTNAME", "foo.bar.col2");

	columnMapping.setColumn("foo.bar.col1", new MutableColumn("col1"));
	assertFalse(columnMapping.isSatisfied());
	assertEquals("[PUBLIC.EMPLOYEES.FIRSTNAME, PUBLIC.EMPLOYEES.LASTNAME, foo.bar.col2]", columnMapping
			.getUnmappedPaths().toString());

	columnMapping.autoMap(datastore);
	assertFalse(columnMapping.isSatisfied());
	assertEquals("[foo.bar.col2]", columnMapping.getUnmappedPaths().toString());

	columnMapping.setColumn("foo.bar.col2", new MutableColumn("col2"));
	assertTrue(columnMapping.isSatisfied());
}
 

开发者ID:datacleaner,
项目名称:AnalyzerBeans,
代码行数:19,
代码来源:SourceColumnMappingTest.java

示例12: testGetOutputColumns

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testGetOutputColumns() throws Exception {
	InputColumn<?> col = new MetaModelInputColumn(new MutableColumn("name"));

	@SuppressWarnings("unchecked")
	InputColumn<String> castColumn = (InputColumn<String>) col;
	TokenizerTransformer transformer = new TokenizerTransformer(castColumn, 2);

	OutputColumns oc = transformer.getOutputColumns();

	assertEquals(2, oc.getColumnCount());
	assertEquals("name (token 1)", oc.getColumnName(0));
	assertEquals("name (token 2)", oc.getColumnName(1));

	transformer = new TokenizerTransformer(castColumn, 1);
	assertEquals("OutputColumns[name (token 1)]", transformer.getOutputColumns().toString());

	transformer = new TokenizerTransformer(castColumn, 0);
	try {
		transformer.getOutputColumns();
		fail("Exception expected");
	} catch (IllegalArgumentException e) {
		assertEquals("Column names length must be 1 or greater", e.getMessage());
	}
}
 

开发者ID:datacleaner,
项目名称:AnalyzerBeans,
代码行数:25,
代码来源:TokenizerTransformerTest.java

示例13: testTransformToColumns

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testTransformToColumns() throws Exception {
	InputColumn<?> col = new MetaModelInputColumn(new MutableColumn("name"));

	@SuppressWarnings("unchecked")
	TokenizerTransformer transformer = new TokenizerTransformer((InputColumn<String>) col, 2);

	assertEquals(2, transformer.getOutputColumns().getColumnCount());

	MockInputRow row = new MockInputRow();
	row.put(col, "Kasper Sorensen");
	String[] values = transformer.transform(row);
	assertEquals(2, values.length);
	assertEquals("Kasper", values[0]);
	assertEquals("Sorensen", values[1]);

	row = new MockInputRow();
	row.put(col, "Kasper ");
	values = transformer.transform(row);
	assertEquals(2, values.length);
	assertEquals("Kasper", values[0]);
	assertNull(values[1]);
}
 

开发者ID:datacleaner,
项目名称:AnalyzerBeans,
代码行数:23,
代码来源:TokenizerTransformerTest.java

示例14: testTransformToRows

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testTransformToRows() throws Exception {
	InputColumn<?> col = new MetaModelInputColumn(new MutableColumn("name"));

	@SuppressWarnings("unchecked")
	TokenizerTransformer transformer = new TokenizerTransformer((InputColumn<String>) col, 2);
	transformer.tokenTarget = TokenTarget.ROWS;
	OutputRowCollector collectorMock = EasyMock.createMock(OutputRowCollector.class);
	transformer.outputRowCollector = collectorMock;

	assertEquals(1, transformer.getOutputColumns().getColumnCount());
	assertEquals("name (token)", transformer.getOutputColumns().getColumnName(0));
	
	collectorMock.putValues("Hello");
	collectorMock.putValues("world");

	EasyMock.replay(collectorMock);

	String[] result = transformer.transform(new MockInputRow().put(col, "Hello world"));
	assertNull(result);

	EasyMock.verify(collectorMock);
}
 

开发者ID:datacleaner,
项目名称:AnalyzerBeans,
代码行数:23,
代码来源:TokenizerTransformerTest.java

示例15: testConfigurableBeanConfiguration

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testConfigurableBeanConfiguration() throws Exception {
    AnalysisJobBuilder ajb = new AnalysisJobBuilder(new AnalyzerBeansConfigurationImpl());
    try {
        List<TableDataProvider<?>> tableDataProviders = Collections.emptyList();
        ajb.setDatastore(new PojoDatastore("ds", tableDataProviders));
        ajb.addSourceColumn(new MutableColumn("foo", ColumnType.VARCHAR));
        
        AnalyzerJobBuilder<CompletenessAnalyzer> analyzer = ajb.addAnalyzer(CompletenessAnalyzer.class);
        analyzer.getConfigurableBean().setValueColumns(ajb.getSourceColumns().toArray(new InputColumn[0]));
        analyzer.getConfigurableBean().fillAllConditions(Condition.NOT_BLANK_OR_NULL);
        
        assertTrue(analyzer.isConfigured(true));
    } finally {
        ajb.close();
    }
}
 

开发者ID:datacleaner,
项目名称:AnalyzerBeans,
代码行数:17,
代码来源:CompletenessAnalyzerTest.java

示例16: testGetValueCountMetric

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testGetValueCountMetric() throws Exception {
    ValueDistributionAnalyzer vd = new ValueDistributionAnalyzer(
            new MetaModelInputColumn(new MutableColumn("col")), true, null, null);
    vd.runInternal(new MockInputRow(), "hello", 1);
    vd.runInternal(new MockInputRow(), "world", 1);
    vd.runInternal(new MockInputRow(), "foobar", 2);
    vd.runInternal(new MockInputRow(), "world", 1);
    vd.runInternal(new MockInputRow(), "hello", 3);
    vd.runInternal(new MockInputRow(), null, 1);
    vd.runInternal(new MockInputRow(), null, 3);

    final ValueCountingAnalyzerResult result = vd.getResult();

    final AnalyzerBeanDescriptor<?> desc = Descriptors.ofAnalyzer(ValueDistributionAnalyzer.class);
    
    final MetricDescriptor metric = desc.getResultMetric("Value count");
    Collection<String> suggestions = metric.getMetricParameterSuggestions(result);
    assertEquals("[hello, foobar, world]", suggestions.toString());

    assertEquals(4, metric.getValue(result, new MetricParameters("hello")));
    assertEquals(2, metric.getValue(result, new MetricParameters("world")));
    assertEquals(6, metric.getValue(result, new MetricParameters("IN [hello,world]")));
    assertEquals(8, metric.getValue(result, new MetricParameters("NOT IN [foobar,world]")));
}
 

开发者ID:datacleaner,
项目名称:AnalyzerBeans,
代码行数:25,
代码来源:ValueDistributionAnalyzerTest.java

示例17: testGetValueDistribution

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testGetValueDistribution() throws Exception {
    ValueDistributionAnalyzer vd = new ValueDistributionAnalyzer(
            new MetaModelInputColumn(new MutableColumn("col")), true, null, null);

    vd.runInternal(new MockInputRow(), "hello", 1);
    vd.runInternal(new MockInputRow(), "hello", 1);
    vd.runInternal(new MockInputRow(), "world", 3);

    ValueCountingAnalyzerResult result = vd.getResult();
    
    ValueCountList topValues = ((SingleValueDistributionResult)result).getTopValues();
    assertEquals(2, topValues.getActualSize());
    assertEquals("[world->3]", topValues.getValueCounts().get(0).toString());
    assertEquals("[hello->2]", topValues.getValueCounts().get(1).toString());

    assertEquals(0, result.getNullCount());
    assertEquals(0, result.getUniqueCount().intValue());

    String[] resultLines = result.toString().split("\n");
    assertEquals(3, resultLines.length);
    assertEquals("Value distribution for: col", resultLines[0]);
    assertEquals(" - world: 3", resultLines[1]);
    assertEquals(" - hello: 2", resultLines[2]);
}
 

开发者ID:datacleaner,
项目名称:AnalyzerBeans,
代码行数:25,
代码来源:ValueDistributionAnalyzerTest.java

示例18: getMainSchema

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Override
protected Schema getMainSchema() throws MetaModelException {
    MutableSchema schema = new MutableSchema(getTransformationName());
    MutableTable table = new MutableTable(getStepName(), TableType.TABLE);
    table.setSchema(schema);
    RowMetaInterface rowMeta = getRowMeta();
    for (int i = 0; i < rowMeta.size(); i++) {
        ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
        MutableColumn column = new MutableColumn(valueMeta.getName(), getColumnType(valueMeta), table, i,
                Integer.valueOf(valueMeta.getLength()), valueMeta.getTypeDesc(), true, valueMeta.getComments(),
                false, "");
        table.addColumn(column);
    }
    schema.addTable(table);
    return schema;
}
 

开发者ID:datacleaner,
项目名称:pdi-datacleaner,
代码行数:17,
代码来源:KettleDataContext.java

示例19: createColumns

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
/**
 * Builds columns based on row/cell values.
 * 
 * @param table
 * @param wb
 * @param row
 */
private void createColumns(MutableTable table, Workbook wb, Row row) {
    if (row == null) {
        logger.warn("Cannot create columns based on null row!");
        return;
    }
    final short rowLength = row.getLastCellNum();

    final int offset = getColumnOffset(row);

    // build columns based on cell values.
    try (final ColumnNamingSession columnNamingSession = _configuration.getColumnNamingStrategy()
            .startColumnNamingSession()) {
        for (int j = offset; j < rowLength; j++) {
            final Cell cell = row.getCell(j);
            final String intrinsicColumnName = ExcelUtils.getCellValue(wb, cell);
            final ColumnNamingContext columnNamingContext = new ColumnNamingContextImpl(table, intrinsicColumnName,
                    j);
            final String columnName = columnNamingSession.getNextColumnName(columnNamingContext);
            final Column column = new MutableColumn(columnName, ColumnType.VARCHAR, table, j, true);
            table.addColumn(column);
        }
    }
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:31,
代码来源:DefaultSpreadsheetReaderDelegate.java

示例20: loadPrimaryKeys

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
private void loadPrimaryKeys(JdbcTable table, DatabaseMetaData metaData) throws MetaModelException {
    Schema schema = table.getSchema();
    try (ResultSet rs = metaData.getPrimaryKeys(getCatalogName(schema), getJdbcSchemaName(schema), table
            .getName());) {
        while (rs.next()) {
            String columnName = rs.getString(4);
            if (columnName != null) {
                MutableColumn column = (MutableColumn) table.getColumnByName(columnName);
                if (column != null) {
                    column.setPrimaryKey(true);
                } else {
                    logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table);
                }
            }
        }
    } catch (SQLException e) {
        throw JdbcUtils.wrapException(e, "retrieve primary keys for " + table.getName(), JdbcActionType.METADATA);
    }
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:20,
代码来源:JdbcMetadataLoader.java

示例21: loadIndexes

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
private void loadIndexes(Table table, DatabaseMetaData metaData) throws MetaModelException {
    Schema schema = table.getSchema();

    // Ticket #170: IndexInfo is nice-to-have, not need-to-have, so
    // we will do a nice failover on SQLExceptions
    try (ResultSet rs = metaData.getIndexInfo(getCatalogName(schema), getJdbcSchemaName(schema), table.getName(),
            false, true)) {
        while (rs.next()) {
            String columnName = rs.getString(9);
            if (columnName != null) {
                MutableColumn column = (MutableColumn) table.getColumnByName(columnName);
                if (column != null) {
                    column.setIndexed(true);
                } else {
                    logger.error("Indexed column \"{}\" could not be found in table: {}", columnName, table);
                }
            }
        }
    } catch (SQLException e) {
        throw JdbcUtils.wrapException(e, "retrieve index information for " + table.getName(), JdbcActionType.METADATA);
    }
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:23,
代码来源:JdbcMetadataLoader.java

示例22: testManyColumnsScenario

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testManyColumnsScenario() throws Exception {
	Column[] cols = new Column[110];
	for (int i = 0; i < cols.length; i++) {
		MutableColumn col = new MutableColumn("foo" + i);
		if (i % 5 == 0) {
			col.setType(ColumnType.INTEGER);
		} else if (i % 4 == 0) {
			col.setType(ColumnType.BOOLEAN);
		} else if (i % 3 == 0) {
			col.setType(ColumnType.DATE);
		} else {
			col.setType(ColumnType.VARCHAR);
		}

		col.setColumnSize(50);
		cols[i] = col;
	}

	FetchSizeCalculator calc = new FetchSizeCalculator(32 * 1024 * 1024);

	assertEquals(613, calc.getFetchSize(cols));
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:23,
代码来源:FetchSizeCalculatorTest.java

示例23: testInsertNullMap

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Test
public void testInsertNullMap() throws SQLException {
    final PreparedStatement statementMock = EasyMock.createMock(PreparedStatement.class);

    final PostgresqlQueryRewriter queryRewriter = new PostgresqlQueryRewriter(null);
    final Column column = new MutableColumn("col").setType(ColumnType.MAP).setNativeType("jsonb");
    final Object value = null;

    // mock behaviour recording
    statementMock.setObject(0, null);

    EasyMock.replay(statementMock);

    queryRewriter.setStatementParameter(statementMock, 0, column, value);

    EasyMock.verify(statementMock);
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:18,
代码来源:PostgresqlQueryRewriterTest.java

示例24: setUp

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    table = new MutableTable("foo");
    table.setSchema(new MutableSchema("MY_SCHEMA"));
    table.setQuote("\"");
    column = new MutableColumn("bar");
    column.setQuote("\"");
    column.setTable(table);

    final JdbcDataContext mockContext = EasyMock.createMock(JdbcDataContext.class);
    EasyMock.expect(mockContext.getDatabaseProductName()).andReturn(DATABASE_PRODUCT_SQLSERVER).anyTimes();
    EasyMock.expect(mockContext.getDatabaseVersion()).andReturn("12.1.1.1").anyTimes();
    EasyMock.expect(mockContext.getIdentifierQuoteString()).andReturn("quoteString").anyTimes();

    EasyMock.replay(mockContext);
    qr = new SQLServerQueryRewriter(mockContext);
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:19,
代码来源:SQLServerQueryRewriterTest.java

示例25: testRewriteFilterItem

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testRewriteFilterItem() {

        MutableColumn timestampColumn = new MutableColumn("timestamp");
        timestampColumn.setType(ColumnType.TIMESTAMP);
        timestampColumn.setNativeType("DATETIME");
        Query q = new Query()
                .from(table)
                .select(column)
                .select(timestampColumn)
                .where(new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN, TimeComparator
                        .toDate("2014-06-28 14:06:00.123")));

        assertEquals(
                "SELECT MY_SCHEMA.\"foo\".\"bar\", timestamp FROM MY_SCHEMA.\"foo\" WHERE timestamp < CAST('20140628 14:06:00.123' AS DATETIME)",
                qr.rewriteQuery(q));
    }
 

开发者ID:apache,
项目名称:metamodel,
代码行数:17,
代码来源:SQLServerQueryRewriterTest.java

示例26: testFullyQualifiedColumnNames

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testFullyQualifiedColumnNames() throws Exception {
    final MutableSchema schema = new MutableSchema("sch");
    final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
    final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
    final MutableColumn ageColumn = new MutableColumn("age", ColumnType.INTEGER).setTable(table);
    schema.addTable(table);
    table.addColumn(nameColumn);
    table.addColumn(ageColumn);

    final Query q = new Query();
    q.select(ageColumn).selectCount();
    q.from(table);
    q.where(ageColumn, OperatorType.GREATER_THAN, 18);
    q.groupBy(ageColumn);
    q.having(FunctionType.COUNT, nameColumn, OperatorType.LESS_THAN, 100);
    q.orderBy(ageColumn);

    final String sql = new DB2QueryRewriter(null).rewriteQuery(q);

    assertEquals("SELECT sch.tab.age, COUNT(*) FROM sch.tab WHERE sch.tab.age > 18 "
            + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", sql);
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:23,
代码来源:DB2QueryRewriterTest.java

示例27: testFullyQualifiedColumnNamesWithFilterItemContainingTimestamp

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testFullyQualifiedColumnNamesWithFilterItemContainingTimestamp() throws Exception {
    final MutableSchema schema = new MutableSchema("sch");
    final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
    final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
    final MutableColumn dateColumn = new MutableColumn("age", ColumnType.TIMESTAMP).setTable(table);
    schema.addTable(table);
    table.addColumn(nameColumn);
    table.addColumn(dateColumn);

    final Query q = new Query();
    q.select(dateColumn).selectCount();
    q.from(table);
    q.where(dateColumn, OperatorType.GREATER_THAN, "2012-10-31 08:09:54");
    q.groupBy(dateColumn);
    q.having(FunctionType.COUNT, nameColumn, OperatorType.LESS_THAN, 100);
    q.orderBy(dateColumn);

    final String sql = new DB2QueryRewriter(null).rewriteQuery(q);

    assertEquals("SELECT sch.tab.age, COUNT(*) FROM sch.tab WHERE sch.tab.age > TIMESTAMP ('2012-10-31 08:09:54') "
            + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", sql);
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:23,
代码来源:DB2QueryRewriterTest.java

示例28: getMainSchema

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Override
protected Schema getMainSchema() throws MetaModelException {
    final MutableSchema theSchema = new MutableSchema(getMainSchemaName());
    for (final SimpleTableDef tableDef : tableDefs) {
        final MutableTable table = tableDef.toTable().setSchema(theSchema);

        final TableMetadata cassandraTable = cassandraCluster.getMetadata().getKeyspace(keySpaceName).getTable(table
                .getName());
        if (cassandraTable != null) {
            final List<ColumnMetadata> primaryKeys = cassandraTable.getPrimaryKey();
            for (ColumnMetadata primaryKey : primaryKeys) {
                final MutableColumn column = (MutableColumn) table.getColumnByName(primaryKey.getName());
                if (column != null) {
                    column.setPrimaryKey(true);
                }
                column.setNativeType(primaryKey.getType().getName().name());
            }
        }

        theSchema.addTable(table);
    }
    return theSchema;
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:24,
代码来源:CassandraDataContext.java

示例29: testCreateRowWithParsableDates

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testCreateRowWithParsableDates() throws Exception {
    SelectItem item1 = new SelectItem(new MutableColumn("value1", ColumnType.STRING));
    SelectItem item2 = new SelectItem(new MutableColumn("value2", ColumnType.DATE));
    List<SelectItem> selectItems1 = Arrays.asList(item1, item2);
    String documentId = "doc1";
    DataSetHeader header = new SimpleDataSetHeader(selectItems1);
    Map<String, Object> values = new HashMap<>();
    values.put("value1", "theValue");
    values.put("value2", "2013-01-04T15:55:51.217+01:00");
    Row row = ElasticSearchUtils.createRow(values, documentId, header);
    Object stringValue = row.getValue(item1);
    Object dateValue = row.getValue(item2);

    assertTrue(stringValue instanceof String);
    assertTrue(dateValue instanceof Date);
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:17,
代码来源:ElasticSearchUtilsTest.java

示例30: testRewriteWhereItem

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testRewriteWhereItem() throws Exception {
    final StringBuilder sb = new StringBuilder("FOOBAR: ");

    final Date date = DateUtils.get(2013, Month.JANUARY, 23);
    final Timestamp dateTime = new Timestamp(0l);

    final List<FilterItem> children = new ArrayList<FilterItem>();
    children.add(new FilterItem(new SelectItem(new MutableColumn("foo")), OperatorType.EQUALS_TO, "hello\n 'world'"));
    children.add(new FilterItem(new SelectItem(new MutableColumn("bar")), OperatorType.EQUALS_TO, 123));
    children.add(new FilterItem(new SelectItem(new MutableColumn("baz").setType(ColumnType.DATE)),
            OperatorType.EQUALS_TO, date));
    children.add(new FilterItem(new SelectItem(new MutableColumn("saz").setType(ColumnType.TIMESTAMP)),
            OperatorType.EQUALS_TO, dateTime));

    final FilterItem filterItem = new FilterItem(children);

    SalesforceDataContext.rewriteFilterItem(sb, filterItem);

    assertEquals(
            "FOOBAR: (foo = 'hello\\n \\'world\\'' OR bar = 123 OR baz = 2013-01-23 OR saz = 1970-01-01T00:00:00+0000)",
            sb.toString());
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:23,
代码来源:SalesforceDataContextTest.java

示例31: getMainSchema

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Override
protected Schema getMainSchema() throws MetaModelException {
    if (_schema == null) {
        MutableSchema schema = new MutableSchema(getMainSchemaName());
        for (SimpleTableDef tableDef : _tableDefs) {

            MutableTable table = tableDef.toTable().setSchema(schema);
            List<Column> rowIdColumns = table.getColumnsOfType(ColumnType.ROWID);
            for (Column column : rowIdColumns) {
                if (column instanceof MutableColumn) {
                    ((MutableColumn) column).setPrimaryKey(true);
                }
            }

            schema.addTable(table);
        }

        _schema = schema;
    }
    return _schema;
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:22,
代码来源:MongoDbDataContext.java

示例32: getMainSchema

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Override
protected Schema getMainSchema() throws MetaModelException {
    if (_schema == null) {
        MutableSchema schema = new MutableSchema(getMainSchemaName());
        for (SimpleTableDef tableDef : _tableDefs) {

            MutableTable table = tableDef.toTable().setSchema(schema);
            for (Column column : table.getColumnsOfType(ColumnType.ROWID)) {
                if (column instanceof MutableColumn) {
                    ((MutableColumn) column).setPrimaryKey(true);
                }
            }

            schema.addTable(table);
        }

        _schema = schema;
    }
    return _schema;
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:21,
代码来源:MongoDbDataContext.java

示例33: testEqualsAndHashCode

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testEqualsAndHashCode() throws Exception {
    MutableSchema schema = new MutableSchema("schema");
    MutableTable table = new MutableTable("table").setSchema(schema);
    schema.addTable(table);

    Column col1 = new MutableColumn("col1").setTable(table);
    Column col2 = new MutableColumn("col2").setTable(table);
    Column col3 = new MutableColumn("col3").setTable(table);
    table.addColumn(col1);
    table.addColumn(col2);
    table.addColumn(col3);

    Query q1 = new Query().select(col1, col2).from(table).where(col3, OperatorType.EQUALS_TO, "m'jello");

    Query q2 = new InitFromBuilderImpl(null).from(table).select(col1).and(col2).where(col3).eq("m'jello").toQuery();

    assertEquals(q1, q2);
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:19,
代码来源:QueryTest.java

示例34: testToSqlWithFullyQualifiedColumnNames

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testToSqlWithFullyQualifiedColumnNames() throws Exception {
    final MutableSchema schema = new MutableSchema("sch");
    final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
    final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
    final MutableColumn ageColumn = new MutableColumn("age", ColumnType.INTEGER).setTable(table);
    schema.addTable(table);
    table.addColumn(nameColumn);
    table.addColumn(ageColumn);

    final Query q = new Query();
    q.select(ageColumn).selectCount();
    q.from(table);
    q.where(ageColumn, OperatorType.GREATER_THAN, 18);
    q.groupBy(ageColumn);
    q.having(FunctionType.COUNT, nameColumn, OperatorType.LESS_THAN, 100);
    q.orderBy(ageColumn);

    assertEquals("SELECT sch.tab.age, COUNT(*) FROM sch.tab WHERE sch.tab.age > 18 "
            + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", q.toSql(true));
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:21,
代码来源:QueryTest.java

示例35: testExpressionBasedFilter

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testExpressionBasedFilter() throws Exception {
    FilterItem filterItem = new FilterItem("foobar");
    assertEquals("foobar", filterItem.getExpression());

    try {
        filterItem.evaluate(null);
        fail("Exception should have been thrown");
    } catch (Exception e) {
        assertEquals("Expression-based filters cannot be manually evaluated", e.getMessage());
    }

    Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
    assertEquals("SELECT Col1 WHERE foobar", new Query().select(col1).where(filterItem).toString());

    assertEquals("SELECT Col1 WHERE YEAR(Col1) = 2008", new Query().select(col1).where("YEAR(Col1) = 2008")
            .toString());
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:18,
代码来源:FilterItemTest.java

示例36: testEqualsAndHashCode

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
/**
 * Tests that the following (general) rules apply to the object:
 * <p/>
 * <li>the hashcode is the same when run twice on an unaltered object</li>
 * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
 * 02.hashCode()
 */
public void testEqualsAndHashCode() throws Exception {
    Column col1 = new MutableColumn("Col1", ColumnType.BIT);

    FilterItem c1 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
    FilterItem c2 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
    assertEquals(c1, c2);
    assertEquals(c1.hashCode(), c2.hashCode());

    c2 = new FilterItem(new SelectItem(col1), OperatorType.GREATER_THAN, true);
    assertFalse(c1.equals(c2));
    assertFalse(c1.hashCode() == c2.hashCode());

    Column col2 = new MutableColumn("Col2", ColumnType.VARBINARY);
    c2 = new FilterItem(new SelectItem(col2), OperatorType.EQUALS_TO, true);
    assertFalse(c1.equals(c2));
    assertFalse(c1.hashCode() == c2.hashCode());
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:25,
代码来源:FilterItemTest.java

示例37: testOrFilterItem

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testOrFilterItem() throws Exception {
    Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);

    SelectItem s1 = new SelectItem(col1);
    FilterItem c1 = new FilterItem(s1, OperatorType.EQUALS_TO, "foo");
    FilterItem c2 = new FilterItem(s1, OperatorType.EQUALS_TO, "bar");
    FilterItem c3 = new FilterItem(s1, OperatorType.EQUALS_TO, "foobar");

    FilterItem filter = new FilterItem(c1, c2, c3);
    assertEquals("(Col1 = 'foo' OR Col1 = 'bar' OR Col1 = 'foobar')", filter.toString());

    DataSetHeader header = new SimpleDataSetHeader(new SelectItem[] { s1 });

    assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
    assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "bar" })));
    assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));

    assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foob" })));
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:20,
代码来源:FilterItemTest.java

示例38: testAndFilterItem

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testAndFilterItem() throws Exception {
    Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);

    SelectItem s1 = new SelectItem(col1);
    FilterItem c1 = new FilterItem(s1, OperatorType.LIKE, "foo%");
    FilterItem c2 = new FilterItem(s1, OperatorType.LIKE, "%bar");
    FilterItem c3 = new FilterItem(s1, OperatorType.DIFFERENT_FROM, "foobar");

    FilterItem filter = new FilterItem(LogicalOperator.AND, c1, c2, c3);
    assertEquals("(Col1 LIKE 'foo%' AND Col1 LIKE '%bar' AND Col1 <> 'foobar')", filter.toString());

    CachingDataSetHeader header = new CachingDataSetHeader(Lists.newArrayList(s1));
    assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo bar" })));
    assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foosenbar" })));
    assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
    assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "hello world" })));
    assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:19,
代码来源:FilterItemTest.java

示例39: testToTableModel

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
public void testToTableModel() throws Exception {
    SelectItem[] selectItems = MetaModelHelper.createSelectItems(new MutableColumn("CUSTOMERNUMBER"),
            new MutableColumn("CUSTOMERNAME"), new MutableColumn("CONTACTLASTNAME"));
    CachingDataSetHeader header = new CachingDataSetHeader(Lists.newArrayList(selectItems));
    List<Row> rows = new ArrayList<Row>();
    rows.add(new DefaultRow(header, new Object[] { 1, "John", "Doe" }));
    rows.add(new DefaultRow(header, new Object[] { 2, "John", "Taylor" }));
    DataSet data = new InMemoryDataSet(header, rows);

    TableModel tableModel = new DataSetTableModel(data);
    data.close();

    assertEquals(3, tableModel.getColumnCount());
    assertEquals("CUSTOMERNUMBER", tableModel.getColumnName(0));
    assertEquals("CUSTOMERNAME", tableModel.getColumnName(1));
    assertEquals("CONTACTLASTNAME", tableModel.getColumnName(2));
    assertEquals(2, tableModel.getRowCount());

    // Take a small sample from the data
    assertEquals("Taylor", tableModel.getValueAt(1, 2).toString());
    
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:23,
代码来源:DataSetTableModelTest.java

示例40: testGetTables

点赞 3

import org.apache.metamodel.schema.MutableColumn; //导入依赖的package包/类
@Test
public void testGetTables() throws Exception {
    MutableTable table1 = new MutableTable("table1");
    MutableTable table2 = new MutableTable("table2");
    MutableColumn t1column1 = new MutableColumn("t1c1", ColumnType.BIGINT);
    MutableColumn t2column1 = new MutableColumn("t2c1", ColumnType.BIGINT);
    MutableColumn t2column2 = new MutableColumn("t2c2", ColumnType.BIGINT);
    table1.addColumn(t1column1);
    t1column1.setTable(table1);
    table2.addColumn(t2column1);
    t2column1.setTable(table2);
    table2.addColumn(t2column2);
    t2column2.setTable(table2);

    ArrayList<Table> tableList = new ArrayList<Table>();
    tableList.add(table1);

    ArrayList<Column> columnList = new ArrayList<Column>();
    columnList.add(t2column1);

    Table[] tables = MetaModelHelper.getTables(tableList, columnList);
    assertEquals(2, tables.length);
    assertTrue(Arrays.asList(tables).contains(table1));
    assertTrue(Arrays.asList(tables).contains(table2));
}
 

开发者ID:apache,
项目名称:metamodel,
代码行数:26,
代码来源:MetaModelHelperTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)