本文整理汇总了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);
}
示例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);
}
示例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.");
}
示例4: shouldThrowForStringAndNumberColumn
@Test(expected = IllegalArgumentException.class)
public void shouldThrowForStringAndNumberColumn() {
final Column numberColumn = new MutableColumn("foo", ColumnType.NUMERIC);
TypeConverter.convertType("bla", numberColumn);
}
示例5: shouldThrowForDataAndNumberColumn
public void shouldThrowForDataAndNumberColumn() {
final Column numberColumn = new MutableColumn("foo", ColumnType.NUMERIC);
TypeConverter.convertType(dateValue, numberColumn);
}
示例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);
}