diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/Command.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/Command.java index 44e921f8efaa8..784ca8494c4d6 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/Command.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/transaction/command/Command.java @@ -23,6 +23,7 @@ import java.util.Collection; import org.neo4j.kernel.impl.api.CommandVisitor; +import org.neo4j.kernel.impl.store.record.Abstract64BitRecord; import org.neo4j.kernel.impl.store.record.AbstractBaseRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord; @@ -125,23 +126,17 @@ protected String beforeAndAfterToString( AbstractBaseRecord before, AbstractBase return format( " -%s%n +%s", before, after ); } - public static class NodeCommand extends Command + + public static abstract class BaseCommand extends Command { - private NodeRecord before; - private NodeRecord after; + protected RECORD before; + protected RECORD after; - public NodeCommand init( NodeRecord before, NodeRecord after ) + protected void initialize( RECORD before, RECORD after ) { setup( after.getId(), Mode.fromRecordState( after ) ); this.before = before; this.after = after; - return this; - } - - @Override - public boolean handle( CommandVisitor handler ) throws IOException - { - return handler.visitNodeCommand( this ); } @Override @@ -150,173 +145,93 @@ public String toString() return beforeAndAfterToString( before, after ); } - public NodeRecord getBefore() + public RECORD getBefore() { return before; } - public NodeRecord getAfter() + public RECORD getAfter() { return after; } } - public static class RelationshipCommand extends Command + public static class NodeCommand extends BaseCommand { - private RelationshipRecord before; - private RelationshipRecord after; - - public RelationshipCommand init( RelationshipRecord before, RelationshipRecord after ) + public NodeCommand init( NodeRecord before, NodeRecord after ) { - setup( after.getId(), Mode.fromRecordState( after ) ); - this.before = before; - this.after = after; + initialize( before, after ); return this; } - @Override - public String toString() - { - return beforeAndAfterToString( before, after ); - } - @Override public boolean handle( CommandVisitor handler ) throws IOException { - return handler.visitRelationshipCommand( this ); + return handler.visitNodeCommand( this ); } + } - public RelationshipRecord getBefore() + public static class RelationshipCommand extends BaseCommand + { + public RelationshipCommand init( RelationshipRecord before, RelationshipRecord after ) { - return before; + initialize( before, after ); + return this; } - public RelationshipRecord getAfter() + @Override + public boolean handle( CommandVisitor handler ) throws IOException { - return after; + return handler.visitRelationshipCommand( this ); } } - public static class RelationshipGroupCommand extends Command + public static class RelationshipGroupCommand extends BaseCommand { - private RelationshipGroupRecord before; - private RelationshipGroupRecord after; - public RelationshipGroupCommand init( RelationshipGroupRecord before, RelationshipGroupRecord after ) { - setup( after.getId(), Mode.fromRecordState( after ) ); - this.before = before; - this.after = after; + initialize( before, after ); return this; } - @Override - public String toString() - { - return beforeAndAfterToString( before, after ); - } - @Override public boolean handle( CommandVisitor handler ) throws IOException { return handler.visitRelationshipGroupCommand( this ); } - - public RelationshipGroupRecord getBefore() - { - return before; - } - - public RelationshipGroupRecord getAfter() - { - return after; - } } - public static class NeoStoreCommand extends Command + public static class NeoStoreCommand extends BaseCommand { - private NeoStoreRecord before; - private NeoStoreRecord after; - public NeoStoreCommand init( NeoStoreRecord before, NeoStoreRecord after ) { - setup( after.getId(), Mode.fromRecordState( after ) ); - this.before = before; - this.after = after; + initialize( before, after ); return this; } - @Override - public String toString() - { - return beforeAndAfterToString( before, after ); - } - @Override public boolean handle( CommandVisitor handler ) throws IOException { return handler.visitNeoStoreCommand( this ); } - - public NeoStoreRecord getBefore() - { - return before; - } - - public NeoStoreRecord getAfter() - { - return after; - } } - public static class PropertyKeyTokenCommand extends TokenCommand + public static class PropertyCommand extends BaseCommand implements PropertyRecordChange { - @Override - public boolean handle( CommandVisitor handler ) throws IOException - { - return handler.visitPropertyKeyTokenCommand( this ); - } - } - - public static class PropertyCommand extends Command implements PropertyRecordChange - { - private PropertyRecord before; - private PropertyRecord after; - // TODO as optimization the deserialized key/values could be passed in here // so that the cost of deserializing them only applies in recovery/HA public PropertyCommand init( PropertyRecord before, PropertyRecord after ) { - setup( after.getId(), Mode.fromRecordState( after ) ); - this.before = before; - this.after = after; + initialize( before, after ); return this; } - @Override - public String toString() - { - return beforeAndAfterToString( before, after ); - } - @Override public boolean handle( CommandVisitor handler ) throws IOException { return handler.visitPropertyCommand( this ); } - @Override - public PropertyRecord getBefore() - { - return before; - } - - @Override - public PropertyRecord getAfter() - { - return after; - } - public long getNodeId() { return after.getNodeId(); @@ -358,6 +273,15 @@ public String toString() } } + public static class PropertyKeyTokenCommand extends TokenCommand + { + @Override + public boolean handle( CommandVisitor handler ) throws IOException + { + return handler.visitPropertyKeyTokenCommand( this ); + } + } + public static class RelationshipTypeTokenCommand extends TokenCommand { @Override diff --git a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/token/ReplicatedTokenHolder.java b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/token/ReplicatedTokenHolder.java index ad3ac2b10a8c3..40abdcf91376d 100644 --- a/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/token/ReplicatedTokenHolder.java +++ b/enterprise/core-edge/src/main/java/org/neo4j/coreedge/raft/replication/token/ReplicatedTokenHolder.java @@ -278,7 +278,7 @@ private int extractTokenId( Collection commands ) throws NoSuchEntryExc { if( command instanceof Command.TokenCommand ) { - return ((Command.TokenCommand) command).getAfter().getId(); + return ((Command.TokenCommand) command).getAfter().getId(); } } throw new NoSuchEntryException( "Expected command not found" );