use of com.axway.ats.log.autodb.io.SQLServerDbReadAccess in project ats-framework by Axway.
the class ActiveDbAppender method obtainDbReadAccessObject.
/**
* Get {@link IDbReadAccess} using the appender's db configuration
* @throws DatabaseAccessException In case of DB error
*/
public IDbReadAccess obtainDbReadAccessObject() throws DatabaseAccessException {
DbConnection dbConnection = null;
if (dbReadAccess == null) {
Exception mssqlException = DbUtils.isMSSQLDatabaseAvailable(appenderConfig.getHost(), Integer.parseInt(appenderConfig.getPort()), appenderConfig.getDatabase(), appenderConfig.getUser(), appenderConfig.getPassword());
if (mssqlException == null) {
Map<String, Object> props = new HashMap<>();
props.put(DbKeys.DRIVER, appenderConfig.getDriver().toUpperCase());
dbConnection = new DbConnSQLServer(appenderConfig.getHost(), Integer.parseInt(appenderConfig.getPort()), appenderConfig.getDatabase(), appenderConfig.getUser(), appenderConfig.getPassword(), props);
// create the db access layer
dbReadAccess = new SQLServerDbReadAccess((DbConnSQLServer) dbConnection);
} else {
Exception pgsqlException = DbUtils.isPostgreSQLDatabaseAvailable(appenderConfig.getHost(), Integer.parseInt(appenderConfig.getPort()), appenderConfig.getDatabase(), appenderConfig.getUser(), appenderConfig.getPassword());
if (pgsqlException == null) {
dbConnection = new DbConnPostgreSQL(appenderConfig.getHost(), Integer.parseInt(appenderConfig.getPort()), appenderConfig.getDatabase(), appenderConfig.getUser(), appenderConfig.getPassword(), null);
// create the db access layer
dbReadAccess = new PGDbReadAccess((DbConnPostgreSQL) dbConnection);
} else {
String errMsg = "Neither MSSQL, nor PostgreSQL server at '" + appenderConfig.getHost() + ":" + appenderConfig.getPort() + "' has database with name '" + appenderConfig.getDatabase() + "'. Exception for MSSQL is : \n\t" + mssqlException + "\n\nException for PostgreSQL is: \n\t" + pgsqlException;
throw new DatabaseAccessException(errMsg);
}
}
}
return dbReadAccess;
}
Aggregations