Search in sources :

Example 1 with DbConnSQLServer

use of com.axway.ats.core.dbaccess.mssql.DbConnSQLServer in project ats-framework by Axway.

the class Test_DatabaseProviderFactory_createDbConnection method createMSSQLWithCustomProperties.

@Test
public void createMSSQLWithCustomProperties() {
    Map<String, Object> customProperties = new HashMap<String, Object>();
    DbConnSQLServer dbConnection = (DbConnSQLServer) DatabaseProviderFactory.createDbConnection(DbConnSQLServer.DATABASE_TYPE, "host", "db", "user", "pass", customProperties);
    assertEquals(DbConnSQLServer.DATABASE_TYPE, dbConnection.getDbType());
    assertEquals("host", dbConnection.getHost());
    assertEquals("db", dbConnection.getDb());
    assertEquals("user", dbConnection.getUser());
    assertEquals("pass", dbConnection.getPassword());
    assertEquals("jdbc:jtds:sqlserver://host:1433/db", dbConnection.getURL());
}
Also used : DbConnSQLServer(com.axway.ats.core.dbaccess.mssql.DbConnSQLServer) HashMap(java.util.HashMap) BaseTest(com.axway.ats.core.BaseTest) Test(org.junit.Test)

Example 2 with DbConnSQLServer

use of com.axway.ats.core.dbaccess.mssql.DbConnSQLServer in project ats-framework by Axway.

the class Test_DatabaseProviderFactory_createDbConnection method createMSSQLNoCustom.

@Test
public void createMSSQLNoCustom() {
    DbConnSQLServer dbConnection = (DbConnSQLServer) DatabaseProviderFactory.createDbConnection(DbConnSQLServer.DATABASE_TYPE, "host", "db", "user", "pass");
    assertEquals(DbConnSQLServer.DATABASE_TYPE, dbConnection.getDbType());
    assertEquals("host", dbConnection.getHost());
    assertEquals("db", dbConnection.getDb());
    assertEquals("user", dbConnection.getUser());
    assertEquals("pass", dbConnection.getPassword());
    assertEquals("jdbc:jtds:sqlserver://host:1433/db", dbConnection.getURL());
}
Also used : DbConnSQLServer(com.axway.ats.core.dbaccess.mssql.DbConnSQLServer) BaseTest(com.axway.ats.core.BaseTest) Test(org.junit.Test)

Example 3 with DbConnSQLServer

use of com.axway.ats.core.dbaccess.mssql.DbConnSQLServer 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 4 with DbConnSQLServer

use of com.axway.ats.core.dbaccess.mssql.DbConnSQLServer in project ats-framework by Axway.

the class DbAccessFactory method getNewDbWriteAccessObject.

/**
     * Retrieves the DB info from the log4j system
     * and then creates a new instance for writing into the DB
     * 
     * @return
     * @throws DatabaseAccessException
     */
public DbWriteAccess getNewDbWriteAccessObject() throws DatabaseAccessException {
    // Our DB appender keeps the DB connection info
    ActiveDbAppender loggingAppender = ActiveDbAppender.getCurrentInstance();
    if (loggingAppender == null) {
        throw new DatabaseAccessException("Unable to initialize connection to the logging database as the ATS ActiveDbAppender is not attached to log4j system");
    }
    // Create DB connection based on the log4j system settings
    DbConnection dbConnection = new DbConnSQLServer(loggingAppender.getHost(), loggingAppender.getDatabase(), loggingAppender.getUser(), loggingAppender.getPassword());
    // Create the database access layer
    return new DbWriteAccess(dbConnection, false);
}
Also used : ActiveDbAppender(com.axway.ats.log.appenders.ActiveDbAppender) DbConnSQLServer(com.axway.ats.core.dbaccess.mssql.DbConnSQLServer) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DbConnection(com.axway.ats.core.dbaccess.DbConnection)

Aggregations

DbConnSQLServer (com.axway.ats.core.dbaccess.mssql.DbConnSQLServer)4 BaseTest (com.axway.ats.core.BaseTest)2 Test (org.junit.Test)2 DbConnection (com.axway.ats.core.dbaccess.DbConnection)1 CassandraDbProvider (com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider)1 DbConnCassandra (com.axway.ats.core.dbaccess.cassandra.DbConnCassandra)1 MssqlDbProvider (com.axway.ats.core.dbaccess.mssql.MssqlDbProvider)1 DbConnMySQL (com.axway.ats.core.dbaccess.mysql.DbConnMySQL)1 MysqlDbProvider (com.axway.ats.core.dbaccess.mysql.MysqlDbProvider)1 DbConnOracle (com.axway.ats.core.dbaccess.oracle.DbConnOracle)1 OracleDbProvider (com.axway.ats.core.dbaccess.oracle.OracleDbProvider)1 ActiveDbAppender (com.axway.ats.log.appenders.ActiveDbAppender)1 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)1 HashMap (java.util.HashMap)1