Search in sources :

Example 1 with MariaDbDbProvider

use of com.axway.ats.core.dbaccess.mariadb.MariaDbDbProvider 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");
    }
    dbType = dbType.toUpperCase();
    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, dbPort, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnPostgreSQL.DATABASE_TYPE:
            dbProvider = new PostgreSqlDbProvider((DbConnPostgreSQL) createDbConnection(dbType, dbHost, dbPort, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnMySQL.DATABASE_TYPE:
            dbProvider = new MysqlDbProvider((DbConnMySQL) createDbConnection(dbType, dbHost, dbPort, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnMariaDB.DATABASE_TYPE:
            dbProvider = new MariaDbDbProvider((DbConnMariaDB) createDbConnection(dbType, dbHost, dbPort, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnOracle.DATABASE_TYPE:
            dbProvider = new OracleDbProvider((DbConnOracle) createDbConnection(dbType, dbHost, dbPort, dbName, dbUser, dbPass, customProperties));
            break;
        case DbConnCassandra.DATABASE_TYPE:
            dbProvider = new CassandraDbProvider((DbConnCassandra) createDbConnection(dbType, dbHost, dbPort, 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) DbConnMariaDB(com.axway.ats.core.dbaccess.mariadb.DbConnMariaDB) MssqlDbProvider(com.axway.ats.core.dbaccess.mssql.MssqlDbProvider) DbConnSQLServer(com.axway.ats.core.dbaccess.mssql.DbConnSQLServer) PostgreSqlDbProvider(com.axway.ats.core.dbaccess.postgresql.PostgreSqlDbProvider) MysqlDbProvider(com.axway.ats.core.dbaccess.mysql.MysqlDbProvider) DbConnMySQL(com.axway.ats.core.dbaccess.mysql.DbConnMySQL) DbConnOracle(com.axway.ats.core.dbaccess.oracle.DbConnOracle) DbConnPostgreSQL(com.axway.ats.core.dbaccess.postgresql.DbConnPostgreSQL) CassandraDbProvider(com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider) OracleDbProvider(com.axway.ats.core.dbaccess.oracle.OracleDbProvider) PostgreSqlDbProvider(com.axway.ats.core.dbaccess.postgresql.PostgreSqlDbProvider) MssqlDbProvider(com.axway.ats.core.dbaccess.mssql.MssqlDbProvider) MysqlDbProvider(com.axway.ats.core.dbaccess.mysql.MysqlDbProvider) MariaDbDbProvider(com.axway.ats.core.dbaccess.mariadb.MariaDbDbProvider) MariaDbDbProvider(com.axway.ats.core.dbaccess.mariadb.MariaDbDbProvider) DbConnCassandra(com.axway.ats.core.dbaccess.cassandra.DbConnCassandra) CassandraDbProvider(com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider)

Example 2 with MariaDbDbProvider

use of com.axway.ats.core.dbaccess.mariadb.MariaDbDbProvider in project ats-framework by Axway.

the class AbstractDbProvider method getTableDescriptions.

/**
 * @param tablesToSkip list of some tables we are not interested in
 * @return description about all important tables
 */
@Override
public List<TableDescription> getTableDescriptions(List<String> tablesToSkip) {
    Connection connection = ConnectionPool.getConnection(dbConnection);
    List<TableDescription> tables = new ArrayList<TableDescription>();
    if (tablesToSkip == null) {
        tablesToSkip = new ArrayList<>();
    }
    try {
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        // ORACLE -> The USER NAME is the TABLE SCHEMA
        String schemaPattern = (this instanceof OracleDbProvider ? dbConnection.getUser() : null);
        // MySQL/MariaDB -> The DB NAME is the TABLE SCHEMA
        schemaPattern = (this instanceof MysqlDbProvider || this instanceof MariaDbDbProvider ? dbConnection.getDb() : schemaPattern);
        ResultSet tablesResultSet = databaseMetaData.getTables(null, schemaPattern, null, new String[] { "TABLE" });
        while (tablesResultSet.next()) {
            String tableName = tablesResultSet.getString(3);
            // check for tables the DB driver rejects to return
            if (!isTableAccepted(tablesResultSet, dbConnection.db, tableName)) {
                continue;
            }
            // check for tables the user is not interested in
            boolean skipThisTable = false;
            for (String tableToSkip : tablesToSkip) {
                if (tableName.equalsIgnoreCase(tableToSkip)) {
                    skipThisTable = true;
                    break;
                }
            }
            if (skipThisTable) {
                continue;
            }
            log.debug("Extracting description about '" + tableName + "' table");
            TableDescription table = new TableDescription();
            table.setName(tableName);
            table.setSchema(tablesResultSet.getString("TABLE_SCHEM"));
            table.setPrimaryKeyColumn(extractPrimaryKeyColumn(tableName, databaseMetaData, schemaPattern));
            table.setIndexes(extractTableIndexes(tableName, databaseMetaData, connection.getCatalog()));
            List<String> columnDescriptions = new ArrayList<>();
            extractTableColumns(tableName, databaseMetaData, schemaPattern, columnDescriptions);
            table.setColumnDescriptions(columnDescriptions);
            tables.add(table);
        }
    } catch (SQLException sqle) {
        throw new DbException("Error extracting DB schema information", sqle);
    }
    return tables;
}
Also used : OracleDbProvider(com.axway.ats.core.dbaccess.oracle.OracleDbProvider) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) DatabaseMetaData(java.sql.DatabaseMetaData) TableDescription(com.axway.ats.common.dbaccess.snapshot.TableDescription) DbException(com.axway.ats.core.dbaccess.exceptions.DbException) MysqlDbProvider(com.axway.ats.core.dbaccess.mysql.MysqlDbProvider) ResultSet(java.sql.ResultSet) MariaDbDbProvider(com.axway.ats.core.dbaccess.mariadb.MariaDbDbProvider)

Aggregations

MariaDbDbProvider (com.axway.ats.core.dbaccess.mariadb.MariaDbDbProvider)2 MysqlDbProvider (com.axway.ats.core.dbaccess.mysql.MysqlDbProvider)2 OracleDbProvider (com.axway.ats.core.dbaccess.oracle.OracleDbProvider)2 TableDescription (com.axway.ats.common.dbaccess.snapshot.TableDescription)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 DbConnMariaDB (com.axway.ats.core.dbaccess.mariadb.DbConnMariaDB)1 DbConnSQLServer (com.axway.ats.core.dbaccess.mssql.DbConnSQLServer)1 MssqlDbProvider (com.axway.ats.core.dbaccess.mssql.MssqlDbProvider)1 DbConnMySQL (com.axway.ats.core.dbaccess.mysql.DbConnMySQL)1 DbConnOracle (com.axway.ats.core.dbaccess.oracle.DbConnOracle)1 DbConnPostgreSQL (com.axway.ats.core.dbaccess.postgresql.DbConnPostgreSQL)1 PostgreSqlDbProvider (com.axway.ats.core.dbaccess.postgresql.PostgreSqlDbProvider)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1