Search in sources :

Example 1 with MysqlDbProvider

use of com.axway.ats.core.dbaccess.mysql.MysqlDbProvider in project ats-framework by Axway.

the class DatabaseProviderFactory method getDatabaseProvider.

/**
	 * Creates a database provider suitable for the given input arguments
	 * 
	 * @param dbType
	 * @param dbHost
	 * @param dbName
	 * @param dbUser
	 * @param dbPass
	 * @param dbPort
	 * @param customProperties
	 * @return
	 */
public static synchronized DbProvider getDatabaseProvider(String dbType, String dbHost, String dbName, String dbUser, String dbPass, int dbPort, Map<String, Object> customProperties) {
    DbProvider dbProvider;
    if (dbType == null) {
        throw new IllegalArgumentException("Database type is not provided");
    }
    if (dbName == null) {
        if ("MSSQL".equals(dbType)) {
            log.warn("Database name is empty! The connection will be made to the admin database!");
        } else {
            throw new IllegalArgumentException("Database name is not provided");
        }
    }
    // eventual custom property value
    if (dbPort > 0) {
        if (customProperties == null) {
            customProperties = new HashMap<String, Object>();
        }
        customProperties.put(DbKeys.PORT_KEY, dbPort);
    }
    // load a custom data provider
    if (dbProviders.containsKey(dbType)) {
        String[] classNames = dbProviders.get(dbType);
        DbConnection dbConnection = loadDbConnection(classNames[0], dbType, dbHost, dbName, dbUser, dbPass, dbPort, customProperties);
        return loadCustomDbProvider(classNames[1], dbConnection);
    }
    // load a common ATS supported data provider
    switch(dbType) {
        case DbConnSQLServer.DATABASE_TYPE:
            dbProvider = new MssqlDbProvider((DbConnSQLServer) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnMySQL.DATABASE_TYPE:
            dbProvider = new MysqlDbProvider((DbConnMySQL) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnOracle.DATABASE_TYPE:
            dbProvider = new OracleDbProvider((DbConnOracle) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnCassandra.DATABASE_TYPE:
            dbProvider = new CassandraDbProvider((DbConnCassandra) createDbConnection(dbType, dbHost, dbName, dbUser, dbPass, customProperties));
            break;
        default:
            {
                // should never happen
                throw new IllegalArgumentException("Database type " + dbType + " not supported");
            }
    }
    return dbProvider;
}
Also used : OracleDbProvider(com.axway.ats.core.dbaccess.oracle.OracleDbProvider) MssqlDbProvider(com.axway.ats.core.dbaccess.mssql.MssqlDbProvider) DbConnSQLServer(com.axway.ats.core.dbaccess.mssql.DbConnSQLServer) MysqlDbProvider(com.axway.ats.core.dbaccess.mysql.MysqlDbProvider) DbConnMySQL(com.axway.ats.core.dbaccess.mysql.DbConnMySQL) DbConnOracle(com.axway.ats.core.dbaccess.oracle.DbConnOracle) CassandraDbProvider(com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider) OracleDbProvider(com.axway.ats.core.dbaccess.oracle.OracleDbProvider) MssqlDbProvider(com.axway.ats.core.dbaccess.mssql.MssqlDbProvider) MysqlDbProvider(com.axway.ats.core.dbaccess.mysql.MysqlDbProvider) DbConnCassandra(com.axway.ats.core.dbaccess.cassandra.DbConnCassandra) CassandraDbProvider(com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider)

Example 2 with MysqlDbProvider

use of com.axway.ats.core.dbaccess.mysql.MysqlDbProvider in project ats-framework by Axway.

the class PackageLoader method loadPackageFromDb.

private static InputStream loadPackageFromDb(int packageId, String messagesHost, String messagesDB, String messagestable, String messagesUser, String messagesPassword) throws PackageException {
    DbConnMySQL dbConnection = new DbConnMySQL(messagesHost, messagesDB, messagesUser, messagesPassword);
    MysqlDbProvider dbProvider = new MysqlDbProvider(dbConnection);
    try {
        InputStream packageContent = dbProvider.selectValue(messagestable, "message_id", Integer.toString(packageId), "data");
        log.info("Successfully extracted package with id '" + packageId + "' from '" + messagestable + "' DB");
        return packageContent;
    } catch (DbRecordsException dbre) {
        throw new PackageException("Package with id '" + packageId + "' does not exist in 'messages' DB");
    } catch (DbException dbe) {
        throw new PackageException("Could not get package with id '" + packageId + "' from the 'messages' DB");
    }
}
Also used : MysqlDbProvider(com.axway.ats.core.dbaccess.mysql.MysqlDbProvider) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DbConnMySQL(com.axway.ats.core.dbaccess.mysql.DbConnMySQL) PackageException(com.axway.ats.action.objects.model.PackageException) DbRecordsException(com.axway.ats.core.dbaccess.exceptions.DbRecordsException) DbException(com.axway.ats.core.dbaccess.exceptions.DbException)

Aggregations

DbConnMySQL (com.axway.ats.core.dbaccess.mysql.DbConnMySQL)2 MysqlDbProvider (com.axway.ats.core.dbaccess.mysql.MysqlDbProvider)2 PackageException (com.axway.ats.action.objects.model.PackageException)1 CassandraDbProvider (com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider)1 DbConnCassandra (com.axway.ats.core.dbaccess.cassandra.DbConnCassandra)1 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1 DbRecordsException (com.axway.ats.core.dbaccess.exceptions.DbRecordsException)1 DbConnSQLServer (com.axway.ats.core.dbaccess.mssql.DbConnSQLServer)1 MssqlDbProvider (com.axway.ats.core.dbaccess.mssql.MssqlDbProvider)1 DbConnOracle (com.axway.ats.core.dbaccess.oracle.DbConnOracle)1 OracleDbProvider (com.axway.ats.core.dbaccess.oracle.OracleDbProvider)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1