From af3d18f898a123632aacf8637aad82d3e007ec93 Mon Sep 17 00:00:00 2001 From: gartens <41197811+gartens@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:09:01 +0100 Subject: [PATCH] Fix Neo4j remote deployment (#526) --- .../polypheny/db/adapter/AdapterManager.java | 8 ++++++ .../org/polypheny/db/adapter/DeployMode.java | 18 +++++-------- .../db/adapter/neo4j/Neo4jPlugin.java | 27 ++++++++++--------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/adapter/AdapterManager.java b/core/src/main/java/org/polypheny/db/adapter/AdapterManager.java index 352d13e5cc..4d1aa30957 100644 --- a/core/src/main/java/org/polypheny/db/adapter/AdapterManager.java +++ b/core/src/main/java/org/polypheny/db/adapter/AdapterManager.java @@ -29,6 +29,7 @@ import org.apache.calcite.linq4j.tree.Expression; import org.apache.calcite.linq4j.tree.Expressions; import org.jetbrains.annotations.NotNull; +import org.polypheny.db.adapter.DeployMode.DeploySetting; import org.polypheny.db.adapter.annotations.AdapterProperties; import org.polypheny.db.adapter.java.AdapterTemplate; import org.polypheny.db.catalog.Catalog; @@ -176,6 +177,13 @@ public Adapter addAdapter( String adapterName, String uniqueName, AdapterType AdapterTemplate adapterTemplate = AdapterTemplate.fromString( adapterName, adapterType ); + + for ( AbstractAdapterSetting setting : adapterTemplate.settings ) { + if ( setting.appliesTo.stream().noneMatch( s -> s.appliesTo( mode ) ) ) { + settings.remove( setting.name ); + } + } + long adapterId = Catalog.getInstance().createAdapter( uniqueName, adapterName, adapterType, settings, mode ); try { Adapter adapter = adapterTemplate.getDeployer().get( adapterId, uniqueName, settings, mode ); diff --git a/core/src/main/java/org/polypheny/db/adapter/DeployMode.java b/core/src/main/java/org/polypheny/db/adapter/DeployMode.java index 812aaa7ab2..2c623bb2ae 100644 --- a/core/src/main/java/org/polypheny/db/adapter/DeployMode.java +++ b/core/src/main/java/org/polypheny/db/adapter/DeployMode.java @@ -35,17 +35,6 @@ public enum DeployMode { } - public static DeployMode fromString( String mode ) { - if ( mode.equals( "remote" ) ) { - return REMOTE; - } else if ( mode.equals( "docker" ) ) { - return DOCKER; - } else { - return EMBEDDED; - } - } - - public enum DeploySetting { REMOTE( DeployMode.REMOTE ), DOCKER( DeployMode.DOCKER ), @@ -83,5 +72,10 @@ List getModes( List availableModes ) { } } + + boolean appliesTo( DeployMode mode ) { + return usedByAll || this.mode.equals( mode ); + } + } -} \ No newline at end of file +} diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java index e47842d40b..4501264812 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/Neo4jPlugin.java @@ -43,8 +43,11 @@ import org.polypheny.db.adapter.DataStore; import org.polypheny.db.adapter.DataStore.IndexMethodModel; import org.polypheny.db.adapter.DeployMode; +import org.polypheny.db.adapter.DeployMode.DeploySetting; import org.polypheny.db.adapter.GraphModifyDelegate; import org.polypheny.db.adapter.annotations.AdapterProperties; +import org.polypheny.db.adapter.annotations.AdapterSettingInteger; +import org.polypheny.db.adapter.annotations.AdapterSettingString; import org.polypheny.db.adapter.neo4j.types.NestedSingleType; import org.polypheny.db.adapter.neo4j.util.NeoUtil; import org.polypheny.db.catalog.catalogs.GraphAdapterCatalog; @@ -130,12 +133,16 @@ private static String getMappingLabel( long id ) { @Slf4j + @Extension @AdapterProperties( name = "Neo4j", description = "Neo4j is a graph-model based database system. It stores data in a graph structure which consists of nodes and edges.", usedModes = { DeployMode.DOCKER, DeployMode.REMOTE }, defaultMode = DeployMode.DOCKER) - @Extension + @AdapterSettingString(name = "host", defaultValue = "localhost", appliesTo = DeploySetting.REMOTE) + @AdapterSettingInteger(name = "port", defaultValue = 7687, appliesTo = DeploySetting.REMOTE) + @AdapterSettingString(name = "user", defaultValue = "neo4j", appliesTo = DeploySetting.REMOTE) + @AdapterSettingString(name = "password", defaultValue = "neo4j", appliesTo = DeploySetting.REMOTE) public static class Neo4jStore extends DataStore { private final String DEFAULT_DATABASE = "public"; @@ -152,9 +159,6 @@ public static class Neo4jStore extends DataStore { @Getter private NeoNamespace currentNamespace; - @Getter - private NeoGraph currentGraph; - private final TransactionProvider transactionProvider; private String host; @@ -173,7 +177,6 @@ public Neo4jStore( final long adapterId, final String uniqueName, final Map