代码拉取完成,页面将自动刷新
同步操作将从 dromara/disjob 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/* __________ _____ *\
** \______ \____ _____/ ____\____ ____ Copyright (c) 2017-2023 Ponfee **
** | ___/ _ \ / \ __\/ __ \_/ __ \ http://www.ponfee.cn **
** | | ( <_> ) | \ | \ ___/\ ___/ Apache License Version 2.0 **
** |____| \____/|___| /__| \___ >\___ > http://www.apache.org/licenses/ **
** \/ \/ \/ **
\* */
package cn.ponfee.disjob.test.db;
import ch.vorburger.mariadb4j.DB;
import ch.vorburger.mariadb4j.DBConfiguration;
import ch.vorburger.mariadb4j.DBConfigurationBuilder;
import cn.ponfee.disjob.common.exception.Throwables.ThrowingRunnable;
import cn.ponfee.disjob.common.util.Files;
import cn.ponfee.disjob.common.util.MavenProjects;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.file.PathUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.stream.Collectors;
import static cn.ponfee.disjob.test.db.DBUtils.*;
/**
* <pre>
* MariaDB Server
* SELECT VERSION() -> 10.2.11-MariaDB
* MacOS如果启动失败报"未找到openssl"错误,参考安装步骤:“/disjob-test/src/main/DB/MariaDB/MariaDB.md”
*
* username: root
* password: 无需密码
*
*
* mysql:
* Maven GAV -> com.mysql:mysql-connector-j:8.0.33
* jdbc-url -> jdbc:mysql://localhost:3306/disjob
* driver-class -> com.mysql.cj.jdbc.Driver
*
* MariaDB:
* Maven GAV -> org.mariadb.jdbc:mariadb-java-client:3.1.4
* jdbc-url -> jdbc:mariadb://localhost:3306/disjob
* driver-class -> org.mariadb.jdbc.Driver
* </pre>
*
* @author Ponfee
*/
public class EmbeddedMysqlServerMariaDB {
public static void main(String[] args) throws Exception {
DB db = start(3306);
Runtime.getRuntime().addShutdownHook(new Thread(ThrowingRunnable.toCaught(db::stop)));
}
public static DB start(int port) throws Exception {
DBConfiguration configuration = DBConfigurationBuilder.newBuilder()
.setPort(port) // OR, default: setPort(0); => autom. detect free port
.setBaseDir(createDirectory("base"))
.setDataDir(createDirectory("data"))
.addArg("--user=root")
.addArg("--character-set-server=utf8mb4")
.addArg("--collation-server=utf8mb4_bin")
//.addArg("--default-character-set=utf8mb4")
//.addArg("--skip-grant-tables") // 默认就是skip-grant-tables
.build();
DB db = DB.newEmbeddedDB(configuration);
System.out.println("Embedded maria db starting...");
db.start();
System.out.println("Embedded maria db started!");
db.source(IOUtils.toInputStream(loadScript(DISJOB_ADMIN_SCRIPT_CLASSPATH), StandardCharsets.UTF_8));
db.source(IOUtils.toInputStream(loadScript(DISJOB_SCRIPT_CLASSPATH), StandardCharsets.UTF_8));
String jdbcUrl = "jdbc:mysql://localhost:" + port + "/" + DB_NAME;
JdbcTemplate jdbcTemplate = DBUtils.createJdbcTemplate(jdbcUrl, USERNAME, PASSWORD);
System.out.println("\n--------------------------------------------------------testDatabase");
DBUtils.testNativeConnection("com.mysql.cj.jdbc.Driver", jdbcUrl, USERNAME, PASSWORD);
System.out.println("\n--------------------------------------------------------testMysql");
DBUtils.testMysqlVersion(jdbcTemplate);
System.out.println("\n--------------------------------------------------------testJdbcTemplate");
DBUtils.testJdbcTemplate(jdbcTemplate);
System.out.println("\n--------------------------------------------------------testQuerySql");
DBUtils.testQuerySchedJob(jdbcTemplate);
return db;
}
private static String loadScript(String scriptPath) throws Exception {
return Arrays.stream(DBUtils.loadScript(scriptPath).split("\n"))
// fix error: The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
.filter(s -> !StringUtils.startsWithAny(s, "DROP USER ", "CREATE USER ", "GRANT ALL PRIVILEGES ON ", "FLUSH PRIVILEGES;"))
.collect(Collectors.joining("\n"));
}
private static String createDirectory(String name) throws IOException {
String dataDir = MavenProjects.getProjectBaseDir() + "/target/mariadb/" + name + "/";
File file = new File(dataDir);
if (file.exists()) {
PathUtils.deleteDirectory(file.toPath());
}
Files.mkdir(file);
return dataDir;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。