From d564fc5b3662538c474fa153e33bd48aac51c97d Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 28 Aug 2024 15:20:30 +0200 Subject: [PATCH 1/6] Use default timezone if calendar is null --- .../org/polypheny/jdbc/utils/TypedValueUtils.java | 3 +++ .../org/polypheny/jdbc/types/TypedValueTest.java | 12 ------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/polypheny/jdbc/utils/TypedValueUtils.java b/src/main/java/org/polypheny/jdbc/utils/TypedValueUtils.java index 350b9a4..0ce038a 100644 --- a/src/main/java/org/polypheny/jdbc/utils/TypedValueUtils.java +++ b/src/main/java/org/polypheny/jdbc/utils/TypedValueUtils.java @@ -158,6 +158,9 @@ public static Timestamp getTimestampInCalendar( Timestamp timestamp, Calendar ca private static long getTimeLongInCalendar( long value, Calendar calendar ) { + if ( calendar == null ) { + return value - Calendar.getInstance().getTimeZone().getOffset( value ); + } return value - calendar.getTimeZone().getOffset( value ); } diff --git a/src/test/java/org/polypheny/jdbc/types/TypedValueTest.java b/src/test/java/org/polypheny/jdbc/types/TypedValueTest.java index 091acf8..e2dcbad 100644 --- a/src/test/java/org/polypheny/jdbc/types/TypedValueTest.java +++ b/src/test/java/org/polypheny/jdbc/types/TypedValueTest.java @@ -317,12 +317,6 @@ public void fromAsciiStreamWithValidStream() throws SQLException { } - @Test() - public void fromTimeWithNullCalendarThrowsException() { - assertThrows( NullPointerException.class, () -> TypedValue.fromTime( new Time( 10, 30, 0 ), null ) ); - } - - @Test public void timeZoneTest() { Time input = new Time( 123456 ); @@ -415,12 +409,6 @@ public void asTimeWithValidValue() throws SQLException { } - @Test() - public void fromDateWhenNullCalendarProvidedThenThrowException() { - assertThrows( NullPointerException.class, () -> TypedValue.fromDate( new Date( 2022, 1, 1 ), null ) ); - } - - @Test public void fromDateWhenValidDateAndCalendarProvided() throws SQLException { Date date = new Date( 2021, Calendar.JANUARY, 1 ); From bf5d45a39867b86f349b9a947dbf528379c6c22a Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 28 Aug 2024 15:20:30 +0200 Subject: [PATCH 2/6] Return an empty List if parameterBatch is empty --- .../java/org/polypheny/jdbc/PolyphenyPreparedStatement.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/polypheny/jdbc/PolyphenyPreparedStatement.java b/src/main/java/org/polypheny/jdbc/PolyphenyPreparedStatement.java index 1a6f1c4..bb9e0eb 100644 --- a/src/main/java/org/polypheny/jdbc/PolyphenyPreparedStatement.java +++ b/src/main/java/org/polypheny/jdbc/PolyphenyPreparedStatement.java @@ -35,6 +35,7 @@ import java.sql.SQLXML; import java.sql.Time; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.LinkedList; @@ -440,6 +441,9 @@ public int[] executeBatch() throws SQLException { private List executeParameterizedBatch() throws SQLException { throwIfClosed(); try { + if ( parameterBatch.isEmpty() ) { + return new ArrayList<>(); + } StatementBatchResponse status = getClient().executeIndexedStatementBatch( statementId, parameterBatch, getTimeout() ); return status.getScalarsList(); } finally { From 030fb316e8faeb6df7e8f0cdb0be559fc6204e09 Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 28 Aug 2024 18:24:06 +0200 Subject: [PATCH 3/6] Treat column names as case-insensitive --- .../polypheny/jdbc/meta/PolyphenyResultSetMetadata.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/polypheny/jdbc/meta/PolyphenyResultSetMetadata.java b/src/main/java/org/polypheny/jdbc/meta/PolyphenyResultSetMetadata.java index 3021f23..c987f91 100644 --- a/src/main/java/org/polypheny/jdbc/meta/PolyphenyResultSetMetadata.java +++ b/src/main/java/org/polypheny/jdbc/meta/PolyphenyResultSetMetadata.java @@ -26,13 +26,13 @@ public class PolyphenyResultSetMetadata implements ResultSetMetaData { - private List columnMetas; - private Map columnIndexes; + private final List columnMetas; + private final Map columnIndexes; public PolyphenyResultSetMetadata( List columnMetas ) { this.columnMetas = columnMetas; - this.columnIndexes = this.columnMetas.stream().collect( Collectors.toMap( PolyphenyColumnMeta::getColumnLabel, c -> c.getOrdinal() + 1, ( m, n ) -> n ) ); + this.columnIndexes = this.columnMetas.stream().collect( Collectors.toMap( c -> c.getColumnName().toLowerCase(), c -> c.getOrdinal() + 1, ( m, n ) -> n ) ); } @@ -47,7 +47,7 @@ private PolyphenyColumnMeta getMeta( int columnIndex ) throws SQLException { public int getColumnIndexFromLabel( String columnLabel ) throws SQLException { - Integer columnIndex = columnIndexes.get( columnLabel ); + Integer columnIndex = columnIndexes.get( columnLabel.toLowerCase() ); if ( columnIndex == null ) { throw new PrismInterfaceServiceException( PrismInterfaceErrors.COLUMN_NOT_EXISTS, "Invalid column label: " + columnLabel ); } From 74ef182a340ff56e1ef69f1ed0079d7a36557c0a Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 28 Aug 2024 18:24:06 +0200 Subject: [PATCH 4/6] Convert BigDecimal to Long --- src/main/java/org/polypheny/jdbc/types/TypedValue.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/polypheny/jdbc/types/TypedValue.java b/src/main/java/org/polypheny/jdbc/types/TypedValue.java index 72c0f3f..83f98db 100644 --- a/src/main/java/org/polypheny/jdbc/types/TypedValue.java +++ b/src/main/java/org/polypheny/jdbc/types/TypedValue.java @@ -680,6 +680,9 @@ public long asLong() throws SQLException { if ( integerValue != null ) { return integerValue; } + if ( bigDecimalValue != null ) { + return bigDecimalValue.longValue(); + } if ( isNull() ) { return 0; } From 49af24453e1a78c8c3dfc1b0db93f1029a279b72 Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 28 Aug 2024 18:24:06 +0200 Subject: [PATCH 5/6] Handle null in asTimestamp --- src/main/java/org/polypheny/jdbc/types/TypedValue.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/polypheny/jdbc/types/TypedValue.java b/src/main/java/org/polypheny/jdbc/types/TypedValue.java index 83f98db..3372913 100644 --- a/src/main/java/org/polypheny/jdbc/types/TypedValue.java +++ b/src/main/java/org/polypheny/jdbc/types/TypedValue.java @@ -1052,6 +1052,9 @@ public Timestamp asTimestamp() throws SQLException { @Override public Timestamp asTimestamp( Calendar calendar ) throws SQLException { + if ( isNull() ) { + return null; + } return TypedValueUtils.getTimestampInCalendar( asTimestamp(), calendar ); } From f6e7f8f18d55b28c0ad21fb38e196289967051b3 Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Wed, 28 Aug 2024 18:24:06 +0200 Subject: [PATCH 6/6] Update exception message --- src/main/java/org/polypheny/jdbc/types/TypedValue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/polypheny/jdbc/types/TypedValue.java b/src/main/java/org/polypheny/jdbc/types/TypedValue.java index 3372913..550af23 100644 --- a/src/main/java/org/polypheny/jdbc/types/TypedValue.java +++ b/src/main/java/org/polypheny/jdbc/types/TypedValue.java @@ -665,7 +665,7 @@ public int asInt() throws SQLException { if ( isNull() ) { return 0; } - throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER or BIGINT." ); + throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER, BIGINT or DECIMAL." ); } @@ -686,7 +686,7 @@ public long asLong() throws SQLException { if ( isNull() ) { return 0; } - throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER or BIGINT." ); + throw new PrismInterfaceServiceException( PrismInterfaceErrors.DATA_TYPE_MISMATCH, "This value is not of type TINYINT, SMALLINT, INTEGER, BIGINT or DECIMAL." ); }