kezhenxu94 commented on a change in pull request #6500:
URL: https://github.com/apache/dolphinscheduler/pull/6500#discussion_r744257866
##########
File path:
dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/server/StandaloneServer.java
##########
@@ -88,25 +76,9 @@ private static void startRegistry() throws Exception {
System.setProperty("registry.servers", server.getConnectString());
}
- private static void startDatabase() throws IOException, SQLException {
- final Path temp = Files.createTempDirectory("dolphinscheduler_");
- LOGGER.info("H2 database directory: {}", temp);
- System.setProperty(
- SPRING_DATASOURCE_DRIVER_CLASS_NAME,
- org.h2.Driver.class.getName()
- );
- System.setProperty(
- SPRING_DATASOURCE_URL,
-
String.format("jdbc:h2:tcp://localhost/%s;MODE=MySQL;DATABASE_TO_LOWER=true",
temp.toAbsolutePath())
- );
- System.setProperty(SPRING_DATASOURCE_USERNAME, "sa");
- System.setProperty(SPRING_DATASOURCE_PASSWORD, "");
-
- Server.createTcpServer("-ifNotExists", "-tcpDaemon").start();
-
- final DataSource ds = ConnectionFactory.getInstance().getDataSource();
- final ScriptRunner runner = new ScriptRunner(ds.getConnection(), true,
true);
- runner.runScript(new FileReader("sql/dolphinscheduler_h2.sql"));
+ private static void startDatabase() {
+ System.setProperty("spring.datasource.sql.schema",
"file:./sql/dolphinscheduler_h2.sql");
+ ConnectionFactory.getInstance().getDataSource();
Review comment:
This seems to be redundant as the result is ignored and this statement
has no side effect, right?
##########
File path:
dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/server/StandaloneServer.java
##########
@@ -88,25 +76,9 @@ private static void startRegistry() throws Exception {
System.setProperty("registry.servers", server.getConnectString());
}
- private static void startDatabase() throws IOException, SQLException {
- final Path temp = Files.createTempDirectory("dolphinscheduler_");
- LOGGER.info("H2 database directory: {}", temp);
- System.setProperty(
- SPRING_DATASOURCE_DRIVER_CLASS_NAME,
- org.h2.Driver.class.getName()
- );
- System.setProperty(
- SPRING_DATASOURCE_URL,
-
String.format("jdbc:h2:tcp://localhost/%s;MODE=MySQL;DATABASE_TO_LOWER=true",
temp.toAbsolutePath())
- );
- System.setProperty(SPRING_DATASOURCE_USERNAME, "sa");
- System.setProperty(SPRING_DATASOURCE_PASSWORD, "");
-
- Server.createTcpServer("-ifNotExists", "-tcpDaemon").start();
-
- final DataSource ds = ConnectionFactory.getInstance().getDataSource();
- final ScriptRunner runner = new ScriptRunner(ds.getConnection(), true,
true);
- runner.runScript(new FileReader("sql/dolphinscheduler_h2.sql"));
+ private static void startDatabase() {
+ System.setProperty("spring.datasource.sql.schema",
"file:./sql/dolphinscheduler_h2.sql");
+ ConnectionFactory.getInstance().getDataSource();
Review comment:
`private static final Logger LOGGER =
LoggerFactory.getLogger(StandaloneServer.class);` is also unused now
##########
File path:
dolphinscheduler-standalone-server/src/main/java/org/apache/dolphinscheduler/server/StandaloneServer.java
##########
@@ -88,25 +76,9 @@ private static void startRegistry() throws Exception {
System.setProperty("registry.servers", server.getConnectString());
}
- private static void startDatabase() throws IOException, SQLException {
- final Path temp = Files.createTempDirectory("dolphinscheduler_");
- LOGGER.info("H2 database directory: {}", temp);
- System.setProperty(
- SPRING_DATASOURCE_DRIVER_CLASS_NAME,
- org.h2.Driver.class.getName()
- );
- System.setProperty(
- SPRING_DATASOURCE_URL,
-
String.format("jdbc:h2:tcp://localhost/%s;MODE=MySQL;DATABASE_TO_LOWER=true",
temp.toAbsolutePath())
- );
- System.setProperty(SPRING_DATASOURCE_USERNAME, "sa");
- System.setProperty(SPRING_DATASOURCE_PASSWORD, "");
-
- Server.createTcpServer("-ifNotExists", "-tcpDaemon").start();
-
- final DataSource ds = ConnectionFactory.getInstance().getDataSource();
- final ScriptRunner runner = new ScriptRunner(ds.getConnection(), true,
true);
- runner.runScript(new FileReader("sql/dolphinscheduler_h2.sql"));
+ private static void startDatabase() {
+ System.setProperty("spring.datasource.sql.schema",
"file:./sql/dolphinscheduler_h2.sql");
Review comment:
What about moving this line to the next line of
`System.setProperty("spring.profiles.active", "api,h2");` and remove
`startDatabase` method as we don't need to manually start the database now?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]