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 ); } }
@Override public String toString() { return "Delete[index:" + indexNameId + ", type:" + IndexEntityType.byId( entityType ).nameToLowerCase() + "]"; }
@Override public boolean checkIndexExistence( IndexEntityType entityType, String indexName, Map<String,String> config ) { Map<String, String> configuration = indexConfigStore.get( entityType.entityClass(), indexName ); if ( configuration == null ) { return false; } String providerName = configuration.get( IndexManager.PROVIDER ); IndexImplementation provider = providerLookup.getProviderByName( providerName ); assertConfigMatches( provider, indexName, configuration, config ); return true; }
@Override public boolean visitIndexCreateCommand( IndexCommand.CreateCommand command ) throws IOException { indexConfigStore.setIfNecessary( IndexEntityType.byId( command.getEntityType() ).entityClass(), defineCommand.getIndexName( command.getIndexNameId() ), command.getConfig() ); return applier( command ).visitIndexCreateCommand( command ); }
@Override public String toString() { return "Index[" + indexName + "," + entityType.nameToLowerCase() + "]"; } }
private CommitContext commitContext( IndexCommand command ) throws ExplicitIndexNotFoundKernelException { Map<String,CommitContext> contextMap = commitContextMap( command.getEntityType() ); String indexName = definitions.getIndexName( command.getIndexNameId() ); CommitContext context = contextMap.get( indexName ); if ( context == null ) { IndexIdentifier identifier = new IndexIdentifier( IndexEntityType.byId( command.getEntityType() ), indexName ); // TODO the fact that we look up index type from config here using the index store // directly should be avoided. But how can we do it in, say recovery? // The `dataSource.getType()` call can throw an exception if the index is concurrently deleted. // To avoid bubbling an exception during commit, we instead ignore the commands related to that index, // and proceed as if the index never existed, and thus cannot accept any modifications. IndexType type = dataSource.getType( identifier, recovery ); context = new CommitContext( dataSource, identifier, type, recovery ); contextMap.put( indexName, context ); } return context; }
public String nameToLowerCase() { return this.name().toLowerCase(); } }
private int calculateHashCode() { int code = 17; code += 7 * entityType.hashCode(); code += 7 * indexName.hashCode(); return code; }
IndexEntityType entityType = IndexEntityType.byId( command.getEntityType() ); Map<String,String> config = indexConfigStore.get( entityType.entityClass(), indexName ); if ( config == null )
private static File getFileDirectory( File storeDir, IndexEntityType type ) { File path = new File( storeDir, "lucene" ); String extra = type.nameToLowerCase(); return new File( path, extra ); }
public String nameToLowerCase() { return this.name().toLowerCase(); } }
public void init( int indexNameId, long entityId, int keyId, Object value ) { super.init( NeoCommandType.INDEX_ADD_COMMAND, indexNameId, IndexEntityType.Node.id(), entityId, keyId, value ); }
@Override public String toString() { return format( "Create%sIndex[index:%d, config:%s]", IndexEntityType.byId( entityType ).nameToLowerCase(), indexNameId, config ); }
@Override public boolean visitIndexCreateCommand( IndexCommand.CreateCommand command ) throws IOException { indexConfigStore.setIfNecessary( IndexEntityType.byId( command.getEntityType() ).entityClass(), defineCommand.getIndexName( command.getIndexNameId() ), command.getConfig() ); return applier( command ).visitIndexCreateCommand( command ); }
@Test public void shouldLowerCaseEnumName() { assertEquals( "node", IndexEntityType.Node.nameToLowerCase() ); assertEquals( "relationship", IndexEntityType.Relationship.nameToLowerCase() ); } }
void deleteIndex( IndexIdentifier identifier, boolean recovery ) throws IOException { if ( readOnly ) { throw new IllegalStateException( "Index deletion in read only mode is not supported." ); } closeIndex( identifier ); FileUtils.deleteRecursively( getFileDirectory( baseStorePath, identifier ) ); indexTypeMap.remove( identifier ); boolean removeFromIndexStore = !recovery || (indexStore.has( identifier.entityType.entityClass(), identifier.indexName )); if ( removeFromIndexStore ) { indexStore.remove( identifier.entityType.entityClass(), identifier.indexName ); } typeCache.invalidate( identifier ); }
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 String toString() { return format( "Remove%s[index:%d, id:%d, key:%d, value:%s]", IndexEntityType.byId( entityType ).nameToLowerCase(), indexNameId, entityId, keyId, value ); }