Search in sources :

Example 1 with DbRecordsException

use of com.axway.ats.core.dbaccess.exceptions.DbRecordsException in project ats-framework by Axway.

the class AbstractDbProvider method selectValue.

public InputStream selectValue(String tableName, String[] keyColumns, String[] keyValues, String queryColumn, int recordNumber) throws DbException, ValidationException {
    InputStream queryValueStream = null;
    //all operands are "equals"
    String[] whereOperands = new String[keyColumns.length];
    for (int i = 0; i < whereOperands.length; i++) {
        whereOperands[i] = "=";
    }
    String sql = constructSelectStatement(new String[] { queryColumn }, tableName, keyColumns, keyValues, whereOperands);
    DbRecordValuesList[] records = select(new DbQuery(sql, new ArrayList<Object>()), DbReturnModes.INPUT_STREAM);
    if (records == null) {
        throw new DbRecordsException();
    }
    if (records.length < recordNumber + 1) {
        throw new DbRecordsException(records.length, recordNumber + 1);
    } else {
        queryValueStream = (InputStream) records[recordNumber].get(queryColumn);
    }
    return queryValueStream;
}
Also used : DbQuery(com.axway.ats.common.dbaccess.DbQuery) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DbRecordsException(com.axway.ats.core.dbaccess.exceptions.DbRecordsException)

Example 2 with DbRecordsException

use of com.axway.ats.core.dbaccess.exceptions.DbRecordsException in project ats-framework by Axway.

the class AbstractDbProvider method selectValue.

public InputStream selectValue(String tableName, String keyColumn, String keyValue, String queryColumn, int recordNumber) throws DbException {
    InputStream queryValueStream = null;
    String sql = " SELECT " + queryColumn + " FROM " + tableName + " WHERE " + keyColumn + " = '" + escapeSql(keyValue) + "'";
    DbRecordValuesList[] records = select(new DbQuery(sql, new ArrayList<Object>()), DbReturnModes.INPUT_STREAM);
    if (records == null) {
        throw new DbRecordsException();
    }
    if (records.length < recordNumber + 1) {
        throw new DbRecordsException(records.length, recordNumber + 1);
    }
    queryValueStream = (InputStream) records[recordNumber].get(queryColumn);
    return queryValueStream;
}
Also used : DbQuery(com.axway.ats.common.dbaccess.DbQuery) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DbRecordsException(com.axway.ats.core.dbaccess.exceptions.DbRecordsException)

Example 3 with DbRecordsException

use of com.axway.ats.core.dbaccess.exceptions.DbRecordsException in project ats-framework by Axway.

the class PackageLoader method loadPackageFromDb.

private static InputStream loadPackageFromDb(int packageId, String messagesHost, String messagesDB, String messagestable, String messagesUser, String messagesPassword) throws PackageException {
    DbConnMySQL dbConnection = new DbConnMySQL(messagesHost, messagesDB, messagesUser, messagesPassword);
    MysqlDbProvider dbProvider = new MysqlDbProvider(dbConnection);
    try {
        InputStream packageContent = dbProvider.selectValue(messagestable, "message_id", Integer.toString(packageId), "data");
        log.info("Successfully extracted package with id '" + packageId + "' from '" + messagestable + "' DB");
        return packageContent;
    } catch (DbRecordsException dbre) {
        throw new PackageException("Package with id '" + packageId + "' does not exist in 'messages' DB");
    } catch (DbException dbe) {
        throw new PackageException("Could not get package with id '" + packageId + "' from the 'messages' DB");
    }
}
Also used : MysqlDbProvider(com.axway.ats.core.dbaccess.mysql.MysqlDbProvider) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DbConnMySQL(com.axway.ats.core.dbaccess.mysql.DbConnMySQL) PackageException(com.axway.ats.action.objects.model.PackageException) DbRecordsException(com.axway.ats.core.dbaccess.exceptions.DbRecordsException) DbException(com.axway.ats.core.dbaccess.exceptions.DbException)

Aggregations

DbRecordsException (com.axway.ats.core.dbaccess.exceptions.DbRecordsException)3 InputStream (java.io.InputStream)3 DbQuery (com.axway.ats.common.dbaccess.DbQuery)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 PackageException (com.axway.ats.action.objects.model.PackageException)1 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1 DbConnMySQL (com.axway.ats.core.dbaccess.mysql.DbConnMySQL)1 MysqlDbProvider (com.axway.ats.core.dbaccess.mysql.MysqlDbProvider)1 FileInputStream (java.io.FileInputStream)1