use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexProviderShellApp method get.
private IndexHits<PropertyContainer> get(AppCommandParser parser, Output out) throws ShellException, RemoteException {
String index = getIndexName(parser);
String key = parser.argument(1, "Key not supplied");
String value = parser.argument(2, "Value not supplied");
Index theIndex = getIndex(index, getEntityType(parser), out);
return theIndex.get(key, value);
}
use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexProviderShellApp method getIndex.
private <T extends PropertyContainer> Index<T> getIndex(String indexName, Class<T> type, Output out) throws RemoteException {
IndexManager index = getServer().getDb().index();
boolean exists = (type.equals(Node.class) && index.existsForNodes(indexName)) || (type.equals(Relationship.class) && index.existsForRelationships(indexName));
if (!exists) {
if (out != null) {
out.println("No such " + type.getSimpleName().toLowerCase() + " index '" + indexName + "'");
}
return null;
}
return (Index<T>) (type.equals(Node.class) ? index.forNodes(indexName) : index.forRelationships(indexName));
}
use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexProviderShellApp method remove.
private void remove(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
NodeOrRelationship current = getCurrent(session);
String index = getIndexName(parser);
String key = parser.argumentWithDefault(1, null);
Object value = null;
if (key != null) {
value = parser.argumentWithDefault(2, null);
}
Index theIndex;
if (current.isNode()) {
theIndex = getIndex(index, Node.class, out);
} else {
theIndex = getIndex(index, Relationship.class, out);
}
if (theIndex != null) {
if (key != null && value != null) {
theIndex.remove(current.asPropertyContainer(), key, value);
} else if (key != null) {
theIndex.remove(current.asPropertyContainer(), key);
} else {
theIndex.remove(current.asPropertyContainer());
}
}
}
use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexOperationsIT method index_objects_can_be_reused_after_role_switch.
@Test
public void index_objects_can_be_reused_after_role_switch() throws Throwable {
// GIVEN
// -- an existing index
String key = "key", value = "value";
HighlyAvailableGraphDatabase master = cluster.getMaster();
long nodeId = createNode(master, key, value, true);
cluster.sync();
// -- get Index and IndexManager references to all dbs
Map<HighlyAvailableGraphDatabase, IndexManager> indexManagers = new HashMap<>();
Map<HighlyAvailableGraphDatabase, Index<Node>> indexes = new HashMap<>();
for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
try (Transaction transaction = db.beginTx()) {
indexManagers.put(db, db.index());
indexes.put(db, db.index().forNodes(key));
transaction.success();
}
}
// WHEN
// -- there's a master switch
RepairKit repair = cluster.shutdown(master);
indexManagers.remove(master);
indexes.remove(master);
cluster.await(ClusterManager.masterAvailable(master));
cluster.await(ClusterManager.masterSeesSlavesAsAvailable(1));
// -- the index instances should still be viable to use
for (Map.Entry<HighlyAvailableGraphDatabase, IndexManager> entry : indexManagers.entrySet()) {
HighlyAvailableGraphDatabase db = entry.getKey();
try (Transaction transaction = db.beginTx()) {
IndexManager indexManager = entry.getValue();
assertTrue(indexManager.existsForNodes(key));
assertEquals(nodeId, indexManager.forNodes(key).get(key, value).getSingle().getId());
}
}
for (Map.Entry<HighlyAvailableGraphDatabase, Index<Node>> entry : indexes.entrySet()) {
HighlyAvailableGraphDatabase db = entry.getKey();
try (Transaction transaction = db.beginTx()) {
Index<Node> index = entry.getValue();
assertEquals(nodeId, index.get(key, value).getSingle().getId());
}
}
repair.repair();
}
use of org.neo4j.graphdb.index.Index in project neo4j by neo4j.
the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.
private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
final AtomicBoolean success = new AtomicBoolean(false);
try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
boolean startFound = false;
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
if (startFound) {
throw new IllegalArgumentException("More than one start entry");
}
startFound = true;
}
if (startFound && entry instanceof LogEntryCommand) {
commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
}
if (entry instanceof LogEntryCommit) {
// The first COMMIT
assertTrue(startFound);
assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
assertEquals(1, createCommands.size());
success.set(true);
break;
}
}
}
assertTrue("Didn't find any commit record in log " + version, success.get());
}
Aggregations