Skip to content

Commit

Permalink
Clean up serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasHafner committed Mar 25, 2024
1 parent 4e312a1 commit ab21ccc
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}


Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyFloat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() );
}


Expand Down
23 changes: 9 additions & 14 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}


Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}


Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolySymbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

}
6 changes: 1 addition & 5 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

}
Loading

0 comments on commit ab21ccc

Please sign in to comment.