Skip to content

Commit

Permalink
Introduces Value as the property read type
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jun 15, 2017
1 parent e290c4d commit bede5d4
Show file tree
Hide file tree
Showing 25 changed files with 166 additions and 121 deletions.
Expand Up @@ -308,7 +308,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
} }


def getProperty(id: Long, propertyKeyId: Int): Any = try { def getProperty(id: Long, propertyKeyId: Int): Any = try {
tc.statement.readOperations().nodeGetProperty(id, propertyKeyId) tc.statement.readOperations().nodeGetProperty(id, propertyKeyId).asPublic()
} catch { } catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int] case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
} }
Expand Down
Expand Up @@ -304,7 +304,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
} }


override def getProperty(id: Long, propertyKeyId: Int): Any = try { override def getProperty(id: Long, propertyKeyId: Int): Any = try {
txContext.statement.readOperations().nodeGetProperty(id, propertyKeyId) txContext.statement.readOperations().nodeGetProperty(id, propertyKeyId).asPublic()
} catch { } catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException => case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id)) if (isDeletedInThisTx(id))
Expand Down
Expand Up @@ -311,7 +311,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
} }


override def getProperty(id: Long, propertyKeyId: Int): Any = try { override def getProperty(id: Long, propertyKeyId: Int): Any = try {
transactionalContext.statement.readOperations().nodeGetProperty(id, propertyKeyId) transactionalContext.statement.readOperations().nodeGetProperty(id, propertyKeyId).asPublic()
} catch { } catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException => case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id)) if (isDeletedInThisTx(id))
Expand Down
Expand Up @@ -311,7 +311,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
} }


override def getProperty(id: Long, propertyKeyId: Int): Any = try { override def getProperty(id: Long, propertyKeyId: Int): Any = try {
transactionalContext.statement.readOperations().nodeGetProperty(id, propertyKeyId) transactionalContext.statement.readOperations().nodeGetProperty(id, propertyKeyId).asPublic()
} catch { } catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException => case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id)) if (isDeletedInThisTx(id))
Expand Down
Expand Up @@ -57,6 +57,7 @@
import org.neo4j.storageengine.api.Token; import org.neo4j.storageengine.api.Token;
import org.neo4j.storageengine.api.lock.ResourceType; import org.neo4j.storageengine.api.lock.ResourceType;
import org.neo4j.storageengine.api.schema.PopulationProgress; import org.neo4j.storageengine.api.schema.PopulationProgress;
import org.neo4j.values.Value;


