New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Procedures now close acquired KernelStatements #9764
Merged
burqen
merged 3 commits into
neo4j:3.1
from
burqen:3.1-procedures-close-kernel-statement
Aug 16, 2017
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import org.neo4j.graphdb.Transaction; | ||
import org.neo4j.kernel.api.KernelTransaction; | ||
import org.neo4j.kernel.api.ReadOperations; | ||
import org.neo4j.kernel.api.Statement; | ||
import org.neo4j.kernel.api.StatementTokenNameLookup; | ||
import org.neo4j.kernel.api.constraints.NodePropertyConstraint; | ||
import org.neo4j.kernel.api.index.IndexDescriptor; | ||
|
@@ -62,82 +63,90 @@ public GraphResult buildSchemaGraph() | |
final Map<String,NodeImpl> nodes = new HashMap<>(); | ||
final Map<String,Set<RelationshipImpl>> relationships = new HashMap<>(); | ||
|
||
ReadOperations readOperations = kernelTransaction.acquireStatement().readOperations(); | ||
StatementTokenNameLookup statementTokenNameLookup = new StatementTokenNameLookup( readOperations ); | ||
|
||
try ( Transaction transaction = graphDatabaseAPI.beginTx(); ) | ||
try ( Statement statement = kernelTransaction.acquireStatement() ) | ||
{ | ||
// add all labelsInDatabase | ||
ResourceIterator<Label> labelsInDatabase = graphDatabaseAPI.getAllLabelsInUse().iterator(); | ||
while ( labelsInDatabase.hasNext() ) | ||
{ | ||
Label label = labelsInDatabase.next(); | ||
Map<String,Object> properties = new HashMap<>(); | ||
|
||
Iterator<IndexDescriptor> indexDescriptorIterator = | ||
readOperations.indexesGetForLabel( readOperations.labelGetForName( label.name() ) ); | ||
ArrayList<String> indexes = new ArrayList<>(); | ||
while ( indexDescriptorIterator.hasNext() ) | ||
{ | ||
indexes.add( statementTokenNameLookup | ||
.propertyKeyGetName( indexDescriptorIterator.next().getPropertyKeyId() ) ); | ||
} | ||
properties.put( "indexes", indexes ); | ||
|
||
Iterator<NodePropertyConstraint> nodePropertyConstraintIterator = | ||
readOperations.constraintsGetForLabel( readOperations.labelGetForName( label.name() ) ); | ||
ArrayList<String> constraints = new ArrayList<>(); | ||
while ( nodePropertyConstraintIterator.hasNext() ) | ||
{ | ||
constraints | ||
.add( nodePropertyConstraintIterator.next().userDescription( statementTokenNameLookup ) ); | ||
} | ||
properties.put( "constraints", constraints ); | ||
|
||
getOrCreateLabel( label.name(), properties, nodes ); | ||
} | ||
|
||
//add all relationships | ||
ReadOperations readOperations = statement.readOperations(); | ||
StatementTokenNameLookup statementTokenNameLookup = new StatementTokenNameLookup( readOperations ); | ||
|
||
Iterator<RelationshipType> relationshipTypeIterator = | ||
graphDatabaseAPI.getAllRelationshipTypesInUse().iterator(); | ||
while ( relationshipTypeIterator.hasNext() ) | ||
try ( Transaction transaction = graphDatabaseAPI.beginTx(); ) | ||
{ | ||
RelationshipType relationshipType = relationshipTypeIterator.next(); | ||
String relationshipTypeGetName = relationshipType.name(); | ||
int relId = readOperations.relationshipTypeGetForName( relationshipTypeGetName ); | ||
ResourceIterator<Label> labelsInUse = graphDatabaseAPI.getAllLabelsInUse().iterator(); | ||
|
||
List<NodeImpl> startNodes = new LinkedList<>(); | ||
List<NodeImpl> endNodes = new LinkedList<>(); | ||
|
||
while ( labelsInUse.hasNext() ) | ||
// add all labelsInDatabase | ||
try ( ResourceIterator<Label> labelsInDatabase = graphDatabaseAPI.getAllLabelsInUse().iterator() ) | ||
{ | ||
Label labelToken = labelsInUse.next(); | ||
String labelName = labelToken.name(); | ||
Map<String,Object> properties = new HashMap<>(); | ||
NodeImpl node = getOrCreateLabel( labelName, properties, nodes ); | ||
int labelId = readOperations.labelGetForName( labelName ); | ||
|
||
if ( readOperations.countsForRelationship( labelId, relId, ReadOperations.ANY_LABEL ) > 0 ) | ||
while ( labelsInDatabase.hasNext() ) | ||
{ | ||
startNodes.add( node ); | ||
} | ||
if ( readOperations.countsForRelationship( ReadOperations.ANY_LABEL, relId, labelId ) > 0 ) | ||
{ | ||
endNodes.add( node ); | ||
Label label = labelsInDatabase.next(); | ||
Map<String,Object> properties = new HashMap<>(); | ||
|
||
Iterator<IndexDescriptor> indexDescriptorIterator = | ||
readOperations.indexesGetForLabel( readOperations.labelGetForName( label.name() ) ); | ||
ArrayList<String> indexes = new ArrayList<>(); | ||
while ( indexDescriptorIterator.hasNext() ) | ||
{ | ||
indexes.add( statementTokenNameLookup | ||
.propertyKeyGetName( indexDescriptorIterator.next().getPropertyKeyId() ) ); | ||
} | ||
properties.put( "indexes", indexes ); | ||
|
||
Iterator<NodePropertyConstraint> nodePropertyConstraintIterator = | ||
readOperations.constraintsGetForLabel( readOperations.labelGetForName( label.name() ) ); | ||
ArrayList<String> constraints = new ArrayList<>(); | ||
while ( nodePropertyConstraintIterator.hasNext() ) | ||
{ | ||
constraints | ||
.add( nodePropertyConstraintIterator.next().userDescription( statementTokenNameLookup ) ); | ||
} | ||
properties.put( "constraints", constraints ); | ||
|
||
getOrCreateLabel( label.name(), properties, nodes ); | ||
} | ||
} | ||
for ( NodeImpl startNode : startNodes ) | ||
|
||
//add all relationships | ||
|
||
try ( ResourceIterator<RelationshipType> relationshipTypeIterator = graphDatabaseAPI.getAllRelationshipTypesInUse() | ||
.iterator() ) | ||
{ | ||
for ( NodeImpl endNode : endNodes ) | ||
while ( relationshipTypeIterator.hasNext() ) | ||
{ | ||
RelationshipImpl relationship = addRelationship( startNode, endNode, relationshipTypeGetName, relationships ); | ||
RelationshipType relationshipType = relationshipTypeIterator.next(); | ||
String relationshipTypeGetName = relationshipType.name(); | ||
int relId = readOperations.relationshipTypeGetForName( relationshipTypeGetName ); | ||
ResourceIterator<Label> labelsInUse = graphDatabaseAPI.getAllLabelsInUse().iterator(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this resource iterator should be closed as well |
||
|
||
List<NodeImpl> startNodes = new LinkedList<>(); | ||
List<NodeImpl> endNodes = new LinkedList<>(); | ||
|
||
while ( labelsInUse.hasNext() ) | ||
{ | ||
Label labelToken = labelsInUse.next(); | ||
String labelName = labelToken.name(); | ||
Map<String,Object> properties = new HashMap<>(); | ||
NodeImpl node = getOrCreateLabel( labelName, properties, nodes ); | ||
int labelId = readOperations.labelGetForName( labelName ); | ||
|
||
if ( readOperations.countsForRelationship( labelId, relId, ReadOperations.ANY_LABEL ) > 0 ) | ||
{ | ||
startNodes.add( node ); | ||
} | ||
if ( readOperations.countsForRelationship( ReadOperations.ANY_LABEL, relId, labelId ) > 0 ) | ||
{ | ||
endNodes.add( node ); | ||
} | ||
} | ||
for ( NodeImpl startNode : startNodes ) | ||
{ | ||
for ( NodeImpl endNode : endNodes ) | ||
{ | ||
RelationshipImpl relationship = | ||
addRelationship( startNode, endNode, relationshipTypeGetName, relationships ); | ||
} | ||
} | ||
} | ||
} | ||
transaction.success(); | ||
return getGraphResult( nodes, relationships ); | ||
} | ||
transaction.success(); | ||
return getGraphResult( nodes, relationships ); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this inner transaction? We are already in a transaction, so this will be a dummy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would guess not, but cleaning this up is outside the scope of this PR.