@Override public void addNode( String indexName, long id, String key, Object value ) { AddNodeCommand command = new AddNodeCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), id, definitions().getOrAssignKeyId( key ), value ); addCommand( indexName, command ); }
@Override public void addRelationship( String indexName, long id, String key, Object value, long startNode, long endNode ) { AddRelationshipCommand command = new AddRelationshipCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), id, definitions().getOrAssignKeyId( key ), value, startNode, endNode ); addCommand( indexName, command ); }
@Override public void removeNode( String indexName, long id, String keyOrNull, Object valueOrNull ) { RemoveCommand command = new RemoveCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), IndexEntityType.Node.id(), id, definitions().getOrAssignKeyId( keyOrNull ), valueOrNull ); addCommand( indexName, command ); }
@Override public void removeRelationship( String indexName, long id, String keyOrNull, Object valueOrNull ) { RemoveCommand command = new RemoveCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), IndexEntityType.Relationship.id(), id, definitions().getOrAssignKeyId( keyOrNull ), valueOrNull ); addCommand( indexName, command ); }
idc.getOrAssignKeyId( "key" + i ); idc.getOrAssignIndexNameId( "index" + i ); idc.getOrAssignKeyId( "dropThatOverflows" ); fail( "IndexDefineCommand should not allow more than " + count + " indexes per transaction" );
@Test public void nodeIndexDeletionRemovesCommands() { ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); state.addNode( "index", 1, "key", "value1" ); state.addNode( "index", 2, "key", "value2" ); state.removeNode( "index", 3, "key", "value3" ); state.deleteIndex( IndexEntityType.Node, "index" ); IndexDefineCommand indexDefinedCommand = new IndexDefineCommand(); indexDefinedCommand.getOrAssignIndexNameId( "index" ); indexDefinedCommand.getOrAssignKeyId( "key" ); IndexCommand.DeleteCommand delete = new IndexCommand.DeleteCommand(); delete.init( 1, IndexEntityType.Node.id() ); Set<Command> expectedCommands = new HashSet<>( Arrays.asList( indexDefinedCommand, delete ) ); assertEquals( expectedCommands, extractCommands( state ) ); }
@Test public void relationshipIndexDeletionRemovesCommands() { ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); state.removeRelationship( "index", 1, "key", "value1" ); state.addRelationship( "index", 2, "key", "value2", 11, 11 ); state.addRelationship( "index", 3, "key", "value3", 22, 22 ); state.deleteIndex( IndexEntityType.Relationship, "index" ); IndexDefineCommand indexDefinedCommand = new IndexDefineCommand(); indexDefinedCommand.getOrAssignIndexNameId( "index" ); indexDefinedCommand.getOrAssignKeyId( "key" ); IndexCommand.DeleteCommand delete = new IndexCommand.DeleteCommand(); delete.init( 1, IndexEntityType.Relationship.id() ); Set<Command> expectedCommands = new HashSet<>( Arrays.asList( indexDefinedCommand, delete ) ); assertEquals( expectedCommands, extractCommands( state ) ); }
@Test public void removalOfRelationshipIndexDoesNotClearNodeCommandsForNodeIndexWithSameName() { ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); state.addNode( "index", 1, "key", "value" ); state.addRelationship( "index", 1, "key", "value", 11, 11 ); state.deleteIndex( IndexEntityType.Relationship, "index" ); IndexDefineCommand indexDefinedCommand = new IndexDefineCommand(); indexDefinedCommand.getOrAssignIndexNameId( "index" ); indexDefinedCommand.getOrAssignKeyId( "key" ); IndexCommand.DeleteCommand delete = new IndexCommand.DeleteCommand(); delete.init( 1, IndexEntityType.Relationship.id() ); Set<Command> expectedCommands = new HashSet<>( Arrays.asList( indexDefinedCommand, delete, addNode( 1, 1, 1, "value" ) ) ); assertEquals( expectedCommands, extractCommands( state ) ); }
@Test public void tracksNodeCommands() { ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); state.addNode( "index1", 1, "key1", "value1" ); state.removeNode( "index1", 1, "key2", "value2" ); state.addNode( "index1", 2, "key1", "value3" ); state.addNode( "index1", 3, "key2", "value4" ); state.removeNode( "index2", 4, "key1", "value5" ); IndexDefineCommand indexDefinedCommand = new IndexDefineCommand(); indexDefinedCommand.getOrAssignIndexNameId( "index1" ); indexDefinedCommand.getOrAssignIndexNameId( "index2" ); indexDefinedCommand.getOrAssignKeyId( "key1" ); indexDefinedCommand.getOrAssignKeyId( "key2" ); Set<Command> expectedCommands = new HashSet<>( Arrays.asList( indexDefinedCommand, addNode( 1, 1, 1, "value1" ), removeNode( 1, 1, 2, "value2" ), addNode( 1, 2, 1, "value3" ), addNode( 1, 3, 2, "value4" ), removeNode( 2, 4, 1, "value5" ) ) ); assertEquals( expectedCommands, extractCommands( state ) ); }
@Test public void tracksRelationshipCommands() { ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); state.removeRelationship( "index1", 1, "key1", "value1" ); state.addRelationship( "index1", 1, "key2", "value2", 11, 11 ); state.removeRelationship( "index1", 2, "key1", "value3" ); state.addRelationship( "index1", 3, "key2", "value4", 22, 22 ); state.addRelationship( "index2", 4, "key1", "value5", 33, 33 ); IndexDefineCommand indexDefinedCommand = new IndexDefineCommand(); indexDefinedCommand.getOrAssignIndexNameId( "index1" ); indexDefinedCommand.getOrAssignIndexNameId( "index2" ); indexDefinedCommand.getOrAssignKeyId( "key1" ); indexDefinedCommand.getOrAssignKeyId( "key2" ); Set<Command> expectedCommands = new HashSet<>( Arrays.asList( indexDefinedCommand, removeRelationship( 1, 1, 1, "value1" ), addRelationship( 1, 1, 2, "value2", 11, 11 ), removeRelationship( 1, 2, 1, "value3" ), addRelationship( 1, 3, 2, "value4", 22, 22 ), addRelationship( 2, 4, 1, "value5", 33, 33 ) ) ); assertEquals( expectedCommands, extractCommands( state ) ); }
@Test public void removalOfNodeIndexDoesNotClearRelationshipCommandsForRelationshipIndexWithSameName() { ExplicitIndexTransactionStateImpl state = newExplicitIndexTxState(); state.addNode( "index", 1, "key", "value" ); state.addRelationship( "index", 1, "key", "value", 11, 11 ); state.deleteIndex( IndexEntityType.Node, "index" ); IndexDefineCommand indexDefinedCommand = new IndexDefineCommand(); indexDefinedCommand.getOrAssignIndexNameId( "index" ); indexDefinedCommand.getOrAssignKeyId( "key" ); IndexCommand.DeleteCommand delete = new IndexCommand.DeleteCommand(); delete.init( 1, IndexEntityType.Node.id() ); Set<Command> expectedCommands = new HashSet<>( Arrays.asList( indexDefinedCommand, delete, addRelationship( 1, 1, 1, "value", 11, 11 ) ) ); assertEquals( expectedCommands, extractCommands( state ) ); }
@Override public void addNode( String indexName, long id, String key, Object value ) { AddNodeCommand command = new AddNodeCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), id, definitions().getOrAssignKeyId( key ), value ); addCommand( indexName, command ); }
@Override public void addRelationship( String indexName, long id, String key, Object value, long startNode, long endNode ) { AddRelationshipCommand command = new AddRelationshipCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), id, definitions().getOrAssignKeyId( key ), value, startNode, endNode ); addCommand( indexName, command ); }
@Override public void removeNode( String indexName, long id, String keyOrNull, Object valueOrNull ) { RemoveCommand command = new RemoveCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), IndexEntityType.Node.id(), id, definitions().getOrAssignKeyId( keyOrNull ), valueOrNull ); addCommand( indexName, command ); }
@Override public void removeRelationship( String indexName, long id, String keyOrNull, Object valueOrNull ) { RemoveCommand command = new RemoveCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), IndexEntityType.Relationship.id(), id, definitions().getOrAssignKeyId( keyOrNull ), valueOrNull ); addCommand( indexName, command ); }