Search in sources :

Example 6 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 7 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 8 with ColumnDescription

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

the class CassandraEnvironmentHandler method extractValue.

// extracts the specific value, considering it's type and the specifics associated with it
@SuppressWarnings("unchecked")
private StringBuilder extractValue(ColumnDescription column, Object fieldValue) throws ParseException {
    if (fieldValue == null) {
        return new StringBuilder("NULL");
    }
    StringBuilder insertStatement = new StringBuilder();
    // non-string values. Should not be in quotes and do not need escaping
    if ("UUID".equalsIgnoreCase(column.getType())) {
        insertStatement.append(fieldValue.toString());
    } else if ("Set".equalsIgnoreCase(column.getType())) {
        final ColumnDescription subElementDescription = new ColumnDescription(null, column.getSubsType()[0]);
        insertStatement.append("{");
        Object[] values = ((Set<Object>) fieldValue).toArray();
        for (int i = 0; i < values.length; i++) {
            insertStatement.append(extractValue(subElementDescription, values[i]));
            if (i < values.length - 1) {
                insertStatement.append(',');
            }
        }
        insertStatement.append("}");
    } else if ("List".equalsIgnoreCase(column.getType())) {
        final ColumnDescription subElementDescription = new ColumnDescription(null, column.getSubsType()[0]);
        insertStatement.append("[");
        Object[] values = ((List<Object>) fieldValue).toArray();
        for (int i = 0; i < values.length; i++) {
            insertStatement.append(extractValue(subElementDescription, values[i]));
            if (i < values.length - 1) {
                insertStatement.append(',');
            }
        }
        insertStatement.append("]");
    } else if ("Map".equalsIgnoreCase(column.getType())) {
        final ColumnDescription subElementKeyDescription = new ColumnDescription(null, column.getSubsType()[0]);
        final ColumnDescription subElementValueDescription = new ColumnDescription(null, column.getSubsType()[1]);
        insertStatement.append("{");
        Map<String, Object> valuesMap = (Map<String, Object>) fieldValue;
        Set<Entry<String, Object>> fieldEntries = valuesMap.entrySet();
        int i = 0;
        for (Entry<String, Object> fieldEntry : fieldEntries) {
            insertStatement.append(extractValue(subElementKeyDescription, fieldEntry.getKey()));
            insertStatement.append(':');
            insertStatement.append(extractValue(subElementValueDescription, fieldEntry.getValue()));
            ++i;
            if (i < fieldEntries.size()) {
                insertStatement.append(',');
            }
        }
        insertStatement.append("}");
    } else if ("Date".equalsIgnoreCase(column.getType())) {
        insertStatement.append('\'');
        insertStatement.append(DATE_FORMATTER.format(fieldValue));
        insertStatement.append('\'');
    } else if ("String".equalsIgnoreCase(column.getType()) || "varchar".equalsIgnoreCase(column.getType())) {
        insertStatement.append('\'');
        insertStatement.append(fieldValue.toString().replace("'", "''"));
        insertStatement.append('\'');
    } else if ("ByteBuffer".equalsIgnoreCase(column.getType())) {
        insertStatement.append(HEX_PREFIX_STR);
        insertStatement.append(byteArrayToHex(((byte[]) fieldValue)));
    } else {
        insertStatement.append(fieldValue.toString().replace("'", "''"));
    }
    return insertStatement;
}
Also used : Entry(java.util.Map.Entry) Set(java.util.Set) ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) ArrayList(java.util.ArrayList) List(java.util.List) DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) Map(java.util.Map)

Example 9 with ColumnDescription

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

the class CassandraEnvironmentHandler method getColumnsString.

@Override
protected String getColumnsString(List<ColumnDescription> columns) {
    StringBuilder columnsBuilder = new StringBuilder();
    //create the columns string
    for (ColumnDescription column : columns) {
        columnsBuilder.append(column.getName());
        columnsBuilder.append(",");
    }
    //remove the last comma
    if (columnsBuilder.length() > 1) {
        columnsBuilder.delete(columnsBuilder.length() - 1, columnsBuilder.length());
    }
    return columnsBuilder.toString();
}
Also used : ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription)

Example 10 with ColumnDescription

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

the class CassandraEnvironmentHandler method getColumnsToSelect.

@Override
protected List<ColumnDescription> getColumnsToSelect(DbTable table, String userName) throws DbException, ColumnHasNoDefaultValueException {
    Map<String, String> columnInfo = ((CassandraDbProvider) this.dbProvider).getColumnInfo(table.getTableName());
    ArrayList<ColumnDescription> columnsToSelect = new ArrayList<ColumnDescription>();
    for (Entry<String, String> columnEntry : columnInfo.entrySet()) {
        //check if the column should be skipped in the backup
        if (!table.getColumnsToExclude().contains(columnEntry.getKey())) {
            String dataTypes = columnEntry.getValue();
            ColumnDescription colDescription;
            if (!dataTypes.contains("|")) {
                colDescription = new ColumnDescription(columnEntry.getKey(), columnEntry.getValue());
            } else {
                String[] dataTypesArray = dataTypes.split("\\|");
                String[] subDataTypesArray = new String[dataTypesArray.length - 1];
                for (int i = 0; i < subDataTypesArray.length; i++) {
                    subDataTypesArray[i] = dataTypesArray[i + 1];
                }
                colDescription = new ColumnDescription(columnEntry.getKey(), dataTypesArray[0], subDataTypesArray);
            }
            columnsToSelect.add(colDescription);
        }
    }
    return columnsToSelect;
}
Also used : ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) ArrayList(java.util.ArrayList) CassandraDbProvider(com.axway.ats.core.dbaccess.cassandra.CassandraDbProvider)

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