Skip to content

Commit

Permalink
Introduces Value as the property write type
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jun 15, 2017
1 parent c27514f commit e290c4d
Show file tree
Hide file tree
Showing 59 changed files with 606 additions and 572 deletions.
Expand Up @@ -45,6 +45,7 @@
import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.kernel.impl.store.record.Record;
import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.values.Values;


import static java.lang.String.format; import static java.lang.String.format;


Expand Down Expand Up @@ -223,7 +224,7 @@ private IndexQuery[] seek( LabelSchemaDescriptor schema, Object[] propertyValues
IndexQuery[] query = new IndexQuery[propertyValues.length]; IndexQuery[] query = new IndexQuery[propertyValues.length];
for ( int i = 0; i < query.length; i++ ) for ( int i = 0; i < query.length; i++ )
{ {
query[i] = IndexQuery.exact( schema.getPropertyIds()[i], propertyValues[i] ); query[i] = IndexQuery.exact( schema.getPropertyIds()[i], Values.of( propertyValues[i] ) );
} }
return query; return query;
} }
Expand Down
Expand Up @@ -52,6 +52,7 @@ import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory
import org.neo4j.kernel.api.schema.{IndexQuery, SchemaDescriptorFactory} import org.neo4j.kernel.api.schema.{IndexQuery, SchemaDescriptorFactory}
import org.neo4j.kernel.api.{exceptions, _} import org.neo4j.kernel.api.{exceptions, _}
import org.neo4j.kernel.impl.core.NodeManager import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.values.Values


import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
import scala.collection.{Iterator, mutable} import scala.collection.{Iterator, mutable}
Expand Down Expand Up @@ -130,7 +131,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)


def indexSeek(index: SchemaTypes.IndexDescriptor, value: Any) = def indexSeek(index: SchemaTypes.IndexDescriptor, value: Any) =
JavaConversionSupport.mapToScalaENFXSafe( JavaConversionSupport.mapToScalaENFXSafe(
tc.statement.readOperations().indexQuery(index, IndexQuery.exact(index.propertyId, value)))(nodeOps.getById) tc.statement.readOperations().indexQuery(index, IndexQuery.exact(index.propertyId, Values.of(value))))(nodeOps.getById)


def indexSeekByRange(index: SchemaTypes.IndexDescriptor, value: Any) = value match { def indexSeekByRange(index: SchemaTypes.IndexDescriptor, value: Any) = value match {


Expand Down Expand Up @@ -250,7 +251,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
mapToScalaENFXSafe(tc.statement.readOperations().indexQuery(index, IndexQuery.exists(index.propertyId)))(nodeOps.getById) mapToScalaENFXSafe(tc.statement.readOperations().indexQuery(index, IndexQuery.exists(index.propertyId)))(nodeOps.getById)


override def lockingExactUniqueIndexSearch(index: SchemaTypes.IndexDescriptor, value: Any): Option[Node] = { override def lockingExactUniqueIndexSearch(index: SchemaTypes.IndexDescriptor, value: Any): Option[Node] = {
val nodeId: Long = tc.statement.readOperations().nodeGetFromUniqueIndexSeek(index, IndexQuery.exact(index.propertyId, value)) val nodeId: Long = tc.statement.readOperations().nodeGetFromUniqueIndexSeek(index, IndexQuery.exact(index.propertyId, Values.of(value)))
if (StatementConstants.NO_SUCH_NODE == nodeId) None else Some(nodeOps.getById(nodeId)) if (StatementConstants.NO_SUCH_NODE == nodeId) None else Some(nodeOps.getById(nodeId))
} }


Expand Down Expand Up @@ -325,7 +326,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
} }


