本文整理汇总了Java中org.apache.metamodel.schema.ColumnType.DATE属性的典型用法代码示例。如果您正苦于以下问题:Java ColumnType.DATE属性的具体用法?Java ColumnType.DATE怎么用?Java ColumnType.DATE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.metamodel.schema.ColumnType
的用法示例。
在下文中一共展示了ColumnType.DATE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
private Object convert(String stringValue, ColumnType type) {
if (stringValue == null || stringValue.length() == 0) {
return null;
}
if (type == ColumnType.FLOAT) {
return Float.parseFloat(stringValue);
} else if (type == ColumnType.DOUBLE) {
return Double.parseDouble(stringValue);
} else if (type == ColumnType.DATE) {
try {
Date date = new SimpleDateFormat("yyyyMMdd").parse(stringValue);
return date;
} catch (ParseException e) {
throw new IllegalArgumentException(stringValue);
}
} else {
return stringValue;
}
}
示例2: getColumnType
private ColumnType getColumnType(ValueMetaInterface valueMeta) {
switch (valueMeta.getType()) {
case ValueMetaInterface.TYPE_STRING:
return ColumnType.VARCHAR;
case ValueMetaInterface.TYPE_INTEGER:
return ColumnType.INTEGER;
case ValueMetaInterface.TYPE_DATE:
return ColumnType.DATE;
case ValueMetaInterface.TYPE_BOOLEAN:
return ColumnType.BOOLEAN;
case ValueMetaInterface.TYPE_NUMBER:
return ColumnType.DOUBLE;
case ValueMetaInterface.TYPE_BINARY:
return ColumnType.BINARY;
case ValueMetaInterface.TYPE_BIGNUMBER:
return ColumnType.DECIMAL;
}
throw new RuntimeException("It is currently not possible to profile values of type: " + valueMeta.getTypeDesc());
}
示例3: getColumnTypeFromElasticSearchType
public static ColumnType getColumnTypeFromElasticSearchType(final String metaDataFieldType) {
final ColumnType columnType;
if (metaDataFieldType.startsWith("date")) {
columnType = ColumnType.DATE;
} else if (metaDataFieldType.equals("long")) {
columnType = ColumnType.BIGINT;
} else if (metaDataFieldType.equals("string")) {
columnType = ColumnType.STRING;
} else if (metaDataFieldType.equals("float")) {
columnType = ColumnType.FLOAT;
} else if (metaDataFieldType.equals("boolean")) {
columnType = ColumnType.BOOLEAN;
} else if (metaDataFieldType.equals("double")) {
columnType = ColumnType.DOUBLE;
} else {
columnType = ColumnType.STRING;
}
return columnType;
}
示例4: testCreateRowWithParsableDates
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);
}
示例5: 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.");
}
示例6: convert
private Object convert(Object value, ColumnType columnType) {
if (value instanceof String && !columnType.isLiteral()) {
if (columnType.isBoolean()) {
return BooleanComparator.toBoolean(value);
}
if (columnType.isNumber()) {
return NumberComparator.toNumber(value);
}
if (columnType.isTimeBased()) {
final SimpleDateFormat dateFormat;
if (columnType == ColumnType.DATE) {
// note: we don't apply the timezone for DATE fields, since
// they don't contain time-of-day information.
dateFormat = new SimpleDateFormat(SalesforceDataContext.SOQL_DATE_FORMAT_IN, Locale.ENGLISH);
} else if (columnType == ColumnType.TIME) {
dateFormat = new SimpleDateFormat(SalesforceDataContext.SOQL_TIME_FORMAT_IN, Locale.ENGLISH);
dateFormat.setTimeZone(SalesforceDataContext.SOQL_TIMEZONE);
} else {
dateFormat = new SimpleDateFormat(SalesforceDataContext.SOQL_DATE_TIME_FORMAT_IN, Locale.ENGLISH);
dateFormat.setTimeZone(SalesforceDataContext.SOQL_TIMEZONE);
}
try {
return dateFormat.parse(value.toString());
} catch (ParseException e) {
throw new IllegalStateException("Unable to parse date/time value: " + value);
}
}
}
return value;
}
示例7: toColumnType
protected static ColumnType toColumnType(FieldType type) {
switch (type) {
case _boolean:
return ColumnType.BOOLEAN;
case _int:
return ColumnType.INTEGER;
case _double:
case currency:
return ColumnType.DOUBLE;
case date:
return ColumnType.DATE;
case datetime:
return ColumnType.TIMESTAMP;
case time:
return ColumnType.TIME;
case string:
case email:
case url:
case phone:
case reference:
case textarea:
case encryptedstring:
case base64:
case id:
case picklist:
return ColumnType.VARCHAR;
default:
return ColumnType.OTHER;
}
}
示例8: formatSqlTime
/**
* Formats a date according to a specific column type (DATE, TIME or
* TIMESTAMP)
*
* @param columnType
* the column type
* @param date
* the date value
* @param typeCastDeclaration
* whether or not to include a type cast declaration
* @param beforeDateLiteral
* before date literal
* @param afterDateLiteral
* after date literal
* @return
*/
public static String formatSqlTime(ColumnType columnType, Date date, boolean typeCastDeclaration,
String beforeDateLiteral, String afterDateLiteral) {
if (columnType == null) {
throw new IllegalArgumentException("Column type cannot be null");
}
final DateFormat format;
final String typePrefix;
if (columnType.isTimeBased()) {
if (columnType == ColumnType.DATE) {
format = DateUtils.createDateFormat("yyyy-MM-dd");
typePrefix = "DATE";
} else if (columnType == ColumnType.TIME) {
format = DateUtils.createDateFormat("HH:mm:ss");
typePrefix = "TIME";
} else {
format = DateUtils.createDateFormat("yyyy-MM-dd HH:mm:ss");
typePrefix = "TIMESTAMP";
}
} else {
throw new IllegalArgumentException("Cannot format time value of type: " + columnType);
}
if (typeCastDeclaration) {
return typePrefix + " " + beforeDateLiteral + format.format(date) + afterDateLiteral;
} else {
return format.format(date);
}
}
示例9: parseSqlTime
/**
* Parses a SQL string representation of a time based value
*
* @param columnType
* @param value
* @return
*/
public static Date parseSqlTime(ColumnType columnType, String value) {
final String[] formats;
if (columnType.isTimeBased()) {
if (columnType == ColumnType.DATE) {
value = DATE_PATTERN.matcher(value).replaceFirst("$1");
formats = new String[] { "yyyy-MM-dd" };
} else if (columnType == ColumnType.TIME) {
value = TIME_PATTERN.matcher(value).replaceFirst("$1");
formats = new String[] { "HH:mm:ss.SSS", "HH:mm:ss", "HH:mm" };
} else {
value = TIMESTAMP_PATTERN.matcher(value).replaceFirst("$1");
formats = new String[] { "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd" };
}
} else {
throw new IllegalArgumentException("Cannot parse time value of type: " + columnType);
}
for (String format : formats) {
try {
DateFormat dateFormat = DateUtils.createDateFormat(format);
return dateFormat.parse(value);
} catch (ParseException e) {
// proceed to next format
}
}
throw new IllegalArgumentException("String value '" + value + "' not parseable as a " + columnType);
}
示例10: testToStringTimeStamp
public void testToStringTimeStamp() throws Exception {
Column timestampColumn = new MutableColumn("TimestampCol", ColumnType.TIMESTAMP);
FilterItem c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN,
"2000-12-31 02:30:05.007");
assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN, "2000-12-31 02:30:05");
assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
c = new FilterItem(new SelectItem(timestampColumn), OperatorType.GREATER_THAN, new SelectItem(dateColumn));
assertEquals("TimestampCol > DateCol", c.toString());
}
示例11: getAvailableColumnTypes
private ColumnType[] getAvailableColumnTypes() {
return new ColumnType[] { ColumnType.VARCHAR, ColumnType.DECIMAL, ColumnType.INTEGER, ColumnType.BOOLEAN,
ColumnType.DATE, ColumnType.TIME, ColumnType.TIMESTAMP, ColumnType.MAP, ColumnType.LIST,
ColumnType.BINARY };
}
示例12: getMainSchema
@Override
protected Schema getMainSchema() throws MetaModelException {
DBF dbf = getDbf();
String schemaName = dbf.getName();
int separatorIndex = Math.max(schemaName.lastIndexOf('/'), schemaName.lastIndexOf('\\'));
if (separatorIndex != -1) {
schemaName = schemaName.substring(separatorIndex + 1);
}
MutableSchema schema = new MutableSchema(schemaName);
MutableTable table = new MutableTable(schemaName.substring(0, schemaName.length() - 4), TableType.TABLE, schema);
schema.addTable(table);
for (int i = 0; i < dbf.getFieldCount(); i++) {
try {
Field field = dbf.getField(i + 1);
MutableColumn column = new MutableColumn(field.getName());
ColumnType columnType = ColumnType.VARCHAR;
if (field instanceof FloatField) {
columnType = ColumnType.FLOAT;
} else if (field instanceof NumField) {
columnType = ColumnType.DOUBLE;
} else if (field instanceof CharField) {
columnType = ColumnType.CHAR;
} else if (field instanceof DateField) {
columnType = ColumnType.DATE;
} else if (field instanceof MemoField) {
columnType = ColumnType.VARCHAR;
} else if (field instanceof LogicalField) {
columnType = ColumnType.OTHER;
} else if (field instanceof PictureField) {
columnType = ColumnType.OTHER;
}
column.setType(columnType);
column.setTable(table);
column.setColumnNumber(i);
column.setNativeType("" + field.getType());
column.setColumnSize(field.getLength());
table.addColumn(column);
} catch (Exception e) {
throw new MetaModelException("Could not retrieve DBF field", e);
}
}
return schema;
}
示例13: testQuery
public void testQuery() throws Exception {
Schema schema = dc.getSchemaByName("METER.DBF");
Table table = schema.getTableByName("METER");
List<Column> columns = table.getColumns();
Query q = new Query().select(columns).from(table);
assertEquals(ColumnType.CHAR, q.getSelectClause().getItem(0)
.getColumn().getType());
assertEquals(ColumnType.CHAR, q.getSelectClause().getItem(6)
.getColumn().getType());
assertEquals(ColumnType.CHAR, q.getSelectClause().getItem(7)
.getColumn().getType());
assertEquals(ColumnType.CHAR, q.getSelectClause().getItem(8)
.getColumn().getType());
assertEquals(ColumnType.CHAR, q.getSelectClause().getItem(9)
.getColumn().getType());
assertEquals(ColumnType.DOUBLE, q.getSelectClause().getItem(30)
.getColumn().getType());
DataSet ds = dc.executeQuery(q);
assertTrue(ds.next());
// create a cross-locale string comparison of the date field
final String dateString;
{
Date date = DateUtils.get(2009, Month.AUGUST, 31);
dateString = date.toString();
}
assertEquals(
"Row[values=[0002, 0001, 0001, 0001, 0001, 0001, 21, 2008, -1, N, C, A, 0, 149627, A, "
+ dateString
+ ", E, NRC E1 , Electric , Cost , $ , , SimActual , Parkwood Hospital , Parkwood Hospital , Neuro Rehab Centre , 2893.26, 2180.46, 4541.75, 2894.24, 2981.31, 2702.11, 2733.67, 2733.67, 2597.37, 2850.39, 2914.74, 2951.58, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 12.0]]",
ds.getRow().toString());
assertEquals(Double.class, ds.getRow().getValue(30).getClass());
while (ds.next()) {
Row row = ds.getRow();
List<SelectItem> selectItems = row.getSelectItems();
for (int i = 0; i < selectItems.size(); i++) {
SelectItem selectItem = selectItems.get(i);
Column column = columns.get(i);
assertSame(selectItem.getColumn(), column);
Object selectItemValue = row.getValue(selectItem);
Object columnValue = row.getValue(column);
assertEquals(selectItemValue, columnValue);
assertNotNull(columnValue);
if (column.getType() == ColumnType.CHAR) {
assertTrue(columnValue instanceof Character
|| columnValue instanceof String);
} else if (column.getType() == ColumnType.FLOAT) {
assertTrue(columnValue instanceof Float);
} else if (column.getType() == ColumnType.DOUBLE) {
assertTrue(columnValue instanceof Double);
} else if (column.getType() == ColumnType.DATE) {
assertTrue(columnValue instanceof Date);
} else if (column.getType() == ColumnType.OTHER) {
System.out.println("other type: " + columnValue);
} else {
throw new MetaModelException(
"Value type not expected for Dbase data: " + column);
}
}
}
ds.close();
}
示例14: 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);
}
示例15: testToSqlWhereItem
public void testToSqlWhereItem() throws Exception {
MutableColumn col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
SelectItem selectItem = new SelectItem(col1);
FilterItem c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, null);
assertEquals("Col1 IS NOT NULL", c.toString());
try {
c = new FilterItem(selectItem, OperatorType.GREATER_THAN, null);
fail("Exception should have been thrown");
} catch (IllegalArgumentException e) {
assertEquals("Can only use EQUALS or DIFFERENT_FROM operator with null-operand", e.getMessage());
}
c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo");
assertEquals("Col1 <> 'foo'", c.toString());
c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "'bar'");
// this will be rewritten so it's not an issue even though it look like
// it needs an escape-char
assertEquals("Col1 <> ''bar''", c.toSql());
c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo's bar");
// the same applies here
assertEquals("Col1 <> 'foo's bar'", c.toSql());
col1.setType(ColumnType.FLOAT);
c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423);
assertEquals("Col1 = 423", c.toString());
c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423426235423.42);
assertEquals("Col1 = 423426235423.42", c.toString());
c = new FilterItem(selectItem, OperatorType.EQUALS_TO, true);
assertEquals("Col1 = 1", c.toString());
c = new FilterItem(selectItem, OperatorType.GREATER_THAN_OR_EQUAL, 123);
assertEquals("Col1 >= 123", c.toString());
c = new FilterItem(selectItem, OperatorType.LESS_THAN_OR_EQUAL, 123);
assertEquals("Col1 <= 123", c.toString());
Column timeColumn = new MutableColumn("TimeCol", ColumnType.TIME);
selectItem = new SelectItem(timeColumn);
c = new FilterItem(selectItem, OperatorType.GREATER_THAN, "02:30:05.000");
assertEquals("TimeCol > TIME '02:30:05'", c.toString());
Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
c = new FilterItem(new SelectItem(dateColumn), OperatorType.GREATER_THAN, "2000-12-31");
assertEquals("DateCol > DATE '2000-12-31'", c.toString());
}