Search in sources :

Example 6 with DbQuery

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());
    }
}
Also used : DatabaseEnvironmentCleanupException(com.axway.ats.environment.database.exceptions.DatabaseEnvironmentCleanupException) DbQuery(com.axway.ats.common.dbaccess.DbQuery) DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) ColumnDescription(com.axway.ats.core.dbaccess.ColumnDescription) DbTable(com.axway.ats.environment.database.model.DbTable)

Aggregations

DbQuery (com.axway.ats.common.dbaccess.DbQuery)6 ArrayList (java.util.ArrayList)4 DbRecordValuesList (com.axway.ats.core.dbaccess.DbRecordValuesList)3 DbRecordsException (com.axway.ats.core.dbaccess.exceptions.DbRecordsException)2 NumberValidationException (com.axway.ats.core.validation.exceptions.NumberValidationException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 DatabaseCell (com.axway.ats.action.dbaccess.model.DatabaseCell)1 DatabaseRow (com.axway.ats.action.dbaccess.model.DatabaseRow)1 DatabaseOperationsException (com.axway.ats.action.exceptions.DatabaseOperationsException)1 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 ColumnDescription (com.axway.ats.core.dbaccess.ColumnDescription)1 DbRecordValue (com.axway.ats.core.dbaccess.DbRecordValue)1 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1 DatabaseEnvironmentCleanupException (com.axway.ats.environment.database.exceptions.DatabaseEnvironmentCleanupException)1 DbTable (com.axway.ats.environment.database.model.DbTable)1 LinkedList (java.util.LinkedList)1