Skip to content

Commit

Permalink
Renaming edges and vertices to nodes and relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Jo committed Sep 15, 2016
1 parent 80277e5 commit 9857291
Showing 1 changed file with 34 additions and 34 deletions.
Expand Up @@ -59,8 +59,8 @@ public SchemaProcedure( final GraphDatabaseAPI graphDatabaseAPI, final KernelTra


public GraphResult buildSchemaGraph() public GraphResult buildSchemaGraph()
{ {
final Map<String,NodeImpl> vertices = new HashMap<>(); final Map<String,NodeImpl> nodes = new HashMap<>();
final Map<String,Set<RelationshipImpl>> edges = new HashMap<>(); final Map<String,Set<RelationshipImpl>> relationships = new HashMap<>();


ReadOperations readOperations = kernelTransaction.acquireStatement().readOperations(); ReadOperations readOperations = kernelTransaction.acquireStatement().readOperations();
StatementTokenNameLookup statementTokenNameLookup = new StatementTokenNameLookup( readOperations ); StatementTokenNameLookup statementTokenNameLookup = new StatementTokenNameLookup( readOperations );
Expand Down Expand Up @@ -94,7 +94,7 @@ public GraphResult buildSchemaGraph()
} }
properties.put( "constraints", constraints ); properties.put( "constraints", constraints );


getOrCreateLabel( label.name(), properties, vertices ); getOrCreateLabel( label.name(), properties, nodes );
} }


//add all relationships //add all relationships
Expand All @@ -108,36 +108,36 @@ public GraphResult buildSchemaGraph()
int relId = readOperations.relationshipTypeGetForName( relationshipTypeGetName ); int relId = readOperations.relationshipTypeGetForName( relationshipTypeGetName );
ResourceIterator<Label> labelsInUse = graphDatabaseAPI.getAllLabelsInUse().iterator(); ResourceIterator<Label> labelsInUse = graphDatabaseAPI.getAllLabelsInUse().iterator();


List<NodeImpl> startVertices = new LinkedList<>(); List<NodeImpl> startNodes = new LinkedList<>();
List<NodeImpl> endVertices = new LinkedList<>(); List<NodeImpl> endNodes = new LinkedList<>();


while ( labelsInUse.hasNext() ) while ( labelsInUse.hasNext() )
{ {
Label labelToken = labelsInUse.next(); Label labelToken = labelsInUse.next();
String labelName = labelToken.name(); String labelName = labelToken.name();
Map<String,Object> properties = new HashMap<>(); Map<String,Object> properties = new HashMap<>();
NodeImpl vertex = getOrCreateLabel( labelName, properties, vertices ); NodeImpl node = getOrCreateLabel( labelName, properties, nodes );
int labelId = readOperations.labelGetForName( labelName ); int labelId = readOperations.labelGetForName( labelName );


if ( readOperations.countsForRelationship( labelId, relId, ReadOperations.ANY_LABEL ) > 0 ) if ( readOperations.countsForRelationship( labelId, relId, ReadOperations.ANY_LABEL ) > 0 )
{ {
startVertices.add( vertex ); startNodes.add( node );
} }
if ( readOperations.countsForRelationship( ReadOperations.ANY_LABEL, relId, labelId ) > 0 ) if ( readOperations.countsForRelationship( ReadOperations.ANY_LABEL, relId, labelId ) > 0 )
{ {
endVertices.add( vertex ); endNodes.add( node );
} }
} }
for ( NodeImpl startVertex : startVertices ) for ( NodeImpl startNode : startNodes )
{ {
for ( NodeImpl endVertex : endVertices ) for ( NodeImpl endNode : endNodes )
{ {
RelationshipImpl edge = addEdge( startVertex, endVertex, relationshipTypeGetName, edges ); RelationshipImpl relationship = addRelationship( startNode, endNode, relationshipTypeGetName, relationships );
} }
} }
} }
transaction.success(); transaction.success();
return getGraphResult( vertices, edges ); return getGraphResult( nodes, relationships );
} }
} }


Expand All @@ -154,49 +154,49 @@ public GraphResult( List<Node> nodes, List<Relationship> relationships )
} }


private NodeImpl getOrCreateLabel( String label, Map<String,Object> properties, private NodeImpl getOrCreateLabel( String label, Map<String,Object> properties,
final Map<String,NodeImpl> vertices ) final Map<String,NodeImpl> nodeMap )
{ {
if ( vertices.containsKey( label ) ) if ( nodeMap.containsKey( label ) )
{ {
return vertices.get( label ); return nodeMap.get( label );
} }
NodeImpl vertex = new NodeImpl( label, properties ); NodeImpl node = new NodeImpl( label, properties );
vertices.put( label, vertex ); nodeMap.put( label, node );
return vertex; return node;
} }


private RelationshipImpl addEdge( NodeImpl startVertex, NodeImpl endVertex, String relType, private RelationshipImpl addRelationship( NodeImpl startNode, NodeImpl endNode, String relType,
final Map<String,Set<RelationshipImpl>> edges ) final Map<String,Set<RelationshipImpl>> relationshipMap )
{ {
Set<RelationshipImpl> edgesForRel; Set<RelationshipImpl> relationshipsForType;
if ( !edges.containsKey( relType ) ) if ( !relationshipMap.containsKey( relType ) )
{ {
edgesForRel = new HashSet<>(); relationshipsForType = new HashSet<>();
edges.put( relType, edgesForRel ); relationshipMap.put( relType, relationshipsForType );
} }
else else
{ {
edgesForRel = edges.get( relType ); relationshipsForType = relationshipMap.get( relType );
} }
RelationshipImpl edge = new RelationshipImpl( startVertex, endVertex, relType ); RelationshipImpl relationship = new RelationshipImpl( startNode, endNode, relType );
if ( !edgesForRel.contains( edge ) ) if ( !relationshipsForType.contains( relationship ) )
{ {
edgesForRel.add( edge ); relationshipsForType.add( relationship );
} }
return edge; return relationship;
} }


private GraphResult getGraphResult( final Map<String,NodeImpl> vertices, private GraphResult getGraphResult( final Map<String,NodeImpl> nodeMap,
final Map<String,Set<RelationshipImpl>> edges ) final Map<String,Set<RelationshipImpl>> relationshipMap )
{ {
List<Relationship> relationships = new LinkedList<>(); List<Relationship> relationships = new LinkedList<>();
for ( Set<RelationshipImpl> edge : edges.values() ) for ( Set<RelationshipImpl> relationship : relationshipMap.values() )
{ {
relationships.addAll( edge ); relationships.addAll( relationship );
} }


GraphResult graphResult; GraphResult graphResult;
graphResult = new GraphResult( new ArrayList<Node>( vertices.values() ), relationships ); graphResult = new GraphResult( new ArrayList<Node>( nodeMap.values() ), relationships );


return graphResult; return graphResult;
} }
Expand Down

0 comments on commit 9857291

Please sign in to comment.