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


Java ColumnType.NUMERIC属性代码示例

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


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

示例1: shouldReturnNumberForNumberColumn

@Test
public void shouldReturnNumberForNumberColumn() {
    final Column numberColumn = new MutableColumn("foo", ColumnType.NUMERIC);

    Object result = TypeConverter.convertType(24, numberColumn);
    assertTrue(result instanceof Number);
    assertEquals(24, result);

    result = TypeConverter.convertType(24.3d, numberColumn);
    assertTrue(result instanceof Number);
    assertEquals(24.3, result);

    result = TypeConverter.convertType("33", numberColumn);
    assertTrue(result instanceof Number);
    assertEquals(33L, result);

    result = TypeConverter.convertType("33.3", numberColumn);
    assertTrue(result instanceof Number);
    assertEquals(33.3, result);

    result = TypeConverter.convertType(true, numberColumn);
    assertTrue(result instanceof Number);
    assertEquals(1, result);

    result = TypeConverter.convertType(false, numberColumn);
    assertTrue(result instanceof Number);
    assertEquals(0, result);

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

示例2: rewriteColumnType

@Override
public String rewriteColumnType(ColumnType columnType, Integer columnSize) {
    if (columnType == ColumnType.NUMERIC) {
        return super.rewriteColumnType(ColumnType.DECIMAL, columnSize);
    }
    if (columnType.isLiteral() && columnSize == null) {
        if (columnType == ColumnType.STRING || columnType == ColumnType.VARCHAR
                || columnType == ColumnType.NVARCHAR) {
            // MySQL requires size to be specified, so instead we choose the
            // text type
            return "TEXT";
        }
    }
    return super.rewriteColumnType(columnType, columnSize);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:15,代码来源:MysqlQueryRewriter.java

示例3: getType

/**
 * Determines the best fitting type. For reference of ElasticSearch types,
 * see
 *
 * <pre>
 * http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html
 * </pre>
 *
 *
 * @param column
 * @return
 */
private static String getType(Column column) {
    String nativeType = column.getNativeType();
    if (!Strings.isNullOrEmpty(nativeType)) {
        return nativeType;
    }

    final ColumnType type = column.getType();
    if (type == null) {
        throw new IllegalStateException("No column type specified for '" + column.getName()
                + "' - cannot build ElasticSearch mapping without type.");
    }

    if (type.isLiteral()) {
        return "text";
    } else if (type == ColumnType.FLOAT) {
        return "float";
    } else if (type == ColumnType.DOUBLE || type == ColumnType.NUMERIC || type == ColumnType.NUMBER) {
        return "double";
    } else if (type == ColumnType.SMALLINT) {
        return "short";
    } else if (type == ColumnType.TINYINT) {
        return "byte";
    } else if (type == ColumnType.INTEGER) {
        return "integer";
    } else if (type == ColumnType.DATE || type == ColumnType.TIMESTAMP) {
        return "date";
    } else if (type == ColumnType.BINARY || type == ColumnType.VARBINARY) {
        return "binary";
    } else if (type == ColumnType.BOOLEAN || type == ColumnType.BIT) {
        return "boolean";
    } else if (type == ColumnType.MAP) {
        return "object";
    }

    throw new UnsupportedOperationException("Unsupported column type '" + type.getName() + "' of column '" + column
            .getName() + "' - cannot translate to an ElasticSearch type.");
}
 
开发者ID:apache,项目名称:metamodel,代码行数:49,代码来源:ElasticSearchUtils.java

示例4: shouldThrowForStringAndNumberColumn

@Test(expected = IllegalArgumentException.class)
public void shouldThrowForStringAndNumberColumn() {
    final Column numberColumn = new MutableColumn("foo", ColumnType.NUMERIC);
    TypeConverter.convertType("bla", numberColumn);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:5,代码来源:TypeConverterTest.java

示例5: shouldThrowForDataAndNumberColumn

public void shouldThrowForDataAndNumberColumn() {
    final Column numberColumn = new MutableColumn("foo", ColumnType.NUMERIC);
    TypeConverter.convertType(dateValue, numberColumn);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:4,代码来源:TypeConverterTest.java

示例6: rewriteColumnType

@Override
public String rewriteColumnType(ColumnType columnType, Integer columnSize) {
    if (columnType == ColumnType.NUMBER || columnType == ColumnType.NUMERIC || columnType == ColumnType.DECIMAL) {
        // as one of the only relational databases out there, Oracle has a
        // NUMBER type. For this reason NUMBER would be replaced by the
        // super-type's logic, but we handle it specifically here.
        super.rewriteColumnTypeInternal("NUMBER", columnSize);
    }
    if (columnType == ColumnType.BOOLEAN || columnType == ColumnType.BIT) {
        // Oracle has no boolean type, but recommends NUMBER(3) or CHAR(1).
        // For consistency with most other databases who have either a
        // boolean or a bit, we use the number variant because it's return
        // values (0 or 1) can be converted the most easily back to a
        // boolean.
        return "NUMBER(3)";
    }
    if (columnType == ColumnType.DOUBLE) {
        return "BINARY_DOUBLE";
    }
    if (columnType == ColumnType.FLOAT) {
        return "BINARY_FLOAT";
    }
    if (columnType == ColumnType.BINARY || columnType == ColumnType.VARBINARY) {
        return "RAW";
    }

    // following conversions based on
    // http://docs.oracle.com/cd/B19306_01/gateways.102/b14270/apa.htm
    if (columnType == ColumnType.TINYINT) {
        return "NUMBER(3)";
    }
    if (columnType == ColumnType.SMALLINT) {
        return "NUMBER(5)";
    }
    if (columnType == ColumnType.INTEGER) {
        return "NUMBER(10)";
    }
    if (columnType == ColumnType.BIGINT) {
        return "NUMBER(19)";
    }

    // Oracle has no "time only" data type but 'date' also includes time
    if (columnType == ColumnType.TIME) {
        super.rewriteColumnType(ColumnType.DATE, columnSize);
    }
    return super.rewriteColumnType(columnType, columnSize);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:47,代码来源:OracleQueryRewriter.java


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