From ab21ccc55f6c385f95bbb4575c3e855d993fcda1 Mon Sep 17 00:00:00 2001 From: TobiasHafner Date: Mon, 25 Mar 2024 08:25:25 +0100 Subject: [PATCH] Clean up serialization --- .../deserialization/ProtoToJdbcTypeMap.java | 14 +-- .../jdbc/nativetypes/PolyBigDecimal.java | 6 +- .../jdbc/nativetypes/PolyBoolean.java | 6 +- .../polypheny/jdbc/nativetypes/PolyDate.java | 6 +- .../jdbc/nativetypes/PolyDouble.java | 6 +- .../polypheny/jdbc/nativetypes/PolyFloat.java | 6 +- .../jdbc/nativetypes/PolyInteger.java | 12 +- .../polypheny/jdbc/nativetypes/PolyList.java | 23 ++-- .../polypheny/jdbc/nativetypes/PolyLong.java | 6 +- .../jdbc/nativetypes/PolyString.java | 6 +- .../jdbc/nativetypes/PolySymbol.java | 6 +- .../polypheny/jdbc/nativetypes/PolyTime.java | 6 +- .../jdbc/nativetypes/PolyTimeStamp.java | 6 +- .../polypheny/jdbc/nativetypes/PolyValue.java | 105 ++++++++---------- .../polypheny/jdbc/nativetypes/TypeUtils.java | 54 ++++----- .../jdbc/nativetypes/graph/PolyEdge.java | 6 +- .../jdbc/nativetypes/graph/PolyGraph.java | 6 +- .../jdbc/nativetypes/graph/PolyNode.java | 6 +- .../jdbc/nativetypes/relational/PolyMap.java | 6 +- .../serialisation/ProtoValueSerializer.java | 1 - 20 files changed, 99 insertions(+), 194 deletions(-) diff --git a/src/main/java/org/polypheny/jdbc/deserialization/ProtoToJdbcTypeMap.java b/src/main/java/org/polypheny/jdbc/deserialization/ProtoToJdbcTypeMap.java index 5ec2005d..b125ff43 100644 --- a/src/main/java/org/polypheny/jdbc/deserialization/ProtoToJdbcTypeMap.java +++ b/src/main/java/org/polypheny/jdbc/deserialization/ProtoToJdbcTypeMap.java @@ -25,19 +25,7 @@ public class ProtoToJdbcTypeMap { .put( ProtoPolyType.TIME_WITH_LOCAL_TIME_ZONE, Types.TIMESTAMP_WITH_TIMEZONE ) .put( ProtoPolyType.TIMESTAMP, Types.TIMESTAMP ) .put( ProtoPolyType.TIMESTAMP_WITH_LOCAL_TIME_ZONE, Types.TIMESTAMP_WITH_TIMEZONE ) - .put( ProtoPolyType.INTERVAL_SECOND, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_MINUTE_SECOND, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_MINUTE, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_HOUR_SECOND, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_HOUR_MINUTE, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_HOUR, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_DAY_SECOND, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_DAY_MINUTE, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_DAY_HOUR, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_DAY, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_MONTH, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_YEAR_MONTH, Types.OTHER ) - .put( ProtoPolyType.INTERVAL_YEAR, Types.OTHER ) + .put( ProtoPolyType.INTERVAL, Types.OTHER ) .put( ProtoPolyType.CHAR, Types.CHAR ) .put( ProtoPolyType.VARCHAR, Types.VARCHAR ) .put( ProtoPolyType.TEXT, Types.VARCHAR ) // TODO is Types.VARCHAR correct? diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyBigDecimal.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyBigDecimal.java index dcfbf68c..60be1ba1 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyBigDecimal.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyBigDecimal.java @@ -145,11 +145,7 @@ public int compareTo( @NotNull PolyValue o ) { if ( !o.isNumber() ) { return -1; } - try { - return ObjectUtils.compare( value, o.asNumber().BigDecimalValue() ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown!" ); - } + return ObjectUtils.compare( value, o.asNumber().BigDecimalValue() ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyBoolean.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyBoolean.java index 8ce7a312..ace828f7 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyBoolean.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyBoolean.java @@ -53,11 +53,7 @@ public static PolyBoolean of( boolean value ) { @Override public int compareTo( @NotNull PolyValue o ) { if ( isSameType( o ) ) { - try { - return ObjectUtils.compare( value, o.asBoolean().value ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown!" ); - } + return ObjectUtils.compare( value, o.asBoolean().value ); } return -1; } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyDate.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyDate.java index 288e4716..14d1b3ab 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyDate.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyDate.java @@ -75,11 +75,7 @@ public int compareTo( @NotNull PolyValue o ) { if ( !isDate() ) { return -1; } - try { - return Long.compare( milliSinceEpoch, o.asDate().milliSinceEpoch ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown!" ); - } + return Long.compare( milliSinceEpoch, o.asDate().milliSinceEpoch ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyDouble.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyDouble.java index 6cbc6f0a..800bb40e 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyDouble.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyDouble.java @@ -55,11 +55,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } - try { - return ObjectUtils.compare( value, o.asNumber().DoubleValue() ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown!" ); - } + return ObjectUtils.compare( value, o.asNumber().DoubleValue() ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyFloat.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyFloat.java index a17a6cc2..ff893192 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyFloat.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyFloat.java @@ -54,11 +54,7 @@ public int compareTo( @NotNull PolyValue o ) { if ( !o.isNumber() ) { return -1; } - try { - return ObjectUtils.compare( value, o.asFloat().value ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown!" ); - } + return ObjectUtils.compare( value, o.asFloat().value ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyInteger.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyInteger.java index 9ece952f..60be322e 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyInteger.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyInteger.java @@ -80,11 +80,7 @@ public boolean equals( Object o ) { PolyValue val = (PolyValue) o; if ( val.isNumber() ) { - try { - return PolyNumber.compareTo( this, val.asNumber() ) == 0; - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown!" ); - } + return PolyNumber.compareTo( this, val.asNumber() ) == 0; } return false; @@ -97,11 +93,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } - try { - return PolyNumber.compareTo( this, o.asNumber() ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown!" ); - } + return PolyNumber.compareTo( this, o.asNumber() ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyList.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyList.java index 39f28c36..384e8d87 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyList.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyList.java @@ -23,7 +23,6 @@ import lombok.EqualsAndHashCode; import lombok.Value; import lombok.experimental.Delegate; -import org.checkerframework.common.value.qual.PolyValue; import org.jetbrains.annotations.NotNull; import org.polypheny.db.protointerface.proto.ProtoPolyType; import org.polypheny.jdbc.ProtoInterfaceServiceException; @@ -70,21 +69,17 @@ public int compareTo( @NotNull PolyValue o ) { if ( !isSameType( o ) ) { return -1; } - try { - PolyList other = o.asList(); - if ( value.size() != other.value.size() ) { - return value.size() - o.asList().value.size(); - } - int size = Math.min( value.size(), other.size() ); - for ( int i = 0; i < size; i++ ) { - if ( value.get( i ).compareTo( other.value.get( i ) ) != 0 ) { - return value.get( i ).compareTo( other.value.get( i ) ); - } + PolyList other = o.asList(); + if ( value.size() != other.value.size() ) { + return value.size() - o.asList().value.size(); + } + int size = Math.min( value.size(), other.size() ); + for ( int i = 0; i < size; i++ ) { + if ( value.get( i ).compareTo( other.value.get( i ) ) != 0 ) { + return value.get( i ).compareTo( other.value.get( i ) ); } - return 0; - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); } + return 0; } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyLong.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyLong.java index b1d8e9e8..dbf2a802 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyLong.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyLong.java @@ -79,11 +79,7 @@ public int compareTo( @NotNull PolyValue o ) { if ( !o.isNumber() ) { return -1; } - try { - return ObjectUtils.compare( value, o.asNumber().LongValue() ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + return ObjectUtils.compare( value, o.asNumber().LongValue() ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyString.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyString.java index 4136a65c..551bc44c 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyString.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyString.java @@ -76,11 +76,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } - try { - return ObjectUtils.compare( value, o.asString().value ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + return ObjectUtils.compare( value, o.asString().value ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolySymbol.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolySymbol.java index d7ad5654..d8397a7a 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolySymbol.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolySymbol.java @@ -42,11 +42,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } - try { - return ((Enum) value).compareTo( o.asSymbol().value ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + return ((Enum) value).compareTo( o.asSymbol().value ); } } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyTime.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyTime.java index 539f4c63..1d592dbb 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyTime.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyTime.java @@ -76,11 +76,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } - try { - return Long.compare( ofDay, o.asTime().ofDay ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + return Long.compare( ofDay, o.asTime().ofDay ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyTimeStamp.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyTimeStamp.java index 66f47fd8..6886207e 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyTimeStamp.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyTimeStamp.java @@ -91,11 +91,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } - try { - return Long.compare( milliSinceEpoch, o.asTimeStamp().milliSinceEpoch ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + return Long.compare( milliSinceEpoch, o.asTimeStamp().milliSinceEpoch ); } } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java index 0043062e..a8e95c3f 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java @@ -23,7 +23,9 @@ import java.math.BigInteger; import java.math.MathContext; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.jetbrains.annotations.NotNull; import org.polypheny.db.protointerface.proto.ProtoBigDecimal; import org.polypheny.db.protointerface.proto.ProtoBinary; @@ -44,8 +46,6 @@ import org.polypheny.db.protointerface.proto.ProtoTime; import org.polypheny.db.protointerface.proto.ProtoTimestamp; import org.polypheny.db.protointerface.proto.ProtoValue; -import org.polypheny.jdbc.ProtoInterfaceErrors; -import org.polypheny.jdbc.ProtoInterfaceServiceException; import org.polypheny.jdbc.nativetypes.PolyInterval.Unit; import org.polypheny.jdbc.nativetypes.category.PolyBlob; import org.polypheny.jdbc.nativetypes.category.PolyNumber; @@ -87,7 +87,7 @@ public boolean isBoolean() { @NotNull - public PolyBoolean asBoolean() throws ProtoInterfaceServiceException { + public PolyBoolean asBoolean() { if ( isBoolean() ) { return (PolyBoolean) this; } @@ -96,9 +96,8 @@ public PolyBoolean asBoolean() throws ProtoInterfaceServiceException { @NotNull - private ProtoInterfaceServiceException cannotParse( PolyValue value, Class clazz ) { - return new ProtoInterfaceServiceException( - ProtoInterfaceErrors.WRAPPER_INCORRECT_TYPE, + private RuntimeException cannotParse( PolyValue value, Class clazz ) { + return new RuntimeException( String.format( "Cannot parse %s to type %s", value, clazz.getSimpleName() ) ); } @@ -110,7 +109,7 @@ public boolean isInteger() { @NotNull - public PolyInteger asInteger() throws ProtoInterfaceServiceException { + public PolyInteger asInteger() { if ( isInteger() ) { return (PolyInteger) this; } @@ -125,7 +124,7 @@ public boolean isDocument() { @NotNull - public PolyDocument asDocument() throws ProtoInterfaceServiceException { + public PolyDocument asDocument() { if ( isDocument() ) { return (PolyDocument) this; } @@ -139,7 +138,7 @@ public boolean isList() { @NotNull - public PolyList asList() throws ProtoInterfaceServiceException { + public PolyList asList() { if ( isList() ) { return (PolyList) this; } @@ -153,7 +152,7 @@ public boolean isString() { @NotNull - public PolyString asString() throws ProtoInterfaceServiceException { + public PolyString asString() { if ( isString() ) { return (PolyString) this; } @@ -167,7 +166,7 @@ public boolean isBinary() { @NotNull - public PolyBinary asBinary() throws ProtoInterfaceServiceException { + public PolyBinary asBinary() { if ( isBinary() ) { return (PolyBinary) this; } @@ -181,7 +180,7 @@ public boolean isBigDecimal() { @NotNull - public PolyBigDecimal asBigDecimal() throws ProtoInterfaceServiceException { + public PolyBigDecimal asBigDecimal() { if ( isBigDecimal() ) { return (PolyBigDecimal) this; } @@ -196,7 +195,7 @@ public boolean isFloat() { @NotNull - public PolyFloat asFloat() throws ProtoInterfaceServiceException { + public PolyFloat asFloat() { if ( isFloat() ) { return (PolyFloat) this; } @@ -211,7 +210,7 @@ public boolean isDouble() { @NotNull - public PolyDouble asDouble() throws ProtoInterfaceServiceException { + public PolyDouble asDouble() { if ( isDouble() ) { return (PolyDouble) this; } @@ -226,7 +225,7 @@ public boolean isLong() { @NotNull - public PolyLong asLong() throws ProtoInterfaceServiceException { + public PolyLong asLong() { if ( isLong() ) { return (PolyLong) this; } @@ -240,7 +239,7 @@ public boolean isTemporal() { } - public PolyTemporal asTemporal() throws ProtoInterfaceServiceException { + public PolyTemporal asTemporal() { if ( isTemporal() ) { return (PolyTemporal) this; } @@ -254,7 +253,7 @@ public boolean isDate() { @NotNull - public PolyDate asDate() throws ProtoInterfaceServiceException { + public PolyDate asDate() { if ( isDate() ) { return (PolyDate) this; } @@ -268,7 +267,7 @@ public boolean isTime() { @NotNull - public PolyTime asTime() throws ProtoInterfaceServiceException { + public PolyTime asTime() { if ( isTime() ) { return (PolyTime) this; } @@ -283,7 +282,7 @@ public boolean isTimestamp() { @NotNull - public PolyTimeStamp asTimeStamp() throws ProtoInterfaceServiceException { + public PolyTimeStamp asTimeStamp() { if ( isTimestamp() ) { return (PolyTimeStamp) this; } @@ -298,7 +297,7 @@ public boolean isMap() { @NotNull - public PolyMap asMap() throws ProtoInterfaceServiceException { + public PolyMap asMap() { if ( isMap() || isDocument() ) { return (PolyMap) this; } @@ -312,7 +311,7 @@ public boolean isEdge() { @NotNull - public PolyEdge asEdge() throws ProtoInterfaceServiceException { + public PolyEdge asEdge() { if ( isEdge() ) { return (PolyEdge) this; } @@ -326,7 +325,7 @@ public boolean isNode() { @NotNull - public PolyNode asNode() throws ProtoInterfaceServiceException { + public PolyNode asNode() { if ( isNode() ) { return (PolyNode) this; } @@ -345,7 +344,7 @@ public boolean isGraph() { @NotNull - public PolyGraph asGraph() throws ProtoInterfaceServiceException { + public PolyGraph asGraph() { if ( isGraph() ) { return (PolyGraph) this; } @@ -358,7 +357,7 @@ public boolean isNumber() { } - public PolyNumber asNumber() throws ProtoInterfaceServiceException { + public PolyNumber asNumber() { if ( isNumber() ) { return (PolyNumber) this; } @@ -367,11 +366,11 @@ public PolyNumber asNumber() throws ProtoInterfaceServiceException { public boolean isInterval() { - return TypeUtils.INTERVAL_TYPES.contains( type ); + return type == ProtoPolyType.INTERVAL; } - public PolyInterval asInterval() throws ProtoInterfaceServiceException { + public PolyInterval asInterval() { if ( isInterval() ) { return (PolyInterval) this; } @@ -384,7 +383,7 @@ public boolean isSymbol() { } - public PolySymbol asSymbol() throws ProtoInterfaceServiceException { + public PolySymbol asSymbol() { if ( isSymbol() ) { return (PolySymbol) this; } @@ -398,7 +397,7 @@ public boolean isBlob() { @NotNull - public PolyBlob asBlob() throws ProtoInterfaceServiceException { + public PolyBlob asBlob() { if ( isBlob() ) { return (PolyBlob) this; } @@ -411,7 +410,7 @@ public boolean isUserDefinedValue() { } - public PolyUserDefinedValue asUserDefinedValue() throws ProtoInterfaceServiceException { + public PolyUserDefinedValue asUserDefinedValue() { if ( isUserDefinedValue() ) { return (PolyUserDefinedValue) this; } @@ -477,13 +476,7 @@ private static PolyMap deserializeToPolyMap( List( entries.stream() .filter( e -> e.getKey().getValueCase() == STRING ) .collect( Collectors.toMap( - e -> { - try { - return PolyValue.fromProto( e.getKey() ).asString(); - } catch ( ProtoInterfaceServiceException ex ) { - throw new RuntimeException( "Should never be thrown." ); - } - }, + e -> PolyValue.fromProto( e.getKey() ).asString(), e -> PolyValue.fromProto( e.getValue() ), ( key1, key2 ) -> key1 ) ) ); @@ -509,7 +502,7 @@ private static BigDecimal deserializeToBigDecimal( ProtoBigDecimal bigDecimal ) } - public ProtoValue toProto() throws ProtoInterfaceServiceException { + public ProtoValue toProto() { switch ( type ) { case BOOLEAN: return toProtoBoolean( this.asBoolean() ); @@ -560,7 +553,7 @@ public ProtoValue toProto() throws ProtoInterfaceServiceException { } - private static ProtoValue toProtoBoolean( PolyBoolean polyBoolean ) { + private ProtoValue toProtoBoolean( PolyBoolean polyBoolean ) { ProtoBoolean protoBoolean = ProtoBoolean.newBuilder() .setBoolean( polyBoolean.value ) .build(); @@ -570,7 +563,7 @@ private static ProtoValue toProtoBoolean( PolyBoolean polyBoolean ) { } - private static ProtoValue toProtoInteger( PolyInteger polyInteger ) { + private ProtoValue toProtoInteger( PolyInteger polyInteger ) { ProtoInteger protoInteger = ProtoInteger.newBuilder() .setInteger( polyInteger.value ) .build(); @@ -580,7 +573,7 @@ private static ProtoValue toProtoInteger( PolyInteger polyInteger ) { } - private static ProtoValue toProtoLong( PolyLong polyLong ) { + private ProtoValue toProtoLong( PolyLong polyLong ) { ProtoLong protoLong = ProtoLong.newBuilder() .setLong( polyLong.value ) .build(); @@ -590,7 +583,7 @@ private static ProtoValue toProtoLong( PolyLong polyLong ) { } - private static ProtoValue toProtoFloat( PolyFloat polyFloat ) { + private ProtoValue toProtoFloat( PolyFloat polyFloat ) { ProtoFloat protoFloat = ProtoFloat.newBuilder() .setFloat( polyFloat.value ) .build(); @@ -600,7 +593,7 @@ private static ProtoValue toProtoFloat( PolyFloat polyFloat ) { } - private static ProtoValue toProtoDouble( PolyDouble polyDouble ) { + private ProtoValue toProtoDouble( PolyDouble polyDouble ) { ProtoDouble protoDouble = ProtoDouble.newBuilder() .setDouble( polyDouble.value ) .build(); @@ -610,7 +603,7 @@ private static ProtoValue toProtoDouble( PolyDouble polyDouble ) { } - private static ProtoValue toProtoDate( PolyDate polyDate ) { + private ProtoValue toProtoDate( PolyDate polyDate ) { ProtoDate protoDate = ProtoDate.newBuilder() .setDate( polyDate.getDaysSinceEpoch() ) .build(); @@ -620,7 +613,7 @@ private static ProtoValue toProtoDate( PolyDate polyDate ) { } - private static ProtoValue toProtoTime( PolyTime polyTime ) { + private ProtoValue toProtoTime( PolyTime polyTime ) { ProtoTime protoTime = ProtoTime.newBuilder() .setTime( polyTime.ofDay ) .build(); @@ -630,7 +623,7 @@ private static ProtoValue toProtoTime( PolyTime polyTime ) { } - private static ProtoValue toProtoTimestamp( PolyTimeStamp polyTimeStamp ) { + private ProtoValue toProtoTimestamp( PolyTimeStamp polyTimeStamp ) { ProtoTimestamp protoTimestamp = ProtoTimestamp.newBuilder() .setTimestamp( polyTimeStamp.getMilliSinceEpoch() ) .build(); @@ -640,7 +633,7 @@ private static ProtoValue toProtoTimestamp( PolyTimeStamp polyTimeStamp ) { } - private static ProtoValue toProtoInterval( PolyInterval polyInterval ) { + private ProtoValue toProtoInterval( PolyInterval polyInterval ) { ProtoInterval.Builder protoInterval = ProtoInterval.newBuilder(); if ( polyInterval.unit == Unit.MONTHS ) { protoInterval.setMonths( polyInterval.value ); @@ -653,7 +646,7 @@ private static ProtoValue toProtoInterval( PolyInterval polyInterval ) { } - private static ProtoValue toProtoString( PolyString polyString ) { + private ProtoValue toProtoString( PolyString polyString ) { ProtoString protoString = ProtoString.newBuilder() .setString( polyString.value ) .build(); @@ -663,7 +656,7 @@ private static ProtoValue toProtoString( PolyString polyString ) { } - private static ProtoValue toProtoBinary( PolyBinary polyBinary ) { + private ProtoValue toProtoBinary( PolyBinary polyBinary ) { ProtoBinary protoBinary = ProtoBinary.newBuilder() .setBinary( ByteString.copyFrom( polyBinary.value ) ) .build(); @@ -673,12 +666,12 @@ private static ProtoValue toProtoBinary( PolyBinary polyBinary ) { } - private static ProtoValue toProtoNull() { + private ProtoValue toProtoNull() { return ProtoValue.newBuilder().setNull( ProtoNull.newBuilder().build() ).build(); } - private static ProtoValue toProtoBigDecimal( PolyBigDecimal polyBigDecimal ) { + private ProtoValue toProtoBigDecimal( PolyBigDecimal polyBigDecimal ) { BigDecimal bigDecimal = polyBigDecimal.value; ProtoBigDecimal protoBigDecimal = ProtoBigDecimal.newBuilder() .setUnscaledValue( ByteString.copyFrom( bigDecimal.unscaledValue().toByteArray() ) ) @@ -691,9 +684,9 @@ private static ProtoValue toProtoBigDecimal( PolyBigDecimal polyBigDecimal ) { } - private static ProtoValue toProtoList( PolyList polyList ) { - List values = polyList.getValue().stream() - .map( v -> v.toProto() ) + private ProtoValue toProtoList( PolyList polyList ) { + List values = ((Stream) polyList.stream()) + .map( PolyValue::toProto ) .collect( Collectors.toList() ); ProtoList protoList = ProtoList.newBuilder() .addAllValues( values ) @@ -704,9 +697,9 @@ private static ProtoValue toProtoList( PolyList polyList ) { } - private static ProtoValue toProtoMap( PolyMap polyMap ) { + private ProtoValue toProtoMap( PolyMap polyMap ) { ProtoMap.Builder protoMapBuilder = ProtoMap.newBuilder(); - List protoEntries = polyMap.entrySet().stream().map( polyMapEntry -> { + List protoEntries = ((Stream>) polyMap.entrySet().stream()).map( polyMapEntry -> { ProtoValue protoKey = polyMapEntry.getKey().toProto(); ProtoValue protoValue = polyMapEntry.getValue().toProto(); return ProtoEntry.newBuilder() @@ -722,7 +715,7 @@ private static ProtoValue toProtoMap( PolyMap polyMap ) { } - private static ProtoValue toProtoDocument( PolyDocument polyDocument ) throws ProtoInterfaceServiceException { + private ProtoValue toProtoDocument( PolyDocument polyDocument ) { List protoEntries = polyDocument.asMap().entrySet().stream().map( polyMapEntry -> { ProtoValue protoKey = polyMapEntry.getKey().toProto(); // Reuse serialize() method for consistency ProtoValue protoValue = polyMapEntry.getValue().toProto(); diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/TypeUtils.java b/src/main/java/org/polypheny/jdbc/nativetypes/TypeUtils.java index 26ac607e..1ddbe9e3 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/TypeUtils.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/TypeUtils.java @@ -17,13 +17,26 @@ package org.polypheny.jdbc.nativetypes; -import static org.polypheny.db.protointerface.proto.ProtoPolyType.*; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.AUDIO; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.BIGINT; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.DATE; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.DECIMAL; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.DOUBLE; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.FILE; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.FLOAT; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.IMAGE; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.INTEGER; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.REAL; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.SMALLINT; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.TIME; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.TIMESTAMP; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.TIMESTAMP_WITH_LOCAL_TIME_ZONE; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.TIME_WITH_LOCAL_TIME_ZONE; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.TINYINT; +import static org.polypheny.db.protointerface.proto.ProtoPolyType.VIDEO; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; import java.util.List; -import java.util.Set; import org.polypheny.db.protointerface.proto.ProtoPolyType; public class TypeUtils { @@ -39,34 +52,15 @@ public class TypeUtils { public static final List FRACTIONAL_TYPES = combine( APPROX_TYPES, ImmutableList.of( DECIMAL ) ); - public static final Set YEAR_INTERVAL_TYPES = - Sets.immutableEnumSet( - INTERVAL_YEAR, - INTERVAL_YEAR_MONTH, - INTERVAL_MONTH ); - - public static final Set DAY_INTERVAL_TYPES = - Sets.immutableEnumSet( - INTERVAL_DAY, - INTERVAL_DAY_HOUR, - INTERVAL_DAY_MINUTE, - INTERVAL_DAY_SECOND, - INTERVAL_HOUR, - INTERVAL_HOUR_MINUTE, - INTERVAL_HOUR_SECOND, - INTERVAL_MINUTE, - INTERVAL_MINUTE_SECOND, - INTERVAL_SECOND ); - - public static final Set INTERVAL_TYPES = Sets.immutableEnumSet( Iterables.concat( YEAR_INTERVAL_TYPES, DAY_INTERVAL_TYPES ) ); public static final List BLOB_TYPES = ImmutableList.of( FILE, AUDIO, IMAGE, VIDEO ); - private static List combine (List < ProtoPolyType > list0, List < ProtoPolyType > list1 ){ - return ImmutableList.builder() - .addAll( list0 ) - .addAll( list1 ) - .build(); - } + private static List combine( List list0, List list1 ) { + return ImmutableList.builder() + .addAll( list0 ) + .addAll( list1 ) + .build(); } + +} diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyEdge.java b/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyEdge.java index e066929d..0db025fd 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyEdge.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyEdge.java @@ -109,11 +109,7 @@ public int compareTo( @NotNull PolyValue o ) { if ( !this.isSameType( o ) ) { return -1; } - try { - return this.equals( o.asEdge() ) ? 0 : -1; - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + return this.equals( o.asEdge() ) ? 0 : -1; } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyGraph.java b/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyGraph.java index 168bf84b..0600d80b 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyGraph.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyGraph.java @@ -48,11 +48,7 @@ public int compareTo( PolyValue other ) { return -1; } PolyGraph o = null; - try { - o = other.asGraph(); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should not be thrown." ); - } + o = other.asGraph(); if ( this.nodes.size() > o.nodes.size() ) { return 1; diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyNode.java b/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyNode.java index dcab6ca8..ab4910a0 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyNode.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/graph/PolyNode.java @@ -85,11 +85,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } - try { - return id.compareTo( o.asNode().id ); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + return id.compareTo( o.asNode().id ); } } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/relational/PolyMap.java b/src/main/java/org/polypheny/jdbc/nativetypes/relational/PolyMap.java index 1bc301f8..efdaf9c6 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/relational/PolyMap.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/relational/PolyMap.java @@ -53,11 +53,7 @@ public int compareTo( @NotNull PolyValue o ) { return -1; } Map other; - try { - other = o.asMap(); - } catch ( ProtoInterfaceServiceException e ) { - throw new RuntimeException( "Should never be thrown." ); - } + other = o.asMap(); if ( map.size() != other.size() ) { return map.size() > other.size() ? 1 : -1; diff --git a/src/main/java/org/polypheny/jdbc/serialisation/ProtoValueSerializer.java b/src/main/java/org/polypheny/jdbc/serialisation/ProtoValueSerializer.java index 85f28891..ce1eb66a 100644 --- a/src/main/java/org/polypheny/jdbc/serialisation/ProtoValueSerializer.java +++ b/src/main/java/org/polypheny/jdbc/serialisation/ProtoValueSerializer.java @@ -103,7 +103,6 @@ public static ProtoValue serialize( TypedValue typedValue ) throws SQLException throw new RuntimeException( "Can't serialize unknown value!" ); } return ((PolyValue) typedValue.getValue()).toProto(); - break; case Types.JAVA_OBJECT: // TODO TH: find something useful to do here... break;