HHH-8617 Revert "HHH-8517 strip time from Date descriptors"
This reverts commit 9dba10cf9e
.
This commit is contained in:
parent
8e556f0029
commit
203140a197
|
@ -106,38 +106,28 @@ public class CalendarDateTypeDescriptor extends AbstractTypeDescriptor<Calendar>
|
|||
}
|
||||
|
||||
public <X> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,38 +106,28 @@ public class CalendarTimeTypeDescriptor extends AbstractTypeDescriptor<Calendar>
|
|||
}
|
||||
|
||||
public <X> 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 );
|
||||
}
|
||||
|
||||
// Ensure the year/month/date is actually stripped out.
|
||||
cal.set( Calendar.YEAR, 0 );
|
||||
cal.set( Calendar.MONTH, 0 );
|
||||
cal.set( Calendar.DATE, 0 );
|
||||
|
||||
return cal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,33 +141,25 @@ public class JdbcDateTypeDescriptor extends AbstractTypeDescriptor<Date> {
|
|||
}
|
||||
@Override
|
||||
public <X> 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() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue