use of com.axway.ats.core.dbaccess.MssqlColumnDescription 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;
}
use of com.axway.ats.core.dbaccess.MssqlColumnDescription in project ats-framework by Axway.
the class MssqlDbProvider method parseDbRecordAsObject.
@Override
protected DbRecordValue parseDbRecordAsObject(DbColumn dbColumn, ResultSet res, int columnIndex) throws IOException, SQLException {
DbRecordValue recordValue = null;
String type = dbColumn.getColumnType().toLowerCase();
String name = dbColumn.getColumnName().toLowerCase();
MssqlColumnDescription columnDescription = new MssqlColumnDescription(name, type);
// otherwise we get the object address
if (columnDescription.isTypeBinary() || "text".equals(type) || "ntext".equals(type)) {
/*
* http://jtds.sourceforge.net/faq.html
* By default useLOBs is true. In such cases calling getObject on the result set returns
* a LOB object, not a java String. In order to get java String it is needed to use the getString method.
* If useLOBs is false - getObject returns java String
*
* "useLOBs=false;" can be added in the connection URL, or we can simply call the getString method here
*/
recordValue = new DbRecordValue(dbColumn, res.getString(columnIndex));
} else {
recordValue = new DbRecordValue(dbColumn, res.getObject(columnIndex));
}
return recordValue;
}
Aggregations