• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TemporalType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.holonplatform.core.temporal.TemporalType的典型用法代码示例。如果您正苦于以下问题:Java TemporalType类的具体用法?Java TemporalType怎么用?Java TemporalType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: convert

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
/**
 * Convert a JPA {@link javax.persistence.TemporalType} enumeration value into a {@link TemporalType} value.
 * @param temporalType JPA enumeration value
 * @return {@link TemporalType} value
 */
private static TemporalType convert(javax.persistence.TemporalType temporalType) {
	if (temporalType != null) {
		switch (temporalType) {
		case DATE:
			return TemporalType.DATE;
		case TIME:
			return TemporalType.TIME;
		case TIMESTAMP:
			return TemporalType.DATE_TIME;
		default:
			break;
		}
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:21,代码来源:JpaTemporalBeanPropertyPostProcessor.java


示例2: convert

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
/**
 * Convert given <code>temporalType</code> into a JPA {@link javax.persistence.TemporalType}.
 * @param temporalType Temporal type to convert
 * @return Converted temporal type
 */
public static javax.persistence.TemporalType convert(TemporalType temporalType) {
	if (temporalType != null) {
		switch (temporalType) {
		case DATE:
			return javax.persistence.TemporalType.DATE;
		case DATE_TIME:
			return javax.persistence.TemporalType.TIMESTAMP;
		case TIME:
			return javax.persistence.TemporalType.TIME;
		default:
			break;
		}
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:21,代码来源:JpaDatastoreUtils.java


示例3: testBeanPropertyPostProcessors

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Test
public void testBeanPropertyPostProcessors() {

	BeanPropertySet<TestJpaDomain> set = BeanPropertySet.create(TestJpaDomain.class);

	assertTrue(set.getProperty("dateValue").isPresent());
	assertEquals(TemporalType.DATE,
			set.getProperty("dateValue").get().getConfiguration().getTemporalType().orElse(null));

	assertTrue(set.getProperty("enumValue").isPresent());
	assertTrue(set.getProperty("enumValue").get().getConverter().isPresent());
	assertEquals(EnumByOrdinalConverter.class, set.getProperty("enumValue").get().getConverter().get().getClass());

	assertEquals("enmv", set.getProperty("enumValue").get().getConfiguration()
			.getParameter(JpaPropertyConfiguration.COLUMN_NAME).orElse(null));
	assertEquals("nested", set.getProperty("nested").get().getConfiguration()
			.getParameter(JpaPropertyConfiguration.COLUMN_NAME).orElse(null));

}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:20,代码来源:TestBase.java


示例4: testBase

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Test
public void testBase() {

	TestUtils.checkEnum(TemporalType.class);
	TestUtils.checkEnum(TemporalFormat.class);
	TestUtils.checkEnum(NumberFormatFeature.class);

	Localization lc = Localization.builder(Locale.ITALY).defaultDecimalPositions(2)
			.defaultDateTemporalFormat(TemporalFormat.MEDIUM).defaultTimeTemporalFormat(TemporalFormat.SHORT)
			.build();

	assertEquals(Locale.ITALY, lc.getLocale());
	assertEquals(new Integer(2), lc.getDefaultDecimalPositions().get());
	assertEquals(TemporalFormat.MEDIUM, lc.getDefaultDateTemporalFormat().get());
	assertEquals(TemporalFormat.SHORT, lc.getDefaultTimeTemporalFormat().get());

	DefaultLocalization l2 = new DefaultLocalization(Locale.US);

	Localization lp = Localization.builder(Locale.ITALY).parent(l2).build();
	assertEquals(l2, lp.getParent().get());

	assertNotEquals(lc, l2);
	assertNotEquals(lc, null);
	assertEquals(lc, lc);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:26,代码来源:TestI18n.java


示例5: processParameter

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Override
public String processParameter(String serialized, ParameterValue parameter, DialectResolutionContext context) {
	if (context.getResolutionQueryClause().isPresent()
			&& (context.getResolutionQueryClause().get() == ResolutionQueryClause.WHERE)) {
		TemporalType temporalType = parameter.getTemporalType().orElse(null);
		if (temporalType != null) {
			Optional<String> serializedTime = SQLValueSerializer.serializeDate(parameter.getValue(),
					temporalType);
			if (serializedTime.isPresent()) {
				context.replaceParameter(serialized,
						ParameterValue.create(String.class, serializedTime.get(), temporalType));
				return serialized;
			}
		}
	}
	return serialized;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:18,代码来源:SQLiteDialect.java


示例6: processParameter

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Override
public String processParameter(String serialized, ParameterValue parameter, DialectResolutionContext context) {
	if (context.getResolutionQueryClause().isPresent()
			&& (context.getResolutionQueryClause().get() == ResolutionQueryClause.WHERE)) {
		TemporalType temporalType = parameter.getTemporalType().orElse(null);
		if (temporalType != null) {
			if (TemporalType.TIME == temporalType) {
				Optional<String> serializedTime = SQLValueSerializer.serializeDate(parameter.getValue(),
						temporalType);
				if (serializedTime.isPresent()) {
					context.replaceParameter(serialized,
							ParameterValue.create(String.class, serializedTime.get(), temporalType));
					return serialized;
				}
			}
		}
	}
	return serialized;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:20,代码来源:SQLServerDialect.java


示例7: renderDate

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
/**
 * Renders a Date value type Field
 * @param property Property to render
 * @return Field instance
 */
protected Field<T> renderDate(Property<T> property) {
	final TemporalType type = property.getConfiguration().getTemporalType().orElse(TemporalType.DATE);
	return postProcessField(
			input.date((type == TemporalType.DATE_TIME) ? Resolution.MINUTE : Resolution.DAY, false).asField(),
			property);
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:12,代码来源:DefaultFieldPropertyRenderer.java


示例8: serialize

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Override
public void serialize(PropertyBox box, JsonGenerator gen, SerializerProvider serializers)
		throws IOException, JsonProcessingException {
	gen.writeStartObject();

	for (Property<?> property : box) {
		if (property instanceof Path) {
			String name = ((Path<?>) property).getName();
			Object value = box.getValue(property);
			if (value != null) {
				if (TypeUtils.isDate(property.getType())) {
					gen.writeStringField(name, new SimpleDateFormat(ISO_DATE_FORMAT).format(value));
				} else if (TypeUtils.isCalendar(property.getType())) {
					gen.writeStringField(name,
							new SimpleDateFormat(ISO_DATE_FORMAT).format(((Calendar) value).getTime()));
				} else if (TypeUtils.isTemporal(property.getType())) {
					Temporal temporal = (Temporal) value;
					TemporalType temporalType = TemporalType.getTemporalType(temporal);
					switch (temporalType) {
					case DATE_TIME:
						gen.writeStringField(name, DateTimeFormatter.ISO_DATE_TIME.format(temporal));
						break;
					case TIME:
						gen.writeStringField(name, DateTimeFormatter.ISO_TIME.format(temporal));
						break;
					case DATE:
					default:
						gen.writeStringField(name, DateTimeFormatter.ISO_DATE.format(temporal));
						break;
					}
				} else {
					gen.writeObjectField(name, value);
				}
			}
		}
	}

	gen.writeEndObject();
}
 
开发者ID:holon-platform,项目名称:holon-json,代码行数:40,代码来源:JacksonPropertyBoxSerializer.java


示例9: getTemporalType

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
/**
 * Try to obtain the {@link TemporalType} of given <code>expression</code>, if the expression type is a temporal
 * type.
 * @param expression Query expression
 * @param treatDateTypeAsDate <code>true</code> to return {@link TemporalType#DATE} for {@link Date} type if
 *        temporal information is not available
 * @return The expression {@link TemporalType}, empty if not available or applicable
 */
public static Optional<TemporalType> getTemporalType(Expression expression, boolean treatDateTypeAsDate) {
	if (expression != null) {
		Class<?> type = null;
		if (Path.class.isAssignableFrom(expression.getClass())) {
			type = ((Path<?>) expression).getType();
		} else if (QueryExpression.class.isAssignableFrom(expression.getClass())) {
			type = ((QueryExpression<?>) expression).getType();
		}

		if (type != null) {
			if (LocalDate.class.isAssignableFrom(type) || ChronoLocalDate.class.isAssignableFrom(type)) {
				return Optional.of(TemporalType.DATE);
			}
			if (LocalTime.class.isAssignableFrom(type) || OffsetTime.class.isAssignableFrom(type)) {
				return Optional.of(TemporalType.TIME);
			}
			if (LocalDateTime.class.isAssignableFrom(type) || OffsetDateTime.class.isAssignableFrom(type)
					|| ZonedDateTime.class.isAssignableFrom(type)
					|| ChronoLocalDateTime.class.isAssignableFrom(type)) {
				return Optional.of(TemporalType.DATE);
			}

			if (Date.class.isAssignableFrom(type) || Calendar.class.isAssignableFrom(type)) {
				if (Property.class.isAssignableFrom(expression.getClass())) {
					Optional<TemporalType> tt = ((Property<?>) expression).getConfiguration().getTemporalType();
					return treatDateTypeAsDate ? Optional.of(tt.orElse(TemporalType.DATE)) : tt;
				} else {
					return treatDateTypeAsDate ? Optional.of(TemporalType.DATE) : Optional.empty();
				}
			}

		}
	}
	return Optional.empty();
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:44,代码来源:JpaDatastoreUtils.java


示例10: setupQueryParameters

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
/**
 * Setup query named parameters
 * @param query Query
 * @param context Resolution context
 */
public static void setupQueryParameters(Query query, JpaResolutionContext context) {
	context.getNamedParameters().forEach((n, p) -> {

		// date and times
		if (TypeUtils.isDate(p.getType())) {
			query.setParameter(n, (Date) p.getValue(),
					JpaDatastoreUtils.convert(p.getTemporalType().orElse(TemporalType.DATE)));
		} else if (TypeUtils.isCalendar(p.getType())) {
			query.setParameter(n, (Calendar) p.getValue(),
					JpaDatastoreUtils.convert(p.getTemporalType().orElse(TemporalType.DATE)));
		} else if (TypeUtils.isLocalTemporal(p.getType())) {
			if (LocalDate.class.isAssignableFrom(p.getType())) {
				query.setParameter(n, ConversionUtils.fromLocalDate((LocalDate) p.getValue()),
						JpaDatastoreUtils.convert(TemporalType.DATE));
			} else if (LocalTime.class.isAssignableFrom(p.getType())) {
				query.setParameter(n, fromLocalTime((LocalTime) p.getValue()),
						JpaDatastoreUtils.convert(TemporalType.TIME));
			} else if (LocalDateTime.class.isAssignableFrom(p.getType())) {
				query.setParameter(n, ConversionUtils.fromLocalDateTime((LocalDateTime) p.getValue()),
						JpaDatastoreUtils.convert(TemporalType.DATE_TIME));
			}
		} else {
			// default
			query.setParameter(n, p.getValue());
		}

	});
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:34,代码来源:JpaDatastoreUtils.java


示例11: config

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
public void config() {
	// tag::config[]
	PathProperty<Date> dateProperty = PathProperty.create("oldDateTypeProperty", Date.class)
			.temporalType(TemporalType.DATE_TIME) // <1>
			.configuration("myAttribute", "myValue"); // <2>

	PropertyConfiguration cfg = dateProperty.getConfiguration(); // <3>
	Optional<String> value = cfg.getParameter("myAttribute", String.class); // <4>
	// end::config[]
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:11,代码来源:ExampleProperty.java


示例12: localization

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
public void localization() {
	// tag::localization[]
	LocalizationContext ctx = LocalizationContext.builder()
			.messageProvider(MessageProvider.fromProperties("messages").build()).withInitialLocale(Locale.US)
			.build();

	ctx.getLocale().ifPresent(l -> System.out.println(l)); // <1>

	String localizedMessage = ctx.getMessage("test.message", "defaultMessage"); // <2>
	localizedMessage = ctx
			.getMessage(Localizable.builder().message("defaultMessage").messageCode("test.message").build()); // <3>

	ctx.format(2.56); // <4>
	ctx.format(0.5, NumberFormatFeature.PERCENT_STYLE); // <5>
	ctx.format(5600.678, 2); // <6>

	NumberFormat nf = ctx.getNumberFormat(Integer.class); // <7>

	ctx.format(new Date(), TemporalType.DATE); // <8>
	ctx.format(new Date(), TemporalType.DATE_TIME, TemporalFormat.LONG, TemporalFormat.LONG); // <9>

	ctx.format(LocalDate.of(2017, Month.MARCH, 15)); // <10>
	ctx.format(LocalDateTime.of(2017, Month.MARCH, 15, 16, 48), TemporalFormat.FULL, TemporalFormat.SHORT); // <11>

	DateFormat df = ctx.getDateFormat(TemporalType.DATE); // <12>
	DateTimeFormatter dtf = ctx.getDateTimeFormatter(TemporalType.DATE_TIME); // <13>
	// end::localization[]
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:29,代码来源:ExampleI18n.java


示例13: format

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Override
public String format(Date date, TemporalType type, TemporalFormat dateFormat, TemporalFormat timeFormat) {
	if (date != null) {
		return getDateFormat(type, dateFormat, timeFormat).format(date);
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:8,代码来源:DefaultLocalizationContext.java


示例14: testTemporal

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Test
public void testTemporal() {

	Builder<String> property = BeanProperty.builder("test", String.class);

	final Temporal annotation = new Temporal() {

		@Override
		public Class<? extends Annotation> annotationType() {
			return Temporal.class;
		}

		@Override
		public TemporalType value() {
			return TemporalType.DATE_TIME;
		}
	};

	property.annotations(new Annotation[] { annotation });

	BeanPropertyTemporalPostProcessor postProcessor = new BeanPropertyTemporalPostProcessor();
	postProcessor.processBeanProperty(property, Object.class);

	assertNotNull(property.getConfiguration());
	assertEquals(TemporalType.DATE_TIME, property.getConfiguration().getTemporalType().orElse(null));

}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:28,代码来源:TestBeanPostProcessor.java


示例15: DefaultLiteralValue

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
/**
 * Constructor
 * @param value Value
 * @param type Value type
 * @param temporalType Optional temporal value type
 */
public DefaultLiteralValue(Object value, Class<?> type, TemporalType temporalType) {
	super();
	this.value = value;
	this.type = type;
	this.temporalType = temporalType;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:13,代码来源:DefaultLiteralValue.java


示例16: deserializeValue

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T deserializeValue(QueryExpression<T> expression, Object value) {
	if (value != null) {

		// date and times
		Optional<TemporalType> temporalType = JdbcDatastoreUtils.getTemporalType(expression, true);
		if (temporalType.isPresent()) {

			LocalDateTime dt = null;
			if (TypeUtils.isString(value.getClass())) {
				dt = asDateTime((String) value, temporalType.orElse(TemporalType.DATE));
			} else if (TypeUtils.isNumber(value.getClass())) {
				dt = asDateTime((Number) value);
			}

			if (dt != null) {
				if (LocalDateTime.class.isAssignableFrom(expression.getType())) {
					return (T) dt;
				}
				if (LocalDate.class.isAssignableFrom(expression.getType())) {
					return (T) dt.toLocalDate();
				}
				if (LocalTime.class.isAssignableFrom(expression.getType())) {
					return (T) dt.toLocalTime();
				}
				if (Date.class.isAssignableFrom(expression.getType())) {
					return (T) ConversionUtils.fromLocalDateTime(dt);
				}
			}
		}
	}

	// fallback to default
	return SQLValueDeserializer.getDefault().deserializeValue(expression, value);
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:37,代码来源:SQLiteDialect.java


示例17: processPath

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Override
public String processPath(String serialized, Path<?> path, ResolutionQueryClause clause) {
	if (clause != null && (clause == ResolutionQueryClause.WHERE)) {
		TemporalType temporalType = JdbcDatastoreUtils.getTemporalType(path, true).orElse(null);
		if (temporalType != null) {
			if (TemporalType.DATE == temporalType) {
				return "trunc(" + serialized + ")";
			}
			if (TemporalType.TIME == temporalType) {
				return "to_char(" + serialized + ",'HH24:MI:SS')";
			}
		}
	}
	return serialized;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:16,代码来源:OracleDialect.java


示例18: processParameter

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
@Override
public String processParameter(String serialized, ParameterValue parameter, DialectResolutionContext context) {
	if (context.getResolutionQueryClause().isPresent()
			&& (context.getResolutionQueryClause().get() == ResolutionQueryClause.WHERE)) {
		TemporalType temporalType = parameter.getTemporalType().orElse(null);
		if (temporalType != null) {
			if (TemporalType.DATE == temporalType) {
				Optional<String> serializedDate = SQLValueSerializer.serializeDate(parameter.getValue(),
						temporalType);
				if (serializedDate.isPresent()) {
					context.replaceParameter(serialized,
							ParameterValue.create(String.class, serializedDate.get(), temporalType));
					return "to_date(" + serialized + ", '" + SQLValueSerializer.ANSI_DATE_FORMAT.toUpperCase()
							+ "')";
				}
			} else if (TemporalType.TIME == temporalType) {
				Optional<String> serializedTime = SQLValueSerializer.serializeDate(parameter.getValue(),
						temporalType);
				if (serializedTime.isPresent()) {
					context.replaceParameter(serialized,
							ParameterValue.create(String.class, serializedTime.get(), temporalType));
					return serialized;
				}
			}
		}
	}
	return serialized;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:29,代码来源:OracleDialect.java


示例19: serializeParameterValue

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
/**
 * Serialize given parameter value as String
 * @param value Value to serialize
 * @param dateFormat Date format to use with {@link Date} value types
 * @return Serialized value
 */
private static String serializeParameterValue(Object value, DateFormat dateFormat) {
	if (!isNullOrEmpty(value)) {
		if (TypeUtils.isString(value.getClass())) {
			return (String) value;
		}
		if (TypeUtils.isBoolean(value.getClass())) {
			return ((Boolean) value) ? "true" : "false";
		}
		if (TypeUtils.isEnum(value.getClass())) {
			int ordinal = ((Enum<?>) value).ordinal();
			return String.valueOf(ordinal);
		}
		if (TypeUtils.isNumber(value.getClass())) {
			if (TypeUtils.isDecimalNumber(value.getClass())) {
				return PARAMETER_VALUE_DECIMAL_FORMAT.format(value);
			} else {
				return PARAMETER_VALUE_INTEGER_FORMAT.format(value);
			}
		}
		if (TypeUtils.isDate(value.getClass())) {
			return dateFormat.format((Date) value);
		}
		if (TypeUtils.isTemporal(value.getClass())) {
			TemporalType type = TemporalType.getTemporalType((Temporal) value);
			if (type == null) {
				type = TemporalType.DATE;
			}
			switch (type) {
			case DATE_TIME:
				return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format((Temporal) value);
			case TIME:
				return DateTimeFormatter.ISO_LOCAL_TIME.format((Temporal) value);
			case DATE:
			default:
				return DateTimeFormatter.ISO_LOCAL_DATE.format((Temporal) value);
			}
		}
		throw new UnsupportedOperationException(
				"Parameter value serialization " + "not supported for type: " + value.getClass().getName());
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:49,代码来源:ViewNavigationUtils.java


示例20: DefaultLiteralValue

import com.holonplatform.core.temporal.TemporalType; //导入依赖的package包/类
public DefaultLiteralValue(Object value, Class<?> type, TemporalType temporalType) {
	super();
	this.value = value;
	this.type = type;
	this.temporalType = temporalType;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:7,代码来源:DefaultLiteralValue.java



注:本文中的com.holonplatform.core.temporal.TemporalType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UrlBuilder类代码示例发布时间:2022-05-22
下一篇:
Java Resource类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap