Search in sources :

Example 1 with ConnectionFactory

use of com.alessiodp.core.common.storage.sql.connection.ConnectionFactory in project ADP-Core by AlessioDP.

the class MigratorTest method testEmptyDatabase.

@Test
public void testEmptyDatabase(@TempDir Path tempDir) throws IOException {
    ConnectionFactory cf = getConnectionFactoryH2();
    Handle handle = cf.getJdbi().open();
    emptyDatabase(handle, cf.getJdbi().onDemand(SchemaHistoryH2Dao.class), prepareMigrator(cf, StorageType.H2));
    handle.close();
    cf = getConnectionFactorySQLite(tempDir);
    handle = cf.getJdbi().open();
    emptyDatabase(handle, cf.getJdbi().onDemand(SchemaHistorySQLiteDao.class), prepareMigrator(cf, StorageType.SQLITE));
    handle.close();
    cf = getConnectionFactoryMySQL();
    if (cf != null) {
        handle = cf.getJdbi().open();
        handle.createUpdate("DROP TABLE IF EXISTS `<prefix>schema_history`, `<prefix>table`;").execute();
        emptyDatabase(handle, cf.getJdbi().onDemand(SchemaHistoryMySQLDao.class), prepareMigrator(cf, StorageType.MYSQL));
        handle.close();
    }
    cf = getConnectionFactoryMariaDB();
    if (cf != null) {
        handle = cf.getJdbi().open();
        handle.createUpdate("DROP TABLE IF EXISTS `<prefix>schema_history`, `<prefix>table`;").execute();
        emptyDatabase(handle, cf.getJdbi().onDemand(SchemaHistoryMariaDBDao.class), prepareMigrator(cf, StorageType.MARIADB));
        handle.close();
    }
    cf = getConnectionFactoryPostgreSQL();
    if (cf != null) {
        handle = cf.getJdbi().open();
        handle.createUpdate("DROP TABLE IF EXISTS <prefix>schema_history, <prefix>table;").execute();
        emptyDatabase(handle, cf.getJdbi().onDemand(SchemaHistoryPostgreSQLDao.class), prepareMigrator(cf, StorageType.POSTGRESQL));
        handle.close();
    }
}
Also used : SchemaHistoryMySQLDao(com.alessiodp.core.common.storage.sql.dao.SchemaHistoryMySQLDao) MySQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory) PostgreSQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory) H2ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory) ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) MariaDBConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory) SQLiteConnectionFactory(com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory) SchemaHistoryPostgreSQLDao(com.alessiodp.core.common.storage.sql.dao.SchemaHistoryPostgreSQLDao) SchemaHistorySQLiteDao(com.alessiodp.core.common.storage.sql.dao.SchemaHistorySQLiteDao) SchemaHistoryMariaDBDao(com.alessiodp.core.common.storage.sql.dao.SchemaHistoryMariaDBDao) Handle(org.jdbi.v3.core.Handle) SchemaHistoryH2Dao(com.alessiodp.core.common.storage.sql.dao.SchemaHistoryH2Dao) Test(org.junit.jupiter.api.Test)

Example 2 with ConnectionFactory

use of com.alessiodp.core.common.storage.sql.connection.ConnectionFactory in project ADP-Core by AlessioDP.

the class StorageTest method testCreate.

@Test
public void testCreate(@TempDir Path tempDir) throws IOException {
    ConnectionFactory cf = MigratorTest.getConnectionFactoryH2();
    create(cf.getJdbi().onDemand(SchemaHistoryH2Dao.class));
    cf.stop();
    cf = MigratorTest.getConnectionFactorySQLite(tempDir);
    create(cf.getJdbi().onDemand(SchemaHistorySQLiteDao.class));
    cf.stop();
}
Also used : ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) SchemaHistorySQLiteDao(com.alessiodp.core.common.storage.sql.dao.SchemaHistorySQLiteDao) SchemaHistoryH2Dao(com.alessiodp.core.common.storage.sql.dao.SchemaHistoryH2Dao) Test(org.junit.jupiter.api.Test)

Example 3 with ConnectionFactory

