com.vaadin.v7.data.util.converter.DateToSqlDateConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-compatibility-server Show documentation
Show all versions of vaadin-compatibility-server Show documentation
Vaadin 7 compatibility package for Vaadin 8
/*
* Copyright (C) 2000-2024 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See for the full
* license.
*/
/**
*
*/
package com.vaadin.v7.data.util.converter;
import java.util.Date;
import java.util.Locale;
/**
* Converter for handling conversion between {@link java.util.Date} and
* {@link java.sql.Date}. This is used when a PopupDateField or InlineDateField
* is connected to a java.sql.Date property, typically through a JPAContainer or
* SQLContainer. Note that information (time information) is lost when
* converting from {@link java.util.Date} to {@link java.sql.Date}.
*
* @since 7.1
* @author Vaadin Ltd
*/
@Deprecated
public class DateToSqlDateConverter implements Converter {
@Override
public java.sql.Date convertToModel(Date value,
Class extends java.sql.Date> targetType, Locale locale)
throws ConversionException {
if (targetType != getModelType()) {
throw new ConversionException(
"Converter only supports " + getModelType().getName()
+ " (targetType was " + targetType.getName() + ")");
}
if (value == null) {
return null;
}
return new java.sql.Date(value.getTime());
}
@Override
public Date convertToPresentation(java.sql.Date value,
Class extends Date> targetType, Locale locale)
throws ConversionException {
if (targetType != getPresentationType()) {
throw new ConversionException(
"Converter only supports " + getPresentationType().getName()
+ " (targetType was " + targetType.getName() + ")");
}
if (value == null) {
return null;
}
return new Date(value.getTime());
}
@Override
public Class getModelType() {
return java.sql.Date.class;
}
@Override
public Class getPresentationType() {
return Date.class;
}
}