Skip to content

Commit

Permalink
fix: console ignored arcadedb.server.databaseDirectory setting
Browse files Browse the repository at this point in the history
Fixed issue #752
  • Loading branch information
lvca committed Jan 9, 2023
1 parent a0f4e1b commit 0343689
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 55 deletions.
9 changes: 0 additions & 9 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,16 @@
<groupId>com.arcadedb</groupId>
<artifactId>arcadedb-engine</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.arcadedb</groupId>
<artifactId>arcadedb-network</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.arcadedb</groupId>
<artifactId>arcadedb-server</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.arcadedb</groupId>
<artifactId>arcadedb-integration</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
Expand Down
59 changes: 25 additions & 34 deletions console/src/main/java/com/arcadedb/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.arcadedb.console;

import com.arcadedb.Constants;
import com.arcadedb.ContextConfiguration;
import com.arcadedb.GlobalConfiguration;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.DatabaseInternal;
Expand All @@ -27,6 +28,7 @@
import com.arcadedb.engine.PaginatedFile;
import com.arcadedb.graph.Edge;
import com.arcadedb.graph.Vertex;
import com.arcadedb.integration.misc.IntegrationUtils;
import com.arcadedb.query.sql.executor.MultiValue;
import com.arcadedb.query.sql.executor.Result;
import com.arcadedb.query.sql.executor.ResultInternal;
Expand All @@ -51,32 +53,36 @@
import java.util.*;

public class Console {
private static final String PROMPT = "%n%s> ";
private static final String REMOTE_PREFIX = "remote:";
private static final String SQL_LANGUAGE = "SQL";
private final boolean system = System.console() != null;
private final Terminal terminal;
private final TerminalParser parser = new TerminalParser();
private RemoteDatabase remoteDatabase;
private ConsoleOutput output;
private DatabaseFactory databaseFactory;
private DatabaseInternal localDatabase;
private int limit = 20;
private int maxMultiValueEntries = 10;
private int maxWidth = TableFormatter.DEFAULT_MAX_WIDTH;
private Boolean expandResultSet;
private ResultSet resultSet;
private String databaseDirectory;
private int verboseLevel = 1;
private String language = SQL_LANGUAGE;
private static final String PROMPT = "%n%s> ";
private static final String REMOTE_PREFIX = "remote:";
private static final String SQL_LANGUAGE = "SQL";
private final boolean system = System.console() != null;
private final Terminal terminal;
private final TerminalParser parser = new TerminalParser();
private RemoteDatabase remoteDatabase;
private ConsoleOutput output;
private DatabaseFactory databaseFactory;
private DatabaseInternal localDatabase;
private int limit = 20;
private int maxMultiValueEntries = 10;
private int maxWidth = TableFormatter.DEFAULT_MAX_WIDTH;
private Boolean expandResultSet;
private ResultSet resultSet;
private String databaseDirectory;
private int verboseLevel = 1;
private String language = SQL_LANGUAGE;
private final ContextConfiguration configuration = new ContextConfiguration();

public Console(final DatabaseInternal database) throws IOException {
this(false);
this.localDatabase = database;
}

public Console(final boolean interactive) throws IOException {
setRootPath(".");
IntegrationUtils.setRootPath(configuration);
databaseDirectory = configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY);
if (!databaseDirectory.endsWith(File.separator))
databaseDirectory += File.separator;

GlobalConfiguration.PROFILE.setValue("low-cpu");

Expand Down Expand Up @@ -155,21 +161,6 @@ public void close() {
}
}

public Console setRootPath(final String rootDirectory) {
String root = rootDirectory;
if (root == null || root.isEmpty())
root = ".";
else if (root.endsWith(File.separator))
root = root.substring(0, root.length() - 1);

if (!new File(root + File.separator + "config").exists() && new File(root + File.separator + ".." + File.separator + "config").exists()) {
databaseDirectory = new File(root).getAbsoluteFile().getParentFile().getPath() + File.separator + "databases" + File.separator;
} else
databaseDirectory = root + File.separator + "databases" + File.separator;

return this;
}

