Search in sources :

Example 1 with JdbcConnectionSource

use of com.j256.ormlite.jdbc.JdbcConnectionSource in project entando-core by entando.

the class TableFactory method createConnectionSource.

private ConnectionSource createConnectionSource() throws ApsSystemException {
    ConnectionSource connectionSource = null;
    try {
        DataSource dataSource = this.getDataSource();
        IDatabaseManager.DatabaseType type = this.getType();
        String url = this.invokeGetMethod("getUrl", dataSource);
        String username = this.invokeGetMethod("getUsername", dataSource);
        String password = this.invokeGetMethod("getPassword", dataSource);
        com.j256.ormlite.db.DatabaseType dataType = null;
        if (type.equals(IDatabaseManager.DatabaseType.DERBY)) {
            dataType = new ApsDerbyEmbeddedDatabaseType();
            url = url + ";user=" + username + ";password=" + password;
            connectionSource = new JdbcConnectionSource(url, dataType);
        } else {
            if (type.equals(IDatabaseManager.DatabaseType.POSTGRESQL)) {
                dataType = new PostgresDatabaseType();
            } else if (type.equals(IDatabaseManager.DatabaseType.MYSQL)) {
                dataType = new MysqlDatabaseType();
            } else if (type.equals(IDatabaseManager.DatabaseType.ORACLE)) {
                dataType = new ApsOracleDatabaseType();
            } else if (type.equals(IDatabaseManager.DatabaseType.SQLSERVER)) {
                dataType = new SqlServerDatabaseType();
            }
            connectionSource = new JdbcConnectionSource(url, username, password, dataType);
        }
    } catch (Throwable t) {
        _logger.error("Error creating connectionSource to db {}", this.getDatabaseName(), t);
        throw new ApsSystemException("Error creating connectionSource to db " + this.getDatabaseName(), t);
    }
    return connectionSource;
}
Also used : IDatabaseManager(org.entando.entando.aps.system.init.IDatabaseManager) PostgresDatabaseType(com.j256.ormlite.db.PostgresDatabaseType) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSource(javax.sql.DataSource) MysqlDatabaseType(com.j256.ormlite.db.MysqlDatabaseType) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource) ConnectionSource(com.j256.ormlite.support.ConnectionSource) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource) SqlServerDatabaseType(com.j256.ormlite.db.SqlServerDatabaseType)

Example 2 with JdbcConnectionSource

use of com.j256.ormlite.jdbc.JdbcConnectionSource in project BachelorPraktikum by lucasbuschlinger.

the class VaultDAO method initDb.

/**
 * Initializes the actual database as a {@link JdbcConnectionSource}.
 *
 * @throws SQLException Thrown if the database can not be successfully initialized.
 */
private void initDb() throws SQLException {
    // create a connection source to our database
    connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "", new HsqldbDatabaseType());
    // instantiate the DAO
    vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
    if (!vaultDao.isTableExists()) {
        TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
    } else {
        LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
    }
// TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
}
Also used : VaultEntry(de.opendiabetes.vault.container.VaultEntry) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource) HsqldbDatabaseType(com.j256.ormlite.db.HsqldbDatabaseType)

Example 3 with JdbcConnectionSource

use of com.j256.ormlite.jdbc.JdbcConnectionSource in project nutch by apache.

the class SpringConfiguration method getConnectionSource.

@Bean
public JdbcConnectionSource getConnectionSource() throws SQLException {
    JdbcConnectionSource source = new JdbcConnectionSource("jdbc:h2:~/.nutch/config", new H2DatabaseType());
    source.initialize();
    return source;
}
Also used : H2DatabaseType(com.j256.ormlite.db.H2DatabaseType) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource) Bean(org.springframework.context.annotation.Bean)

Example 4 with JdbcConnectionSource

use of com.j256.ormlite.jdbc.JdbcConnectionSource in project IridiumSkyblock by Iridium-Development.

the class DatabaseManager method init.

