当前位置: 首页>>代码示例>>Java>>正文


Java DB.newEmbeddedDB方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:26,代码来源:DatabaseIT.java

示例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);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:27,代码来源:DatabaseTest.java

示例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);
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:16,代码来源:ParticleEffectMetaMySQLControllerIT.java

示例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);
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:16,代码来源:PlayerMetaMySQLControllerIT.java

示例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);
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:16,代码来源:PetMetaMySQLControllerIT.java

示例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());
    }
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:13,代码来源:LocalDatabase.java

示例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);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:16,代码来源:StatsMySQLControllerTest.java

示例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);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:16,代码来源:PlayerMetaMySQLControllerTest.java

示例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;
    }
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:12,代码来源:App.java

示例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();
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:12,代码来源:TestSupport.java

示例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");
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:8,代码来源:MariaDB_IT_Base.java

示例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);
}
 
开发者ID:jinahya,项目名称:database-metadata-bind,代码行数:12,代码来源:EmbeddedMariadbTest.java

示例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);
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:44,代码来源:MariaDBEmbeddedDb.java

示例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);
	}

}
 
开发者ID:conwetlab,项目名称:WMarket,代码行数:58,代码来源:Environment.java


注:本文中的ch.vorburger.mariadb4j.DB.newEmbeddedDB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。