def setProperty(id: Long, propertyKeyId: Int, value: Any) = try { def setProperty(id: Long, propertyKeyId: Int, value: Any) = try {
tc.statement.dataWriteOperations().nodeSetProperty(id, properties.Property.property(propertyKeyId, value) ) tc.statement.dataWriteOperations().nodeSetProperty(id, propertyKeyId, Values.of(value))
} catch { } catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => //ignore case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => //ignore
} }
Expand Down Expand Up @@ -395,7 +396,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
} }


override def setProperty(id: Long, propertyKeyId: Int, value: Any) = try { override def setProperty(id: Long, propertyKeyId: Int, value: Any) = try {
tc.statement.dataWriteOperations().relationshipSetProperty(id, properties.Property.property(propertyKeyId, value)) tc.statement.dataWriteOperations().relationshipSetProperty(id, propertyKeyId, Values.of(value))
} catch { } catch {
case _: exceptions.EntityNotFoundException => //ignore case _: exceptions.EntityNotFoundException => //ignore
} }
Expand Down
Expand Up @@ -58,6 +58,7 @@ import org.neo4j.kernel.api.schema.constaints.{ConstraintDescriptor, ConstraintD
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory
import org.neo4j.kernel.impl.core.NodeManager import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.kernel.impl.locking.ResourceTypes import org.neo4j.kernel.impl.locking.ResourceTypes
import org.neo4j.values.Values


import scala.collection.Iterator import scala.collection.Iterator
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
Expand Down Expand Up @@ -140,7 +141,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)


override def indexSeek(index: IndexDescriptor, value: Any) = { override def indexSeek(index: IndexDescriptor, value: Any) = {
indexSearchMonitor.indexSeek(index, value) indexSearchMonitor.indexSeek(index, value)
JavaConversionSupport.mapToScalaENFXSafe(txContext.statement.readOperations().indexQuery(index, IndexQuery.exact(index.propertyId, value)))(nodeOps.getById) JavaConversionSupport.mapToScalaENFXSafe(txContext.statement.readOperations().indexQuery(index, IndexQuery.exact(index.propertyId, Values.of(value))))(nodeOps.getById)
} }


