private Map<String,CommitContext> commitContextMap( byte entityType ) { if ( entityType == IndexEntityType.Node.id() ) { return nodeContexts; } if ( entityType == IndexEntityType.Relationship.id() ) { return relationshipContexts; } throw new IllegalArgumentException( "Unknown entity type " + entityType ); } }
public static IndexEntityType byId( byte id ) { for ( IndexEntityType type : values() ) { if ( type.id() == id ) { return type; } } throw new IllegalArgumentException( "Unknown id " + id ); }
public void init( int indexNameId, long entityId, int keyId, Object value ) { super.init( NeoCommandType.INDEX_ADD_COMMAND, indexNameId, IndexEntityType.Node.id(), entityId, keyId, value ); }
public void init( int indexNameId, long entityId, int keyId, Object value, long startNode, long endNode ) { super.init( NeoCommandType.INDEX_ADD_RELATIONSHIP_COMMAND, indexNameId, IndexEntityType.Relationship.id(), entityId, keyId, value ); this.startNode = startNode; this.endNode = endNode; }
private void addCommand( String indexName, IndexCommand command, boolean clearFirst ) { List<IndexCommand> commands; if ( command.getEntityType() == IndexEntityType.Node.id() ) { commands = nodeCommands.computeIfAbsent( indexName, k -> new ArrayList<>() ); } else if ( command.getEntityType() == IndexEntityType.Relationship.id() ) { commands = relationshipCommands.computeIfAbsent( indexName, k -> new ArrayList<>() ); } else { throw new IllegalArgumentException( "" + command.getEntityType() ); } if ( clearFirst ) { commands.clear(); } commands.add( command ); }
private Map<String,TransactionApplier> applierByIndexMap( IndexCommand command ) { if ( command.getEntityType() == IndexEntityType.Node.id() ) { if ( applierByNodeIndex.isEmpty() ) { applierByNodeIndex = new HashMap<>(); lazyCreateApplierByprovider(); } return applierByNodeIndex; } if ( command.getEntityType() == IndexEntityType.Relationship.id() ) { if ( applierByRelationshipIndex.isEmpty() ) { applierByRelationshipIndex = new HashMap<>(); lazyCreateApplierByprovider(); } return applierByRelationshipIndex; } throw new UnsupportedOperationException( "Unknown entity type " + command.getEntityType() ); }
@Override public void createIndex( IndexEntityType entityType, String indexName, Map<String, String> config ) { CreateCommand command = new CreateCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), entityType.id(), config ); addCommand( indexName, command ); }
@Override public void deleteIndex( IndexEntityType entityType, String indexName ) { DeleteCommand command = new DeleteCommand(); command.init( definitions().getOrAssignIndexNameId( indexName ), entityType.id() ); addCommand( indexName, command, true ); }
private static Command removeNode( int index, long id, int key, Object value ) { IndexCommand.RemoveCommand command = new IndexCommand.RemoveCommand(); command.init( index, IndexEntityType.Node.id(), id, key, value ); return command; }
private static Command removeRelationship( int index, long id, int key, Object value ) { IndexCommand.RemoveCommand command = new IndexCommand.RemoveCommand(); command.init( index, IndexEntityType.Relationship.id(), id, key, value ); return 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 ); }
@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 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 ) ); }
@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 shouldReadNoKeyIdAsMinusOne() throws Exception { // GIVEN InMemoryClosableChannel channel = new InMemoryClosableChannel(); IndexDefineCommand definitions = new IndexDefineCommand(); int indexNameId = 10; definitions.init( ObjectIntHashMap.newWithKeysValues( "myindex", indexNameId ), new ObjectIntHashMap<>() ); definitions.serialize( channel ); RemoveCommand removeCommand = new IndexCommand.RemoveCommand(); removeCommand.init( indexNameId, IndexEntityType.Node.id(), 1234, -1, null ); removeCommand.serialize( channel ); // WHEN PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4(); assertTrue( reader.read( channel ) instanceof IndexDefineCommand ); RemoveCommand readRemoveCommand = (RemoveCommand) reader.read( channel ); // THEN assertEquals( removeCommand.getIndexNameId(), readRemoveCommand.getIndexNameId() ); assertEquals( removeCommand.getEntityType(), readRemoveCommand.getEntityType() ); assertEquals( removeCommand.getEntityId(), readRemoveCommand.getEntityId() ); assertEquals( removeCommand.getKeyId(), readRemoveCommand.getKeyId() ); assertNull( removeCommand.getValue() ); } }
public void init( int indexNameId, long entityId, int keyId, Object value, long startNode, long endNode ) { super.init( NeoCommandType.INDEX_ADD_RELATIONSHIP_COMMAND, indexNameId, IndexEntityType.Relationship.id(), entityId, keyId, value ); this.startNode = startNode; this.endNode = endNode; }
@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 ); }