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());
}
}
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());
}
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;
}
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();
}
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;
}
Aggregations