HHH-8617 Revert "HHH-8517 strip time from Date descriptors"

This reverts commit 24a36b9cbb.
This commit is contained in:
Brett Meyer 2013-10-23 12:54:52 -04:00
parent 3fbb7d3c82
commit 60075ce1d5
2 changed files with 20 additions and 38 deletions

View File

@ -106,20 +106,18 @@ public class CalendarDateTypeDescriptor extends AbstractTypeDescriptor<Calendar>
} }
public <X> Calendar wrap(X value, WrapperOptions options) { public <X> Calendar wrap(X value, WrapperOptions options) {
Calendar cal = null;
if ( value == null ) { if ( value == null ) {
return null; return null;
} }
if ( Calendar.class.isInstance( value ) ) { if ( Calendar.class.isInstance( value ) ) {
cal = (Calendar) value; return (Calendar) value;
} }
if ( ! Date.class.isInstance( value ) ) { if ( ! Date.class.isInstance( value ) ) {
throw unknownWrap( value.getClass() ); throw unknownWrap( value.getClass() );
} }
if ( cal == null ) { Calendar cal = new GregorianCalendar();
cal = new GregorianCalendar();
if ( Environment.jvmHasTimestampBug() ) { if ( Environment.jvmHasTimestampBug() ) {
final long milliseconds = ( (Date) value ).getTime(); final long milliseconds = ( (Date) value ).getTime();
final long nanoseconds = java.sql.Timestamp.class.isInstance( value ) final long nanoseconds = java.sql.Timestamp.class.isInstance( value )
@ -130,14 +128,6 @@ public class CalendarDateTypeDescriptor extends AbstractTypeDescriptor<Calendar>
else { else {
cal.setTime( (Date) value ); cal.setTime( (Date) value );
} }
}
// Some JDBC drivers (*ahem* Oracle 12c) are incorrect and, even though rs#getDate is used, return the Date
// without the time stripped. For extra safety, ensure here.
cal.set( Calendar.HOUR, 0 );
cal.set( Calendar.MINUTE, 0 );
cal.set( Calendar.SECOND, 0 );
return cal; return cal;
} }
} }

View File

@ -141,33 +141,25 @@ public class JdbcDateTypeDescriptor extends AbstractTypeDescriptor<Date> {
@SuppressWarnings({ "UnnecessaryUnboxing" }) @SuppressWarnings({ "UnnecessaryUnboxing" })
public <X> Date wrap(X value, WrapperOptions options) { public <X> Date wrap(X value, WrapperOptions options) {
java.sql.Date date = null;
if ( value == null ) { if ( value == null ) {
return null; return null;
} }
if ( java.sql.Date.class.isInstance( value ) ) { if ( Date.class.isInstance( value ) ) {
date = (java.sql.Date) value; return (Date) value;
} }
if ( Long.class.isInstance( value ) ) { if ( Long.class.isInstance( value ) ) {
date = new java.sql.Date( ( (Long) value ).longValue() ); return new java.sql.Date( ( (Long) value ).longValue() );
} }
if ( Calendar.class.isInstance( value ) ) { if ( Calendar.class.isInstance( value ) ) {
date = new java.sql.Date( ( (Calendar) value ).getTimeInMillis() ); return new java.sql.Date( ( (Calendar) value ).getTimeInMillis() );
} }
if ( Date.class.isInstance( value ) ) { if ( java.util.Date.class.isInstance( value ) ) {
date = new java.sql.Date( ( (java.util.Date) value ).getTime() ); return new java.sql.Date( ( (java.util.Date) value ).getTime() );
} }
if ( date == null ) {
throw unknownWrap( value.getClass() ); throw unknownWrap( value.getClass() );
} }
// Some JDBC drivers (*ahem* Oracle 12c) are incorrect and, even though rs#getDate is used, return the Date
// without the time stripped. For extra safety, ensure here.
return new java.sql.Date(date.getYear(), date.getMonth(), date.getDate());
}
} }