public void init() throws SQLException {
    LoggerFactory.setLogBackendFactory(new NullLogBackend.NullLogBackendFactory());
    SQL sqlConfig = IridiumSkyblock.getInstance().getSql();
    String databaseURL = getDatabaseURL(sqlConfig);
    DataPersisterManager.registerDataPersisters(XMaterialType.getSingleton());
    if (!IridiumSkyblock.getInstance().isTesting()) {
        this.connectionSource = new JdbcConnectionSource(databaseURL, sqlConfig.username, sqlConfig.password, DatabaseTypeUtils.createDatabaseType(databaseURL));
        if (connectionSource.getReadWriteConnection(null).isTableExists("islands")) {
            convertDatabaseData(sqlConfig.driver);
        }
    }
    this.islandTableManager = new IslandTableManager(connectionSource);
    this.userTableManager = new UserTableManager(connectionSource);
    this.islandInviteTableManager = new ForeignIslandTableManager<>(connectionSource, IslandInvite.class, Comparator.comparing(IslandInvite::getIslandId).thenComparing(islandInvite -> islandInvite.getUser().getUuid()));
    this.islandPermissionTableManager = new ForeignIslandTableManager<>(connectionSource, IslandPermission.class, Comparator.comparing(IslandPermission::getIslandId).thenComparing(IslandPermission::getRank).thenComparing(IslandPermission::getPermission));
    this.islandBlocksTableManager = new ForeignIslandTableManager<>(connectionSource, IslandBlocks.class, Comparator.comparing(IslandBlocks::getIslandId).thenComparing(IslandBlocks::getMaterial));
    this.islandSpawnersTableManager = new ForeignIslandTableManager<>(connectionSource, IslandSpawners.class, Comparator.comparing(IslandSpawners::getIslandId).thenComparing(IslandSpawners::getSpawnerType));
    this.islandBankTableManager = new ForeignIslandTableManager<>(connectionSource, IslandBank.class, Comparator.comparing(IslandBank::getIslandId).thenComparing(IslandBank::getBankItem));
    this.islandMissionTableManager = new ForeignIslandTableManager<>(connectionSource, IslandMission.class, Comparator.comparing(IslandMission::getIslandId).thenComparing(IslandMission::getMissionName).thenComparing(IslandMission::getMissionIndex));
    this.islandRewardTableManager = new ForeignIslandTableManager<>(connectionSource, IslandReward.class, Comparator.comparing(IslandReward::getIslandId));
    this.islandUpgradeTableManager = new ForeignIslandTableManager<>(connectionSource, IslandUpgrade.class, Comparator.comparing(IslandUpgrade::getIslandId).thenComparing(IslandUpgrade::getUpgrade));
    this.islandTrustedTableManager = new ForeignIslandTableManager<>(connectionSource, IslandTrusted.class, Comparator.comparing(IslandTrusted::getIslandId).thenComparing(islandTrusted -> islandTrusted.getUser().getUuid()));
    this.islandBoosterTableManager = new ForeignIslandTableManager<>(connectionSource, IslandBooster.class, Comparator.comparing(IslandBooster::getIslandId).thenComparing(IslandBooster::getBooster));
    this.islandWarpTableManager = new ForeignIslandTableManager<>(connectionSource, IslandWarp.class, Comparator.comparing(IslandWarp::getIslandId));
    this.islandLogTableManager = new ForeignIslandTableManager<>(connectionSource, IslandLog.class, Comparator.comparing(IslandLog::getIslandId));
    this.islandBanTableManager = new ForeignIslandTableManager<>(connectionSource, IslandBan.class, Comparator.comparing(IslandBan::getIslandId).thenComparing(islandBan -> islandBan.getBannedUser().getUuid()));
    this.islandSettingTableManager = new ForeignIslandTableManager<>(connectionSource, IslandSetting.class, Comparator.comparing(IslandSetting::getIslandId).thenComparing(IslandSetting::getSetting));
}
Also used : ForeignIslandTableManager(com.iridium.iridiumskyblock.managers.tablemanagers.ForeignIslandTableManager) IslandTableManager(com.iridium.iridiumskyblock.managers.tablemanagers.IslandTableManager) NullLogBackend(com.j256.ormlite.logger.NullLogBackend) SQL(com.iridium.iridiumskyblock.configs.SQL) UserTableManager(com.iridium.iridiumskyblock.managers.tablemanagers.UserTableManager) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource)

