From 60075ce1d551484e12747930f55713c8080a7baf Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Wed, 23 Oct 2013 12:54:52 -0400 Subject: [PATCH] HHH-8617 Revert "HHH-8517 strip time from Date descriptors" This reverts commit 24a36b9cbb4b586aea3401374b991c68492cd08a. --- .../java/CalendarDateTypeDescriptor.java | 36 +++++++------------ .../java/JdbcDateTypeDescriptor.java | 22 ++++-------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java index 15b08dcf30..0a8f5d6346 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java @@ -106,38 +106,28 @@ public class CalendarDateTypeDescriptor extends AbstractTypeDescriptor } public Calendar wrap(X value, WrapperOptions options) { - Calendar cal = null; if ( value == null ) { return null; } if ( Calendar.class.isInstance( value ) ) { - cal = (Calendar) value; + return (Calendar) value; } if ( ! Date.class.isInstance( value ) ) { throw unknownWrap( value.getClass() ); } - - if ( cal == null ) { - cal = new GregorianCalendar(); - if ( Environment.jvmHasTimestampBug() ) { - final long milliseconds = ( (Date) value ).getTime(); - final long nanoseconds = java.sql.Timestamp.class.isInstance( value ) - ? ( (java.sql.Timestamp) value ).getNanos() - : 0; - cal.setTime( new Date( milliseconds + nanoseconds / 1000000 ) ); - } - else { - cal.setTime( (Date) value ); - } + + Calendar cal = new GregorianCalendar(); + if ( Environment.jvmHasTimestampBug() ) { + final long milliseconds = ( (Date) value ).getTime(); + final long nanoseconds = java.sql.Timestamp.class.isInstance( value ) + ? ( (java.sql.Timestamp) value ).getNanos() + : 0; + cal.setTime( new Date( milliseconds + nanoseconds / 1000000 ) ); + } + else { + 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; } -} +} \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java index 8a19d6b2d6..4e96131ce4 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java @@ -141,33 +141,25 @@ public class JdbcDateTypeDescriptor extends AbstractTypeDescriptor { @SuppressWarnings({ "UnnecessaryUnboxing" }) public Date wrap(X value, WrapperOptions options) { - java.sql.Date date = null; - if ( value == null ) { return null; } - if ( java.sql.Date.class.isInstance( value ) ) { - date = (java.sql.Date) value; + if ( Date.class.isInstance( value ) ) { + return (Date) 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 ) ) { - date = new java.sql.Date( ( (Calendar) value ).getTimeInMillis() ); + return new java.sql.Date( ( (Calendar) value ).getTimeInMillis() ); } - if ( Date.class.isInstance( value ) ) { - date = new java.sql.Date( ( (java.util.Date) value ).getTime() ); + if ( java.util.Date.class.isInstance( value ) ) { + return new java.sql.Date( ( (java.util.Date) value ).getTime() ); } - if ( date == null ) { - 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()); + throw unknownWrap( value.getClass() ); } }