Skip to content

Commit 04f4628

Browse files
committed
Fix H2 Server.
1 parent dbcaf80 commit 04f4628

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>de.ree6</groupId>
88
<artifactId>Ree6-SQL</artifactId>
99
<description>This is the SQL-Module for Ree6!</description>
10-
<version>2.2.3</version>
10+
<version>2.2.4</version>
1111

1212
<properties>
1313
<sonar.organization>ree6-applications</sonar.organization>

src/main/java/de/presti/ree6/sql/SQLSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public SQLSession(SQLConfig config) {
146146
if (databaseTyp == DatabaseTyp.H2) {
147147
try {
148148
embeddedDatabaseServer = new H2DatabaseServer();
149-
embeddedDatabaseServer.createServer();
149+
embeddedDatabaseServer.createServer(config.getPort(), config.getPassword(), config.getPath());
150150
} catch (Exception exception) {
151151
log.error("Couldn't start embedded H2 Database!", exception);
152152
}

src/main/java/de/presti/ree6/sql/util/IDatabaseServer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ public interface IDatabaseServer {
77

88
/**
99
* Create the server.
10+
*
11+
* @param port The port of the server.
12+
* @param password The password of the server.
13+
* @param path The path of the storage file.
14+
*
1015
* @throws Exception If something goes wrong.
1116
*/
12-
void createServer() throws Exception;
17+
void createServer(int port, String password, String path) throws Exception;
1318

1419
/**
1520
* Destroy the server.
21+
*
1622
* @throws Exception If something goes wrong.
1723
*/
1824
void destroyServer() throws Exception;

src/main/java/de/presti/ree6/sql/util/server/H2DatabaseServer.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.presti.ree6.sql.util.server;
22

3+
import de.presti.ree6.sql.SQLSession;
34
import de.presti.ree6.sql.util.IDatabaseServer;
45
import org.h2.tools.Server;
56

@@ -17,11 +18,18 @@ public class H2DatabaseServer implements IDatabaseServer {
1718

1819
/**
1920
* Create the server.
21+
*
2022
* @throws SQLException If something goes wrong.
2123
*/
2224
@Override
23-
public void createServer() throws SQLException {
24-
server = Server.createTcpServer().start();
25+
public void createServer(int port, String password, String path) throws SQLException {
26+
String[] args = new String[] { "-tcp", "-tcpAllowOthers", "-ifNotExists", "-tcpPort", String.valueOf(port), "-tcpPassword", password, "-baseDir", path };
27+
server = Server.createTcpServer(args).start();
28+
if (server.isRunning(true)) {
29+
System.out.println("H2-Server started successfully.");
30+
} else {
31+
System.out.println("H2-Server could not be started.");
32+
}
2533
}
2634

2735
/**

0 commit comments

Comments
 (0)