Skip to content

Commit

Permalink
Don't swallow NotFoundException
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Aug 21, 2017
1 parent b34baff commit c747f51
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ case class LabelsFunction(nodeExpr: Expression) extends NullInNullOutExpression(

override def compute(value: AnyValue, m: ExecutionContext)
(implicit state: QueryState): AnyValue = value match {
case n: NodeValue => VirtualValues.fromArray(n.labels())
case n: NodeValue =>
VirtualValues.fromArray(n.labels())
case x => throw new ParameterWrongTypeException("Expected a Node, got: " + x)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public int hashCode()
{
//We will always recompute hashcode for values
//where `hashCode == 0`, e.g. empty strings and empty lists
//however that should be shouldn't be too costly
//however that shouldn't be shouldn't be too costly
if ( hash == 0 )
{
hash = computeHash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ static class RelationshipProxyWrappingEdgeValue extends EdgeValue
this.relationship = relationship;
}

@Override
public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E
{
MapValue p;
try
{
p = properties();
}
catch ( NotFoundException e )
{
p = VirtualValues.EMPTY_MAP;

}
writer.writeEdge( id(), startNode().id(), endNode().id(), type(), p);
}

@Override
public NodeValue startNode()
{
Expand Down Expand Up @@ -172,14 +188,7 @@ public TextValue type()
t = type;
if ( t == null )
{
try
{
t = type = Values.stringValue( relationship.getType().name() );
}
catch ( NotFoundException e )
{
t = type = Values.EMPTY_STRING;
}
t = type = Values.stringValue( relationship.getType().name() );
}
}
}
Expand All @@ -197,14 +206,7 @@ public MapValue properties()
m = properties;
if ( m == null )
{
try
{
m = properties = AnyValues.asMapValue( relationship.getAllProperties() );
}
catch ( NotFoundException e )
{
m = VirtualValues.EMPTY_MAP;
}
m = properties = AnyValues.asMapValue( relationship.getAllProperties() );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ static class NodeProxyWrappingNodeValue extends NodeValue
this.node = node;
}

@Override
public <E extends Exception> void writeTo( AnyValueWriter<E> writer ) throws E
{
TextArray l;
MapValue p;
try
{
l = labels();
p = properties();
}
catch ( NotFoundException e )
{
l = Values.stringArray();
p = VirtualValues.EMPTY_MAP;

}
writer.writeNode( node.getId(), l, p );
}

@Override
public TextArray labels()
{
Expand All @@ -111,19 +130,13 @@ public TextArray labels()
l = labels;
if ( l == null )
{
try
{
ArrayList<String> ls = new ArrayList<>();
for ( Label label : node.getLabels() )
{
ls.add( label.name() );
}
l = labels = Values.stringArray( ls.toArray( new String[ls.size()] ) );
}
catch ( NotFoundException e )
ArrayList<String> ls = new ArrayList<>();
for ( Label label : node.getLabels() )
{
l = Values.stringArray( );
ls.add( label.name() );
}
l = labels = Values.stringArray( ls.toArray( new String[ls.size()] ) );

}
}
}
Expand All @@ -141,14 +154,7 @@ public MapValue properties()
m = properties;
if ( m == null )
{
try
{
m = properties = AnyValues.asMapValue( node.getAllProperties() );
}
catch ( NotFoundException e )
{
m = VirtualValues.EMPTY_MAP;
}
m = properties = AnyValues.asMapValue( node.getAllProperties() );
}
}
}
Expand Down

0 comments on commit c747f51

Please sign in to comment.