use of com.alessiodp.core.common.storage.sql.connection.ConnectionFactory in project ADP-Core by AlessioDP.

the class StorageTest method testInsert.

@Test
public void testInsert(@TempDir Path tempDir) throws IOException {
    ConnectionFactory cf = MigratorTest.getConnectionFactoryH2();
    insert(cf.getJdbi().onDemand(SchemaHistoryH2Dao.class));
    cf.stop();
    cf = MigratorTest.getConnectionFactorySQLite(tempDir);
    insert(cf.getJdbi().onDemand(SchemaHistorySQLiteDao.class));
    cf.stop();
}
Also used : ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) SchemaHistorySQLiteDao(com.alessiodp.core.common.storage.sql.dao.SchemaHistorySQLiteDao) SchemaHistoryH2Dao(com.alessiodp.core.common.storage.sql.dao.SchemaHistoryH2Dao) Test(org.junit.jupiter.api.Test)

Example 4 with ConnectionFactory

use of com.alessiodp.core.common.storage.sql.connection.ConnectionFactory in project Parties by AlessioDP.

the class SQLDispatcherTest method getSQLDispatcherH2.

private PartiesSQLDispatcher getSQLDispatcherH2() {
    ConfigMain.STORAGE_SETTINGS_H2_DBFILE = "";
    PartiesSQLDispatcher ret = new PartiesSQLDispatcher(mockPlugin, StorageType.H2) {

        @Override
        public ConnectionFactory initConnectionFactory() {
            ConnectionFactory ret = super.initConnectionFactory();
            ret.setDatabaseUrl("jdbc:h2:mem:" + UUID.randomUUID() + ";DB_CLOSE_DELAY=-1");
            return ret;
        }
    };
    ret.init();
    return ret;
}
Also used : ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) PartiesSQLDispatcher(com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher)

Example 5 with ConnectionFactory

use of com.alessiodp.core.common.storage.sql.connection.ConnectionFactory in project Parties by AlessioDP.

the class SQLDispatcherTest method getSQLDispatcherSQLite.

private PartiesSQLDispatcher getSQLDispatcherSQLite(Path temporaryDirectory) {
    ConfigMain.STORAGE_SETTINGS_SQLITE_DBFILE = "";
    PartiesSQLDispatcher ret = new PartiesSQLDispatcher(mockPlugin, StorageType.SQLITE) {

        @Override
        public ConnectionFactory initConnectionFactory() {
            ConnectionFactory ret = super.initConnectionFactory();
            ret.setDatabaseUrl("jdbc:sqlite:" + temporaryDirectory.resolve("database.db"));
            return ret;
        }
    };
    ret.init();
    return ret;
}
Also used : ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) PartiesSQLDispatcher(com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher)

Aggregations

ConnectionFactory (com.alessiodp.core.common.storage.sql.connection.ConnectionFactory)7 H2ConnectionFactory (com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory)3 MariaDBConnectionFactory (com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory)3 MySQLConnectionFactory (com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory)3 PostgreSQLConnectionFactory (com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory)3 SQLiteConnectionFactory (com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory)3 SchemaHistoryH2Dao (com.alessiodp.core.common.storage.sql.dao.SchemaHistoryH2Dao)3 SchemaHistorySQLiteDao (com.alessiodp.core.common.storage.sql.dao.SchemaHistorySQLiteDao)3 Test (org.junit.jupiter.api.Test)3 PartiesSQLDispatcher (com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher)2 SQLDispatcher (com.alessiodp.core.common.storage.dispatchers.SQLDispatcher)1 SchemaHistoryMariaDBDao (com.alessiodp.core.common.storage.sql.dao.SchemaHistoryMariaDBDao)1 SchemaHistoryMySQLDao (com.alessiodp.core.common.storage.sql.dao.SchemaHistoryMySQLDao)1 SchemaHistoryPostgreSQLDao (com.alessiodp.core.common.storage.sql.dao.SchemaHistoryPostgreSQLDao)1 TreeSet (java.util.TreeSet)1 Handle (org.jdbi.v3.core.Handle)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1