override def indexSeekByRange(index: IndexDescriptor, value: Any) = value match { override def indexSeekByRange(index: IndexDescriptor, value: Any) = value match {
Expand Down Expand Up @@ -328,7 +329,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)


override def setProperty(id: Long, propertyKeyId: Int, value: Any) { override def setProperty(id: Long, propertyKeyId: Int, value: Any) {
try { try {
txContext.statement.dataWriteOperations().nodeSetProperty(id, properties.Property.property(propertyKeyId, value) ) txContext.statement.dataWriteOperations().nodeSetProperty(id, propertyKeyId, Values.of(value) )
} catch { } catch {
case _: exceptions.EntityNotFoundException => //ignore case _: exceptions.EntityNotFoundException => //ignore
} }
Expand Down Expand Up @@ -403,7 +404,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)


override def setProperty(id: Long, propertyKeyId: Int, value: Any) { override def setProperty(id: Long, propertyKeyId: Int, value: Any) {
try { try {
txContext.statement.dataWriteOperations().relationshipSetProperty(id, properties.Property.property(propertyKeyId, value)) txContext.statement.dataWriteOperations().relationshipSetProperty(id, propertyKeyId, Values.of(value) )
} catch { } catch {
case _: exceptions.EntityNotFoundException => //ignore case _: exceptions.EntityNotFoundException => //ignore
} }
Expand Down
Expand Up @@ -56,6 +56,7 @@ import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.api.schema.{IndexQuery, SchemaDescriptorFactory} import org.neo4j.kernel.api.schema.{IndexQuery, SchemaDescriptorFactory}
import org.neo4j.kernel.impl.core.NodeManager import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.kernel.impl.locking.ResourceTypes import org.neo4j.kernel.impl.locking.ResourceTypes
import org.neo4j.values.Values


import scala.collection.Iterator import scala.collection.Iterator
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
Expand Down Expand Up @@ -335,7 +336,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional


override def setProperty(id: Long, propertyKeyId: Int, value: Any) { override def setProperty(id: Long, propertyKeyId: Int, value: Any) {
try { try {
transactionalContext.statement.dataWriteOperations().nodeSetProperty(id, properties.Property.property(propertyKeyId, value) ) transactionalContext.statement.dataWriteOperations().nodeSetProperty(id, propertyKeyId, Values.of(value))
} catch { } catch {
case _: exceptions.EntityNotFoundException => //ignore case _: exceptions.EntityNotFoundException => //ignore
} }
Expand Down Expand Up @@ -410,7 +411,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional


override def setProperty(id: Long, propertyKeyId: Int, value: Any) { override def setProperty(id: Long, propertyKeyId: Int, value: Any) {
try { try {
transactionalContext.statement.dataWriteOperations().relationshipSetProperty(id, properties.Property.property(propertyKeyId, value)) transactionalContext.statement.dataWriteOperations().relationshipSetProperty(id, propertyKeyId, Values.of(value))
} catch { } catch {
case _: exceptions.EntityNotFoundException => //ignore case _: exceptions.EntityNotFoundException => //ignore
} }
Expand Down
Expand Up @@ -56,6 +56,7 @@ import org.neo4j.kernel.impl.locking.ResourceTypes
import JavaConversionSupport._ import JavaConversionSupport._
import org.neo4j.cypher.internal.compatibility.v3_3.runtime.commands.expressions.{KernelPredicate, OnlyDirectionExpander, TypeAndDirectionExpander, UserDefinedAggregator} import org.neo4j.cypher.internal.compatibility.v3_3.runtime.commands.expressions.{KernelPredicate, OnlyDirectionExpander, TypeAndDirectionExpander, UserDefinedAggregator}
import org.neo4j.cypher.internal.compatibility.v3_3.runtime.commands.expressions import org.neo4j.cypher.internal.compatibility.v3_3.runtime.commands.expressions
import org.neo4j.values.Values


import scala.collection.Iterator import scala.collection.Iterator
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
Expand Down Expand Up @@ -335,7 +336,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional


override def setProperty(id: Long, propertyKeyId: Int, value: Any) { override def setProperty(id: Long, propertyKeyId: Int, value: Any) {
try { try {
transactionalContext.statement.dataWriteOperations().nodeSetProperty(id, properties.Property.property(propertyKeyId, value) ) transactionalContext.statement.dataWriteOperations().nodeSetProperty(id, propertyKeyId, Values.of(value))
} catch { } catch {
case _: exceptions.EntityNotFoundException => //ignore case _: exceptions.EntityNotFoundException => //ignore
} }
Expand Down Expand Up @@ -409,7 +410,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional


override def setProperty(id: Long, propertyKeyId: Int, value: Any) { override def setProperty(id: Long, propertyKeyId: Int, value: Any) {
try { try {
transactionalContext.statement.dataWriteOperations().relationshipSetProperty(id, properties.Property.property(propertyKeyId, value)) transactionalContext.statement.dataWriteOperations().relationshipSetProperty(id, propertyKeyId, Values.of(value))
} catch { } catch {
case _: exceptions.EntityNotFoundException => //ignore case _: exceptions.EntityNotFoundException => //ignore
} }
Expand Down
5 changes: 5 additions & 0 deletions community/kernel/pom.xml
Expand Up @@ -160,6 +160,11 @@ the relevant Commercial Agreement.
<artifactId>neo4j-common</artifactId> <artifactId>neo4j-common</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-values</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.neo4j</groupId> <groupId>org.neo4j</groupId>
<artifactId>neo4j-collections</artifactId> <artifactId>neo4j-collections</artifactId>
Expand Down
Expand Up @@ -28,8 +28,7 @@
import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException; import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException;
import org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException; import org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException; import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException;
import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.values.Value;
import org.neo4j.kernel.api.properties.Property;


public interface DataWriteOperations public interface DataWriteOperations
{ {
Expand Down Expand Up @@ -70,26 +69,26 @@ boolean nodeAddLabel( long nodeId, int labelId )
*/ */
boolean nodeRemoveLabel( long nodeId, int labelId ) throws EntityNotFoundException; boolean nodeRemoveLabel( long nodeId, int labelId ) throws EntityNotFoundException;


Property nodeSetProperty( long nodeId, DefinedProperty property ) Value nodeSetProperty( long nodeId, int propertyKeyId, Value value )
throws EntityNotFoundException, AutoIndexingKernelException, throws EntityNotFoundException, AutoIndexingKernelException,
InvalidTransactionTypeKernelException, ConstraintValidationException; InvalidTransactionTypeKernelException, ConstraintValidationException;


Property relationshipSetProperty( long relationshipId, DefinedProperty property ) Value relationshipSetProperty( long relationshipId, int propertyKeyId, Value value )
throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException; throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException;


Property graphSetProperty( DefinedProperty property ); Value graphSetProperty( int propertyKeyId, Value value );


/** /**
* Remove a node's property given the node's id and the property key id and return the value to which * Remove a node's property given the node's id and the property key id and return the value to which
* it was set or null if it was not set on the node * it was set or null if it was not set on the node
*/ */
Property nodeRemoveProperty( long nodeId, int propertyKeyId ) Value nodeRemoveProperty( long nodeId, int propertyKeyId )
throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException; throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException;


Property relationshipRemoveProperty( long relationshipId, int propertyKeyId ) Value relationshipRemoveProperty( long relationshipId, int propertyKeyId )
throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException; throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException;


Property graphRemoveProperty( int propertyKeyId ); Value graphRemoveProperty( int propertyKeyId );


/** /**
* Creates a legacy index in a separate transaction if not yet available. * Creates a legacy index in a separate transaction if not yet available.
Expand Down
Expand Up @@ -23,7 +23,7 @@


import org.neo4j.kernel.api.DataWriteOperations; import org.neo4j.kernel.api.DataWriteOperations;
import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException; import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException;
import org.neo4j.kernel.api.properties.Property; import org.neo4j.values.Value;


/** /**
* Abstract interface for accessing legacy auto indexing facilities for a given type of entity (nodes or relationships) * Abstract interface for accessing legacy auto indexing facilities for a given type of entity (nodes or relationships)
Expand All @@ -38,8 +38,8 @@
*/ */
public interface AutoIndexOperations public interface AutoIndexOperations
{ {
void propertyAdded( DataWriteOperations ops, long entityId, Property property ) throws AutoIndexingKernelException; void propertyAdded( DataWriteOperations ops, long entityId, int propertyKeyId, Value value ) throws AutoIndexingKernelException;
void propertyChanged( DataWriteOperations ops, long entityId, Property oldProperty, Property newProperty ) void propertyChanged( DataWriteOperations ops, long entityId, int propertyKeyId, Value oldValue, Value newValue )
throws AutoIndexingKernelException; throws AutoIndexingKernelException;
void propertyRemoved( DataWriteOperations ops, long entityId, int propertyKey ) void propertyRemoved( DataWriteOperations ops, long entityId, int propertyKey )
throws AutoIndexingKernelException; throws AutoIndexingKernelException;
Expand All @@ -60,14 +60,15 @@ void propertyRemoved( DataWriteOperations ops, long entityId, int propertyKey )
AutoIndexOperations UNSUPPORTED = new AutoIndexOperations() AutoIndexOperations UNSUPPORTED = new AutoIndexOperations()
{ {
@Override @Override
public void propertyAdded( DataWriteOperations ops, long entityId, Property property ) throws AutoIndexingKernelException public void propertyAdded( DataWriteOperations ops, long entityId, int propertyKeyId, Value value )
throws AutoIndexingKernelException
{ {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override @Override
public void propertyChanged( DataWriteOperations ops, long entityId, Property oldProperty, public void propertyChanged( DataWriteOperations ops, long entityId, int propertyKeyId, Value oldValue,
Property newProperty ) throws AutoIndexingKernelException Value newValue ) throws AutoIndexingKernelException
{ {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
Expand Down
Expand Up @@ -31,6 +31,8 @@
import org.neo4j.kernel.api.properties.Property; 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.Values;


public abstract class IndexQuery implements Predicate<Object> public abstract class IndexQuery implements Predicate<Object>
{ {
Expand Down Expand Up @@ -203,12 +205,12 @@ public boolean test( Object value )


public static final class ExactPredicate extends IndexQuery public static final class ExactPredicate extends IndexQuery
{ {
private final DefinedProperty exactValue; private final Value exactValue;


ExactPredicate( int propertyKeyId, Object value ) ExactPredicate( int propertyKeyId, Object value )
{ {
super( propertyKeyId ); super( propertyKeyId );
this.exactValue = Property.property( propertyKeyId, value ); this.exactValue = value instanceof Value ? (Value)value : Values.of( value );
} }


@Override @Override
Expand All @@ -220,12 +222,12 @@ public IndexQueryType type()
@Override @Override
public boolean test( Object value ) public boolean test( Object value )
{ {
return exactValue.valueEquals( value ); return exactValue.equals( Values.of( value ) );
} }


public Object value() public Object value()
{ {
return exactValue.value(); return exactValue.asPublic();
} }
} }


Expand Down
Expand Up @@ -19,14 +19,13 @@
*/ */
package org.neo4j.kernel.api.txstate; package org.neo4j.kernel.api.txstate;


import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.api.properties.Property;
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.OrderedPropertyValues;
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor;
import org.neo4j.kernel.api.schema.constaints.IndexBackedConstraintDescriptor; import org.neo4j.kernel.api.schema.constaints.IndexBackedConstraintDescriptor;
import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;
import org.neo4j.values.Value;


/** /**
* Kernel transaction state, please see {@link org.neo4j.kernel.impl.api.state.TxState} for implementation details. * Kernel transaction state, please see {@link org.neo4j.kernel.impl.api.state.TxState} for implementation details.
Expand All @@ -50,20 +49,19 @@ public interface TransactionState extends ReadableTransactionState


void nodeDoDelete( long nodeId ); void nodeDoDelete( long nodeId );


void nodeDoAddProperty( long nodeId, DefinedProperty newProperty ); void nodeDoAddProperty( long nodeId, int newPropertyKeyId, Value value );


void nodeDoChangeProperty( long nodeId, DefinedProperty replacedProperty, DefinedProperty newProperty ); void nodeDoChangeProperty( long nodeId, int propertyKeyId, Value replacedValue, Value newValue );


void relationshipDoReplaceProperty( long relationshipId, void relationshipDoReplaceProperty( long relationshipId, int propertyKeyId, Value replacedValue, Value newValue );
Property replacedProperty, DefinedProperty newProperty );


void graphDoReplaceProperty( Property replacedProperty, DefinedProperty newProperty ); void graphDoReplaceProperty( int propertyKeyId, Value replacedValue, Value newValue );


void nodeDoRemoveProperty( long nodeId, DefinedProperty removedProperty ); void nodeDoRemoveProperty( long nodeId, int propertyKeyId, Value removedValue );


void relationshipDoRemoveProperty( long relationshipId, DefinedProperty removedProperty ); void relationshipDoRemoveProperty( long relationshipId, int propertyKeyId, Value removedValue );


void graphDoRemoveProperty( DefinedProperty removedProperty ); void graphDoRemoveProperty( int propertyKeyId, Value removedValue );


void nodeDoAddLabel( int labelId, long nodeId ); void nodeDoAddLabel( int labelId, long nodeId );


Expand Down

0 comments on commit e290c4d

Please sign in to comment.