Example 5 with JdbcConnectionSource

use of com.j256.ormlite.jdbc.JdbcConnectionSource in project entando-engine by entando.

the class TableFactory method createConnectionSource.

private ConnectionSource createConnectionSource() throws EntException {
    ConnectionSource connectionSource = null;
    try {
        DataSource dataSource = this.getDataSource();
        IDatabaseManager.DatabaseType type = this.getType();
        String url = this.invokeGetMethod("getUrl", dataSource);
        String username = this.invokeGetMethod("getUsername", dataSource);
        String password = this.invokeGetMethod("getPassword", dataSource);
        com.j256.ormlite.db.DatabaseType dataType = null;
        if (type.equals(IDatabaseManager.DatabaseType.DERBY)) {
            dataType = new ApsDerbyEmbeddedDatabaseType();
            url = url + ";user=" + username + ";password=" + password;
            connectionSource = new JdbcConnectionSource(url, dataType);
        } else {
            if (type.equals(IDatabaseManager.DatabaseType.POSTGRESQL)) {
                dataType = new PostgresDatabaseType();
            } else if (type.equals(IDatabaseManager.DatabaseType.MYSQL)) {
                dataType = new MysqlDatabaseType();
            } else if (type.equals(IDatabaseManager.DatabaseType.ORACLE)) {
                dataType = new ApsOracleDatabaseType();
            } else if (type.equals(IDatabaseManager.DatabaseType.SQLSERVER)) {
                dataType = new SqlServerDatabaseType();
            }
            connectionSource = new JdbcConnectionSource(url, username, password, dataType);
        }
    } catch (Throwable t) {
        _logger.error("Error creating connectionSource to db {}", this.getDatabaseName(), t);
        throw new EntException("Error creating connectionSource to db " + this.getDatabaseName(), t);
    }
    return connectionSource;
}
Also used : IDatabaseManager(org.entando.entando.aps.system.init.IDatabaseManager) PostgresDatabaseType(com.j256.ormlite.db.PostgresDatabaseType) EntException(org.entando.entando.ent.exception.EntException) DataSource(javax.sql.DataSource) MysqlDatabaseType(com.j256.ormlite.db.MysqlDatabaseType) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource) ConnectionSource(com.j256.ormlite.support.ConnectionSource) JdbcConnectionSource(com.j256.ormlite.jdbc.JdbcConnectionSource) SqlServerDatabaseType(com.j256.ormlite.db.SqlServerDatabaseType)

Aggregations

JdbcConnectionSource (com.j256.ormlite.jdbc.JdbcConnectionSource)5 MysqlDatabaseType (com.j256.ormlite.db.MysqlDatabaseType)2 PostgresDatabaseType (com.j256.ormlite.db.PostgresDatabaseType)2 SqlServerDatabaseType (com.j256.ormlite.db.SqlServerDatabaseType)2 ConnectionSource (com.j256.ormlite.support.ConnectionSource)2 DataSource (javax.sql.DataSource)2 IDatabaseManager (org.entando.entando.aps.system.init.IDatabaseManager)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 SQL (com.iridium.iridiumskyblock.configs.SQL)1 ForeignIslandTableManager (com.iridium.iridiumskyblock.managers.tablemanagers.ForeignIslandTableManager)1 IslandTableManager (com.iridium.iridiumskyblock.managers.tablemanagers.IslandTableManager)1 UserTableManager (com.iridium.iridiumskyblock.managers.tablemanagers.UserTableManager)1 H2DatabaseType (com.j256.ormlite.db.H2DatabaseType)1 HsqldbDatabaseType (com.j256.ormlite.db.HsqldbDatabaseType)1 NullLogBackend (com.j256.ormlite.logger.NullLogBackend)1 VaultEntry (de.opendiabetes.vault.container.VaultEntry)1 EntException (org.entando.entando.ent.exception.EntException)1 Bean (org.springframework.context.annotation.Bean)1