本文整理汇总了Java中org.apache.metamodel.schema.ColumnType.TIME属性的典型用法代码示例。如果您正苦于以下问题:Java ColumnType.TIME属性的具体用法?Java ColumnType.TIME怎么用?Java ColumnType.TIME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.metamodel.schema.ColumnType
的用法示例。
在下文中一共展示了ColumnType.TIME属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
}
示例3: 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);
}
}
示例4: 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);
}
示例5: 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 };
}
示例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);
}
示例7: 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());
}