use of com.axway.ats.common.dbaccess.DbQuery in project ats-framework by Axway.
the class AbstractEnvironmentHandler method writeBackupToFile.
/**
* Write the backup to a file
*
* @param fileWriter the file writer
* @throws IOException on io error
* @throws DatabaseEnvironmentCleanupException on error
* @throws DbException on error reading from the database
* @throws ParseException
*/
protected void writeBackupToFile(FileWriter fileWriter) throws IOException, DatabaseEnvironmentCleanupException, DbException, ParseException {
if (disableForeignKeys) {
fileWriter.write(disableForeignKeyChecksStart());
}
for (DbTable dbTable : dbTables) {
if (log.isDebugEnabled()) {
log.debug("Preparing data for backup of table " + (dbTable != null ? dbTable.getTableName() : null));
}
List<ColumnDescription> columnsToSelect = null;
columnsToSelect = getColumnsToSelect(dbTable, dbConnection.getUser());
if (columnsToSelect == null || columnsToSelect.size() == 0) {
// it contains some meaningful data and so it has columns
throw new DatabaseEnvironmentCleanupException("No columns to backup for table " + (dbTable != null ? dbTable.getTableName() : ""));
}
StringBuilder selectQuery = new StringBuilder();
selectQuery.append("SELECT ");
selectQuery.append(getColumnsString(columnsToSelect));
selectQuery.append(" FROM ");
selectQuery.append(dbTable.getTableName());
DbQuery query = new DbQuery(selectQuery.toString());
DbRecordValuesList[] records = dbProvider.select(query, DbReturnModes.ESCAPED_STRING);
writeTableToFile(columnsToSelect, dbTable, records, fileWriter);
}
if (disableForeignKeys) {
fileWriter.write(disableForeignKeyChecksEnd());
}
}
Aggregations