Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DON'T MERGE] WIP Change Oracle default TS precision to 9 #8268

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,12 @@ public int getMaxIdentifierLength() {
return getVersion().isSameOrAfter( 12, 2 ) ? 128 : 30;
}

@Override
public int getDefaultTimestampPrecision() {
// 9 is supported at least since v10
return getVersion().isSameOrAfter( 10 ) ? 9 : 6;
}

@Override
public CallableStatementSupport getCallableStatementSupport() {
// Oracle supports returning cursors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,11 @@ public int getMaxIdentifierLength() {
return 128;
}

@Override
public int getDefaultTimestampPrecision() {
return 9;
}

@Override
public CallableStatementSupport getCallableStatementSupport() {
// Oracle supports returning cursors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Object unwrap(Date value, Class type, WrapperOptions options) {
}

if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
return new java.sql.Timestamp( value.getTime() );
return new java.sql.Timestamp( unwrapDateEpoch( value ) );
}

if ( java.sql.Time.class.isAssignableFrom( type ) ) {
Expand All @@ -158,18 +158,28 @@ public Object unwrap(Date value, Class type, WrapperOptions options) {
private LocalDate unwrapLocalDate(Date value) {
return value instanceof java.sql.Date
? ( (java.sql.Date) value ).toLocalDate()
: new java.sql.Date( value.getTime() ).toLocalDate();
: new java.sql.Date( unwrapDateEpoch( value ) ).toLocalDate();
}

private java.sql.Date unwrapSqlDate(Date value) {
return value instanceof java.sql.Date
? (java.sql.Date) value
: new java.sql.Date( value.getTime() );
: new java.sql.Date( unwrapDateEpoch( value ) );

}

private static long unwrapDateEpoch(Date value) {
return value.getTime();
return toDateEpoch( value.getTime() );
}

private static long toDateEpoch(long value) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis( value );
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.clear(Calendar.MINUTE);
calendar.clear(Calendar.SECOND);
calendar.clear(Calendar.MILLISECOND);
return calendar.getTimeInMillis();
}

@Override
Expand All @@ -183,15 +193,15 @@ public Date wrap(Object value, WrapperOptions options) {
}

if ( value instanceof Long ) {
return new java.sql.Date( (Long) value );
return new java.sql.Date( toDateEpoch( (Long) value ) );
}

if ( value instanceof Calendar ) {
return new java.sql.Date( ( (Calendar) value ).getTimeInMillis() );
return new java.sql.Date( toDateEpoch( ( (Calendar) value ).getTimeInMillis() ) );
}

if ( value instanceof Date ) {
return new java.sql.Date( ( (Date) value ).getTime() );
return unwrapSqlDate( (Date) value );
}

if ( value instanceof LocalDate ) {
Expand Down