From e897df4ce37355eac9d448982f67dee44eb463ab Mon Sep 17 00:00:00 2001 From: Sascha Peukert Date: Mon, 2 Jul 2018 15:39:31 +0200 Subject: [PATCH] Second part of feedback --- .../kernel/builtinprocs/SchemaCalculator.java | 68 +++++++++---------- .../kernel/builtinprocs/SchemaInfoResult.java | 4 +- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java index 7649b9bef6e7..aceec198cd6a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java @@ -41,8 +41,7 @@ import org.neo4j.internal.kernel.api.RelationshipScanCursor; import org.neo4j.internal.kernel.api.SchemaRead; import org.neo4j.internal.kernel.api.TokenRead; -import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.kernel.api.Statement; +import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.values.storable.Value; import org.neo4j.values.storable.ValueGroup; @@ -52,7 +51,7 @@ public class SchemaCalculator { - private KernelTransaction ktx; + private org.neo4j.internal.kernel.api.Transaction ktx; private Map> labelSetToPropertyKeysMapping; private Map,ValueTypeDecider> labelSetANDNodePropertyKeyIdToValueTypeMapping; @@ -69,7 +68,7 @@ public class SchemaCalculator private final String NODE = "Node"; private final String RELATIONSHIP = "Relationship"; - SchemaCalculator( KernelTransaction ktx ) + SchemaCalculator( Transaction ktx ) { this.ktx = ktx; } @@ -159,35 +158,32 @@ public Stream calculateGraphResultStream() private void calculateSchema() { // this one does most of the work - try ( Statement ignore = ktx.acquireStatement() ) - { - Read dataRead = ktx.dataRead(); - TokenRead tokenRead = ktx.tokenRead(); - SchemaRead schemaRead = ktx.schemaRead(); - CursorFactory cursors = ktx.cursors(); - - // setup mappings - int labelCount = tokenRead.labelCount(); - int relationshipTypeCount = tokenRead.relationshipTypeCount(); - labelSetToPropertyKeysMapping = new HashMap<>( labelCount ); - labelIdToLabelNameMapping = new HashMap<>( labelCount ); - propertyIdToPropertylNameMapping = new HashMap<>( tokenRead.propertyKeyCount() ); - relationshipTypIdToRelationshipNameMapping = new HashMap<>( relationshipTypeCount ); - relationshipTypeIdToPropertyKeysMapping = new HashMap<>( relationshipTypeCount ); - labelSetANDNodePropertyKeyIdToValueTypeMapping = new HashMap<>(); - relationshipTypeIdANDPropertyTypeIdToValueTypeMapping = new HashMap<>(); - - scanEverythingBelongingToNodes( dataRead, cursors ); - scanEverythingBelongingToRelationships( dataRead, cursors ); - - // OTHER: - // go through all labels - addNamesToCollection( tokenRead.labelsGetAllTokens(), labelIdToLabelNameMapping ); - // go through all propertyKeys - addNamesToCollection( tokenRead.propertyKeyGetAllTokens(), propertyIdToPropertylNameMapping ); - // go through all relationshipTypes - addNamesToCollection( tokenRead.relationshipTypesGetAllTokens(), relationshipTypIdToRelationshipNameMapping ); - } + Read dataRead = ktx.dataRead(); + TokenRead tokenRead = ktx.tokenRead(); + SchemaRead schemaRead = ktx.schemaRead(); + CursorFactory cursors = ktx.cursors(); + + // setup mappings + int labelCount = tokenRead.labelCount(); + int relationshipTypeCount = tokenRead.relationshipTypeCount(); + labelSetToPropertyKeysMapping = new HashMap<>( labelCount ); + labelIdToLabelNameMapping = new HashMap<>( labelCount ); + propertyIdToPropertylNameMapping = new HashMap<>( tokenRead.propertyKeyCount() ); + relationshipTypIdToRelationshipNameMapping = new HashMap<>( relationshipTypeCount ); + relationshipTypeIdToPropertyKeysMapping = new HashMap<>( relationshipTypeCount ); + labelSetANDNodePropertyKeyIdToValueTypeMapping = new HashMap<>(); + relationshipTypeIdANDPropertyTypeIdToValueTypeMapping = new HashMap<>(); + + scanEverythingBelongingToNodes( dataRead, cursors ); + scanEverythingBelongingToRelationships( dataRead, cursors ); + + // OTHER: + // go through all labels + addNamesToCollection( tokenRead.labelsGetAllTokens(), labelIdToLabelNameMapping ); + // go through all propertyKeys + addNamesToCollection( tokenRead.propertyKeyGetAllTokens(), propertyIdToPropertylNameMapping ); + // go through all relationshipTypes + addNamesToCollection( tokenRead.relationshipTypesGetAllTokens(), relationshipTypIdToRelationshipNameMapping ); } private void scanEverythingBelongingToRelationships( Read dataRead, CursorFactory cursors ) @@ -303,7 +299,6 @@ private class ValueTypeDecider private ValueGroup valueGroup; private ValueStatus valueStatus; private Boolean isNullable = false; - private String nullableSuffix = ""; ValueTypeDecider( Value v ) { @@ -319,7 +314,6 @@ private class ValueTypeDecider private void setNullable( ) { isNullable = true; - nullableSuffix = NULLABLE; } /* @@ -330,10 +324,10 @@ String getCypherTypeString() switch ( valueStatus ) { case VALUE: - return isNullable ? concreteValue.getTypeName().toUpperCase() + nullableSuffix + return isNullable ? concreteValue.getTypeName().toUpperCase() + NULLABLE : concreteValue.getTypeName().toUpperCase(); case VALUE_GROUP: - return isNullable ? valueGroup.name() + nullableSuffix + return isNullable ? valueGroup.name() + NULLABLE : valueGroup.name(); case ANY: return isNullable ? NULLABLE_ANYVALUE diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaInfoResult.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaInfoResult.java index d873d1096c28..b31e459ee8c4 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaInfoResult.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaInfoResult.java @@ -32,11 +32,11 @@ public class SchemaInfoResult */ public final List nodeLabelsOrRelType; /** - * A property that occurs on the given label combination / relationship type + * A property that occurs on the given label combination / relationship type or null */ public final String property; /** - * The CypherType of the given property on the given label combination / relationship type + * The CypherType of the given property on the given label combination / relationship type or null */ public final String cypherType;