Search in sources :

Example 1 with MysqlColumnDescription

use of com.axway.ats.core.dbaccess.MysqlColumnDescription 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;
}
Also used : DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) ColumnHasNoDefaultValueException(com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException) MysqlColumnDescription(com.axway.ats.core.dbaccess.MysqlColumnDescription) ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) ArrayList(java.util.ArrayList) MysqlColumnDescription(com.axway.ats.core.dbaccess.MysqlColumnDescription) DbException(com.axway.ats.core.dbaccess.exceptions.DbException)

Aggregations

ColumnDescription (com.axway.ats.core.dbaccess.ColumnDescription)1 DbRecordValuesList (com.axway.ats.core.dbaccess.DbRecordValuesList)1 MysqlColumnDescription (com.axway.ats.core.dbaccess.MysqlColumnDescription)1 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1 ColumnHasNoDefaultValueException (com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException)1 ArrayList (java.util.ArrayList)1