/** /**
* Defines all types of read operations that can be done from the {@link KernelAPI}. * Defines all types of read operations that can be done from the {@link KernelAPI}.
Expand Down Expand Up @@ -190,15 +191,15 @@ long nodesCountIndexed( IndexDescriptor index, long nodeId, Object value )


boolean nodeHasProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException; boolean nodeHasProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException;


Object nodeGetProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException; Value nodeGetProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException;


boolean relationshipHasProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException; boolean relationshipHasProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException;


Object relationshipGetProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException; Value relationshipGetProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException;


boolean graphHasProperty( int propertyKeyId ); boolean graphHasProperty( int propertyKeyId );


Object graphGetProperty( int propertyKeyId ); Value graphGetProperty( int propertyKeyId );


<EXCEPTION extends Exception> void relationshipVisit( long relId, RelationshipVisitor<EXCEPTION> visitor ) <EXCEPTION extends Exception> void relationshipVisit( long relId, RelationshipVisitor<EXCEPTION> visitor )
throws EntityNotFoundException, EXCEPTION; throws EntityNotFoundException, EXCEPTION;
Expand Down
Expand Up @@ -27,8 +27,6 @@
import java.util.function.Predicate; import java.util.function.Predicate;


import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.ReadOperations;
import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.api.properties.Property;
import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.impl.api.PropertyValueComparison; import org.neo4j.kernel.impl.api.PropertyValueComparison;
import org.neo4j.values.Value; import org.neo4j.values.Value;
Expand Down Expand Up @@ -222,7 +220,8 @@ public IndexQueryType type()
@Override @Override
public boolean test( Object value ) public boolean test( Object value )
{ {
return exactValue.equals( Values.of( value ) ); Value typed = value instanceof Value ? (Value)value : Values.of( value );
return exactValue.equals( typed );
} }


public Object value() public Object value()
Expand All @@ -233,17 +232,17 @@ public Object value()


public static final class NumberRangePredicate extends IndexQuery public static final class NumberRangePredicate extends IndexQuery
{ {
private final Number from; private final Value from;
private final boolean fromInclusive; private final boolean fromInclusive;
private final Number to; private final Value to;
private final boolean toInclusive; private final boolean toInclusive;


NumberRangePredicate( int propertyKeyId, Number from, boolean fromInclusive, Number to, boolean toInclusive ) NumberRangePredicate( int propertyKeyId, Number from, boolean fromInclusive, Number to, boolean toInclusive )
{ {
super( propertyKeyId ); super( propertyKeyId );
this.from = from; this.from = Values.numberValue( from );
this.fromInclusive = fromInclusive; this.fromInclusive = fromInclusive;
this.to = to; this.to = Values.numberValue( to );
this.toInclusive = toInclusive; this.toInclusive = toInclusive;
} }


Expand All @@ -260,38 +259,61 @@ public boolean test( Object value )
{ {
return false; return false;
} }
if ( !(value instanceof Number) ) if ( Values.isNumberValue( value ) )
{ {
return false; Value number = (Value) value;
} if ( from != Values.NO_VALUE )
Number number = (Number) value;
if ( from != null )
{
int compare = PropertyValueComparison.COMPARE_NUMBERS.compare( number, from );
if ( compare < 0 || !fromInclusive && compare == 0 )
{ {
return false; int compare = Values.VALUE_COMPARATOR.compare( number, from );
if ( compare < 0 || !fromInclusive && compare == 0 )
{
return false;
}
}
if ( to != Values.NO_VALUE )
{
int compare = Values.VALUE_COMPARATOR.compare( number, to );
if ( compare > 0 || !toInclusive && compare == 0 )
{
return false;
}
} }
return true;
} }
if ( to != null ) if ( value instanceof Number )
{ {
int compare = PropertyValueComparison.COMPARE_NUMBERS.compare( number, to ); Number number = (Number) value;
if ( compare > 0 || !toInclusive && compare == 0 ) if ( from != Values.NO_VALUE )
{ {
return false; Number from = (Number) this.from.asPublic();
int compare = PropertyValueComparison.COMPARE_NUMBERS.compare( number, from );
if ( compare < 0 || !fromInclusive && compare == 0 )
{
return false;
}
} }
if ( to != Values.NO_VALUE )
{
Number to = (Number) this.to.asPublic();
int compare = PropertyValueComparison.COMPARE_NUMBERS.compare( number, to );
if ( compare > 0 || !toInclusive && compare == 0 )
{
return false;
}
}
return true;
} }
return true; return false;
} }


public Number from() public Number from()
{ {
return from; return (Number)from.asPublic();
} }


public Number to() public Number to()
{ {
return to; return (Number)to.asPublic();
} }


public boolean fromInclusive() public boolean fromInclusive()
Expand Down
Expand Up @@ -157,8 +157,8 @@ public Value nodeSetProperty( KernelStatement state, long nodeId, int propertyKe


if ( propertyIds.contains( propertyKeyId ) ) if ( propertyIds.contains( propertyKeyId ) )
{ {
Object previousValue = nodeGetProperty( state, node, propertyKeyId ); Value previousValue = nodeGetProperty( state, node, propertyKeyId );
if ( value.equals( Values.of( previousValue ) ) ) if ( value.equals( previousValue ) )
{ {
// since we are changing to the same value, there is no need to check // since we are changing to the same value, there is no need to check
return; return;
Expand Down Expand Up @@ -434,7 +434,7 @@ public boolean graphHasProperty( KernelStatement state, int propertyKeyId )
} }


@Override @Override
public Object graphGetProperty( KernelStatement state, int propertyKeyId ) public Value graphGetProperty( KernelStatement state, int propertyKeyId )
{ {
return entityReadOperations.graphGetProperty( state, propertyKeyId ); return entityReadOperations.graphGetProperty( state, propertyKeyId );
} }
Expand Down Expand Up @@ -496,7 +496,7 @@ public Cursor<PropertyItem> nodeGetProperties( KernelStatement statement, NodeIt
} }


@Override @Override
public Object nodeGetProperty( KernelStatement statement, NodeItem node, int propertyKeyId ) public Value nodeGetProperty( KernelStatement statement, NodeItem node, int propertyKeyId )
{ {
return entityReadOperations.nodeGetProperty( statement, node, propertyKeyId ); return entityReadOperations.nodeGetProperty( statement, node, propertyKeyId );
} }
Expand All @@ -520,7 +520,7 @@ public Cursor<PropertyItem> relationshipGetProperties( KernelStatement statement
} }


@Override @Override
public Object relationshipGetProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId ) public Value relationshipGetProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId )
{ {
return entityReadOperations.relationshipGetProperty( statement, relationship, propertyKeyId ); return entityReadOperations.relationshipGetProperty( statement, relationship, propertyKeyId );
} }
Expand Down
Expand Up @@ -205,7 +205,7 @@ public boolean graphHasProperty( KernelStatement statement, int propertyKeyId )
} }


@Override @Override
public Object graphGetProperty( KernelStatement statement, int propertyKeyId ) public Value graphGetProperty( KernelStatement statement, int propertyKeyId )
{ {
guard.check( statement ); guard.check( statement );
return entityReadDelegate.graphGetProperty( statement, propertyKeyId ); return entityReadDelegate.graphGetProperty( statement, propertyKeyId );
Expand Down Expand Up @@ -287,7 +287,7 @@ public Cursor<PropertyItem> nodeGetProperties( KernelStatement statement, NodeIt
} }


@Override @Override
public Object nodeGetProperty( KernelStatement statement, NodeItem node, int propertyKeyId ) public Value nodeGetProperty( KernelStatement statement, NodeItem node, int propertyKeyId )
{ {
guard.check( statement ); guard.check( statement );
return entityReadDelegate.nodeGetProperty( statement, node, propertyKeyId ); return entityReadDelegate.nodeGetProperty( statement, node, propertyKeyId );
Expand Down Expand Up @@ -315,7 +315,7 @@ public Cursor<PropertyItem> relationshipGetProperties( KernelStatement statement
} }


@Override @Override
public Object relationshipGetProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId ) public Value relationshipGetProperty( KernelStatement statement, RelationshipItem relationship, int propertyKeyId )
{ {
guard.check( statement ); guard.check( statement );
return entityReadDelegate.relationshipGetProperty( statement, relationship, propertyKeyId ); return entityReadDelegate.relationshipGetProperty( statement, relationship, propertyKeyId );
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.api.schema.IndexQuery;
import org.neo4j.kernel.impl.api.operations.EntityOperations; import org.neo4j.kernel.impl.api.operations.EntityOperations;
import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.values.Value;


/** /**
* When looking up nodes by a property value, we have to do a two-stage check. * When looking up nodes by a property value, we have to do a two-stage check.
Expand Down Expand Up @@ -116,8 +117,8 @@ public static PrimitiveLongIterator exactIndexMatches( EntityOperations operatio
for ( IndexQuery predicate : numericPredicates ) for ( IndexQuery predicate : numericPredicates )
{ {
int propertyKeyId = predicate.propertyKeyId(); int propertyKeyId = predicate.propertyKeyId();
Object value = operations.nodeGetProperty( state, nodeItem, propertyKeyId ); Value value = operations.nodeGetProperty( state, nodeItem, propertyKeyId );
if ( !predicate.test( value ) ) if ( !predicate.test( value.asPublic() ) )
{ {
return false; return false;
} }
Expand Down
Expand Up @@ -111,6 +111,7 @@
import org.neo4j.storageengine.api.schema.PopulationProgress; import org.neo4j.storageengine.api.schema.PopulationProgress;
import org.neo4j.storageengine.api.schema.SchemaRule; import org.neo4j.storageengine.api.schema.SchemaRule;
import org.neo4j.values.Value; import org.neo4j.values.Value;
import org.neo4j.values.Values;


import static java.lang.String.format; import static java.lang.String.format;
import static org.neo4j.collection.primitive.PrimitiveIntCollections.deduplicate; import static org.neo4j.collection.primitive.PrimitiveIntCollections.deduplicate;
Expand Down Expand Up @@ -289,12 +290,12 @@ public boolean nodeHasProperty( long nodeId, int propertyKeyId ) throws EntityNo
} }


@Override @Override
public Object nodeGetProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException public Value nodeGetProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException
{ {
statement.assertOpen(); statement.assertOpen();
if ( propertyKeyId == StatementConstants.NO_SUCH_PROPERTY_KEY ) if ( propertyKeyId == StatementConstants.NO_SUCH_PROPERTY_KEY )
{ {
return null; return Values.NO_VALUE;
} }
try ( Cursor<NodeItem> node = dataRead().nodeCursorById( statement, nodeId ) ) try ( Cursor<NodeItem> node = dataRead().nodeCursorById( statement, nodeId ) )
{ {
Expand Down Expand Up @@ -392,12 +393,12 @@ public boolean relationshipHasProperty( long relationshipId, int propertyKeyId )
} }


@Override @Override
public Object relationshipGetProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException public Value relationshipGetProperty( long relationshipId, int propertyKeyId ) throws EntityNotFoundException
{ {
statement.assertOpen(); statement.assertOpen();
if ( propertyKeyId == StatementConstants.NO_SUCH_PROPERTY_KEY ) if ( propertyKeyId == StatementConstants.NO_SUCH_PROPERTY_KEY )
{ {
return null; return Values.NO_VALUE;
} }
try ( Cursor<RelationshipItem> relationship = dataRead().relationshipCursorById( statement, relationshipId ) ) try ( Cursor<RelationshipItem> relationship = dataRead().relationshipCursorById( statement, relationshipId ) )
{ {
Expand All @@ -417,7 +418,7 @@ public boolean graphHasProperty( int propertyKeyId )
} }


@Override @Override
public Object graphGetProperty( int propertyKeyId ) public Value graphGetProperty( int propertyKeyId )
{ {
statement.assertOpen(); statement.assertOpen();
if ( propertyKeyId == StatementConstants.NO_SUCH_PROPERTY_KEY ) if ( propertyKeyId == StatementConstants.NO_SUCH_PROPERTY_KEY )
Expand Down

0 comments on commit bede5d4

Please sign in to comment.