diff --git a/core/src/main/java/apoc/util/Util.java b/core/src/main/java/apoc/util/Util.java index e4145acb76..b1d5205eb4 100644 --- a/core/src/main/java/apoc/util/Util.java +++ b/core/src/main/java/apoc/util/Util.java @@ -66,6 +66,9 @@ import java.util.zip.ZipInputStream; import javax.lang.model.SourceVersion; +import org.neo4j.configuration.Config; +import org.neo4j.configuration.connectors.BoltConnector; +import org.neo4j.dbms.api.DatabaseManagementService; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.Entity; import org.neo4j.graphdb.GraphDatabaseService; @@ -89,6 +92,7 @@ import static apoc.ApocConfig.apocConfig; import static apoc.util.DateFormatUtil.getOrCreate; import static java.lang.String.format; +import static org.neo4j.configuration.GraphDatabaseSettings.SYSTEM_DATABASE_NAME; /** * @author mh @@ -695,24 +699,13 @@ public static String withMapping(Stream columns, Function Iterators.single(result.columnAs("role"))); - return role.equalsIgnoreCase("LEADER"); - } catch(QueryExecutionException e) { - if (e.getStatusCode().equalsIgnoreCase("Neo.ClientError.Procedure.ProcedureNotFound")) return true; - throw e; - } + public static boolean isWriteableInstance( GraphDatabaseAPI db ) + { + var socketAddress = db.getDependencyResolver().resolveDependency( Config.class ).get( BoltConnector.advertised_address ).toString(); + GraphDatabaseService systemDb = db.getDependencyResolver().resolveDependency( DatabaseManagementService.class ).database( SYSTEM_DATABASE_NAME ); + String role = systemDb.executeTransactionally( "SHOW DATABASE $databaseName WHERE address = $socketAddress", + Map.of( "databaseName", db.databaseName(), "socketAddress", socketAddress ), result -> Iterators.single( result.columnAs( "role" ) ) ); + return role.equalsIgnoreCase( "LEADER" ) || role.equalsIgnoreCase( "standalone" ); } /**