Skip to content

Commit

Permalink
Make ValueWriter and writeTo throw exceptions
Browse files Browse the repository at this point in the history
In many cases the writer will write to disk or network buffers where
most thing will throw IOExceptions. We should allow a `ValueWriter` and
 `Value.writeTo` to throw along these exceptions and not force
 implementations to catch and rethrow.
  • Loading branch information
pontusmelke committed Jun 19, 2017
1 parent b2a969f commit 14908b2
Show file tree
Hide file tree
Showing 32 changed files with 206 additions and 71 deletions.
6 changes: 6 additions & 0 deletions community/bolt/pom.xml
Expand Up @@ -60,6 +60,12 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>


<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-values</artifactId>
<version>${project.version}</version>
</dependency>

<dependency> <dependency>
<groupId>org.neo4j</groupId> <groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId> <artifactId>neo4j-kernel</artifactId>
Expand Down
Expand Up @@ -27,5 +27,5 @@ public abstract class AnyValue
@Override @Override
public abstract int hashCode(); public abstract int hashCode();


public abstract void writeTo( AnyValueWriter writer ); public abstract <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E;
} }
30 changes: 15 additions & 15 deletions community/values/src/main/java/org/neo4j/values/AnyValueWriter.java
Expand Up @@ -24,34 +24,34 @@
/** /**
* Writer of any values. * Writer of any values.
*/ */
public interface AnyValueWriter extends ValueWriter public interface AnyValueWriter<E extends Exception> extends ValueWriter<E>
{ {


void writeNodeReference( long nodeId ); void writeNodeReference( long nodeId ) throws E;


void beginLabels( int numberOfLabels ); void beginLabels( int numberOfLabels ) throws E;


void writeLabel( int labelId ); void writeLabel( int labelId ) throws E;


void endLabels(); void endLabels() throws E;


void writeEdgeReference( long edgeId ); void writeEdgeReference( long edgeId ) throws E;


void beginMap( int size ); void beginMap( int size ) throws E;


void writeKeyId( int keyId ); void writeKeyId( int keyId ) throws E;


void endMap(); void endMap() throws E;


void beginList( int size ); void beginList( int size ) throws E;


void endList(); void endList() throws E;


void beginPath( int length ); void beginPath( int length ) throws E;


void endPath(); void endPath() throws E;


void beginPoint( CoordinateReferenceSystem coordinateReferenceSystem ); void beginPoint( CoordinateReferenceSystem coordinateReferenceSystem ) throws E;


void endPoint(); void endPoint() throws E;
} }
Expand Up @@ -81,7 +81,7 @@ public int compareTo( BooleanValue other )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeBoolean( value ); writer.writeBoolean( value );
} }
Expand Down
Expand Up @@ -59,7 +59,7 @@ public boolean equals( String x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeInteger( value ); writer.writeInteger( value );
} }
Expand Down
Expand Up @@ -77,7 +77,7 @@ public String stringValue( int offset )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
PrimitiveArrayWriting.writeTo( writer, value() ); PrimitiveArrayWriting.writeTo( writer, value() );
} }
Expand Down
Expand Up @@ -67,7 +67,7 @@ public int hashCode()
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeString( value ); writer.writeString( value );
} }
Expand Down
Expand Up @@ -94,7 +94,7 @@ public boolean equals( double[] x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
PrimitiveArrayWriting.writeTo( writer, value() ); PrimitiveArrayWriting.writeTo( writer, value() );
} }
Expand Down
Expand Up @@ -55,7 +55,7 @@ public boolean equals( String x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeFloatingPoint( value ); writer.writeFloatingPoint( value );
} }
Expand Down
Expand Up @@ -94,7 +94,7 @@ public boolean equals( double[] x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
PrimitiveArrayWriting.writeTo( writer, value() ); PrimitiveArrayWriting.writeTo( writer, value() );
} }
Expand Down
Expand Up @@ -55,7 +55,7 @@ public boolean equals( String x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeFloatingPoint( value ); writer.writeFloatingPoint( value );
} }
Expand Down
Expand Up @@ -94,7 +94,7 @@ public boolean equals( double[] x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
PrimitiveArrayWriting.writeTo( writer, value() ); PrimitiveArrayWriting.writeTo( writer, value() );
} }
Expand Down
Expand Up @@ -37,7 +37,7 @@ public long longValue()
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeInteger( value ); writer.writeInteger( value );
} }
Expand Down
Expand Up @@ -94,7 +94,7 @@ public boolean equals( double[] x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
PrimitiveArrayWriting.writeTo( writer, value() ); PrimitiveArrayWriting.writeTo( writer, value() );
} }
Expand Down
Expand Up @@ -55,7 +55,7 @@ public boolean equals( String x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeInteger( value ); writer.writeInteger( value );
} }
Expand Down
Expand Up @@ -125,7 +125,7 @@ public boolean equals( String[] x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeNull(); writer.writeNull();
} }
Expand Down
Expand Up @@ -24,7 +24,7 @@
*/ */
public final class PrimitiveArrayWriting public final class PrimitiveArrayWriting
{ {
public static void writeTo( ValueWriter writer, byte[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, byte[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.BYTE ); writer.beginArray( values.length, ValueWriter.ArrayType.BYTE );
for ( byte x : values ) for ( byte x : values )
Expand All @@ -34,7 +34,7 @@ public static void writeTo( ValueWriter writer, byte[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, short[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, short[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.SHORT ); writer.beginArray( values.length, ValueWriter.ArrayType.SHORT );
for ( short x : values ) for ( short x : values )
Expand All @@ -44,7 +44,7 @@ public static void writeTo( ValueWriter writer, short[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, int[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, int[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.INT ); writer.beginArray( values.length, ValueWriter.ArrayType.INT );
for ( int x : values ) for ( int x : values )
Expand All @@ -54,7 +54,7 @@ public static void writeTo( ValueWriter writer, int[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, long[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, long[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.LONG ); writer.beginArray( values.length, ValueWriter.ArrayType.LONG );
for ( long x : values ) for ( long x : values )
Expand All @@ -64,7 +64,7 @@ public static void writeTo( ValueWriter writer, long[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, float[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, float[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.FLOAT ); writer.beginArray( values.length, ValueWriter.ArrayType.FLOAT );
for ( float x : values ) for ( float x : values )
Expand All @@ -74,7 +74,7 @@ public static void writeTo( ValueWriter writer, float[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, double[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, double[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.DOUBLE ); writer.beginArray( values.length, ValueWriter.ArrayType.DOUBLE );
for ( double x : values ) for ( double x : values )
Expand All @@ -84,7 +84,7 @@ public static void writeTo( ValueWriter writer, double[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, boolean[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, boolean[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.BOOLEAN ); writer.beginArray( values.length, ValueWriter.ArrayType.BOOLEAN );
for ( boolean x : values ) for ( boolean x : values )
Expand All @@ -94,7 +94,7 @@ public static void writeTo( ValueWriter writer, boolean[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, char[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, char[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.CHAR ); writer.beginArray( values.length, ValueWriter.ArrayType.CHAR );
for ( char x : values ) for ( char x : values )
Expand All @@ -104,7 +104,7 @@ public static void writeTo( ValueWriter writer, char[] values )
writer.endArray(); writer.endArray();
} }


public static void writeTo( ValueWriter writer, String[] values ) public static <E extends Exception> void writeTo( ValueWriter<E> writer, String[] values ) throws E
{ {
writer.beginArray( values.length, ValueWriter.ArrayType.STRING ); writer.beginArray( values.length, ValueWriter.ArrayType.STRING );
for ( String x : values ) for ( String x : values )
Expand Down
Expand Up @@ -59,7 +59,7 @@ public boolean equals( String x )
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeInteger( value ); writer.writeInteger( value );
} }
Expand Down
Expand Up @@ -70,7 +70,7 @@ public int hashCode()
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
PrimitiveArrayWriting.writeTo( writer, value() ); PrimitiveArrayWriting.writeTo( writer, value() );
} }
Expand Down
Expand Up @@ -56,7 +56,7 @@ public int hashCode()
} }


@Override @Override
public void writeTo( ValueWriter writer ) public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{ {
writer.writeString( value() ); writer.writeString( value() );
} }
Expand Down
6 changes: 3 additions & 3 deletions community/values/src/main/java/org/neo4j/values/Value.java
Expand Up @@ -47,12 +47,12 @@ public abstract class Value extends AnyValue


public abstract boolean equals( String[] x ); public abstract boolean equals( String[] x );


public void writeTo( AnyValueWriter writer ) public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E
{ {
writeTo( (ValueWriter)writer ); writeTo( (ValueWriter<E>)writer );
} }


public abstract void writeTo( ValueWriter writer ); public abstract <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E;


/** /**
* Return this value as a regular java boxed primitive, String or primitive array. This method performs defensive * Return this value as a regular java boxed primitive, String or primitive array. This method performs defensive
Expand Down
36 changes: 18 additions & 18 deletions community/values/src/main/java/org/neo4j/values/ValueWriter.java
Expand Up @@ -24,7 +24,7 @@
* *
* Has functionality to write all supported primitives, as well as arrays and different representations of Strings. * Has functionality to write all supported primitives, as well as arrays and different representations of Strings.
*/ */
public interface ValueWriter public interface ValueWriter<E extends Exception>
{ {
enum ArrayType enum ArrayType
{ {
Expand All @@ -39,40 +39,40 @@ enum ArrayType
CHAR CHAR
} }


void writeNull(); void writeNull() throws E;


void writeBoolean( boolean value ); void writeBoolean( boolean value ) throws E;


void writeInteger( byte value ); void writeInteger( byte value ) throws E;


void writeInteger( short value ); void writeInteger( short value ) throws E;


void writeInteger( int value ); void writeInteger( int value ) throws E;


void writeInteger( long value ); void writeInteger( long value ) throws E;


void writeFloatingPoint( float value ); void writeFloatingPoint( float value ) throws E;


void writeFloatingPoint( double value ); void writeFloatingPoint( double value ) throws E;


void writeString( String value ); void writeString( String value ) throws E;


void writeString( char value ); void writeString( char value ) throws E;


default void writeString( char[] value ) default void writeString( char[] value ) throws E
{ {
writeString( value, 0, value.length ); writeString( value, 0, value.length );
} }


void writeString( char[] value, int offset, int length ); void writeString( char[] value, int offset, int length ) throws E;


void beginUTF8( int size ); void beginUTF8( int size ) throws E;


void copyUTF8( long fromAddress, int length ); void copyUTF8( long fromAddress, int length ) throws E;


void endUTF8(); void endUTF8() throws E;


void beginArray( int size, ArrayType arrayType ); void beginArray( int size, ArrayType arrayType ) throws E;


void endArray(); void endArray() throws E;
} }
Expand Up @@ -37,7 +37,7 @@ public class EdgeReference extends VirtualValue
} }


@Override @Override
public void writeTo( AnyValueWriter writer ) public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E
{ {
writer.writeEdgeReference( id ); writer.writeEdgeReference( id );
} }
Expand Down
Expand Up @@ -60,7 +60,7 @@ public int getLabelId( int offset )
} }


@Override @Override
public void writeTo( AnyValueWriter writer ) public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E
{ {
writer.beginLabels( labelIds.length ); writer.beginLabels( labelIds.length );
for ( int labelId : labelIds ) for ( int labelId : labelIds )
Expand Down

0 comments on commit 14908b2

Please sign in to comment.