本文整理汇总了Java中ch.vorburger.mariadb4j.DB.newEmbeddedDB方法的典型用法代码示例。如果您正苦于以下问题:Java DB.newEmbeddedDB方法的具体用法?Java DB.newEmbeddedDB怎么用?Java DB.newEmbeddedDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.vorburger.mariadb4j.DB
的用法示例。
在下文中一共展示了DB.newEmbeddedDB方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enableDatabaseMySQLTest
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
try {
final DB database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
final HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setConnectionTestQuery("SELECT 1");
config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
config.setMaxLifetime(60000);
config.setIdleTimeout(45000);
config.setMaximumPoolSize(50);
final HikariDataSource ds = new HikariDataSource(config);
ds.close();
database.stop();
} catch (final Exception ex) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
Assert.fail();
}
}
示例2: enableDatabaseMySQLTest
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
try {
final DB database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
final HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setConnectionTestQuery("SELECT 1");
config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
config.setMaxLifetime(60000);
config.setIdleTimeout(45000);
config.setMaximumPoolSize(50);
final HikariDataSource ds = new HikariDataSource(config);
ds.close();
database.stop();
} catch (final Exception ex) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
Assertions.fail(ex);
}
}
示例3: startMariaDB
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeAll
public static void startMariaDB() {
try {
Factory.disable();
database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
} catch (SQLException | ManagedProcessException e) {
Logger.getLogger(ParticleEffectMetaMySQLControllerIT.class.getSimpleName()).log(Level.WARNING, "Failed to start maria db.", e);
}
}
示例4: startMariaDB
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeAll
public static void startMariaDB() {
try {
Factory.disable();
database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
} catch (SQLException | ManagedProcessException e) {
Logger.getLogger(PlayerMetaMySQLControllerIT.class.getSimpleName()).log(Level.WARNING, "Failed to start mariadb.", e);
}
}
示例5: startMariaDB
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeAll
public static void startMariaDB() {
try {
Factory.disable();
database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
} catch (SQLException | ManagedProcessException e) {
Logger.getLogger(PetMetaMySQLControllerIT.class.getSimpleName()).log(Level.WARNING, "Failed start maria db.", e);
}
}
示例6: createDatabase
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
private static DB createDatabase(JsonObject config) {
config.put("user", "root");
config.remove("password");
try {
DB db = DB.newEmbeddedDB(3366);
db.start();
return db;
} catch (ManagedProcessException e) {
LOG.debug("DB startup failed", e);
throw new RuntimeException(e.getCause());
}
}
示例7: startMariaDB
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeAll
public static void startMariaDB() {
try {
Factory.disable();
database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
} catch (SQLException | ManagedProcessException e) {
Logger.getLogger(StatsMySQLControllerTest.class.getSimpleName()).log(Level.WARNING, "Failed start maria db.", e);
}
}
示例8: startMariaDB
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeAll
public static void startMariaDB() {
try {
Factory.disable();
database = DB.newEmbeddedDB(3306);
database.start();
try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
try (Statement statement = conn.createStatement()) {
statement.executeUpdate("CREATE DATABASE db");
}
}
} catch (SQLException | ManagedProcessException e) {
Logger.getLogger(PlayerMetaMySQLControllerTest.class.getSimpleName()).log(Level.WARNING, "Failed to start mariadb.", e);
}
}
示例9: createDatabase
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
private DB createDatabase() throws ManagedProcessException {
DBConfigurationBuilder configBuilder = DBConfigurationBuilder.newBuilder();
configBuilder.setPort(3306);
configBuilder.setDataDir("target/mariaDB");
configBuilder.setBaseDir("target/mariaDB");
DB database = DB.newEmbeddedDB(configBuilder.build());
database.start();
return database;
}
示例10: newEmbeddedDB
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeClass
public static void newEmbeddedDB() throws ManagedProcessException
{
dbport = random.nextInt(4100) + 3306;
dbname = getProperty("org.excalibur.database.name", "dohko");
db = DB.newEmbeddedDB(dbport);
db.start();
db.createDB(dbname);
addVMShutdownHook();
}
示例11: setUpBeforeClass
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_DATABASE = DB.newEmbeddedDB(PORT);
TEST_DATABASE.start();
TEST_DATABASE.createDB("test");
TEST_DATABASE.source("jdbc/mariadb/init.sql");
}
示例12: beforeClass
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
@BeforeClass
private static void beforeClass() throws Exception {
final DBConfigurationBuilder builder
= DBConfigurationBuilder.newBuilder();
builder.setPort(0);
DB__ = DB.newEmbeddedDB(builder.build());
DB__.start();
logger.debug("embedded mariadb started");
URL = builder.getURL("test");
logger.debug("url: {}", URL);
}
示例13: startup
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
public void startup() throws SQLException {
try {
if (db != null)
db.stop();
boolean firstTime = false;
File baseDir = new File(config.getBaseDir());
if (!baseDir.exists() || baseDir.listFiles().length == 0) {
firstTime = true;
if (!baseDir.exists() && !baseDir.mkdirs())
throw new IOException("Cannot create db base dir: " + baseDir);
ZipHelper.unzip(dbJar, baseDir, binariesSubLoc, null, false);
if (!config.isWindows()) {
Util.forceExecutable(new File(baseDir, "bin/my_print_defaults"));
Util.forceExecutable(new File(baseDir, "bin/mysql_install_db"));
Util.forceExecutable(new File(baseDir, "bin/mysqld"));
Util.forceExecutable(new File(baseDir, "bin/mysql"));
}
}
if (!firstTime) {
File dataDir = new File(config.getDataDir());
if (!dataDir.exists() || dataDir.listFiles().length == 0)
firstTime = true;
}
db = DB.newEmbeddedDB(config);
db.start();
if (firstTime) {
String rootPass = "mdwchangeme"; // can only connect from localhost, so hardwired is okay
db.run("CREATE DATABASE IF NOT EXISTS `" + dbName + "`;", "root", null, null);
// set a password on the root account
db.run("SET PASSWORD FOR 'root'@'localhost' = PASSWORD('" + rootPass + "');", "root", null, null);
// create the app user account and grant permissions
db.run("GRANT ALL ON " + dbName + ".* to '" + user + "'@'%' IDENTIFIED BY '" + password + "'", "root", rootPass, null);
db.run("GRANT ALL ON " + dbName + ".* to '" + user + "'@'localhost' IDENTIFIED BY '" + password + "'", "root", rootPass, null);
// db.createDB(dbName);
}
}
catch (Exception ex) {
throw new SQLException("MariaDB4j startup error: " + ex, ex);
}
}
示例14: Environment
import ch.vorburger.mariadb4j.DB; //导入方法依赖的package包/类
/**
* Make constructor private in order to control the number of instances (there should be only one).
* If the environ cannot be set up, a non-checked exception will be thrown.
*/
private Environment() {
try {
// Initialize Tomcat and Temporary folder
tomcat = new Tomcat();
baseDir = new TemporaryFolder();
// Initialize DB
int port = getFreePort();
embeddedDB = DB.newEmbeddedDB(port);
// Initialize baseDir and the webapps directory
baseDir.create();
File webApps = baseDir.newFolder("webapps");
// Set up Tomcat
tomcat.setPort(0); // Automatic port
tomcat.setBaseDir(baseDir.getRoot().getAbsolutePath()); // Base Dir
tomcat.addContext("/", webApps.getAbsolutePath()); // Context
// Create properties
Properties properties = new Properties();
properties.setProperty("jdbc.driverClassName", "com.mysql.jdbc.Driver");
properties.setProperty("jdbc.url", String.format("jdbc:mysql://localhost:%d/%s", port, DATABASE));
properties.setProperty("jdbc.username", "root");
properties.setProperty("jdbc.password", "");
File propertiesFile = baseDir.newFile("properties.properties");
propertiesFile.createNewFile();
properties.store(new FileOutputStream(propertiesFile), "");
// Copy the WAR (the original one cannot be modified)
String projectDirectory = Paths.get(".").toAbsolutePath().toString();
String modifiedWarPath = projectDirectory + "/target/" + MODIFIED_WAR_NAME;
Path originalWar = Paths.get(projectDirectory + "/target/WMarket.war");
Path modifiedWar = Paths.get(modifiedWarPath);
Files.copy(originalWar, modifiedWar, StandardCopyOption.REPLACE_EXISTING);
// Modify properties using the file created previously
FileSystem fs = FileSystems.newFileSystem(modifiedWar, null);
Path fileInsideZipPath = fs.getPath("WEB-INF/classes/properties/database.properties");
// Copy properties into the WAR
Files.copy(propertiesFile.toPath(), fileInsideZipPath, StandardCopyOption.REPLACE_EXISTING);
fs.close();
// Add modified WAR
tomcat.addWebapp("WMarket", modifiedWarPath);
} catch (Exception ex) {
// This will prevent test from starting...
throw new RuntimeException(ex);
}
}