Search in sources :

Example 1 with UriResolver

use of apoc.util.UriResolver in project neo4j-apoc-procedures by neo4j-contrib.

the class Bolt method load.

@Procedure()
@Description("apoc.bolt.load(url-or-key, statement, params, config) - access to other databases via bolt for read")
public Stream<RowResult> load(@Name("url") String url, @Name("statement") String statement, @Name(value = "params", defaultValue = "{}") Map<String, Object> params, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws URISyntaxException {
    if (params == null)
        params = Collections.emptyMap();
    if (config == null)
        config = Collections.emptyMap();
    boolean virtual = (boolean) config.getOrDefault("virtual", false);
    boolean addStatistics = (boolean) config.getOrDefault("statistics", false);
    boolean readOnly = (boolean) config.getOrDefault("readOnly", true);
    Config driverConfig = toDriverConfig(config.getOrDefault("driverConfig", map()));
    UriResolver uri = new UriResolver(url, "bolt");
    uri.initialize();
    try (Driver driver = GraphDatabase.driver(uri.getConfiguredUri(), uri.getToken(), driverConfig);
        Session session = driver.session()) {
        if (addStatistics)
            return Stream.of(new RowResult(toMap(runStatement(statement, session, params, readOnly).summary().counters())));
        else
            return getRowResultStream(virtual, session, params, statement, readOnly);
    } catch (Exception e) {
        throw new RuntimeException("It's not possible to create a connection due to: " + e.getMessage());
    }
}
Also used : RowResult(apoc.result.RowResult) UriResolver(apoc.util.UriResolver) URISyntaxException(java.net.URISyntaxException) Description(apoc.Description) Procedure(org.neo4j.procedure.Procedure)

Aggregations

Description (apoc.Description)1 RowResult (apoc.result.RowResult)1 UriResolver (apoc.util.UriResolver)1 URISyntaxException (java.net.URISyntaxException)1 Procedure (org.neo4j.procedure.Procedure)1