Search in sources :

Example 1 with ColumnDescription

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

the class Test_ColumnDescription method isTypeNumericNegative.

@Test
public void isTypeNumericNegative() {
    ColumnDescription columnDescription = new ColumnDescription("name", "type");
    assertFalse(columnDescription.isTypeNumeric());
}
Also used : ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 2 with ColumnDescription

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

the class Test_ColumnDescription method isTypeNumericPositive.

@Test
public void isTypeNumericPositive() {
    List<String> numericTypes = new ArrayList<String>();
    numericTypes.add("int");
    numericTypes.add("decimal");
    numericTypes.add("numeric");
    numericTypes.add("real");
    numericTypes.add("double");
    numericTypes.add("bit");
    for (String numericType : numericTypes) {
        ColumnDescription columnDescription = new ColumnDescription("name", numericType);
        assertTrue(columnDescription.isTypeNumeric());
    }
}
Also used : ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) ArrayList(java.util.ArrayList) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 3 with ColumnDescription

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

the class Test_ColumnDescription method accessors.

@Test
public void accessors() {
    ColumnDescription columnDescription = new ColumnDescription("name", "type");
    assertEquals("name", columnDescription.getName());
    assertEquals("type", columnDescription.getType());
}
Also used : ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 4 with ColumnDescription

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

the class OracleEnvironmentHandler method getColumnsToSelect.

@Override
protected List<ColumnDescription> getColumnsToSelect(DbTable table, String userName) throws DbException, ColumnHasNoDefaultValueException {
    // TODO Implementation might be replaced with JDBC DatabaseMetaData.getColumns() but should be verified
    // with default column values
    // ALL_TAB_COLS - All columns of tables accessible by this user. OWNER restriction is used because user might
    // have access to other user's tables and columns
    String selectColumnsInfo = "SELECT * FROM ALL_TAB_COLS WHERE TABLE_NAME='" + table.getTableName().toUpperCase() + "' AND OWNER='" + userName.toUpperCase() + "'";
    ArrayList<ColumnDescription> columnsToSelect = new ArrayList<ColumnDescription>();
    DbRecordValuesList[] columnsMetaData = null;
    try {
        columnsMetaData = this.dbProvider.select(selectColumnsInfo);
    } catch (DbException e) {
        log.error("Could not get columns for table " + table.getTableName() + ". You may check if the table exists, if the you are using the right user and it has the right permissions. See more details in the trace.");
        throw e;
    }
    if (columnsMetaData.length == 0) {
        throw new DbException("Could not get columns for table " + table.getTableName() + ". You may check if the table exists, if the you are using the right user and it has the right permissions.");
    }
    for (DbRecordValuesList columnMetaData : columnsMetaData) {
        String columnName = (String) columnMetaData.get("COLUMN_NAME");
        //check if the column should be skipped in the backup
        if (!table.getColumnsToExclude().contains(columnName)) {
            ColumnDescription colDescription = new OracleColumnDescription(columnName, (String) columnMetaData.get("DATA_TYPE"));
            columnsToSelect.add(colDescription);
        } else {
            //if this column has no default value, we cannot skip it in the backup
            if (columnMetaData.get("DATA_DEFAULT") == null) {
                log.error("Cannot skip columns with no default values while creating backup");
                throw new ColumnHasNoDefaultValueException(table.getTableName(), columnName);
            }
        }
    }
    return columnsToSelect;
}
Also used : DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) ColumnHasNoDefaultValueException(com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException) OracleColumnDescription(com.axway.ats.core.dbaccess.OracleColumnDescription) ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) ArrayList(java.util.ArrayList) OracleColumnDescription(com.axway.ats.core.dbaccess.OracleColumnDescription) DbException(com.axway.ats.core.dbaccess.exceptions.DbException)

Example 5 with ColumnDescription

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

the class MssqlEnvironmentHandler method getColumnsToSelect.

@Override
protected List<ColumnDescription> getColumnsToSelect(DbTable table, String userName) throws DbException, ColumnHasNoDefaultValueException {
    String selectColumnsInfo = "SELECT COLUMN_NAME, DATA_TYPE, COLUMN_DEFAULT, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE, " + "columnproperty(object_id('" + table.getTableName() + "'), COLUMN_NAME,'IsIdentity') as isIdentity " + "FROM information_schema.COLUMNS WHERE table_name LIKE '" + table.getTableName() + "'";
    ArrayList<ColumnDescription> columnsToSelect = new ArrayList<ColumnDescription>();
    DbRecordValuesList[] columnsMetaData = null;
    try {
        columnsMetaData = this.dbProvider.select(selectColumnsInfo);
    } catch (DbException e) {
        log.error("Could not get columns for table " + table.getTableName() + ". Check if the table is existing and that the user has permissions. See more details in the trace.");
        throw e;
    }
    // the Identity column can be skipped(excluded)
    table.setIdentityColumnPresent(false);
    for (DbRecordValuesList columnMetaData : columnsMetaData) {
        String columnName = (String) columnMetaData.get("COLUMN_NAME");
        //check if the column should be skipped in the backup
        if (!table.getColumnsToExclude().contains(columnName)) {
            ColumnDescription colDescription = new MssqlColumnDescription(columnName, (String) columnMetaData.get("DATA_TYPE"));
            columnsToSelect.add(colDescription);
            if ((Integer) columnMetaData.get("isIdentity") == 1) {
                table.setIdentityColumnPresent(true);
            }
        } else {
            //if this column has no default value, we cannot skip it in the backup
            if (columnMetaData.get("COLUMN_DEFAULT") == null) {
                log.error("Cannot skip columns with no default values while creating backup");
                throw new ColumnHasNoDefaultValueException(table.getTableName(), columnName);
            }
        }
    }
    return columnsToSelect;
}
Also used : DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) ColumnHasNoDefaultValueException(com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException) MssqlColumnDescription(com.axway.ats.core.dbaccess.MssqlColumnDescription) ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) ArrayList(java.util.ArrayList) MssqlColumnDescription(com.axway.ats.core.dbaccess.MssqlColumnDescription) DbException(com.axway.ats.core.dbaccess.exceptions.DbException)

Aggregations

ColumnDescription (com.axway.ats.core.dbaccess.ColumnDescription)17 BaseTest (com.axway.ats.environment.BaseTest)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 DbRecordValuesList (com.axway.ats.core.dbaccess.DbRecordValuesList)6 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)3 ColumnHasNoDefaultValueException (com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException)3 MssqlColumnDescription (com.axway.ats.core.dbaccess.MssqlColumnDescription)2 OracleColumnDescription (com.axway.ats.core.dbaccess.OracleColumnDescription)2 DbQuery (com.axway.ats.common.dbaccess.DbQuery)1 DbRecordValue (com.axway.ats.core.dbaccess.DbRecordValue)1 MysqlColumnDescription (com.axway.ats.core.dbaccess.MysqlColumnDescription)1 CassandraDbProvider (com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider)1 DatabaseEnvironmentCleanupException (com.axway.ats.environment.database.exceptions.DatabaseEnvironmentCleanupException)1 DbTable (com.axway.ats.environment.database.model.DbTable)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1