use of org.neo4j.graphdb.ResourceIterator in project neo4j by neo4j.
the class GraphDatabaseFacade method allNodesWithLabel.
private ResourceIterator<Node> allNodesWithLabel(final Label myLabel) {
Statement statement = spi.currentStatement();
int labelId = statement.readOperations().labelGetForName(myLabel.name());
if (labelId == KeyReadOperations.NO_SUCH_LABEL) {
statement.close();
return emptyIterator();
}
final PrimitiveLongIterator nodeIds = statement.readOperations().nodesGetForLabel(labelId);
return ResourceClosingIterator.newResourceIterator(statement, map(nodeId -> new NodeProxy(nodeActions, nodeId), nodeIds));
}
use of org.neo4j.graphdb.ResourceIterator in project neo4j by neo4j.
the class NeoStoreFileListing method gatherLegacyIndexFiles.
private Resource gatherLegacyIndexFiles(Collection<StoreFileMetadata> files) throws IOException {
final Collection<ResourceIterator<File>> snapshots = new ArrayList<>();
for (IndexImplementation indexProvider : legacyIndexProviders.all()) {
ResourceIterator<File> snapshot = indexProvider.listStoreFiles();
snapshots.add(snapshot);
snapshot.stream().map(toNotAStoreTypeFile).collect(Collectors.toCollection(() -> files));
}
// the targetFiles list.
return new MultiResource(snapshots);
}
use of org.neo4j.graphdb.ResourceIterator in project elasticsearch-river-neo4j by sksamuel.
the class SimpleIndexingStrategyTest method thatNodePropertiesAreUsedAsFieldValues.
@Test
public void thatNodePropertiesAreUsedAsFieldValues() throws IOException {
long id = new Random().nextInt(50000) + 1;
Node node = mock(Node.class);
when(node.getId()).thenReturn(id);
when(node.getPropertyKeys()).thenReturn(Arrays.asList("name", "location", "band"));
when(node.getProperty("name")).thenReturn("chris martin");
when(node.getProperty("location")).thenReturn("hampstead");
when(node.getProperty("band")).thenReturn("coldplay");
when(node.hasLabel(DynamicLabel.label("User"))).thenReturn(true);
when(node.getLabels()).thenReturn(new ResourceIterable<Label>() {
@Override
public ResourceIterator<Label> iterator() {
return new ResourceIterator<Label>() {
private List<Label> labels = Arrays.asList(DynamicLabel.label("User"), DynamicLabel.label("Swedish"));
private int position = 0;
@Override
public void close() {
}
@Override
public boolean hasNext() {
boolean result = false;
if (position < labels.size()) {
result = true;
}
return result;
}
@Override
public Label next() {
Label label = labels.get(position);
position++;
return label;
}
@Override
public void remove() {
}
};
}
});
IndexRequest req = s.build("neo4j-index", "node", node, 12);
assertEquals("neo4j-index", req.index());
assertEquals("node", req.type());
assertEquals(12, req.sourceAsMap().get("version"));
assertEquals(String.valueOf(id), req.id());
assertEquals(new ArrayList<String>() {
{
add("User");
add("Swedish");
}
}, req.sourceAsMap().get("labels"));
assertEquals("coldplay", req.sourceAsMap().get("band"));
assertEquals("hampstead", req.sourceAsMap().get("location"));
assertEquals("chris martin", req.sourceAsMap().get("name"));
}
use of org.neo4j.graphdb.ResourceIterator in project neo4j by neo4j.
the class AbstractLuceneIndex method snapshot.
/**
* Snapshot of all file in all index partitions.
*
* @return iterator over all index files.
* @throws IOException
* @see WritableIndexSnapshotFileIterator
*/
public ResourceIterator<File> snapshot() throws IOException {
ensureOpen();
List<ResourceIterator<File>> snapshotIterators = null;
try {
List<AbstractIndexPartition> partitions = getPartitions();
snapshotIterators = new ArrayList<>(partitions.size());
for (AbstractIndexPartition partition : partitions) {
snapshotIterators.add(partition.snapshot());
}
return Iterators.concatResourceIterators(snapshotIterators.iterator());
} catch (Exception e) {
if (snapshotIterators != null) {
try {
IOUtils.closeAll(snapshotIterators);
} catch (IOException ex) {
throw Exceptions.withCause(ex, e);
}
}
throw e;
}
}
use of org.neo4j.graphdb.ResourceIterator in project neo4j by neo4j.
the class CommunityLockAcquisitionTimeoutIT method timeoutOnAcquiringSharedLock.
@Test(timeout = TEST_TIMEOUT)
public void timeoutOnAcquiringSharedLock() throws Exception {
expectedException.expect(new RootCauseMatcher<>(LockAcquisitionTimeoutException.class, "The transaction has been terminated. " + "Retry your operation in a new transaction, and you should see a successful result. " + "Unable to acquire lock within configured timeout. " + "Unable to acquire lock for resource: SCHEMA with id: 0 within 2000 millis."));
try (Transaction ignored = database.beginTx()) {
database.schema().indexFor(marker).on(TEST_PROPERTY_NAME).create();
Future<Void> propertySetFuture = secondTransactionExecutor.executeDontWait(state -> {
try (Transaction nestedTransaction = database.beginTx()) {
ResourceIterator<Node> nodes = database.findNodes(marker);
Node node = nodes.next();
node.addLabel(Label.label("anotherLabel"));
nestedTransaction.success();
}
return null;
});
secondTransactionExecutor.waitUntilWaiting(sharedLockWaitingPredicate());
clockExecutor.execute((OtherThreadExecutor.WorkerCommand<Void, Void>) state -> {
fakeClock.forward(3, TimeUnit.SECONDS);
return null;
});
propertySetFuture.get();
fail("Should throw termination exception.");
}
}
Aggregations