Skip to content

Commit

Permalink
Move AnyValues.of out of values module
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Aug 31, 2017
1 parent dd4994a commit 4e591a6
Show file tree
Hide file tree
Showing 77 changed files with 752 additions and 660 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.List;
import java.util.Map;

import org.neo4j.cypher.internal.javacompat.ValueUtils;
import org.neo4j.graphdb.ExecutionPlanDescription;
import org.neo4j.values.AnyValue;
import org.neo4j.values.AnyValues;
import org.neo4j.values.virtual.ListValue;
import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.VirtualValues;
Expand All @@ -46,8 +46,8 @@ public static MapValue convert( ExecutionPlanDescription plan )
{
Map<String,AnyValue> out = new HashMap<>();
out.put( "operatorType", stringValue( plan.getName() ) );
out.put( "args", AnyValues.asMapValue( plan.getArguments() ) );
out.put( "identifiers", AnyValues.asListValue( plan.getIdentifiers() ) );
out.put( "args", ValueUtils.asMapValue( plan.getArguments() ) );
out.put( "identifiers", ValueUtils.asListValue( plan.getIdentifiers() ) );
out.put( "children", children( plan ) );
if ( plan.hasProfilerStatistics() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import org.neo4j.bolt.v1.runtime.BoltConnectionFatality;
import org.neo4j.bolt.v1.runtime.BoltStateMachine;
import org.neo4j.bolt.v1.runtime.StatementProcessor;
import org.neo4j.cypher.internal.javacompat.ValueUtils;
import org.neo4j.function.ThrowingAction;
import org.neo4j.function.ThrowingBiConsumer;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.values.AnyValue;
import org.neo4j.values.AnyValues;
import org.neo4j.values.result.QueryResult;
import org.neo4j.values.storable.TextValue;

Expand Down Expand Up @@ -99,7 +99,7 @@ public static Matcher<RecordedBoltResponse> succeededWithRecord( final Object...
{
return new BaseMatcher<RecordedBoltResponse>()
{
private AnyValue[] anyValues = Arrays.stream( values ).map( AnyValues::of ).toArray( AnyValue[]::new );
private AnyValue[] anyValues = Arrays.stream( values ).map( ValueUtils::of ).toArray( AnyValue[]::new );

@Override
public boolean matches( final Object item )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import org.neo4j.bolt.v1.messaging.message.RequestMessage;
import org.neo4j.bolt.v1.runtime.Neo4jError;
import org.neo4j.values.AnyValues;
import org.neo4j.cypher.internal.javacompat.ValueUtils;

import static org.neo4j.bolt.v1.messaging.BoltRequestMessage.ACK_FAILURE;
import static org.neo4j.bolt.v1.messaging.BoltRequestMessage.DISCARD_ALL;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void onInit( String clientName, Map<String,Object> credentials ) throws I
{
packer.packStructHeader( 1, INIT.signature() );
packer.pack( clientName );
packer.packRawMap( AnyValues.asMapValue( credentials ) );
packer.packRawMap( ValueUtils.asMapValue( credentials ) );
onMessageComplete.onMessageComplete();
}

Expand All @@ -81,7 +81,7 @@ public void onRun( String statement, Map<String,Object> params )
{
packer.packStructHeader( 2, RUN.signature() );
packer.pack( statement );
packer.packRawMap( AnyValues.asMapValue( params ) );
packer.packRawMap( ValueUtils.asMapValue( params ) );
onMessageComplete.onMessageComplete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import org.neo4j.bolt.v1.messaging.message.SuccessMessage;
import org.neo4j.bolt.v1.packstream.BufferedChannelInput;
import org.neo4j.bolt.v1.packstream.BufferedChannelOutput;
import org.neo4j.cypher.internal.javacompat.ValueUtils;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.impl.util.HexPrinter;
import org.neo4j.values.AnyValue;
import org.neo4j.values.AnyValues;
import org.neo4j.values.virtual.EdgeValue;
import org.neo4j.values.virtual.NodeValue;
import org.neo4j.values.virtual.VirtualValues;
Expand Down Expand Up @@ -258,7 +258,7 @@ private <T extends ResponseMessage> T unpack( BoltResponseMessageReader reader,

private void assertSerializesNeoValue( Object val ) throws IOException
{
assertSerializes( new RecordMessage( record( AnyValues.of( val ) ) ) );
assertSerializes( new RecordMessage( record( ValueUtils.of( val ) ) ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import org.neo4j.bolt.v1.packstream.PackedInputArray;
import org.neo4j.bolt.v1.packstream.PackedOutputArray;
import org.neo4j.bolt.v1.runtime.Neo4jError;
import org.neo4j.cypher.internal.javacompat.ValueUtils;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.values.AnyValue;
import org.neo4j.values.AnyValues;
import org.neo4j.values.storable.TextArray;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.storable.Values;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void shouldBeAbleToPackAndUnpackListStream() throws IOException
// Then
assertThat( unpacked, instanceOf( ListValue.class ) );
ListValue unpackedList = (ListValue) unpacked;
assertThat( unpackedList, equalTo( AnyValues.asListValue( expected ) ) );
assertThat( unpackedList, equalTo( ValueUtils.asListValue( expected ) ) );
}

@SuppressWarnings( "unchecked" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.util.Map;
import java.util.Set;

import org.neo4j.cypher.internal.javacompat.ValueUtils;
import org.neo4j.graphdb.ExecutionPlanDescription;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.values.AnyValues;
import org.neo4j.values.storable.DoubleValue;
import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.VirtualValues;
Expand All @@ -48,8 +48,8 @@ public void profileStatisticConversion() throws Exception
new TestExecutionPlanDescription( "description", getProfilerStatistics(), getIdentifiers(),
getArguments() ) );
assertEquals( convertedMap.get( "operatorType" ), stringValue( "description" ) );
assertEquals( convertedMap.get( "args" ), AnyValues.asMapValue( getArguments() ) );
assertEquals( convertedMap.get( "identifiers" ), AnyValues.asListValue( getIdentifiers() ));
assertEquals( convertedMap.get( "args" ), ValueUtils.asMapValue( getArguments() ) );
assertEquals( convertedMap.get( "identifiers" ), ValueUtils.asListValue( getIdentifiers() ));
assertEquals( convertedMap.get( "children" ), VirtualValues.EMPTY_LIST );
assertEquals( convertedMap.get( "rows" ), longValue( 1L ));
assertEquals( convertedMap.get( "dbHits" ), longValue( 2L ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.javacompat;

import java.util.ArrayList;

import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.values.AnyValueWriter;
import org.neo4j.values.storable.TextArray;
import org.neo4j.values.storable.Values;
import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.NodeValue;
import org.neo4j.values.virtual.VirtualValues;

public class NodeProxyWrappingNodeValue extends NodeValue
{
private final Node node;
private volatile TextArray labels;
private volatile MapValue properties;

NodeProxyWrappingNodeValue( Node node )
{
super( node.getId() );
this.node = node;
}

public Node nodeProxy()
{
return 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()
{
TextArray l = labels;
if ( l == null )
{
synchronized ( this )
{
l = labels;
if ( l == null )
{
ArrayList<String> ls = new ArrayList<>();
for ( Label label : node.getLabels() )
{
ls.add( label.name() );
}
l = labels = Values.stringArray( ls.toArray( new String[ls.size()] ) );

}
}
}
return l;
}

@Override
public MapValue properties()
{
MapValue m = properties;
if ( m == null )
{
synchronized ( this )
{
m = properties;
if ( m == null )
{
m = properties = ValueUtils.asMapValue( node.getAllProperties() );
}
}
}
return m;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.javacompat;

import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Relationship;
import org.neo4j.values.AnyValueWriter;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.storable.Values;
import org.neo4j.values.virtual.EdgeValue;
import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.NodeValue;
import org.neo4j.values.virtual.VirtualValues;

public class RelationshipProxyWrappingEdgeValue extends EdgeValue
{
private final Relationship relationship;
private volatile TextValue type;
private volatile MapValue properties;
private volatile NodeValue startNode;
private volatile NodeValue endNode;

RelationshipProxyWrappingEdgeValue( Relationship relationship )
{
super( relationship.getId() );
this.relationship = relationship;
}

public Relationship relationshipProxy()
{
return 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()
{
NodeValue start = startNode;
if ( start == null )
{
synchronized ( this )
{
start = startNode;
if ( start == null )
{
start = startNode = ValueUtils.fromNodeProxy( relationship.getStartNode() );
}
}
}
return start;
}

@Override
public NodeValue endNode()
{
NodeValue end = endNode;
if ( end == null )
{
synchronized ( this )
{
end = endNode;
if ( end == null )
{
end = endNode = ValueUtils.fromNodeProxy( relationship.getEndNode() );
}
}
}
return end;
}

@Override
public TextValue type()
{
TextValue t = type;
if ( t == null )
{
synchronized ( this )
{
t = type;
if ( t == null )
{
t = type = Values.stringValue( relationship.getType().name() );
}
}
}
return t;
}

@Override
public MapValue properties()
{
MapValue m = properties;
if ( m == null )
{
synchronized ( this )
{
m = properties;
if ( m == null )
{
m = properties = ValueUtils.asMapValue( relationship.getAllProperties() );
}
}
}
return m;
}
}

0 comments on commit 4e591a6

Please sign in to comment.