From 55d72a3da2d11565abb2f372bd15d393f8f92b08 Mon Sep 17 00:00:00 2001 From: fickludd Date: Mon, 29 May 2017 22:16:28 +0200 Subject: [PATCH] Monster commit. Sorry. Ripped out Property classes and replaced with Value equivalents. Not completely optimized everywhere, but might give decent performance. In particular haven't worked with cursors, because those will be touched by separate work. --- .../checking/PropertyRecordCheck.java | 2 +- .../full/PropertyAndNodeIndexedCheck.java | 9 +- .../checking/full/PropertyReader.java | 15 +- .../full/FullCheckIntegrationTest.java | 8 +- .../org/neo4j/kernel/api/ReadOperations.java | 2 +- .../index/IndexEntryConflictException.java | 69 +++- .../api/index/DelegatingIndexReader.java | 3 +- .../kernel/api/index/IndexEntryUpdate.java | 33 +- .../kernel/api/index/PropertyAccessor.java | 4 +- .../kernel/api/properties/ArrayValue.java | 205 ----------- .../api/properties/BooleanArrayProperty.java | 89 ----- .../api/properties/BooleanProperty.java | 60 ---- .../api/properties/ByteArrayProperty.java | 50 --- .../kernel/api/properties/ByteProperty.java | 47 --- .../api/properties/CharArrayProperty.java | 120 ------- .../kernel/api/properties/CharProperty.java | 87 ----- .../api/properties/DefinedProperty.java | 223 ------------ .../api/properties/DoubleArrayProperty.java | 50 --- .../kernel/api/properties/DoubleProperty.java | 43 --- .../api/properties/FloatArrayProperty.java | 50 --- .../kernel/api/properties/FloatProperty.java | 43 --- .../FloatingPointArrayProperty.java | 116 ------ .../FloatingPointNumberProperty.java | 74 ---- .../api/properties/IntArrayProperty.java | 50 --- .../kernel/api/properties/IntProperty.java | 47 --- .../api/properties/IntegralArrayProperty.java | 116 ------ .../properties/IntegralNumberProperty.java | 78 ---- .../api/properties/LazyArrayProperty.java | 310 ---------------- .../kernel/api/properties/LazyProperty.java | 85 ----- .../api/properties/LazyStringProperty.java | 48 --- .../api/properties/LongArrayProperty.java | 50 --- .../kernel/api/properties/LongProperty.java | 43 --- .../kernel/api/properties/NoProperty.java | 95 ----- .../kernel/api/properties/NumberProperty.java | 28 -- .../neo4j/kernel/api/properties/Property.java | 220 ------------ .../api/properties/PropertyConversion.java | 171 --------- .../api/properties/PropertyKeyValue.java | 98 +++++ .../api/properties/ShortArrayProperty.java | 50 --- .../kernel/api/properties/ShortProperty.java | 47 --- .../api/properties/StringArrayProperty.java | 105 ------ .../kernel/api/properties/StringProperty.java | 86 ----- .../neo4j/kernel/api/schema/IndexQuery.java | 23 +- .../api/schema/OrderedPropertyValues.java | 214 ----------- .../kernel/api/txstate/TransactionState.java | 4 +- .../ConstraintEnforcingEntityOperations.java | 8 +- .../impl/api/GuardingStatementOperations.java | 2 +- .../neo4j/kernel/impl/api/LookupFilter.java | 9 +- .../kernel/impl/api/OperationsFacade.java | 2 +- .../api/StateHandlingStatementOperations.java | 28 +- .../api/cursor/TxAbstractPropertyCursor.java | 9 +- .../impl/api/cursor/TxAllPropertyCursor.java | 9 +- .../api/cursor/TxSinglePropertyCursor.java | 9 +- .../kernel/impl/api/index/IndexStoreView.java | 7 +- .../kernel/impl/api/index/NodeUpdates.java | 103 ++---- .../kernel/impl/api/index/PropertyLoader.java | 3 +- .../PropertyPhysicalToLogicalConverter.java | 10 +- .../api/operations/EntityReadOperations.java | 2 +- .../impl/api/state/IndexTxStateUpdater.java | 42 +-- .../api/state/PropertyContainerStateImpl.java | 9 +- .../neo4j/kernel/impl/api/state/TxState.java | 84 ++--- .../impl/api/store/StorePropertyCursor.java | 5 +- .../api/store/StorePropertyPayloadCursor.java | 28 +- .../impl/core/GraphPropertiesProxy.java | 2 +- .../org/neo4j/kernel/impl/core/NodeProxy.java | 2 +- .../core/PropertyContainerProxyHelper.java | 2 +- .../kernel/impl/core/RelationshipProxy.java | 2 +- .../TxStateTransactionDataSnapshot.java | 51 +-- .../impl/factory/GraphDatabaseFacade.java | 1 - .../schema/NativeSchemaIndexPopulator.java | 5 +- .../schema/NonUniqueSchemaNumberKey.java | 9 +- .../schema/NonUniqueSchemaNumberValue.java | 9 +- .../impl/index/schema/SchemaNumberKey.java | 4 +- .../impl/index/schema/SchemaNumberValue.java | 3 +- .../schema/SchemaNumberValueConversion.java | 8 +- .../index/schema/UniqueSchemaNumberKey.java | 9 +- .../index/schema/UniqueSchemaNumberValue.java | 9 +- .../kernel/impl/locking/ResourceTypes.java | 16 +- .../TransactionToRecordStateVisitor.java | 25 +- .../kernel/impl/store/PropertyStore.java | 59 +-- .../neo4j/kernel/impl/store/PropertyType.java | 132 +++---- .../impl/store/record/PropertyBlock.java | 16 +- .../IndexConsultedPropertyBlockSweeper.java | 3 +- .../propertydeduplication/IndexLookup.java | 3 +- .../transaction/state/PropertyCreator.java | 7 +- .../transaction/state/PropertyLoader.java | 2 +- .../state/TransactionRecordState.java | 42 +-- .../storeview/NeoStoreIndexStoreView.java | 15 +- .../storeview/StoreViewNodeStoreScan.java | 8 +- .../neo4j/storageengine/api/PropertyItem.java | 4 +- .../storageengine/api/StorageProperty.java | 17 +- .../storageengine/api/schema/IndexReader.java | 6 +- .../api/txstate/ReadableTransactionState.java | 5 +- .../unsafe/batchinsert/BatchInserter.java | 5 +- .../internal/BatchInserterImpl.java | 21 +- .../FileSystemClosingBatchInserter.java | 5 +- .../store/BatchingTokenRepository.java | 4 +- .../IndexEntryConflictExceptionTest.java | 11 +- .../CompositeIndexAccessorCompatibility.java | 31 +- .../CompositeIndexPopulatorCompatibility.java | 17 +- .../api/index/IndexEntryUpdateTest.java | 33 +- .../kernel/api/index/IndexQueryHelper.java | 36 ++ .../api/index/NodePropertyAccessor.java | 21 +- .../kernel/api/index/NodeUpdatesTest.java | 65 ++-- .../SimpleIndexAccessorCompatibility.java | 107 +++--- .../SimpleIndexPopulatorCompatibility.java | 24 +- .../api/properties/DefinedPropertyTest.java | 173 --------- .../api/properties/LazyPropertyTest.java | 183 ---------- .../properties/PropertyConversionTest.java | 308 ---------------- .../api/properties/PropertyEqualityTest.java | 338 ------------------ .../api/LockingStatementOperationsTest.java | 2 - .../ConstraintIndexCreatorTest.java | 3 +- .../BatchingMultipleIndexPopulatorTest.java | 16 +- .../kernel/impl/api/index/IndexCRUDIT.java | 5 +- .../api/index/IndexPopulationJobTest.java | 30 +- .../impl/api/index/IndexRecoveryIT.java | 3 +- .../impl/api/index/IndexingServiceTest.java | 7 +- .../api/index/MultipleIndexPopulatorTest.java | 7 +- .../MultipleIndexPopulatorUpdatesTest.java | 3 +- ...ropertyPhysicalToLogicalConverterTest.java | 24 +- .../api/index/inmemory/HashBasedIndex.java | 3 +- .../api/index/inmemory/InMemoryIndex.java | 5 +- .../inmemory/InMemoryIndexImplementation.java | 46 +-- .../index/inmemory/UniqueInMemoryIndex.java | 19 +- .../state/IndexQueryTransactionStateTest.java | 6 +- .../api/state/IndexTxStateUpdaterTest.java | 16 +- .../state/PropertyContainerStateImplTest.java | 13 +- .../StateHandlingStatementOperationsTest.java | 31 +- .../StateOperationsAutoIndexingTest.java | 8 +- .../kernel/impl/api/state/StubCursors.java | 11 +- .../api/state/TxStateCompositeIndexTest.java | 60 ++-- .../kernel/impl/api/state/TxStateTest.java | 7 +- .../impl/api/state/TxStateVisitorTest.java | 5 +- .../api/store/StorageLayerPropertyTest.java | 9 +- .../api/store/StorePropertyCursorTest.java | 31 +- .../store/StorePropertyPayloadCursorTest.java | 7 +- .../core/IteratingPropertyReceiverTest.java | 7 +- .../TxStateTransactionDataViewTest.java | 15 +- .../FullScanNonUniqueIndexSamplerTest.java | 8 +- .../NativeSchemaIndexPopulatorTest.java | 3 +- .../kernel/impl/store/NeoStoresTest.java | 191 +++++----- .../kernel/impl/store/PropertyRecordTest.java | 3 +- .../store/RecordStoreConsistentReadTest.java | 4 +- .../store/format/LimitedRecordGenerators.java | 3 +- .../impl/transaction/command/Commands.java | 3 +- .../state/PropertyCreatorTest.java | 10 +- .../transaction/state/PropertyLoaderTest.java | 11 +- .../state/TransactionRecordStateTest.java | 81 +++-- .../LabelScanViewNodeStoreScanTest.java | 11 +- .../storeview/NeoStoreIndexStoreViewTest.java | 9 +- .../batchinsert/internal/BatchInsertTest.java | 111 +++--- .../schema/reader/PartitionedIndexReader.java | 3 +- .../impl/schema/reader/SimpleIndexReader.java | 3 +- .../CompositeDuplicateCheckingCollector.java | 40 +-- .../DuplicateCheckingCollector.java | 26 +- .../index/LuceneSchemaIndexPopulationIT.java | 3 +- ...neSchemaIndexUniquenessVerificationIT.java | 130 +++---- .../api/impl/index/TestPropertyAccessor.java | 13 +- .../SimpleUniquenessVerifierTest.java | 8 +- .../schema/AccessUniqueDatabaseIndexTest.java | 7 +- .../DatabaseCompositeIndexAccessorTest.java | 7 +- .../schema/DatabaseIndexAccessorTest.java | 7 +- .../api/impl/schema/LuceneSchemaIndexIT.java | 3 +- .../LuceneSchemaIndexPopulatorTest.java | 9 +- ...queDatabaseIndexPopulatingUpdaterTest.java | 7 +- .../NonUniqueDatabaseIndexPopulatorTest.java | 19 +- ...queDatabaseIndexPopulatingUpdaterTest.java | 7 +- .../UniqueDatabaseIndexPopulatorTest.java | 99 +++-- .../reader/PartitionedIndexReaderTest.java | 8 +- .../schema/reader/SimpleIndexReaderTest.java | 2 +- .../schema/IndexPopulationFlipRaceIT.java | 7 +- ...ltiIndexPopulationConcurrentUpdatesIT.java | 32 +- .../main/java/org/neo4j/values/TextValue.java | 8 +- .../java/org/neo4j/values/ValueTuple.java | 37 +- .../main/java/org/neo4j/values/Values.java | 22 +- .../acceptance/Neo4jValueComparisonTest.scala | 15 +- 175 files changed, 1547 insertions(+), 5419 deletions(-) delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/ArrayValue.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/DefinedProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointNumberProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralNumberProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyStringProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/NoProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/NumberProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/Property.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyConversion.java create mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyKeyValue.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringArrayProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringProperty.java delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/api/schema/OrderedPropertyValues.java delete mode 100644 community/kernel/src/test/java/org/neo4j/kernel/api/properties/DefinedPropertyTest.java delete mode 100644 community/kernel/src/test/java/org/neo4j/kernel/api/properties/LazyPropertyTest.java delete mode 100644 community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyConversionTest.java delete mode 100644 community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyEqualityTest.java diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/PropertyRecordCheck.java b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/PropertyRecordCheck.java index 8e2488160b574..aef8e58361652 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/PropertyRecordCheck.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/PropertyRecordCheck.java @@ -82,7 +82,7 @@ public static void checkDataBlock( PropertyBlock block, default: try { - type.getValue( block, null ); + type.getValueNow( block, null ); } catch ( Exception e ) { diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java index 0e9d7ac86bd8f..bba0b37972155 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyAndNodeIndexedCheck.java @@ -45,6 +45,7 @@ import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.storageengine.api.schema.IndexReader; +import org.neo4j.values.Value; import org.neo4j.values.Values; import static java.lang.String.format; @@ -105,7 +106,7 @@ private void matchIndexesToNode( int[] indexPropertyIds = indexRule.schema().getPropertyIds(); if ( nodeHasSchemaProperties( nodePropertyMap, indexPropertyIds ) ) { - Object[] values = getPropertyValues( nodePropertyMap, indexPropertyIds ); + Value[] values = getPropertyValues( nodePropertyMap, indexPropertyIds ); try ( IndexReader reader = indexes.accessorFor( indexRule ).newReader() ) { long nodeId = record.getId(); @@ -197,13 +198,13 @@ private void checkProperty( NodeRecord record, } } - private Object[] getPropertyValues( PrimitiveIntObjectMap propertyMap, int[] indexPropertyIds ) + private Value[] getPropertyValues( PrimitiveIntObjectMap propertyMap, int[] indexPropertyIds ) { - Object[] values = new Object[indexPropertyIds.length]; + Value[] values = new Value[indexPropertyIds.length]; for ( int i = 0; i < indexPropertyIds.length; i++ ) { PropertyBlock propertyBlock = propertyMap.get( indexPropertyIds[i] ); - values[i] = propertyReader.propertyValue( propertyBlock ).value(); + values[i] = propertyReader.propertyValue( propertyBlock ); } return values; } diff --git a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyReader.java b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyReader.java index a6b996d4a3394..d55759a6e43ac 100644 --- a/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyReader.java +++ b/community/consistency-check/src/main/java/org/neo4j/consistency/checking/full/PropertyReader.java @@ -26,8 +26,7 @@ import org.neo4j.function.Suppliers; import org.neo4j.kernel.api.index.PropertyAccessor; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.impl.store.NodeStore; import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.StoreAccess; @@ -35,6 +34,10 @@ import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.Record; +import org.neo4j.storageengine.api.StorageProperty; +import org.neo4j.values.Value; +import org.neo4j.values.Values; + import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE; public class PropertyReader implements PropertyAccessor @@ -93,13 +96,13 @@ public List propertyBlocks( NodeRecord nodeRecord ) return propertyBlocks; } - public DefinedProperty propertyValue( PropertyBlock block ) + public Value propertyValue( PropertyBlock block ) { - return block.getType().readProperty( block.getKeyIndexId(), block, Suppliers.singleton( propertyStore ) ); + return block.getType().getValue( block, propertyStore ); } @Override - public Property getProperty( long nodeId, int propertyKeyId ) + public Value getPropertyValue( long nodeId, int propertyKeyId ) { NodeRecord nodeRecord = nodeStore.newRecord(); if ( nodeStore.getRecord( nodeId, nodeRecord, FORCE ).inUse() ) @@ -112,6 +115,6 @@ public Property getProperty( long nodeId, int propertyKeyId ) } } } - return Property.noNodeProperty( nodeId, propertyKeyId ); + return Values.NO_VALUE; } } diff --git a/community/consistency-check/src/test/java/org/neo4j/consistency/checking/full/FullCheckIntegrationTest.java b/community/consistency-check/src/test/java/org/neo4j/consistency/checking/full/FullCheckIntegrationTest.java index d82961a040a85..980b37e27034b 100644 --- a/community/consistency-check/src/test/java/org/neo4j/consistency/checking/full/FullCheckIntegrationTest.java +++ b/community/consistency-check/src/test/java/org/neo4j/consistency/checking/full/FullCheckIntegrationTest.java @@ -107,6 +107,8 @@ import org.neo4j.storageengine.api.schema.SchemaRule; import org.neo4j.string.UTF8; import org.neo4j.test.rule.SuppressOutput; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.lang.String.format; import static java.util.Arrays.asList; @@ -598,12 +600,12 @@ public void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex() throws Ex .andThatsAllFolks(); } - private Object[] values( IndexRule indexRule ) + private Value[] values( IndexRule indexRule ) { switch ( indexRule.schema().getPropertyIds().length ) { - case 1: return Iterators.array( VALUE1 ); - case 2: return Iterators.array( VALUE1, VALUE2 ); + case 1: return Iterators.array( Values.of( VALUE1 ) ); + case 2: return Iterators.array( Values.of( VALUE1 ), Values.of( VALUE2 ) ); default: throw new UnsupportedOperationException(); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java index e54f2730930b9..18e4718f67e09 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java @@ -158,7 +158,7 @@ RelationshipIterator nodeGetRelationships( long nodeId, Direction direction, int long nodeGetFromUniqueIndexSeek( IndexDescriptor index, IndexQuery.ExactPredicate... predicates ) throws IndexNotFoundKernelException, IndexBrokenKernelException, IndexNotApplicableKernelException; - long nodesCountIndexed( IndexDescriptor index, long nodeId, Object value ) + long nodesCountIndexed( IndexDescriptor index, long nodeId, Value value ) throws IndexNotFoundKernelException, IndexBrokenKernelException; boolean nodeExists( long nodeId ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictException.java b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictException.java index 79a6b649ea091..654b62a277595 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictException.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictException.java @@ -19,14 +19,18 @@ */ package org.neo4j.kernel.api.exceptions.index; +import java.util.Arrays; + import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.exceptions.KernelException; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.SchemaUtil; import org.neo4j.kernel.api.schema.index.IndexDescriptor; +import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; import static java.lang.String.format; +import static java.lang.String.valueOf; import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE; /** @@ -34,16 +38,16 @@ */ public class IndexEntryConflictException extends Exception { - private final OrderedPropertyValues propertyValues; + private final ValueTuple propertyValues; private final long addedNodeId; private final long existingNodeId; - public IndexEntryConflictException( long existingNodeId, long addedNodeId, Object propertyValue ) + public IndexEntryConflictException( long existingNodeId, long addedNodeId, Value propertyValue ) { - this( existingNodeId, addedNodeId, OrderedPropertyValues.ofUndefined( propertyValue ) ); + this( existingNodeId, addedNodeId, ValueTuple.of( propertyValue ) ); } - public IndexEntryConflictException( long existingNodeId, long addedNodeId, OrderedPropertyValues propertyValues ) + public IndexEntryConflictException( long existingNodeId, long addedNodeId, ValueTuple propertyValues ) { super( format( "Both node %d and node %d share the property value %s", existingNodeId, addedNodeId, propertyValues ) ); @@ -81,14 +85,14 @@ public String evidenceMessage( TokenNameLookup tokenNameLookup, LabelSchemaDescr } } - public OrderedPropertyValues getPropertyValues() + public ValueTuple getPropertyValues() { return propertyValues; } - public Object getSinglePropertyValue() + public Value getSinglePropertyValue() { - return propertyValues.getSinglePropertyValue(); + return propertyValues.getOnlyValue(); } public long getAddedNodeId() @@ -150,8 +154,55 @@ private String propertyString( TokenNameLookup tokenNameLookup, int[] propertyId sb.append( '`' ); sb.append( tokenNameLookup.propertyKeyGetName( propertyIds[i] ) ); sb.append( "` = " ); - sb.append( OrderedPropertyValues.quote( propertyValues.valueAt( i ) ) ); + sb.append( quote( propertyValues.valueAt( i ).asPublic() ) ); } return sb.toString(); } + + private static String quote( Object propertyValue ) + { + if ( propertyValue instanceof String ) + { + return format( "'%s'", propertyValue ); + } + else if ( propertyValue.getClass().isArray() ) + { + Class type = propertyValue.getClass().getComponentType(); + if ( type == Boolean.TYPE ) + { + return Arrays.toString( (boolean[]) propertyValue ); + } + else if ( type == Byte.TYPE ) + { + return Arrays.toString( (byte[]) propertyValue ); + } + else if ( type == Short.TYPE ) + { + return Arrays.toString( (short[]) propertyValue ); + } + else if ( type == Character.TYPE ) + { + return Arrays.toString( (char[]) propertyValue ); + } + else if ( type == Integer.TYPE ) + { + return Arrays.toString( (int[]) propertyValue ); + } + else if ( type == Long.TYPE ) + { + return Arrays.toString( (long[]) propertyValue ); + } + else if ( type == Float.TYPE ) + { + return Arrays.toString( (float[]) propertyValue ); + } + else if ( type == Double.TYPE ) + { + return Arrays.toString( (double[]) propertyValue ); + } + return Arrays.toString( (Object[]) propertyValue ); + } + return valueOf( propertyValue ); + } + } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/DelegatingIndexReader.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/DelegatingIndexReader.java index 1022fc6be5df5..4518c2749ea01 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/index/DelegatingIndexReader.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/DelegatingIndexReader.java @@ -24,6 +24,7 @@ import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexSampler; +import org.neo4j.values.Value; public class DelegatingIndexReader implements IndexReader { @@ -35,7 +36,7 @@ public DelegatingIndexReader( IndexReader delegate ) } @Override - public long countIndexedNodes( long nodeId, Object... propertyValues ) + public long countIndexedNodes( long nodeId, Value... propertyValues ) { return delegate.countIndexedNodes( nodeId, propertyValues ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexEntryUpdate.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexEntryUpdate.java index bd3ebab8b695c..4c212fe1408cb 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexEntryUpdate.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexEntryUpdate.java @@ -24,6 +24,7 @@ import org.neo4j.kernel.api.schema.LabelSchemaSupplier; import org.neo4j.kernel.api.schema.SchemaUtil; import org.neo4j.kernel.impl.api.index.UpdateMode; +import org.neo4j.values.Value; import static java.lang.String.format; @@ -36,17 +37,17 @@ public class IndexEntryUpdate { private final long entityId; private final UpdateMode updateMode; - private final Object[] before; - private final Object[] values; + private final Value[] before; + private final Value[] values; private final INDEX_KEY indexKey; - private IndexEntryUpdate( long entityId, INDEX_KEY indexKey, UpdateMode updateMode, Object... values ) + private IndexEntryUpdate( long entityId, INDEX_KEY indexKey, UpdateMode updateMode, Value... values ) { this( entityId, indexKey, updateMode, null, values ); } - private IndexEntryUpdate( long entityId, INDEX_KEY indexKey, UpdateMode updateMode, Object[] before, - Object[] values ) + private IndexEntryUpdate( long entityId, INDEX_KEY indexKey, UpdateMode updateMode, Value[] before, + Value[] values ) { // we do not support partial index entries assert indexKey.schema().getPropertyIds().length == values.length : @@ -76,7 +77,7 @@ public INDEX_KEY indexKey() return indexKey; } - public Object[] values() + public Value[] values() { return values; } @@ -103,11 +104,11 @@ public boolean equals( Object o ) { return false; } - if ( !Arrays.deepEquals( before, that.before ) ) + if ( !Arrays.equals( before, that.before ) ) { return false; } - if ( !Arrays.deepEquals( values, that.values ) ) + if ( !Arrays.equals( values, that.values ) ) { return false; } @@ -119,8 +120,8 @@ public int hashCode() { int result = (int) (entityId ^ (entityId >>> 32)); result = 31 * result + (updateMode != null ? updateMode.hashCode() : 0); - result = 31 * result + Arrays.deepHashCode( before ); - result = 31 * result + Arrays.deepHashCode( values ); + result = 31 * result + Arrays.hashCode( before ); + result = 31 * result + Arrays.hashCode( values ); result = 31 * result + (indexKey != null ? indexKey.schema().hashCode() : 0); return result; } @@ -133,31 +134,31 @@ public String toString() } public static IndexEntryUpdate add( - long nodeId, INDEX_KEY indexKey, Object... values ) + long nodeId, INDEX_KEY indexKey, Value... values ) { return new IndexEntryUpdate<>( nodeId, indexKey, UpdateMode.ADDED, values ); } public static IndexEntryUpdate remove( - long nodeId, INDEX_KEY indexKey, Object... values ) + long nodeId, INDEX_KEY indexKey, Value... values ) { return new IndexEntryUpdate<>( nodeId, indexKey, UpdateMode.REMOVED, values ); } public static IndexEntryUpdate change( - long nodeId, INDEX_KEY indexKey, Object before, Object after ) + long nodeId, INDEX_KEY indexKey, Value before, Value after ) { return new IndexEntryUpdate<>( nodeId, indexKey, UpdateMode.CHANGED, - new Object[]{before}, new Object[]{after} ); + new Value[]{before}, new Value[]{after} ); } public static IndexEntryUpdate change( - long nodeId, INDEX_KEY indexKey, Object[] before, Object[] after ) + long nodeId, INDEX_KEY indexKey, Value[] before, Value[] after ) { return new IndexEntryUpdate<>( nodeId, indexKey, UpdateMode.CHANGED, before, after ); } - public Object[] beforeValues() + public Value[] beforeValues() { if ( before == null ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/PropertyAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/PropertyAccessor.java index cd5b8f8ba68b8..27f9b56e2d118 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/index/PropertyAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/PropertyAccessor.java @@ -20,12 +20,12 @@ package org.neo4j.kernel.api.index; import org.neo4j.kernel.api.exceptions.EntityNotFoundException; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.values.Value; /** * Used by the {@link IndexPopulator} for verifying constraints, if need be. */ public interface PropertyAccessor { - Property getProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException; + Value getPropertyValue( long nodeId, int propertyKeyId ) throws EntityNotFoundException; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ArrayValue.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ArrayValue.java deleted file mode 100644 index 996f475b5abd4..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ArrayValue.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -interface ArrayValue -{ - int length(); - - interface IntegralArray extends ArrayValue - { - long longValue( int index ); - } - - interface FloatingPointArray extends ArrayValue - { - double doubleValue( int index ); - } - - final class ByteArray implements IntegralArray - { - private final byte[] value; - - ByteArray( byte[] value ) - { - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } - } - - final class ShortArray implements IntegralArray - { - private final short[] value; - - ShortArray( short[] value ) - { - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } - } - - final class IntArray implements IntegralArray - { - private final int[] value; - - IntArray( int[] value ) - { - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } - } - - final class LongArray implements IntegralArray - { - private final long[] value; - - LongArray( long[] value ) - { - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } - } - - final class FloatArray implements FloatingPointArray - { - private final float[] value; - - FloatArray( float[] value ) - { - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public double doubleValue( int index ) - { - return value[index]; - } - } - - final class DoubleArray implements FloatingPointArray - { - private final double[] value; - - DoubleArray( double[] value ) - { - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public double doubleValue( int index ) - { - return value[index]; - } - } - - final class NumberArray implements IntegralArray, FloatingPointArray - { - static IntegralArray asIntegral( Number[] value ) - { - return new NumberArray( value ); - } - - static FloatingPointArray asFloatingPoint( Number[] value ) - { - return new NumberArray( value ); - } - - private final Number[] value; - - private NumberArray( Number[] value ) - { - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index].longValue(); - } - - @Override - public double doubleValue( int index ) - { - return value[index].doubleValue(); - } - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanArrayProperty.java deleted file mode 100644 index 0c40b92f455c2..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanArrayProperty.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.Arrays; - -class BooleanArrayProperty extends DefinedProperty -{ - private final boolean[] value; - - BooleanArrayProperty( int propertyKeyId, boolean[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public boolean[] value() - { - return value.clone(); - } - - @Override - public boolean valueEquals( Object other ) - { - return valueEquals( this.value, other ); - } - - static boolean valueEquals( boolean[] value, Object other ) - { - if ( other instanceof boolean[] ) - { - return Arrays.equals( value, (boolean[]) other ); - } - if ( other instanceof Boolean[] ) - { - Boolean[] that = (Boolean[]) other; - int length = value.length; - if ( length == that.length ) - { - for ( int i = 0; i < length; i++ ) - { - Boolean bool = that[i]; - if ( bool == null || bool != value[i] ) - { - return false; - } - } - return true; - } - } - return false; - } - - @Override - public int valueHash() - { - return hash( value ); - } - - static int hash( boolean[] value ) - { - return Arrays.hashCode( value ); - } - - @Override - boolean hasEqualValue( DefinedProperty that ) - { - return that instanceof BooleanArrayProperty && Arrays.equals( this.value, ((BooleanArrayProperty) that).value ); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanProperty.java deleted file mode 100644 index 9c38c472a1b70..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/BooleanProperty.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -/** - * This does not extend AbstractProperty since the JVM can take advantage of the 4 byte initial field alignment if - * we don't extend a class that has fields. - */ -final class BooleanProperty extends DefinedProperty -{ - private final boolean value; - - BooleanProperty( int propertyKeyId, boolean value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - @SuppressWarnings( "UnnecessaryUnboxing" ) - public boolean valueEquals( Object other ) - { - return other instanceof Boolean && value == ((Boolean) other).booleanValue(); - } - - @Override - public Boolean value() - { - return value; - } - - @Override - public int valueHash() - { - return value ? -1 : 0; - } - - @Override - boolean hasEqualValue( DefinedProperty that ) - { - return that instanceof BooleanProperty && value == ((BooleanProperty) that).value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteArrayProperty.java deleted file mode 100644 index cb354c1e497f7..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteArrayProperty.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -class ByteArrayProperty extends IntegralArrayProperty -{ - private final byte[] value; - - ByteArrayProperty( int propertyKeyId, byte[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public byte[] value() - { - return value.clone(); - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteProperty.java deleted file mode 100644 index 7c8ed7a20cffa..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ByteProperty.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -/** - * This does not extend AbstractProperty since the JVM can take advantage of the 4 byte initial field alignment if - * we don't extend a class that has fields. - */ -final class ByteProperty extends IntegralNumberProperty -{ - private final byte value; - - ByteProperty( int propertyKeyId, byte value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - public Byte value() - { - return value; - } - - @Override - public long longValue() - { - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharArrayProperty.java deleted file mode 100644 index abe069f073cf2..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharArrayProperty.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.Arrays; - -class CharArrayProperty extends DefinedProperty -{ - final char[] value; - - CharArrayProperty( int propertyKeyId, char[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public char[] value() - { - return value.clone(); - } - - @Override - public boolean valueEquals( Object other ) - { - return valueEquals( this.value, other ); - } - - static boolean valueEquals( char[] value, Object other ) - { - if ( other instanceof char[] ) - { - return Arrays.equals( value, (char[]) other ); - } - if ( other instanceof Character[] ) - { - Character[] that = (Character[]) other; - if ( value.length == that.length ) - { - for ( int i = 0; i < that.length; i++ ) - { - Character character = that[i]; - if ( character == null || character != value[i] ) - { - return false; - } - } - return true; - } - } - else if ( other instanceof String[] ) - { - return eq( (String[]) other, value ); - } - // else if ( other instanceof String ) // should we perhaps support this? - return false; - } - - @Override - public int valueHash() - { - return hash( value ); - } - - static int hash( char[] value ) - { - return Arrays.hashCode( value ); - } - - @Override - boolean hasEqualValue( DefinedProperty other ) - { - if ( other instanceof CharArrayProperty ) - { - CharArrayProperty that = (CharArrayProperty) other; - return Arrays.equals( this.value, that.value ); - } - if ( other instanceof StringArrayProperty ) - { - StringArrayProperty that = (StringArrayProperty) other; - return eq( that.value, this.value ); - } - return false; - } - - static boolean eq( String[] strings, char[] chars ) - { - if ( strings.length == chars.length ) - { - for ( int i = 0; i < strings.length; i++ ) - { - String str = strings[i]; - if ( str == null || str.length() != 1 || str.charAt( 0 ) != chars[i] ) - { - return false; - } - } - return true; - } - return false; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharProperty.java deleted file mode 100644 index d44f245b37d87..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/CharProperty.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -/** - * This does not extend AbstractProperty since the JVM can take advantage of the 4 byte initial field alignment if - * we don't extend a class that has fields. - */ -final class CharProperty extends DefinedProperty implements DefinedProperty.WithStringValue -{ - final char value; - - CharProperty( int propertyKeyId, char value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - @SuppressWarnings( "UnnecessaryUnboxing" ) - public boolean valueEquals( Object other ) - { - if ( other instanceof Character ) - { - return value == ((Character) other).charValue(); - } - if ( other instanceof String ) - { - String that = (String) other; - return that.length() == 1 && that.charAt( 0 ) == value; - } - return false; - } - - @Override - public Character value() - { - return value; - } - - @Override - public int valueHash() - { - return value; - } - - @Override - boolean hasEqualValue( DefinedProperty that ) - { - if ( that instanceof CharProperty ) - { - return value == ((CharProperty) that).value; - } - else if ( that instanceof StringProperty ) - { - String str = ((StringProperty) that).value(); - return str.length() == 1 && value == str.charAt( 0 ); - } - else - { - return false; - } - } - - @Override - public String stringValue() - { - return Character.toString( value ); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DefinedProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DefinedProperty.java deleted file mode 100644 index 7d89833a9154f..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DefinedProperty.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.Comparator; - -import org.neo4j.helpers.MathUtil; -import org.neo4j.helpers.Strings; - -import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY; -import static org.neo4j.kernel.impl.api.PropertyValueComparison.COMPARE_VALUES; - - -/** - * Base class for properties that have a value. - * - * About {@link #sizeOfObjectInBytesIncludingOverhead() size} of property objects. - * Java Object layout: - * - * |----4b----|----4b----| - * | header | ref | - * | hashCode | (unused) | - * | (members of object) | - * | ... | ... | - * | ... | ... | - * |---------------------| - * - * The property key, being an int and the first member of {@link Property} objects will be squeezed into - * the (unused) area. Added members after that will be appended after that. The total space of the object - * will be aligned to whole 8 bytes. - */ -public abstract class DefinedProperty extends Property -{ - public static final DefinedProperty NO_SUCH_PROPERTY = new DefinedProperty( NO_SUCH_PROPERTY_KEY ) - { - @Override - public Object value() - { - throw new UnsupportedOperationException( "This property does not exist!" ); - } - - @Override - public int valueHash() - { - return -1; - } - - @Override - boolean hasEqualValue( DefinedProperty that ) - { - return false; - } - - @Override - public boolean valueEquals( Object other ) - { - return false; - } - }; - - public static final Comparator COMPARATOR = ( left, right ) -> - { - int cmp = left.propertyKeyId - right.propertyKeyId; - if ( cmp == 0 ) - { - return COMPARE_VALUES.compare( left.value(), right.value() ); - } - - // else - return cmp; - }; - - @Override - public boolean isDefined() - { - return true; - } - - @Override - public abstract Object value(); - - @Override - public Object value( Object defaultValue ) - { - return value(); - } - - @Override - public String toString() - { - return getClass().getSimpleName() + "[propertyKeyId=" + propertyKeyId() + ", value=" + valueAsString() + "]"; - } - - @Override - public final boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o instanceof DefinedProperty ) - { - DefinedProperty that = (DefinedProperty) o; - if ( this.propertyKeyId == that.propertyKeyId ) - { - if ( o instanceof LazyProperty ) - { // the cost of boxing is small compared to what LazyProperty does - return that.valueEquals( value() ); - } - else - { - return hasEqualValue( that ); - } - } - } - return false; - } - - @Override - public final int hashCode() - { - return propertyKeyId ^ valueHash(); - } - - public abstract int valueHash(); - - /** We never pass {@link LazyProperty} to this method, since we check for it in {@link #equals(Object)}. */ - abstract boolean hasEqualValue( DefinedProperty that ); - - @Override - public String valueAsString() - { - return Strings.prettyPrint( value() ); - } - - DefinedProperty( int propertyKeyId ) - { - super( propertyKeyId ); - } - - static boolean numbersEqual( ArrayValue.IntegralArray lhs, ArrayValue.IntegralArray rhs ) - { - int length = lhs.length(); - if ( length != rhs.length() ) - { - return false; - } - for ( int i = 0; i < length; i++ ) - { - if ( lhs.longValue( i ) != rhs.longValue( i ) ) - { - return false; - } - } - return true; - } - - static boolean numbersEqual( ArrayValue.FloatingPointArray lhs, ArrayValue.FloatingPointArray rhs ) - { - int length = lhs.length(); - if ( length != rhs.length() ) - { - return false; - } - for ( int i = 0; i < length; i++ ) - { - if ( lhs.doubleValue( i ) != rhs.doubleValue( i ) ) - { - return false; - } - } - return true; - } - - static boolean numbersEqual( ArrayValue.FloatingPointArray fps, ArrayValue.IntegralArray ins ) - { - int length = ins.length(); - if ( length != fps.length() ) - { - return false; - } - for ( int i = 0; i < length; i++ ) - { - if ( !MathUtil.numbersEqual( fps.doubleValue( i ), ins.longValue( i ) ) ) - { - return false; - } - } - return true; - } - - public interface WithStringValue - { - String stringValue(); - } - - public interface WithDoubleValue - { - double doubleValue(); - } - - public interface WithLongValue - { - long longValue(); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleArrayProperty.java deleted file mode 100644 index 6ff3ace74290a..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleArrayProperty.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -class DoubleArrayProperty extends FloatingPointArrayProperty -{ - private final double[] value; - - DoubleArrayProperty( int propertyKeyId, double[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public double[] value() - { - return value.clone(); - } - - @Override - public int length() - { - return value.length; - } - - @Override - public double doubleValue( int index ) - { - return value[index]; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleProperty.java deleted file mode 100644 index 09872de3b8dfe..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/DoubleProperty.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -final class DoubleProperty extends FloatingPointNumberProperty -{ - private final double value; - - DoubleProperty( int propertyKeyId, double value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - public double doubleValue() - { - return value; - } - - @Override - public Double value() - { - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatArrayProperty.java deleted file mode 100644 index df6885b9e2a6c..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatArrayProperty.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -class FloatArrayProperty extends FloatingPointArrayProperty -{ - private final float[] value; - - FloatArrayProperty( int propertyKeyId, float[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public int length() - { - return value.length; - } - - @Override - public double doubleValue( int index ) - { - return value[index]; - } - - @Override - public float[] value() - { - return value.clone(); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatProperty.java deleted file mode 100644 index 26c3fd59e8a73..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatProperty.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -final class FloatProperty extends FloatingPointNumberProperty -{ - private final float value; - - FloatProperty( int propertyKeyId, float value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - public double doubleValue() - { - return value; - } - - @Override - public Float value() - { - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointArrayProperty.java deleted file mode 100644 index a30a93fe16a1c..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointArrayProperty.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -abstract class FloatingPointArrayProperty extends DefinedProperty implements ArrayValue.FloatingPointArray -{ - FloatingPointArrayProperty( int propertyKeyId ) - { - super( propertyKeyId ); - } - - public abstract int length(); - - public abstract double doubleValue( int index ); - - @Override - public final int valueHash() - { - return hash( this ); - } - - static int hash( FloatingPointArray value ) - { - int result = 1; - for ( int i = 0, len = value.length(); i < len; i++ ) - { - long element = (long) value.doubleValue( i ); - int elementHash = (int) (element ^ (element >>> 32)); - result = 31 * result + elementHash; - } - return result; - } - - @Override - public final boolean valueEquals( Object other ) - { - return valueEquals( this, other ); - } - - static boolean valueEquals( FloatingPointArray value, Object other ) - { - if ( other instanceof double[] ) - { - return numbersEqual( value, new DoubleArray( (double[]) other ) ); - } - else if ( other instanceof float[] ) - { - return numbersEqual( value, new FloatArray( (float[]) other ) ); - } - else if ( other instanceof Number[] ) - { - Number[] that = (Number[]) other; - if ( that.length == value.length() ) - { - if ( other instanceof Double[] || other instanceof Float[] ) - { - return numbersEqual( value, NumberArray.asFloatingPoint( that ) ); - } - else - { - return numbersEqual( value, NumberArray.asIntegral( that ) ); - } - } - } - else if ( other instanceof long[] ) - { - return numbersEqual( value, new LongArray( (long[]) other ) ); - } - else if ( other instanceof int[] ) - { - return numbersEqual( value, new IntArray( (int[]) other ) ); - } - else if ( other instanceof short[] ) - { - return numbersEqual( value, new ShortArray( (short[]) other ) ); - } - else if ( other instanceof byte[] ) - { - return numbersEqual( value, new ByteArray( (byte[]) other ) ); - } - return false; - } - - @Override - final boolean hasEqualValue( DefinedProperty other ) - { - if ( other instanceof FloatingPointArrayProperty ) - { - FloatingPointArrayProperty that = (FloatingPointArrayProperty) other; - return numbersEqual( this, that ); - } - else if ( other instanceof IntegralArrayProperty ) - { - IntegralArrayProperty that = (IntegralArrayProperty) other; - return numbersEqual( this, that ); - } - return false; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointNumberProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointNumberProperty.java deleted file mode 100644 index f4cbaf584a88b..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/FloatingPointNumberProperty.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import org.neo4j.helpers.MathUtil; - -abstract class FloatingPointNumberProperty extends NumberProperty -{ - FloatingPointNumberProperty( int propertyKeyId ) - { - super( propertyKeyId ); - } - - @Override - public final int valueHash() - { - long value = (long) doubleValue(); - return (int) (value ^ (value >>> 32)); - } - - @Override - public final boolean valueEquals( Object other ) - { - if ( other instanceof Number ) - { - Number that = (Number) other; - if ( other instanceof Double || other instanceof Float ) - { - return this.doubleValue() == that.doubleValue(); - } - else - { - return MathUtil.numbersEqual( this.doubleValue(), that.longValue() ); - } - } - return false; - } - - @Override - final boolean hasEqualValue( DefinedProperty other ) - { - if ( other instanceof FloatingPointNumberProperty ) - { - FloatingPointNumberProperty that = (FloatingPointNumberProperty) other; - return this.doubleValue() == that.doubleValue(); - } - else if ( other instanceof IntegralNumberProperty ) - { - IntegralNumberProperty that = (IntegralNumberProperty) other; - return MathUtil.numbersEqual( this.doubleValue(), that.longValue() ); - } - else - { - return false; - } - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntArrayProperty.java deleted file mode 100644 index 117ac5c719e48..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntArrayProperty.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -class IntArrayProperty extends IntegralArrayProperty -{ - private final int[] value; - - IntArrayProperty( int propertyKeyId, int[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public int[] value() - { - return value.clone(); - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntProperty.java deleted file mode 100644 index 063b70abb899f..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntProperty.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -/** - * This does not extend AbstractProperty since the JVM can take advantage of the 4 byte initial field alignment if - * we don't extend a class that has fields. - */ -final class IntProperty extends IntegralNumberProperty -{ - private final int value; - - IntProperty( int propertyKeyId, int value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - public Integer value() - { - return value; - } - - @Override - public long longValue() - { - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralArrayProperty.java deleted file mode 100644 index 1555181cfe041..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralArrayProperty.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -abstract class IntegralArrayProperty extends DefinedProperty implements ArrayValue.IntegralArray -{ - IntegralArrayProperty( int propertyKeyId ) - { - super( propertyKeyId ); - } - - public abstract int length(); - - public abstract long longValue( int index ); - - @Override - public final int valueHash() - { - return hash( this ); - } - - static int hash( IntegralArray value ) - { - int result = 1; - for ( int i = 0, len = value.length(); i < len; i++ ) - { - long element = value.longValue( i ); - int elementHash = (int) (element ^ (element >>> 32)); - result = 31 * result + elementHash; - } - return result; - } - - @Override - public final boolean valueEquals( Object other ) - { - return valueEquals( this, other ); - } - - static boolean valueEquals( IntegralArray value, Object other ) - { - if ( other instanceof long[] ) - { - return numbersEqual( value, new LongArray( (long[]) other ) ); - } - else if ( other instanceof int[] ) - { - return numbersEqual( value, new IntArray( (int[]) other ) ); - } - else if ( other instanceof short[] ) - { - return numbersEqual( value, new ShortArray( (short[]) other ) ); - } - else if ( other instanceof byte[] ) - { - return numbersEqual( value, new ByteArray( (byte[]) other ) ); - } - else if ( other instanceof Number[] ) - { - Number[] that = (Number[]) other; - if ( that.length == value.length() ) - { - if ( other instanceof Double[] || other instanceof Float[] ) - { - return numbersEqual( NumberArray.asFloatingPoint( that ), value ); - } - else - { - return numbersEqual( value, NumberArray.asIntegral( that ) ); - } - } - } - else if ( other instanceof double[] ) - { - return numbersEqual( new DoubleArray( (double[]) other ), value ); - } - else if ( other instanceof float[] ) - { - return numbersEqual( new FloatArray( (float[]) other ), value ); - } - return false; - } - - @Override - final boolean hasEqualValue( DefinedProperty other ) - { - if ( other instanceof IntegralArrayProperty ) - { - IntegralArrayProperty that = (IntegralArrayProperty) other; - return numbersEqual( this, that ); - } - else if ( other instanceof FloatingPointArrayProperty ) - { - FloatingPointArrayProperty that = (FloatingPointArrayProperty) other; - return numbersEqual( that, this ); - } - return false; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralNumberProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralNumberProperty.java deleted file mode 100644 index 9edd8dc0088e5..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/IntegralNumberProperty.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; -import org.neo4j.helpers.MathUtil; - -abstract class IntegralNumberProperty extends NumberProperty implements DefinedProperty.WithLongValue -{ - IntegralNumberProperty( int propertyKeyId ) - { - super( propertyKeyId ); - } - - public double doubleValue() - { - return (double) longValue(); - } - - @Override - public final int valueHash() - { - long value = longValue(); - return (int) (value ^ (value >>> 32)); - } - - @Override - public final boolean valueEquals( Object other ) - { - if ( other instanceof Number ) - { - Number that = (Number) other; - if ( other instanceof Double || other instanceof Float ) - { - return MathUtil.numbersEqual( that.doubleValue(), this.longValue() ); - } - else - { - return this.longValue() == that.longValue(); - } - } - return false; - } - - @Override - final boolean hasEqualValue( DefinedProperty other ) - { - if ( other instanceof IntegralNumberProperty ) - { - IntegralNumberProperty that = (IntegralNumberProperty) other; - return this.longValue() == that.longValue(); - } - else if ( other instanceof FloatingPointNumberProperty ) - { - FloatingPointNumberProperty that = (FloatingPointNumberProperty) other; - return MathUtil.numbersEqual( that.doubleValue(), this.longValue() ); - } - else - { - return false; - } - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyArrayProperty.java deleted file mode 100644 index 2913dc75d7725..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyArrayProperty.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.concurrent.Callable; - -class LazyArrayProperty extends LazyProperty -{ - /* - * Access to this field needs synchronization, since it must be safe for use from multiple threads. - * The synchronization of this field is carefully designed to be implicit. - * - * - * assuming: produceValue() is called under synchronization - this is where this field is written. - * produceValue() is called *before* assigning the volatile LazyProperty.value field - * (still under synchronization) - * assuming: value member field is volatile, so accessing it implies the required read barrier. - * type doesn't need to be volatile since any call path to it first reads value, - * it's ALWAYS written before value, implying write barrier, and read after value, implying read barrier. - */ - private Type type; - - LazyArrayProperty( int propertyKeyId, final Callable producer ) - { - super( propertyKeyId, producer ); - } - - @Override - protected Object produceValue() - { - // this method is called under synchronization, before assigning LazyProperty.value ... - Object value = super.produceValue(); - this.type = Type.from( value ); // ... so assigning type is safe - return value; - } - - @Override - public boolean valueEquals( Object value ) - { - Object myValue = value(); // value() accesses LazyProperty.value, implying a read barrier ... - return type.equals( myValue, value ); // ... so accessing type is safe - } - - @Override - public int valueHash() - { - Object myValue = value(); // value() accesses LazyProperty.value, implying a read barrier ... - return type.hashCode( myValue ); // ... so accessing type is safe - } - - @Override - protected Object castAndPrepareForReturn( Object value ) - { - // this method is invoked after accessing LazyProperty.value, implying a read barrier ... - return type.clone( value ); // ... so accessing type is safe - } - - private enum Type - { - INT - { - @Override - int hashCode( Object array ) - { - return IntegralArrayProperty.hash( new ArrayValue.IntArray( (int[]) array ) ); - } - - @Override - boolean equals( Object value, Object other ) - { - return IntegralArrayProperty.valueEquals( new ArrayValue.IntArray( (int[]) value ), other ); - } - - @Override - Object clone( Object array ) - { - return ((int[]) array).clone(); - } - }, - LONG - { - @Override - int hashCode( Object array ) - { - return IntegralArrayProperty.hash( new ArrayValue.LongArray( (long[]) array ) ); - } - - @Override - boolean equals( Object value, Object other ) - { - return IntegralArrayProperty.valueEquals( new ArrayValue.LongArray( (long[]) value ), other ); - } - - @Override - Object clone( Object array ) - { - return ((long[]) array).clone(); - } - }, - BOOLEAN - { - @Override - int hashCode( Object array ) - { - return BooleanArrayProperty.hash( (boolean[]) array ); - } - - @Override - boolean equals( Object value, Object other ) - { - return BooleanArrayProperty.valueEquals( (boolean[]) value, other ); - } - - @Override - Object clone( Object array ) - { - return ((boolean[]) array).clone(); - } - }, - BYTE - { - @Override - int hashCode( Object array ) - { - return IntegralArrayProperty.hash( new ArrayValue.ByteArray( (byte[]) array ) ); - } - - @Override - boolean equals( Object value, Object other ) - { - return IntegralArrayProperty.valueEquals( new ArrayValue.ByteArray( (byte[]) value ), other ); - } - - @Override - Object clone( Object array ) - { - return ((byte[]) array).clone(); - } - }, - DOUBLE - { - @Override - int hashCode( Object array ) - { - return FloatingPointArrayProperty.hash( new ArrayValue.DoubleArray( (double[]) array ) ); - } - - @Override - boolean equals( Object value, Object other ) - { - return FloatingPointArrayProperty.valueEquals( new ArrayValue.DoubleArray( (double[]) value ), other ); - } - - @Override - Object clone( Object array ) - { - return ((double[]) array).clone(); - } - }, - STRING - { - @Override - int hashCode( Object array ) - { - return StringArrayProperty.hash( (String[]) array ); - } - - @Override - boolean equals( Object value, Object other ) - { - return StringArrayProperty.valueEquals( (String[]) value, other ); - } - - @Override - Object clone( Object array ) - { - return ((String[]) array).clone(); - } - }, - SHORT - { - @Override - int hashCode( Object array ) - { - return IntegralArrayProperty.hash( new ArrayValue.ShortArray( (short[]) array ) ); - } - - @Override - boolean equals( Object value, Object other ) - { - return IntegralArrayProperty.valueEquals( new ArrayValue.ShortArray( (short[]) value ), other ); - } - - @Override - Object clone( Object array ) - { - return ((short[]) array).clone(); - } - }, - CHAR - { - @Override - int hashCode( Object array ) - { - return CharArrayProperty.hash( (char[]) array ); - } - - @Override - boolean equals( Object value, Object other ) - { - return CharArrayProperty.valueEquals( (char[]) value, other ); - } - - @Override - Object clone( Object array ) - { - return ((char[]) array).clone(); - } - }, - FLOAT - { - @Override - int hashCode( Object array ) - { - return FloatingPointArrayProperty.hash( new ArrayValue.FloatArray( (float[]) array ) ); - } - - @Override - boolean equals( Object value, Object other ) - { - return FloatingPointArrayProperty.valueEquals( new ArrayValue.FloatArray( (float[]) value ), other ); - } - - @Override - Object clone( Object array ) - { - return ((float[]) array).clone(); - } - }; - - abstract int hashCode( Object array ); - - abstract boolean equals( Object value, Object other ); - - abstract Object clone( Object array ); - - public static Type from( Object array ) - { - if ( !array.getClass().isArray() ) - { - throw new IllegalArgumentException( array + " is not an array, it's a " + array.getClass() ); - } - - if ( array instanceof int[] ) - { - return INT; - } - if ( array instanceof long[] ) - { - return LONG; - } - if ( array instanceof boolean[] ) - { - return BOOLEAN; - } - if ( array instanceof byte[] ) - { - return BYTE; - } - if ( array instanceof double[] ) - { - return DOUBLE; - } - if ( array instanceof String[] ) - { - return STRING; - } - if ( array instanceof short[] ) - { - return SHORT; - } - if ( array instanceof char[] ) - { - return CHAR; - } - if ( array instanceof float[] ) - { - return FLOAT; - } - throw new IllegalArgumentException( "Unrecognized array type " + array.getClass().getComponentType() ); - } - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyProperty.java deleted file mode 100644 index 316fd609e169f..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyProperty.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.concurrent.Callable; - -abstract class LazyProperty extends DefinedProperty -{ - private volatile Object value; - - LazyProperty( int propertyKeyId, Callable producer ) - { - super( propertyKeyId ); - this.value = producer; - } - - @Override - final boolean hasEqualValue( DefinedProperty that ) - { - return valueEquals( that.value() ); - } - - @Override - public abstract boolean valueEquals( Object value ); - - @Override - public final T value() - { - Object value = this.value; - if ( value instanceof Callable ) - { - synchronized ( this ) - { - value = this.value; - if ( value instanceof Callable ) - { - this.value = value = produceValue(); - } - } - } - return castAndPrepareForReturn( value ); - } - - protected Object produceValue() - { - try - { - return ((Callable) value).call(); - } - catch ( Exception e ) - { - throw new RuntimeException( e ); - } - } - - /** - * Casts the internal value to the correct type and makes it ready for returning out, - * potentially all the way out to the user. - * - * @param value the value to cast and prepare. - * @return the cast and prepared value. - */ - @SuppressWarnings( "unchecked" ) - protected T castAndPrepareForReturn( Object value ) - { - return (T) value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyStringProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyStringProperty.java deleted file mode 100644 index ab7a97c025c75..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LazyStringProperty.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.concurrent.Callable; - -class LazyStringProperty extends LazyProperty implements DefinedProperty.WithStringValue -{ - LazyStringProperty( int propertyKeyId, Callable producer ) - { - super( propertyKeyId, producer ); - } - - @Override - public boolean valueEquals( Object value ) - { - return StringProperty.valueEquals( value(), value ); - } - - @Override - public int valueHash() - { - return value().hashCode(); - } - - @Override - public String stringValue() - { - return value(); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongArrayProperty.java deleted file mode 100644 index 0ec65152a5288..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongArrayProperty.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -class LongArrayProperty extends IntegralArrayProperty -{ - private final long[] value; - - LongArrayProperty( int propertyKeyId, long[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public long[] value() - { - return value.clone(); - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongProperty.java deleted file mode 100644 index 84d89fd0d196f..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/LongProperty.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -final class LongProperty extends IntegralNumberProperty -{ - private final long value; - - LongProperty( int propertyKeyId, long value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - public Long value() - { - return value; - } - - @Override - public long longValue() - { - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/NoProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/NoProperty.java deleted file mode 100644 index 11bad61166483..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/NoProperty.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import org.neo4j.kernel.api.exceptions.PropertyNotFoundException; -import org.neo4j.storageengine.api.EntityType; - -final class NoProperty extends Property -{ - private final EntityType entityType; - private final long entityId; - - NoProperty( int propertyKeyId, EntityType entityType, long entityId ) - { - super( propertyKeyId ); - this.entityType = entityType; - this.entityId = entityId; - } - - @Override - public String toString() - { - StringBuilder string = new StringBuilder( getClass().getSimpleName() ); - string.append( "[" ).append( entityType.name().toLowerCase() ); - if ( entityType == EntityType.GRAPH ) - { - string.append( "Property" ); - } - else - { - string.append( "Id=" ).append( entityId ); - } - string.append( ", propertyKeyId=" ).append( propertyKeyId ); - return string.append( "]" ).toString(); - } - - @Override - public boolean equals( Object o ) - { - return this == o || o instanceof NoProperty && propertyKeyId == ((NoProperty) o).propertyKeyId; - } - - @Override - public boolean isDefined() - { - return false; - } - - @Override - public int hashCode() - { - return propertyKeyId; - } - - @Override - public boolean valueEquals( Object value ) - { - return false; - } - - @Override - public Object value( Object defaultValue ) - { - return defaultValue; - } - - @Override - public String valueAsString() throws PropertyNotFoundException - { - throw new PropertyNotFoundException( propertyKeyId, entityType, entityId ); - } - - @Override - public Object value() throws PropertyNotFoundException - { - throw new PropertyNotFoundException( propertyKeyId, entityType, entityId ); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/NumberProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/NumberProperty.java deleted file mode 100644 index 6e8f0775c6641..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/NumberProperty.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -public abstract class NumberProperty extends DefinedProperty implements DefinedProperty.WithDoubleValue -{ - public NumberProperty( int propertyKeyId ) - { - super( propertyKeyId ); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/Property.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/Property.java deleted file mode 100644 index 1ade057a75ba3..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/Property.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.concurrent.Callable; - -import org.neo4j.kernel.api.exceptions.PropertyNotFoundException; -import org.neo4j.storageengine.api.EntityType; -import org.neo4j.storageengine.api.StorageProperty; - -public abstract class Property implements StorageProperty -{ - public static Property noNodeProperty( long nodeId, int propertyKeyId ) - { - return noProperty( propertyKeyId, EntityType.NODE, nodeId ); - } - - public static Property noRelationshipProperty( long relationshipId, int propertyKeyId ) - { - return noProperty( propertyKeyId, EntityType.RELATIONSHIP, relationshipId ); - } - - public static Property noGraphProperty( int propertyKeyId ) - { - return noProperty( propertyKeyId, EntityType.GRAPH, -1 ); - } - - public static Property noProperty( int propertyKeyId, EntityType type, long entityId ) - { - return new NoProperty( propertyKeyId, type, entityId ); - } - - public static DefinedProperty property( int propertyKeyId, Object value ) - { - return PropertyConversion.convertProperty( propertyKeyId, value ); - } - - final int propertyKeyId; - - Property( int propertyKeyId ) - { - this.propertyKeyId = propertyKeyId; - } - - @Override - public final int propertyKeyId() - { - return propertyKeyId; - } - - @Override - public abstract boolean valueEquals( Object other ); - - @Override - public abstract Object value() throws PropertyNotFoundException; - - @Override - public abstract Object value( Object defaultValue ); - - @Override - public abstract String valueAsString() throws PropertyNotFoundException; - - @Override - public abstract boolean equals( Object obj ); - - @Override - public abstract int hashCode(); - - @Override - public abstract boolean isDefined(); - - // direct factory methods - - public static DefinedProperty stringProperty( int propertyKeyId, String value ) - { - return new StringProperty( propertyKeyId, value ); - } - - public static DefinedProperty lazyStringProperty( int propertyKeyId, Callable producer ) - { - return new LazyStringProperty( propertyKeyId, producer ); - } - - public static DefinedProperty lazyArrayProperty( int propertyKeyId, Callable producer ) - { - return new LazyArrayProperty( propertyKeyId, producer ); - } - - public static DefinedProperty numberProperty( int propertyKeyId, Number number ) - { - if ( number instanceof Long ) - { - return longProperty( propertyKeyId, number.longValue() ); - } - if ( number instanceof Integer ) - { - return intProperty( propertyKeyId, number.intValue() ); - } - if ( number instanceof Double ) - { - return doubleProperty( propertyKeyId, number.doubleValue() ); - } - if ( number instanceof Byte ) - { - return byteProperty( propertyKeyId, number.byteValue() ); - } - if ( number instanceof Float ) - { - return floatProperty( propertyKeyId, number.floatValue() ); - } - if ( number instanceof Short ) - { - return shortProperty( propertyKeyId, number.shortValue() ); - } - - throw new UnsupportedOperationException( "Unsupported type of Number " + number.toString() ); - } - - public static DefinedProperty longProperty( int propertyKeyId, long value ) - { - return new LongProperty( propertyKeyId, value ); - } - - public static DefinedProperty intProperty( int propertyKeyId, int value ) - { - return new IntProperty( propertyKeyId, value ); - } - - public static DefinedProperty shortProperty( int propertyKeyId, short value ) - { - return new ShortProperty( propertyKeyId, value ); - } - - public static DefinedProperty byteProperty( int propertyKeyId, byte value ) - { - return new ByteProperty( propertyKeyId, value ); - } - - public static DefinedProperty booleanProperty( int propertyKeyId, boolean value ) - { - return new BooleanProperty( propertyKeyId, value ); - } - - public static DefinedProperty charProperty( int propertyKeyId, char value ) - { - return new CharProperty( propertyKeyId, value ); - } - - public static DefinedProperty doubleProperty( int propertyKeyId, double value ) - { - return new DoubleProperty( propertyKeyId, value ); - } - - public static DefinedProperty floatProperty( int propertyKeyId, float value ) - { - return new FloatProperty( propertyKeyId, value ); - } - - public static DefinedProperty stringArrayProperty( int propertyKeyId, String[] value ) - { - return new StringArrayProperty( propertyKeyId, value ); - } - - public static DefinedProperty byteArrayProperty( int propertyKeyId, byte[] value ) - { - return new ByteArrayProperty( propertyKeyId, value ); - } - - public static DefinedProperty longArrayProperty( int propertyKeyId, long[] value ) - { - return new LongArrayProperty( propertyKeyId, value ); - } - - public static DefinedProperty intArrayProperty( int propertyKeyId, int[] value ) - { - return new IntArrayProperty( propertyKeyId, value ); - } - - public static DefinedProperty doubleArrayProperty( int propertyKeyId, double[] value ) - { - return new DoubleArrayProperty( propertyKeyId, value ); - } - - public static DefinedProperty floatArrayProperty( int propertyKeyId, float[] value ) - { - return new FloatArrayProperty( propertyKeyId, value ); - } - - public static DefinedProperty booleanArrayProperty( int propertyKeyId, boolean[] value ) - { - return new BooleanArrayProperty( propertyKeyId,value ); - } - - public static DefinedProperty charArrayProperty( int propertyKeyId, char[] value ) - { - return new CharArrayProperty( propertyKeyId, value ); - } - - public static DefinedProperty shortArrayProperty( int propertyKeyId, short[] value ) - { - return new ShortArrayProperty( propertyKeyId, value ); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyConversion.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyConversion.java deleted file mode 100644 index ff48b772906cf..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyConversion.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.lang.reflect.Array; - -class PropertyConversion -{ - private PropertyConversion() - { - } - - static DefinedProperty convertProperty( int propertyKeyId, Object value ) - { - if ( value instanceof String ) - { - return Property.stringProperty( propertyKeyId, (String) value ); - } - if ( value instanceof Object[] ) - { - return arrayProperty( propertyKeyId, (Object[]) value ); - } - if ( value instanceof Long ) - { - return Property.longProperty( propertyKeyId, (Long) value ); - } - if ( value instanceof Integer ) - { - return Property.intProperty( propertyKeyId, (Integer) value ); - } - if ( value instanceof Boolean ) - { - return Property.booleanProperty( propertyKeyId, (Boolean) value ); - } - if ( value instanceof Double ) - { - return Property.doubleProperty( propertyKeyId, (Double) value ); - } - if ( value instanceof Float ) - { - return Property.floatProperty( propertyKeyId, (Float) value ); - } - if ( value instanceof Short ) - { - return Property.shortProperty( propertyKeyId, (Short) value ); - } - if ( value instanceof Byte ) - { - return Property.byteProperty( propertyKeyId, (Byte) value ); - } - if ( value instanceof Character ) - { - return Property.charProperty( propertyKeyId, (Character) value ); - } - if ( value instanceof byte[] ) - { - return Property.byteArrayProperty( propertyKeyId, ((byte[]) value).clone() ); - } - if ( value instanceof long[] ) - { - return Property.longArrayProperty( propertyKeyId, ((long[]) value).clone() ); - } - if ( value instanceof int[] ) - { - return Property.intArrayProperty( propertyKeyId, ((int[]) value).clone() ); - } - if ( value instanceof double[] ) - { - return Property.doubleArrayProperty( propertyKeyId, ((double[]) value).clone() ); - } - if ( value instanceof float[] ) - { - return Property.floatArrayProperty( propertyKeyId, ((float[]) value).clone() ); - } - if ( value instanceof boolean[] ) - { - return Property.booleanArrayProperty( propertyKeyId, ((boolean[]) value).clone() ); - } - if ( value instanceof char[] ) - { - return Property.charArrayProperty( propertyKeyId, ((char[]) value).clone() ); - } - if ( value instanceof short[] ) - { - return Property.shortArrayProperty( propertyKeyId, ((short[]) value).clone() ); - } - // otherwise fail - if ( value == null ) - { - throw new IllegalArgumentException( "[null] is not a supported property value" ); - } - else - { - throw new IllegalArgumentException( - String.format( "[%s:%s] is not a supported property value", value, value.getClass().getName() ) ); - } - } - - private static DefinedProperty arrayProperty( int propertyKeyId, Object[] value ) - { - if ( value instanceof String[] ) - { - return Property.stringArrayProperty( propertyKeyId, copy( value, new String[value.length] ) ); - } - if ( value instanceof Byte[] ) - { - return Property.byteArrayProperty( propertyKeyId, copy( value, new byte[value.length] ) ); - } - if ( value instanceof Long[] ) - { - return Property.longArrayProperty( propertyKeyId, copy( value, new long[value.length] ) ); - } - if ( value instanceof Integer[] ) - { - return Property.intArrayProperty( propertyKeyId, copy( value, new int[value.length] ) ); - } - if ( value instanceof Double[] ) - { - return Property.doubleArrayProperty( propertyKeyId, copy( value, new double[value.length] ) ); - } - if ( value instanceof Float[] ) - { - return Property.floatArrayProperty( propertyKeyId, copy( value, new float[value.length] ) ); - } - if ( value instanceof Boolean[] ) - { - return Property.booleanArrayProperty( propertyKeyId, copy( value, new boolean[value.length] ) ); - } - if ( value instanceof Character[] ) - { - return Property.charArrayProperty( propertyKeyId, copy( value, new char[value.length] ) ); - } - if ( value instanceof Short[] ) - { - return Property.shortArrayProperty( propertyKeyId, copy( value, new short[value.length] ) ); - } - throw new IllegalArgumentException( - String.format( "%s[] is not a supported property value type", - value.getClass().getComponentType().getName() ) ); - } - - private static T copy( Object[] value, T target ) - { - for ( int i = 0; i < value.length; i++ ) - { - if ( value[i] == null ) - { - throw new IllegalArgumentException( "Property array value elements may not be null." ); - } - Array.set( target, i, value[i] ); - } - return target; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyKeyValue.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyKeyValue.java new file mode 100644 index 0000000000000..3eb4f240ca945 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/PropertyKeyValue.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2002-2017 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.api.properties; + +import org.neo4j.kernel.api.exceptions.PropertyNotFoundException; +import org.neo4j.storageengine.api.StorageProperty; +import org.neo4j.values.Value; +import org.neo4j.values.Values; + +public class PropertyKeyValue implements StorageProperty +{ + private final int propertyKeyId; + private final Value value; + + public PropertyKeyValue( int propertyKeyId, Value value ) + { + assert value != null; + this.propertyKeyId = propertyKeyId; + this.value = value; + } + + @Override + public int propertyKeyId() + { + return propertyKeyId; + } + + @Override + public boolean valueEquals( Value other ) + { + return value.equals( other ); + } + + @Override + public Value value() throws PropertyNotFoundException + { + if ( value == Values.NO_VALUE ) + { + // TODO + throw new PropertyNotFoundException( propertyKeyId, null, -1 ); + } + return value; + } + + @Override + public Value valueForced() + { + return value; + } + + @Override + public boolean isDefined() + { + return value != Values.NO_VALUE; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + PropertyKeyValue that = (PropertyKeyValue) o; + + return propertyKeyId == that.propertyKeyId && value.equals( that.value ); + } + + @Override + public int hashCode() + { + int result = propertyKeyId; + result = 31 * result + value.hashCode(); + return result; + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortArrayProperty.java deleted file mode 100644 index 6439320f36e56..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortArrayProperty.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -class ShortArrayProperty extends IntegralArrayProperty -{ - private final short[] value; - - ShortArrayProperty( int propertyKeyId, short[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public short[] value() - { - return value.clone(); - } - - @Override - public int length() - { - return value.length; - } - - @Override - public long longValue( int index ) - { - return value[index]; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortProperty.java deleted file mode 100644 index b9cc53c64cbdf..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/ShortProperty.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -/** - * This does not extend AbstractProperty since the JVM can take advantage of the 4 byte initial field alignment if - * we don't extend a class that has fields. - */ -final class ShortProperty extends IntegralNumberProperty -{ - private final short value; - - ShortProperty( int propertyKeyId, short value ) - { - super( propertyKeyId ); - this.value = value; - } - - @Override - public Short value() - { - return value; - } - - @Override - public long longValue() - { - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringArrayProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringArrayProperty.java deleted file mode 100644 index c9213f5ce6e4d..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringArrayProperty.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import java.util.Arrays; - -class StringArrayProperty extends DefinedProperty -{ - final String[] value; - - StringArrayProperty( int propertyKeyId, String[] value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public String[] value() - { - return value.clone(); - } - - @Override - public boolean valueEquals( Object other ) - { - String[] value = this.value; - return valueEquals( value, other ); - } - - static boolean valueEquals( String[] value, Object other ) - { - if ( other instanceof String[] ) - { - return Arrays.equals( value, (String[]) other ); - } - if ( other instanceof char[] ) - { - return CharArrayProperty.eq( value, (char[]) other ); - } - else if ( other instanceof Character[] ) - { - Character[] that = (Character[]) other; - if ( value.length == that.length ) - { - for ( int i = 0; i < that.length; i++ ) - { - String str = value[i]; - Character character = that[i]; - if ( character == null || str.length() != 1 || str.charAt( 0 ) != character ) - { - return false; - } - } - return true; - } - return false; - } - return false; - } - - @Override - public int valueHash() - { - return hash( value ); - } - - static int hash( String[] value ) - { - return Arrays.hashCode( value ); - } - - @Override - boolean hasEqualValue( DefinedProperty other ) - { - if ( other instanceof StringArrayProperty ) - { - StringArrayProperty that = (StringArrayProperty) other; - return Arrays.equals( this.value, that.value ); - } - if ( other instanceof CharArrayProperty ) - { - CharArrayProperty that = (CharArrayProperty) other; - return CharArrayProperty.eq( this.value, that.value ); - } - return false; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringProperty.java b/community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringProperty.java deleted file mode 100644 index 462c0117d5389..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/properties/StringProperty.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -final class StringProperty extends DefinedProperty implements DefinedProperty.WithStringValue -{ - private final String value; - - StringProperty( int propertyKeyId, String value ) - { - super( propertyKeyId ); - assert value != null; - this.value = value; - } - - @Override - public boolean valueEquals( Object other ) - { - return valueEquals( value, other ); - } - - static boolean valueEquals( String value, Object other ) - { - if ( other instanceof String ) - { - return value.equals( other ); - } - if ( other instanceof Character ) - { - Character that = (Character) other; - return value.length() == 1 && value.charAt( 0 ) == that; - } - return false; - } - - @Override - public String value() - { - return value; - } - - @Override - public int valueHash() - { - return value.hashCode(); - } - - @Override - boolean hasEqualValue( DefinedProperty other ) - { - if ( other instanceof StringProperty ) - { - StringProperty that = (StringProperty) other; - return value.equals( that.value ); - } - if ( other instanceof CharProperty ) - { - CharProperty that = (CharProperty) other; - return value.length() == 1 && that.value == value.charAt( 0 ); - } - return false; - } - - @Override - public String stringValue() - { - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/schema/IndexQuery.java b/community/kernel/src/main/java/org/neo4j/kernel/api/schema/IndexQuery.java index 2382d73bcaf46..1f62b604d0fb8 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/schema/IndexQuery.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/schema/IndexQuery.java @@ -28,8 +28,10 @@ import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.schema.index.IndexDescriptor; -import org.neo4j.kernel.impl.api.PropertyValueComparison; +import org.neo4j.values.TextValue; import org.neo4j.values.Value; +import org.neo4j.values.ValueGroup; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; public abstract class IndexQuery implements Predicate @@ -132,6 +134,16 @@ public static StringSuffixPredicate stringSuffix( int propertyKeyId, String suff return new StringSuffixPredicate( propertyKeyId, suffix ); } + public static ValueTuple asValueTuple( IndexQuery.ExactPredicate... query ) + { + Value[] values = new Value[query.length]; + for ( int i = 0; i < query.length; i++ ) + { + values[i] = query[i].value(); + } + return ValueTuple.of( values ); + } + private final int propertyKeyId; protected IndexQuery( int propertyKeyId ) @@ -197,7 +209,7 @@ public IndexQueryType type() @Override public boolean test( Value value ) { - return value != null; + return value != null && value != Values.NO_VALUE; } } @@ -223,9 +235,9 @@ public boolean test( Value value ) return exactValue.equals( value ); } - public Object value() + public Value value() { - return exactValue.asPublic(); + return exactValue; } } @@ -394,7 +406,8 @@ public IndexQueryType type() @Override public boolean test( Value value ) { - return value != null && Values.isTextValue( value ) && ((String)value.asPublic()).startsWith( prefix ); + return value != null && Values.isTextValue( value ) && + ((TextValue)value).stringValue().startsWith( prefix ); } public String prefix() diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/schema/OrderedPropertyValues.java b/community/kernel/src/main/java/org/neo4j/kernel/api/schema/OrderedPropertyValues.java deleted file mode 100644 index a776de9bb540a..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/schema/OrderedPropertyValues.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.schema; - -import java.util.Arrays; -import java.util.Comparator; - -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; - -import static java.lang.String.format; -import static java.lang.String.valueOf; -import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY; -import static org.neo4j.kernel.impl.api.PropertyValueComparison.COMPARE_VALUES; - -/** - * Holder for n property values, ordered according to a schema descriptor property id order - * - * This implementation uses the Property class hierarchy to achieve correct equality between property values of - * different types. However, the propertyKeyId is really not needed and we could consider reimplementing the class if - * we make static methods for comparing property values. - */ -public class OrderedPropertyValues -{ - // FACTORY METHODS - - public static OrderedPropertyValues ofUndefined( Object... values ) - { - return new OrderedPropertyValues( - Arrays.stream( values ) - .map( value -> Property.property( NO_SUCH_PROPERTY_KEY, value ) ) - .toArray( DefinedProperty[]::new ) - ); - } - - public static OrderedPropertyValues of( DefinedProperty[] values ) - { - return new OrderedPropertyValues( values ); - } - - public static OrderedPropertyValues of( IndexQuery.ExactPredicate[] exactPreds ) - { - DefinedProperty[] values = new DefinedProperty[exactPreds.length]; - for ( int i = 0; i < exactPreds.length; i++ ) - { - values[i] = Property.property( exactPreds[i].propertyKeyId(), exactPreds[i].value() ); - } - return new OrderedPropertyValues( values ); - } - - // ACTUAL CLASS - - private final DefinedProperty[] properties; - - private OrderedPropertyValues( DefinedProperty[] properties ) - { - this.properties = properties; - } - - public Object valueAt( int position ) - { - return properties[position].value(); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - OrderedPropertyValues that = (OrderedPropertyValues) o; - - if ( that.properties.length != properties.length ) - { - return false; - } - - for ( int i = 0; i < properties.length; i++ ) - { - if ( !properties[i].valueEquals( that.properties[i].value() ) ) - { - return false; - } - } - return true; - } - - @Override - public int hashCode() - { - int result = 0; - for ( DefinedProperty property : properties ) - { - result = 31 * ( result + property.valueHash() ); - } - return result; - } - - public int size() - { - return properties.length; - } - - public Object getSinglePropertyValue() - { - assert properties.length == 1 : "Assumed single property but had " + properties.length; - return properties[0].value(); - } - - @Override - public String toString() - { - StringBuilder sb = new StringBuilder(); - String sep = "( "; - for ( DefinedProperty property : properties ) - { - sb.append( sep ); - sep = ", "; - sb.append( quote( property.value() ) ); - } - sb.append( " )" ); - return sb.toString(); - } - - // STATIC HELPERS - - public static String quote( Object propertyValue ) - { - if ( propertyValue instanceof String ) - { - return format( "'%s'", propertyValue ); - } - else if ( propertyValue.getClass().isArray() ) - { - Class type = propertyValue.getClass().getComponentType(); - if ( type == Boolean.TYPE ) - { - return Arrays.toString( (boolean[]) propertyValue ); - } - else if ( type == Byte.TYPE ) - { - return Arrays.toString( (byte[]) propertyValue ); - } - else if ( type == Short.TYPE ) - { - return Arrays.toString( (short[]) propertyValue ); - } - else if ( type == Character.TYPE ) - { - return Arrays.toString( (char[]) propertyValue ); - } - else if ( type == Integer.TYPE ) - { - return Arrays.toString( (int[]) propertyValue ); - } - else if ( type == Long.TYPE ) - { - return Arrays.toString( (long[]) propertyValue ); - } - else if ( type == Float.TYPE ) - { - return Arrays.toString( (float[]) propertyValue ); - } - else if ( type == Double.TYPE ) - { - return Arrays.toString( (double[]) propertyValue ); - } - return Arrays.toString( (Object[]) propertyValue ); - } - return valueOf( propertyValue ); - } - - public static final Comparator COMPARATOR = ( left, right ) -> - { - if ( left.properties.length != right.properties.length ) - { - throw new IllegalStateException( "Comparing two OrderedPropertyValues of different lengths!" ); - } - - int compare = 0; - for ( int i = 0; i < left.properties.length; i++ ) - { - compare = COMPARE_VALUES.compare( left.properties[i].value(), right.properties[i].value() ); - if ( compare != 0 ) - { - return compare; - } - } - return compare; - }; -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/txstate/TransactionState.java b/community/kernel/src/main/java/org/neo4j/kernel/api/txstate/TransactionState.java index 539f25adb02f6..f1633abfb6e39 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/txstate/TransactionState.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/txstate/TransactionState.java @@ -20,12 +20,12 @@ package org.neo4j.kernel.api.txstate; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema.constaints.IndexBackedConstraintDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; /** * Kernel transaction state, please see {@link org.neo4j.kernel.impl.api.state.TxState} for implementation details. @@ -91,5 +91,5 @@ public interface TransactionState extends ReadableTransactionState boolean constraintDoUnRemove( ConstraintDescriptor constraint ); - void indexDoUpdateEntry( LabelSchemaDescriptor descriptor, long nodeId, OrderedPropertyValues before, OrderedPropertyValues after ); + void indexDoUpdateEntry( LabelSchemaDescriptor descriptor, long nodeId, ValueTuple before, ValueTuple after ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java index 88741ce944e44..1124bffc66633 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java @@ -51,7 +51,6 @@ import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.api.schema.IndexQuery.ExactPredicate; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.RelationTypeSchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaDescriptor; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; @@ -210,7 +209,7 @@ private ExactPredicate[] getAllPropertyValues( KernelStatement state, SchemaDesc { if ( nodePropertyId != changedPropertyKeyId ) { - values[k] = IndexQuery.exact( nodePropertyId, Values.of( property.value() ) ); + values[k] = IndexQuery.exact( nodePropertyId, property.value() ); } nMatched++; } @@ -255,8 +254,7 @@ private void validateNoExistingNodeWithExactValues( if ( existing != NO_SUCH_NODE && existing != modifiedNode ) { throw new UniquePropertyValueValidationException( constraint, VALIDATION, - new IndexEntryConflictException( existing, NO_SUCH_NODE, - OrderedPropertyValues.of( propertyValues ) ) ); + new IndexEntryConflictException( existing, NO_SUCH_NODE, IndexQuery.asValueTuple( propertyValues ) ) ); } } catch ( IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e ) @@ -421,7 +419,7 @@ private void assertPredicatesMatchSchema( LabelSchemaDescriptor schema, ExactPre } @Override - public long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Object value ) + public long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Value value ) throws IndexNotFoundKernelException, IndexBrokenKernelException { return entityReadOperations.nodesCountIndexed( statement, index, nodeId, value ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/GuardingStatementOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/GuardingStatementOperations.java index 1776dafeb8b57..15c9415c6cf9a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/GuardingStatementOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/GuardingStatementOperations.java @@ -190,7 +190,7 @@ public long nodeGetFromUniqueIndexSeek( KernelStatement statement, IndexDescript } @Override - public long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Object value ) + public long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Value value ) throws IndexNotFoundKernelException, IndexBrokenKernelException { guard.check( statement ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LookupFilter.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LookupFilter.java index b6e495126c446..3a7a7f9cef365 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LookupFilter.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LookupFilter.java @@ -31,6 +31,7 @@ import org.neo4j.kernel.impl.api.operations.EntityOperations; import org.neo4j.storageengine.api.NodeItem; import org.neo4j.values.Value; +import org.neo4j.values.ValueGroup; import org.neo4j.values.Values; /** @@ -72,8 +73,8 @@ public static PrimitiveLongIterator exactIndexMatches( PropertyAccessor accessor for ( IndexQuery predicate : numericPredicates ) { int propertyKeyId = predicate.propertyKeyId(); - Object value = accessor.getProperty( nodeId, propertyKeyId ).value( null ); - if ( !predicate.test( Values.of( value ) ) ) + Value value = accessor.getPropertyValue( nodeId, propertyKeyId ); + if ( !predicate.test( value ) ) { return false; } @@ -155,8 +156,8 @@ else if ( predicate.type() == IndexQuery.IndexQueryType.rangeNumeric ) return false; } - private static boolean isNumberOrArray( Object value ) + private static boolean isNumberOrArray( Value value ) { - return value instanceof Number || value.getClass().isArray(); + return Values.isNumberValue( value ) || Values.isArrayValue( value ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java index 2619a0cb130cc..2aaf159700c46 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java @@ -513,7 +513,7 @@ public Set proceduresGetAll() } @Override - public long nodesCountIndexed( IndexDescriptor index, long nodeId, Object value ) + public long nodesCountIndexed( IndexDescriptor index, long nodeId, Value value ) throws IndexNotFoundKernelException, IndexBrokenKernelException { statement.assertOpen(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java index 14b52884124e6..93daa94667428 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java @@ -57,11 +57,9 @@ import org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException; import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.legacyindex.AutoIndexing; -import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.properties.PropertyKeyIdIterator; import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.RelationTypeSchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaUtil; @@ -106,6 +104,7 @@ import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.RelationshipState; import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; import static java.lang.String.format; @@ -293,7 +292,7 @@ public Value nodeGetProperty( KernelStatement statement, NodeItem node, int prop { if ( cursor.next() ) { - return Values.of( cursor.get().value() ); + return cursor.get().value(); } } catch ( NotFoundException e ) @@ -374,7 +373,7 @@ public Value relationshipGetProperty( KernelStatement statement, RelationshipIte { if ( cursor.next() ) { - return Values.of( cursor.get().value() ); + return cursor.get().value(); } } catch ( NotFoundException e ) @@ -832,7 +831,7 @@ public long nodeGetFromUniqueIndexSeek( PrimitiveLongResourceIterator committed = resourceIterator( reader.query( query ), reader ); PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches( this, state, committed, query ); PrimitiveLongIterator changesFiltered = - filterIndexStateChangesForSeek( state, exactMatches, index, OrderedPropertyValues.of( query ) ); + filterIndexStateChangesForSeek( state, exactMatches, index, IndexQuery.asValueTuple( query ) ); return single( resourceIterator( changesFiltered, committed ), NO_SUCH_NODE ); } @@ -850,7 +849,8 @@ public PrimitiveLongIterator indexQuery( KernelStatement state, IndexDescriptor { case exact: IndexQuery.ExactPredicate[] exactPreds = assertOnlyExactPredicates( predicates ); - return filterIndexStateChangesForSeek( state, exactMatches, index, OrderedPropertyValues.of( exactPreds ) ); + return filterIndexStateChangesForSeek( state, exactMatches, index, IndexQuery.asValueTuple( exactPreds ) ); + case stringSuffix: case stringContains: case exists: @@ -918,7 +918,7 @@ private void assertSinglePredicate( IndexQuery[] predicates ) } @Override - public long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Object value ) + public long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Value value ) throws IndexNotFoundKernelException, IndexBrokenKernelException { IndexReader reader = statement.getStoreStatement().getIndexReader( index ); @@ -942,7 +942,7 @@ private PrimitiveLongIterator filterIndexStateChangesForScan( private PrimitiveLongIterator filterIndexStateChangesForSeek( KernelStatement state, PrimitiveLongIterator nodeIds, IndexDescriptor index, - OrderedPropertyValues propertyValues ) + ValueTuple propertyValues ) { if ( state.hasTxStateWithChanges() ) { @@ -1030,7 +1030,7 @@ public Value nodeSetProperty( KernelStatement state, long nodeId, int propertyKe } else { - existingValue = Values.of( properties.get().value() ); + existingValue = properties.get().value(); autoIndexing.nodes().propertyChanged( ops, nodeId, propertyKeyId, existingValue, value ); } } @@ -1070,7 +1070,7 @@ public Value relationshipSetProperty( KernelStatement state, long relationshipId } else { - existingValue = Values.of( properties.get().value() ); + existingValue = properties.get().value(); autoIndexing.relationships().propertyChanged( ops, relationshipId, propertyKeyId, existingValue, value ); } @@ -1110,7 +1110,7 @@ public Value nodeRemoveProperty( KernelStatement state, long nodeId, int propert { if ( properties.next() ) { - existingValue = Values.of( properties.get().value() ); + existingValue = properties.get().value(); autoIndexing.nodes().propertyRemoved( ops, nodeId, propertyKeyId ); state.txState().nodeDoRemoveProperty( node.id(), propertyKeyId, existingValue ); @@ -1136,7 +1136,7 @@ public Value relationshipRemoveProperty( KernelStatement state, long relationshi { if ( properties.next() ) { - existingValue = Values.of( properties.get().value() ); + existingValue = properties.get().value(); autoIndexing.relationships().propertyRemoved( ops, relationshipId, propertyKeyId ); state.txState() @@ -1181,10 +1181,10 @@ public Value graphGetProperty( KernelStatement state, int propertyKeyId ) Iterator properties = graphGetAllProperties( state ); while ( properties.hasNext() ) { - DefinedProperty property = (DefinedProperty) properties.next(); + StorageProperty property = properties.next(); if ( property.propertyKeyId() == propertyKeyId ) { - return Values.of( property.value() ); + return property.valueForced(); } } return Values.NO_VALUE; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAbstractPropertyCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAbstractPropertyCursor.java index dfd8182845c92..9b37d02903143 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAbstractPropertyCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAbstractPropertyCursor.java @@ -22,9 +22,10 @@ import java.util.function.Consumer; import org.neo4j.cursor.Cursor; -import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.storageengine.api.PropertyItem; +import org.neo4j.storageengine.api.StorageProperty; import org.neo4j.storageengine.api.txstate.PropertyContainerState; +import org.neo4j.values.Value; /** * Overlays transaction state on a {@link PropertyItem} cursors. @@ -34,7 +35,7 @@ public abstract class TxAbstractPropertyCursor implements Cursor, private final Consumer instanceCache; protected Cursor cursor; - protected DefinedProperty property; + protected StorageProperty property; protected PropertyContainerState state; public TxAbstractPropertyCursor( Consumer instanceCache ) @@ -77,8 +78,8 @@ public int propertyKeyId() } @Override - public Object value() + public Value value() { - return property.value(); + return property.valueForced(); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAllPropertyCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAllPropertyCursor.java index 496ca8a98951e..ee55d93533266 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAllPropertyCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxAllPropertyCursor.java @@ -22,8 +22,7 @@ import java.util.Iterator; import java.util.function.Consumer; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.StorageProperty; @@ -51,13 +50,13 @@ public boolean next() StorageProperty changedProperty = state.getChangedProperty( propertyKeyId ); if ( changedProperty != null ) { - this.property = (DefinedProperty) changedProperty; + this.property = changedProperty; return true; } if ( !state.isPropertyRemoved( propertyKeyId ) ) { - this.property = Property.property( propertyKeyId, cursor.get().value() ); + this.property = new PropertyKeyValue( propertyKeyId, cursor.get().value() ); return true; } } @@ -67,7 +66,7 @@ public boolean next() if ( added != null && added.hasNext() ) { - property = (DefinedProperty) added.next(); + property = added.next(); return true; } else diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxSinglePropertyCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxSinglePropertyCursor.java index 00638f3479847..d747d755885b4 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxSinglePropertyCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/cursor/TxSinglePropertyCursor.java @@ -23,8 +23,7 @@ import org.neo4j.cursor.Cursor; import org.neo4j.kernel.api.StatementConstants; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.StorageProperty; import org.neo4j.storageengine.api.txstate.PropertyContainerState; @@ -65,14 +64,14 @@ public boolean next() StorageProperty changedProperty = state.getChangedProperty( propertyKeyId ); if ( changedProperty != null ) { - this.property = (DefinedProperty) changedProperty; + this.property = changedProperty; return true; } StorageProperty addedProperty = state.getAddedProperty( propertyKeyId ); if ( addedProperty != null ) { - this.property = (DefinedProperty) addedProperty; + this.property = addedProperty; return true; } @@ -109,7 +108,7 @@ public PropertyItem get() if ( seekFoundIt ) { - property = Property.property( cursor.get().propertyKeyId(), cursor.get().value() ); + property = new PropertyKeyValue( cursor.get().propertyKeyId(), cursor.get().value() ); } seekFoundIt = false; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexStoreView.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexStoreView.java index 9d95b8ae7c051..2097a7661b219 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexStoreView.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexStoreView.java @@ -28,9 +28,10 @@ import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.labelscan.NodeLabelUpdate; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.register.Register.DoubleLongRegister; import org.neo4j.storageengine.api.schema.PopulationProgress; +import org.neo4j.values.Value; +import org.neo4j.values.Values; /** The indexing services view of the universe. */ public interface IndexStoreView extends PropertyAccessor, PropertyLoader @@ -109,9 +110,9 @@ public void loadProperties( long nodeId, PrimitiveIntSet propertyIds, PropertyLo } @Override - public Property getProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException + public Value getPropertyValue( long nodeId, int propertyKeyId ) throws EntityNotFoundException { - return Property.noNodeProperty( nodeId, propertyKeyId ); + return Values.NO_VALUE; } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java index f4d67e9e6732a..2b896a7722cac 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/NodeUpdates.java @@ -31,9 +31,9 @@ import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.helpers.collection.Iterables; import org.neo4j.kernel.api.index.IndexEntryUpdate; -import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.LabelSchemaSupplier; +import org.neo4j.values.Value; import static java.lang.String.format; import static java.util.Arrays.binarySearch; @@ -65,35 +65,32 @@ private Builder( NodeUpdates updates ) this.updates = updates; } - public Builder added( int propertyKeyId, Object value ) + public Builder added( int propertyKeyId, Value value ) { updates.put( propertyKeyId, NodeUpdates.after( value ) ); return this; } - public Builder removed( int propertyKeyId, Object value ) + public Builder removed( int propertyKeyId, Value value ) { updates.put( propertyKeyId, NodeUpdates.before( value ) ); return this; } - public Builder changed( int propertyKeyId, Object before, Object after ) + public Builder changed( int propertyKeyId, Value before, Value after ) { updates.put( propertyKeyId, NodeUpdates.changed( before, after ) ); return this; } - public NodeUpdates build() + public Builder existing( int propertyKeyId, Value value ) { - return updates; + updates.put( propertyKeyId, NodeUpdates.unchanged( value ) ); + return this; } - public NodeUpdates buildWithExistingProperties( DefinedProperty... definedProperties ) + public NodeUpdates build() { - for ( DefinedProperty property : definedProperties ) - { - updates.put( property.propertyKeyId(), NodeUpdates.unchanged( property.value() ) ); - } return updates; } } @@ -149,7 +146,7 @@ PrimitiveIntCollection propertiesChanged() } @Override - public void onProperty( int propertyId, Object value ) + public void onProperty( int propertyId, Value value ) { knownProperties.put( propertyId, unchanged( value ) ); } @@ -330,9 +327,9 @@ private boolean hasPropsAfter( int[] propertyIds ) return true; } - private Object[] valuesBefore( int[] propertyIds ) + private Value[] valuesBefore( int[] propertyIds ) { - Object[] values = new Object[propertyIds.length]; + Value[] values = new Value[propertyIds.length]; for ( int i = 0; i < propertyIds.length; i++ ) { values[i] = knownProperties.get( propertyIds[i] ).before; @@ -340,9 +337,9 @@ private Object[] valuesBefore( int[] propertyIds ) return values; } - private Object[] valuesAfter( int[] propertyIds ) + private Value[] valuesAfter( int[] propertyIds ) { - Object[] values = new Object[propertyIds.length]; + Value[] values = new Value[propertyIds.length]; for ( int i = 0; i < propertyIds.length; i++ ) { PropertyValue propertyValue = knownProperties.get( propertyIds[i] ); @@ -452,11 +449,11 @@ enum PropertyValueType private static class PropertyValue { - private final Object before; - private final Object after; + private final Value before; + private final Value after; private final PropertyValueType type; - private PropertyValue( Object before, Object after, PropertyValueType type ) + private PropertyValue( Value before, Value after, PropertyValueType type ) { this.before = before; this.after = after; @@ -508,11 +505,11 @@ public boolean equals( Object o ) switch ( type ) { case NoValue: return true; - case Before: return propertyValueEqual( before, that.before ); - case After: return propertyValueEqual( after, that.after ); - case UnChanged: return propertyValueEqual( after, that.after ); - case Changed: return propertyValueEqual( before, that.before ) && - propertyValueEqual( after, that.after ); + case Before: return before.equals( that.before ); + case After: return after.equals( that.after ); + case UnChanged: return after.equals( that.after ); + case Changed: return before.equals( that.before ) && + after.equals( that.after ); default: throw new IllegalStateException( "This cannot happen!" ); } } @@ -527,74 +524,24 @@ public int hashCode() } } - private static boolean propertyValueEqual( Object a, Object b ) - { - if ( a == null ) - { - return b == null; - } - if ( b == null ) - { - return false; - } - - if ( a instanceof boolean[] && b instanceof boolean[] ) - { - return Arrays.equals( (boolean[]) a, (boolean[]) b ); - } - if ( a instanceof byte[] && b instanceof byte[] ) - { - return Arrays.equals( (byte[]) a, (byte[]) b ); - } - if ( a instanceof short[] && b instanceof short[] ) - { - return Arrays.equals( (short[]) a, (short[]) b ); - } - if ( a instanceof int[] && b instanceof int[] ) - { - return Arrays.equals( (int[]) a, (int[]) b ); - } - if ( a instanceof long[] && b instanceof long[] ) - { - return Arrays.equals( (long[]) a, (long[]) b ); - } - if ( a instanceof char[] && b instanceof char[] ) - { - return Arrays.equals( (char[]) a, (char[]) b ); - } - if ( a instanceof float[] && b instanceof float[] ) - { - return Arrays.equals( (float[]) a, (float[]) b ); - } - if ( a instanceof double[] && b instanceof double[] ) - { - return Arrays.equals( (double[]) a, (double[]) b ); - } - if ( a instanceof Object[] && b instanceof Object[] ) - { - return Arrays.equals( (Object[]) a, (Object[]) b ); - } - return a.equals( b ); - } - private static PropertyValue noValue = new PropertyValue( null, null, NoValue ); - private static PropertyValue before( Object value ) + private static PropertyValue before( Value value ) { return new PropertyValue( value, null, PropertyValueType.Before ); } - private static PropertyValue after( Object value ) + private static PropertyValue after( Value value ) { return new PropertyValue( null, value, PropertyValueType.After ); } - private static PropertyValue unchanged( Object value ) + private static PropertyValue unchanged( Value value ) { return new PropertyValue( value, value, PropertyValueType.UnChanged ); } - private static PropertyValue changed( Object before, Object after ) + private static PropertyValue changed( Value before, Value after ) { return new PropertyValue( before, after, PropertyValueType.Changed ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyLoader.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyLoader.java index 97f32425ee4e4..9953a2cbac482 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyLoader.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyLoader.java @@ -21,6 +21,7 @@ import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.kernel.api.index.PropertyAccessor; +import org.neo4j.values.Value; /** * The PropertyLoader provides a stream-lined interface for getting multiple property values from a node in a single @@ -41,6 +42,6 @@ public interface PropertyLoader interface PropertyLoadSink { - void onProperty( int propertyId, Object value ); + void onProperty( int propertyId, Value value ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java index d8d79a8bfc872..c364a2b77f5e0 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverter.java @@ -28,6 +28,8 @@ import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.transaction.state.PropertyRecordChange; +import org.neo4j.values.Value; +import org.neo4j.values.Values; public class PropertyPhysicalToLogicalConverter { @@ -58,8 +60,8 @@ public void convertPropertyRecord( long nodeId, Iterable c // CHANGE if ( !beforeBlock.hasSameContentsAs( afterBlock ) ) { - Object beforeVal = valueOf( beforeBlock ); - Object afterVal = valueOf( afterBlock ); + Value beforeVal = valueOf( beforeBlock ); + Value afterVal = valueOf( afterBlock ); properties.changed( key, beforeVal, afterVal ); } } @@ -115,13 +117,13 @@ private void mapBlocks( PropertyRecord record, Map block } } - private Object valueOf( PropertyBlock block ) + private Value valueOf( PropertyBlock block ) { if ( block == null ) { return null; } - return block.getType().getValue( block, propertyStore ); + return block.getType().getValueNow( block, propertyStore ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/EntityReadOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/EntityReadOperations.java index 81ce6f2db2fde..e5c40cf5d8280 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/EntityReadOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/EntityReadOperations.java @@ -68,7 +68,7 @@ PrimitiveLongIterator indexQuery( KernelStatement statement, IndexDescriptor ind long nodeGetFromUniqueIndexSeek( KernelStatement state, IndexDescriptor index, IndexQuery.ExactPredicate... predicates ) throws IndexNotFoundKernelException, IndexBrokenKernelException, IndexNotApplicableKernelException; - long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Object value ) + long nodesCountIndexed( KernelStatement statement, IndexDescriptor index, long nodeId, Value value ) throws IndexNotFoundKernelException, IndexBrokenKernelException; boolean graphHasProperty( KernelStatement state, int propertyKeyId ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdater.java index beb904a21dc50..1a85d33dff7b9 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdater.java @@ -27,9 +27,6 @@ import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.cursor.Cursor; import org.neo4j.kernel.api.exceptions.EntityNotFoundException; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.impl.api.KernelStatement; import org.neo4j.kernel.impl.api.operations.EntityReadOperations; @@ -39,6 +36,7 @@ import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.StoreReadLayer; import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY; @@ -81,7 +79,7 @@ public void onLabelChange( KernelStatement state, int labelId, NodeItem node, La int[] indexPropertyIds = index.schema().getPropertyIds(); if ( nodeHasIndexProperties( nodePropertyIds, indexPropertyIds ) ) { - OrderedPropertyValues values = getOrderedPropertyValues( state, node, indexPropertyIds ); + ValueTuple values = getValueTuple( state, node, indexPropertyIds ); if ( changeType == LabelChangeType.ADDED_LABEL ) { for ( int i = 0; i < values.size(); i++ ) @@ -115,8 +113,8 @@ public void onPropertyAdd( KernelStatement state, NodeItem node, int propertyKey ( index, propertyKeyIds ) -> { Validators.INDEX_VALUE_VALIDATOR.validate( value ); - OrderedPropertyValues values = - getOrderedPropertyValues( state, node, propertyKeyId, value, index.schema().getPropertyIds() ); + ValueTuple values = + getValueTuple( state, node, propertyKeyId, value, index.schema().getPropertyIds() ); state.txState().indexDoUpdateEntry( index.schema(), node.id(), null, values ); } ); } @@ -130,8 +128,8 @@ public void onPropertyRemove( KernelStatement state, NodeItem node, int property nodeIndexMatcher.onMatchingSchema( state, indexes, node, propertyKeyId, ( index, propertyKeyIds ) -> { - OrderedPropertyValues values = - getOrderedPropertyValues( state, node, propertyKeyId, value, index.schema().getPropertyIds() ); + ValueTuple values = + getValueTuple( state, node, propertyKeyId, value, index.schema().getPropertyIds() ); state.txState().indexDoUpdateEntry( index.schema(), node.id(), values, null ); }); } @@ -147,41 +145,40 @@ public void onPropertyChange( KernelStatement state, NodeItem node, int property Validators.INDEX_VALUE_VALIDATOR.validate( afterValue ); int[] indexPropertyIds = index.schema().getPropertyIds(); - Object[] valuesBefore = new Object[indexPropertyIds.length]; - Object[] valuesAfter = new Object[indexPropertyIds.length]; + Value[] valuesBefore = new Value[indexPropertyIds.length]; + Value[] valuesAfter = new Value[indexPropertyIds.length]; for ( int i = 0; i < indexPropertyIds.length; i++ ) { int indexPropertyId = indexPropertyIds[i]; if ( indexPropertyId == propertyKeyId ) { - valuesBefore[i] = beforeValue.asPublic(); - valuesAfter[i] = afterValue.asPublic(); + valuesBefore[i] = beforeValue; + valuesAfter[i] = afterValue; } else { - Object value = readOps.nodeGetProperty( state, node, indexPropertyId ).asPublic(); + Value value = readOps.nodeGetProperty( state, node, indexPropertyId ); valuesBefore[i] = value; valuesAfter[i] = value; } } state.txState().indexDoUpdateEntry( index.schema(), node.id(), - OrderedPropertyValues.ofUndefined( valuesBefore ), OrderedPropertyValues.ofUndefined( - valuesAfter ) ); + ValueTuple.of( valuesBefore ), ValueTuple.of( valuesAfter ) ); }); } // HELPERS - private OrderedPropertyValues getOrderedPropertyValues( KernelStatement state, NodeItem node, + private ValueTuple getValueTuple( KernelStatement state, NodeItem node, int[] indexPropertyIds ) { - return getOrderedPropertyValues( state, node, NO_SUCH_PROPERTY_KEY, Values.NO_VALUE, indexPropertyIds ); + return getValueTuple( state, node, NO_SUCH_PROPERTY_KEY, Values.NO_VALUE, indexPropertyIds ); } - private OrderedPropertyValues getOrderedPropertyValues( KernelStatement state, NodeItem node, + private ValueTuple getValueTuple( KernelStatement state, NodeItem node, int changedPropertyKeyId, Value changedValue, int[] indexPropertyIds ) { - DefinedProperty[] values = new DefinedProperty[indexPropertyIds.length]; + Value[] values = new Value[indexPropertyIds.length]; Cursor propertyCursor = readOps.nodeGetProperties( state, node ); while ( propertyCursor.next() ) { @@ -190,8 +187,7 @@ private OrderedPropertyValues getOrderedPropertyValues( KernelStatement state, N if ( k >= 0 ) { values[k] = indexPropertyIds[k] == changedPropertyKeyId - ? Property.property( property.propertyKeyId(), changedValue.asPublic() ) - : Property.property( property.propertyKeyId(), property.value() ); + ? changedValue : property.value(); } } @@ -200,11 +196,11 @@ private OrderedPropertyValues getOrderedPropertyValues( KernelStatement state, N int k = ArrayUtils.indexOf( indexPropertyIds, changedPropertyKeyId ); if ( k >= 0 ) { - values[k] = Property.property( changedPropertyKeyId, changedValue.asPublic() ); + values[k] = changedValue; } } - return OrderedPropertyValues.of( values ); + return ValueTuple.of( values ); } private static boolean nodeHasIndexProperties( PrimitiveIntSet nodeProperties, int[] indexPropertyIds ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImpl.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImpl.java index fdaa9b43e4ee0..a370c4d3d35d2 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImpl.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImpl.java @@ -25,8 +25,7 @@ import org.neo4j.helpers.collection.Iterators; import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.impl.util.VersionedHashMap; import org.neo4j.storageengine.api.StorageProperty; import org.neo4j.storageengine.api.txstate.PropertyContainerState; @@ -231,14 +230,14 @@ private Iterator toPropertyIterator( VersionedHashMap Property.property( entry.getKey(), entry.getValue().asPublic() ), + entry -> new PropertyKeyValue( entry.getKey(), entry.getValue() ), propertyMap.entrySet().iterator() ); } - private DefinedProperty getPropertyOrNull( VersionedHashMap propertyMap, int propertyKeyId ) + private PropertyKeyValue getPropertyOrNull( VersionedHashMap propertyMap, int propertyKeyId ) { Value value = propertyMap.get( propertyKeyId ); - return value == null ? null : Property.property( propertyKeyId, value.asPublic() ); + return value == null ? null : new PropertyKeyValue( propertyKeyId, value ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java index 98770ef106ff2..bb68fbb859433 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/TxState.java @@ -36,7 +36,6 @@ import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException; import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.SchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaDescriptorPredicates; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; @@ -67,7 +66,10 @@ import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.RelationshipState; import org.neo4j.storageengine.api.txstate.TxStateVisitor; +import org.neo4j.values.TextValue; import org.neo4j.values.Value; +import org.neo4j.values.ValueGroup; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; import static org.neo4j.collection.primitive.PrimitiveLongCollections.toPrimitiveIterator; @@ -160,7 +162,7 @@ void setMap( TxState state, Map map ) private Map createdConstraintIndexesByConstraint; - private Map>> indexUpdates; + private Map>> indexUpdates; private InstanceCache singleNodeCursor; private InstanceCache iteratorRelationshipCursor; @@ -996,7 +998,7 @@ public ReadableDiffSets indexUpdatesForScan( IndexDescriptor descriptor ) } @Override - public ReadableDiffSets indexUpdatesForSeek( IndexDescriptor descriptor, OrderedPropertyValues values ) + public ReadableDiffSets indexUpdatesForSeek( IndexDescriptor descriptor, ValueTuple values ) { assert values != null; return ReadableDiffSets.Empty.ifNull( getIndexUpdatesForSeek( descriptor.schema(), values, /*create=*/false ) ); @@ -1016,38 +1018,38 @@ private ReadableDiffSets getIndexUpdatesForRangeSeekByNumber( IndexDescrip Number lower, boolean includeLower, Number upper, boolean includeUpper ) { - TreeMap> sortedUpdates = getSortedIndexUpdates( descriptor.schema() ); + TreeMap> sortedUpdates = getSortedIndexUpdates( descriptor.schema() ); if ( sortedUpdates == null ) { return null; } - OrderedPropertyValues selectedLower; + ValueTuple selectedLower; boolean selectedIncludeLower; - OrderedPropertyValues selectedUpper; + ValueTuple selectedUpper; boolean selectedIncludeUpper; - //TODO: Get working with composite indexes + //TODO: Get working with composite indexes' if ( lower == null ) { - selectedLower = OrderedPropertyValues.ofUndefined( NUMBER.lowLimit.castValue( Number.class ) ); - selectedIncludeLower = NUMBER.lowLimit.isInclusive; + selectedLower = ValueTuple.of( Values.MIN_NUMBER ); + selectedIncludeLower = true; } else { - selectedLower = OrderedPropertyValues.ofUndefined( lower ); + selectedLower = ValueTuple.of( Values.numberValue( lower ) ); selectedIncludeLower = includeLower; } if ( upper == null ) { - selectedUpper = OrderedPropertyValues.ofUndefined( NUMBER.highLimit.castValue( Number.class ) ); - selectedIncludeUpper = NUMBER.highLimit.isInclusive; + selectedUpper = ValueTuple.of( Values.MAX_NUMBER ); + selectedIncludeUpper = true; } else { - selectedUpper = OrderedPropertyValues.ofUndefined( upper ); + selectedUpper = ValueTuple.of( Values.numberValue( upper ) ); selectedIncludeUpper = includeUpper; } @@ -1078,38 +1080,38 @@ private ReadableDiffSets getIndexUpdatesForRangeSeekByString( IndexDescrip String lower, boolean includeLower, String upper, boolean includeUpper ) { - TreeMap> sortedUpdates = getSortedIndexUpdates( descriptor.schema() ); + TreeMap> sortedUpdates = getSortedIndexUpdates( descriptor.schema() ); if ( sortedUpdates == null ) { return null; } - OrderedPropertyValues selectedLower; + ValueTuple selectedLower; boolean selectedIncludeLower; - OrderedPropertyValues selectedUpper; + ValueTuple selectedUpper; boolean selectedIncludeUpper; //TODO: Get working with composite indexes if ( lower == null ) { - selectedLower = OrderedPropertyValues.ofUndefined( STRING.lowLimit.castValue( String.class ) ); - selectedIncludeLower = STRING.lowLimit.isInclusive; + selectedLower = ValueTuple.of( Values.MIN_STRING ); + selectedIncludeLower = true; } else { - selectedLower = OrderedPropertyValues.ofUndefined( lower ); + selectedLower = ValueTuple.of( Values.stringValue( lower ) ); selectedIncludeLower = includeLower; } if ( upper == null ) { - selectedUpper = OrderedPropertyValues.ofUndefined( STRING.highLimit.castValue( Boolean.class ).booleanValue() ); - selectedIncludeUpper = STRING.highLimit.isInclusive; + selectedUpper = ValueTuple.of( Values.MAX_STRING ); + selectedIncludeUpper = false; } else { - selectedUpper = OrderedPropertyValues.ofUndefined( upper ); + selectedUpper = ValueTuple.of( Values.stringValue( upper ) ); selectedIncludeUpper = includeUpper; } @@ -1133,18 +1135,18 @@ public ReadableDiffSets indexUpdatesForRangeSeekByPrefix( IndexDescriptor private ReadableDiffSets getIndexUpdatesForRangeSeekByPrefix( IndexDescriptor descriptor, String prefix ) { - TreeMap> sortedUpdates = getSortedIndexUpdates( descriptor.schema() ); + TreeMap> sortedUpdates = getSortedIndexUpdates( descriptor.schema() ); if ( sortedUpdates == null ) { return null; } //TODO: get working with composite indexes - OrderedPropertyValues floor = OrderedPropertyValues.ofUndefined( prefix ); + ValueTuple floor = ValueTuple.of( Values.stringValue( prefix ) ); DiffSets diffs = new DiffSets<>(); - for ( Map.Entry> entry : sortedUpdates.tailMap( floor ).entrySet() ) + for ( Map.Entry> entry : sortedUpdates.tailMap( floor ).entrySet() ) { - OrderedPropertyValues key = entry.getKey(); - if ( key.getSinglePropertyValue().toString().startsWith( prefix ) ) + ValueTuple key = entry.getKey(); + if ( ((TextValue)key.getOnlyValue()).stringValue().startsWith( prefix ) ) { DiffSets diffSets = entry.getValue(); diffs.addAll( diffSets.getAdded().iterator() ); @@ -1161,25 +1163,25 @@ private ReadableDiffSets getIndexUpdatesForRangeSeekByPrefix( IndexDescrip // Ensure sorted index updates for a given index. This is needed for range query support and // may involve converting the existing hash map first // - private TreeMap> getSortedIndexUpdates( LabelSchemaDescriptor descriptor ) + private TreeMap> getSortedIndexUpdates( LabelSchemaDescriptor descriptor ) { if ( indexUpdates == null ) { return null; } - Map> updates = indexUpdates.get( descriptor ); + Map> updates = indexUpdates.get( descriptor ); if ( updates == null ) { return null; } - TreeMap> sortedUpdates; + TreeMap> sortedUpdates; if ( updates instanceof TreeMap ) { - sortedUpdates = (TreeMap>) updates; + sortedUpdates = (TreeMap>) updates; } else { - sortedUpdates = new TreeMap<>( OrderedPropertyValues.COMPARATOR ); + sortedUpdates = new TreeMap<>( ValueTuple.COMPARATOR ); sortedUpdates.putAll( updates ); indexUpdates.put( descriptor, sortedUpdates ); } @@ -1188,10 +1190,10 @@ private TreeMap> getSortedIndexUpdates( La @Override public void indexDoUpdateEntry( LabelSchemaDescriptor descriptor, long nodeId, - OrderedPropertyValues propertiesBefore, OrderedPropertyValues propertiesAfter ) + ValueTuple propertiesBefore, ValueTuple propertiesAfter ) { NodeStateImpl nodeState = getOrCreateNodeState( nodeId ); - Map> updates = getIndexUpdatesByDescriptor( descriptor, true); + Map> updates = getIndexUpdatesByDescriptor( descriptor, true); if ( propertiesBefore != null ) { DiffSets before = getIndexUpdatesForSeek( updates, propertiesBefore, true ); @@ -1223,9 +1225,9 @@ public void indexDoUpdateEntry( LabelSchemaDescriptor descriptor, long nodeId, } private DiffSets getIndexUpdatesForSeek( - LabelSchemaDescriptor schema, OrderedPropertyValues values, boolean create ) + LabelSchemaDescriptor schema, ValueTuple values, boolean create ) { - Map> updates = getIndexUpdatesByDescriptor( schema, create ); + Map> updates = getIndexUpdatesByDescriptor( schema, create ); if ( updates != null ) { return getIndexUpdatesForSeek( updates, values, create ); @@ -1233,8 +1235,8 @@ private DiffSets getIndexUpdatesForSeek( return null; } - private DiffSets getIndexUpdatesForSeek( Map> updates, - OrderedPropertyValues values, boolean create ) + private DiffSets getIndexUpdatesForSeek( Map> updates, + ValueTuple values, boolean create ) { DiffSets diffs = updates.get( values ); if ( diffs == null && create ) @@ -1244,7 +1246,7 @@ private DiffSets getIndexUpdatesForSeek( Map> getIndexUpdatesByDescriptor( LabelSchemaDescriptor schema, + private Map> getIndexUpdatesByDescriptor( LabelSchemaDescriptor schema, boolean create ) { if ( indexUpdates == null ) @@ -1255,7 +1257,7 @@ private Map> getIndexUpdatesByDescriptor( L } indexUpdates = new HashMap<>(); } - Map> updates = indexUpdates.get( schema ); + Map> updates = indexUpdates.get( schema ); if ( updates == null ) { if ( !create ) @@ -1273,7 +1275,7 @@ private DiffSets getIndexUpdatesForScan( LabelSchemaDescriptor schema ) { return null; } - Map> updates = indexUpdates.get( schema ); + Map> updates = indexUpdates.get( schema ); if ( updates == null ) { return null; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyCursor.java index 6bcfe098f6ad8..356c4de2a7006 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyCursor.java @@ -29,6 +29,7 @@ import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.storageengine.api.PropertyItem; +import org.neo4j.values.Value; import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE; @@ -100,9 +101,9 @@ public int propertyKeyId() } @Override - public Object value() + public Value value() { - Object value = payload.value(); + Value value = payload.value(); assertOpen.assertOpen(); return value; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursor.java index ac68711f1d927..edfd1c5fcff25 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursor.java @@ -31,6 +31,8 @@ import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.kernel.impl.util.Bits; import org.neo4j.string.UTF8; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.neo4j.kernel.impl.store.PropertyType.ARRAY; import static org.neo4j.kernel.impl.store.PropertyType.BOOL; @@ -215,34 +217,34 @@ Object arrayValue() return readArrayFromBuffer( buffer ); } - Object value() + Value value() { switch ( type() ) { case BOOL: - return booleanValue(); + return Values.booleanValue( booleanValue() ); case BYTE: - return byteValue(); + return Values.byteValue( byteValue() ); case SHORT: - return shortValue(); + return Values.shortValue( shortValue() ); case CHAR: - return charValue(); + return Values.charValue( charValue() ); case INT: - return intValue(); + return Values.intValue( intValue() ); case LONG: - return longValue(); + return Values.longValue( longValue() ); case FLOAT: - return floatValue(); + return Values.floatValue( floatValue() ); case DOUBLE: - return doubleValue(); + return Values.doubleValue( doubleValue() ); case SHORT_STRING: - return shortStringValue(); + return Values.stringValue( shortStringValue() ); case STRING: - return stringValue(); + return Values.stringValue( stringValue() ); case SHORT_ARRAY: - return shortArrayValue(); + return Values.of( shortArrayValue() ); case ARRAY: - return arrayValue(); + return Values.of( arrayValue() ); default: throw new IllegalStateException( "No such type:" + type() ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/GraphPropertiesProxy.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/GraphPropertiesProxy.java index 15325eff6a303..e0f510de90056 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/GraphPropertiesProxy.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/GraphPropertiesProxy.java @@ -228,7 +228,7 @@ public Map getAllProperties() { int propertyKeyId = propertyKeys.next(); properties.put( readOperations.propertyKeyGetName( propertyKeyId ), - readOperations.graphGetProperty( propertyKeyId ) ); + readOperations.graphGetProperty( propertyKeyId ).asPublic() ); } return properties; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/NodeProxy.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/NodeProxy.java index 8087f890beccc..9f3ef3929ef33 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/NodeProxy.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/NodeProxy.java @@ -420,7 +420,7 @@ public Map getAllProperties() { String name = statement.readOperations().propertyKeyGetName( propertyCursor.get().propertyKeyId() ); - properties.put( name, propertyCursor.get().value() ); + properties.put( name, propertyCursor.get().value().asPublic() ); } return properties; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/PropertyContainerProxyHelper.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/PropertyContainerProxyHelper.java index 0c92394ca69ea..94b31ccd7fedd 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/core/PropertyContainerProxyHelper.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/core/PropertyContainerProxyHelper.java @@ -52,7 +52,7 @@ static Map getProperties( Statement statement, Cursor getAllProperties() { String name = statement.readOperations().propertyKeyGetName( propertyCursor.get().propertyKeyId() ); - properties.put( name, propertyCursor.get().value() ); + properties.put( name, propertyCursor.get().value().asPublic() ); } return properties; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataSnapshot.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataSnapshot.java index 373257e894e03..c630a05fa9d7a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataSnapshot.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataSnapshot.java @@ -39,7 +39,6 @@ import org.neo4j.kernel.api.exceptions.EntityNotFoundException; import org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException; import org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException; -import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.impl.api.KernelTransactionImplementation; import org.neo4j.kernel.impl.core.NodeProxy; import org.neo4j.kernel.impl.core.RelationshipProxy; @@ -55,6 +54,8 @@ import org.neo4j.storageengine.api.txstate.ReadableDiffSets; import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.RelationshipState; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.neo4j.kernel.api.AssertOpen.ALWAYS_OPEN; @@ -256,9 +257,9 @@ private void takeSnapshot() Iterator added = nodeState.addedAndChangedProperties(); while ( added.hasNext() ) { - DefinedProperty property = (DefinedProperty) added.next(); + StorageProperty property = added.next(); assignedNodeProperties.add( new NodePropertyEntryView( nodeState.getId(), - store.propertyKeyGetName( property.propertyKeyId() ), property.value(), + store.propertyKeyGetName( property.propertyKeyId() ), property.valueForced(), committedValue( nodeState, property.propertyKeyId() ) ) ); } Iterator removed = nodeState.removedProperties(); @@ -285,9 +286,9 @@ private void takeSnapshot() Iterator added = relState.addedAndChangedProperties(); while ( added.hasNext() ) { - DefinedProperty property = (DefinedProperty) added.next(); + StorageProperty property = added.next(); assignedRelationshipProperties.add( new RelationshipPropertyEntryView( relationship, - store.propertyKeyGetName( property.propertyKeyId() ), property.value(), + store.propertyKeyGetName( property.propertyKeyId() ), property.valueForced(), committedValue( relState, property.propertyKeyId() ) ) ); } Iterator removed = relState.removedProperties(); @@ -355,18 +356,18 @@ protected Relationship underlyingObjectToObject( Long id ) }; } - private Object committedValue( NodeState nodeState, int property ) + private Value committedValue( NodeState nodeState, int property ) { if ( state.nodeIsAddedInThisTx( nodeState.getId() ) ) { - return null; + return Values.NO_VALUE; } try ( Cursor node = storeStatement.acquireSingleNodeCursor( nodeState.getId() ) ) { if ( !node.next() ) { - return null; + return Values.NO_VALUE; } Lock lock = node.get().lock(); @@ -380,14 +381,14 @@ private Object committedValue( NodeState nodeState, int property ) } } - return null; + return Values.NO_VALUE; } - private Object committedValue( RelationshipState relState, int property ) + private Value committedValue( RelationshipState relState, int property ) { if ( state.relationshipIsAddedInThisTx( relState.getId() ) ) { - return null; + return Values.NO_VALUE; } try ( Cursor relationship = storeStatement.acquireSingleRelationshipCursor( @@ -395,7 +396,7 @@ private Object committedValue( RelationshipState relState, int property ) { if ( !relationship.next() ) { - return null; + return Values.NO_VALUE; } Lock lock = relationship.get().lock(); @@ -409,17 +410,17 @@ private Object committedValue( RelationshipState relState, int property ) } } - return null; + return Values.NO_VALUE; } private class NodePropertyEntryView implements PropertyEntry { private final long nodeId; private final String key; - private final Object newValue; - private final Object oldValue; + private final Value newValue; + private final Value oldValue; - NodePropertyEntryView( long nodeId, String key, Object newValue, Object oldValue ) + NodePropertyEntryView( long nodeId, String key, Value newValue, Value oldValue ) { this.nodeId = nodeId; this.key = key; @@ -442,17 +443,17 @@ public String key() @Override public Object previouslyCommitedValue() { - return oldValue; + return oldValue.asPublic(); } @Override public Object value() { - if ( newValue == null ) + if ( newValue == null || newValue == Values.NO_VALUE ) { throw new IllegalStateException( "This property has been removed, it has no value anymore." ); } - return newValue; + return newValue.asPublic(); } @Override @@ -471,10 +472,10 @@ private class RelationshipPropertyEntryView implements PropertyEntry update ) throws IndexEntryConflictException { long existingNodeId = conflictDetectingValueMerger.existingNodeId(); long addedNodeId = conflictDetectingValueMerger.addedNodeId(); - // TODO: not sure about the OrderedPropertyValues#ofUndefined bit - throw new IndexEntryConflictException( existingNodeId, addedNodeId, ofUndefined( update.values() ) ); + throw new IndexEntryConflictException( existingNodeId, addedNodeId, ValueTuple.of( update.values() ) ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberKey.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberKey.java index b0aa7f432277a..4e2719c75775f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberKey.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberKey.java @@ -19,7 +19,9 @@ */ package org.neo4j.kernel.impl.index.schema; -import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumberPropertyValue; +import org.neo4j.values.Value; + +import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumber; /** * Includes comparison value and entity id (to be able to handle non-unique values). @@ -37,10 +39,9 @@ class NonUniqueSchemaNumberKey implements SchemaNumberKey long entityId; @Override - public void from( long entityId, Object[] values ) + public void from( long entityId, Value[] values ) { - assertValidSingleNumberPropertyValue( values ); - this.value = ((Number) values[0]).doubleValue(); + this.value = assertValidSingleNumber( values ).doubleValue(); this.entityId = entityId; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberValue.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberValue.java index 29c3f54af64ba..3fffeb4afad6d 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberValue.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NonUniqueSchemaNumberValue.java @@ -19,9 +19,11 @@ */ package org.neo4j.kernel.impl.index.schema; +import org.neo4j.values.Value; + import static java.lang.String.format; -import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumberPropertyValue; +import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumber; import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.toValue; /** @@ -34,10 +36,9 @@ class NonUniqueSchemaNumberValue extends SchemaNumberValue Long.SIZE; /* value bits */ @Override - public void from( long entityId, Object[] values ) + public void from( long entityId, Value[] values ) { - assertValidSingleNumberPropertyValue( values ); - extractValue( (Number) values[0] ); + extractValue( assertValidSingleNumber( values ) ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberKey.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberKey.java index 7c6d47e1d9b70..023665f279ba4 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberKey.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberKey.java @@ -19,12 +19,14 @@ */ package org.neo4j.kernel.impl.index.schema; +import org.neo4j.values.Value; + /** * Key in a native schema index for numbers. */ interface SchemaNumberKey { - void from( long entityId, Object[] values ); + void from( long entityId, Value[] values ); String propertiesAsString(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValue.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValue.java index 31d6b915a0761..14163c48ba44d 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValue.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValue.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.impl.index.schema; import org.neo4j.index.internal.gbptree.GBPTree; +import org.neo4j.values.Value; /** * Value in a {@link GBPTree} handling numbers suitable for schema indexing. @@ -34,7 +35,7 @@ abstract class SchemaNumberValue protected byte type; protected long rawValueBits; - abstract void from( long entityId, Object[] values ); + abstract void from( long entityId, Value[] values ); abstract long getEntityId(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValueConversion.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValueConversion.java index b4e125232a56d..4fb472784e606 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValueConversion.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SchemaNumberValueConversion.java @@ -19,6 +19,9 @@ */ package org.neo4j.kernel.impl.index.schema; +import org.neo4j.values.Value; +import org.neo4j.values.Values; + import static org.neo4j.kernel.impl.index.schema.SchemaNumberValue.DOUBLE; import static org.neo4j.kernel.impl.index.schema.SchemaNumberValue.FLOAT; import static org.neo4j.kernel.impl.index.schema.SchemaNumberValue.LONG; @@ -28,7 +31,7 @@ */ class SchemaNumberValueConversion { - static void assertValidSingleNumberPropertyValue( Object[] values ) + static Number assertValidSingleNumber( Value[] values ) { // TODO: support multiple values, right? if ( values.length > 1 ) @@ -39,11 +42,12 @@ static void assertValidSingleNumberPropertyValue( Object[] values ) { throw new IllegalArgumentException( "Tried to create key without value" ); } - if ( !(values[0] instanceof Number) ) + if ( !Values.isNumberValue( values[0] ) ) { throw new IllegalArgumentException( "Key layout does only support numbers, tried to create key from " + values[0] ); } + return (Number) values[0].asPublic(); } static Number toValue( byte type, long rawValueBits ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberKey.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberKey.java index 5cc46f9aa472c..2f0080ebba6dc 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberKey.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberKey.java @@ -19,7 +19,9 @@ */ package org.neo4j.kernel.impl.index.schema; -import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumberPropertyValue; +import org.neo4j.values.Value; + +import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumber; /** * Contains only comparison value, which means that all values needs to be unique. @@ -35,10 +37,9 @@ class UniqueSchemaNumberKey implements SchemaNumberKey boolean isHighest; @Override - public void from( long entityId, Object[] values ) + public void from( long entityId, Value[] values ) { - assertValidSingleNumberPropertyValue( values ); - value = ((Number) values[0]).doubleValue(); + value = assertValidSingleNumber( values ).doubleValue(); isHighest = false; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberValue.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberValue.java index 6251d723608b1..ccd43f7783bf7 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberValue.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/UniqueSchemaNumberValue.java @@ -19,9 +19,11 @@ */ package org.neo4j.kernel.impl.index.schema; +import org.neo4j.values.Value; + import static java.lang.String.format; -import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumberPropertyValue; +import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.assertValidSingleNumber; import static org.neo4j.kernel.impl.index.schema.SchemaNumberValueConversion.toValue; /** @@ -38,10 +40,9 @@ class UniqueSchemaNumberValue extends SchemaNumberValue long entityId; @Override - public void from( long entityId, Object[] values ) + public void from( long entityId, Value[] values ) { - assertValidSingleNumberPropertyValue( values ); - extractValue( (Number) values[0] ); + extractValue( assertValidSingleNumber( values ) ); this.entityId = entityId; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java index cb17598aba0dc..9c23717e2d9f7 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ResourceTypes.java @@ -22,12 +22,13 @@ import java.util.HashMap; import java.util.Map; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.helpers.Strings; import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.impl.util.concurrent.LockWaitStrategies; import org.neo4j.storageengine.api.lock.ResourceType; import org.neo4j.storageengine.api.lock.WaitStrategy; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.neo4j.collection.primitive.hopscotch.HopScotchHashingAlgorithm.DEFAULT_HASHING; @@ -87,10 +88,10 @@ public static long indexEntryResourceId( long labelId, IndexQuery.ExactPredicate private static long indexEntryResourceId( long labelId, IndexQuery.ExactPredicate[] predicates, int i ) { int propertyKeyId = predicates[i].propertyKeyId(); - Object value = predicates[i].value(); + Value value = predicates[i].value(); // Note: // It is important that single-property indexes only hash with this particular call; no additional hashing! - long hash = indexEntryResourceId( labelId, propertyKeyId, stringOf( propertyKeyId, value ) ); + long hash = indexEntryResourceId( labelId, propertyKeyId, stringOf( value ) ); i++; if ( i < predicates.length ) { @@ -106,12 +107,11 @@ private static long indexEntryResourceId( long labelId, long propertyKeyId, Stri return hob + propertyValue.hashCode(); } - private static String stringOf( int propertyKeyId, Object value ) + private static String stringOf( Value value ) { - if ( null != value ) + if ( null != Values.NO_VALUE ) { - DefinedProperty property = Property.property( propertyKeyId, value ); - return property.valueAsString(); + return Strings.prettyPrint( value.asPublic() ); } return ""; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java index 928cb5c856e72..e98788afb3b8f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/storageengine/impl/recordstorage/TransactionToRecordStateVisitor.java @@ -27,7 +27,6 @@ import org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException; import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; import org.neo4j.kernel.api.index.SchemaIndexProvider; -import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema.constaints.IndexBackedConstraintDescriptor; import org.neo4j.kernel.api.schema.constaints.NodeKeyConstraintDescriptor; @@ -115,13 +114,13 @@ public void visitNodePropertyChanges( long id, Iterator added, } while ( changed.hasNext() ) { - DefinedProperty prop = (DefinedProperty) changed.next(); - recordState.nodeChangeProperty( id, prop.propertyKeyId(), prop.value() ); + StorageProperty prop = changed.next(); + recordState.nodeChangeProperty( id, prop.propertyKeyId(), prop.valueForced() ); } while ( added.hasNext() ) { - DefinedProperty prop = (DefinedProperty) added.next(); - recordState.nodeAddProperty( id, prop.propertyKeyId(), prop.value() ); + StorageProperty prop = added.next(); + recordState.nodeAddProperty( id, prop.propertyKeyId(), prop.valueForced() ); } } @@ -135,13 +134,13 @@ public void visitRelPropertyChanges( long id, Iterator added, } while ( changed.hasNext() ) { - DefinedProperty prop = (DefinedProperty) changed.next(); - recordState.relChangeProperty( id, prop.propertyKeyId(), prop.value() ); + StorageProperty prop = changed.next(); + recordState.relChangeProperty( id, prop.propertyKeyId(), prop.valueForced() ); } while ( added.hasNext() ) { - DefinedProperty prop = (DefinedProperty) added.next(); - recordState.relAddProperty( id, prop.propertyKeyId(), prop.value() ); + StorageProperty prop = added.next(); + recordState.relAddProperty( id, prop.propertyKeyId(), prop.valueForced() ); } } @@ -155,13 +154,13 @@ public void visitGraphPropertyChanges( Iterator added, Iterator } while ( changed.hasNext() ) { - DefinedProperty prop = (DefinedProperty) changed.next(); - recordState.graphChangeProperty( prop.propertyKeyId(), prop.value() ); + StorageProperty prop = changed.next(); + recordState.graphChangeProperty( prop.propertyKeyId(), prop.valueForced() ); } while ( added.hasNext() ) { - DefinedProperty prop = (DefinedProperty) added.next(); - recordState.graphAddProperty( prop.propertyKeyId(), prop.value() ); + StorageProperty prop = added.next(); + recordState.graphAddProperty( prop.propertyKeyId(), prop.valueForced() ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyStore.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyStore.java index 359fe4ffb623e..a691ab6989ec2 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyStore.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyStore.java @@ -43,6 +43,7 @@ import org.neo4j.kernel.impl.store.record.RecordLoad; import org.neo4j.logging.LogProvider; import org.neo4j.string.UTF8; +import org.neo4j.values.Value; import static org.neo4j.kernel.impl.store.DynamicArrayStore.getRightArray; import static org.neo4j.kernel.impl.store.NoStoreHeaderFormat.NO_STORE_HEADER_FORMAT; @@ -200,9 +201,9 @@ private RecordStore dynamicStoreForValueType( PropertyType type ) } } - public Object getValue( PropertyBlock propertyBlock ) + public Value getValue( PropertyBlock propertyBlock ) { - return propertyBlock.getType().getValue( propertyBlock, this ); + return propertyBlock.getType().getValueNow( propertyBlock, this ); } public static void allocateStringRecords( Collection target, byte[] chars, @@ -217,17 +218,19 @@ public static void allocateArrayRecords( Collection target, Objec DynamicArrayStore.allocateRecords( target, array, allocator ); } - public void encodeValue( PropertyBlock block, int keyId, Object value ) + public void encodeValue( PropertyBlock block, int keyId, Value value ) { encodeValue( block, keyId, value, stringStore, arrayStore ); } - public static void encodeValue( PropertyBlock block, int keyId, Object value, + public static void encodeValue( PropertyBlock block, int keyId, Value value, DynamicRecordAllocator stringAllocator, DynamicRecordAllocator arrayAllocator ) { - if ( value instanceof String ) + // TODO: use ValueWriter + Object asObject = value.asPublic(); + if ( asObject instanceof String ) { // Try short string first, i.e. inlined in the property block - String string = (String) value; + String string = (String) asObject; if ( LongerShortString.encode( keyId, string, block, PropertyType.getPayloadSize() ) ) { return; @@ -244,60 +247,60 @@ public static void encodeValue( PropertyBlock block, int keyId, Object value, } block.setValueRecords( valueRecords ); } - else if ( value instanceof Integer ) + else if ( asObject instanceof Integer ) { - setSingleBlockValue( block, keyId, PropertyType.INT, ((Integer) value).longValue() ); + setSingleBlockValue( block, keyId, PropertyType.INT, ((Integer) asObject).longValue() ); } - else if ( value instanceof Boolean ) + else if ( asObject instanceof Boolean ) { - setSingleBlockValue( block, keyId, PropertyType.BOOL, (Boolean) value ? 1L : 0L ); + setSingleBlockValue( block, keyId, PropertyType.BOOL, (Boolean) asObject ? 1L : 0L ); } - else if ( value instanceof Float ) + else if ( asObject instanceof Float ) { - setSingleBlockValue( block, keyId, PropertyType.FLOAT, Float.floatToRawIntBits( (Float) value ) ); + setSingleBlockValue( block, keyId, PropertyType.FLOAT, Float.floatToRawIntBits( (Float) asObject ) ); } - else if ( value instanceof Long ) + else if ( asObject instanceof Long ) { long keyAndType = keyId | (((long) PropertyType.LONG.intValue()) << StandardFormatSettings.PROPERTY_TOKEN_MAXIMUM_ID_BITS); - if ( ShortArray.LONG.getRequiredBits( (Long) value ) <= 35 ) + if ( ShortArray.LONG.getRequiredBits( (Long) asObject ) <= 35 ) { // We only need one block for this value, special layout compared to, say, an integer - block.setSingleBlock( keyAndType | (1L << 28) | ((Long) value << 29) ); + block.setSingleBlock( keyAndType | (1L << 28) | ((Long) asObject << 29) ); } else { // We need two blocks for this value - block.setValueBlocks( new long[]{keyAndType, (Long) value} ); + block.setValueBlocks( new long[]{keyAndType, (Long) asObject} ); } } - else if ( value instanceof Double ) + else if ( asObject instanceof Double ) { block.setValueBlocks( new long[]{ keyId | (((long) PropertyType.DOUBLE.intValue()) << StandardFormatSettings.PROPERTY_TOKEN_MAXIMUM_ID_BITS), - Double.doubleToRawLongBits( (Double) value )} ); + Double.doubleToRawLongBits( (Double) asObject )} ); } - else if ( value instanceof Byte ) + else if ( asObject instanceof Byte ) { - setSingleBlockValue( block, keyId, PropertyType.BYTE, ((Byte) value).longValue() ); + setSingleBlockValue( block, keyId, PropertyType.BYTE, ((Byte) asObject).longValue() ); } - else if ( value instanceof Character ) + else if ( asObject instanceof Character ) { - setSingleBlockValue( block, keyId, PropertyType.CHAR, (Character) value ); + setSingleBlockValue( block, keyId, PropertyType.CHAR, (Character) asObject ); } - else if ( value instanceof Short ) + else if ( asObject instanceof Short ) { - setSingleBlockValue( block, keyId, PropertyType.SHORT, ((Short) value).longValue() ); + setSingleBlockValue( block, keyId, PropertyType.SHORT, ((Short) asObject).longValue() ); } - else if ( value.getClass().isArray() ) + else if ( asObject.getClass().isArray() ) { // Try short array first, i.e. inlined in the property block - if ( ShortArray.encode( keyId, value, block, PropertyType.getPayloadSize() ) ) + if ( ShortArray.encode( keyId, asObject, block, PropertyType.getPayloadSize() ) ) { return; } // Fall back to dynamic array store List arrayRecords = new ArrayList<>(); - allocateArrayRecords( arrayRecords, value, arrayAllocator ); + allocateArrayRecords( arrayRecords, asObject, arrayAllocator ); setSingleBlockValue( block, keyId, PropertyType.ARRAY, Iterables.first( arrayRecords ).getId() ); for ( DynamicRecord valueRecord : arrayRecords ) { @@ -307,7 +310,7 @@ else if ( value.getClass().isArray() ) } else { - throw new IllegalArgumentException( "Unknown property type on: " + value + ", " + value.getClass() ); + throw new IllegalArgumentException( "Unknown property type on: " + asObject + ", " + asObject.getClass() ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyType.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyType.java index c9bfa0f3a3887..4e7058c64398f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyType.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/PropertyType.java @@ -20,12 +20,11 @@ package org.neo4j.kernel.impl.store; import java.util.Arrays; -import java.util.function.Supplier; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.impl.store.format.standard.PropertyRecordFormat; import org.neo4j.kernel.impl.store.record.PropertyBlock; +import org.neo4j.values.Value; +import org.neo4j.values.Values; /** * Defines valid property types. @@ -36,15 +35,15 @@ public enum PropertyType BOOL( 1 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.booleanProperty( propertyKeyId, getValue( block.getSingleValueLong() ) ); + return Values.booleanValue( getValue( block.getSingleValueLong() ) ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return getValue( block.getSingleValueLong() ); + return getValue( block, store ); } private boolean getValue( long propBlock ) @@ -55,80 +54,73 @@ private boolean getValue( long propBlock ) BYTE( 2 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.byteProperty( propertyKeyId, block.getSingleValueByte() ); + return Values.byteValue( block.getSingleValueByte() ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return Byte.valueOf( block.getSingleValueByte() ); + return Values.byteValue( block.getSingleValueByte() ); } }, SHORT( 3 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.shortProperty( propertyKeyId, block.getSingleValueShort() ); + return Values.shortValue( block.getSingleValueShort() ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return Short.valueOf( block.getSingleValueShort() ); + return Values.shortValue( block.getSingleValueShort() ); } }, CHAR( 4 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.charProperty( propertyKeyId, (char) block.getSingleValueShort() ); + return Values.charValue( (char) block.getSingleValueShort() ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return Character.valueOf( (char) block.getSingleValueShort() ); + return Values.charValue( (char) block.getSingleValueShort() ); } }, INT( 5 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.intProperty( propertyKeyId, block.getSingleValueInt() ); + return Values.intValue( block.getSingleValueInt() ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return Integer.valueOf( block.getSingleValueInt() ); + return Values.intValue( block.getSingleValueInt() ); } }, LONG( 6 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { long firstBlock = block.getSingleValueBlock(); long value = valueIsInlined( firstBlock ) ? (block.getSingleValueLong() >>> 1) : block.getValueBlocks()[1]; - return Property.longProperty( propertyKeyId, value ); + return Values.longValue( value ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return Long.valueOf( getLongValue( block ) ); - } - - private long getLongValue( PropertyBlock block ) - { - long firstBlock = block.getSingleValueBlock(); - return valueIsInlined( firstBlock ) ? (block.getSingleValueLong() >>> 1) : - block.getValueBlocks()[1]; + return getValue( block, store ); } private boolean valueIsInlined( long firstBlock ) @@ -146,39 +138,29 @@ public int calculateNumberOfBlocksUsed( long firstBlock ) FLOAT( 7 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.floatProperty( propertyKeyId, Float.intBitsToFloat( block.getSingleValueInt() ) ); + return Values.floatValue( Float.intBitsToFloat( block.getSingleValueInt() ) ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) - { - return Float.valueOf( getValue( block.getSingleValueInt() ) ); - } - - private float getValue( int propBlock ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return Float.intBitsToFloat( propBlock ); + return Values.floatValue( Float.intBitsToFloat( block.getSingleValueInt() ) ); } }, DOUBLE( 8 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.doubleProperty( propertyKeyId, Double.longBitsToDouble( block.getValueBlocks()[1] ) ); + return Values.doubleValue( Double.longBitsToDouble( block.getValueBlocks()[1] ) ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return Double.valueOf( getValue( block.getValueBlocks()[1] ) ); - } - - private double getValue( long propBlock ) - { - return Double.longBitsToDouble( propBlock ); + return Values.doubleValue( Double.longBitsToDouble( block.getValueBlocks()[1] ) ); } @Override @@ -190,20 +172,15 @@ public int calculateNumberOfBlocksUsed( long firstBlock ) STRING( 9 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, final PropertyBlock block, - final Supplier store ) + public Value getValue( final PropertyBlock block, final PropertyStore store ) { - return Property.lazyStringProperty(propertyKeyId, () -> getValue( block, store.get() ) ); + return Values.lazyStringValue( () -> store.getStringFor( block ) ); } @Override - public String getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - if ( store == null ) - { - return null; - } - return store.getStringFor( block ); + return Values.stringValue( store.getStringFor( block ) ); } @Override @@ -215,19 +192,16 @@ public byte[] readDynamicRecordHeader( byte[] recordBytes ) ARRAY( 10 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, final PropertyBlock block, final Supplier store ) + public Value getValue( final PropertyBlock block, final PropertyStore store ) { - return Property.lazyArrayProperty(propertyKeyId, () -> getValue( block, store.get() ) ); + // TODO: make me lazy again? + return getValueNow( block, store ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - if ( store == null ) - { - return null; - } - return store.getArrayFor( block ); + return Values.of( store.getArrayFor( block ) ); } @Override @@ -253,15 +227,15 @@ private byte[] headOf( byte[] bytes, int length ) SHORT_STRING( 11 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { - return Property.stringProperty( propertyKeyId, LongerShortString.decode( block ) ); + return Values.stringValue( LongerShortString.decode( block ) ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return LongerShortString.decode( block ); + return Values.stringValue( LongerShortString.decode( block ) ); } @Override @@ -273,16 +247,16 @@ public int calculateNumberOfBlocksUsed( long firstBlock ) SHORT_ARRAY( 12 ) { @Override - public DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ) + public Value getValue( PropertyBlock block, PropertyStore store ) { // TODO: Specialize per type - return Property.property( propertyKeyId, ShortArray.decode(block) ); + return Values.of( ShortArray.decode(block) ); } @Override - public Object getValue( PropertyBlock block, PropertyStore store ) + public Value getValueNow( PropertyBlock block, PropertyStore store ) { - return ShortArray.decode( block ); + return Values.of( ShortArray.decode( block ) ); } @Override @@ -327,9 +301,9 @@ public byte byteValue() return (byte) type; } - public abstract Object getValue( PropertyBlock block, PropertyStore store ); + public abstract Value getValueNow( PropertyBlock block, PropertyStore store ); - public abstract DefinedProperty readProperty( int propertyKeyId, PropertyBlock block, Supplier store ); + public abstract Value getValue( PropertyBlock block, PropertyStore store ); public static PropertyType getPropertyTypeOrNull( long propBlock ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/PropertyBlock.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/PropertyBlock.java index c32b3c6c09613..51b70e4ac6689 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/PropertyBlock.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/PropertyBlock.java @@ -25,12 +25,11 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.function.Supplier; -import org.neo4j.function.Suppliers; -import org.neo4j.kernel.api.properties.DefinedProperty; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.PropertyType; +import org.neo4j.values.Value; public class PropertyBlock implements Cloneable { @@ -180,7 +179,7 @@ public String toString() result.append( ",firstDynamic=" ).append( getSingleValueLong() ); break; default: - Object value = type.getValue( this, null ); + Object value = type.getValueNow( this, null ); if ( value != null && value.getClass().isArray() ) { int length = Array.getLength( value ); @@ -246,14 +245,15 @@ public boolean hasSameContentsAs( PropertyBlock other ) return Arrays.equals( valueBlocks, other.valueBlocks ); } - public DefinedProperty newPropertyData( PropertyStore propertyStore ) + public Value newPropertyValue( PropertyStore propertyStore ) { - return newPropertyData( Suppliers.singleton( propertyStore ) ); + return getType().getValue( this, propertyStore ); } - public DefinedProperty newPropertyData( Supplier propertyStore ) + public PropertyKeyValue newPropertyKeyValue( PropertyStore propertyStore ) { - return getType().readProperty( getKeyIndexId(), this, propertyStore ); + int propertyKeyId = getKeyIndexId(); + return new PropertyKeyValue( propertyKeyId, getType().getValue( this, propertyStore ) ); } public static int keyIndexId( long valueBlock ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexConsultedPropertyBlockSweeper.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexConsultedPropertyBlockSweeper.java index 366678f813730..bcb126b3dc9e7 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexConsultedPropertyBlockSweeper.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexConsultedPropertyBlockSweeper.java @@ -27,6 +27,7 @@ import org.neo4j.kernel.impl.store.record.NodeRecord; import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.PropertyRecord; +import org.neo4j.values.Value; import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL; @@ -65,7 +66,7 @@ public boolean visited( long propRecordId ) throws IOException if ( block.getKeyIndexId() == propertyKeyId ) { - Object propertyValue = propertyStore.getValue( block ); + Value propertyValue = propertyStore.getValue( block ); if ( !foundExact && index.contains( nodeRecord.getId(), propertyValue ) ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexLookup.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexLookup.java index 8d64bc81457b6..e90711caa067e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexLookup.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/storemigration/legacystore/v21/propertydeduplication/IndexLookup.java @@ -37,6 +37,7 @@ import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.SchemaRule; +import org.neo4j.values.Value; class IndexLookup implements AutoCloseable { @@ -142,6 +143,6 @@ public boolean hasAnyIndexes() interface Index { - boolean contains( long nodeId, Object propertyValue ) throws IOException; + boolean contains( long nodeId, Value propertyValue ) throws IOException; } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyCreator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyCreator.java index 9f49af5a08bf7..fa56c17e62beb 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyCreator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyCreator.java @@ -32,6 +32,7 @@ import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy; +import org.neo4j.values.Value; public class PropertyCreator { @@ -55,7 +56,7 @@ public PropertyCreator( DynamicRecordAllocator stringRecordAllocator, DynamicRec } public

void primitiveSetProperty( - RecordProxy primitiveRecordChange, int propertyKey, Object value, + RecordProxy primitiveRecordChange, int propertyKey, Value value, RecordAccess propertyRecords ) { PropertyBlock block = encodePropertyValue( propertyKey, value ); @@ -184,12 +185,12 @@ private boolean propertyFitsInside( int newBlockSizeInBytes, PropertyRecord prop return propSize + newBlockSizeInBytes <= PropertyType.getPayloadSize(); } - public PropertyBlock encodePropertyValue( int propertyKey, Object value ) + public PropertyBlock encodePropertyValue( int propertyKey, Value value ) { return encodeValue( new PropertyBlock(), propertyKey, value ); } - public PropertyBlock encodeValue( PropertyBlock block, int propertyKey, Object value ) + public PropertyBlock encodeValue( PropertyBlock block, int propertyKey, Value value ) { PropertyStore.encodeValue( block, propertyKey, value, stringRecordAllocator, arrayRecordAllocator ); return block; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyLoader.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyLoader.java index eff8282675a4e..b47c4b0dd94fe 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyLoader.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/PropertyLoader.java @@ -96,7 +96,7 @@ private RECEIVER receivePropertyChain( RECEI { for ( PropertyBlock propBlock : propRecord ) { - receiver.receive( propBlock.newPropertyData( propertyStore ), propRecord.getId() ); + receiver.receive( propBlock.newPropertyKeyValue( propertyStore ), propRecord.getId() ); } } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java index e6ec1f9a9b9ba..ef3ea4fc5506e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordState.java @@ -25,8 +25,6 @@ import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.exceptions.TransactionFailureException; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.impl.core.RelationshipTypeToken; import org.neo4j.kernel.impl.store.MetaDataStore; import org.neo4j.kernel.impl.store.NeoStores; @@ -58,6 +56,7 @@ import org.neo4j.storageengine.api.Token; import org.neo4j.storageengine.api.lock.ResourceLocker; import org.neo4j.storageengine.api.schema.SchemaRule; +import org.neo4j.values.Value; import static java.lang.String.format; import static org.neo4j.kernel.impl.store.NodeLabelsField.parseLabelsField; @@ -358,65 +357,53 @@ public void nodeRemoveProperty( long nodeId, int propertyKey ) /** * Changes an existing property's value of the given relationship, with the * given index to the passed value - * - * @param relId The id of the relationship which holds the property to + * @param relId The id of the relationship which holds the property to * change. * @param propertyKey The index of the key of the property to change. * @param value The new value of the property. - * @return The changed property, as a PropertyData object. */ - public DefinedProperty relChangeProperty( long relId, int propertyKey, Object value ) + public void relChangeProperty( long relId, int propertyKey, Value value ) { RecordProxy rel = recordChangeSet.getRelRecords().getOrLoad( relId, null ); propertyCreator.primitiveSetProperty( rel, propertyKey, value, recordChangeSet.getPropertyRecords() ); - return Property.property( propertyKey, value ); } /** * Changes an existing property of the given node, with the given index to * the passed value - * - * @param nodeId The id of the node which holds the property to change. + * @param nodeId The id of the node which holds the property to change. * @param propertyKey The index of the key of the property to change. * @param value The new value of the property. - * @return The changed property, as a PropertyData object. */ - public DefinedProperty nodeChangeProperty( long nodeId, int propertyKey, Object value ) + public void nodeChangeProperty( long nodeId, int propertyKey, Value value ) { RecordProxy node = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ); propertyCreator.primitiveSetProperty( node, propertyKey, value, recordChangeSet.getPropertyRecords() ); - return Property.property( propertyKey, value ); } /** * Adds a property to the given relationship, with the given index and * value. - * - * @param relId The id of the relationship to which to add the property. + * @param relId The id of the relationship to which to add the property. * @param propertyKey The index of the key of the property to add. * @param value The value of the property. - * @return The added property, as a PropertyData object. */ - public DefinedProperty relAddProperty( long relId, int propertyKey, Object value ) + public void relAddProperty( long relId, int propertyKey, Value value ) { RecordProxy rel = recordChangeSet.getRelRecords().getOrLoad( relId, null ); propertyCreator.primitiveSetProperty( rel, propertyKey, value, recordChangeSet.getPropertyRecords() ); - return Property.property( propertyKey, value ); } /** * Adds a property to the given node, with the given index and value. - * - * @param nodeId The id of the node to which to add the property. + * @param nodeId The id of the node to which to add the property. * @param propertyKey The index of the key of the property to add. * @param value The value of the property. - * @return The added property, as a PropertyData object. */ - public DefinedProperty nodeAddProperty( long nodeId, int propertyKey, Object value ) + public void nodeAddProperty( long nodeId, int propertyKey, Value value ) { RecordProxy node = recordChangeSet.getNodeRecords().getOrLoad( nodeId, null ); propertyCreator.primitiveSetProperty( node, propertyKey, value, recordChangeSet.getPropertyRecords() ); - return Property.property( propertyKey, value ); } /** @@ -544,16 +531,13 @@ public NeoStoreRecord clone( NeoStoreRecord neoStoreRecord ) /** * Adds a property to the graph, with the given index and value. - * - * @param propertyKey The index of the key of the property to add. + * @param propertyKey The index of the key of the property to add. * @param value The value of the property. - * @return The added property, as a PropertyData object. */ - public DefinedProperty graphAddProperty( int propertyKey, Object value ) + public void graphAddProperty( int propertyKey, Value value ) { propertyCreator.primitiveSetProperty( getOrLoadNeoStoreRecord(), propertyKey, value, recordChangeSet.getPropertyRecords() ); - return Property.property( propertyKey, value ); } /** @@ -562,13 +546,11 @@ public DefinedProperty graphAddProperty( int propertyKey, Object value ) * * @param propertyKey The index of the key of the property to change. * @param value The new value of the property. - * @return The changed property, as a PropertyData object. */ - public DefinedProperty graphChangeProperty( int propertyKey, Object value ) + public void graphChangeProperty( int propertyKey, Value value ) { propertyCreator.primitiveSetProperty( getOrLoadNeoStoreRecord(), propertyKey, value, recordChangeSet.getPropertyRecords() ); - return Property.property( propertyKey, value ); } /** diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreView.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreView.java index 54b68cb9f2064..2fc175b19f40e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreView.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreView.java @@ -25,7 +25,6 @@ import org.neo4j.helpers.collection.Visitor; import org.neo4j.kernel.api.exceptions.EntityNotFoundException; import org.neo4j.kernel.api.labelscan.NodeLabelUpdate; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.impl.api.CountsAccessor; import org.neo4j.kernel.impl.api.index.IndexStoreView; import org.neo4j.kernel.impl.api.index.NodeUpdates; @@ -41,6 +40,8 @@ import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.register.Register.DoubleLongRegister; import org.neo4j.storageengine.api.EntityType; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.neo4j.kernel.impl.store.NodeLabelsField.parseLabelsField; import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE; @@ -128,7 +129,7 @@ public NodeUpdates nodeAsUpdates( long nodeId ) { for ( PropertyBlock property : propertyRecord ) { - Object value = property.getType().getValue( property, propertyStore ); + Value value = property.getType().getValueNow( property, propertyStore ); update.added( property.getKeyIndexId(), value ); } } @@ -136,7 +137,7 @@ public NodeUpdates nodeAsUpdates( long nodeId ) } @Override - public Property getProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException + public Value getPropertyValue( long nodeId, int propertyKeyId ) throws EntityNotFoundException { NodeRecord node = nodeStore.getRecord( nodeId, nodeStore.newRecord(), FORCE ); if ( !node.inUse() ) @@ -146,17 +147,17 @@ public Property getProperty( long nodeId, int propertyKeyId ) throws EntityNotFo long firstPropertyId = node.getNextProp(); if ( firstPropertyId == Record.NO_NEXT_PROPERTY.intValue() ) { - return Property.noNodeProperty( nodeId, propertyKeyId ); + return Values.NO_VALUE; } for ( PropertyRecord propertyRecord : propertyStore.getPropertyRecordChain( firstPropertyId ) ) { PropertyBlock propertyBlock = propertyRecord.getPropertyBlock( propertyKeyId ); if ( propertyBlock != null ) { - return propertyBlock.newPropertyData( propertyStore ); + return propertyBlock.newPropertyValue( propertyStore ); } } - return Property.noNodeProperty( nodeId, propertyKeyId ); + return Values.NO_VALUE; } @Override @@ -179,7 +180,7 @@ public void loadProperties( long nodeId, PrimitiveIntSet propertyIds, PropertyLo int currentPropertyId = block.getKeyIndexId(); if ( propertyIds.contains( currentPropertyId ) ) { - Object currentValue = block.getType().getValue( block, propertyStore ); + Value currentValue = block.getType().getValueNow( block, propertyStore ); sink.onProperty( currentPropertyId, currentValue ); propertyIds.remove( currentPropertyId ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/StoreViewNodeStoreScan.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/StoreViewNodeStoreScan.java index 4f0689765224b..6d1f2aafb203f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/StoreViewNodeStoreScan.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/state/storeview/StoreViewNodeStoreScan.java @@ -40,6 +40,8 @@ import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.kernel.impl.util.Validators; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.util.Collections.emptyIterator; import static org.neo4j.collection.primitive.PrimitiveLongCollections.EMPTY_LONG_ARRAY; @@ -104,7 +106,7 @@ public void process( NodeRecord node ) throws FAILURE if ( propertyKeyIdFilter.test( propertyKeyId ) ) { // This node has a property of interest to us - Object value = valueOf( property ); + Value value = valueOf( property ); Validators.INDEX_VALUE_VALIDATOR.validate( value ); updates.added( propertyKeyId, value ); hasRelevantProperty = true; @@ -123,11 +125,11 @@ private Iterable properties( final NodeRecord node ) return () -> new PropertyBlockIterator( node ); } - private Object valueOf( PropertyBlock property ) + private Value valueOf( PropertyBlock property ) { // Make sure the value is loaded, even if it's of a "heavy" kind. propertyStore.ensureHeavy( property ); - return property.getType().getValue( property, propertyStore ); + return property.getType().getValueNow( property, propertyStore ); } private static boolean containsAnyLabel( int[] labelIdFilter, long[] labels ) diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/PropertyItem.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/PropertyItem.java index 596bc046749a4..336f25faf863b 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/PropertyItem.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/PropertyItem.java @@ -19,6 +19,8 @@ */ package org.neo4j.storageengine.api; +import org.neo4j.values.Value; + /** * Property item returned from property cursors */ @@ -32,5 +34,5 @@ public interface PropertyItem /** * @return the value of the current property. */ - Object value(); + Value value(); } diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/StorageProperty.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/StorageProperty.java index 480293aa36ab5..bdbfe87252afe 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/StorageProperty.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/StorageProperty.java @@ -20,6 +20,7 @@ package org.neo4j.storageengine.api; import org.neo4j.kernel.api.exceptions.PropertyNotFoundException; +import org.neo4j.values.Value; /** * Abstraction pairing property key token id and property value. Can represent both defined and undefined @@ -37,26 +38,18 @@ public interface StorageProperty * @param other value to compare with for equality. * @return whether or not the property value is equal to the given {@code value}. */ - boolean valueEquals( Object other ); + boolean valueEquals( Value other ); /** * @return the property value. * @throws PropertyNotFoundException if this property instance represented a non-existent property. */ - Object value() throws PropertyNotFoundException; + Value value() throws PropertyNotFoundException; /** - * @param defaultValue value to return if this property has no value associated with it, instead - * of throwing exception. - * @return the property value. - */ - Object value( Object defaultValue ); - - /** - * @return the property value as, a {@link String} representation of it. - * @throws PropertyNotFoundException if this property instance represented a non-existent property. + * @return the property value or Values.NO_VALUE is this property does not exist. */ - String valueAsString() throws PropertyNotFoundException; + Value valueForced(); /** * @return whether or not the property is defined, e.g. if it exists (has a value) or not. diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java index 97f93a1588a01..93e502b760d8c 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java @@ -25,7 +25,7 @@ import org.neo4j.graphdb.Resource; import org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException; import org.neo4j.kernel.api.schema.IndexQuery; - +import org.neo4j.values.Value; /** * Reader for an index. Must honor repeatable reads, which means that if a lookup is executed multiple times the @@ -38,7 +38,7 @@ public interface IndexReader extends Resource * @param propertyValues property values to match. * @return number of index entries for the given {@code nodeId} and {@code propertyValue}. */ - long countIndexedNodes( long nodeId, Object... propertyValues ); + long countIndexedNodes( long nodeId, Value... propertyValues ); IndexSampler createSampler(); @@ -54,7 +54,7 @@ public interface IndexReader extends Resource { // Used for checking index correctness @Override - public long countIndexedNodes( long nodeId, Object... propertyValues ) + public long countIndexedNodes( long nodeId, Value... propertyValues ) { return 0; } diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/ReadableTransactionState.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/ReadableTransactionState.java index 14829542cd770..ec04a571a0b1e 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/ReadableTransactionState.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/txstate/ReadableTransactionState.java @@ -26,7 +26,6 @@ import org.neo4j.cursor.Cursor; import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException; import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.SchemaDescriptor; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptor; @@ -37,6 +36,7 @@ import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.RelationshipItem; import org.neo4j.storageengine.api.StorageProperty; +import org.neo4j.values.ValueTuple; /** * This interface contains the methods for reading transaction state from the transaction state. @@ -126,7 +126,7 @@ public interface ReadableTransactionState ReadableDiffSets indexUpdatesForScan( IndexDescriptor index ); - ReadableDiffSets indexUpdatesForSeek( IndexDescriptor index, OrderedPropertyValues values ); + ReadableDiffSets indexUpdatesForSeek( IndexDescriptor index, ValueTuple values ); ReadableDiffSets indexUpdatesForRangeSeekByNumber( IndexDescriptor index, Number lower, boolean includeLower, @@ -173,4 +173,5 @@ Cursor augmentNodeRelationshipCursor( Cursor * The same applies to schema changes, such as creating and dropping indexes and constraints. */ boolean hasDataChanges(); + } diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/BatchInserter.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/BatchInserter.java index d923bb1260ab2..ce9ac67ae2ffb 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/BatchInserter.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/BatchInserter.java @@ -25,6 +25,7 @@ import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.schema.ConstraintCreator; import org.neo4j.graphdb.schema.IndexCreator; +import org.neo4j.values.Value; /** * The batch inserter drops support for transactions and concurrency in favor @@ -161,7 +162,7 @@ void setRelationshipProperty( long relationship, * * @return map containing this node's properties. */ - Map getNodeProperties( long nodeId ); + Map getNodeProperties( long nodeId ); /** * Returns an iterable over all the relationship ids connected to node with @@ -225,7 +226,7 @@ void setRelationshipProperties( long rel, * @param relId the id of the relationship. * @return map containing the relationship's properties. */ - Map getRelationshipProperties( long relId ); + Map getRelationshipProperties( long relId ); /** * Removes the property named {@code property} from the node with id diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java index 1a34bf3eccec2..6e845a56255a3 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java @@ -66,7 +66,6 @@ import org.neo4j.kernel.api.labelscan.LabelScanStore; import org.neo4j.kernel.api.labelscan.LabelScanWriter; import org.neo4j.kernel.api.labelscan.NodeLabelUpdate; -import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.LabelSchemaSupplier; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; @@ -163,6 +162,8 @@ import org.neo4j.unsafe.batchinsert.BatchInserter; import org.neo4j.unsafe.batchinsert.BatchRelationship; import org.neo4j.unsafe.batchinsert.DirectRecordAccessSet; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.lang.Boolean.parseBoolean; import static java.util.Collections.emptyIterator; @@ -405,7 +406,7 @@ private void setPrimitiveProperty( RecordProxy propertyRecords = recordAccess.getPropertyRecords(); - propertyCreator.primitiveSetProperty( primitiveRecord, propertyKey, propertyValue, propertyRecords ); + propertyCreator.primitiveSetProperty( primitiveRecord, propertyKey, Values.of( propertyValue ), propertyRecords ); } private void validateIndexCanBeCreated( int labelId, int[] propertyKeyIds ) @@ -770,7 +771,7 @@ private Iterator propertiesIterator( Map properti protected PropertyBlock underlyingObjectToObject( Entry property ) { return propertyCreator.encodePropertyValue( - getOrCreatePropertyKeyId( property.getKey() ), property.getValue() ); + getOrCreatePropertyKeyId( property.getKey() ), Values.of( property.getValue() ) ); } }; } @@ -919,7 +920,7 @@ public boolean nodeExists( long nodeId ) } @Override - public Map getNodeProperties( long nodeId ) + public Map getNodeProperties( long nodeId ) { NodeRecord record = getNodeRecord( nodeId ).forReadingData(); if ( record.getNextProp() != Record.NO_NEXT_PROPERTY.intValue() ) @@ -967,7 +968,7 @@ public BatchRelationship getRelationshipById( long relId ) } @Override - public Map getRelationshipProperties( long relId ) + public Map getRelationshipProperties( long relId ) { RelationshipRecord record = recordAccess.getRelRecords().getOrLoad( relId, null ).forChangingData(); if ( record.getNextProp() != Record.NO_NEXT_PROPERTY.intValue() ) @@ -1024,16 +1025,14 @@ public String toString() return "EmbeddedBatchInserter[" + storeDir + "]"; } - private Map getPropertyChain( long nextProp ) + private Map getPropertyChain( long nextProp ) { - final Map map = new HashMap<>(); + final Map map = new HashMap<>(); propertyTraverser.getPropertyChain( nextProp, recordAccess.getPropertyRecords(), propBlock -> { String key = propertyKeyTokens.byId( propBlock.getKeyIndexId() ).name(); - DefinedProperty propertyData = propBlock.newPropertyData( propertyStore ); - Object value = propertyData.value() != null ? propertyData.value() : - propBlock.getType().getValue( propBlock, propertyStore ); - map.put( key, value ); + Value propertyValue = propBlock.newPropertyValue( propertyStore ); + map.put( key, propertyValue ); } ); return map; } diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/FileSystemClosingBatchInserter.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/FileSystemClosingBatchInserter.java index 3c857a484ba0a..ea0cb3a6c9433 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/FileSystemClosingBatchInserter.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/FileSystemClosingBatchInserter.java @@ -31,6 +31,7 @@ import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.unsafe.batchinsert.BatchInserter; import org.neo4j.unsafe.batchinsert.BatchRelationship; +import org.neo4j.values.Value; public class FileSystemClosingBatchInserter implements BatchInserter, IndexConfigStoreProvider { @@ -113,7 +114,7 @@ public void setRelationshipProperty( long relationship, String propertyName, Obj } @Override - public Map getNodeProperties( long nodeId ) + public Map getNodeProperties( long nodeId ) { return delegate.getNodeProperties( nodeId ); } @@ -149,7 +150,7 @@ public void setRelationshipProperties( long rel, Map properties ) } @Override - public Map getRelationshipProperties( long relId ) + public Map getRelationshipProperties( long relId ) { return delegate.getRelationshipProperties( relId ); } diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingTokenRepository.java b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingTokenRepository.java index 82c4f95cc54a3..17c2a12d336a4 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingTokenRepository.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/store/BatchingTokenRepository.java @@ -35,6 +35,8 @@ import org.neo4j.kernel.impl.transaction.state.PropertyCreator; import org.neo4j.kernel.impl.transaction.state.TokenCreator; import org.neo4j.storageengine.api.Token; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.lang.Math.max; @@ -223,7 +225,7 @@ public void propertyKeysAndValues( PropertyBlock[] target, int offset, Object[] { int key = getOrCreateId( properties[cursor++] ); Object value = properties[cursor++]; - target[offset + i] = creator.encodeValue( new PropertyBlock(), key, value ); + target[offset + i] = creator.encodeValue( new PropertyBlock(), key, Values.of( value ) ); } } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictExceptionTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictExceptionTest.java index 518b7098af6a6..e8900e620939c 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictExceptionTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/exceptions/index/IndexEntryConflictExceptionTest.java @@ -23,9 +23,11 @@ import org.neo4j.kernel.api.StatementConstants; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; import org.neo4j.kernel.api.schema.SchemaUtil; +import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; +import org.neo4j.values.Values; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -33,12 +35,13 @@ public class IndexEntryConflictExceptionTest { public static final int labelId = 1; + public static final Value value = Values.of( "hi" ); @Test public void shouldMakeEntryConflicts() { LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, 2 ); - IndexEntryConflictException e = new IndexEntryConflictException( 0L, 1L, "hi" ); + IndexEntryConflictException e = new IndexEntryConflictException( 0L, 1L, value ); assertThat( e.evidenceMessage( SchemaUtil.idTokenNameLookup, schema ), equalTo( "Both Node(0) and Node(1) have the label `label[1]` and property `property[2]` = 'hi'" ) ); @@ -48,7 +51,7 @@ public void shouldMakeEntryConflicts() public void shouldMakeEntryConflictsForOneNode() { LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, 2 ); - IndexEntryConflictException e = new IndexEntryConflictException( 0L, StatementConstants.NO_SUCH_NODE, "hi" ); + IndexEntryConflictException e = new IndexEntryConflictException( 0L, StatementConstants.NO_SUCH_NODE, value ); assertThat( e.evidenceMessage( SchemaUtil.idTokenNameLookup, schema ), equalTo( "Node(0) already exists with label `label[1]` and property `property[2]` = 'hi'" ) ); @@ -58,7 +61,7 @@ public void shouldMakeEntryConflictsForOneNode() public void shouldMakeCompositeEntryConflicts() { LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, 2, 3, 4 ); - OrderedPropertyValues values = OrderedPropertyValues.ofUndefined( true, "hi", new long[]{6L, 4L} ); + ValueTuple values = ValueTuple.of( true, "hi", new long[]{6L, 4L} ); IndexEntryConflictException e = new IndexEntryConflictException( 0L, 1L, values ); assertThat( e.evidenceMessage( SchemaUtil.idTokenNameLookup, schema ), diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java index adff48bbbd792..7192f972b4f9a 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java @@ -22,8 +22,10 @@ import org.junit.Ignore; import org.junit.Test; +import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; +import org.neo4j.values.Values; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; @@ -49,9 +51,9 @@ public CompositeIndexAccessorCompatibility( public void testIndexSeekAndScanByString() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a", "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "b", "b" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "a", "b" ) ) ); + add( 1L, descriptor.schema(), "a", "a" ), + add( 2L, descriptor.schema(), "b", "b" ), + add( 3L, descriptor.schema(), "a", "b" ) ) ); assertThat( query( exact( 0, "a" ), exact( 1, "a" ) ), equalTo( singletonList( 1L ) ) ); assertThat( query( exact( 0, "b" ), exact( 1, "b" ) ), equalTo( singletonList( 2L ) ) ); @@ -63,9 +65,9 @@ public void testIndexSeekAndScanByString() throws Exception public void testIndexSeekAndScanByNumber() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), 333, 333 ), - IndexEntryUpdate.add( 2L, descriptor.schema(), 101, 101 ), - IndexEntryUpdate.add( 3L, descriptor.schema(), 333, 101 ) ) ); + add( 1L, descriptor.schema(), 333, 333 ), + add( 2L, descriptor.schema(), 101, 101 ), + add( 3L, descriptor.schema(), 333, 101 ) ) ); assertThat( query( exact( 0, 333 ), exact( 1, 333 ) ), equalTo( singletonList( 1L ) ) ); assertThat( query( exact( 0, 101 ), exact( 1, 101 ) ), equalTo( singletonList( 2L ) ) ); @@ -86,8 +88,8 @@ public General( IndexProviderCompatibilityTestSuite testSuite ) public void testDuplicatesInIndexSeekByString() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a", "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "a", "a" ) ) ); + add( 1L, descriptor.schema(), "a", "a" ), + add( 2L, descriptor.schema(), "a", "a" ) ) ); assertThat( query( exact( 0, "a" ), exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); } @@ -96,8 +98,8 @@ public void testDuplicatesInIndexSeekByString() throws Exception public void testDuplicatesInIndexSeekByNumber() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), 333, 333 ), - IndexEntryUpdate.add( 2L, descriptor.schema(), 333, 333 ) ) ); + add( 1L, descriptor.schema(), 333, 333 ), + add( 2L, descriptor.schema(), 333, 333 ) ) ); assertThat( query( exact( 0, 333 ), exact( 1, 333 ) ), equalTo( asList( 1L, 2L ) ) ); } @@ -122,13 +124,18 @@ public void closingAnOnlineIndexUpdaterMustNotThrowEvenIfItHasBeenFedConflicting // the exact-match filtering we do on index seeks in StateHandlingStatementOperations. updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a", "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "a", "a" ) ) ); + add( 1L, descriptor.schema(), "a", "a" ), + add( 2L, descriptor.schema(), "a", "a" ) ) ); assertThat( query( exact( 0, "a" ), exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); } } + private static IndexEntryUpdate add( long nodeId, LabelSchemaDescriptor schema, Object value1, Object value2 ) + { + return IndexEntryUpdate.add( nodeId, schema, Values.of( value1 ), Values.of( value2 ) ); + } + //TODO: add when supported: //testIndexSeekByString //testIndexSeekByPrefix diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexPopulatorCompatibility.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexPopulatorCompatibility.java index 1082cb671acb2..118ff32fd0af3 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexPopulatorCompatibility.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/CompositeIndexPopulatorCompatibility.java @@ -28,17 +28,20 @@ import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.schema.IndexQuery; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; +import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; import org.neo4j.storageengine.api.schema.IndexReader; +import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.neo4j.helpers.collection.Iterators.asSet; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; @Ignore( "Not a test. This is a compatibility suite that provides test cases for verifying" + " SchemaIndexProvider implementations. Each index provider that is to be tested by this suite" + @@ -68,8 +71,8 @@ public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception IndexPopulator populator = indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ); populator.create(); populator.add( Arrays.asList( - IndexEntryUpdate.add( 1, descriptor.schema(), "v1", "v2" ), - IndexEntryUpdate.add( 2, descriptor.schema(), "v1", "v2" ) ) ); + add( 1, descriptor.schema(), "v1", "v2" ), + add( 2, descriptor.schema(), "v1", "v2" ) ) ); populator.close( true ); // then @@ -85,9 +88,9 @@ public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception public static class Unique extends CompositeIndexPopulatorCompatibility { - String value1 = "value1"; - String value2 = "value2"; - String value3 = "value3"; + Value value1 = Values.of( "value1" ); + Value value2 = Values.of( "value2" ); + Value value3 = Values.of( "value3" ); int nodeId1 = 3; int nodeId2 = 4; @@ -120,7 +123,7 @@ public void shouldEnforceUniqueConstraintsDirectly() throws Exception catch ( IndexEntryConflictException conflict ) { assertEquals( nodeId1, conflict.getExistingNodeId() ); - assertEquals( OrderedPropertyValues.ofUndefined( value1, value2 ), conflict.getPropertyValues() ); + assertEquals( ValueTuple.of( value1, value2 ), conflict.getPropertyValues() ); assertEquals( nodeId2, conflict.getAddedNodeId() ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexEntryUpdateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexEntryUpdateTest.java index 3bbbe25f99ea2..72e8d6b69dfa4 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexEntryUpdateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexEntryUpdateTest.java @@ -24,6 +24,8 @@ import org.junit.rules.ExpectedException; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -31,8 +33,8 @@ public class IndexEntryUpdateTest { - private final Object[] multiValue = new Object[]{"value", "value2"}; - private final String singleValue = "value"; + private final Value[] multiValue = new Value[]{Values.of( "value" ), Values.of( "value2" )}; + private final Value singleValue = Values.of( "value" ); @Rule public ExpectedException thrown = ExpectedException.none(); @@ -40,8 +42,8 @@ public class IndexEntryUpdateTest @Test public void indexEntryUpdatesShouldBeEqual() { - IndexEntryUpdate a = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), "hi" ); - IndexEntryUpdate b = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), "hi" ); + IndexEntryUpdate a = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue ); + IndexEntryUpdate b = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue ); assertThat( a, equalTo( b ) ); assertThat( a.hashCode(), equalTo( b.hashCode() ) ); } @@ -87,7 +89,7 @@ public void removeShouldThrowIfAskedForChanged() throws Exception public void updatesShouldEqualRegardlessOfCreationMethod() { IndexEntryUpdate singleAdd = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue ); - Object[] singleAsArray = {singleValue}; + Value[] singleAsArray = {singleValue}; IndexEntryUpdate multiAdd = IndexEntryUpdate .add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleAsArray ); IndexEntryUpdate singleRemove = IndexEntryUpdate @@ -106,10 +108,10 @@ public void updatesShouldEqualRegardlessOfCreationMethod() @Test public void changedShouldRetainValues() throws Exception { - String singleAfter = "Hello"; + Value singleAfter = Values.of( "Hello" ); IndexEntryUpdate singleChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue, singleAfter ); - Object[] multiAfter = {"Hello", "Hi"}; + Value[] multiAfter = {Values.of( "Hello" ), Values.of( "Hi" )}; IndexEntryUpdate multiChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4, 5 ), multiValue, multiAfter ); assertThat( new Object[]{singleValue}, equalTo( singleChange.beforeValues() ) ); @@ -117,21 +119,4 @@ public void changedShouldRetainValues() throws Exception assertThat( multiValue, equalTo( multiChange.beforeValues() ) ); assertThat( multiAfter, equalTo( multiChange.values() ) ); } - - @Test - public void indexEntryUpdatesShouldBeEqualForDeepValues() - { - Object value1 = arraysOfDepth( 13 ); - Object value2 = arraysOfDepth( 13 ); - - IndexEntryUpdate a = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), value1 ); - IndexEntryUpdate b = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), value2 ); - assertThat( a, equalTo( b ) ); - assertThat( a.hashCode(), equalTo( b.hashCode() ) ); - } - - private Object[] arraysOfDepth( int n ) - { - return n == 0 ? new Object[]{"hej"} : new Object[]{arraysOfDepth( n - 1 )}; - } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexQueryHelper.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexQueryHelper.java index 4666c5209853c..2acdf280178b8 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexQueryHelper.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexQueryHelper.java @@ -20,6 +20,8 @@ package org.neo4j.kernel.api.index; import org.neo4j.kernel.api.schema.IndexQuery; +import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; +import org.neo4j.values.Value; import org.neo4j.values.Values; public class IndexQueryHelper @@ -32,4 +34,38 @@ public static IndexQuery exact( int propertyKeyId, Object value ) { return IndexQuery.exact( propertyKeyId, Values.of( value ) ); } + + public static IndexEntryUpdate add( + long nodeId, LabelSchemaDescriptor schema, Object... objects ) + { + return IndexEntryUpdate.add( nodeId, schema, toValues( objects ) ); + } + + public static IndexEntryUpdate remove( + long nodeId, LabelSchemaDescriptor schema, Object... objects ) + { + return IndexEntryUpdate.remove( nodeId, schema, toValues( objects ) ); + } + + public static IndexEntryUpdate change( + long nodeId, LabelSchemaDescriptor schema, Object o1, Object o2 ) + { + return IndexEntryUpdate.change( nodeId, schema, Values.of( o1 ), Values.of( o2 ) ); + } + + public static IndexEntryUpdate change( + long nodeId, LabelSchemaDescriptor schema, Object[] o1, Object[] o2 ) + { + return IndexEntryUpdate.change( nodeId, schema, toValues( o1 ), toValues( o2 ) ); + } + + private static Value[] toValues( Object[] objects ) + { + Value[] values = new Value[objects.length]; + for ( int i = 0; i < objects.length; i++ ) + { + values[i] = Values.of( objects[i] ); + } + return values; + } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodePropertyAccessor.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodePropertyAccessor.java index 67a4baab09220..ffdcbee0a2a4e 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodePropertyAccessor.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodePropertyAccessor.java @@ -23,22 +23,23 @@ import java.util.Map; import org.neo4j.kernel.api.exceptions.EntityNotFoundException; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; +import org.neo4j.values.Value; +import org.neo4j.values.Values; public class NodePropertyAccessor implements PropertyAccessor { - private final Map> nodePropertyMap; + private final Map> nodePropertyMap; - NodePropertyAccessor( long nodeId, LabelSchemaDescriptor schema, Object... values ) + NodePropertyAccessor( long nodeId, LabelSchemaDescriptor schema, Value... values ) { nodePropertyMap = new HashMap<>(); addNode( nodeId, schema, values ); } - public void addNode( long nodeId, LabelSchemaDescriptor schema, Object... values ) + public void addNode( long nodeId, LabelSchemaDescriptor schema, Value... values ) { - Map propertyMap = new HashMap<>(); + Map propertyMap = new HashMap<>(); for ( int i = 0; i < schema.getPropertyIds().length; i++ ) { propertyMap.put( schema.getPropertyIds()[i], values[i] ); @@ -47,20 +48,20 @@ public void addNode( long nodeId, LabelSchemaDescriptor schema, Object... values } @Override - public Property getProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException + public Value getPropertyValue( long nodeId, int propertyKeyId ) throws EntityNotFoundException { if ( nodePropertyMap.containsKey( nodeId ) ) { - Object value = nodePropertyMap.get( nodeId ).get( propertyKeyId ); + Value value = nodePropertyMap.get( nodeId ).get( propertyKeyId ); if ( value == null ) { - return Property.noNodeProperty( nodeId, propertyKeyId ); + return Values.NO_VALUE; } else { - return Property.property( propertyKeyId, value ); + return value; } } - return Property.noNodeProperty( nodeId, propertyKeyId ); + return Values.NO_VALUE; } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodeUpdatesTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodeUpdatesTest.java index e61d948cbbada..632948aaa3e6b 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodeUpdatesTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/NodeUpdatesTest.java @@ -28,12 +28,14 @@ import java.util.Map; import org.neo4j.collection.primitive.PrimitiveIntIterator; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; import org.neo4j.kernel.impl.api.index.NodeUpdates; import org.neo4j.kernel.impl.api.index.PropertyLoader; +import org.neo4j.storageengine.api.StorageProperty; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -55,9 +57,9 @@ public class NodeUpdatesTest private static final LabelSchemaDescriptor index12 = SchemaDescriptorFactory.forLabel( labelId, propertyKeyId1, propertyKeyId2 ); private static final List indexes = Arrays.asList( index1, index2, index12 ); - private static final DefinedProperty property1 = Property.stringProperty( propertyKeyId1, "Neo" ); - private static final DefinedProperty property2 = Property.longProperty( propertyKeyId2, 100L ); - private static final Object[] values12 = new Object[]{property1.value(), property2.value()}; + private static final StorageProperty property1 = new PropertyKeyValue( propertyKeyId1, Values.of( "Neo" ) ); + private static final StorageProperty property2 = new PropertyKeyValue( propertyKeyId2, Values.of( 100L ) ); + private static final Value[] values12 = new Value[]{property1.valueForced(), property2.valueForced()}; @Test public void shouldNotGenerateUpdatesForEmptyNodeUpdates() @@ -74,7 +76,9 @@ public void shouldNotGenerateUpdateForMultipleExistingPropertiesAndLabels() { // When NodeUpdates updates = NodeUpdates.forNode( nodeId, labels ) - .buildWithExistingProperties( property1, property2 ); + .existing( propertyKeyId1, Values.of( "Neo" ) ) + .existing( propertyKeyId2, Values.of( 100L ) ) + .build(); // Then assertThat( updates.forIndexKeys( indexes, assertNoLoading() ), emptyIterable() ); @@ -100,7 +104,7 @@ public void shouldGenerateUpdateForLabelAdditionWithExistingProperty() assertThat( updates.forIndexKeys( indexes, propertyLoader( property1 ) ), containsInAnyOrder( - IndexEntryUpdate.add( nodeId, index1, property1.value() ) + IndexEntryUpdate.add( nodeId, index1, property1.valueForced() ) ) ); } @@ -109,14 +113,17 @@ public void shouldGenerateUpdatesForLabelAdditionWithExistingProperties() { // When NodeUpdates updates = - NodeUpdates.forNode( nodeId, empty, labels ).buildWithExistingProperties( property1, property2 ); + NodeUpdates.forNode( nodeId, empty, labels ) + .existing( propertyKeyId1, Values.of( "Neo" ) ) + .existing( propertyKeyId2, Values.of( 100L ) ) + .build(); // Then assertThat( updates.forIndexKeys( indexes, propertyLoader( property1, property2 ) ), containsInAnyOrder( - IndexEntryUpdate.add( nodeId, index1, property1.value() ), - IndexEntryUpdate.add( nodeId, index2, property2.value() ), + IndexEntryUpdate.add( nodeId, index1, property1.valueForced() ), + IndexEntryUpdate.add( nodeId, index2, property2.valueForced() ), IndexEntryUpdate.add( nodeId, index12, values12 ) ) ); } @@ -142,7 +149,7 @@ public void shouldGenerateUpdateForLabelRemovalWithExistingProperty() assertThat( updates.forIndexKeys( indexes, propertyLoader( property1 ) ), containsInAnyOrder( - IndexEntryUpdate.remove( nodeId, index1, property1.value() ) + IndexEntryUpdate.remove( nodeId, index1, property1.valueForced() ) ) ); } @@ -157,8 +164,8 @@ public void shouldGenerateUpdatesForLabelRemovalWithExistingProperties() assertThat( updates.forIndexKeys( indexes, propertyLoader( property1, property2 ) ), containsInAnyOrder( - IndexEntryUpdate.remove( nodeId, index1, property1.value() ), - IndexEntryUpdate.remove( nodeId, index2, property2.value() ), + IndexEntryUpdate.remove( nodeId, index1, property1.valueForced() ), + IndexEntryUpdate.remove( nodeId, index2, property2.valueForced() ), IndexEntryUpdate.remove( nodeId, index12, values12 ) ) ); } @@ -168,7 +175,7 @@ public void shouldNotGenerateUpdatesForPropertyAdditionWithNoLabels() { // When NodeUpdates updates = NodeUpdates.forNode( nodeId ) - .added( property1.propertyKeyId(), property1.value() ) + .added( property1.propertyKeyId(), property1.valueForced() ) .build(); // Then @@ -180,14 +187,14 @@ public void shouldGenerateUpdatesForSinglePropertyAdditionWithLabels() { // When NodeUpdates updates = NodeUpdates.forNode( nodeId, labels ) - .added( property1.propertyKeyId(), property1.value() ) + .added( property1.propertyKeyId(), property1.valueForced() ) .build(); // Then assertThat( updates.forIndexKeys( indexes, propertyLoader() ), containsInAnyOrder( - IndexEntryUpdate.add( nodeId, index1, property1.value() ) + IndexEntryUpdate.add( nodeId, index1, property1.valueForced() ) ) ); } @@ -196,16 +203,16 @@ public void shouldGenerateUpdatesForMultiplePropertyAdditionWithLabels() { // When NodeUpdates updates = NodeUpdates.forNode( nodeId, labels ) - .added( property1.propertyKeyId(), property1.value() ) - .added( property2.propertyKeyId(), property2.value() ) + .added( property1.propertyKeyId(), property1.valueForced() ) + .added( property2.propertyKeyId(), property2.valueForced() ) .build(); // Then assertThat( updates.forIndexKeys( indexes, propertyLoader( property1, property2 ) ), containsInAnyOrder( - IndexEntryUpdate.add( nodeId, index1, property1.value() ), - IndexEntryUpdate.add( nodeId, index2, property2.value() ), + IndexEntryUpdate.add( nodeId, index1, property1.valueForced() ), + IndexEntryUpdate.add( nodeId, index2, property2.valueForced() ), IndexEntryUpdate.add( nodeId, index12, values12 ) ) ); } @@ -215,8 +222,8 @@ public void shouldNotGenerateUpdatesForLabelAddAndPropertyRemove() { // When NodeUpdates updates = NodeUpdates.forNode( nodeId, empty, labels ) - .removed( property1.propertyKeyId(), property1.value() ) - .removed( property2.propertyKeyId(), property2.value() ) + .removed( property1.propertyKeyId(), property1.valueForced() ) + .removed( property2.propertyKeyId(), property2.valueForced() ) .build(); // Then @@ -228,8 +235,8 @@ public void shouldNotGenerateUpdatesForLabelRemoveAndPropertyAdd() { // When NodeUpdates updates = NodeUpdates.forNode( nodeId, labels, empty ) - .added( property1.propertyKeyId(), property1.value() ) - .added( property2.propertyKeyId(), property2.value() ) + .added( property1.propertyKeyId(), property1.valueForced() ) + .added( property2.propertyKeyId(), property2.valueForced() ) .build(); // Then @@ -253,7 +260,7 @@ public void shouldNotLoadPropertyForNoLabelsAndButPropertyAddition() { // When NodeUpdates updates = NodeUpdates.forNode( nodeId, empty ) - .added( property1.propertyKeyId(), property1.value() ) + .added( property1.propertyKeyId(), property1.valueForced() ) .build(); // Then @@ -262,12 +269,12 @@ public void shouldNotLoadPropertyForNoLabelsAndButPropertyAddition() emptyIterable() ); } - private PropertyLoader propertyLoader( DefinedProperty... properties ) + private PropertyLoader propertyLoader( StorageProperty... properties ) { - Map propertyMap = new HashMap<>( ); - for ( DefinedProperty p : properties ) + Map propertyMap = new HashMap<>( ); + for ( StorageProperty p : properties ) { - propertyMap.put( p.propertyKeyId(), p.value() ); + propertyMap.put( p.propertyKeyId(), p.valueForced() ); } return ( nodeId1, propertyIds, sink ) -> { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java index 23a73a9a574f6..f0ea456895776 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java @@ -39,6 +39,7 @@ import static org.neo4j.kernel.api.schema.IndexQuery.stringContains; import static org.neo4j.kernel.api.schema.IndexQuery.stringPrefix; import static org.neo4j.kernel.api.schema.IndexQuery.stringSuffix; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; @Ignore( "Not a test. This is a compatibility suite that provides test cases for verifying" + " SchemaIndexProvider implementations. Each index provider that is to be tested by this suite" + @@ -59,11 +60,11 @@ public SimpleIndexAccessorCompatibility( IndexProviderCompatibilityTestSuite tes public void testIndexSeekByNumber() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), -5 ), - IndexEntryUpdate.add( 2L, descriptor.schema(), 0 ), - IndexEntryUpdate.add( 3L, descriptor.schema(), 5.5 ), - IndexEntryUpdate.add( 4L, descriptor.schema(), 10.0 ), - IndexEntryUpdate.add( 5L, descriptor.schema(), 100.0 ) ) ); + add( 1L, descriptor.schema(), -5 ), + add( 2L, descriptor.schema(), 0 ), + add( 3L, descriptor.schema(), 5.5 ), + add( 4L, descriptor.schema(), 10.0 ), + add( 5L, descriptor.schema(), 100.0 ) ) ); assertThat( query( range( 1, 0, true, 10, true ) ), equalTo( asList( 2L, 3L, 4L ) ) ); assertThat( query( range( 1, 10, true, null, true ) ), equalTo( asList( 4L, 5L ) ) ); @@ -78,11 +79,11 @@ public void testIndexSeekByNumber() throws Exception public void testIndexSeekByString() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "Anabelle" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "Anna" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "Bob" ), - IndexEntryUpdate.add( 4L, descriptor.schema(), "Harriet" ), - IndexEntryUpdate.add( 5L, descriptor.schema(), "William" ) ) ); + add( 1L, descriptor.schema(), "Anabelle" ), + add( 2L, descriptor.schema(), "Anna" ), + add( 3L, descriptor.schema(), "Bob" ), + add( 4L, descriptor.schema(), "Harriet" ), + add( 5L, descriptor.schema(), "William" ) ) ); assertThat( query( range( 1, "Anna", true, "Harriet", false ) ), equalTo( asList( 2L, 3L ) ) ); assertThat( query( range( 1, "Harriet", true, null, false ) ), equalTo( asList( 4L, 5L ) ) ); @@ -99,11 +100,11 @@ public void testIndexSeekByString() throws Exception public void testIndexSeekByPrefix() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "A" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "apa" ), - IndexEntryUpdate.add( 4L, descriptor.schema(), "apA" ), - IndexEntryUpdate.add( 5L, descriptor.schema(), "b" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "A" ), + add( 3L, descriptor.schema(), "apa" ), + add( 4L, descriptor.schema(), "apA" ), + add( 5L, descriptor.schema(), "b" ) ) ); assertThat( query( IndexQuery.stringPrefix( 1, "a" ) ), equalTo( asList( 1L, 3L, 4L ) ) ); assertThat( query( IndexQuery.stringPrefix( 1, "A" ) ), equalTo( Collections.singletonList( 2L ) ) ); @@ -115,8 +116,8 @@ public void testIndexSeekByPrefix() throws Exception public void testIndexSeekByPrefixOnNonStrings() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), 2L ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), 2L ) ) ); assertThat( query( IndexQuery.stringPrefix( 1, "2" ) ), equalTo( EMPTY_LIST ) ); } @@ -139,8 +140,8 @@ public void closingAnOnlineIndexUpdaterMustNotThrowEvenIfItHasBeenFedConflicting // the exact-match filtering we do on index seeks in StateHandlingStatementOperations. updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "a" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "a" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); } @@ -149,9 +150,9 @@ public void closingAnOnlineIndexUpdaterMustNotThrowEvenIfItHasBeenFedConflicting public void testIndexSeekAndScan() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "b" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "a" ), + add( 3L, descriptor.schema(), "b" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); assertThat( query( exists( 1 ) ), equalTo( asList( 1L, 2L, 3L ) ) ); @@ -161,11 +162,11 @@ public void testIndexSeekAndScan() throws Exception public void testIndexRangeSeekByNumberWithDuplicates() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), -5 ), - IndexEntryUpdate.add( 2L, descriptor.schema(), -5 ), - IndexEntryUpdate.add( 3L, descriptor.schema(), 0 ), - IndexEntryUpdate.add( 4L, descriptor.schema(), 5 ), - IndexEntryUpdate.add( 5L, descriptor.schema(), 5 ) ) ); + add( 1L, descriptor.schema(), -5 ), + add( 2L, descriptor.schema(), -5 ), + add( 3L, descriptor.schema(), 0 ), + add( 4L, descriptor.schema(), 5 ), + add( 5L, descriptor.schema(), 5 ) ) ); assertThat( query( range( 1, -5, true, 5, true ) ), equalTo( asList( 1L, 2L, 3L, 4L, 5L ) ) ); assertThat( query( range( 1, -3, true, -1, true ) ), equalTo( EMPTY_LIST ) ); @@ -178,11 +179,11 @@ public void testIndexRangeSeekByNumberWithDuplicates() throws Exception public void testIndexRangeSeekByStringWithDuplicates() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "Anna" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "Anna" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "Bob" ), - IndexEntryUpdate.add( 4L, descriptor.schema(), "William" ), - IndexEntryUpdate.add( 5L, descriptor.schema(), "William" ) ) ); + add( 1L, descriptor.schema(), "Anna" ), + add( 2L, descriptor.schema(), "Anna" ), + add( 3L, descriptor.schema(), "Bob" ), + add( 4L, descriptor.schema(), "William" ), + add( 5L, descriptor.schema(), "William" ) ) ); assertThat( query( range( 1, "Anna", false, "William", false ) ), equalTo( singletonList( 3L ) ) ); assertThat( query( range( 1, "Arabella", false, "Bob", false ) ), equalTo( EMPTY_LIST ) ); @@ -195,11 +196,11 @@ public void testIndexRangeSeekByStringWithDuplicates() throws Exception public void testIndexRangeSeekByPrefixWithDuplicates() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "A" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "apa" ), - IndexEntryUpdate.add( 4L, descriptor.schema(), "apa" ), - IndexEntryUpdate.add( 5L, descriptor.schema(), "apa" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "A" ), + add( 3L, descriptor.schema(), "apa" ), + add( 4L, descriptor.schema(), "apa" ), + add( 5L, descriptor.schema(), "apa" ) ) ); assertThat( query( stringPrefix( 1, "a" ) ), equalTo( asList( 1L, 3L, 4L, 5L ) ) ); assertThat( query( stringPrefix( 1, "apa" ) ), equalTo( asList( 3L, 4L, 5L ) ) ); @@ -209,11 +210,11 @@ public void testIndexRangeSeekByPrefixWithDuplicates() throws Exception public void testIndexFullSearchWithDuplicates() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "A" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "apa" ), - IndexEntryUpdate.add( 4L, descriptor.schema(), "apa" ), - IndexEntryUpdate.add( 5L, descriptor.schema(), "apalong" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "A" ), + add( 3L, descriptor.schema(), "apa" ), + add( 4L, descriptor.schema(), "apa" ), + add( 5L, descriptor.schema(), "apalong" ) ) ); assertThat( query( stringContains( 1, "a" ) ), equalTo( asList( 1L, 3L, 4L, 5L ) ) ); assertThat( query( stringContains( 1, "apa" ) ), equalTo( asList( 3L, 4L, 5L ) ) ); @@ -224,12 +225,12 @@ public void testIndexFullSearchWithDuplicates() throws Exception public void testIndexEndsWithWithDuplicated() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "A" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "apa" ), - IndexEntryUpdate.add( 4L, descriptor.schema(), "apa" ), - IndexEntryUpdate.add( 5L, descriptor.schema(), "longapa" ), - IndexEntryUpdate.add( 6L, descriptor.schema(), "apalong" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "A" ), + add( 3L, descriptor.schema(), "apa" ), + add( 4L, descriptor.schema(), "apa" ), + add( 5L, descriptor.schema(), "longapa" ), + add( 6L, descriptor.schema(), "apalong" ) ) ); assertThat( query( stringSuffix( 1, "a" ) ), equalTo( asList( 1L, 3L, 4L, 5L ) ) ); assertThat( query( stringSuffix( 1, "apa" ) ), equalTo( asList( 3L, 4L, 5L ) ) ); @@ -257,8 +258,8 @@ public void closingAnOnlineIndexUpdaterMustNotThrowEvenIfItHasBeenFedConflicting // the exact-match filtering we do on index seeks in StateHandlingStatementOperations. updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "a" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "a" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); } @@ -267,9 +268,9 @@ public void closingAnOnlineIndexUpdaterMustNotThrowEvenIfItHasBeenFedConflicting public void testIndexSeekAndScan() throws Exception { updateAndCommit( asList( - IndexEntryUpdate.add( 1L, descriptor.schema(), "a" ), - IndexEntryUpdate.add( 2L, descriptor.schema(), "b" ), - IndexEntryUpdate.add( 3L, descriptor.schema(), "c" ) ) ); + add( 1L, descriptor.schema(), "a" ), + add( 2L, descriptor.schema(), "b" ), + add( 3L, descriptor.schema(), "c" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( asList( 1L ) ) ); assertThat( query( IndexQuery.exists( 1 ) ), equalTo( asList( 1L, 2L, 3L ) ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java index d931e3aefc8aa..24793aba6ab63 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/SimpleIndexPopulatorCompatibility.java @@ -27,14 +27,15 @@ import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.api.schema.IndexQuery; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; import org.neo4j.storageengine.api.schema.IndexReader; +import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; +import org.neo4j.values.Values; import static java.util.Collections.singletonList; import static org.junit.Assert.assertEquals; @@ -111,9 +112,9 @@ public void shouldApplyUpdatesIdempotently() throws Exception populator.create(); populator.configureSampling( true ); long nodeId = 1; - final String propertyValue = "value1"; + final Value propertyValue = Values.of( "value1" ); PropertyAccessor propertyAccessor = - ( nodeId1, propertyKeyId ) -> Property.stringProperty( propertyKeyId, propertyValue ); + ( nodeId1, propertyKeyId ) -> propertyValue; // this update (using add())... populator.add( singletonList( IndexEntryUpdate.add( nodeId, descriptor.schema(), propertyValue ) ) ); @@ -150,15 +151,17 @@ public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.empty() ); IndexPopulator populator = indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ); populator.create(); - populator.add( Arrays.asList( IndexEntryUpdate.add( 1, descriptor.schema(), "value1" ), - IndexEntryUpdate.add( 2, descriptor.schema(), "value1" ) ) ); + Value value = Values.of( "value1" ); + populator.add( Arrays.asList( + IndexEntryUpdate.add( 1, descriptor.schema(), value ), + IndexEntryUpdate.add( 2, descriptor.schema(), value ) ) ); populator.close( true ); // then IndexAccessor accessor = indexProvider.getOnlineAccessor( 17, descriptor, indexSamplingConfig ); try ( IndexReader reader = accessor.newReader() ) { - PrimitiveLongIterator nodes = reader.query( IndexQuery.exact( 1, "value1" ) ); + PrimitiveLongIterator nodes = reader.query( IndexQuery.exact( 1, value ) ); assertEquals( asSet( 1L, 2L ), PrimitiveLongCollections.toSet( nodes ) ); } accessor.close(); @@ -179,7 +182,7 @@ public Unique( IndexProviderCompatibilityTestSuite testSuite ) public void shouldProvidePopulatorThatEnforcesUniqueConstraints() throws Exception { // when - String value = "value1"; + Value value = Values.of( "value1" ); int nodeId1 = 1; int nodeId2 = 2; @@ -187,7 +190,8 @@ public void shouldProvidePopulatorThatEnforcesUniqueConstraints() throws Excepti IndexPopulator populator = indexProvider.getPopulator( 17, descriptor, indexSamplingConfig ); populator.create(); - populator.add( Arrays.asList( IndexEntryUpdate.add( nodeId1, descriptor.schema(), value ), + populator.add( Arrays.asList( + IndexEntryUpdate.add( nodeId1, descriptor.schema(), value ), IndexEntryUpdate.add( nodeId2, descriptor.schema(), value ) ) ); try { @@ -202,7 +206,7 @@ public void shouldProvidePopulatorThatEnforcesUniqueConstraints() throws Excepti catch ( IndexEntryConflictException conflict ) { assertEquals( nodeId1, conflict.getExistingNodeId() ); - assertEquals( OrderedPropertyValues.ofUndefined( value ), conflict.getPropertyValues() ); + assertEquals( ValueTuple.of( value ), conflict.getPropertyValues() ); assertEquals( nodeId2, conflict.getAddedNodeId() ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/DefinedPropertyTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/properties/DefinedPropertyTest.java deleted file mode 100644 index d915b6d136b0c..0000000000000 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/DefinedPropertyTest.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import org.junit.Test; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; -import static org.neo4j.kernel.api.properties.Property.doubleProperty; -import static org.neo4j.kernel.api.properties.Property.intProperty; -import static org.neo4j.kernel.api.properties.Property.lazyStringProperty; -import static org.neo4j.kernel.api.properties.Property.stringProperty; - -public class DefinedPropertyTest -{ - @Test - public void shouldSortStringPropertiesWithSameValueByPropertyKeyId() - { - DefinedProperty p1 = stringProperty( 1, "x" ); - DefinedProperty p2 = stringProperty( 2, "x" ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortStringPropertiesWithDifferentValueByPropertyKeyId() - { - DefinedProperty p1 = stringProperty( 1, "x" ); - DefinedProperty p2 = stringProperty( 2, "y" ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortStringPropertiesWithSamePropertyKeyIdByValue() - { - DefinedProperty p1 = stringProperty( 1, "x" ); - DefinedProperty p2 = stringProperty( 1, "y" ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortIntPropertiesWithSameValueByPropertyKeyId() - { - DefinedProperty p1 = intProperty( 1, 10 ); - DefinedProperty p2 = intProperty( 2, 10 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortIntPropertiesWithDifferentValueByPropertyKeyId() - { - DefinedProperty p1 = intProperty( 1, 10 ); - DefinedProperty p2 = intProperty( 2, 20 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortIntPropertiesWithSamePropertyKeyIdByValue() - { - DefinedProperty p1 = intProperty( 1, 10 ); - DefinedProperty p2 = intProperty( 1, 20 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortDoublePropertiesWithSameValueByPropertyKeyId() - { - DefinedProperty p1 = doubleProperty( 1, 10 ); - DefinedProperty p2 = doubleProperty( 2, 10 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortDoublePropertiesWithDifferentValueByPropertyKeyId() - { - DefinedProperty p1 = doubleProperty( 1, 10 ); - DefinedProperty p2 = doubleProperty( 2, 20 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortDoublePropertiesWithSamePropertyKeyIdByValue() - { - DefinedProperty p1 = doubleProperty( 1, 10 ); - DefinedProperty p2 = doubleProperty( 1, 20 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortIntAndDoublePropertiesWithSamePropertyKeyIdByValue() - { - DefinedProperty p1 = intProperty( 1, 10 ); - DefinedProperty p2 = doubleProperty( 1, 20 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldSortDoubleAndStringPropertiesWithSamePropertyKeyIdByValue() - { - DefinedProperty p1 = doubleProperty( 1, 10 ); - DefinedProperty p2 = stringProperty( 1, "20" ); - - assertThat( compare( p1, p2 ), greaterThan( 0 ) ); - } - - @Test - public void shouldSortStringAndIntPropertiesWithSamePropertyKeyIdByValue() - { - DefinedProperty p1 = stringProperty( 1, "10" ); - DefinedProperty p2 = intProperty( 1, 20 ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - @Test - public void shouldFindIntAndDoubleEqualForPropertiesWithSamePropertyKeyIdAndValue() - { - DefinedProperty p1 = intProperty( 1, 10 ); - DefinedProperty p2 = doubleProperty( 1, 10 ); - - assertThat( compare( p1, p2 ), equalTo( 0 ) ); - } - - @Test - public void shouldSortLazyStringAndNonLazyStringPropertiesByValue() - { - DefinedProperty p1 = lazyStringProperty( 1, () -> "x" ); - DefinedProperty p2 = stringProperty( 1, "y" ); - - assertThat( compare( p1, p2 ), lessThan( 0 ) ); - } - - private int compare( DefinedProperty leftProperty, DefinedProperty rightProperty ) - { - int leftComparison = DefinedProperty.COMPARATOR.compare( leftProperty, rightProperty ); - int rightComparison = DefinedProperty.COMPARATOR.compare( rightProperty, leftProperty ); - assertThat( sign( leftComparison ), equalTo( -sign( rightComparison ) ) ); - return leftComparison; - } - - private int sign( int value ) - { - return value == 0 ? 0 : ( value < 0 ? -1 : + 1 ); - } -} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/LazyPropertyTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/properties/LazyPropertyTest.java deleted file mode 100644 index 535a43bd51a77..0000000000000 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/LazyPropertyTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import org.junit.Test; - -import java.util.concurrent.Callable; - -import org.neo4j.helpers.ArrayUtil; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class LazyPropertyTest -{ - - @Test - public void shouldLoadLazyStringProperty() throws Exception - { - // given - LazyStringProperty property = new LazyStringProperty( 0, value( "person" ) ); - // when / then - assertEquals( "person", property.value() ); - } - - @Test - public void shouldLoadLazyStringPropertyOnlyOnce() throws Exception - { - // given - LazyStringProperty property = new LazyStringProperty( 0, value( "person" ) ); - // when / then - assertEquals( "person", property.value() ); - assertEquals( "person", property.value() ); - } - - @Test - public void shouldExhibitCorrectEqualityForBooleanArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new boolean[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForByteArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new byte[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForShortArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new short[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForCharArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new char[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForIntArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new int[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForLongArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new long[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForFloatArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new float[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForDoubleArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new double[]{} ); - } - - @Test - public void shouldExhibitCorrectEqualityForStringArray() throws Exception - { - verifyCorrectValueEqualityForLazyArrayProperty( new String[]{} ); - } - - public static final Object[] ENPTY_ARRAYS = new Object[]{ - new boolean[]{}, new char[]{}, new String[]{}, new float[]{}, new double[]{}, - new byte[]{}, new short[]{}, new int[]{}, new long[]{},}; - - private static void verifyCorrectValueEqualityForLazyArrayProperty( Object array ) - { - // given - LazyArrayProperty property = new LazyArrayProperty( 0, value( ArrayUtil.clone( array ) ) ); - // when/then - assertTrue( "value should be reported equal with same type", property.valueEquals( array ) ); - // when - for ( Object value : ENPTY_ARRAYS ) - { - if ( coercible( value.getClass(), array.getClass() ) ) - { - continue; - } - // then - assertFalse( "value should be reported inequal with different type", property.valueEquals( value ) ); - } - } - - private static boolean coercible( Class lhs, Class rhs ) - { - if ( lhs == rhs ) - { - return true; - } - if ( lhs.isArray() && rhs.isArray() ) - { - return coercible( lhs.getComponentType(), rhs.getComponentType() ); - } - if ( lhs.isArray() || rhs.isArray() ) - { - return false; - } - switch ( lhs.getName() ) - { - case "boolean": - return rhs == boolean.class; - case "char": - case "java.lang.String": - return rhs == char.class || rhs == String.class; - case "float": - case "double": - case "byte": - case "short": - case "int": - case "long": - return rhs == float.class || - rhs == double.class || - rhs == byte.class || - rhs == short.class || - rhs == int.class || - rhs == long.class; - default: - return false; - } - } - - private static Callable value( final T value ) - { - return new Callable() - { - boolean called; - - @Override - public T call() throws Exception - { - assertFalse( "Already called for value: " + value, called ); - called = true; - return value; - } - }; - } -} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyConversionTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyConversionTest.java deleted file mode 100644 index 55497db729108..0000000000000 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyConversionTest.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import org.junit.BeforeClass; -import org.junit.Test; - -import java.lang.reflect.Array; -import java.util.Random; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class PropertyConversionTest -{ - private static Random random; - - @Test - public void shouldConvertStringProperty() throws Exception - { - assertConverts( "a value" ); - } - - @Test - @SuppressWarnings( "UnnecessaryBoxing" ) - public void shouldConvertSmallLongProperty() throws Exception - { - assertConverts( Long.valueOf( 1 + random.nextInt( 1024 ) ) ); - } - - @Test - public void shouldConvertBigLongProperty() throws Exception - { - assertConverts( (1L + random.nextInt( 1024 )) << 32 ); - } - - @Test - public void shouldConvertIntegerProperty() throws Exception - { - assertConverts( 1 + random.nextInt( 1024 ) ); - } - - @Test - public void shouldConvertCharProperty() throws Exception - { - assertConverts( randomChar() ); - } - - @Test - public void shouldConvertShortProperty() throws Exception - { - assertConverts( randomShort() ); - } - - @Test - public void shouldConvertByteProperty() throws Exception - { - assertConverts( randomByte() ); - } - - @Test - public void shouldConvertBooleanProperty() throws Exception - { - assertConverts( random.nextBoolean() ); - } - - @Test - public void shouldConvertFloatProperty() throws Exception - { - assertConverts( 1f + random.nextFloat() ); - } - - @Test - public void shouldConvertDoubleProperty() throws Exception - { - assertConverts( 1.0 + random.nextDouble() ); - } - - // Arrays - - @Test - public void shouldConvertStringArrayProperty() throws Exception - { - assertConverts( new String[]{"foo", "bar", "baz"} ); - } - - @Test - public void shouldNotSupportNullInArrays() throws Exception - { - // given - for ( Object[] array : new Object[][]{new String[]{null}, - new Byte[]{null}, - new Long[]{null}, - new Integer[]{null}, - new Double[]{null}, - new Float[]{null}, - new Boolean[]{null}, - new Character[]{null}, - new Short[]{null}} ) - { - // when - try - { - PropertyConversion.convertProperty( 17, array ); - fail( "Should not support nulls in " + array.getClass() ); - } - // then - catch ( IllegalArgumentException e ) - { - assertEquals( "Property array value elements may not be null.", e.getMessage() ); - } - } - } - - @Test - public void shouldConvertLongArrayProperty() throws Exception - { - assertConverts( new long[]{random.nextLong(), random.nextLong(), random.nextLong()} ); - assertConverts( new Long[]{random.nextLong(), random.nextLong(), random.nextLong()} ); - } - - @Test - public void shouldConvertIntegerArrayProperty() throws Exception - { - assertConverts( new int[]{random.nextInt(), random.nextInt(), random.nextInt()} ); - assertConverts( new Integer[]{random.nextInt(), random.nextInt(), random.nextInt()} ); - } - - @Test - public void shouldConvertCharArrayProperty() throws Exception - { - assertConverts( new char[]{randomChar(), randomChar(), randomChar()} ); - assertConverts( new Character[]{randomChar(), randomChar(), randomChar()} ); - } - - @Test - public void shouldConvertShortArrayProperty() throws Exception - { - assertConverts( new short[]{randomShort(), randomShort(), randomShort()} ); - assertConverts( new Short[]{randomShort(), randomShort(), randomShort()} ); - } - - @Test - public void shouldConvertByteArrayProperty() throws Exception - { - assertConverts( new byte[]{randomByte(), randomByte(), randomByte()} ); - assertConverts( new Byte[]{randomByte(), randomByte(), randomByte()} ); - } - - @Test - public void shouldConvertBooleanArrayProperty() throws Exception - { - assertConverts( new boolean[]{random.nextBoolean(), random.nextBoolean(), random.nextBoolean()} ); - assertConverts( new Boolean[]{random.nextBoolean(), random.nextBoolean(), random.nextBoolean()} ); - } - - @Test - public void shouldConvertFloatArrayProperty() throws Exception - { - assertConverts( new float[]{random.nextFloat(), random.nextFloat(), random.nextFloat()} ); - assertConverts( new Float[]{random.nextFloat(), random.nextFloat(), random.nextFloat()} ); - } - - @Test - public void shouldConvertDoubleArrayProperty() throws Exception - { - assertConverts( new double[]{random.nextDouble(), random.nextDouble(), random.nextDouble()} ); - assertConverts( new Double[]{random.nextDouble(), random.nextDouble(), random.nextDouble()} ); - } - - private static char randomChar() - { - return (char) (1 + random.nextInt( Character.MAX_VALUE - 1 )); - } - - private static short randomShort() - { - return (short) (1 + random.nextInt( Short.MAX_VALUE - 1 )); - } - - private static byte randomByte() - { - return (byte) (1 + random.nextInt( Byte.MAX_VALUE - 1 )); - } - - @BeforeClass - public static void randomize() - { - random = new Random(); - } - - private static void assertConverts( Object value ) - { - DefinedProperty property = PropertyConversion.convertProperty( 17, value ); - assertDeepEquals( value, property.value() ); - assertTrue( "valueEquals:" + value.getClass(), property.valueEquals( value ) ); - assertTrue( "two conversions are equal", property.equals( PropertyConversion.convertProperty( 17, value ) ) ); - assertEquals( "hashCode()", property.hashCode(), PropertyConversion.convertProperty( 17, value ).hashCode() ); - assertFalse( "properties with different keys should not be equal", - property.equals( PropertyConversion.convertProperty( 666, value ) ) ); - // this needs to be last, because another() will mutate arrays in place for extra nastyness - assertFalse( "properties with different values should not be equal", - property.equals( PropertyConversion.convertProperty( 17, another( value ) ) ) ); - } - - private static void assertDeepEquals( Object expected, Object actual ) - { - if ( expected.getClass().isArray() ) - { - assertNotNull( actual ); - assertTrue( "is array", actual.getClass().isArray() ); - int length = Array.getLength( expected ); - if ( expected instanceof Object[] ) - { - if ( expected instanceof String[] ) - { - assertEquals( expected.getClass(), actual.getClass() ); - } - else - { - assertTrue( "can only compare boxed arrays of non-zero length", length > 0 ); - } - } - else - { - assertEquals( "component type", expected.getClass(), actual.getClass() ); - } - assertEquals( "array length", length, Array.getLength( actual ) ); - for ( int i = 0; i < length; i++ ) - { - assertEquals( Array.get( expected, i ), Array.get( actual, i ) ); - } - } - else - { - assertEquals( expected, actual ); - } - } - - private static Object another( Object value ) - { - if ( value instanceof Long ) - { - return -((Long) value); - } - if ( value instanceof Integer ) - { - return -((Integer) value); - } - if ( value instanceof Short ) - { - return (short) -((Short) value); - } - if ( value instanceof Byte ) - { - return (byte) -((Byte) value); - } - if ( value instanceof Character ) - { - return (char) -((Character) value); - } - if ( value instanceof Boolean ) - { - return !(Boolean) value; - } - if ( value instanceof Float ) - { - return -(Float) value; - } - if ( value instanceof Double ) - { - return -(Double) value; - } - if ( value instanceof String ) - { - return "not " + value; - } - if ( value.getClass().isArray() ) - { - for ( int i = 0, len = Array.getLength( value ); i < len; i++ ) - { - Array.set( value, i, another( Array.get( value, i ) ) ); - } - return value; - } - throw new AssertionError( "unexpected type: " + value.getClass().getName() ); - } -} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyEqualityTest.java b/community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyEqualityTest.java deleted file mode 100644 index 699ff04f2d706..0000000000000 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/properties/PropertyEqualityTest.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.api.properties; - -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.lang.reflect.Array; -import java.util.Arrays; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.neo4j.helpers.collection.Iterables.asIterable; - -@RunWith( value = Parameterized.class ) -public class PropertyEqualityTest -{ - @Parameterized.Parameters( name = "{0}" ) - public static Iterable data() - { - return asIterable( - // boolean properties - shouldMatch( true, true ), - shouldMatch( false, false ), - shouldNotMatch( true, false ), - shouldNotMatch( false, true ), - shouldNotMatch( true, 0 ), - shouldNotMatch( false, 0 ), - shouldNotMatch( true, 1 ), - shouldNotMatch( false, 1 ), - shouldNotMatch( false, "false" ), - shouldNotMatch( true, "true" ), - - //byte properties - shouldMatch( (byte) 42, (byte) 42 ), - shouldMatch( (byte) 42, (short) 42 ), - shouldNotMatch( (byte) 42, 42 + 256 ), - shouldMatch( (byte) 43, 43 ), - shouldMatch( (byte) 43, (long) 43 ), - shouldMatch( (byte) 23, 23.0d ), - shouldMatch( (byte) 23, 23.0f ), - shouldNotMatch( (byte) 23, 23.5 ), - shouldNotMatch( (byte) 23, 23.5f ), - - //short properties - shouldMatch( (short) 11, (byte) 11 ), - shouldMatch( (short) 42, (short) 42 ), - shouldNotMatch( (short) 42, 42 + 65536 ), - shouldMatch( (short) 43, 43 ), - shouldMatch( (short) 43, (long) 43 ), - shouldMatch( (short) 23, 23.0f ), - shouldMatch( (short) 23, 23.0d ), - shouldNotMatch( (short) 23, 23.5 ), - shouldNotMatch( (short) 23, 23.5f ), - - //int properties - shouldMatch( 11, (byte) 11 ), - shouldMatch( 42, (short) 42 ), - shouldNotMatch( 42, 42 + 4294967296L ), - shouldMatch( 43, 43 ), - shouldMatch( Integer.MAX_VALUE, Integer.MAX_VALUE ), - shouldMatch( 43, (long) 43 ), - shouldMatch( 23, 23.0 ), - shouldNotMatch( 23, 23.5 ), - shouldNotMatch( 23, 23.5f ), - - //long properties - shouldMatch( 11L, (byte) 11 ), - shouldMatch( 42L, (short) 42 ), - shouldMatch( 43L, 43 ), - shouldMatch( 43L, (long) 43 ), - shouldMatch( 87L, (long) 87 ), - shouldMatch( Long.MAX_VALUE, Long.MAX_VALUE ), - shouldMatch( 23L, 23.0 ), - shouldNotMatch( 23L, 23.5 ), - shouldNotMatch( 23L, 23.5f ), - shouldMatch(9007199254740992L, 9007199254740992D), - // shouldMatch(9007199254740993L, 9007199254740992D), // is stupid, m'kay?! - - // floats goddamnit - shouldMatch( 11f, (byte) 11 ), - shouldMatch( 42f, (short) 42 ), - shouldMatch( 43f, 43 ), - shouldMatch( 43f, (long) 43 ), - shouldMatch( 23f, 23.0 ), - shouldNotMatch( 23f, 23.5 ), - shouldNotMatch( 23f, 23.5f ), - shouldMatch( 3.14f, 3.14f ), - shouldNotMatch( 3.14f, 3.14d ), // Would be nice if they matched, but they don't - - // doubles - shouldMatch( 11d, (byte) 11 ), - shouldMatch( 42d, (short) 42 ), - shouldMatch( 43d, 43 ), - shouldMatch( 43d, (long) 43 ), - shouldMatch( 23d, 23.0 ), - shouldNotMatch( 23d, 23.5 ), - shouldNotMatch( 23d, 23.5f ), - shouldNotMatch( 3.14d, 3.14f ), // this really is sheeeet - shouldMatch( 3.14d, 3.14d ), - - // strings - shouldMatch( "A", "A" ), - shouldMatch( 'A', 'A' ), - shouldMatch( 'A', "A" ), - shouldMatch( "A", 'A' ), - shouldNotMatch( "AA", 'A' ), - shouldNotMatch( "a", "A" ), - shouldNotMatch( "A", "a" ), - shouldNotMatch( "0", 0 ), - shouldNotMatch( '0', 0 ), - - // arrays - shouldMatch( new int[]{1, 2, 3}, new int[]{1, 2, 3} ), - shouldMatch( new int[]{1, 2, 3}, new long[]{1, 2, 3} ), - shouldMatch( new int[]{1, 2, 3}, new double[]{1.0, 2.0, 3.0} ), - shouldMatch( new String[]{"A", "B", "C"}, new String[]{"A", "B", "C"} ), - shouldMatch( new String[]{"A", "B", "C"}, new char[]{'A', 'B', 'C'} ), - shouldMatch( new char[]{'A', 'B', 'C'}, new String[]{"A", "B", "C"} ) - ); - } - - private Test currentTest; - - public PropertyEqualityTest( Test currentTest ) - { - this.currentTest = currentTest; - } - - @org.junit.Test - public void runTest() - { - currentTest.checkAssertion(); - } - - public static Test shouldMatch( boolean propertyValue, Object value ) - { - return new Test( new BooleanProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( boolean propertyValue, Object value ) - { - return new Test( new BooleanProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( byte propertyValue, Object value ) - { - return new Test( new ByteProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( byte propertyValue, Object value ) - { - return new Test( new ByteProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( short propertyValue, Object value ) - { - return new Test( new ShortProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( short propertyValue, Object value ) - { - return new Test( new ShortProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( float propertyValue, Object value ) - { - return new Test( new FloatProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( float propertyValue, Object value ) - { - return new Test( new FloatProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( long propertyValue, Object value ) - { - return new Test( new LongProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( long propertyValue, Object value ) - { - return new Test( new LongProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( double propertyValue, Object value ) - { - return new Test( new DoubleProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( double propertyValue, Object value ) - { - return new Test( new DoubleProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( String propertyValue, Object value ) - { - return new Test( new StringProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( String propertyValue, Object value ) - { - return new Test( new StringProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( char propertyValue, Object value ) - { - return new Test( new CharProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( char propertyValue, Object value ) - { - return new Test( new CharProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( int[] propertyValue, Object value ) - { - return new Test( new IntArrayProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( int[] propertyValue, Object value ) - { - return new Test( new IntArrayProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( char[] propertyValue, Object value ) - { - return new Test( new CharArrayProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( char[] propertyValue, Object value ) - { - return new Test( new CharArrayProperty( 0, propertyValue ), value, false ); - } - - public static Test shouldMatch( String[] propertyValue, Object value ) - { - return new Test( new StringArrayProperty( 0, propertyValue ), value, true ); - } - - public static Test shouldNotMatch( String[] propertyValue, Object value ) - { - return new Test( new StringArrayProperty( 0, propertyValue ), value, false ); - } - - private static class Test - { - final DefinedProperty property; - final Object value; - final boolean shouldMatch; - - private Test( DefinedProperty property, Object value, boolean shouldMatch ) - { - this.property = property; - this.value = value; - this.shouldMatch = shouldMatch; - } - - @Override - public String toString() - { - return String.format( "%s (%s) %s %s (%s)", - property.value(), property.value().getClass().getSimpleName(), shouldMatch ? "==" : "!=", value, - value.getClass().getSimpleName() ); - } - - void checkAssertion() - { - if ( shouldMatch ) - { - assertEquality( property, value ); - } - else - { - assertNonEquality( property, value ); - } - } - - void assertEquality( Property property, Object value ) - { - assertTrue( String.format( "Expected the value %s to be equal to %s but it wasn't.", - getValueRepresentation( value ), property.toString() ), property.valueEquals( value ) ); - } - - private String getValueRepresentation( Object value ) - { - String className = value.getClass().getSimpleName(); - - String valueRepresentation; - - if ( value.getClass().isArray() ) - { - if ( value instanceof Object[] ) - { - valueRepresentation = Arrays.toString( (Object[]) value ); - } - else - { - int length = Array.getLength( value ); - Object[] objArr = new Object[length]; - for ( int i = 0; i < length; i++ ) - { - objArr[i] = Array.get( value, i ); - } - valueRepresentation = Arrays.toString( objArr ); - } - } - else - { - valueRepresentation = value.toString(); - } - return valueRepresentation + " of type " + className; - } - - void assertNonEquality( Property property, Object value ) - { - assertFalse( String.format( "Expected the value %s to not be equal to %s but it was.", - getValueRepresentation( value ), property.toString() ), property.valueEquals( value ) ); - } - } -} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java index 9385712ebff27..24c935acd4314 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java @@ -31,8 +31,6 @@ import org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException; import org.neo4j.kernel.api.exceptions.KernelException; import org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException; -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.SchemaDescriptorFactory; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java index c7fdf22ff2122..d198ee7e46b2c 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java @@ -52,6 +52,7 @@ import org.neo4j.kernel.impl.api.index.IndexingService; import org.neo4j.kernel.impl.api.state.ConstraintIndexCreator; import org.neo4j.kernel.impl.locking.ResourceTypes; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -124,7 +125,7 @@ public void shouldDropIndexIfPopulationFails() throws Exception .thenReturn( 2468L ); IndexProxy indexProxy = mock( IndexProxy.class ); when( indexingService.getIndexProxy( 2468L ) ).thenReturn( indexProxy ); - IndexEntryConflictException cause = new IndexEntryConflictException( 2, 1, "a" ); + IndexEntryConflictException cause = new IndexEntryConflictException( 2, 1, Values.of( "a" ) ); doThrow( new IndexPopulationFailedKernelException( descriptor, "some index", cause ) ) .when( indexProxy ).awaitStoreScanCompleted(); PropertyAccessor propertyAccessor = mock( PropertyAccessor.class ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulatorTest.java index 57670e5130b43..301e78fefc107 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/BatchingMultipleIndexPopulatorTest.java @@ -45,6 +45,7 @@ import org.neo4j.logging.NullLogProvider; import org.neo4j.storageengine.api.schema.PopulationProgress; import org.neo4j.unsafe.impl.internal.dragons.FeatureToggles; +import org.neo4j.values.Values; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; @@ -57,6 +58,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; import static org.neo4j.kernel.impl.api.index.BatchingMultipleIndexPopulator.AWAIT_TIMEOUT_MINUTES_NAME; import static org.neo4j.kernel.impl.api.index.BatchingMultipleIndexPopulator.BATCH_SIZE_NAME; import static org.neo4j.kernel.impl.api.index.BatchingMultipleIndexPopulator.TASK_QUEUE_SIZE_NAME; @@ -91,8 +93,8 @@ public void populateFromQueueDoesNothingIfThresholdNotReached() throws Exception IndexUpdater updater = mock( IndexUpdater.class ); when( populator.newPopulatingUpdater( any() ) ).thenReturn( updater ); - IndexEntryUpdate update1 = IndexEntryUpdate.add( 1, index1.schema(), "foo" ); - IndexEntryUpdate update2 = IndexEntryUpdate.add( 2, index1.schema(), "bar" ); + IndexEntryUpdate update1 = add( 1, index1.schema(), "foo" ); + IndexEntryUpdate update2 = add( 2, index1.schema(), "bar" ); batchingPopulator.queue( update1 ); batchingPopulator.queue( update2 ); @@ -125,9 +127,9 @@ public void populateFromQueuePopulatesWhenThresholdReached() throws Exception when( populator2.newPopulatingUpdater( any() ) ).thenReturn( updater2 ); batchingPopulator.indexAllNodes(); - IndexEntryUpdate update1 = IndexEntryUpdate.add( 1, index1.schema(), "foo" ); - IndexEntryUpdate update2 = IndexEntryUpdate.add( 2, index42.schema(), "bar" ); - IndexEntryUpdate update3 = IndexEntryUpdate.add( 3, index1.schema(), "baz" ); + IndexEntryUpdate update1 = add( 1, index1.schema(), "foo" ); + IndexEntryUpdate update2 = add( 2, index42.schema(), "bar" ); + IndexEntryUpdate update3 = add( 3, index1.schema(), "baz" ); batchingPopulator.queue( update1 ); batchingPopulator.queue( update2 ); batchingPopulator.queue( update3 ); @@ -308,7 +310,9 @@ private List> forUpdates( IndexDescriptor inde private NodeUpdates nodeUpdates( int nodeId, int propertyId, String propertyValue, long... labelIds ) { - return NodeUpdates.forNode( nodeId, labelIds, labelIds ).added( propertyId, propertyValue ).build(); + return NodeUpdates.forNode( nodeId, labelIds, labelIds ) + .added( propertyId, Values.of( propertyValue ) ) + .build(); } private static IndexPopulator addPopulator( BatchingMultipleIndexPopulator batchingPopulator, IndexDescriptor descriptor ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexCRUDIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexCRUDIT.java index 85b96426a1302..396e233f6860d 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexCRUDIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexCRUDIT.java @@ -58,6 +58,7 @@ import org.neo4j.storageengine.api.schema.IndexSample; import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.rule.fs.EphemeralFileSystemRule; +import org.neo4j.values.Values; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -96,7 +97,7 @@ public void addingANodeWithPropertyShouldGetIndexed() throws Exception int label = readOperations.labelGetForName( myLabel.name() ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( label, propertyKey1 ); assertThat( writer.updatesCommitted, equalTo( asSet( - IndexEntryUpdate.add( node.getId(), descriptor, value1 ) ) ) ); + IndexEntryUpdate.add( node.getId(), descriptor, Values.of( value1 ) ) ) ) ); tx.success(); } // We get two updates because we both add a label and a property to be indexed @@ -136,7 +137,7 @@ public void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception int label = readOperations.labelGetForName( myLabel.name() ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( label, propertyKey1 ); assertThat( writer.updatesCommitted, equalTo( asSet( - IndexEntryUpdate.add( node.getId(), descriptor, value ) ) ) ); + IndexEntryUpdate.add( node.getId(), descriptor, Values.of( value ) ) ) ) ); tx.success(); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java index 3febf11e90c56..5e9a22fcac9df 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexPopulationJobTest.java @@ -72,6 +72,8 @@ import org.neo4j.test.OtherThreadExecutor; import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.rule.CleanupRule; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.lang.String.format; import static org.hamcrest.MatcherAssert.assertThat; @@ -153,7 +155,7 @@ public void shouldPopulateIndexWithOneNode() throws Exception job.run(); // THEN - IndexEntryUpdate update = IndexEntryUpdate.add( nodeId, descriptor, value ); + IndexEntryUpdate update = IndexEntryUpdate.add( nodeId, descriptor, Values.of( value ) ); verify( populator ).create(); verify( populator ).configureSampling( true ); @@ -200,8 +202,8 @@ public void shouldPopulateIndexWithASmallDataset() throws Exception job.run(); // THEN - IndexEntryUpdate update1 = IndexEntryUpdate.add( node1, descriptor, value ); - IndexEntryUpdate update2 = add( node4, descriptor, value ); + IndexEntryUpdate update1 = IndexEntryUpdate.add( node1, descriptor, Values.of( value ) ); + IndexEntryUpdate update2 = add( node4, descriptor, Values.of( value ) ); verify( populator ).create(); verify( populator ).configureSampling( true ); @@ -452,15 +454,15 @@ private class NodeChangingWriter extends IndexPopulator.Adapter private final Set> added = new HashSet<>(); private IndexPopulationJob job; private final long nodeToChange; - private final Object newValue; - private final Object previousValue; + private final Value newValue; + private final Value previousValue; private final LabelSchemaDescriptor index; NodeChangingWriter( long nodeToChange, int propertyKeyId, Object previousValue, Object newValue, int label ) { this.nodeToChange = nodeToChange; - this.previousValue = previousValue; - this.newValue = newValue; + this.previousValue = Values.of( previousValue ); + this.newValue = Values.of( newValue ); this.index = SchemaDescriptorFactory.forLabel( label, propertyKeyId ); } @@ -480,7 +482,7 @@ public void add( IndexEntryUpdate update ) { job.update( IndexEntryUpdate.change( nodeToChange, index, previousValue, newValue ) ); } - added.add( Pair.of( update.getEntityId(), update.values()[0] ) ); + added.add( Pair.of( update.getEntityId(), update.values()[0].asPublic() ) ); } @Override @@ -495,7 +497,7 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntryCon { case ADDED: case CHANGED: - added.add( Pair.of( update.getEntityId(), update.values()[0] ) ); + added.add( Pair.of( update.getEntityId(), update.values()[0].asPublic() ) ); break; default: throw new IllegalArgumentException( update.updateMode().name() ); @@ -527,13 +529,13 @@ private class NodeDeletingWriter extends IndexPopulator.Adapter private final Map removed = new HashMap<>(); private final long nodeToDelete; private IndexPopulationJob job; - private final Object valueToDelete; + private final Value valueToDelete; private final LabelSchemaDescriptor index; NodeDeletingWriter( long nodeToDelete, int propertyKeyId, Object valueToDelete, int label ) { this.nodeToDelete = nodeToDelete; - this.valueToDelete = valueToDelete; + this.valueToDelete = Values.of( valueToDelete ); this.index = SchemaDescriptorFactory.forLabel( label, propertyKeyId ); } @@ -558,7 +560,7 @@ public void add( IndexEntryUpdate update ) { job.update( IndexEntryUpdate.remove( nodeToDelete, index, valueToDelete ) ); } - added.put( update.getEntityId(), update.values()[0] ); + added.put( update.getEntityId(), update.values()[0].asPublic() ); } @Override @@ -573,10 +575,10 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntryCon { case ADDED: case CHANGED: - added.put( update.getEntityId(), update.values()[0] ); + added.put( update.getEntityId(), update.values()[0].asPublic() ); break; case REMOVED: - removed.put( update.getEntityId(), update.values()[0] ); // on remove, value is the before value + removed.put( update.getEntityId(), update.values()[0].asPublic() ); // on remove, value is the before value break; default: throw new IllegalArgumentException( update.updateMode().name() ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java index eefb8cc6fdbba..2ca28a78c6b96 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexRecoveryIT.java @@ -66,6 +66,7 @@ import org.neo4j.storageengine.api.schema.IndexSample; import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.rule.fs.EphemeralFileSystemRule; +import org.neo4j.values.Values; import static java.util.concurrent.Executors.newSingleThreadExecutor; import static java.util.concurrent.TimeUnit.SECONDS; @@ -353,7 +354,7 @@ private Set createSomeBananas( Label label ) { Node node = db.createNode( label ); node.setProperty( key, number ); - updates.add( IndexEntryUpdate.add( node.getId(), schemaDescriptor, number ) ); + updates.add( IndexEntryUpdate.add( node.getId(), schemaDescriptor, Values.of( number ) ) ); } } tx.success(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java index f01ef5f31bd1e..f09f67d346c76 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexingServiceTest.java @@ -99,6 +99,7 @@ import org.neo4j.storageengine.api.schema.PopulationProgress; import org.neo4j.test.DoubleLatch; import org.neo4j.test.mockito.answer.AwaitAnswer; +import org.neo4j.values.Values; import static java.lang.String.format; import static java.lang.System.currentTimeMillis; @@ -1185,18 +1186,18 @@ private NodeUpdates addNodeUpdate( long nodeId, Object propertyValue ) private NodeUpdates addNodeUpdate( long nodeId, Object propertyValue, int labelId ) { return NodeUpdates.forNode( nodeId, new long[]{labelId} ) - .added( index.schema().getPropertyId(), propertyValue ).build(); + .added( index.schema().getPropertyId(), Values.of( propertyValue ) ).build(); } private IndexEntryUpdate add( long nodeId, Object propertyValue ) { - return IndexEntryUpdate.add( nodeId, index.schema(), propertyValue ); + return IndexEntryUpdate.add( nodeId, index.schema(), Values.of( propertyValue ) ); } private IndexEntryUpdate add( long nodeId, Object propertyValue, int labelId ) { LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, index.schema().getPropertyId() ); - return IndexEntryUpdate.add( nodeId, schema, propertyValue ); + return IndexEntryUpdate.add( nodeId, schema, Values.of( propertyValue ) ); } private IndexingService newIndexingServiceWithMockedDependencies( IndexPopulator populator, diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorTest.java index ea3524c142151..c34194b245556 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorTest.java @@ -61,6 +61,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; @RunWith( MockitoJUnitRunner.class ) public class MultipleIndexPopulatorTest @@ -366,8 +367,8 @@ public void testMultiplePropertyUpdateFailures() throws IOException, IndexEntryConflictException { PropertyAccessor propertyAccessor = mock( PropertyAccessor.class ); - IndexEntryUpdate update1 = IndexEntryUpdate.add( 1, index1, "foo" ); - IndexEntryUpdate update2 = IndexEntryUpdate.add( 2, index1, "bar" ); + IndexEntryUpdate update1 = add( 1, index1, "foo" ); + IndexEntryUpdate update2 = add( 2, index1, "bar" ); IndexUpdater updater = mock( IndexUpdater.class ); IndexPopulator populator = createIndexPopulator( updater ); @@ -388,7 +389,7 @@ public void testMultiplePropertyUpdateFailures() private IndexEntryUpdate createIndexEntryUpdate( LabelSchemaDescriptor schemaDescriptor ) { - return IndexEntryUpdate.add( 1, schemaDescriptor, "theValue" ); + return add( 1, schemaDescriptor, "theValue" ); } private RuntimeException getSampleError() diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorUpdatesTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorUpdatesTest.java index 1ae91f886a7f1..a53d6da111418 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorUpdatesTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/MultipleIndexPopulatorUpdatesTest.java @@ -61,6 +61,7 @@ import org.neo4j.register.Register; import org.neo4j.register.Registers; import org.neo4j.storageengine.api.schema.IndexSample; +import org.neo4j.values.Values; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; @@ -199,7 +200,7 @@ public void receive( NodeRecord nodeRecord ) { if ( nodeRecord.getId() == 7 ) { - indexPopulator.queue( IndexEntryUpdate.change( 8L, index, "a", "b" ) ); + indexPopulator.queue( IndexEntryUpdate.change( 8L, index, Values.of( "a" ), Values.of( "b" ) ) ); } } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverterTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverterTest.java index 01619a58f4263..cbeabd11e8807 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverterTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/PropertyPhysicalToLogicalConverterTest.java @@ -39,6 +39,8 @@ import org.neo4j.logging.NullLogProvider; import org.neo4j.test.rule.PageCacheRule; import org.neo4j.test.rule.fs.EphemeralFileSystemRule; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -55,7 +57,7 @@ public void shouldConvertInlinedAddedProperty() throws Exception { // GIVEN int key = 10; - int value = 12345; + Value value = Values.of( 12345 ); PropertyRecord before = propertyRecord(); PropertyRecord after = propertyRecord( property( key, value ) ); @@ -70,8 +72,8 @@ public void shouldConvertInlinedChangedProperty() throws Exception { // GIVEN int key = 10; - int valueBefore = 12341; - int valueAfter = 738; + Value valueBefore = Values.of( 12341 ); + Value valueAfter = Values.of( 738 ); PropertyRecord before = propertyRecord( property( key, valueBefore ) ); PropertyRecord after = propertyRecord( property( key, valueAfter ) ); @@ -88,7 +90,7 @@ public void shouldIgnoreInlinedUnchangedProperty() throws Exception { // GIVEN int key = 10; - int value = 12341; + Value value = Values.of( 12341 ); PropertyRecord before = propertyRecord( property( key, value ) ); PropertyRecord after = propertyRecord( property( key, value ) ); @@ -103,7 +105,7 @@ public void shouldConvertInlinedRemovedProperty() throws Exception { // GIVEN int key = 10; - int value = 12341; + Value value = Values.of( 12341 ); PropertyRecord before = propertyRecord( property( key, value ) ); PropertyRecord after = propertyRecord(); @@ -166,8 +168,8 @@ public void shouldTreatPropertyThatMovedToAnotherRecordAsChange() throws Excepti { // GIVEN int key = 12; - String oldValue = "value1"; - String newValue = "value two"; + Value oldValue = Values.of( "value1" ); + Value newValue = Values.of( "value two" ); PropertyRecordChange movedFrom = change( propertyRecord( property( key, oldValue ) ), propertyRecord() ); @@ -198,7 +200,7 @@ private PropertyRecord propertyRecord( PropertyBlock... propertyBlocks ) return record; } - private PropertyBlock property( long key, Object value ) + private PropertyBlock property( long key, Value value ) { PropertyBlock block = new PropertyBlock(); store.encodeValue( block, (int) key, value ); @@ -210,8 +212,10 @@ private PropertyBlock property( long key, Object value ) @Rule public EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); private PropertyStore store; - private final String longString = "my super looooooooooooooooooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiing"; - private final String longerString = "my super looooooooooooooooooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiingdd"; + private final Value longString = Values.of( + "my super looooooooooooooooooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiing" ); + private final Value longerString = Values.of( + "my super looooooooooooooooooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiingdd" ); private PropertyPhysicalToLogicalConverter converter; private final long[] none = new long[0]; private final long[] labels = new long[]{11}; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/HashBasedIndex.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/HashBasedIndex.java index 6e7519e21b144..e30114e23a345 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/HashBasedIndex.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/HashBasedIndex.java @@ -33,6 +33,7 @@ import org.neo4j.helpers.collection.Iterables; import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.storageengine.api.schema.IndexSampler; +import org.neo4j.values.Value; import static org.neo4j.collection.primitive.PrimitiveLongCollections.toPrimitiveIterator; import static org.neo4j.kernel.api.schema.IndexQuery.IndexQueryType.exact; @@ -252,7 +253,7 @@ public PrimitiveLongIterator query( IndexQuery... predicates ) { if ( predicates.length > 1 ) { - Object[] values = new Object[predicates.length]; + Value[] values = new Value[predicates.length]; for ( int i = 0; i < predicates.length; i++ ) { assert predicates[i].type() == exact : "composite indexes only supported for seek"; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndex.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndex.java index 324d70583d778..b9ea2d351d26a 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndex.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndex.java @@ -39,6 +39,7 @@ import org.neo4j.kernel.impl.api.index.IndexUpdateMode; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexSample; +import org.neo4j.values.Value; import static org.neo4j.helpers.collection.Iterators.emptyResourceIterator; @@ -91,14 +92,14 @@ final IndexAccessor getOnlineAccessor() return new OnlineAccessor(); } - protected boolean add( long nodeId, Object[] propertyValues, boolean applyIdempotently ) + protected boolean add( long nodeId, Value[] propertyValues, boolean applyIdempotently ) throws IndexEntryConflictException, IOException { assert propertyValues.length > 0; return indexData.add( nodeId, applyIdempotently, propertyValues ); } - protected void remove( long nodeId, Object[] propertyValues ) + protected void remove( long nodeId, Value[] propertyValues ) { assert propertyValues.length > 0; indexData.remove( nodeId, propertyValues ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndexImplementation.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndexImplementation.java index 5316c99369ed0..8cf62e7d8f6bf 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndexImplementation.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/InMemoryIndexImplementation.java @@ -25,6 +25,7 @@ import org.neo4j.helpers.collection.BoundedIterable; import org.neo4j.kernel.api.index.ArrayEncoder; import org.neo4j.storageengine.api.schema.IndexReader; +import org.neo4j.values.Value; abstract class InMemoryIndexImplementation implements IndexReader, BoundedIterable { @@ -32,23 +33,23 @@ abstract class InMemoryIndexImplementation implements IndexReader, BoundedIterab abstract void drop(); - public final PrimitiveLongIterator seek( Object... values ) + public final PrimitiveLongIterator seek( Value... values ) { return doIndexSeek( encode( values ) ); } - final boolean add( long nodeId, boolean applyIdempotently, Object... propertyValues ) + final boolean add( long nodeId, boolean applyIdempotently, Value... propertyValues ) { return doAdd( nodeId, applyIdempotently, encode( propertyValues ) ); } - final void remove( long nodeId, Object... propertyValues ) + final void remove( long nodeId, Value... propertyValues ) { doRemove( nodeId, encode( propertyValues ) ); } @Override - public final long countIndexedNodes( long nodeId, Object... propertyValues ) + public final long countIndexedNodes( long nodeId, Value... propertyValues ) { return doCountIndexedNodes( nodeId, encode( propertyValues ) ); } @@ -70,28 +71,33 @@ public void close() { } - private static Object[] encode( Object... propertyValues ) + private static Object[] encode( Value[] propertyValues ) { + Object[] encoded = new Object[propertyValues.length]; for ( int i = 0; i < propertyValues.length; i++ ) { + encoded[i] = encode( propertyValues[i] ); + } - if ( propertyValues[i] instanceof Number ) - { - propertyValues[i] = ((Number) propertyValues[i]).doubleValue(); - } - - if ( propertyValues[i] instanceof Character ) - { - propertyValues[i] = propertyValues[i].toString(); - } + return encoded; + } - if ( propertyValues[i].getClass().isArray() ) - { - propertyValues[i] = new ArrayKey( ArrayEncoder.encode( propertyValues[i] ) ); - } + private static Object encode( Value value ) + { + Object asPublic = value.asPublic(); + if ( asPublic instanceof Number ) + { + asPublic = ((Number) asPublic).doubleValue(); } - - return propertyValues; + else if ( asPublic instanceof Character ) + { + asPublic = asPublic.toString(); + } + else if ( asPublic.getClass().isArray() ) + { + asPublic = new ArrayKey( ArrayEncoder.encode( asPublic ) ); + } + return asPublic; } static class ArrayKey diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/UniqueInMemoryIndex.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/UniqueInMemoryIndex.java index c3fd7820b36bd..966a80a42fec7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/UniqueInMemoryIndex.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/inmemory/UniqueInMemoryIndex.java @@ -33,9 +33,10 @@ import org.neo4j.kernel.api.index.IndexUpdater; import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.impl.api.index.IndexUpdateMode; import org.neo4j.kernel.impl.api.index.updater.UniquePropertyIndexUpdater; +import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; class UniqueInMemoryIndex extends InMemoryIndex { @@ -139,11 +140,11 @@ public void visitEntry( Object key, Set nodeIds ) throws Exception Map entries = new HashMap<>(); for ( long nodeId : nodeIds ) { - final Object value = accessor.getProperty( nodeId, schema.getPropertyId() ).value(); + final Value value = accessor.getPropertyValue( nodeId, schema.getPropertyId() ); if ( entries.containsKey( value ) ) { long existingNodeId = entries.get( value ); - throw new IndexEntryConflictException( existingNodeId, nodeId, OrderedPropertyValues.ofUndefined( value ) ); + throw new IndexEntryConflictException( existingNodeId, nodeId, ValueTuple.of( value ) ); } entries.put( value, nodeId ); } @@ -162,10 +163,10 @@ private class MultiPropertyValidator implements InMemoryIndexImplementation.Inde @Override public void visitEntry( Object key, Set nodeIds ) throws Exception { - Map entries = new HashMap<>(); + Map entries = new HashMap<>(); for ( long nodeId : nodeIds ) { - final OrderedPropertyValues values = getValues( nodeId ); + final ValueTuple values = getValues( nodeId ); if ( entries.containsKey( values ) ) { long existingNodeId = entries.get( values ); @@ -175,15 +176,15 @@ public void visitEntry( Object key, Set nodeIds ) throws Exception } } - OrderedPropertyValues getValues( long nodeId ) throws PropertyNotFoundException, EntityNotFoundException + ValueTuple getValues( long nodeId ) throws PropertyNotFoundException, EntityNotFoundException { int[] propertyIds = schema.getPropertyIds(); - Object[] values = new Object[propertyIds.length]; + Value[] values = new Value[propertyIds.length]; for ( int i = 0; i < values.length; i++ ) { - values[i] = accessor.getProperty( nodeId, propertyIds[i] ).value(); + values[i] = accessor.getPropertyValue( nodeId, propertyIds[i] ); } - return OrderedPropertyValues.ofUndefined( values ); + return ValueTuple.of( values ); } } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java index 398b1118b7882..b20cc20574141 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexQueryTransactionStateTest.java @@ -31,6 +31,7 @@ import org.neo4j.graphdb.Resource; import org.neo4j.kernel.api.AssertOpen; import org.neo4j.kernel.api.index.InternalIndexState; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; @@ -62,7 +63,6 @@ import static org.mockito.Mockito.when; import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE; -import static org.neo4j.kernel.api.properties.Property.property; import static org.neo4j.kernel.impl.api.state.StubCursors.asNodeCursor; import static org.neo4j.kernel.impl.api.state.StubCursors.asPropertyCursor; import static org.neo4j.kernel.impl.api.state.StubCursors.labels; @@ -347,10 +347,10 @@ public void shouldExcludeUniqueNodeWithRemovedProperty() throws Exception private void mockStoreProperty() { when( store.nodeGetProperties( eq( statement ), any( NodeItem.class ), any( AssertOpen.class ) ) ) - .thenReturn( asPropertyCursor( property( propertyKeyId, value.asPublic() ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKeyId, value ) ) ); when( store.nodeGetProperty( eq( statement ), any( NodeItem.class ), eq( propertyKeyId ), any( AssertOpen.class ) ) ) - .thenReturn( asPropertyCursor( property( propertyKeyId, value.asPublic() ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKeyId, value ) ) ); } private void assertNoSuchNode( long node ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdaterTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdaterTest.java index 00dd7c308038b..f40614d302b68 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdaterTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/IndexTxStateUpdaterTest.java @@ -30,9 +30,8 @@ import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.cursor.Cursor; import org.neo4j.kernel.api.exceptions.EntityNotFoundException; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; import org.neo4j.kernel.api.txstate.TransactionState; @@ -40,6 +39,7 @@ import org.neo4j.kernel.impl.api.operations.EntityReadOperations; import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.StoreReadLayer; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; import static org.mockito.Matchers.any; @@ -108,9 +108,9 @@ public void setup() EntityReadOperations readOps = mock( EntityReadOperations.class ); when( readOps.nodeGetPropertyKeys( state, node ) ).thenReturn( defaultPropertyIds ); when( readOps.nodeGetProperties( state, node ) ).thenAnswer( p -> StubCursors.asPropertyCursor( - Property.property( propId1, "hi1" ), - Property.property( propId2, "hi2" ), - Property.property( propId3, "hi3" ) ) ); + new PropertyKeyValue( propId1, Values.of( "hi1" ) ), + new PropertyKeyValue( propId2, Values.of( "hi2" ) ), + new PropertyKeyValue( propId3, Values.of( "hi3" ) ) ) ); when( readOps.nodeGetProperty( state, node, propId1 ) ).thenReturn( Values.of( "hi1" ) ); when( readOps.nodeGetProperty( state, node, propId2 ) ).thenReturn( Values.of( "hi2" ) ); when( readOps.nodeGetProperty( state, node, propId3 ) ).thenReturn( Values.of( "hi3" ) ); @@ -205,13 +205,13 @@ public void shouldUpdateIndexesOnChangesProperty() throws EntityNotFoundExceptio verify( txState, times( 2 ) ).indexDoUpdateEntry( any(), anyInt(), any(), any() ); } - private OrderedPropertyValues values( Object... values ) + private ValueTuple values( Object... values ) { - return OrderedPropertyValues.ofUndefined( values ); + return ValueTuple.of( values ); } private void verifyIndexUpdate( - LabelSchemaDescriptor schema, long nodeId, OrderedPropertyValues before, OrderedPropertyValues after ) + LabelSchemaDescriptor schema, long nodeId, ValueTuple before, ValueTuple after ) { verify( txState ).indexDoUpdateEntry( eq( schema ), eq( nodeId), eq( before ), eq( after ) ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImplTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImplTest.java index 66877eef211de..56c6f5af8c7d2 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImplTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/PropertyContainerStateImplTest.java @@ -24,16 +24,14 @@ import java.util.Iterator; import org.neo4j.helpers.collection.Iterators; -import org.neo4j.kernel.api.properties.DefinedProperty; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.storageengine.api.StorageProperty; -import org.neo4j.test.Property; import org.neo4j.values.Values; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; -import static org.neo4j.kernel.api.properties.Property.stringProperty; public class PropertyContainerStateImplTest { @@ -51,7 +49,7 @@ public void shouldListAddedProperties() throws Exception // Then assertThat( Iterators.asList( added ), - equalTo( asList( stringProperty( 2, "Hello" ) ) ) ); + equalTo( asList( new PropertyKeyValue( 2, Values.of( "Hello" ) ) ) ) ); } @Test @@ -68,7 +66,10 @@ public void shouldListAddedPropertiesEvenIfPropertiesHaveBeenReplaced() throws E // Then assertThat( Iterators.asList( added ), - equalTo( asList( stringProperty( 1, "WAT" ), stringProperty( 2, "Hello" ) ) ) ); + equalTo( asList( + new PropertyKeyValue( 1, Values.of( "WAT" ) ), + new PropertyKeyValue( 2, Values.of( "Hello" ) ) ) + ) ); } @Test @@ -83,7 +84,7 @@ public void shouldConvertAddRemoveToChange() throws Exception // Then assertThat( Iterators.asList( state.changedProperties() ), - equalTo( asList( stringProperty( 4, "another value" ) ) ) ); + equalTo( asList( new PropertyKeyValue( 4, Values.of( "another value" ) ) ) ) ); assertFalse( state.addedProperties().hasNext() ); assertFalse( state.removedProperties().hasNext() ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java index 986bfe8c8f2bf..5d19290a690f2 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateHandlingStatementOperationsTest.java @@ -33,10 +33,9 @@ import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.legacyindex.AutoIndexOperations; import org.neo4j.kernel.api.legacyindex.AutoIndexing; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory; @@ -58,6 +57,7 @@ import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.txstate.PropertyContainerState; import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; import static java.util.Collections.emptyIterator; @@ -75,7 +75,6 @@ import static org.neo4j.helpers.collection.Iterators.asIterable; import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.helpers.collection.Iterators.iterator; -import static org.neo4j.kernel.api.properties.Property.intProperty; import static org.neo4j.kernel.impl.api.StatementOperationsTestHelper.mockedState; import static org.neo4j.kernel.impl.api.state.StubCursors.asNodeCursor; import static org.neo4j.kernel.impl.api.state.StubCursors.asPropertyCursor; @@ -251,7 +250,7 @@ public void shouldConsiderTransactionStateDuringIndexSeekWithIndexQuery() throws KernelStatement statement = mock( KernelStatement.class ); when( statement.hasTxStateWithChanges() ).thenReturn( true ); when( statement.txState() ).thenReturn( txState ); - when( txState.indexUpdatesForSeek( index, OrderedPropertyValues.ofUndefined( "value" ) ) ).thenReturn( + when( txState.indexUpdatesForSeek( index, ValueTuple.of( "value" ) ) ).thenReturn( new DiffSets<>( Collections.singleton( 42L ), Collections.singleton( 44L ) ) ); when( txState.addedAndRemovedNodes() ).thenReturn( @@ -420,7 +419,8 @@ public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWit { long nodeId = (long) invocationOnMock.getArguments()[1]; when( txState.augmentSinglePropertyCursor( any( Cursor.class ), any( PropertyContainerState.class ), - eq( propertyKey ) ) ).thenReturn( asPropertyCursor( intProperty( propertyKey, inRange ) ) ); + eq( propertyKey ) ) ) + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKey, Values.of( inRange ) ) ) ); return asNodeCursor( nodeId, nodeId + 20000 ); } ); @@ -434,7 +434,8 @@ public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWit { long nodeId = (long) invocationOnMock.getArguments()[0]; when( storeReadLayer.nodeGetProperty( eq( storageStatement ), any( NodeItem.class ), eq( propertyKey ), - any( AssertOpen.class ) ) ).thenReturn( asPropertyCursor( intProperty( propertyKey, inRange ) ) ); + any( AssertOpen.class ) ) ) + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKey, Values.of( inRange ) ) ) ); return asNodeCursor( nodeId, nodeId + 20000 ); } ); @@ -506,7 +507,7 @@ public void shouldNotRecordNodeSetPropertyOnSameValue() throws Exception // GIVEN int propertyKeyId = 5; long nodeId = 0; - String value = "The value"; + Value value = Values.of( "The value" ); KernelStatement kernelStatement = mock( KernelStatement.class ); StoreStatement storeStatement = mock( StoreStatement.class ); Cursor ourNode = nodeCursorWithProperty( propertyKeyId ); @@ -523,7 +524,7 @@ public void shouldNotRecordNodeSetPropertyOnSameValue() throws Exception StateHandlingStatementOperations operations = newTxStateOps( storeReadLayer, autoIndexing ); // WHEN - Value newValue = Values.of( value ); + Value newValue = Values.of( "The value" ); operations.nodeSetProperty( kernelStatement, nodeId, propertyKeyId, newValue ); // THEN @@ -531,7 +532,7 @@ public void shouldNotRecordNodeSetPropertyOnSameValue() throws Exception // although auto-indexing should still be notified verify( autoIndexOps ).propertyChanged( any( DataWriteOperations.class ), eq( nodeId ), - eq( propertyKeyId ), eq( Values.of( value ) ), eq( newValue ) ); + eq( propertyKeyId ), eq( value ), eq( newValue ) ); } @Test @@ -540,7 +541,7 @@ public void shouldNotRecordRelationshipSetPropertyOnSameValue() throws Exception // GIVEN int propertyKeyId = 5; long relationshipId = 0; - String value = "The value"; + Value value = Values.of( "The value" ); KernelStatement kernelStatement = mock( KernelStatement.class ); StoreStatement storeStatement = mock( StoreStatement.class ); Cursor ourRelationship = relationshipCursorWithProperty( propertyKeyId ); @@ -557,7 +558,7 @@ public void shouldNotRecordRelationshipSetPropertyOnSameValue() throws Exception StateHandlingStatementOperations operations = newTxStateOps( storeReadLayer, autoIndexing ); // WHEN - Value newValue = Values.of( value ); + Value newValue = Values.of( "The value" ); operations.relationshipSetProperty( kernelStatement, relationshipId, propertyKeyId, newValue ); // THEN @@ -573,15 +574,15 @@ public void shouldNotRecordGraphSetPropertyOnSameValue() throws Exception { // GIVEN int propertyKeyId = 5; - String value = "The value"; + Value value = Values.of( "The value" ); KernelStatement kernelStatement = mock( KernelStatement.class ); StoreStatement storeStatement = mock( StoreStatement.class ); when( kernelStatement.getStoreStatement() ).thenReturn( storeStatement ); - when( inner.graphGetAllProperties() ).thenReturn( iterator( Property.stringProperty( propertyKeyId, value ) ) ); + when( inner.graphGetAllProperties() ).thenReturn( iterator( new PropertyKeyValue( propertyKeyId, value ) ) ); StateHandlingStatementOperations operations = newTxStateOps( inner ); // WHEN - Value newValue = Values.of( value ); + Value newValue = Values.of( "The value" ); operations.graphSetProperty( kernelStatement, propertyKeyId, newValue ); // THEN @@ -602,7 +603,7 @@ private Cursor relationshipCursorWithProperty( long propertyKe return StubCursors.cursor( item ); } - private Cursor propertyCursor( long propertyKeyId, String value ) + private Cursor propertyCursor( long propertyKeyId, Value value ) { PropertyItem propertyItem = mock( PropertyItem.class ); when( propertyItem.propertyKeyId() ).thenReturn( (int) propertyKeyId ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateOperationsAutoIndexingTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateOperationsAutoIndexingTest.java index 74592f9209bb4..7f62dba236fa2 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateOperationsAutoIndexingTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StateOperationsAutoIndexingTest.java @@ -148,7 +148,7 @@ public void shouldSignalNodePropertyChangedToAutoIndex() throws Exception PropertyItem existingProperty = mock( PropertyItem.class ); when(existingProperty.propertyKeyId()).thenReturn( propertyKeyId ); - when(existingProperty.value()).thenReturn( "Goodbye!" ); + when(existingProperty.value()).thenReturn( Values.of( "Goodbye!" ) ); NodeItem node = mock( NodeItem.class ); when( node.labels() ).thenReturn( PrimitiveIntCollections.emptySet() ); @@ -174,7 +174,7 @@ public void shouldSignalRelationshipPropertyChangedToAutoIndex() throws Exceptio PropertyItem existingProperty = mock( PropertyItem.class ); when(existingProperty.propertyKeyId()).thenReturn( propertyKeyId ); - when(existingProperty.value()).thenReturn( "Goodbye!" ); + when(existingProperty.value()).thenReturn( Values.of( "Goodbye!" ) ); RelationshipItem relationship = mock( RelationshipItem.class ); when( storeStmt.acquireSingleRelationshipCursor( 1337 ) ).thenReturn( cursor( relationship ) ); @@ -195,7 +195,7 @@ public void shouldSignalNodePropertyRemovedToAutoIndex() throws Exception // Given PropertyItem existingProperty = mock( PropertyItem.class ); when( existingProperty.propertyKeyId() ).thenReturn( 1 ); - when( existingProperty.value() ).thenReturn( "Goodbye!" ); + when( existingProperty.value() ).thenReturn( Values.of( "Goodbye!" ) ); int propertyKeyId = existingProperty.propertyKeyId(); NodeItem node = mock( NodeItem.class ); @@ -220,7 +220,7 @@ public void shouldSignalRelationshipPropertyRemovedToAutoIndex() throws Exceptio int propertyKeyId = 1; when( existingProperty.propertyKeyId() ).thenReturn( propertyKeyId ); - when( existingProperty.value() ).thenReturn( "Goodbye!" ); + when( existingProperty.value() ).thenReturn( Values.of( "Goodbye!" ) ); RelationshipItem relationship = mock( RelationshipItem.class ); when( storeStmt.acquireSingleRelationshipCursor( 1337 ) ).thenReturn( cursor( relationship ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StubCursors.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StubCursors.java index fc10fe2eaf541..dc18b0e5bbb55 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StubCursors.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/StubCursors.java @@ -26,11 +26,12 @@ import org.neo4j.collection.primitive.PrimitiveIntSet; import org.neo4j.cursor.Cursor; import org.neo4j.helpers.collection.Iterables; -import org.neo4j.kernel.api.properties.DefinedProperty; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.impl.locking.Lock; import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.RelationshipItem; +import org.neo4j.values.Value; import static org.neo4j.collection.primitive.PrimitiveIntCollections.emptySet; import static org.neo4j.helpers.collection.Iterables.map; @@ -247,12 +248,12 @@ public static PrimitiveIntSet labels( final int... labels ) return PrimitiveIntCollections.asSet( labels ); } - public static Cursor asPropertyCursor( final DefinedProperty... properties ) + public static Cursor asPropertyCursor( final PropertyKeyValue... properties ) { return cursor( map( StubCursors::asPropertyItem, Arrays.asList( properties ) ) ); } - private static PropertyItem asPropertyItem( final DefinedProperty property ) + private static PropertyItem asPropertyItem( final PropertyKeyValue property ) { return new PropertyItem() { @@ -263,9 +264,9 @@ public int propertyKeyId() } @Override - public Object value() + public Value value() { - return property.value(); + return property.valueForced(); } }; } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateCompositeIndexTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateCompositeIndexTest.java index 0b84bffe53c4d..471b2e789af98 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateCompositeIndexTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateCompositeIndexTest.java @@ -27,11 +27,11 @@ import org.neo4j.helpers.collection.Iterators; import org.neo4j.helpers.collection.Pair; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.storageengine.api.txstate.ReadableDiffSets; +import org.neo4j.values.ValueTuple; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -68,7 +68,7 @@ public void shouldSeekOnAnEmptyTxState() throws Exception { // WHEN ReadableDiffSets diffSets = - state.indexUpdatesForSeek( indexOn_1_1_2, OrderedPropertyValues.ofUndefined( "43value1", "43value2" ) ); + state.indexUpdatesForSeek( indexOn_1_1_2, ValueTuple.of( "43value1", "43value2" ) ); // THEN assertTrue( diffSets.isEmpty() ); @@ -97,7 +97,7 @@ public void shouldSeekWhenThereAreNewStringNodes() throws Exception // WHEN ReadableDiffSets diffSets = - state.indexUpdatesForSeek( indexOn_1_1_2, OrderedPropertyValues.ofUndefined( "43value1", "43value2" ) ); + state.indexUpdatesForSeek( indexOn_1_1_2, ValueTuple.of( "43value1", "43value2" ) ); // THEN assertEquals( asSet( 43L ), diffSets.getAdded() ); @@ -112,7 +112,7 @@ public void shouldSeekWhenThereAreNewNumberNodes() throws Exception // WHEN ReadableDiffSets diffSets = - state.indexUpdatesForSeek( indexOn_1_1_2, OrderedPropertyValues.ofUndefined( 43001.0, 43002.0 ) ); + state.indexUpdatesForSeek( indexOn_1_1_2, ValueTuple.of( 43001.0, 43002.0 ) ); // THEN assertEquals( asSet( 43L ), diffSets.getAdded() ); @@ -145,7 +145,7 @@ public void shouldSeekWhenThereAreManyEntriesWithTheSameValues() throws Exceptio // WHEN ReadableDiffSets diffSets = - state.indexUpdatesForSeek( indexOn_1_1_2, OrderedPropertyValues.ofUndefined( "43value1", "43value2" ) ); + state.indexUpdatesForSeek( indexOn_1_1_2, ValueTuple.of( "43value1", "43value2" ) ); // THEN assertEquals( asSet( 43L, 44L ), diffSets.getAdded() ); @@ -155,20 +155,20 @@ public void shouldSeekWhenThereAreManyEntriesWithTheSameValues() throws Exceptio public void shouldSeekInComplexMix() throws Exception { // GIVEN - OrderedPropertyValues[] values2_1 = Iterators.array( - OrderedPropertyValues.ofUndefined( "hi", 3 ), - OrderedPropertyValues.ofUndefined( 9L, 33L ), - OrderedPropertyValues.ofUndefined( "sneaker", false ) ); + ValueTuple[] values2_1 = Iterators.array( + ValueTuple.of( "hi", 3 ), + ValueTuple.of( 9L, 33L ), + ValueTuple.of( "sneaker", false ) ); - OrderedPropertyValues[] values2_2 = Iterators.array( - OrderedPropertyValues.ofUndefined( true, false ), - OrderedPropertyValues.ofUndefined( new int[]{ 10,100}, "array-buddy" ), - OrderedPropertyValues.ofUndefined( 40.1, 40.2 ) ); + ValueTuple[] values2_2 = Iterators.array( + ValueTuple.of( true, false ), + ValueTuple.of( new int[]{ 10,100}, "array-buddy" ), + ValueTuple.of( 40.1, 40.2 ) ); - OrderedPropertyValues[] values3 = Iterators.array( - OrderedPropertyValues.ofUndefined( "hi", "ho", "hello" ), - OrderedPropertyValues.ofUndefined( true, new long[]{4L}, 33L ), - OrderedPropertyValues.ofUndefined( 2, false, 1 ) ); + ValueTuple[] values3 = Iterators.array( + ValueTuple.of( "hi", "ho", "hello" ), + ValueTuple.of( true, new long[]{4L}, 33L ), + ValueTuple.of( 2, false, 1 ) ); addEntries( indexOn_1_1_2, values2_1, 10 ); addEntries( indexOn_2_2_3, values2_2, 100 ); @@ -179,7 +179,7 @@ public void shouldSeekInComplexMix() throws Exception assertSeek( indexOn_2_2_3_4, values3, 1000 ); } - private void addEntries( IndexDescriptor index, OrderedPropertyValues[] values, long nodeIdStart ) + private void addEntries( IndexDescriptor index, ValueTuple[] values, long nodeIdStart ) { for ( int i = 0; i < values.length; i++ ) { @@ -187,7 +187,7 @@ private void addEntries( IndexDescriptor index, OrderedPropertyValues[] values, } } - private void assertSeek( IndexDescriptor index, OrderedPropertyValues[] values, long nodeIdStart ) + private void assertSeek( IndexDescriptor index, ValueTuple[] values, long nodeIdStart ) { for ( int i = 0; i < values.length; i++ ) { @@ -227,7 +227,7 @@ public void removeDefaultStringEntries( long... nodeIds ) @Override public void addDefaultStringProperties( long... nodeIds ) { - Collection> entries = new ArrayList<>( nodeIds.length ); + Collection> entries = new ArrayList<>( nodeIds.length ); for ( long nodeId : nodeIds ) { int[] propertyIds = descriptor.schema().getPropertyIds(); @@ -236,36 +236,36 @@ public void addDefaultStringProperties( long... nodeIds ) { values[i] = nodeId * 1000.0 + propertyIds[i]; } - entries.add( of( nodeId, OrderedPropertyValues.ofUndefined( values ) ) ); + entries.add( of( nodeId, ValueTuple.of( values ) ) ); } addEntries( entries ); } - void addEntries( Collection> nodesWithValues ) + void addEntries( Collection> nodesWithValues ) { - for ( Pair entry : nodesWithValues ) + for ( Pair entry : nodesWithValues ) { long nodeId = entry.first(); state.indexDoUpdateEntry( descriptor.schema(), nodeId, null, entry.other() ); } } - void removeEntries( Collection> nodesWithValues ) + void removeEntries( Collection> nodesWithValues ) { - for ( Pair entry : nodesWithValues ) + for ( Pair entry : nodesWithValues ) { long nodeId = entry.first(); state.indexDoUpdateEntry( descriptor.schema(), nodeId, entry.other(), null ); } } - private Collection> getDefaultStringEntries( long[] nodeIds ) + private Collection> getDefaultStringEntries( long[] nodeIds ) { - Collection> entries = new ArrayList<>( nodeIds.length ); + Collection> entries = new ArrayList<>( nodeIds.length ); for ( long nodeId : nodeIds ) { int[] propertyIds = descriptor.schema().getPropertyIds(); - OrderedPropertyValues values = getDefaultStringPropertyValues( nodeId, propertyIds ); + ValueTuple values = getDefaultStringPropertyValues( nodeId, propertyIds ); entries.add( of( nodeId, values ) ); } return entries; @@ -273,13 +273,13 @@ private Collection> getDefaultStringEntries( lo }; } - private OrderedPropertyValues getDefaultStringPropertyValues( long nodeId, int[] propertyIds ) + private ValueTuple getDefaultStringPropertyValues( long nodeId, int[] propertyIds ) { Object[] values = new Object[propertyIds.length]; for ( int i = 0; i < propertyIds.length; i++ ) { values[i] = nodeId + "value" + propertyIds[i]; } - return OrderedPropertyValues.ofUndefined( values ); + return ValueTuple.of( values ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java index ada93eff21189..6984de11837be 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateTest.java @@ -38,7 +38,6 @@ import org.neo4j.cursor.Cursor; import org.neo4j.helpers.collection.Iterables; import org.neo4j.helpers.collection.Pair; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory; import org.neo4j.kernel.api.schema.constaints.UniquenessConstraintDescriptor; @@ -52,6 +51,7 @@ import org.neo4j.test.rule.RandomRule; import org.neo4j.test.rule.RepeatRule; import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; import org.neo4j.values.Values; import static java.util.Arrays.asList; @@ -222,8 +222,7 @@ public void shouldComputeIndexUpdatesForSeekWhenThereAreNewNodes() throws Except addNodesToIndex( indexOn_1_2 ).withDefaultStringProperties( 44L ); // WHEN - ReadableDiffSets diffSets = state.indexUpdatesForSeek( indexOn_1_1, OrderedPropertyValues.ofUndefined( "value43" - ) ); + ReadableDiffSets diffSets = state.indexUpdatesForSeek( indexOn_1_1, ValueTuple.of( "value43" ) ); // THEN assertEquals( asSet( 43L ), diffSets.getAdded() ); @@ -1689,7 +1688,7 @@ private void withProperties( Collection> nodesWithValues ) Value valueAfter = Values.of( entry.other() ); state.nodeDoAddProperty( nodeId, propertyKeyId, valueAfter ); state.indexDoUpdateEntry( descriptor.schema(), nodeId, null, - OrderedPropertyValues.ofUndefined( valueAfter.asPublic() ) ); + ValueTuple.of( valueAfter.asPublic() ) ); } } }; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateVisitorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateVisitorTest.java index 7e002c30d36a0..71c24d820a352 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateVisitorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/TxStateVisitorTest.java @@ -31,11 +31,10 @@ import org.neo4j.helpers.collection.Iterables; import org.neo4j.helpers.collection.Iterators; -import org.neo4j.kernel.api.properties.DefinedProperty; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.storageengine.api.StorageProperty; import org.neo4j.storageengine.api.txstate.TxStateVisitor; -import org.neo4j.test.Property; import org.neo4j.values.Value; import org.neo4j.values.Values; @@ -59,7 +58,7 @@ public void shouldSeeAddedRelationshipProperties() throws Exception state.accept( visitor ); // Then - DefinedProperty prop = DefinedProperty.stringProperty( propKey, "hello" ); + StorageProperty prop = new PropertyKeyValue( propKey, Values.of( "hello" ) ); assertThat(visitor.relPropertyChanges, contains( propChange( relId, noProperty, asList( prop ), noRemoved ) ) ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerPropertyTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerPropertyTest.java index f55a5338c7d38..6b7ba53e7b409 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerPropertyTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorageLayerPropertyTest.java @@ -24,12 +24,13 @@ import java.lang.reflect.Array; import org.neo4j.cursor.Cursor; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.impl.api.operations.KeyReadOperations; import org.neo4j.kernel.impl.locking.Lock; import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.StorageStatement; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.util.Collections.singletonMap; import static org.junit.Assert.assertEquals; @@ -107,11 +108,11 @@ public void should_get_all_node_properties() throws Exception { if ( props.next() ) { - Object propVal = props.get().value(); + Value propVal = props.get().value(); //then - assertTrue( propVal + ".valueEquals(" + value + ")", - Property.property( propKey, propVal ).valueEquals( value ) ); + assertTrue( propVal + ".equals(" + value + ")", + propVal.equals( Values.of( value ) ) ); } else { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyCursorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyCursorTest.java index ad2f697a0364a..c2e45622f3c3d 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyCursorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyCursorTest.java @@ -58,6 +58,8 @@ import org.neo4j.test.MockedNeoStores; import org.neo4j.test.rule.PageCacheRule; import org.neo4j.test.rule.fs.EphemeralFileSystemRule; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.lang.Math.toIntExact; import static java.util.Arrays.asList; @@ -528,10 +530,10 @@ public void callNextAfterReadingPropertyChain() cursor.init( firstPropertyId, NO_LOCK, ALWAYS_OPEN ); assertTrue( cursor.next() ); - assertEquals( "1", cursor.value() ); + assertEquals( Values.of( "1" ), cursor.value() ); assertTrue( cursor.next() ); - assertEquals( "2", cursor.value() ); + assertEquals( Values.of( "2" ), cursor.value() ); assertFalse( cursor.next() ); assertFalse( cursor.next() ); @@ -715,7 +717,7 @@ private void verifyPropertyValue( String expectedValue, long recordId ) { cursor.init( recordId, NO_LOCK, ALWAYS_OPEN ); assertTrue( cursor.next() ); - assertEquals( expectedValue, cursor.value() ); + assertEquals( Values.of( expectedValue ), cursor.value() ); assertFalse( cursor.next() ); } } @@ -726,7 +728,7 @@ private void verifyPropertyValue( byte[] expectedValue, long recordId ) { cursor.init( recordId, NO_LOCK, ALWAYS_OPEN ); assertTrue( cursor.next() ); - assertArrayEquals( expectedValue, (byte[]) cursor.value() ); + assertTrue( cursor.value().equals( expectedValue ) ); assertFalse( cursor.next() ); } } @@ -735,16 +737,9 @@ private void verifyPropertyValue( byte[] expectedValue, long recordId ) private static void assertEqualValues( Object expectedValue, PropertyItem item ) { // fetch twice with typed methods - if ( expectedValue.getClass().isArray() ) - { - assertArrayEquals( (double[]) expectedValue, (double[]) item.value(), 0.0 ); - assertArrayEquals( (double[]) expectedValue, (double[]) item.value(), 0.0 ); - } - else - { - assertEquals( expectedValue, item.value() ); - assertEquals( expectedValue, item.value() ); - } + Value expected = Values.of( expectedValue ); + assertTrue( item.value().equals( expected ) ); + assertTrue( item.value().equals( expected ) ); } public static long firstIdOf( List propertyChain ) @@ -830,7 +825,7 @@ private static PropertyRecord createSinglePropertyValue( PropertyStore store, in DynamicRecordAllocator arrayAllocator = store.getArrayStore(); PropertyBlock block = new PropertyBlock(); - PropertyStore.encodeValue( block, keyId, value, stringAllocator, arrayAllocator ); + PropertyStore.encodeValue( block, keyId, Values.of( value ), stringAllocator, arrayAllocator ); PropertyRecord record = new PropertyRecord( store.nextId() ); record.addPropertyBlock( block ); @@ -847,9 +842,9 @@ private static PropertyRecord createTwoPropertyValues( PropertyStore store, DynamicRecordAllocator arrayAllocator = store.getArrayStore(); PropertyBlock block1 = new PropertyBlock(); - PropertyStore.encodeValue( block1, keyId1, value1, stringAllocator, arrayAllocator ); + PropertyStore.encodeValue( block1, keyId1, Values.of( value1 ), stringAllocator, arrayAllocator ); PropertyBlock block2 = new PropertyBlock(); - PropertyStore.encodeValue( block2, keyId2, value2, stringAllocator, arrayAllocator ); + PropertyStore.encodeValue( block2, keyId2, Values.of( value2 ), stringAllocator, arrayAllocator ); PropertyRecord record = new PropertyRecord( store.nextId() ); record.addPropertyBlock( block1 ); @@ -891,7 +886,7 @@ private static List asPropertyValuesList( StorePropertyCursor cursor ) List values = new ArrayList<>(); while ( cursor.next() ) { - values.add( cursor.value() ); + values.add( cursor.value().asPublic() ); } return values; } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursorTest.java index 0672419035da7..da4e9cb61df10 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/store/StorePropertyPayloadCursorTest.java @@ -43,6 +43,7 @@ import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.RecordLoad; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -258,7 +259,7 @@ public void shouldReturnCorrectSingleValue() // Then assertTrue( next ); assertEquals( param.type, cursor.type() ); - assertObjectOrArrayEquals( param.value, cursor.value() ); + assertEquals( Values.of( param.value ), cursor.value() ); } } @@ -438,7 +439,7 @@ public void shouldReturnCorrectValues() // Then assertTrue( next ); assertEquals( param.type, cursor.type() ); - assertObjectOrArrayEquals( param.value, cursor.value() ); + assertEquals( Values.of( param.value ), cursor.value() ); } } } @@ -489,7 +490,7 @@ private static long[] asBlocks( Object... values ) Object value = values[i]; PropertyBlock block = new PropertyBlock(); - PropertyStore.encodeValue( block, i, value, stringAllocator, arrayAllocator ); + PropertyStore.encodeValue( block, i, Values.of( value ), stringAllocator, arrayAllocator ); long[] valueBlocks = block.getValueBlocks(); System.arraycopy( valueBlocks, 0, blocks, cursor, valueBlocks.length ); cursor += valueBlocks.length; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/IteratingPropertyReceiverTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/IteratingPropertyReceiverTest.java index a6dc522e56e3b..54ea844d9906b 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/IteratingPropertyReceiverTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/IteratingPropertyReceiverTest.java @@ -22,8 +22,9 @@ import org.junit.Test; import org.neo4j.kernel.api.exceptions.PropertyNotFoundException; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.storageengine.api.StorageProperty; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -38,7 +39,7 @@ public void shouldAcceptAndThenIterateOverProperties() throws PropertyNotFoundEx int propertyCount = 100; for ( int i = 0; i < propertyCount; i++ ) { - receiver.receive( Property.intProperty( 1, i ), 5 ); + receiver.receive( new PropertyKeyValue( 1, Values.of( i ) ), 5 ); } // THEN @@ -46,7 +47,7 @@ public void shouldAcceptAndThenIterateOverProperties() throws PropertyNotFoundEx while ( receiver.hasNext() ) { StorageProperty property = receiver.next(); - assertEquals( count++, ((Integer) property.value()).intValue() ); + assertEquals( Values.of( count++ ), property.value() ); } assertFalse( receiver.hasNext() ); assertEquals( propertyCount, count ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataViewTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataViewTest.java index 61570b3e3ba60..f996b8d951b5b 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataViewTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/coreapi/TxStateTransactionDataViewTest.java @@ -33,7 +33,7 @@ import org.neo4j.kernel.api.AssertOpen; import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.Statement; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.api.security.AccessMode; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.kernel.api.security.AuthSubject; @@ -63,7 +63,6 @@ import static org.mockito.Mockito.when; import static org.neo4j.helpers.collection.Iterables.single; import static org.neo4j.helpers.collection.MapUtil.genericMap; -import static org.neo4j.kernel.api.properties.Property.stringProperty; import static org.neo4j.kernel.impl.api.state.StubCursors.asNodeCursor; import static org.neo4j.kernel.impl.api.state.StubCursors.asPropertyCursor; import static org.neo4j.kernel.impl.api.state.StubCursors.asRelationshipCursor; @@ -108,7 +107,7 @@ public void showsDeletedNodes() throws Exception when( storeStatement.acquireSingleNodeCursor( 2L ) ).thenReturn( asNodeCursor( 2L, 20L, labels( 15 ) ) ); when( storeStatement.acquirePropertyCursor( eq( 20L ), any( Lock.class ), any( AssertOpen.class ) ) ) - .thenReturn( asPropertyCursor( stringProperty( 1, "p" ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( 1, Values.of( "p" ) ) ) ); when( storeStatement.acquireSingleNodeCursor( 1L ) ).thenReturn( asNodeCursor( 1L, 21L, labels() ) ); when( storeStatement.acquirePropertyCursor( eq( 21L ), any( Lock.class ), any( AssertOpen.class ) ) ) @@ -151,7 +150,7 @@ public void showsRemovedRelationships() throws Exception when( storeStatement.acquireSingleRelationshipCursor( 2L ) ). thenReturn( asRelationshipCursor( 2L, 1, 1L, 1L, propertyId ) ); when( storeStatement.acquirePropertyCursor( propertyId, NO_LOCK, AssertOpen.ALWAYS_OPEN ) ) - .thenReturn( asPropertyCursor( Property.stringProperty( 1, "p" ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( 1, Values.of( "p" ) ) ) ); when( ops.propertyKeyGetName( 1 ) ).thenReturn( "key" ); @@ -207,7 +206,7 @@ public void shouldListAddedNodePropertiesProperties() throws Exception asNodeCursor( 1L, propertyId, labels() ) ); when( storeStatement .acquireSinglePropertyCursor( propertyId, propertyKeyId, NO_LOCK, AssertOpen.ALWAYS_OPEN ) ) - .thenReturn( asPropertyCursor( Property.property( propertyKeyId, prevValue.asPublic() ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKeyId, prevValue ) ) ); // When Iterable> propertyEntries = snapshot().assignedNodeProperties(); @@ -233,7 +232,7 @@ public void shouldListRemovedNodeProperties() throws Exception asNodeCursor( 1L, propertyId, labels() ) ); when( storeStatement .acquireSinglePropertyCursor( propertyId, propertyKeyId, NO_LOCK, AssertOpen.ALWAYS_OPEN ) ) - .thenReturn( asPropertyCursor( Property.property( propertyKeyId, prevValue.asPublic() ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKeyId, prevValue ) ) ); // When Iterable> propertyEntries = snapshot().removedNodeProperties(); @@ -258,7 +257,7 @@ public void shouldListRemovedRelationshipProperties() throws Exception .thenReturn( asRelationshipCursor( 1, 0, 0, 0, propertyId ) ); when( storeStatement .acquireSinglePropertyCursor( propertyId, propertyKeyId, NO_LOCK, AssertOpen.ALWAYS_OPEN ) ) - .thenReturn( asPropertyCursor( Property.property( propertyKeyId, prevValue.asPublic() ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKeyId, prevValue ) ) ); // When Iterable> propertyEntries = snapshot().removedRelationshipProperties(); @@ -284,7 +283,7 @@ public void shouldListAddedRelationshipProperties() throws Exception asRelationshipCursor( 1, 0, 0, 0, propertyId ) ); when( storeStatement .acquireSinglePropertyCursor( propertyId, propertyKeyId, NO_LOCK, AssertOpen.ALWAYS_OPEN ) ) - .thenReturn( asPropertyCursor( Property.property( propertyKeyId, prevValue.asPublic() ) ) ); + .thenReturn( asPropertyCursor( new PropertyKeyValue( propertyKeyId, prevValue ) ) ); // When Iterable> propertyEntries = snapshot().assignedRelationshipProperties(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/FullScanNonUniqueIndexSamplerTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/FullScanNonUniqueIndexSamplerTest.java index 6b638f8417b9c..27f4780c3fcee 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/FullScanNonUniqueIndexSamplerTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/FullScanNonUniqueIndexSamplerTest.java @@ -40,6 +40,7 @@ import org.neo4j.test.rule.RandomRule; import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.fs.DefaultFileSystemRule; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.rules.RuleChain.outerRule; @@ -49,6 +50,7 @@ import static org.neo4j.index.internal.gbptree.GBPTree.NO_MONITOR; import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; import static org.neo4j.test.rule.PageCacheRule.config; +import static org.neo4j.values.Values.values; public class FullScanNonUniqueIndexSamplerTest { @@ -103,7 +105,7 @@ private List generateNumberValues() List result = new ArrayList<>(); for ( IndexEntryUpdate update : NativeSchemaIndexPopulatorTest.someDuplicateIndexEntryUpdates() ) { - result.add( (Number) update.values()[0] ); + result.add( (Number) update.values()[0].asPublic() ); } // TODO: perhaps some more values? return result; @@ -120,8 +122,8 @@ private void buildTree( List values ) throws IOException long nodeId = 0; for ( Number number : values ) { - key.from( nodeId, array( number ) ); - value.from( nodeId, array( number ) ); + key.from( nodeId, values( number ) ); + value.from( nodeId, values( number ) ); writer.put( key, value ); nodeId++; } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java index 35b2065b9cc9d..0e6d2847cb5ac 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java @@ -63,6 +63,7 @@ import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.fs.DefaultFileSystemRule; import org.neo4j.test.rule.fs.FileSystemRule; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -908,7 +909,7 @@ private RawCursor, IOException> scan( GBPTree tree ) t protected static IndexEntryUpdate add( long nodeId, Object value ) { - return IndexEntryUpdate.add( nodeId, indexDescriptor, value ); + return IndexEntryUpdate.add( nodeId, indexDescriptor, Values.of( value ) ); } private byte[] fileWithContent() throws IOException diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java index fe376fc53a216..9807e345cedba 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/NeoStoresTest.java @@ -52,9 +52,8 @@ import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.exceptions.EntityNotFoundException; import org.neo4j.kernel.api.exceptions.TransactionFailureException; -import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.api.txstate.TransactionState; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.api.KernelStatement; import org.neo4j.kernel.impl.api.KernelTransactionImplementation; @@ -80,6 +79,7 @@ import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.RelationshipItem; import org.neo4j.storageengine.api.StorageStatement; +import org.neo4j.storageengine.api.StorageProperty; import org.neo4j.storageengine.api.StoreReadLayer; import org.neo4j.storageengine.api.Token; import org.neo4j.string.UTF8; @@ -106,7 +106,6 @@ import static org.neo4j.graphdb.factory.GraphDatabaseSettings.counts_store_rotation_timeout; import static org.neo4j.helpers.collection.MapUtil.stringMap; import static org.neo4j.kernel.api.AssertOpen.ALWAYS_OPEN; -import static org.neo4j.kernel.api.properties.DefinedProperty.NO_SUCH_PROPERTY; import static org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED; import static org.neo4j.kernel.configuration.Config.embeddedDefaults; import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK; @@ -215,13 +214,13 @@ public void testCreateStore() throws Exception transaction.nodeDoCreate( node1 ); long node2 = nextId( Node.class ); transaction.nodeDoCreate( node2 ); - DefinedProperty n1prop1 = nodeAddProperty( node1, index( "prop1" ), "string1" ); - DefinedProperty n1prop2 = nodeAddProperty( node1, index( "prop2" ), 1 ); - DefinedProperty n1prop3 = nodeAddProperty( node1, index( "prop3" ), true ); + StorageProperty n1prop1 = nodeAddProperty( node1, index( "prop1" ), "string1" ); + StorageProperty n1prop2 = nodeAddProperty( node1, index( "prop2" ), 1 ); + StorageProperty n1prop3 = nodeAddProperty( node1, index( "prop3" ), true ); - DefinedProperty n2prop1 = nodeAddProperty( node2, index( "prop1" ), "string2" ); - DefinedProperty n2prop2 = nodeAddProperty( node2, index( "prop2" ), 2 ); - DefinedProperty n2prop3 = nodeAddProperty( node2, index( "prop3" ), false ); + StorageProperty n2prop1 = nodeAddProperty( node2, index( "prop1" ), "string2" ); + StorageProperty n2prop2 = nodeAddProperty( node2, index( "prop2" ), 2 ); + StorageProperty n2prop3 = nodeAddProperty( node2, index( "prop3" ), false ); int relType1 = (int) nextId( RelationshipType.class ); String typeName1 = "relationshiptype1"; @@ -234,13 +233,13 @@ public void testCreateStore() throws Exception long rel2 = nextId( Relationship.class ); transaction.relationshipDoCreate( rel2, relType2, node2, node1 ); - DefinedProperty r1prop1 = relAddProperty( rel1, index( "prop1" ), "string1" ); - DefinedProperty r1prop2 = relAddProperty( rel1, index( "prop2" ), 1 ); - DefinedProperty r1prop3 = relAddProperty( rel1, index( "prop3" ), true ); + StorageProperty r1prop1 = relAddProperty( rel1, index( "prop1" ), "string1" ); + StorageProperty r1prop2 = relAddProperty( rel1, index( "prop2" ), 1 ); + StorageProperty r1prop3 = relAddProperty( rel1, index( "prop3" ), true ); - DefinedProperty r2prop1 = relAddProperty( rel2, index( "prop1" ), "string2" ); - DefinedProperty r2prop2 = relAddProperty( rel2, index( "prop2" ), 2 ); - DefinedProperty r2prop3 = relAddProperty( rel2, index( "prop3" ), false ); + StorageProperty r2prop1 = relAddProperty( rel2, index( "prop1" ), "string2" ); + StorageProperty r2prop2 = relAddProperty( rel2, index( "prop2" ), 2 ); + StorageProperty r2prop3 = relAddProperty( rel2, index( "prop3" ), false ); commitTx(); ds.stop(); @@ -295,10 +294,10 @@ public void testCreateStore() throws Exception ds.stop(); } - private DefinedProperty nodeAddProperty( long nodeId, int key, Object value ) + private StorageProperty nodeAddProperty( long nodeId, int key, Object value ) { - DefinedProperty property = Property.property( key, value ); - DefinedProperty oldProperty = NO_SUCH_PROPERTY; + StorageProperty property = new PropertyKeyValue( key, Values.of( value ) ); + StorageProperty oldProperty = null; try ( StorageStatement statement = storeLayer.newStatement(); Cursor cursor = statement.acquireSingleNodeCursor( nodeId ) ) { @@ -306,7 +305,7 @@ private DefinedProperty nodeAddProperty( long nodeId, int key, Object value ) { if ( cursor.next() ) { - DefinedProperty fetched = getProperty( key, statement, cursor.get().nextPropertyId() ); + StorageProperty fetched = getProperty( key, statement, cursor.get().nextPropertyId() ); if ( fetched != null ) { oldProperty = fetched; @@ -315,30 +314,30 @@ private DefinedProperty nodeAddProperty( long nodeId, int key, Object value ) } } - if ( oldProperty == NO_SUCH_PROPERTY ) + if ( oldProperty == null ) { - transaction.nodeDoAddProperty( nodeId, key, Values.of( value ) ); + transaction.nodeDoAddProperty( nodeId, key, property.valueForced() ); } else { - transaction.nodeDoChangeProperty( nodeId, key, Values.of( oldProperty.value() ), Values.of( value ) ); + transaction.nodeDoChangeProperty( nodeId, key, oldProperty.valueForced(), property.valueForced() ); } return property; } - private DefinedProperty relAddProperty( long relationshipId, int key, Object value ) + private StorageProperty relAddProperty( long relationshipId, int key, Object value ) { - DefinedProperty property = Property.property( key, value ); + StorageProperty property = new PropertyKeyValue( key, Values.of( value ) ); Value oldValue = Values.NO_VALUE; try ( StorageStatement statement = storeLayer.newStatement(); Cursor cursor = statement.acquireSingleRelationshipCursor( relationshipId ) ) { if ( cursor.next() ) { - DefinedProperty fetched = getProperty( key, statement, cursor.get().nextPropertyId() ); + StorageProperty fetched = getProperty( key, statement, cursor.get().nextPropertyId() ); if ( fetched != null ) { - oldValue = Values.of( fetched.value() ); + oldValue = fetched.valueForced(); } } } @@ -347,17 +346,17 @@ private DefinedProperty relAddProperty( long relationshipId, int key, Object val return property; } - private DefinedProperty getProperty( int key, StorageStatement statement, long propertyId ) + private StorageProperty getProperty( int key, StorageStatement statement, long propertyId ) { try ( Cursor propertyCursor = statement .acquireSinglePropertyCursor( propertyId, key, NO_LOCK, ALWAYS_OPEN ) ) { if ( propertyCursor.next() ) { - Object oldValue = propertyCursor.get().value(); + Value oldValue = propertyCursor.get().value(); if ( oldValue != null ) { - return Property.property( key, oldValue ); + return new PropertyKeyValue( key, oldValue ); } } } @@ -499,13 +498,13 @@ public void testProps1() throws Exception long nodeId = nextId( Node.class ); transaction.nodeDoCreate( nodeId ); pStore.nextId(); - DefinedProperty prop = nodeAddProperty( nodeId, index( "nisse" ), 10 ); + StorageProperty prop = nodeAddProperty( nodeId, index( "nisse" ), 10 ); commitTx(); ds.stop(); initializeStores( storeDir, stringMap() ); startTx(); - DefinedProperty prop2 = nodeAddProperty( nodeId, prop.propertyKeyId(), 5 ); - transaction.nodeDoRemoveProperty( nodeId, prop2.propertyKeyId(), Values.of( prop2.value() ) ); + StorageProperty prop2 = nodeAddProperty( nodeId, prop.propertyKeyId(), 5 ); + transaction.nodeDoRemoveProperty( nodeId, prop2.propertyKeyId(), prop2.value() ); transaction.nodeDoDelete( nodeId ); commitTx(); ds.stop(); @@ -969,13 +968,13 @@ private long nextId( Class clazz ) throw new IllegalArgumentException( clazz.getName() ); } - private void validateNodeRel1( final long node, DefinedProperty prop1, - DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, + private void validateNodeRel1( final long node, StorageProperty prop1, + StorageProperty prop2, StorageProperty prop3, long rel1, long rel2, final int relType1, final int relType2 ) throws IOException { assertTrue( nodeExists( node ) ); - ArrayMap> props = new ArrayMap<>(); - PropertyReceiver receiver = newPropertyReceiver( props ); + ArrayMap> props = new ArrayMap<>(); + PropertyReceiver receiver = newPropertyReceiver( props ); propertyLoader.nodeLoadProperties( node, receiver ); int count = 0; for ( int keyId : props.keySet() ) @@ -983,26 +982,26 @@ private void validateNodeRel1( final long node, DefinedProperty prop1, long id = props.get( keyId ).other(); PropertyRecord record = getRecord( pStore, id ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "string1", data.value() ); + assertEquals( "string1", data.valueForced().asPublic() ); nodeAddProperty( node, prop1.propertyKeyId(), "-string1" ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( 1, data.value() ); + assertEquals( 1, data.valueForced().asPublic() ); nodeAddProperty( node, prop2.propertyKeyId(), -1 ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( true, data.value() ); + assertEquals( true, data.valueForced().asPublic() ); nodeAddProperty( node, prop3.propertyKeyId(), false ); } else @@ -1055,18 +1054,18 @@ else if ( rel == rel2 ) return count; } - private PropertyReceiver newPropertyReceiver( final ArrayMap> props ) + private PropertyReceiver newPropertyReceiver( final ArrayMap> props ) { return ( property, propertyRecordId ) -> props.put( property.propertyKeyId(), Pair.of( property, propertyRecordId ) ); } - private void validateNodeRel2( final long node, DefinedProperty prop1, - DefinedProperty prop2, DefinedProperty prop3, + private void validateNodeRel2( final long node, StorageProperty prop1, + StorageProperty prop2, StorageProperty prop3, long rel1, long rel2, final int relType1, final int relType2 ) throws IOException, RuntimeException { assertTrue( nodeExists( node ) ); - ArrayMap> props = new ArrayMap<>(); + ArrayMap> props = new ArrayMap<>(); propertyLoader.nodeLoadProperties( node, newPropertyReceiver( props ) ); int count = 0; for ( int keyId : props.keySet() ) @@ -1074,26 +1073,26 @@ private void validateNodeRel2( final long node, DefinedProperty prop1, long id = props.get( keyId ).other(); PropertyRecord record = getRecord( pStore, id ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "string2", data.value() ); + assertEquals( "string2", data.valueForced().asPublic() ); nodeAddProperty( node, prop1.propertyKeyId(), "-string2" ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( 2, data.value() ); + assertEquals( 2, data.valueForced().asPublic() ); nodeAddProperty( node, prop2.propertyKeyId(), -2 ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( false, data.value() ); + assertEquals( false, data.valueForced().asPublic() ); nodeAddProperty( node, prop3.propertyKeyId(), true ); } else @@ -1149,11 +1148,11 @@ private boolean nodeExists( long nodeId ) } } - private void validateRel1( long rel, DefinedProperty prop1, - DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, + private void validateRel1( long rel, StorageProperty prop1, + StorageProperty prop2, StorageProperty prop3, long firstNode, long secondNode, int relType ) throws IOException { - ArrayMap> props = new ArrayMap<>(); + ArrayMap> props = new ArrayMap<>(); propertyLoader.relLoadProperties( rel, newPropertyReceiver( props ) ); int count = 0; for ( int keyId : props.keySet() ) @@ -1161,26 +1160,26 @@ private void validateRel1( long rel, DefinedProperty prop1, long id = props.get( keyId ).other(); PropertyRecord record = getRecord( pStore, id ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "string1", data.value() ); + assertEquals( "string1", data.valueForced().asPublic() ); relAddProperty( rel, prop1.propertyKeyId(), "-string1" ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( 1, data.value() ); + assertEquals( 1, data.valueForced().asPublic() ); relAddProperty( rel, prop2.propertyKeyId(), -1 ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( true, data.value() ); + assertEquals( true, data.valueForced().asPublic() ); relAddProperty( rel, prop3.propertyKeyId(), false ); } else @@ -1211,11 +1210,11 @@ private void assertRelationshipData( long rel, final long firstNode, final long } } - private void validateRel2( long rel, DefinedProperty prop1, - DefinedProperty prop2, DefinedProperty prop3, + private void validateRel2( long rel, StorageProperty prop1, + StorageProperty prop2, StorageProperty prop3, long firstNode, long secondNode, int relType ) throws IOException { - ArrayMap> props = new ArrayMap<>(); + ArrayMap> props = new ArrayMap<>(); propertyLoader.relLoadProperties( rel, newPropertyReceiver( props ) ); int count = 0; for ( int keyId : props.keySet() ) @@ -1223,26 +1222,26 @@ private void validateRel2( long rel, DefinedProperty prop1, long id = props.get( keyId ).other(); PropertyRecord record = getRecord( pStore, id ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "string2", data.value() ); + assertEquals( "string2", data.valueForced().asPublic() ); relAddProperty( rel, prop1.propertyKeyId(), "-string2" ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( 2, data.value() ); + assertEquals( 2, data.valueForced().asPublic() ); relAddProperty( rel, prop2.propertyKeyId(), -2 ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( false, data.value() ); + assertEquals( false, data.valueForced().asPublic() ); relAddProperty( rel, prop3.propertyKeyId(), true ); } else @@ -1285,11 +1284,11 @@ else if ( allData.get(i).id() == relType2 ) } } - private void deleteRel1( long rel, DefinedProperty prop1, DefinedProperty prop2, - DefinedProperty prop3, long firstNode, long secondNode, int relType ) + private void deleteRel1( long rel, StorageProperty prop1, StorageProperty prop2, + StorageProperty prop3, long firstNode, long secondNode, int relType ) throws Exception { - ArrayMap> props = new ArrayMap<>(); + ArrayMap> props = new ArrayMap<>(); propertyLoader.relLoadProperties( rel, newPropertyReceiver( props ) ); int count = 0; for ( int keyId : props.keySet() ) @@ -1297,25 +1296,25 @@ private void deleteRel1( long rel, DefinedProperty prop1, DefinedProperty prop2, long id = props.get( keyId ).other(); PropertyRecord record = pStore.getRecord( id, pStore.newRecord(), NORMAL ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "-string1", data.value() ); + assertEquals( "-string1", data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( -1, data.value() ); + assertEquals( -1, data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( false, data.value() ); - transaction.relationshipDoRemoveProperty( rel, prop3.propertyKeyId(), Values.of( prop3.value() ) ); + assertEquals( false, data.valueForced().asPublic() ); + transaction.relationshipDoRemoveProperty( rel, prop3.propertyKeyId(), prop3.value() ); } else { @@ -1335,22 +1334,22 @@ else if ( data.propertyKeyId() == prop3.propertyKeyId() ) assertHasRelationships( secondNode ); } - private static class CountingPropertyReceiver implements PropertyReceiver + private static class CountingPropertyReceiver implements PropertyReceiver { private int count; @Override - public void receive( DefinedProperty property, long propertyRecordId ) + public void receive( StorageProperty property, long propertyRecordId ) { count++; } } - private void deleteRel2( long rel, DefinedProperty prop1, DefinedProperty prop2, - DefinedProperty prop3, long firstNode, long secondNode, int relType ) + private void deleteRel2( long rel, StorageProperty prop1, StorageProperty prop2, + StorageProperty prop3, long firstNode, long secondNode, int relType ) throws Exception { - ArrayMap> props = new ArrayMap<>(); + ArrayMap> props = new ArrayMap<>(); propertyLoader.relLoadProperties( rel, newPropertyReceiver( props ) ); int count = 0; for ( int keyId : props.keySet() ) @@ -1358,25 +1357,25 @@ private void deleteRel2( long rel, DefinedProperty prop1, DefinedProperty prop2, long id = props.get( keyId ).other(); PropertyRecord record = pStore.getRecord( id, pStore.newRecord(), NORMAL ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "-string2", data.value() ); + assertEquals( "-string2", data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( -2, data.value() ); + assertEquals( -2, data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( true, data.value() ); - transaction.relationshipDoRemoveProperty( rel, prop3.propertyKeyId(), Values.of( prop3.value() ) ); + assertEquals( true, data.valueForced().asPublic() ); + transaction.relationshipDoRemoveProperty( rel, prop3.propertyKeyId(), prop3.value() ); } else { @@ -1412,11 +1411,11 @@ private void assertHasRelationships( long node ) } } - private void deleteNode1( long node, DefinedProperty prop1, - DefinedProperty prop2, DefinedProperty prop3 ) + private void deleteNode1( long node, StorageProperty prop1, + StorageProperty prop2, StorageProperty prop3 ) throws IOException { - ArrayMap> props = new ArrayMap<>(); + ArrayMap> props = new ArrayMap<>(); propertyLoader.nodeLoadProperties( node, newPropertyReceiver( props ) ); int count = 0; for ( int keyId : props.keySet() ) @@ -1424,25 +1423,25 @@ private void deleteNode1( long node, DefinedProperty prop1, long id = props.get( keyId ).other(); PropertyRecord record = pStore.getRecord( id, pStore.newRecord(), NORMAL ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "-string1", data.value() ); + assertEquals( "-string1", data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( -1, data.value() ); + assertEquals( -1, data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( false, data.value() ); - transaction.nodeDoRemoveProperty( node, prop3.propertyKeyId(), Values.of( prop3.value() ) ); + assertEquals( false, data.valueForced().asPublic() ); + transaction.nodeDoRemoveProperty( node, prop3.propertyKeyId(), prop3.valueForced() ); } else { @@ -1458,11 +1457,11 @@ else if ( data.propertyKeyId() == prop3.propertyKeyId() ) transaction.nodeDoDelete( node ); } - private void deleteNode2( long node, DefinedProperty prop1, - DefinedProperty prop2, DefinedProperty prop3 ) + private void deleteNode2( long node, StorageProperty prop1, + StorageProperty prop2, StorageProperty prop3 ) throws IOException { - ArrayMap> props = new ArrayMap<>(); + ArrayMap> props = new ArrayMap<>(); propertyLoader.nodeLoadProperties( node, newPropertyReceiver( props ) ); int count = 0; for ( int keyId : props.keySet() ) @@ -1470,25 +1469,25 @@ private void deleteNode2( long node, DefinedProperty prop1, long id = props.get( keyId ).other(); PropertyRecord record = pStore.getRecord( id, pStore.newRecord(), NORMAL ); PropertyBlock block = record.getPropertyBlock( props.get( keyId ).first().propertyKeyId() ); - DefinedProperty data = block.newPropertyData( pStore ); + StorageProperty data = block.newPropertyKeyValue( pStore ); if ( data.propertyKeyId() == prop1.propertyKeyId() ) { assertEquals( "prop1", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( "-string2", data.value() ); + assertEquals( "-string2", data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop2.propertyKeyId() ) { assertEquals( "prop2", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( -2, data.value() ); + assertEquals( -2, data.valueForced().asPublic() ); } else if ( data.propertyKeyId() == prop3.propertyKeyId() ) { assertEquals( "prop3", MyPropertyKeyToken.getIndexFor( keyId ).name() ); - assertEquals( true, data.value() ); - transaction.nodeDoRemoveProperty( node, prop3.propertyKeyId(), Values.of( prop3.value() ) ); + assertEquals( true, data.valueForced().asPublic() ); + transaction.nodeDoRemoveProperty( node, prop3.propertyKeyId(), prop3.valueForced() ); } else { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/PropertyRecordTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/PropertyRecordTest.java index f4c58020c1155..7aba017ab4986 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/PropertyRecordTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/PropertyRecordTest.java @@ -29,6 +29,7 @@ import org.neo4j.helpers.collection.Iterables; import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.PropertyRecord; +import org.neo4j.values.Values; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; @@ -173,7 +174,7 @@ private void assertIteratorRemoveThrowsIllegalState( Iterator ite private static void addBlock( PropertyRecord record, int key, int value ) { PropertyBlock block = new PropertyBlock(); - PropertyStore.encodeValue( block, key, value, null, null ); + PropertyStore.encodeValue( block, key, Values.of( value ), null, null ); for ( long valueBlock : block.getValueBlocks() ) { record.addLoadedBlock( valueBlock ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/RecordStoreConsistentReadTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/RecordStoreConsistentReadTest.java index 82033fb3f1c28..58bfaf856c34f 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/RecordStoreConsistentReadTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/RecordStoreConsistentReadTest.java @@ -46,6 +46,8 @@ import org.neo4j.logging.NullLogProvider; import org.neo4j.string.UTF8; import org.neo4j.test.rule.PageCacheRule; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertNotNull; @@ -441,7 +443,7 @@ protected PropertyRecord createExistingRecord( boolean light ) record.setInUse( true ); PropertyBlock block = new PropertyBlock(); DynamicRecordAllocator stringAllocator = new ReusableRecordsAllocator( 64, new DynamicRecord( 7 ) ); - String value = "a string too large to fit in the property block itself"; + Value value = Values.of( "a string too large to fit in the property block itself" ); PropertyStore.encodeValue( block, 6, value, stringAllocator, null ); if ( light ) { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/LimitedRecordGenerators.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/LimitedRecordGenerators.java index fa15f0305c8c7..ad6bb2ec50b84 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/LimitedRecordGenerators.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/format/LimitedRecordGenerators.java @@ -32,6 +32,7 @@ import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord; import org.neo4j.test.Randoms; +import org.neo4j.values.Values; import static java.lang.Long.max; import static java.lang.Math.abs; @@ -125,7 +126,7 @@ public Generator property() PropertyBlock block = new PropertyBlock(); // Dynamic records will not be written and read by the property record format, // that happens in the store where it delegates to a "sub" store. - PropertyStore.encodeValue( block, random.nextInt( tokenBits ), random.propertyValue(), + PropertyStore.encodeValue( block, random.nextInt( tokenBits ), Values.of( random.propertyValue() ), stringAllocator, arrayAllocator ); int tentativeBlocksWithThisOne = blocksOccupied + block.getValueBlocks().length; if ( tentativeBlocksWithThisOne <= 4 ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/Commands.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/Commands.java index 74e9b7f58423c..433521fc33773 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/Commands.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/command/Commands.java @@ -54,6 +54,7 @@ import org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation; import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.schema.SchemaRule; +import org.neo4j.values.Values; import static java.util.Collections.singletonList; @@ -166,7 +167,7 @@ public static PropertyCommand createProperty( long id, PropertyType type, int ke PropertyBlock block = new PropertyBlock(); if ( valueRecordIds.length == 0 ) { - PropertyStore.encodeValue( block, key, 123 /*value*/, null, null ); + PropertyStore.encodeValue( block, key, Values.of( 123 ), null, null ); } else { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyCreatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyCreatorTest.java index bc4f7ffda3d23..b2f44b26eb4aa 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyCreatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyCreatorTest.java @@ -34,6 +34,8 @@ import org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy; import org.neo4j.unsafe.batchinsert.DirectRecordAccess; import org.neo4j.unsafe.impl.batchimport.store.BatchingIdSequence; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -252,7 +254,7 @@ private void existingRecord( PropertyRecord record, ExpectedRecord initialRecord private void setProperty( int key, Object value ) { - creator.primitiveSetProperty( primitive, key, value, records ); + creator.primitiveSetProperty( primitive, key, Values.of( value ), records ); } private void assertChain( ExpectedRecord... expectedRecords ) @@ -274,20 +276,20 @@ private void assertRecord( PropertyRecord record, ExpectedRecord expectedRecord { PropertyBlock block = record.getPropertyBlock( expectedProperty.key ); assertNotNull( block ); - assertEquals( expectedProperty.value, block.getType().getValue( block, null ) ); + assertEquals( expectedProperty.value, block.getType().getValueNow( block, null ) ); } } private static class ExpectedProperty { private final int key; - private final Object value; + private final Value value; ExpectedProperty( int key, Object value ) { super(); this.key = key; - this.value = value; + this.value = Values.of( value ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyLoaderTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyLoaderTest.java index 10c4021aaea31..7ca106116ccfb 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyLoaderTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/PropertyLoaderTest.java @@ -29,6 +29,7 @@ import java.util.List; import org.neo4j.helpers.collection.Iterators; +import org.neo4j.kernel.api.properties.PropertyKeyValue; import org.neo4j.kernel.impl.core.IteratingPropertyReceiver; import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine; import org.neo4j.kernel.impl.store.CommonAbstractStore; @@ -44,7 +45,9 @@ import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.RecordLoad; import org.neo4j.kernel.impl.store.record.RelationshipRecord; +import org.neo4j.storageengine.api.StorageProperty; import org.neo4j.test.rule.EmbeddedDatabaseRule; +import org.neo4j.values.Values; import static java.util.Arrays.asList; import static org.hamcrest.Matchers.startsWith; @@ -55,7 +58,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.neo4j.kernel.api.properties.Property.intProperty; public class PropertyLoaderTest { @@ -195,8 +197,13 @@ private static PropertyRecord newSingleIntProperty( long id, int value ) private static PropertyBlock newSingleIntPropertyBlock( int value ) { PropertyBlock block = new PropertyBlock(); - PropertyStore.encodeValue( block, PROP_KEY_ID, value, null, null ); + PropertyStore.encodeValue( block, PROP_KEY_ID, Values.intValue( value ), null, null ); block.setKeyIndexId( PROP_KEY_ID ); return block; } + + private StorageProperty intProperty( int propKeyId, int value ) + { + return new PropertyKeyValue( propKeyId, Values.of( value ) ); + } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java index e64aad5ca235d..75d9400ae1f6c 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/TransactionRecordStateTest.java @@ -40,7 +40,6 @@ import org.neo4j.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.index.IndexEntryUpdate; -import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.impl.api.BatchTransactionApplier; import org.neo4j.kernel.impl.api.CommandVisitor; @@ -87,6 +86,8 @@ import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.schema.SchemaRule; import org.neo4j.test.rule.NeoStoresRule; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -116,8 +117,8 @@ public class TransactionRecordStateTest private static final String LONG_STRING = "string value long enough not to be stored as a short string"; private static final int propertyId1 = 1; private static final int propertyId2 = 2; - private static final String value1 = "first"; - private static final int value2 = 4; + private static final Value value1 = Values.of( "first" ); + private static final Value value2 = Values.of( 4 ); private static final long[] noLabels = new long[0]; private final long[] oneLabelId = new long[]{3}; private final long[] secondLabelId = new long[]{4}; @@ -219,7 +220,7 @@ public void shouldCreateEqualNodePropertyUpdatesOnRecoveryOfCreatedNode() throws recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); recordState.addLabelToNode( labelId, nodeId ); - recordState.nodeAddProperty( nodeId, propertyKeyId, "Neo" ); + recordState.nodeAddProperty( nodeId, propertyKeyId, Values.of( "Neo" ) ); // WHEN PhysicalTransactionRepresentation transaction = transactionRepresentationOf( recordState ); @@ -301,8 +302,8 @@ public void shouldConvertLabelAdditionToNodePropertyUpdates() throws Exception NeoStores neoStores = neoStoresRule.builder().build(); long nodeId = 0; TransactionRecordState recordState = newTransactionRecordState( neoStores ); - Object value1 = LONG_STRING; - Object value2 = LONG_STRING.getBytes(); + Value value1 = Values.of( LONG_STRING ); + Value value2 = Values.of( LONG_STRING.getBytes() ); recordState.nodeCreate( nodeId ); recordState.nodeAddProperty( nodeId, propertyId1, value1 ); recordState.nodeAddProperty( nodeId, propertyId2, value2 ); @@ -375,20 +376,20 @@ public void shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates long nodeId = 0; TransactionRecordState recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); - DefinedProperty property1 = recordState.nodeAddProperty( nodeId, propertyId1, value1 ); + recordState.nodeAddProperty( nodeId, propertyId1, value1 ); addLabelsToNode( recordState, nodeId, bothLabelIds ); apply( neoStores, recordState ); // WHEN recordState = newTransactionRecordState( neoStores ); - recordState.nodeRemoveProperty( nodeId, property1.propertyKeyId() ); + recordState.nodeRemoveProperty( nodeId, propertyId1 ); removeLabelsFromNode( recordState, nodeId, secondLabelId ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); // THEN NodeUpdates expected = NodeUpdates.forNode( nodeId, bothLabelIds, oneLabelId ) - .removed( property1.propertyKeyId(), property1.value() ) + .removed( propertyId1, value1 ) .build(); assertEquals( expected, Iterables.single( indexUpdates ) ); } @@ -401,20 +402,20 @@ public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() long nodeId = 0; TransactionRecordState recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); - DefinedProperty ignored = recordState.nodeAddProperty( nodeId, propertyId1, value1 ); + recordState.nodeAddProperty( nodeId, propertyId1, value1 ); addLabelsToNode( recordState, nodeId, bothLabelIds ); apply( neoStores, recordState ); // WHEN recordState = newTransactionRecordState( neoStores ); - DefinedProperty property2 = recordState.nodeAddProperty( nodeId, propertyId2, value2 ); + recordState.nodeAddProperty( nodeId, propertyId2, value2 ); removeLabelsFromNode( recordState, nodeId, secondLabelId ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); // THEN NodeUpdates expected = NodeUpdates.forNode( nodeId, bothLabelIds, oneLabelId ) - .added( property2.propertyKeyId(), property2.value() ) + .added( propertyId2, value2 ) .build(); assertEquals( expected, Iterables.single( indexUpdates ) ); } @@ -427,23 +428,23 @@ public void shouldConvertChangedPropertyToNodePropertyUpdates() throws Exception int nodeId = 0; TransactionRecordState recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); - DefinedProperty property1 = recordState.nodeAddProperty( nodeId, propertyId1, value1 ); - DefinedProperty property2 = recordState.nodeAddProperty( nodeId, propertyId2, value2 ); + recordState.nodeAddProperty( nodeId, propertyId1, value1 ); + recordState.nodeAddProperty( nodeId, propertyId2, value2 ); apply( neoStores, transactionRepresentationOf( recordState ) ); // WHEN - String newValue1 = "new"; - String newValue2 = "new 2"; + Value newValue1 = Values.of( "new" ); + Value newValue2 = Values.of( "new 2" ); recordState = newTransactionRecordState( neoStores ); - recordState.nodeChangeProperty( nodeId, property1.propertyKeyId(), newValue1 ); - recordState.nodeChangeProperty( nodeId, property2.propertyKeyId(), newValue2 ); + recordState.nodeChangeProperty( nodeId, propertyId1, newValue1 ); + recordState.nodeChangeProperty( nodeId, propertyId2, newValue2 ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); // THEN NodeUpdates expected = NodeUpdates.forNode( nodeId ) - .changed( property1.propertyKeyId(), property1.value(), newValue1 ) - .changed( property2.propertyKeyId(), property2.value(), newValue2 ) + .changed( propertyId1, value1, newValue1 ) + .changed( propertyId2, value2, newValue2 ) .build(); assertEquals( expected, Iterables.single( indexUpdates ) ); } @@ -457,21 +458,21 @@ public void shouldConvertRemovedPropertyToNodePropertyUpdates() throws Exception TransactionRecordState recordState = newTransactionRecordState( neoStores ); recordState.nodeCreate( nodeId ); addLabelsToNode( recordState, nodeId, oneLabelId ); - DefinedProperty property1 = recordState.nodeAddProperty( nodeId, propertyId1, value1 ); - DefinedProperty property2 = recordState.nodeAddProperty( nodeId, propertyId2, value2 ); + recordState.nodeAddProperty( nodeId, propertyId1, value1 ); + recordState.nodeAddProperty( nodeId, propertyId2, value2 ); apply( neoStores, transactionRepresentationOf( recordState ) ); // WHEN recordState = newTransactionRecordState( neoStores ); - recordState.nodeRemoveProperty( nodeId, property1.propertyKeyId() ); - recordState.nodeRemoveProperty( nodeId, property2.propertyKeyId() ); + recordState.nodeRemoveProperty( nodeId, propertyId1 ); + recordState.nodeRemoveProperty( nodeId, propertyId2 ); Iterable indexUpdates = indexUpdatesOf( neoStores, recordState ); // THEN NodeUpdates expected = NodeUpdates.forNode( nodeId, oneLabelId ) - .removed( property1.propertyKeyId(), property1.value() ) - .removed( property2.propertyKeyId(), property2.value() ) + .removed( propertyId1, value1 ) + .removed( propertyId2, value2 ) .build(); assertEquals( expected, Iterables.single( indexUpdates ) ); } @@ -531,7 +532,7 @@ public void shouldExtractCreatedCommandsInCorrectOrder() throws Throwable recordState.nodeCreate( nodeId ); recordState.relCreate( relId++, 0, nodeId, nodeId ); recordState.relCreate( relId, 0, nodeId, nodeId ); - recordState.nodeAddProperty( nodeId, 0, 101 ); + recordState.nodeAddProperty( nodeId, 0, value2 ); // WHEN Collection commands = new ArrayList<>(); @@ -562,15 +563,15 @@ public void shouldExtractUpdateCommandsInCorrectOrder() throws Throwable recordState.nodeCreate( nodeId ); recordState.relCreate( relId1, 0, nodeId, nodeId ); recordState.relCreate( relId2, 0, nodeId, nodeId ); - recordState.nodeAddProperty( nodeId, 0, 101 ); + recordState.nodeAddProperty( nodeId, 0, Values.of( 101 ) ); BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, mock( CacheAccessBackDoor.class ), LockService.NO_LOCK_SERVICE ); apply( applier, transaction( recordState ) ); recordState = newTransactionRecordState( neoStores ); - recordState.nodeChangeProperty( nodeId, 0, 102 ); + recordState.nodeChangeProperty( nodeId, 0, Values.of( 102 ) ); recordState.relCreate( relId3, 0, nodeId, nodeId ); - recordState.relAddProperty( relId1, 0, 123 ); + recordState.relAddProperty( relId1, 0, Values.of( 123 ) ); // WHEN Collection commands = new ArrayList<>(); @@ -650,7 +651,7 @@ public void shouldExtractDeleteCommandsInCorrectOrder() throws Exception recordState.relCreate( relId1, 0, nodeId1, nodeId1 ); recordState.relCreate( relId2, 0, nodeId1, nodeId1 ); recordState.relCreate( relId4, 1, nodeId1, nodeId1 ); - recordState.nodeAddProperty( nodeId1, 0, 101 ); + recordState.nodeAddProperty( nodeId1, 0, value1 ); BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, mock( CacheAccessBackDoor.class ), LockService.NO_LOCK_SERVICE ); apply( applier, transaction( recordState ) ); @@ -707,11 +708,9 @@ public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() int nodeId = 1; recordState.nodeCreate( nodeId ); - int propertyKey = 1; - Object value = 5; // WHEN - recordState.nodeAddProperty( nodeId, propertyKey, value ); + recordState.nodeAddProperty( nodeId, propertyId1, value1 ); Collection commands = new ArrayList<>(); recordState.extractCommands( commands ); PropertyCommand propertyCommand = singlePropertyCommand( commands ); @@ -780,8 +779,8 @@ public synchronized Object answer( final InvocationOnMock invocation ) throws Th { tx.nodeCreate( nodes[i] ); } - tx.nodeAddProperty( nodes[3], 0, "old" ); - tx.nodeAddProperty( nodes[4], 0, "old" ); + tx.nodeAddProperty( nodes[3], 0, Values.of( "old" ) ); + tx.nodeAddProperty( nodes[4], 0, Values.of( "old" ) ); BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, mock( CacheAccessBackDoor.class ), locks ); apply( applier, transaction( tx ) ); @@ -792,14 +791,14 @@ public synchronized Object answer( final InvocationOnMock invocation ) throws Th TransactionRecordState tx = newTransactionRecordState( neoStores ); tx.nodeCreate( nodes[0] ); tx.addLabelToNode( 0, nodes[1] ); - tx.nodeAddProperty( nodes[2], 0, "value" ); - tx.nodeChangeProperty( nodes[3], 0, "value" ); + tx.nodeAddProperty( nodes[2], 0, Values.of( "value" ) ); + tx.nodeChangeProperty( nodes[3], 0, Values.of( "value" ) ); tx.nodeRemoveProperty( nodes[4], 0 ); tx.nodeDelete( nodes[5] ); tx.nodeCreate( nodes[6] ); tx.addLabelToNode( 0, nodes[6] ); - tx.nodeAddProperty( nodes[6], 0, "value" ); + tx.nodeAddProperty( nodes[6], 0, Values.of( "value" ) ); //commit( tx ); BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, mock( CacheAccessBackDoor.class ), locks ); @@ -1380,7 +1379,7 @@ private void assertDynamicLabelRecordInUse( NeoStores store, long id, boolean in assertTrue( inUse == record.inUse() ); } - private String string( int length ) + private Value string( int length ) { StringBuilder result = new StringBuilder(); char ch = 'a'; @@ -1388,7 +1387,7 @@ private String string( int length ) { result.append( (char) ((ch + (i % 10))) ); } - return result.toString(); + return Values.of( result.toString() ); } private PropertyCommand singlePropertyCommand( Collection commands ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewNodeStoreScanTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewNodeStoreScanTest.java index ef0b6e55f0b7b..25a41d8dbd274 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewNodeStoreScanTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/LabelScanViewNodeStoreScanTest.java @@ -48,6 +48,7 @@ import org.neo4j.logging.LogProvider; import org.neo4j.logging.NullLogProvider; import org.neo4j.storageengine.api.schema.LabelScanReader; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -152,10 +153,12 @@ public void resetNodeIdIteratorDuringConcurrentUpdates() private void populateWithConcurrentUpdates( LabelScanViewNodeStoreScan scanViewStoreScan ) { MultipleIndexPopulator.MultipleIndexUpdater indexUpdater = mock( MultipleIndexPopulator.MultipleIndexUpdater.class ); - scanViewStoreScan.acceptUpdate( indexUpdater, add( 1, index.schema(), "add" ), 0L ); - scanViewStoreScan.acceptUpdate( indexUpdater, change( 2, index.schema(), "changeBefore", "changeAfter" ), 0L ); - scanViewStoreScan.acceptUpdate( indexUpdater, change( 2, index.schema(), "changeBefore2", "changeAfter2" ), 0L ); - scanViewStoreScan.acceptUpdate( indexUpdater, remove( 3, index.schema(), "remove" ), 0L ); + scanViewStoreScan.acceptUpdate( indexUpdater, add( 1, index.schema(), Values.of( "add" ) ), 0L ); + scanViewStoreScan.acceptUpdate( indexUpdater, + change( 2, index.schema(), Values.of( "changeBefore" ), Values.of( "changeAfter" ) ), 0L ); + scanViewStoreScan.acceptUpdate( indexUpdater, + change( 2, index.schema(), Values.of( "changeBefore2" ), Values.of( "changeAfter2" ) ), 0L ); + scanViewStoreScan.acceptUpdate( indexUpdater, remove( 3, index.schema(), Values.of( "remove" ) ), 0L ); } private MultipleIndexPopulator.IndexPopulation getPopulation( LabelScanTestMultipleIndexPopulator indexPopulator ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreViewTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreViewTest.java index f72ab2383a30c..7ba5fe81adc98 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreViewTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/storeview/NeoStoreIndexStoreViewTest.java @@ -42,7 +42,6 @@ import org.neo4j.kernel.api.exceptions.KernelException; import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.labelscan.NodeLabelUpdate; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; import org.neo4j.kernel.impl.api.index.NodeUpdates; @@ -56,6 +55,8 @@ import org.neo4j.kernel.impl.store.record.RecordLoad; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.test.rule.EmbeddedDatabaseRule; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.util.Collections.emptySet; import static org.hamcrest.MatcherAssert.assertThat; @@ -173,8 +174,8 @@ public void shouldLockNodesWhileReadingThem() throws Exception @Test public void shouldReadProperties() throws EntityNotFoundException { - Property property = storeView.getProperty( alistair.getId(), propertyKeyId ); - assertTrue( property.valueEquals( "Alistair" ) ); + Value value = storeView.getPropertyValue( alistair.getId(), propertyKeyId ); + assertTrue( value.equals( Values.of( "Alistair" ) ) ); } @Test @@ -209,7 +210,7 @@ public void processAllNodeProperties() throws Exception NodeUpdates add( long nodeId, int propertyKeyId, Object value, long[] labels ) { - return NodeUpdates.forNode( nodeId, labels ).added( propertyKeyId, value ).build(); + return NodeUpdates.forNode( nodeId, labels ).added( propertyKeyId, Values.of( value ) ).build(); } private void createAlistairAndStefanNodes() diff --git a/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java b/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java index 475f91df58eb2..826dfc0272527 100644 --- a/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java +++ b/community/kernel/src/test/java/org/neo4j/unsafe/batchinsert/internal/BatchInsertTest.java @@ -85,11 +85,14 @@ import org.neo4j.kernel.impl.store.SchemaStorage; import org.neo4j.kernel.impl.store.SchemaStore; import org.neo4j.kernel.impl.store.UnderlyingStorageException; +import org.neo4j.kernel.impl.store.format.RecordGenerators; +import org.neo4j.kernel.impl.store.record.AbstractBaseRecord; import org.neo4j.kernel.impl.store.record.ConstraintRule; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.NodeRecord; import org.neo4j.kernel.impl.store.record.RecordLoad; +import org.neo4j.kernel.impl.traversal.AsOneStartBranchTest; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.kernel.lifecycle.Lifecycle; import org.neo4j.storageengine.api.schema.LabelScanReader; @@ -101,6 +104,8 @@ import org.neo4j.unsafe.batchinsert.BatchInserter; import org.neo4j.unsafe.batchinsert.BatchInserters; import org.neo4j.unsafe.batchinsert.BatchRelationship; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.lang.Integer.parseInt; import static java.lang.String.format; @@ -273,25 +278,25 @@ private GraphDatabaseService switchToEmbeddedGraphDatabaseService( BatchInserter public void shouldUpdateStringArrayPropertiesOnNodesUsingBatchInserter1() throws Exception { // Given - BatchInserter batchInserter = globalInserter; + BatchInserter inserter = globalInserter; String[] array1 = { "1" }; String[] array2 = { "a" }; - long id1 = batchInserter.createNode(map("array", array1)); - long id2 = batchInserter.createNode( map() ); + long id1 = inserter.createNode(map("array", array1)); + long id2 = inserter.createNode( map() ); // When - batchInserter.getNodeProperties( id1 ).get( "array" ); - batchInserter.setNodeProperty( id1, "array", array1 ); - batchInserter.setNodeProperty( id2, "array", array2 ); + inserter.getNodeProperties( id1 ).get( "array" ); + inserter.setNodeProperty( id1, "array", array1 ); + inserter.setNodeProperty( id2, "array", array2 ); - batchInserter.getNodeProperties( id1 ).get( "array" ); - batchInserter.setNodeProperty( id1, "array", array1 ); - batchInserter.setNodeProperty( id2, "array", array2 ); + inserter.getNodeProperties( id1 ).get( "array" ); + inserter.setNodeProperty( id1, "array", array1 ); + inserter.setNodeProperty( id2, "array", array2 ); // Then - assertThat( batchInserter.getNodeProperties( id1 ).get( "array" ), equalTo( array1 ) ); + assertThat( inserter.getNodeProperties( id1 ).get( "array" ), equalTo( Values.of( array1 ) ) ); } @Test @@ -316,7 +321,7 @@ public void testSetAndAddNodeProperties() throws Exception long tehNode = inserter.createNode( MapUtil.map( "one", "one" ,"two","two","three","three") ); inserter.setNodeProperty( tehNode, "four", "four" ); inserter.setNodeProperty( tehNode, "five", "five" ); - Map props = inserter.getNodeProperties( tehNode ); + Map props = getNodeProperties( inserter, tehNode ); assertEquals( 5, props.size() ); assertEquals( "one", props.get( "one" ) ); assertEquals( "five", props.get( "five" ) ); @@ -344,7 +349,7 @@ public void testSetAndKeepNodeProperty() throws Exception long tehNode = inserter.createNode( MapUtil.map( "foo", "bar" ) ); inserter.setNodeProperty( tehNode, "foo2", "bar2" ); - Map props = inserter.getNodeProperties( tehNode ); + Map props = getNodeProperties( inserter, tehNode ); assertEquals( 2, props.size() ); assertEquals( "bar", props.get( "foo" ) ); assertEquals( "bar2", props.get( "foo2" ) ); @@ -353,14 +358,14 @@ public void testSetAndKeepNodeProperty() throws Exception inserter = newBatchInserter(); - props = inserter.getNodeProperties( tehNode ); + props = getNodeProperties( inserter, tehNode ); assertEquals( 2, props.size() ); assertEquals( "bar", props.get( "foo" ) ); assertEquals( "bar2", props.get( "foo2" ) ); inserter.setNodeProperty( tehNode, "foo", "bar3" ); - props = inserter.getNodeProperties( tehNode ); + props = getNodeProperties( inserter, tehNode ); assertEquals( "bar3", props.get( "foo" ) ); assertEquals( 2, props.size() ); assertEquals( "bar3", props.get( "foo" ) ); @@ -369,7 +374,7 @@ public void testSetAndKeepNodeProperty() throws Exception inserter.shutdown(); inserter = newBatchInserter(); - props = inserter.getNodeProperties( tehNode ); + props = getNodeProperties( inserter, tehNode ); assertEquals( "bar3", props.get( "foo" ) ); assertEquals( 2, props.size() ); assertEquals( "bar3", props.get( "foo" ) ); @@ -389,7 +394,7 @@ public void testSetAndKeepRelationshipProperty() throws Exception RelationshipType.withName( "TestingPropsHere" ), MapUtil.map( "foo", "bar" ) ); inserter.setRelationshipProperty( theRel, "foo2", "bar2" ); - Map props = inserter.getRelationshipProperties( theRel ); + Map props = getRelationshipProperties( inserter, theRel ); assertEquals( 2, props.size() ); assertEquals( "bar", props.get( "foo" ) ); assertEquals( "bar2", props.get( "foo2" ) ); @@ -398,14 +403,14 @@ public void testSetAndKeepRelationshipProperty() throws Exception inserter = newBatchInserter(); - props = inserter.getRelationshipProperties( theRel ); + props = getRelationshipProperties( inserter, theRel ); assertEquals( 2, props.size() ); assertEquals( "bar", props.get( "foo" ) ); assertEquals( "bar2", props.get( "foo2" ) ); inserter.setRelationshipProperty( theRel, "foo", "bar3" ); - props = inserter.getRelationshipProperties( theRel ); + props = getRelationshipProperties( inserter, theRel ); assertEquals( "bar3", props.get( "foo" ) ); assertEquals( 2, props.size() ); assertEquals( "bar3", props.get( "foo" ) ); @@ -414,7 +419,7 @@ public void testSetAndKeepRelationshipProperty() throws Exception inserter.shutdown(); inserter = newBatchInserter(); - props = inserter.getRelationshipProperties( theRel ); + props = getRelationshipProperties( inserter, theRel ); assertEquals( "bar3", props.get( "foo" ) ); assertEquals( 2, props.size() ); assertEquals( "bar3", props.get( "foo" ) ); @@ -530,7 +535,7 @@ public void shouldBeAbleToOverwriteDynamicProperty() throws Exception batchInserter.setNodeProperty( nodeId, key, secondValue ); // THEN - assertTrue( Arrays.equals( secondValue, (String[]) batchInserter.getNodeProperties( nodeId ).get( key ) ) ); + assertTrue( Arrays.equals( secondValue, (String[]) getNodeProperties( batchInserter, nodeId ).get( key ) ) ); } @Test @@ -649,7 +654,7 @@ public void createEntitiesWithEmptyPropertiesMap() throws Exception // Assert for node long nodeId = inserter.createNode( map() ); - inserter.getNodeProperties( nodeId ); + getNodeProperties( inserter, nodeId ); //cp=N U http://www.w3.org/1999/02/22-rdf-syntax-ns#type, c=N // Assert for relationship @@ -938,7 +943,7 @@ public void shouldRunIndexPopulationJobAtShutdown() throws Throwable verify( provider ).start(); verify( provider ).getPopulator( anyLong(), any( IndexDescriptor.class ), any( IndexSamplingConfig.class ) ); verify( populator ).create(); - verify( populator ).add( IndexEntryUpdate.add( nodeId, internalIndex.schema(), "Jakewins" ) ); + verify( populator ).add( IndexEntryUpdate.add( nodeId, internalIndex.schema(), Values.of( "Jakewins" ) ) ); verify( populator ).verifyDeferredConstraints( any( PropertyAccessor.class ) ); verify( populator ).close( true ); verify( provider ).stop(); @@ -972,7 +977,8 @@ public void shouldRunConstraintPopulationJobAtShutdown() throws Throwable verify( provider ).start(); verify( provider ).getPopulator( anyLong(), any( IndexDescriptor.class ), any( IndexSamplingConfig.class ) ); verify( populator ).create(); - verify( populator ).add( IndexEntryUpdate.add( nodeId, internalUniqueIndex.schema(), "Jakewins" ) ); + verify( populator ).add( + IndexEntryUpdate.add( nodeId, internalUniqueIndex.schema(), Values.of( "Jakewins" ) ) ); verify( populator ).verifyDeferredConstraints( any( PropertyAccessor.class ) ); verify( populator ).close( true ); verify( provider ).stop(); @@ -1006,8 +1012,8 @@ public void shouldRepopulatePreexistingIndexed() throws Throwable verify( provider ).start(); verify( provider ).getPopulator( anyLong(), any( IndexDescriptor.class ), any( IndexSamplingConfig.class ) ); verify( populator ).create(); - verify( populator ).add( IndexEntryUpdate.add( jakewins, internalIndex.schema(), "Jakewins" ) ); - verify( populator ).add( IndexEntryUpdate.add( boggle, internalIndex.schema(), "b0ggl3" ) ); + verify( populator ).add( IndexEntryUpdate.add( jakewins, internalIndex.schema(), Values.of( "Jakewins" ) ) ); + verify( populator ).add( IndexEntryUpdate.add( boggle, internalIndex.schema(), Values.of( "b0ggl3" ) ) ); verify( populator ).verifyDeferredConstraints( any( PropertyAccessor.class ) ); verify( populator ).close( true ); verify( provider ).stop(); @@ -1079,8 +1085,8 @@ public void propertiesCanBeReSetUsingBatchInserter() throws Exception batchInserter.setNodeProperty( nodeId, "additional", "something" ); // THEN there should be no problems doing so - assertEquals( "YetAnotherOne", batchInserter.getNodeProperties( nodeId ).get( "name" ) ); - assertEquals( "something", batchInserter.getNodeProperties( nodeId ).get( "additional" ) ); + assertEquals( Values.of( "YetAnotherOne" ), batchInserter.getNodeProperties( nodeId ).get( "name" ) ); + assertEquals( Values.of( "something" ), batchInserter.getNodeProperties( nodeId ).get( "additional" ) ); } /** @@ -1115,17 +1121,17 @@ public void testCleanupEmptyPropertyRecords() throws Exception properties.put( "languages", new String[0] ); long personNodeId = inserter.createNode(properties); - assertEquals( "Shevchenko", inserter.getNodeProperties( personNodeId ).get( "lastName" ) ); - assertThat( (String[]) inserter.getNodeProperties( personNodeId ).get( "email" ), is( emptyArray() ) ); + assertEquals( "Shevchenko", getNodeProperties( inserter, personNodeId ).get( "lastName" ) ); + assertThat( (String[]) getNodeProperties( inserter, personNodeId ).get( "email" ), is( emptyArray() ) ); inserter.setNodeProperty( personNodeId, "email", new String[]{"Edward1099511659993@gmail.com"} ); - assertThat( (String[]) inserter.getNodeProperties( personNodeId ).get( "email" ), + assertThat( (String[]) getNodeProperties( inserter, personNodeId ).get( "email" ), arrayContaining( "Edward1099511659993@gmail.com" ) ); inserter.setNodeProperty( personNodeId, "email", new String[]{"Edward1099511659993@gmail.com", "backup@gmail.com"} ); - assertThat( (String[]) inserter.getNodeProperties( personNodeId ).get( "email" ), + assertThat( (String[]) getNodeProperties( inserter, personNodeId ).get( "email" ), arrayContaining( "Edward1099511659993@gmail.com", "backup@gmail.com" ) ); } @@ -1134,14 +1140,14 @@ public void propertiesCanBeReSetUsingBatchInserter2() throws Exception { // GIVEN BatchInserter batchInserter = globalInserter; - long id = batchInserter.createNode( new HashMap() ); + long id = batchInserter.createNode( new HashMap<>() ); // WHEN batchInserter.setNodeProperty( id, "test", "looooooooooong test" ); batchInserter.setNodeProperty( id, "test", "small test" ); // THEN - assertEquals( "small test", batchInserter.getNodeProperties( id ).get( "test" ) ); + assertEquals( Values.of( "small test" ), batchInserter.getNodeProperties( id ).get( "test" ) ); } @Test @@ -1160,7 +1166,7 @@ public void replaceWithBiggerPropertySpillsOverIntoNewPropertyRecord() throws Ex batchInserter.setNodeProperty( id, "count", "something" ); // THEN - assertEquals( "something", batchInserter.getNodeProperties( id ).get( "count" ) ); + assertEquals( Values.of( "something" ), batchInserter.getNodeProperties( id ).get( "count" ) ); } @Test @@ -1385,7 +1391,7 @@ public void uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfV catch ( RuntimeException ex ) { // good - assertEquals( new IndexEntryConflictException( 0, 1, value ), ex.getCause() ); + assertEquals( new IndexEntryConflictException( 0, 1, Values.of( value ) ), ex.getCause() ); } } @@ -1402,7 +1408,7 @@ public void shouldChangePropertiesInCurrentBatch() throws Exception inserter.setNodeProperties( node, properties ); // THEN - assertEquals( properties, inserter.getNodeProperties( node ) ); + assertEquals( properties, getNodeProperties( inserter, node ) ); } private void createRelationships( BatchInserter inserter, long node, RelationshipType relType, @@ -1588,15 +1594,8 @@ public Lifecycle newInstance( KernelContext context, NoDependencies dependencies private void setAndGet( BatchInserter inserter, Object value ) { long nodeId = inserter.createNode( map( "key", value ) ); - Object readValue = inserter.getNodeProperties( nodeId ).get( "key" ); - if ( readValue.getClass().isArray() ) - { - assertTrue( Arrays.equals( (int[])value, (int[])readValue ) ); - } - else - { - assertEquals( value, readValue ); - } + Value readValue = inserter.getNodeProperties( nodeId ).get( "key" ); + assertEquals( Values.of( value ), readValue ); } private int[] intArray( int length ) @@ -1652,4 +1651,26 @@ private Pair> manyLabels( int count ) } return Pair.of( labels, expectedLabelNames ); } + + private Map getNodeProperties( BatchInserter inserter, long nodeId ) + { + Map asValues = inserter.getNodeProperties( nodeId ); + return valueMapToObjectMap( asValues ); + } + + private Map getRelationshipProperties( BatchInserter inserter, long relId ) + { + Map asValues = inserter.getRelationshipProperties( relId ); + return valueMapToObjectMap( asValues ); + } + + private Map valueMapToObjectMap( Map asValues ) + { + Map asObjects = new HashMap<>(); + for ( Map.Entry entry : asValues.entrySet() ) + { + asObjects.put( entry.getKey(), entry.getValue().asPublic() ); + } + return asObjects; + } } diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReader.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReader.java index 8a6dd2e6bf622..102b441132f3c 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReader.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReader.java @@ -36,6 +36,7 @@ import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexSampler; +import org.neo4j.values.Value; /** * Index reader that is able to read/sample multiple partitions of a partitioned Lucene index. @@ -104,7 +105,7 @@ public synchronized IndexNotApplicableKernelException getCause() } @Override - public long countIndexedNodes( long nodeId, Object... propertyValues ) + public long countIndexedNodes( long nodeId, Value... propertyValues ) { return indexReaders.parallelStream() .mapToLong( reader -> reader.countIndexedNodes( nodeId, propertyValues ) ) diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReader.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReader.java index cbab091440892..321b2deaea421 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReader.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReader.java @@ -44,6 +44,7 @@ import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexSampler; +import org.neo4j.values.Value; import static org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure.NODE_ID_KEY; import static org.neo4j.kernel.api.schema.IndexQuery.IndexQueryType.exact; @@ -179,7 +180,7 @@ private PrimitiveLongIterator endsWith( String suffix ) } @Override - public long countIndexedNodes( long nodeId, Object... propertyValues ) + public long countIndexedNodes( long nodeId, Value... propertyValues ) { Query nodeIdQuery = new TermQuery( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ) ); Query valueQuery = LuceneDocumentStructure.newSeekQuery( propertyValues ); diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/CompositeDuplicateCheckingCollector.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/CompositeDuplicateCheckingCollector.java index c9dbaa92febdc..3324486a9fee1 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/CompositeDuplicateCheckingCollector.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/CompositeDuplicateCheckingCollector.java @@ -29,8 +29,8 @@ import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure; import org.neo4j.kernel.api.index.PropertyAccessor; -import org.neo4j.kernel.api.properties.Property; -import org.neo4j.kernel.api.schema.OrderedPropertyValues; +import org.neo4j.values.Value; +import org.neo4j.values.ValueTuple; public class CompositeDuplicateCheckingCollector extends DuplicateCheckingCollector { @@ -49,46 +49,44 @@ protected void doCollect( int doc ) throws IOException, KernelException, IndexEn { Document document = reader.document( doc ); long nodeId = LuceneDocumentStructure.getNodeId( document ); - Property[] properties = new Property[propertyKeyIds.length]; - Object[] values = new Object[propertyKeyIds.length]; - for ( int i = 0; i < properties.length; i++ ) + Value[] reference = new Value[propertyKeyIds.length]; + for ( int i = 0; i < reference.length; i++ ) { - properties[i] = accessor.getProperty( nodeId, propertyKeyIds[i] ); - values[i] = properties[i].value(); + reference[i] = accessor.getPropertyValue( nodeId, propertyKeyIds[i] ); } // We either have to find the first conflicting entry set element, // or append one for the property we just fetched: - CompositeEntrySet current = actualValues; + CompositeEntrySet currentEntrySet = actualValues; scan: do { for ( int i = 0; i < CompositeEntrySet.INCREMENT; i++ ) { - Object[] currentValues = current.values[i]; + Value[] currentValues = currentEntrySet.values[i]; - if ( current.nodeId[i] == StatementConstants.NO_SUCH_NODE ) + if ( currentEntrySet.nodeId[i] == StatementConstants.NO_SUCH_NODE ) { - current.values[i] = values; - current.nodeId[i] = nodeId; + currentEntrySet.values[i] = reference; + currentEntrySet.nodeId[i] = nodeId; if ( i == CompositeEntrySet.INCREMENT - 1 ) { - current.next = new CompositeEntrySet(); + currentEntrySet.next = new CompositeEntrySet(); } break scan; } - else if ( propertyValuesEqual( properties, currentValues ) ) + else if ( propertyValuesEqual( reference, currentValues ) ) { - throw new IndexEntryConflictException( current.nodeId[i], nodeId, - OrderedPropertyValues.ofUndefined( currentValues ) ); + throw new IndexEntryConflictException( + currentEntrySet.nodeId[i], nodeId, ValueTuple.of( currentValues ) ); } } - current = current.next; + currentEntrySet = currentEntrySet.next; } - while ( current != null ); + while ( currentEntrySet != null ); } - private boolean propertyValuesEqual( Property[] properties, Object[] values ) + private boolean propertyValuesEqual( Value[] properties, Value[] values ) { if ( properties.length != values.length ) { @@ -96,7 +94,7 @@ private boolean propertyValuesEqual( Property[] properties, Object[] values ) } for ( int i = 0; i < properties.length; i++ ) { - if ( !properties[i].valueEquals( values[i] ) ) + if ( !properties[i].equals( values[i] ) ) { return false; } @@ -125,7 +123,7 @@ private static class CompositeEntrySet { static final int INCREMENT = 10000; - Object[][] values = new Object[INCREMENT][]; + Value[][] values = new Value[INCREMENT][]; long[] nodeId = new long[INCREMENT]; CompositeEntrySet next; diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/DuplicateCheckingCollector.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/DuplicateCheckingCollector.java index bcefa8d7b44ff..5455f36aaf87d 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/DuplicateCheckingCollector.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/verification/DuplicateCheckingCollector.java @@ -32,7 +32,7 @@ import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure; import org.neo4j.kernel.api.index.PropertyAccessor; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.values.Value; public class DuplicateCheckingCollector extends SimpleCollector { @@ -75,36 +75,36 @@ protected void doCollect( int doc ) throws IOException, KernelException, IndexEn { Document document = reader.document( doc ); long nodeId = LuceneDocumentStructure.getNodeId( document ); - Property property = accessor.getProperty( nodeId, propertyKeyId ); + Value reference = accessor.getPropertyValue( nodeId, propertyKeyId ); // We either have to find the first conflicting entry set element, // or append one for the property we just fetched: - EntrySet current = actualValues; + EntrySet currentEntrySet = actualValues; scan: do { for ( int i = 0; i < EntrySet.INCREMENT; i++ ) { - Object value = current.value[i]; + Value value = currentEntrySet.value[i]; - if ( current.nodeId[i] == StatementConstants.NO_SUCH_NODE ) + if ( currentEntrySet.nodeId[i] == StatementConstants.NO_SUCH_NODE ) { - current.value[i] = property.value(); - current.nodeId[i] = nodeId; + currentEntrySet.value[i] = reference; + currentEntrySet.nodeId[i] = nodeId; if ( i == EntrySet.INCREMENT - 1 ) { - current.next = new EntrySet(); + currentEntrySet.next = new EntrySet(); } break scan; } - else if ( property.valueEquals( value ) ) + else if ( reference.equals( value ) ) { - throw new IndexEntryConflictException( current.nodeId[i], nodeId, value ); + throw new IndexEntryConflictException( currentEntrySet.nodeId[i], nodeId, value ); } } - current = current.next; + currentEntrySet = currentEntrySet.next; } - while ( current != null ); + while ( currentEntrySet != null ); } @Override @@ -134,7 +134,7 @@ private static class EntrySet { static final int INCREMENT = 10000; - Object[] value = new Object[INCREMENT]; + Value[] value = new Value[INCREMENT]; long[] nodeId = new long[INCREMENT]; EntrySet next; diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulationIT.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulationIT.java index cdb8ea181446a..5efef4f05adbe 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulationIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexPopulationIT.java @@ -46,6 +46,7 @@ import org.neo4j.storageengine.api.schema.IndexSampler; import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.fs.DefaultFileSystemRule; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -137,6 +138,6 @@ private void generateUpdates( LuceneIndexAccessor indexAccessor, int nodesToUpda private IndexEntryUpdate add( long nodeId, Object value ) { - return IndexEntryUpdate.add( nodeId, descriptor.schema(), value ); + return IndexEntryUpdate.add( nodeId, descriptor.schema(), Values.of( value ) ); } } diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexUniquenessVerificationIT.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexUniquenessVerificationIT.java index 3effe23245929..ea14497c5e0f0 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexUniquenessVerificationIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/LuceneSchemaIndexUniquenessVerificationIT.java @@ -32,13 +32,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.IntStream; import org.neo4j.function.Factory; -import org.neo4j.helpers.ArrayUtil; import org.neo4j.helpers.Exceptions; import org.neo4j.helpers.Strings; import org.neo4j.io.IOUtils; @@ -48,12 +46,13 @@ import org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexBuilder; import org.neo4j.kernel.api.impl.schema.SchemaIndex; import org.neo4j.kernel.api.index.PropertyAccessor; -import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; import org.neo4j.test.Randoms; import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.fs.DefaultFileSystemRule; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.util.stream.Collectors.toSet; import static org.hamcrest.Matchers.instanceOf; @@ -106,7 +105,7 @@ public void resetPartitionSize() throws IOException @Test public void stringValuesWithoutDuplicates() throws IOException { - Set data = randomStrings(); + Set data = randomStrings(); insert( data ); @@ -116,7 +115,7 @@ public void stringValuesWithoutDuplicates() throws IOException @Test public void stringValuesWithDuplicates() throws IOException { - List data = withDuplicate( randomStrings() ); + List data = withDuplicate( randomStrings() ); insert( data ); @@ -128,7 +127,7 @@ public void smallLongValuesWithoutDuplicates() throws IOException { long min = randomLongInRange( 100, 10_000 ); long max = min + nodesToCreate; - Set data = randomLongs( min, max ); + Set data = randomLongs( min, max ); insert( data ); @@ -140,7 +139,7 @@ public void smallLongValuesWithDuplicates() throws IOException { long min = randomLongInRange( 100, 10_000 ); long max = min + nodesToCreate; - List data = withDuplicate( randomLongs( min, max ) ); + List data = withDuplicate( randomLongs( min, max ) ); insert( data ); @@ -152,7 +151,7 @@ public void largeLongValuesWithoutDuplicates() throws IOException { long max = randomLongInRange( MIN_LONG_VALUE, MAX_LONG_VALUE ); long min = max - nodesToCreate; - Set data = randomLongs( min, max ); + Set data = randomLongs( min, max ); insert( data ); @@ -164,7 +163,7 @@ public void largeLongValuesWithDuplicates() throws IOException { long max = randomLongInRange( MIN_LONG_VALUE, MAX_LONG_VALUE ); long min = max - nodesToCreate; - List data = withDuplicate( randomLongs( min, max ) ); + List data = withDuplicate( randomLongs( min, max ) ); insert( data ); @@ -176,7 +175,7 @@ public void smallDoubleValuesWithoutDuplicates() throws IOException { double min = randomDoubleInRange( 100, 10_000 ); double max = min + nodesToCreate; - Set data = randomDoubles( min, max ); + Set data = randomDoubles( min, max ); insert( data ); @@ -188,7 +187,7 @@ public void smallDoubleValuesWithDuplicates() throws IOException { double min = randomDoubleInRange( 100, 10_000 ); double max = min + nodesToCreate; - List data = withDuplicate( randomDoubles( min, max ) ); + List data = withDuplicate( randomDoubles( min, max ) ); insert( data ); @@ -200,7 +199,7 @@ public void largeDoubleValuesWithoutDuplicates() throws IOException { double max = randomDoubleInRange( Double.MAX_VALUE / 2, Double.MAX_VALUE ); double min = max / 2; - Set data = randomDoubles( min, max ); + Set data = randomDoubles( min, max ); insert( data ); @@ -212,7 +211,7 @@ public void largeDoubleValuesWithDuplicates() throws IOException { double max = randomDoubleInRange( Double.MAX_VALUE / 2, Double.MAX_VALUE ); double min = max / 2; - List data = withDuplicate( randomDoubles( min, max ) ); + List data = withDuplicate( randomDoubles( min, max ) ); insert( data ); @@ -222,7 +221,7 @@ public void largeDoubleValuesWithDuplicates() throws IOException @Test public void smallArrayValuesWithoutDuplicates() throws IOException { - Set data = randomArrays( 3, 7 ); + Set data = randomArrays( 3, 7 ); insert( data ); @@ -232,7 +231,7 @@ public void smallArrayValuesWithoutDuplicates() throws IOException @Test public void smallArrayValuesWithDuplicates() throws IOException { - List data = withDuplicate( randomArrays( 3, 7 ) ); + List data = withDuplicate( randomArrays( 3, 7 ) ); insert( data ); @@ -242,7 +241,7 @@ public void smallArrayValuesWithDuplicates() throws IOException @Test public void largeArrayValuesWithoutDuplicates() throws IOException { - Set data = randomArrays( 70, 100 ); + Set data = randomArrays( 70, 100 ); insert( data ); @@ -252,7 +251,7 @@ public void largeArrayValuesWithoutDuplicates() throws IOException @Test public void largeArrayValuesWithDuplicates() throws IOException { - List data = withDuplicate( randomArrays( 70, 100 ) ); + List data = withDuplicate( randomArrays( 70, 100 ) ); insert( data ); @@ -262,7 +261,7 @@ public void largeArrayValuesWithDuplicates() throws IOException @Test public void variousValuesWithoutDuplicates() throws IOException { - Set data = randomPropertyValues(); + Set data = randomValues(); insert( data ); @@ -272,25 +271,25 @@ public void variousValuesWithoutDuplicates() throws IOException @Test public void variousValuesWitDuplicates() throws IOException { - List data = withDuplicate( randomPropertyValues() ); + List data = withDuplicate( randomValues() ); insert( data ); assertUniquenessConstraintFails( data ); } - private void insert( Collection data ) throws IOException + private void insert( Collection data ) throws IOException { - PropertyValue[] dataArray = data.toArray( new PropertyValue[data.size()] ); + Value[] dataArray = data.toArray( new Value[data.size()] ); for ( int i = 0; i < dataArray.length; i++ ) { - Document doc = LuceneDocumentStructure.documentRepresentingProperties( i, dataArray[i].value ); + Document doc = LuceneDocumentStructure.documentRepresentingProperties( i, dataArray[i].asPublic() ); index.getIndexWriter().addDocument( doc ); } index.maybeRefreshBlocking(); } - private void assertUniquenessConstraintHolds( Collection data ) + private void assertUniquenessConstraintHolds( Collection data ) { try { @@ -303,7 +302,7 @@ private void assertUniquenessConstraintHolds( Collection data ) } } - private void assertUniquenessConstraintFails( Collection data ) + private void assertUniquenessConstraintFails( Collection data ) { try { @@ -317,19 +316,18 @@ private void assertUniquenessConstraintFails( Collection data ) } } - private void verifyUniqueness( Collection data ) throws IOException, IndexEntryConflictException + private void verifyUniqueness( Collection data ) throws IOException, IndexEntryConflictException { - Object[] propertyValues = data.stream().map( property -> property.value ).toArray(); - PropertyAccessor propertyAccessor = new TestPropertyAccessor( propertyValues ); + PropertyAccessor propertyAccessor = new TestPropertyAccessor( new ArrayList<>( data ) ); index.verifyUniqueness( propertyAccessor, new int[]{PROPERTY_KEY_ID} ); } - private Set randomStrings() + private Set randomStrings() { return ThreadLocalRandom.current() .ints( nodesToCreate, 1, 200 ) .mapToObj( this::randomString ) - .map( PropertyValue::new ) + .map( Values::of ) .collect( toSet() ); } @@ -340,47 +338,47 @@ private String randomString( int size ) : RandomStringUtils.randomAlphabetic( size ); } - private Set randomLongs( long min, long max ) + private Set randomLongs( long min, long max ) { return ThreadLocalRandom.current() .longs( nodesToCreate, min, max ) .boxed() - .map( PropertyValue::new ) + .map( Values::of ) .collect( toSet() ); } - private Set randomDoubles( double min, double max ) + private Set randomDoubles( double min, double max ) { return ThreadLocalRandom.current() .doubles( nodesToCreate, min, max ) .boxed() - .map( PropertyValue::new ) + .map( Values::of ) .collect( toSet() ); } - private Set randomArrays( int minLength, int maxLength ) + private Set randomArrays( int minLength, int maxLength ) { Randoms randoms = new Randoms( ThreadLocalRandom.current(), new ArraySizeConfig( minLength, maxLength ) ); return IntStream.range( 0, nodesToCreate ) .mapToObj( i -> randoms.array() ) - .map( PropertyValue::new ) + .map( Values::of ) .collect( toSet() ); } - private Set randomPropertyValues() + private Set randomValues() { Randoms randoms = new Randoms( ThreadLocalRandom.current(), new ArraySizeConfig( 5, 100 ) ); return IntStream.range( 0, nodesToCreate ) .mapToObj( i -> randoms.propertyValue() ) - .map( PropertyValue::new ) + .map( Values::of ) .collect( toSet() ); } - private static List withDuplicate( Set set ) + private static List withDuplicate( Set set ) { - List data = new ArrayList<>( set ); + List data = new ArrayList<>( set ); if ( data.isEmpty() ) { throw new IllegalStateException(); @@ -398,15 +396,15 @@ else if ( data.size() == 1 ) duplicateValueIndex = ThreadLocalRandom.current().nextInt( data.size() ); } while ( duplicateValueIndex == duplicateIndex ); - PropertyValue duplicate = duplicatePropertyValue( data.get( duplicateValueIndex ) ); + Value duplicate = duplicateValue( data.get( duplicateValueIndex ) ); data.set( duplicateIndex, duplicate ); } return data; } - private static PropertyValue duplicatePropertyValue( PropertyValue propertyValue ) + private static Value duplicateValue( Value propertyValue ) { - return new PropertyValue( propertyValue.value ); + return Values.of( propertyValue.asPublic() ); } private static int randomIntInRange( int min, int max ) @@ -448,54 +446,6 @@ public int arrayMaxLength() } } - /** - * This class is used to implement correct equals and hashCode for property values of numeric and array types. - */ - private static class PropertyValue - { - final Object value; - - PropertyValue( Object value ) - { - this.value = Objects.requireNonNull( value ); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - PropertyValue that = (PropertyValue) o; - return Property.property( PROPERTY_KEY_ID, value ).valueEquals( that.value ); - } - - @Override - public int hashCode() - { - if ( value instanceof Number ) - { - return Double.hashCode( ((Number) value).doubleValue() ); - } - else if ( value.getClass().isArray() ) - { - return ArrayUtil.hashCode( value ); - } - return value.hashCode(); - } - - @Override - public String toString() - { - return Strings.prettyPrint( value ); - } - } - private static class TestConfigFactory implements Factory { diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/TestPropertyAccessor.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/TestPropertyAccessor.java index 306f7f498a423..06510bb154c18 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/TestPropertyAccessor.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/TestPropertyAccessor.java @@ -19,21 +19,24 @@ */ package org.neo4j.kernel.api.impl.index; +import java.util.List; + import org.neo4j.kernel.api.index.PropertyAccessor; -import org.neo4j.kernel.api.properties.Property; +import org.neo4j.values.Value; +import org.neo4j.values.Values; public class TestPropertyAccessor implements PropertyAccessor { - private final Object[] propertyValues; + private final List propertyValues; - public TestPropertyAccessor( Object[] propertyValues ) + public TestPropertyAccessor( List propertyValues ) { this.propertyValues = propertyValues; } @Override - public Property getProperty( long nodeId, int propertyKeyId ) + public Value getPropertyValue( long nodeId, int propertyKeyId ) { - return Property.property( propertyKeyId, propertyValues[(int) nodeId] ); + return Values.of( propertyValues.get( (int)nodeId ) ); } } diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/verification/SimpleUniquenessVerifierTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/verification/SimpleUniquenessVerifierTest.java index e8e7113fd2a21..fca489d3f074d 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/verification/SimpleUniquenessVerifierTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/index/verification/SimpleUniquenessVerifierTest.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.util.List; +import java.util.stream.Collectors; import org.neo4j.io.IOUtils; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; @@ -46,6 +47,8 @@ import org.neo4j.kernel.api.impl.schema.verification.UniquenessVerifier; import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.test.rule.TestDirectory; +import org.neo4j.values.Value; +import org.neo4j.values.Values; import static java.util.Arrays.asList; import static org.hamcrest.Matchers.instanceOf; @@ -285,7 +288,10 @@ private void insert( List data ) throws IOException private PropertyAccessor newPropertyAccessor( List propertyValues ) { - return new TestPropertyAccessor( propertyValues.toArray() ); + return new TestPropertyAccessor( + propertyValues.stream() + .map( Values::of ) + .collect( Collectors.toList() ) ); } private UniquenessVerifier newSimpleUniquenessVerifier() throws IOException diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/AccessUniqueDatabaseIndexTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/AccessUniqueDatabaseIndexTest.java index ed1d63ba84742..4c3a5ed38482a 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/AccessUniqueDatabaseIndexTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/AccessUniqueDatabaseIndexTest.java @@ -32,6 +32,7 @@ import org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage; import org.neo4j.kernel.api.index.IndexAccessor; import org.neo4j.kernel.api.index.IndexEntryUpdate; +import org.neo4j.kernel.api.index.IndexQueryHelper; import org.neo4j.kernel.api.index.IndexUpdater; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; @@ -149,17 +150,17 @@ private PartitionedIndexStorage getIndexStorage() throws IOException private IndexEntryUpdate add( long nodeId, Object propertyValue ) { - return IndexEntryUpdate.add( nodeId, index.schema(), propertyValue ); + return IndexQueryHelper.add( nodeId, index.schema(), propertyValue ); } private IndexEntryUpdate change( long nodeId, Object oldValue, Object newValue ) { - return IndexEntryUpdate.change( nodeId, index.schema(), oldValue, newValue ); + return IndexQueryHelper.change( nodeId, index.schema(), oldValue, newValue ); } private IndexEntryUpdate remove( long nodeId, Object oldValue ) { - return IndexEntryUpdate.remove( nodeId, index.schema(), oldValue ); + return IndexQueryHelper.remove( nodeId, index.schema(), oldValue ); } private List getAllNodes( PartitionedIndexStorage indexStorage, String propertyValue ) throws IOException diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseCompositeIndexAccessorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseCompositeIndexAccessorTest.java index 7a7898c9f0f13..e01f8854a103b 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseCompositeIndexAccessorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseCompositeIndexAccessorTest.java @@ -42,6 +42,7 @@ import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory; import org.neo4j.kernel.api.index.IndexEntryUpdate; +import org.neo4j.kernel.api.index.IndexQueryHelper; import org.neo4j.kernel.api.index.IndexUpdater; import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.api.schema.index.IndexDescriptor; @@ -261,17 +262,17 @@ public void shouldStopSamplingWhenIndexIsDropped() throws Exception private IndexEntryUpdate add( long nodeId, Object... values ) { - return IndexEntryUpdate.add( nodeId, indexDescriptor.schema(), values ); + return IndexQueryHelper.add( nodeId, indexDescriptor.schema(), values ); } private IndexEntryUpdate remove( long nodeId, Object... values ) { - return IndexEntryUpdate.remove( nodeId, indexDescriptor.schema(), values ); + return IndexQueryHelper.remove( nodeId, indexDescriptor.schema(), values ); } private IndexEntryUpdate change( long nodeId, Object[] valuesBefore, Object[] valuesAfter ) { - return IndexEntryUpdate.change( nodeId, indexDescriptor.schema(), valuesBefore, valuesAfter ); + return IndexQueryHelper.change( nodeId, indexDescriptor.schema(), valuesBefore, valuesAfter ); } private void updateAndCommit( List nodePropertyUpdates ) diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseIndexAccessorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseIndexAccessorTest.java index cc956122e5007..aa6709a3a0ac1 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseIndexAccessorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/DatabaseIndexAccessorTest.java @@ -42,6 +42,7 @@ import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory; import org.neo4j.kernel.api.index.IndexEntryUpdate; +import org.neo4j.kernel.api.index.IndexQueryHelper; import org.neo4j.kernel.api.index.IndexUpdater; import org.neo4j.kernel.api.schema.IndexQuery; import org.neo4j.kernel.api.schema.index.IndexDescriptor; @@ -330,17 +331,17 @@ public void shouldStopSamplingWhenIndexIsDropped() throws Exception private IndexEntryUpdate add( long nodeId, Object value ) { - return IndexEntryUpdate.add( nodeId, index.schema(), value ); + return IndexQueryHelper.add( nodeId, index.schema(), value ); } private IndexEntryUpdate remove( long nodeId, Object value ) { - return IndexEntryUpdate.remove( nodeId, index.schema(), value ); + return IndexQueryHelper.remove( nodeId, index.schema(), value ); } private IndexEntryUpdate change( long nodeId, Object valueBefore, Object valueAfter ) { - return IndexEntryUpdate.change( nodeId, index.schema(), valueBefore, valueAfter ); + return IndexQueryHelper.change( nodeId, index.schema(), valueBefore, valueAfter ); } private void updateAndCommit( List nodePropertyUpdates ) diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexIT.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexIT.java index 75c7830e25dc7..56eacdd0a7639 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexIT.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexIT.java @@ -46,6 +46,7 @@ import org.neo4j.kernel.impl.api.index.IndexUpdateMode; import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.fs.DefaultFileSystemRule; +import org.neo4j.values.Values; import static java.util.Collections.emptySet; import static org.hamcrest.core.IsEqual.equalTo; @@ -309,7 +310,7 @@ private void generateUpdates( LuceneIndexAccessor indexAccessor, int nodesToUpda private IndexEntryUpdate add( long nodeId, Object value ) { - return IndexEntryUpdate.add( nodeId, descriptor.schema(), value ); + return IndexEntryUpdate.add( nodeId, descriptor.schema(), Values.of( value ) ); } } diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexPopulatorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexPopulatorTest.java index fa17f130f549e..db851d96e7998 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexPopulatorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/LuceneSchemaIndexPopulatorTest.java @@ -40,6 +40,7 @@ import org.neo4j.kernel.api.impl.index.storage.DirectoryFactory; import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.IndexPopulator; +import org.neo4j.kernel.api.index.IndexQueryHelper; import org.neo4j.kernel.api.index.IndexUpdater; import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.index.PropertyAccessor; @@ -255,17 +256,17 @@ private static class Hit private IndexEntryUpdate add( long nodeId, Object value ) { - return IndexEntryUpdate.add( nodeId, index.schema(), value ); + return IndexQueryHelper.add( nodeId, index.schema(), value ); } private IndexEntryUpdate change( long nodeId, Object valueBefore, Object valueAfter ) { - return IndexEntryUpdate.change( nodeId, index.schema(), valueBefore, valueAfter ); + return IndexQueryHelper.change( nodeId, index.schema(), valueBefore, valueAfter ); } private IndexEntryUpdate remove( long nodeId, Object removedValue ) { - return IndexEntryUpdate.remove( nodeId, index.schema(), removedValue ); + return IndexQueryHelper.remove( nodeId, index.schema(), removedValue ); } private void assertIndexedValues( Hit... expectedHits ) throws IOException @@ -297,7 +298,7 @@ private void switchToVerification() throws IOException private static void addUpdate( IndexPopulator populator, long nodeId, Object value ) throws IOException, IndexEntryConflictException { - populator.add( Collections.singletonList( IndexEntryUpdate.add( nodeId, index.schema(), value ) ) ); + populator.add( Collections.singletonList( IndexQueryHelper.add( nodeId, index.schema(), value ) ) ); } private static void updatePopulator( diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatingUpdaterTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatingUpdaterTest.java index 7db9998902e2c..cafe220e94d2a 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatingUpdaterTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatingUpdaterTest.java @@ -27,6 +27,7 @@ import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure; import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter; +import org.neo4j.kernel.api.index.IndexQueryHelper; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; import org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler; @@ -43,9 +44,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure.newTermForChangeOrRemove; -import static org.neo4j.kernel.api.index.IndexEntryUpdate.add; -import static org.neo4j.kernel.api.index.IndexEntryUpdate.change; -import static org.neo4j.kernel.api.index.IndexEntryUpdate.remove; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; +import static org.neo4j.kernel.api.index.IndexQueryHelper.change; +import static org.neo4j.kernel.api.index.IndexQueryHelper.remove; public class NonUniqueDatabaseIndexPopulatingUpdaterTest { diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatorTest.java index 4cbb3800cbd54..80b60d8df4f84 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/NonUniqueDatabaseIndexPopulatorTest.java @@ -50,6 +50,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; public class NonUniqueDatabaseIndexPopulatorTest { @@ -102,9 +103,9 @@ public void sampleIncludedUpdates() throws Exception populator = newPopulator(); List updates = Arrays.asList( - IndexEntryUpdate.add( 1, labelSchemaDescriptor, "aaa" ), - IndexEntryUpdate.add( 2, labelSchemaDescriptor, "bbb" ), - IndexEntryUpdate.add( 3, labelSchemaDescriptor, "ccc" ) ); + add( 1, labelSchemaDescriptor, "aaa" ), + add( 2, labelSchemaDescriptor, "bbb" ), + add( 3, labelSchemaDescriptor, "ccc" ) ); updates.forEach( populator::includeSample ); @@ -119,9 +120,9 @@ public void sampleIncludedUpdatesWithDuplicates() throws Exception populator = newPopulator(); List updates = Arrays.asList( - IndexEntryUpdate.add( 1, labelSchemaDescriptor, "foo" ), - IndexEntryUpdate.add( 2, labelSchemaDescriptor, "bar" ), - IndexEntryUpdate.add( 3, labelSchemaDescriptor, "foo" ) ); + add( 1, labelSchemaDescriptor, "foo" ), + add( 2, labelSchemaDescriptor, "bar" ), + add( 3, labelSchemaDescriptor, "foo" ) ); updates.forEach( populator::includeSample ); @@ -136,9 +137,9 @@ public void addUpdates() throws Exception populator = newPopulator(); List> updates = Arrays.asList( - IndexEntryUpdate.add( 1, labelSchemaDescriptor, "foo" ), - IndexEntryUpdate.add( 2, labelSchemaDescriptor, "bar" ), - IndexEntryUpdate.add( 42, labelSchemaDescriptor, "bar" ) ); + add( 1, labelSchemaDescriptor, "foo" ), + add( 2, labelSchemaDescriptor, "bar" ), + add( 42, labelSchemaDescriptor, "bar" ) ); populator.add( updates ); diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatingUpdaterTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatingUpdaterTest.java index 719aaba565734..1ae536e805bf1 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatingUpdaterTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatingUpdaterTest.java @@ -28,6 +28,7 @@ import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure; import org.neo4j.kernel.api.impl.schema.SchemaIndex; import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter; +import org.neo4j.kernel.api.index.IndexQueryHelper; import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; @@ -44,9 +45,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure.newTermForChangeOrRemove; -import static org.neo4j.kernel.api.index.IndexEntryUpdate.add; -import static org.neo4j.kernel.api.index.IndexEntryUpdate.change; -import static org.neo4j.kernel.api.index.IndexEntryUpdate.remove; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; +import static org.neo4j.kernel.api.index.IndexQueryHelper.change; +import static org.neo4j.kernel.api.index.IndexQueryHelper.remove; public class UniqueDatabaseIndexPopulatingUpdaterTest { diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatorTest.java index 019907e05ccb7..0557be1d310ad 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/populator/UniqueDatabaseIndexPopulatorTest.java @@ -55,6 +55,7 @@ import org.neo4j.test.rule.CleanupRule; import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.fs.DefaultFileSystemRule; +import org.neo4j.values.Values; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.SECONDS; @@ -64,9 +65,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.neo4j.kernel.api.impl.schema.AllNodesCollector.getAllNodes; -import static org.neo4j.kernel.api.properties.Property.intProperty; -import static org.neo4j.kernel.api.properties.Property.longProperty; -import static org.neo4j.kernel.api.properties.Property.stringProperty; +import static org.neo4j.kernel.api.index.IndexQueryHelper.add; +import static org.neo4j.kernel.api.index.IndexQueryHelper.change; +import static org.neo4j.kernel.api.index.IndexQueryHelper.remove; public class UniqueDatabaseIndexPopulatorTest { @@ -151,7 +152,7 @@ public void shouldUpdateEntryForNodeThatHasAlreadyBeenIndexed() throws Exception // when IndexUpdater updater = populator.newPopulatingUpdater( propertyAccessor ); - updater.process( IndexEntryUpdate.change( 1, schemaDescriptor, "value1", "value2" ) ); + updater.process( change( 1, schemaDescriptor, "value1", "value2" ) ); populator.close( true ); @@ -171,8 +172,8 @@ public void shouldUpdateEntryForNodeThatHasPropertyRemovedAndThenAddedAgain() th // when IndexUpdater updater = populator.newPopulatingUpdater( propertyAccessor ); - updater.process( IndexEntryUpdate.remove( 1, schemaDescriptor, "value1" ) ); - updater.process( IndexEntryUpdate.add( 1, schemaDescriptor, "value1" ) ); + updater.process( remove( 1, schemaDescriptor, "value1" ) ); + updater.process( add( 1, schemaDescriptor, "value1" ) ); populator.close( true ); @@ -191,7 +192,7 @@ public void shouldRemoveEntryForNodeThatHasAlreadyBeenIndexed() throws Exception // when IndexUpdater updater = populator.newPopulatingUpdater( propertyAccessor ); - updater.process( IndexEntryUpdate.remove( 1, schemaDescriptor, "value1" ) ); + updater.process( remove( 1, schemaDescriptor, "value1" ) ); populator.close( true ); @@ -211,8 +212,8 @@ public void shouldBeAbleToHandleSwappingOfIndexValues() throws Exception // when IndexUpdater updater = populator.newPopulatingUpdater( propertyAccessor ); - updater.process( IndexEntryUpdate.change( 1, schemaDescriptor, "value1", "value2" ) ); - updater.process( IndexEntryUpdate.change( 2, schemaDescriptor, "value2", "value1" ) ); + updater.process( change( 1, schemaDescriptor, "value1", "value2" ) ); + updater.process( change( 2, schemaDescriptor, "value2", "value1" ) ); populator.close( true ); @@ -232,10 +233,8 @@ public void shouldFailAtVerificationStageWithAlreadyIndexedStringValue() throws addUpdate( populator, 2, "value2" ); addUpdate( populator, 3, value ); - when( propertyAccessor.getProperty( 1, PROPERTY_KEY_ID ) ).thenReturn( - stringProperty( PROPERTY_KEY_ID, value ) ); - when( propertyAccessor.getProperty( 3, PROPERTY_KEY_ID ) ).thenReturn( - stringProperty( PROPERTY_KEY_ID, value ) ); + when( propertyAccessor.getPropertyValue( 1, PROPERTY_KEY_ID ) ).thenReturn( Values.of( value ) ); + when( propertyAccessor.getPropertyValue( 3, PROPERTY_KEY_ID ) ).thenReturn( Values.of( value ) ); // when try @@ -263,8 +262,8 @@ public void shouldFailAtVerificationStageWithAlreadyIndexedNumberValue() throws addUpdate( populator, 2, 2 ); addUpdate( populator, 3, 1 ); - when( propertyAccessor.getProperty( 1, PROPERTY_KEY_ID ) ).thenReturn( intProperty( PROPERTY_KEY_ID, 1 ) ); - when( propertyAccessor.getProperty( 3, PROPERTY_KEY_ID ) ).thenReturn( intProperty( PROPERTY_KEY_ID, 1 ) ); + when( propertyAccessor.getPropertyValue( 1, PROPERTY_KEY_ID ) ).thenReturn( Values.of( 1 ) ); + when( propertyAccessor.getPropertyValue( 3, PROPERTY_KEY_ID ) ).thenReturn( Values.of( 1 ) ); // when try @@ -291,16 +290,16 @@ public void shouldRejectDuplicateEntryWhenUsingPopulatingUpdater() throws Except addUpdate( populator, 1, "value1" ); addUpdate( populator, 2, "value2" ); - when( propertyAccessor.getProperty( 1, PROPERTY_KEY_ID ) ).thenReturn( - stringProperty( PROPERTY_KEY_ID, "value1" ) ); - when( propertyAccessor.getProperty( 3, PROPERTY_KEY_ID ) ).thenReturn( - stringProperty( PROPERTY_KEY_ID, "value1" ) ); + when( propertyAccessor.getPropertyValue( 1, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( "value1" ) ); + when( propertyAccessor.getPropertyValue( 3, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( "value1" ) ); // when try { IndexUpdater updater = populator.newPopulatingUpdater( propertyAccessor ); - updater.process( IndexEntryUpdate.add( 3, schemaDescriptor, "value1" ) ); + updater.process( add( 3, schemaDescriptor, "value1" ) ); updater.close(); fail( "should have thrown exception" ); @@ -322,13 +321,13 @@ public void shouldRejectDuplicateEntryAfterUsingPopulatingUpdater() throws Excep String value = "value1"; IndexUpdater updater = populator.newPopulatingUpdater( propertyAccessor ); - updater.process( IndexEntryUpdate.add( 1, schemaDescriptor, value ) ); + updater.process( add( 1, schemaDescriptor, value ) ); addUpdate( populator, 2, value ); - when( propertyAccessor.getProperty( 1, PROPERTY_KEY_ID ) ).thenReturn( - stringProperty( PROPERTY_KEY_ID, value ) ); - when( propertyAccessor.getProperty( 2, PROPERTY_KEY_ID ) ).thenReturn( - stringProperty( PROPERTY_KEY_ID, value ) ); + when( propertyAccessor.getPropertyValue( 1, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( value ) ); + when( propertyAccessor.getPropertyValue( 2, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( value ) ); // when try @@ -352,12 +351,12 @@ public void shouldNotRejectDuplicateEntryOnSameNodeIdAfterUsingPopulatingUpdater // given populator = newPopulator(); - when( propertyAccessor.getProperty( 1, PROPERTY_KEY_ID ) ).thenReturn( - stringProperty( PROPERTY_KEY_ID, "value1" ) ); + when( propertyAccessor.getPropertyValue( 1, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( "value1" ) ); IndexUpdater updater = populator.newPopulatingUpdater( propertyAccessor ); - updater.process( IndexEntryUpdate.add( 1, schemaDescriptor, "value1" ) ); - updater.process( IndexEntryUpdate.change( 1, schemaDescriptor, "value1", "value1" ) ); + updater.process( add( 1, schemaDescriptor, "value1" ) ); + updater.process( change( 1, schemaDescriptor, "value1", "value1" ) ); updater.close(); addUpdate( populator, 2, "value2" ); addUpdate( populator, 3, "value3" ); @@ -384,10 +383,8 @@ public void shouldNotRejectIndexCollisionsCausedByPrecisionLossAsDuplicates() th addUpdate( populator, 3, 1000000000000000001L ); // ... but the actual data in the store does not collide - when( propertyAccessor.getProperty( 1, PROPERTY_KEY_ID ) ).thenReturn( - longProperty( PROPERTY_KEY_ID, 1000000000000000001L ) ); - when( propertyAccessor.getProperty( 3, PROPERTY_KEY_ID ) ).thenReturn( - longProperty( PROPERTY_KEY_ID, 1000000000000000002L ) ); + when( propertyAccessor.getPropertyValue( 1, PROPERTY_KEY_ID ) ).thenReturn( Values.of( 1000000000000000001L ) ); + when( propertyAccessor.getPropertyValue( 3, PROPERTY_KEY_ID ) ).thenReturn( Values.of( 1000000000000000002L ) ); // Then our verification should NOT fail: populator.verifyDeferredConstraints( propertyAccessor ); @@ -404,15 +401,15 @@ public void shouldCheckAllCollisionsFromPopulatorAdd() throws Exception for ( int nodeId = 0; nodeId < iterations; nodeId++ ) { - updater.process( IndexEntryUpdate.add( nodeId, schemaDescriptor, 1 ) ); - when( propertyAccessor.getProperty( nodeId, PROPERTY_KEY_ID ) ).thenReturn( - intProperty( PROPERTY_KEY_ID, nodeId ) ); + updater.process( add( nodeId, schemaDescriptor, 1 ) ); + when( propertyAccessor.getPropertyValue( nodeId, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( nodeId ) ); } // ... and the actual conflicting property: - updater.process( IndexEntryUpdate.add( iterations, schemaDescriptor, 1 ) ); - when( propertyAccessor.getProperty( iterations, PROPERTY_KEY_ID ) ).thenReturn( - intProperty( PROPERTY_KEY_ID, 1 ) ); // This collision is real!!! + updater.process( add( iterations, schemaDescriptor, 1 ) ); + when( propertyAccessor.getPropertyValue( iterations, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( 1 ) ); // This collision is real!!! // when try @@ -440,14 +437,14 @@ public void shouldCheckAllCollisionsFromUpdaterClose() throws Exception for ( int nodeId = 0; nodeId < iterations; nodeId++ ) { addUpdate( populator, nodeId, 1 ); - when( propertyAccessor.getProperty( nodeId, PROPERTY_KEY_ID ) ).thenReturn( - intProperty( PROPERTY_KEY_ID, nodeId ) ); + when( propertyAccessor.getPropertyValue( nodeId, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( nodeId ) ); } // ... and the actual conflicting property: addUpdate( populator, iterations, 1 ); - when( propertyAccessor.getProperty( iterations, PROPERTY_KEY_ID ) ).thenReturn( - intProperty( PROPERTY_KEY_ID, 1 ) ); // This collision is real!!! + when( propertyAccessor.getPropertyValue( iterations, PROPERTY_KEY_ID ) ).thenReturn( + Values.of( 1 ) ); // This collision is real!!! // when try @@ -518,10 +515,10 @@ public void sampleIncludedUpdates() throws Exception LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel( 1, 1 ); populator = newPopulator(); List updates = Arrays.asList( - IndexEntryUpdate.add( 1, schemaDescriptor, "foo" ), - IndexEntryUpdate.add( 2, schemaDescriptor, "bar" ), - IndexEntryUpdate.add( 3, schemaDescriptor, "baz" ), - IndexEntryUpdate.add( 4, schemaDescriptor, "qux" ) ); + add( 1, schemaDescriptor, "foo" ), + add( 2, schemaDescriptor, "bar" ), + add( 3, schemaDescriptor, "baz" ), + add( 4, schemaDescriptor, "qux" ) ); updates.forEach( populator::includeSample ); @@ -536,9 +533,9 @@ public void addUpdates() throws Exception populator = newPopulator(); List> updates = Arrays.asList( - IndexEntryUpdate.add( 1, schemaDescriptor, "aaa" ), - IndexEntryUpdate.add( 2, schemaDescriptor, "bbb" ), - IndexEntryUpdate.add( 3, schemaDescriptor, "ccc" ) ); + add( 1, schemaDescriptor, "aaa" ), + add( 2, schemaDescriptor, "bbb" ), + add( 3, schemaDescriptor, "ccc" ) ); populator.add( updates ); @@ -560,7 +557,7 @@ private UniqueLuceneIndexPopulator newPopulator() throws IOException private static void addUpdate( UniqueLuceneIndexPopulator populator, long nodeId, Object value ) throws IOException, IndexEntryConflictException { - IndexEntryUpdate update = IndexEntryUpdate.add( nodeId, descriptor.schema(), value ); + IndexEntryUpdate update = add( nodeId, descriptor.schema(), value ); populator.add( update ); } } diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReaderTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReaderTest.java index 56ac23e9d686c..3314f6c5a2128 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReaderTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/PartitionedIndexReaderTest.java @@ -154,11 +154,11 @@ public void scanOverPartitions() throws Exception public void countNodesOverPartitions() { PartitionedIndexReader indexReader = createPartitionedReaderFromReaders(); - when( indexReader1.countIndexedNodes(1, "a") ).thenReturn( 1L ); - when( indexReader2.countIndexedNodes(1, "a") ).thenReturn( 2L ); - when( indexReader3.countIndexedNodes(1, "a") ).thenReturn( 3L ); + when( indexReader1.countIndexedNodes( 1, Values.of( "a" ) ) ).thenReturn( 1L ); + when( indexReader2.countIndexedNodes( 1, Values.of( "a" ) ) ).thenReturn( 2L ); + when( indexReader3.countIndexedNodes( 1, Values.of( "a" ) ) ).thenReturn( 3L ); - assertEquals( 6, indexReader.countIndexedNodes( 1, "a" ) ); + assertEquals( 6, indexReader.countIndexedNodes( 1, Values.of( "a" ) ) ); } @Test diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java index 527907f84c792..d54e7995d88c0 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java @@ -129,7 +129,7 @@ public void countIndexedNodesReachSearcher() throws IOException { IndexReader simpleIndexReader = getUniqueSimpleReader(); - simpleIndexReader.countIndexedNodes( 2, "testValue" ); + simpleIndexReader.countIndexedNodes( 2, Values.of( "testValue" ) ); verify( indexSearcher ).search( any( BooleanQuery.class ), any( DocValuesCollector.class ) ); } diff --git a/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java b/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java index 02347b8209b27..36c94c4ed26dc 100644 --- a/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java +++ b/community/neo4j/src/test/java/schema/IndexPopulationFlipRaceIT.java @@ -35,6 +35,7 @@ import org.neo4j.test.rule.DatabaseRule; import org.neo4j.test.rule.EmbeddedDatabaseRule; import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.Values; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertEquals; @@ -150,9 +151,11 @@ private void verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes( int i, P for ( int j = 0; j < NODES_PER_INDEX; j++ ) { long nodeAId = data.first()[j]; - assertEquals( 1, statement.readOperations().nodesCountIndexed( indexA, nodeAId, nodeAId ) ); + assertEquals( 1, statement.readOperations().nodesCountIndexed( + indexA, nodeAId, Values.of( nodeAId ) ) ); long nodeBId = data.other()[j]; - assertEquals( 1, statement.readOperations().nodesCountIndexed( indexB, nodeBId, nodeBId ) ); + assertEquals( 1, statement.readOperations().nodesCountIndexed( + indexB, nodeBId, Values.of( nodeBId ) ) ); } } } diff --git a/community/neo4j/src/test/java/schema/MultiIndexPopulationConcurrentUpdatesIT.java b/community/neo4j/src/test/java/schema/MultiIndexPopulationConcurrentUpdatesIT.java index 543c06892d0fb..e6a45b0dddb96 100644 --- a/community/neo4j/src/test/java/schema/MultiIndexPopulationConcurrentUpdatesIT.java +++ b/community/neo4j/src/test/java/schema/MultiIndexPopulationConcurrentUpdatesIT.java @@ -79,6 +79,7 @@ import org.neo4j.scheduler.JobScheduler; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.test.rule.EmbeddedDatabaseRule; +import org.neo4j.values.Values; import static org.junit.Assert.assertEquals; @@ -130,9 +131,9 @@ public void applyConcurrentDeletesToPopulatedIndex() throws Throwable { List updates = new ArrayList<>( 2 ); updates.add( NodeUpdates.forNode( 0, id( COUNTRY_LABEL ) ) - .removed( propertyId, "Sweden" ).build() ); + .removed( propertyId, Values.of( "Sweden" ) ).build() ); updates.add( NodeUpdates.forNode( 3, id( COLOR_LABEL ) ) - .removed( propertyId, "green" ).build() ); + .removed( propertyId, Values.of( "green" ) ).build() ); launchCustomIndexPopulation( labelsNameIdMap, propertyId, updates ); waitAndActivateIndexes( labelsNameIdMap, propertyId ); @@ -144,13 +145,13 @@ public void applyConcurrentDeletesToPopulatedIndex() throws Throwable try ( IndexReader indexReader = getIndexReader( propertyId, countryLabelId ) ) { assertEquals("Should be removed by concurrent remove.", - 0, indexReader.countIndexedNodes( 0, "Sweden" ) ); + 0, indexReader.countIndexedNodes( 0, Values.of( "Sweden" )) ); } try ( IndexReader indexReader = getIndexReader( propertyId, colorLabelId ) ) { assertEquals("Should be removed by concurrent remove.", - 0, indexReader.countIndexedNodes( 3, "green" ) ); + 0, indexReader.countIndexedNodes( 3, Values.of( "green" )) ); } } } @@ -160,9 +161,9 @@ public void applyConcurrentAddsToPopulatedIndex() throws Throwable { List updates = new ArrayList<>( 2 ); updates.add( NodeUpdates.forNode( 6, id( COUNTRY_LABEL ) ) - .added( propertyId, "Denmark" ).build() ); + .added( propertyId, Values.of( "Denmark" ) ).build() ); updates.add( NodeUpdates.forNode( 7, id( CAR_LABEL ) ) - .added( propertyId, "BMW" ).build() ); + .added( propertyId, Values.of( "BMW" ) ).build() ); launchCustomIndexPopulation( labelsNameIdMap, propertyId, updates ); waitAndActivateIndexes( labelsNameIdMap, propertyId ); @@ -173,12 +174,14 @@ public void applyConcurrentAddsToPopulatedIndex() throws Throwable Integer carLabelId = labelsNameIdMap.get( CAR_LABEL ); try ( IndexReader indexReader = getIndexReader( propertyId, countryLabelId ) ) { - assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes( 6, "Denmark" ) ); + assertEquals("Should be added by concurrent add.", 1, + indexReader.countIndexedNodes( 6, Values.of( "Denmark" ) ) ); } try ( IndexReader indexReader = getIndexReader( propertyId, carLabelId ) ) { - assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes( 7, "BMW" ) ); + assertEquals("Should be added by concurrent add.", 1, + indexReader.countIndexedNodes( 7, Values.of( "BMW" ) ) ); } } } @@ -188,9 +191,9 @@ public void applyConcurrentChangesToPopulatedIndex() throws Exception { List updates = new ArrayList<>( 2 ); updates.add( NodeUpdates.forNode( 3, id( COLOR_LABEL ) ) - .changed( propertyId, "green", "pink" ).build() ); + .changed( propertyId, Values.of( "green" ), Values.of( "pink" ) ).build() ); updates.add( NodeUpdates.forNode( 5, id( CAR_LABEL ) ) - .changed( propertyId, "Ford", "SAAB" ).build() ); + .changed( propertyId, Values.of( "Ford" ), Values.of( "SAAB" ) ).build() ); launchCustomIndexPopulation( labelsNameIdMap, propertyId, updates ); waitAndActivateIndexes( labelsNameIdMap, propertyId ); @@ -201,16 +204,19 @@ public void applyConcurrentChangesToPopulatedIndex() throws Exception Integer carLabelId = labelsNameIdMap.get( CAR_LABEL ); try ( IndexReader indexReader = getIndexReader( propertyId, colorLabelId ) ) { - assertEquals("Should be deleted by concurrent change.", 0, indexReader.countIndexedNodes( 3, "green" ) ); + assertEquals("Should be deleted by concurrent change.", 0, + indexReader.countIndexedNodes( 3, Values.of( "green" ) ) ); } try ( IndexReader indexReader = getIndexReader( propertyId, colorLabelId ) ) { - assertEquals("Should be updated by concurrent change.", 1, indexReader.countIndexedNodes( 3, "pink" ) ); + assertEquals("Should be updated by concurrent change.", 1, + indexReader.countIndexedNodes( 3, Values.of( "pink" ) ) ); } try ( IndexReader indexReader = getIndexReader( propertyId, carLabelId ) ) { - assertEquals("Should be added by concurrent change.", 1, indexReader.countIndexedNodes( 5, "SAAB" ) ); + assertEquals("Should be added by concurrent change.", 1, + indexReader.countIndexedNodes( 5, Values.of( "SAAB" ) ) ); } } } diff --git a/community/values/src/main/java/org/neo4j/values/TextValue.java b/community/values/src/main/java/org/neo4j/values/TextValue.java index 09e6b0beca8cc..8d76e8ebfdb3b 100644 --- a/community/values/src/main/java/org/neo4j/values/TextValue.java +++ b/community/values/src/main/java/org/neo4j/values/TextValue.java @@ -19,9 +19,13 @@ */ package org.neo4j.values; -abstract class TextValue extends ScalarValue +public abstract class TextValue extends ScalarValue { - abstract String stringValue(); + TextValue() + { + } + + public abstract String stringValue(); abstract int compareTo( TextValue other ); diff --git a/community/values/src/main/java/org/neo4j/values/ValueTuple.java b/community/values/src/main/java/org/neo4j/values/ValueTuple.java index 4c30662c76674..e363b0dd5e52f 100644 --- a/community/values/src/main/java/org/neo4j/values/ValueTuple.java +++ b/community/values/src/main/java/org/neo4j/values/ValueTuple.java @@ -22,6 +22,8 @@ /** * A tuple of n values. */ +import java.util.Comparator; + public class ValueTuple { public static ValueTuple of( Value... values ) @@ -31,6 +33,18 @@ public static ValueTuple of( Value... values ) return new ValueTuple( values ); } + public static ValueTuple of( Object... objects ) + { + assert objects.length > 0 : "Empty ValueTuple is not allowed"; + assert noNulls( objects ); + Value[] values = new Value[objects.length]; + for ( int i = 0; i < values.length; i++ ) + { + values[i] = Values.of( objects[i] ); + } + return new ValueTuple( values ); + } + private final Value[] values; private ValueTuple( Value[] values ) @@ -109,9 +123,9 @@ public String toString() return sb.toString(); } - private static boolean noNulls( Value[] values ) + private static boolean noNulls( Object[] values ) { - for ( Value v : values ) + for ( Object v : values ) { if ( v == null ) { @@ -120,4 +134,23 @@ private static boolean noNulls( Value[] values ) } return true; } + + public static Comparator COMPARATOR = ( left, right ) -> + { + if ( left.values.length != right.values.length ) + { + throw new IllegalStateException( "Comparing two ValueTuples of different lengths!" ); + } + + int compare = 0; + for ( int i = 0; i < left.values.length; i++ ) + { + compare = Values.VALUE_COMPARATOR.compare( left.valueAt( i ), right.valueAt( i ) ); + if ( compare != 0 ) + { + return compare; + } + } + return compare; + }; } diff --git a/community/values/src/main/java/org/neo4j/values/Values.java b/community/values/src/main/java/org/neo4j/values/Values.java index 7fb298defea86..29fb024e8a10a 100644 --- a/community/values/src/main/java/org/neo4j/values/Values.java +++ b/community/values/src/main/java/org/neo4j/values/Values.java @@ -37,11 +37,16 @@ @SuppressWarnings( "WeakerAccess" ) public class Values { + public static final Value MIN_NUMBER = Values.doubleValue( Double.NEGATIVE_INFINITY ); + public static final Value MAX_NUMBER = Values.doubleValue( Double.NaN ); + public static final Value MIN_STRING = Values.stringValue( "" ); + public static final Value MAX_STRING = Values.booleanValue( false ); + private Values() { } - interface ValueLoader + public interface ValueLoader { T load() throws ValueLoadException; } @@ -70,6 +75,11 @@ public static boolean isTextValue( Object value ) return value instanceof TextValue; } + public static boolean isArrayValue( Value value ) + { + return value instanceof ArrayValue; + } + // DIRECT FACTORY METHODS public static final Value NO_VALUE = NoValue.NO_VALUE; @@ -355,6 +365,16 @@ public static Value of( Object value ) String.format( "[%s:%s] is not a supported property value", value, value.getClass().getName() ) ); } + public static Value[] values( Object... objects ) + { + Value[] values = new Value[objects.length]; + for ( int i = 0; i < objects.length; i++ ) + { + values[i] = Values.of( objects[i] ); + } + return values; + } + private static Value arrayValue( Object[] value ) { if ( value instanceof String[] ) diff --git a/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/Neo4jValueComparisonTest.scala b/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/Neo4jValueComparisonTest.scala index a161d219e1be4..7c22c34772fce 100644 --- a/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/Neo4jValueComparisonTest.scala +++ b/enterprise/cypher/acceptance-spec-suite/src/test/scala/org/neo4j/internal/cypher/acceptance/Neo4jValueComparisonTest.scala @@ -22,9 +22,8 @@ package org.neo4j.internal.cypher.acceptance import org.neo4j.cypher.internal.codegen.CompiledEquivalenceUtils import org.neo4j.cypher.internal.compatibility.v3_3.runtime.commands.predicates.Equivalent import org.neo4j.cypher.internal.frontend.v3_3.test_helpers.CypherFunSuite -import org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure -import org.neo4j.kernel.api.properties.Property +import org.neo4j.values.Values import org.scalacheck._ import org.scalatest.prop.GeneratorDrivenPropertyChecks @@ -100,16 +99,16 @@ class Neo4jValueComparisonTest extends CypherFunSuite { Arbitrary.arbitrary[Double] ) - val testCase: Gen[Values] = for { + val testCase: Gen[ValuePair] = for { a <- arbAnyVal b <- arbAnyVal t <- testDifficulties } yield { val (x, y) = t(a, b) - Values(x, y) + ValuePair(x, y) } - case class Values(a: Any, b: Any) { + case class ValuePair(a: Any, b: Any) { override def toString: String = s"(a: ${str(a)}, b: ${str(b)})" private def str(x: Any) = if (x == null) "NULL" else s"${x.getClass.getSimpleName} $x" @@ -119,7 +118,7 @@ class Neo4jValueComparisonTest extends CypherFunSuite { test("compare equality between modules") { GeneratorDrivenPropertyChecks.forAll(testCase) { - case Values(l, r) => + case ValuePair(l, r) => val compiledL2R = CompiledEquivalenceUtils.equals(l, r) val compiledR2L = CompiledEquivalenceUtils.equals(r, l) val interpretedL2R = Equivalent(l).equals(r) @@ -130,8 +129,8 @@ class Neo4jValueComparisonTest extends CypherFunSuite { if (compiledL2R != interpretedL2R) fail(s"compiled[$compiledL2R] = interpreted[$interpretedL2R]") if (l != null && r != null) { - val propertyL2R = Property.property(NO_SUCH_PROPERTY_KEY, l).valueEquals(r) - val propertyR2L = Property.property(NO_SUCH_PROPERTY_KEY, r).valueEquals(l) + val propertyL2R = Values.of(l).equals(Values.of(r)) + val propertyR2L = Values.of(r).equals(Values.of(l)) if (propertyL2R != propertyR2L) fail(s"property (l = r)[$propertyL2R] = (r = l)[$propertyR2L]") if (propertyL2R != interpretedL2R) fail(s"property[$propertyL2R] = interpreted[$interpretedL2R]")