Search in sources :

Example 1 with PostgresDatabaseType

use of com.j256.ormlite.db.PostgresDatabaseType 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 PostgresDatabaseType

use of com.j256.ormlite.db.PostgresDatabaseType 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

MysqlDatabaseType (com.j256.ormlite.db.MysqlDatabaseType)2 PostgresDatabaseType (com.j256.ormlite.db.PostgresDatabaseType)2 SqlServerDatabaseType (com.j256.ormlite.db.SqlServerDatabaseType)2 JdbcConnectionSource (com.j256.ormlite.jdbc.JdbcConnectionSource)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 EntException (org.entando.entando.ent.exception.EntException)1