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 c5f238424b79..3cd58dc2689c 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 @@ -90,7 +90,6 @@ import org.neo4j.kernel.impl.store.SchemaStore; import org.neo4j.kernel.impl.store.StoreAccess; import org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; import org.neo4j.kernel.impl.store.record.ConstraintRule; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.IndexRule; @@ -1066,7 +1065,7 @@ public static Collection serializeRule( SchemaRule rule, DynamicR public static Collection serializeRule( SchemaRule rule, Collection records ) { RecordSerializer serializer = new RecordSerializer(); - serializer.append( (AbstractSchemaRule)rule ); + serializer.append( rule ); byte[] data = serializer.serialize(); ReusableRecordsAllocator dynamicRecordAllocator = new ReusableRecordsAllocator( data.length, records ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/NewIndexDescriptor.java b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/NewIndexDescriptor.java index 86477e550124..f537832cb9fe 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/NewIndexDescriptor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/index/NewIndexDescriptor.java @@ -37,7 +37,7 @@ public enum Type { GENERAL, UNIQUE } public interface Supplier { - NewIndexDescriptor getNewIndexDescriptor(); + NewIndexDescriptor getIndexDescriptor(); } private final LabelSchemaDescriptor schema; @@ -81,7 +81,7 @@ public String userDescription( TokenNameLookup tokenNameLookup ) */ public boolean isSame( Supplier supplier ) { - return this.equals( supplier.getNewIndexDescriptor() ); + return this.equals( supplier.getIndexDescriptor() ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/SchemaStore.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/SchemaStore.java index 3dc4644717ec..877ec0c8fed0 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/SchemaStore.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/SchemaStore.java @@ -34,7 +34,7 @@ import org.neo4j.kernel.impl.store.format.RecordFormats; import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; import org.neo4j.kernel.impl.store.id.IdType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.RecordSerializer; import org.neo4j.logging.LogProvider; @@ -71,7 +71,7 @@ public void accept( Processor processor, Dy public List allocateFrom( SchemaRule rule ) { RecordSerializer serializer = new RecordSerializer(); - serializer = serializer.append( (AbstractSchemaRule)rule ); + serializer = serializer.append( rule ); List records = new ArrayList<>(); DynamicRecord record = getRecord( rule.getId(), nextRecord(), CHECK ); ReusableRecordsAllocator recordAllocator = new ReusableRecordsAllocator( this.getRecordSize(), record ); @@ -94,6 +94,6 @@ static SchemaRule readSchemaRule( long id, Collection records, by throws MalformedSchemaRuleException { ByteBuffer scratchBuffer = concatData( records, buffer ); - return AbstractSchemaRule.deserialize( id, scratchBuffer ); + return SchemaRuleDeserializer2_0to3_1.deserialize( id, scratchBuffer ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/AbstractSchemaRule.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/AbstractSchemaRule.java deleted file mode 100644 index 8dc2bd6f75df..000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/AbstractSchemaRule.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.impl.store.record; - -import java.nio.ByteBuffer; - -import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException; -import org.neo4j.storageengine.api.schema.SchemaRule; - -/** - * Partial implementation of SchemaRule. Note that the id of a SchemaRule is a fixed property that should - * never be modified of overridden by subclasses. - */ -public abstract class AbstractSchemaRule implements SchemaRule, RecordSerializable -{ - protected final long id; - - public AbstractSchemaRule( long id ) - { - this.id = id; - } - - @Override - public final long getId() - { - return this.id; - } - - public static SchemaRule deserialize( long id, ByteBuffer buffer ) throws MalformedSchemaRuleException - { - int labelId = buffer.getInt(); - Kind kind = Kind.forId( buffer.get() ); - try - { - SchemaRule rule = newRule( kind, id, labelId, buffer ); - if ( null == rule ) - { - throw new MalformedSchemaRuleException( null, - "Deserialized null schema rule for id %d with kind %s", id, kind.name() ); - } - return rule; - } - catch ( Exception e ) - { - throw new MalformedSchemaRuleException( e, - "Could not deserialize schema rule for id %d with kind %s", id, kind.name() ); - } - } - - private static SchemaRule newRule( Kind kind, long id, int labelId, ByteBuffer buffer ) - { - switch ( kind ) - { - case INDEX_RULE: - return IndexRule.readIndexRule( id, false, labelId, buffer ); - case CONSTRAINT_INDEX_RULE: - return IndexRule.readIndexRule( id, true, labelId, buffer ); - case UNIQUENESS_CONSTRAINT: - return ConstraintRule.readUniquenessConstraintRule( id, labelId, buffer ); - case NODE_PROPERTY_EXISTENCE_CONSTRAINT: - return ConstraintRule.readNodePropertyExistenceConstraintRule( id, labelId, buffer ); - case RELATIONSHIP_PROPERTY_EXISTENCE_CONSTRAINT: - return ConstraintRule.readRelPropertyExistenceConstraintRule( id, labelId, buffer ); - default: - throw new IllegalArgumentException( kind.name() ); - } - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java index d99a714db21f..f00d446054f9 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java @@ -29,6 +29,7 @@ import org.neo4j.kernel.api.schema_new.SchemaProcessor; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory; +import org.neo4j.storageengine.api.schema.SchemaRule; import static org.neo4j.kernel.api.schema_new.SchemaUtil.noopTokenNameLookup; import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt; @@ -36,30 +37,16 @@ import static org.neo4j.storageengine.api.schema.SchemaRule.Kind.RELATIONSHIP_PROPERTY_EXISTENCE_CONSTRAINT; import static org.neo4j.storageengine.api.schema.SchemaRule.Kind.UNIQUENESS_CONSTRAINT; -public class ConstraintRule extends AbstractSchemaRule implements ConstraintDescriptor.Supplier +public class ConstraintRule implements SchemaRule, ConstraintDescriptor.Supplier { + private final long id; private final Optional ownedIndexRule; private final ConstraintDescriptor descriptor; - public static ConstraintRule readUniquenessConstraintRule( long id, int labelId, ByteBuffer buffer ) - { - return new ConstraintRule( id, - ConstraintDescriptorFactory.uniqueForLabel( labelId, readPropertyKeys( buffer ) ), - readOwnedIndexRule( buffer ) ); - } - - public static ConstraintRule readNodePropertyExistenceConstraintRule( long id, int labelId, ByteBuffer buffer ) - { - return new ConstraintRule( id, - ConstraintDescriptorFactory.existsForLabel( labelId, readPropertyKey( buffer ) ), - Optional.empty() ); - } - - public static ConstraintRule readRelPropertyExistenceConstraintRule( long id, int relTypeId, ByteBuffer buffer ) + @Override + public final long getId() { - return new ConstraintRule( id, - ConstraintDescriptorFactory.existsForRelType( relTypeId, readPropertyKey( buffer ) ), - Optional.empty() ); + return this.id; } public static ConstraintRule constraintRule( @@ -74,29 +61,9 @@ public static ConstraintRule constraintRule( return new ConstraintRule( id, descriptor, Optional.of( ownedIndexRule ) ); } - private static int readPropertyKey( ByteBuffer buffer ) - { - return buffer.getInt(); - } - - private static int[] readPropertyKeys( ByteBuffer buffer ) - { - int[] keys = new int[buffer.get()]; - for ( int i = 0; i < keys.length; i++ ) - { - keys[i] = safeCastLongToInt( buffer.getLong() ); - } - return keys; - } - - private static Optional readOwnedIndexRule( ByteBuffer buffer ) - { - return Optional.of( buffer.getLong() ); - } - - private ConstraintRule( long id, ConstraintDescriptor descriptor, Optional ownedIndexRule ) + ConstraintRule( long id, ConstraintDescriptor descriptor, Optional ownedIndexRule ) { - super( id ); + this.id = id; this.descriptor = descriptor; this.ownedIndexRule = ownedIndexRule; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java index 822801a63a0b..163acf5c072b 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java @@ -28,6 +28,7 @@ import org.neo4j.kernel.api.schema_new.SchemaComputer; import org.neo4j.kernel.api.schema_new.SchemaProcessor; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.storageengine.api.schema.SchemaRule; import org.neo4j.string.UTF8; import static org.neo4j.kernel.api.schema_new.SchemaUtil.noopTokenNameLookup; @@ -41,9 +42,11 @@ /** * A {@link Label} can have zero or more index rules which will have data specified in the rules indexed. */ -public class IndexRule extends AbstractSchemaRule +public class IndexRule implements SchemaRule, NewIndexDescriptor.Supplier { - private static final long NO_OWNING_CONSTRAINT = -1; + static final long NO_OWNING_CONSTRAINT = -1; + + private final long id; private final SchemaIndexProvider.Descriptor providerDescriptor; private final NewIndexDescriptor descriptor; /** @@ -52,16 +55,6 @@ public class IndexRule extends AbstractSchemaRule */ private final long owningConstraint; - static IndexRule readIndexRule( long id, boolean constraintIndex, int label, ByteBuffer serialized ) - { - SchemaIndexProvider.Descriptor providerDescriptor = readProviderDescriptor( serialized ); - int[] propertyKeyIds = readPropertyKeys( serialized ); - NewIndexDescriptor descriptor = constraintIndex ? - uniqueForLabel( label, propertyKeyIds ) : forLabel( label, propertyKeyIds ); - long owningConstraint = constraintIndex ? readOwningConstraint( serialized ) : NO_OWNING_CONSTRAINT; - return new IndexRule( id, providerDescriptor, descriptor, owningConstraint ); - } - public static IndexRule indexRule( long id, NewIndexDescriptor descriptor, SchemaIndexProvider.Descriptor providerDescriptor ) { @@ -75,37 +68,10 @@ public static IndexRule constraintIndexRule( long id, NewIndexDescriptor descrip return new IndexRule( id, providerDescriptor, descriptor, owningConstraint ); } - private static SchemaIndexProvider.Descriptor readProviderDescriptor( ByteBuffer serialized ) - { - String providerKey = getDecodedStringFrom( serialized ); - String providerVersion = getDecodedStringFrom( serialized ); - return new SchemaIndexProvider.Descriptor( providerKey, providerVersion ); - } - - private static int[] readPropertyKeys( ByteBuffer serialized ) - { - // Currently only one key is supported although the data format supports multiple - int count = serialized.getShort(); - assert count >= 1; - - // Changed from being a long to an int 2013-09-10, but keeps reading a long to not change the store format. - int[] props = new int[count]; - for ( int i = 0; i < count; i++ ) - { - props[i] = safeCastLongToInt( serialized.getLong() ); - } - return props; - } - - private static long readOwningConstraint( ByteBuffer serialized ) - { - return serialized.getLong(); - } - - private IndexRule( long id, SchemaIndexProvider.Descriptor providerDescriptor, + IndexRule( long id, SchemaIndexProvider.Descriptor providerDescriptor, NewIndexDescriptor descriptor, long owningConstraint ) { - super( id ); + this.id = id; if ( providerDescriptor == null ) { throw new IllegalArgumentException( "null provider descriptor prohibited" ); @@ -149,6 +115,12 @@ public IndexRule withOwningConstraint( long constraintId ) return constraintIndexRule( id, descriptor, providerDescriptor, constraintId ); } + @Override + public long getId() + { + return id; + } + @Override public int length() { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/SchemaRuleDeserializer2_0to3_1.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/SchemaRuleDeserializer2_0to3_1.java new file mode 100644 index 000000000000..6839e23abf15 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/SchemaRuleDeserializer2_0to3_1.java @@ -0,0 +1,167 @@ +/* + * 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.impl.store.record; + +import java.nio.ByteBuffer; +import java.util.Optional; + +import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException; +import org.neo4j.kernel.api.index.SchemaIndexProvider; +import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; +import org.neo4j.storageengine.api.schema.SchemaRule; +import org.neo4j.storageengine.api.schema.SchemaRule.Kind; + +import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt; +import static org.neo4j.string.UTF8.getDecodedStringFrom; + +/** + * Deserializes SchemaRules from a ByteBuffer. + */ +public class SchemaRuleDeserializer2_0to3_1 +{ + private SchemaRuleDeserializer2_0to3_1() + { + } + + public static SchemaRule deserialize( long id, ByteBuffer buffer ) throws MalformedSchemaRuleException + { + int labelId = buffer.getInt(); + Kind kind = Kind.forId( buffer.get() ); + try + { + SchemaRule rule = newRule( kind, id, labelId, buffer ); + if ( null == rule ) + { + throw new MalformedSchemaRuleException( null, + "Deserialized null schema rule for id %d with kind %s", id, kind.name() ); + } + return rule; + } + catch ( Exception e ) + { + throw new MalformedSchemaRuleException( e, + "Could not deserialize schema rule for id %d with kind %s", id, kind.name() ); + } + } + + private static SchemaRule newRule( Kind kind, long id, int labelId, ByteBuffer buffer ) + { + switch ( kind ) + { + case INDEX_RULE: + return readIndexRule( id, false, labelId, buffer ); + case CONSTRAINT_INDEX_RULE: + return readIndexRule( id, true, labelId, buffer ); + case UNIQUENESS_CONSTRAINT: + return readUniquenessConstraintRule( id, labelId, buffer ); + case NODE_PROPERTY_EXISTENCE_CONSTRAINT: + return readNodePropertyExistenceConstraintRule( id, labelId, buffer ); + case RELATIONSHIP_PROPERTY_EXISTENCE_CONSTRAINT: + return readRelPropertyExistenceConstraintRule( id, labelId, buffer ); + default: + throw new IllegalArgumentException( kind.name() ); + } + } + + // === INDEX RULES === + + private static IndexRule readIndexRule( long id, boolean constraintIndex, int label, ByteBuffer serialized ) + { + SchemaIndexProvider.Descriptor providerDescriptor = readIndexProviderDescriptor( serialized ); + int[] propertyKeyIds = readIndexPropertyKeys( serialized ); + NewIndexDescriptor descriptor = constraintIndex ? + NewIndexDescriptorFactory.uniqueForLabel( label, propertyKeyIds ) : + NewIndexDescriptorFactory.forLabel( label, propertyKeyIds ); + long owningConstraint = constraintIndex ? readOwningConstraint( serialized ) : IndexRule.NO_OWNING_CONSTRAINT; + return new IndexRule( id, providerDescriptor, descriptor, owningConstraint ); + } + + private static SchemaIndexProvider.Descriptor readIndexProviderDescriptor( ByteBuffer serialized ) + { + String providerKey = getDecodedStringFrom( serialized ); + String providerVersion = getDecodedStringFrom( serialized ); + return new SchemaIndexProvider.Descriptor( providerKey, providerVersion ); + } + + private static int[] readIndexPropertyKeys( ByteBuffer serialized ) + { + // Currently only one key is supported although the data format supports multiple + int count = serialized.getShort(); + assert count >= 1; + + // Changed from being a long to an int 2013-09-10, but keeps reading a long to not change the store format. + int[] props = new int[count]; + for ( int i = 0; i < count; i++ ) + { + props[i] = safeCastLongToInt( serialized.getLong() ); + } + return props; + } + + private static long readOwningConstraint( ByteBuffer serialized ) + { + return serialized.getLong(); + } + + // === CONSTRAINT RULES === + + public static ConstraintRule readUniquenessConstraintRule( long id, int labelId, ByteBuffer buffer ) + { + return new ConstraintRule( id, + ConstraintDescriptorFactory.uniqueForLabel( labelId, readConstraintPropertyKeys( buffer ) ), + readOwnedIndexRule( buffer ) ); + } + + public static ConstraintRule readNodePropertyExistenceConstraintRule( long id, int labelId, ByteBuffer buffer ) + { + return new ConstraintRule( id, + ConstraintDescriptorFactory.existsForLabel( labelId, readPropertyKey( buffer ) ), + Optional.empty() ); + } + + public static ConstraintRule readRelPropertyExistenceConstraintRule( long id, int relTypeId, ByteBuffer buffer ) + { + return new ConstraintRule( id, + ConstraintDescriptorFactory.existsForRelType( relTypeId, readPropertyKey( buffer ) ), + Optional.empty() ); + } + + private static int readPropertyKey( ByteBuffer buffer ) + { + return buffer.getInt(); + } + + private static int[] readConstraintPropertyKeys( ByteBuffer buffer ) + { + int[] keys = new int[buffer.get()]; + for ( int i = 0; i < keys.length; i++ ) + { + keys[i] = safeCastLongToInt( buffer.getLong() ); + } + return keys; + } + + private static Optional readOwnedIndexRule( ByteBuffer buffer ) + { + return Optional.of( buffer.getLong() ); + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_0.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_0.java index bb322c197750..9486dd24f109 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_0.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_0.java @@ -28,7 +28,7 @@ import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException; import org.neo4j.kernel.impl.store.AbstractDynamicStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord; @@ -449,7 +449,7 @@ private SchemaRule readSchemaRule( Collection recordsBefore ) ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { - rule = AbstractSchemaRule.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); + rule = SchemaRuleDeserializer2_0to3_1.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_1.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_1.java index 4875745e9e94..9e1496872996 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_1.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_1.java @@ -28,7 +28,7 @@ import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException; import org.neo4j.kernel.impl.store.AbstractDynamicStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord; @@ -474,7 +474,7 @@ private SchemaRule readSchemaRule( Collection recordsBefore ) ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { - rule = AbstractSchemaRule.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); + rule = SchemaRuleDeserializer2_0to3_1.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2.java index a97803031907..50ef092f52ac 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2.java @@ -37,7 +37,7 @@ import org.neo4j.kernel.impl.index.IndexDefineCommand; import org.neo4j.kernel.impl.store.AbstractDynamicStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord; @@ -536,7 +536,7 @@ private SchemaRule readSchemaRule( Collection recordsBefore ) ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { - rule = AbstractSchemaRule.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); + rule = SchemaRuleDeserializer2_0to3_1.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_10.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_10.java index 6e4c10f752a3..ec576a0dcf75 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_10.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_10.java @@ -37,7 +37,7 @@ import org.neo4j.kernel.impl.index.IndexDefineCommand; import org.neo4j.kernel.impl.store.AbstractDynamicStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord; @@ -536,7 +536,7 @@ private SchemaRule readSchemaRule( Collection recordsBefore ) ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { - rule = AbstractSchemaRule.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); + rule = SchemaRuleDeserializer2_0to3_1.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_4.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_4.java index af0495030ef0..cd123e64a0ad 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_4.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV2_2_4.java @@ -37,7 +37,7 @@ import org.neo4j.kernel.impl.index.IndexDefineCommand; import org.neo4j.kernel.impl.store.AbstractDynamicStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord; @@ -536,7 +536,7 @@ private SchemaRule readSchemaRule( Collection recordsBefore ) ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { - rule = AbstractSchemaRule.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); + rule = SchemaRuleDeserializer2_0to3_1.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0.java index 27b3f04b9f4a..96ea7107a4bd 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0.java @@ -37,7 +37,7 @@ import org.neo4j.kernel.impl.index.IndexDefineCommand; import org.neo4j.kernel.impl.store.AbstractDynamicStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord; @@ -631,7 +631,7 @@ private SchemaRule readSchemaRule( Collection recordsBefore ) ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { - rule = AbstractSchemaRule.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); + rule = SchemaRuleDeserializer2_0to3_1.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0_2.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0_2.java index 880b35600a47..dd1df3836cdb 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0_2.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/PhysicalLogCommandReaderV3_0_2.java @@ -37,7 +37,7 @@ import org.neo4j.kernel.impl.index.IndexDefineCommand; import org.neo4j.kernel.impl.store.AbstractDynamicStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord; @@ -631,7 +631,7 @@ private SchemaRule readSchemaRule( Collection recordsBefore ) ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { - rule = AbstractSchemaRule.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); + rule = SchemaRuleDeserializer2_0to3_1.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/SchemaRule.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/SchemaRule.java index b2b70aa97fe9..bebb083c6d8d 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/SchemaRule.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/SchemaRule.java @@ -26,11 +26,12 @@ import org.neo4j.kernel.api.schema_new.SchemaDescriptor; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.impl.store.record.RecordSerializable; /** * Represents a stored schema rule. */ -public interface SchemaRule extends SchemaDescriptor.Supplier +public interface SchemaRule extends SchemaDescriptor.Supplier, RecordSerializable { /** * The persistence id for this rule. diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/SchemaStoreTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/SchemaStoreTest.java index f9a1563e356d..9abbcccd5e70 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/store/SchemaStoreTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/store/SchemaStoreTest.java @@ -34,7 +34,7 @@ import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; +import org.neo4j.kernel.impl.store.record.SchemaRuleDeserializer2_0to3_1; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.RecordSerializer; @@ -45,7 +45,6 @@ import static java.nio.ByteBuffer.wrap; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.neo4j.helpers.collection.Iterators.asCollection; import static org.neo4j.kernel.impl.api.index.TestSchemaIndexProviderDescriptor.PROVIDER_DESCRIPTOR; @@ -100,7 +99,7 @@ public void serializationAndDeserialization() throws Exception // WHEN byte[] serialized = new RecordSerializer().append( indexRule ).serialize(); - IndexRule readIndexRule = (IndexRule) AbstractSchemaRule.deserialize( indexRule.getId(), wrap( serialized ) ); + IndexRule readIndexRule = (IndexRule) SchemaRuleDeserializer2_0to3_1.deserialize( indexRule.getId(), wrap( serialized ) ); // THEN assertEquals( indexRule.getId(), readIndexRule.getId() ); @@ -113,7 +112,7 @@ public void serializationAndDeserialization() throws Exception public void storeAndLoadAllShortRules() throws Exception { // GIVEN - Collection rules = Arrays.asList( + Collection rules = Arrays.asList( indexRule( store.nextId(), 0, 5, PROVIDER_DESCRIPTOR ), indexRule( store.nextId(), 1, 6, PROVIDER_DESCRIPTOR ), indexRule( store.nextId(), 1, 7, PROVIDER_DESCRIPTOR ) ); 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 63b4c11cfb78..310370aff6cb 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 @@ -31,7 +31,6 @@ import org.neo4j.kernel.impl.store.DynamicNodeLabels; import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.PropertyType; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; @@ -149,7 +148,7 @@ public static SchemaRuleCommand createIndexRule( SchemaIndexProvider.Descriptor NewIndexDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() ), provider ); RecordSerializer serializer = new RecordSerializer(); - serializer.append( (AbstractSchemaRule)rule ); + serializer.append( rule ); DynamicRecord record = new DynamicRecord( id ); record.setInUse( true ); record.setCreated(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/SchemaRuleCommandTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/SchemaRuleCommandTest.java index 4f55f556b2f4..d78dbb74cdc6 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/SchemaRuleCommandTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/state/SchemaRuleCommandTest.java @@ -41,7 +41,6 @@ import org.neo4j.kernel.impl.store.NodeStore; import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.SchemaStore; -import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; import org.neo4j.kernel.impl.store.record.ConstraintRule; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.IndexRule; @@ -59,6 +58,7 @@ import org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation; import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.TransactionApplicationMode; +import org.neo4j.storageengine.api.schema.SchemaRule; import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertEquals; @@ -224,7 +224,7 @@ public void shouldRecreateSchemaRuleWhenDeleteCommandReadFromDisk() throws Excep assertSchemaRule( (SchemaRuleCommand)readCommand ); } - private SchemaRecord serialize( AbstractSchemaRule rule, long id, boolean inUse, boolean created ) + private SchemaRecord serialize( SchemaRule rule, long id, boolean inUse, boolean created ) { RecordSerializer serializer = new RecordSerializer(); serializer = serializer.append( rule );