use of com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException 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;
}
use of com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException 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.environment.database.exceptions.ColumnHasNoDefaultValueException in project ats-framework by Axway.
the class MysqlEnvironmentHandler method getColumnsToSelect.
@Override
protected List<ColumnDescription> getColumnsToSelect(DbTable table, String userName) throws DbException, ColumnHasNoDefaultValueException {
// TODO Might be replaced with JDBC DatabaseMetaData.getColumns() but should be verified with default values
ArrayList<ColumnDescription> columnsToSelect = new ArrayList<ColumnDescription>();
DbRecordValuesList[] columnsMetaData = null;
try {
columnsMetaData = dbProvider.select("SHOW COLUMNS FROM " + table.getTableName());
} 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;
}
for (DbRecordValuesList columnMetaData : columnsMetaData) {
String columnName = (String) columnMetaData.get(MysqlColumnNames.COLUMN_NAME.getName(isJDBC4));
//check if the column should be skipped in the backup
if (!table.getColumnsToExclude().contains(columnName)) {
ColumnDescription colDescription = new MysqlColumnDescription(columnName, (String) columnMetaData.get(MysqlColumnNames.COLUMN_TYPE.getName(isJDBC4)));
columnsToSelect.add(colDescription);
} else {
//if this column has no default value, we cannot skip it in the backup
if (columnMetaData.get(MysqlColumnNames.DEFAULT_COLUMN.getName(isJDBC4)) == null) {
log.error("Cannot skip columns with no default values while creating backup");
throw new ColumnHasNoDefaultValueException(table.getTableName(), columnName);
}
}
}
return columnsToSelect;
}
Aggregations