use of org.neo4j.graphdb.index.Index in project neo4j-clean-remote-db-addon by jexp.
the class Neo4jDatabaseCleaner method getMutableIndex.
private <T extends PropertyContainer> Index<T> getMutableIndex(Index<T> index) {
final Class<? extends Index> indexClass = index.getClass();
if (indexClass.getName().endsWith("ReadOnlyIndexToIndexAdapter")) {
try {
final Field delegateIndexField = indexClass.getDeclaredField("delegate");
delegateIndexField.setAccessible(true);
return (Index<T>) delegateIndexField.get(index);
} catch (Exception e) {
throw new UnsupportedOperationException(e);
}
} else {
return index;
}
}
use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexProviderShellApp method index.
private void index(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
NodeOrRelationship current = getCurrent(session);
String index = getIndexName(parser);
String key = parser.argument(1, "Key not supplied");
Object value = parser.arguments().size() > 2 ? parser.arguments().get(2) : current.getProperty(key, null);
if (value == null) {
throw new ShellException("No value to index");
}
Index theIndex = current.isNode() ? getServer().getDb().index().forNodes(index) : getServer().getDb().index().forRelationships(index);
theIndex.add(current.asPropertyContainer(), key, value);
}
use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexProviderShellApp method query.
private IndexHits<PropertyContainer> query(AppCommandParser parser, Output out) throws RemoteException, ShellException {
String index = getIndexName(parser);
String query1 = parser.argument(1, "Key not supplied");
String query2 = parser.argumentWithDefault(2, null);
Index theIndex = getIndex(index, getEntityType(parser), out);
return query2 != null ? theIndex.query(query1, query2) : theIndex.query(query1);
}
use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexCreationTest method indexCreationConfigRaceCondition.
@Test
public void indexCreationConfigRaceCondition() throws Exception {
// a couple of times to be sure.
for (int run = 0; run < 10; run++) {
final int r = run;
final CountDownLatch latch = new CountDownLatch(1);
ExecutorService executor = newCachedThreadPool();
for (int thread = 0; thread < 10; thread++) {
executor.submit((Runnable) () -> {
try (Transaction tx = db.beginTx()) {
latch.await();
Index<Node> index = db.index().forNodes("index" + r);
Node node = db.createNode();
index.add(node, "name", "Name");
tx.success();
} catch (InterruptedException e) {
Thread.interrupted();
}
});
}
latch.countDown();
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
verifyThatIndexCreationTransactionIsTheFirstOne();
}
}
use of org.neo4j.graphdb.index.Index in project neo4j-apoc-procedures by neo4j-contrib.
the class IndexUpdateTransactionEventHandler method initIndexConfiguration.
// might be run from a scheduler, so we need to make sure we have a transaction
private synchronized Map<String, Map<String, Collection<Index<Node>>>> initIndexConfiguration() {
Map<String, Map<String, Collection<Index<Node>>>> indexesByLabelAndProperty = new HashMap<>();
try (Transaction tx = graphDatabaseService.beginTx()) {
final IndexManager indexManager = graphDatabaseService.index();
for (String indexName : indexManager.nodeIndexNames()) {
final Index<Node> index = indexManager.forNodes(indexName);
Map<String, String> indexConfig = indexManager.getConfiguration(index);
if (Util.toBoolean(indexConfig.get("autoUpdate"))) {
String labels = indexConfig.getOrDefault("labels", "");
for (String label : labels.split(":")) {
Map<String, Collection<Index<Node>>> propertyKeyToIndexMap = indexesByLabelAndProperty.computeIfAbsent(label, s -> new HashMap<>());
String[] keysForLabel = indexConfig.getOrDefault("keysForLabel:" + label, "").split(":");
for (String property : keysForLabel) {
propertyKeyToIndexMap.computeIfAbsent(property, s -> new ArrayList<>()).add(index);
}
}
}
}
tx.success();
}
return indexesByLabelAndProperty;
}
Aggregations