private Pair<Map<String, String>, /*was it created now?*/ Boolean> getOrCreateIndexConfig( Class<? extends PropertyContainer> cls, String indexName, Map<String, String> suppliedConfig) { Pair<Map<String, String>, Boolean> result = findIndexConfig(cls, indexName, suppliedConfig, config.getParams()); boolean createdNow = false; if (result.other()) { // Ok, we need to create this config synchronized (this) { // Were we the first ones to get here? Map<String, String> existing = indexStore.get(cls, indexName); if (existing != null) { // No, someone else made it before us, cool assertConfigMatches( getIndexProvider(existing.get(PROVIDER)), indexName, existing, result.first()); return Pair.of(result.first(), false); } // We were the first one here, let's create this config ExecutorService executorService = Executors.newSingleThreadExecutor(); try { executorService.submit(new IndexCreatorJob(cls, indexName, result.first())).get(); indexStore.set(cls, indexName, result.first()); createdNow = true; } catch (ExecutionException ex) { throw new TransactionFailureException( "Index creation failed for " + indexName + ", " + result.first(), ex.getCause()); } catch (InterruptedException ex) { Thread.interrupted(); } finally { executorService.shutdownNow(); } } } return Pair.of(result.first(), createdNow); }
@Override public Map<String, String> getConfiguration(Index<? extends PropertyContainer> index) { Map<String, String> config = indexStore.get(index.getEntityType(), index.getName()); if (config == null) { throw new NotFoundException( "No " + index.getEntityType().getSimpleName() + " index '" + index.getName() + "' found"); } return config; }
private void removeProvidersFromIndexDbFile(File storeDir) { IndexStore indexStore = new IndexStore(storeDir.getPath()); for (Class<? extends PropertyContainer> cls : new Class[] {Node.class, Relationship.class}) { for (String name : indexStore.getNames(cls)) { Map<String, String> config = indexStore.get(cls, name); config = new HashMap<String, String>(config); config.remove(IndexManager.PROVIDER); indexStore.set(Node.class, name, config); } } }
private Map<String, String> config( Class<? extends PropertyContainer> cls, String indexName, Map<String, String> config) { // TODO Doesn't look right if (config != null) { config = MapUtil.stringMap( new HashMap<String, String>(config), "provider", BerkeleyDbIndexImplementation.SERVICE_NAME); indexStore.setIfNecessary(cls, indexName, config); return config; } else { return indexStore.get(cls, indexName); } }
private Pair<Map<String, String>, Boolean /*true=needs to be set*/> findIndexConfig( Class<? extends PropertyContainer> cls, String indexName, Map<String, String> suppliedConfig, Map<?, ?> dbConfig) { // Check stored config (has this index been created previously?) Map<String, String> storedConfig = indexStore.get(cls, indexName); if (storedConfig != null && suppliedConfig == null) { // Fill in "provider" if not already filled in, backwards compatibility issue Map<String, String> newConfig = injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig); if (newConfig != storedConfig) { indexStore.set(cls, indexName, newConfig); } return Pair.of(newConfig, Boolean.FALSE); } Map<String, String> configToUse = suppliedConfig; // Check db config properties for provider String provider = null; IndexImplementation indexProvider = null; if (configToUse == null) { provider = getDefaultProvider(indexName, dbConfig); configToUse = MapUtil.stringMap(PROVIDER, provider); } else { provider = configToUse.get(PROVIDER); provider = provider == null ? getDefaultProvider(indexName, dbConfig) : provider; } indexProvider = getIndexProvider(provider); configToUse = indexProvider.fillInDefaults(configToUse); configToUse = injectDefaultProviderIfMissing(cls, indexName, dbConfig, configToUse); // Do they match (stored vs. supplied)? if (storedConfig != null) { assertConfigMatches(indexProvider, indexName, storedConfig, suppliedConfig); // Fill in "provider" if not already filled in, backwards compatibility issue Map<String, String> newConfig = injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig); if (newConfig != storedConfig) { indexStore.set(cls, indexName, newConfig); } configToUse = newConfig; } boolean needsToBeSet = !indexStore.has(cls, indexName); return Pair.of(Collections.unmodifiableMap(configToUse), needsToBeSet); }
@Override public boolean existsForRelationships(String indexName) { return indexStore.get(Relationship.class, indexName) != null; }
@Override public boolean existsForNodes(String indexName) { return indexStore.get(Node.class, indexName) != null; }
@Override public boolean existsForNodes(String indexName) { assertInTransaction(); return indexStore.get(Node.class, indexName) != null; }