Search in sources :

Example 6 with ConnectionFactory

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

the class PartiesSQLDispatcher method initConnectionFactory.

@Override
public ConnectionFactory initConnectionFactory() {
    ConnectionFactory ret = null;
    switch(storageType) {
        case MARIADB:
            ret = new MariaDBConnectionFactory();
            ((MariaDBConnectionFactory) ret).setTablePrefix(ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX);
            ((MariaDBConnectionFactory) ret).setCharset(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_CHARSET);
            ((MariaDBConnectionFactory) ret).setServerName(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_ADDRESS);
            ((MariaDBConnectionFactory) ret).setPort(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_PORT);
            ((MariaDBConnectionFactory) ret).setDatabaseName(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_DATABASE);
            ((MariaDBConnectionFactory) ret).setUsername(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_USERNAME);
            ((MariaDBConnectionFactory) ret).setPassword(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_PASSWORD);
            ((MariaDBConnectionFactory) ret).setMaximumPoolSize(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_POOLSIZE);
            ((MariaDBConnectionFactory) ret).setMaxLifetime(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_CONNLIFETIME);
            ((MariaDBConnectionFactory) ret).setAdditionalParameters(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_ADDITIONAL_PARAMETERS);
            break;
        case MYSQL:
            ret = new MySQLConnectionFactory();
            ((MySQLConnectionFactory) ret).setTablePrefix(ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX);
            ((MySQLConnectionFactory) ret).setCharset(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_CHARSET);
            ((MySQLConnectionFactory) ret).setServerName(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_ADDRESS);
            ((MySQLConnectionFactory) ret).setPort(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_PORT);
            ((MySQLConnectionFactory) ret).setDatabaseName(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_DATABASE);
            ((MySQLConnectionFactory) ret).setUsername(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_USERNAME);
            ((MySQLConnectionFactory) ret).setPassword(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_PASSWORD);
            ((MySQLConnectionFactory) ret).setMaximumPoolSize(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_POOLSIZE);
            ((MySQLConnectionFactory) ret).setMaxLifetime(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_CONNLIFETIME);
            ((MySQLConnectionFactory) ret).setUseSSL(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_USESSL);
            ((MySQLConnectionFactory) ret).setAdditionalParameters(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_ADDITIONAL_PARAMETERS);
            break;
        case POSTGRESQL:
            ret = new PostgreSQLConnectionFactory();
            ((PostgreSQLConnectionFactory) ret).setTablePrefix(ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX);
            ((PostgreSQLConnectionFactory) ret).setCharset(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_CHARSET);
            ((PostgreSQLConnectionFactory) ret).setServerName(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_ADDRESS);
            ((PostgreSQLConnectionFactory) ret).setPort(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_PORT);
            ((PostgreSQLConnectionFactory) ret).setDatabaseName(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_DATABASE);
            ((PostgreSQLConnectionFactory) ret).setUsername(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_USERNAME);
            ((PostgreSQLConnectionFactory) ret).setPassword(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_PASSWORD);
            ((PostgreSQLConnectionFactory) ret).setMaximumPoolSize(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_POOLSIZE);
            ((PostgreSQLConnectionFactory) ret).setMaxLifetime(ConfigMain.STORAGE_SETTINGS_REMOTE_SQL_CONNLIFETIME);
            playersDao = PostgreSQLPlayersDao.class;
            partiesDao = PostgreSQLPartiesDao.class;
            break;
        case SQLITE:
            ret = new SQLiteConnectionFactory(plugin, plugin.getFolder().resolve(ConfigMain.STORAGE_SETTINGS_SQLITE_DBFILE));
            ((SQLiteConnectionFactory) ret).setTablePrefix(ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX);
            playersDao = SQLitePlayersDao.class;
            partiesDao = SQLitePartiesDao.class;
            break;
        case H2:
            ret = new H2ConnectionFactory(plugin, plugin.getFolder().resolve(ConfigMain.STORAGE_SETTINGS_H2_DBFILE));
            ((H2ConnectionFactory) ret).setTablePrefix(ConfigMain.STORAGE_SETTINGS_GENERAL_SQL_PREFIX);
            playersDao = H2PlayersDao.class;
            partiesDao = H2PartiesDao.class;
            break;
        default:
    }
    return ret;
}
Also used : 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) MariaDBConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory) PostgreSQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory) H2ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory) MySQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory) SQLiteConnectionFactory(com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory)

Example 7 with ConnectionFactory

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

the class MigratorTest method prepareMigrator.

private Migrator prepareMigrator(ConnectionFactory cf, StorageType storageType) {
    if (cf == null)
        return null;
    TreeSet<String> scripts = new TreeSet<>();
    switch(storageType) {
        case MARIADB:
        case MYSQL:
        case POSTGRESQL:
        case SQLITE:
        case H2:
            scripts.add("1__Test_queries.sql");
            scripts.add("2__Second_test.sql");
            break;
        default:
            return null;
    }
    return Migrator.configure().setLocation("db/migrations/" + CommonUtils.toLowerCase(storageType.name()) + "/").setScripts(scripts).setConnectionFactory(cf).setStorageType(storageType).load(mockPlugin, new SQLDispatcher(mockPlugin, storageType) {

        @Override
        protected ConnectionFactory initConnectionFactory() {
            return null;
        }
    });
}
Also used : 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) SQLDispatcher(com.alessiodp.core.common.storage.dispatchers.SQLDispatcher) TreeSet(java.util.TreeSet) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

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