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;
}
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);
}
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;
}
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));
}
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;
}
Aggregations