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


Java ColumnType.isTimeBased方法代码示例

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


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

示例1: convert

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
private Object convert(final String value, final ColumnType type) {
    if (value == null) {
        return null;
    }
    if (type == null) {
        return value;
    }

    final Object result;
    if (type.isNumber()) {
        result = NumberComparator.toNumber(value);
    } else if (type.isBoolean()) {
        result = BooleanComparator.toBoolean(value);
    } else if (type.isTimeBased()) {
        result = TimeComparator.toDate(value);
    } else {
        result = value;
    }

    if (result == null) {
        throw new IllegalStateException("Failed to convert value '" + value + "' to type: " + type);
    }

    return result;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:26,代码来源:SugarCrmDataSet.java

示例2: rewriteFilterItem

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
@Override
public String rewriteFilterItem(FilterItem item) {
    final SelectItem selectItem = item.getSelectItem();
    final Object itemOperand = item.getOperand();
    final OperatorType operator = item.getOperator();
    if (null != selectItem && itemOperand != null) {
        ColumnType columnType = selectItem.getExpectedColumnType();
        if (columnType != null) {
            if (columnType.isTimeBased()) {
                // special logic for DB2 based time operands.

                StringBuilder sb = new StringBuilder();
                sb.append(selectItem.getSameQueryAlias(true));
                final Object operand = FilterItem.appendOperator(sb, itemOperand, operator);

                if (operand instanceof SelectItem) {
                    final String selectItemString = ((SelectItem) operand).getSameQueryAlias(true);
                    sb.append(selectItemString);
                } else {
                    Date date = TimeComparator.toDate(itemOperand);
                    if (date == null) {
                        throw new IllegalStateException("Could not convert " + itemOperand + " to date");
                    }

                    final String sqlValue = FormatHelper.formatSqlTime(columnType, date, true, "('", "')");
                    sb.append(sqlValue);
                }

                return sb.toString();
            }
        }
    }
    return super.rewriteFilterItem(item);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:35,代码来源:DB2QueryRewriter.java

示例3: convert

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:32,代码来源:SalesforceDataSet.java

示例4: getExpectedColumnType

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
@Override
public ColumnType getExpectedColumnType(ColumnType type) {
    if (type.isTimeBased()) {
        return type;
    }
    return ColumnType.TIMESTAMP;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:8,代码来源:ToDateFunction.java

示例5: createOperand

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
private Object createOperand(final String token, final SelectItem leftSelectItem, final boolean searchSelectItems) {
    if (token.equalsIgnoreCase("NULL")) {
        return null;
    }

    if (token.startsWith("'") && token.endsWith("'") && token.length() > 2) {
        String stringOperand = token.substring(1, token.length() - 1);
        stringOperand = stringOperand.replaceAll("\\\\'", "'");
        return stringOperand;
    }

    if (searchSelectItems) {
        final SelectItem selectItem = findSelectItem(token, false);
        if (selectItem != null) {
            return selectItem;
        }
    }

    final ColumnType expectedColumnType = leftSelectItem.getExpectedColumnType();
    final Object result;
    if (expectedColumnType == null) {
        // We're assuming number here, but it could also be boolean or a
        // time based type. But anyways, this should not happen since
        // expected column type should be available.
        result = NumberComparator.toNumber(token);
    } else if (expectedColumnType.isBoolean()) {
        result = BooleanComparator.toBoolean(token);
    } else if (expectedColumnType.isTimeBased()) {
        result = FormatHelper.parseSqlTime(expectedColumnType, token);
    } else {
        result = NumberComparator.toNumber(token);
    }

    if (result == null) {
        // shouldn't happen since only "NULL" is parsed as null.
        throw new QueryParserException("Could not parse operand: " + token);
    }

    return result;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:41,代码来源:Query.java

示例6: formatSqlTime

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:apache,项目名称:metamodel,代码行数:46,代码来源:FormatHelper.java

示例7: parseSqlTime

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:36,代码来源:FormatHelper.java

示例8: isTimeBased

import org.apache.metamodel.schema.ColumnType; //导入方法依赖的package包/类
private static boolean isTimeBased(ColumnType columnType, Object operand) {
    if (columnType == null) {
        return TimeComparator.isTimeBased(operand);
    }
    return columnType.isTimeBased();
}
 
开发者ID:apache,项目名称:metamodel,代码行数:7,代码来源:FormatHelper.java


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