Skip to content

Commit

Permalink
Second part of feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaPeukert committed Jul 26, 2018
1 parent a924bbd commit e897df4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
Expand Up @@ -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;

Expand All @@ -52,7 +51,7 @@

public class SchemaCalculator
{
private KernelTransaction ktx;
private org.neo4j.internal.kernel.api.Transaction ktx;

private Map<LabelSet,Set<Integer>> labelSetToPropertyKeysMapping;
private Map<Pair<LabelSet,Integer>,ValueTypeDecider> labelSetANDNodePropertyKeyIdToValueTypeMapping;
Expand All @@ -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;
}
Expand Down Expand Up @@ -159,35 +158,32 @@ public Stream<SchemaProcedure.GraphResult> 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 )
Expand Down Expand Up @@ -303,7 +299,6 @@ private class ValueTypeDecider
private ValueGroup valueGroup;
private ValueStatus valueStatus;
private Boolean isNullable = false;
private String nullableSuffix = "";

ValueTypeDecider( Value v )
{
Expand All @@ -319,7 +314,6 @@ private class ValueTypeDecider
private void setNullable( )
{
isNullable = true;
nullableSuffix = NULLABLE;
}

/*
Expand All @@ -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
Expand Down
Expand Up @@ -32,11 +32,11 @@ public class SchemaInfoResult
*/
public final List<String> 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;

Expand Down

0 comments on commit e897df4

Please sign in to comment.