public void setOutput(final ConsoleOutput output) {
this.output = output;
}
Expand Down
6 changes: 4 additions & 2 deletions console/src/test/java/com/arcadedb/console/ConsoleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.arcadedb.console;

import com.arcadedb.GlobalConfiguration;
import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.exception.DatabaseOperationException;
Expand All @@ -43,7 +44,8 @@ public class ConsoleTest {
@BeforeEach
public void populate() throws IOException {
FileUtils.deleteRecursively(new File("./target/databases"));
console = new Console(false).setRootPath("./target");
GlobalConfiguration.SERVER_ROOT_PATH.setValue("./target");
console = new Console(false);
Assertions.assertTrue(console.parse("create database " + DB_NAME + "; close", false));
}

Expand Down Expand Up @@ -228,7 +230,7 @@ public void testImportNeo4jConsoleOK() throws IOException {

Console.main(new String[] { "create database " + DATABASE_PATH + ";import database file://src/test/resources/neo4j-export-mini.jsonl" });

try (final DatabaseFactory factory = new DatabaseFactory("databases/" + DATABASE_PATH)) {
try (final DatabaseFactory factory = new DatabaseFactory("./target/databases/" + DATABASE_PATH)) {
try (final Database database = factory.open()) {
final DocumentType personType = database.getSchema().getType("User");
Assertions.assertNotNull(personType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023 Arcade Data Ltd
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.arcadedb.integration.misc;

import com.arcadedb.ContextConfiguration;
import com.arcadedb.GlobalConfiguration;

import java.io.*;

/**
* Utility class for common packages.
*
* @author Luca Garulli ([email protected])
*/
public class IntegrationUtils {
public static String setRootPath(final ContextConfiguration configuration) {
String serverRootPath = configuration.getValueAsString(GlobalConfiguration.SERVER_ROOT_PATH);
if (serverRootPath == null) {
serverRootPath = new File("config").exists() ? "." : new File("../config").exists() ? ".." : ".";
configuration.setValue(GlobalConfiguration.SERVER_ROOT_PATH, serverRootPath);
}
return serverRootPath;
}
}
13 changes: 3 additions & 10 deletions server/src/main/java/com/arcadedb/server/ArcadeDBServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.arcadedb.exception.CommandExecutionException;
import com.arcadedb.exception.ConfigurationException;
import com.arcadedb.exception.DatabaseIsClosedException;
import com.arcadedb.integration.misc.IntegrationUtils;
import com.arcadedb.log.LogManager;
import com.arcadedb.query.QueryEngineManager;
import com.arcadedb.server.ha.HAServer;
Expand Down Expand Up @@ -70,7 +71,7 @@ public enum STATUS {OFFLINE, STARTING, ONLINE, SHUTTING_DOWN}

public ArcadeDBServer() {
this.configuration = new ContextConfiguration();
setRootPath(configuration);
serverRootPath = IntegrationUtils.setRootPath(configuration);
loadConfiguration();
this.serverName = configuration.getValueAsString(GlobalConfiguration.SERVER_NAME);
this.testEnabled = configuration.getValueAsBoolean(GlobalConfiguration.TEST);
Expand All @@ -79,7 +80,7 @@ public ArcadeDBServer() {

public ArcadeDBServer(final ContextConfiguration configuration) {
this.configuration = configuration;
setRootPath(configuration);
serverRootPath = IntegrationUtils.setRootPath(configuration);
this.serverName = configuration.getValueAsString(GlobalConfiguration.SERVER_NAME);
this.testEnabled = configuration.getValueAsBoolean(GlobalConfiguration.TEST);
init();
Expand Down Expand Up @@ -539,14 +540,6 @@ private void loadConfiguration() {
}
}

private void setRootPath(final ContextConfiguration configuration) {
serverRootPath = configuration.getValueAsString(GlobalConfiguration.SERVER_ROOT_PATH);
if (serverRootPath == null) {
serverRootPath = new File("config").exists() ? "." : new File("../config").exists() ? ".." : ".";
configuration.setValue(GlobalConfiguration.SERVER_ROOT_PATH, serverRootPath);
}
}

private void init() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
stop();
Expand Down

0 comments on commit 0343689

Please sign in to comment.