Search in sources :

Example 1 with NumberValidationException

use of com.axway.ats.core.validation.exceptions.NumberValidationException in project ats-framework by Axway.

the class AbstractDbProvider method rowCount.

/**
     * @param tableName         the name of the table
     * @param whereCondition    the where condition ( without the WHERE keyword )
     * @return                  returns the number of the rows that
     *                          match the where statement as a int. Returns 0 if there is
     *                          an error or the rowcount is 0
     */
@Override
public int rowCount(String tableName, String whereCondition) throws DbException, NumberValidationException {
    int returnCount;
    String sql = " SELECT " + " COUNT(*)" + " FROM " + tableName;
    if (whereCondition != null && whereCondition.length() > 0) {
        sql += " WHERE " + whereCondition;
    }
    DbRecordValuesList[] records = select(new DbQuery(sql, new ArrayList<Object>()), DbReturnModes.STRING);
    try {
        returnCount = records == null ? 0 : Integer.parseInt((String) records[0].get("COUNT(*)"));
    } catch (NumberFormatException nfe) {
        throw new NumberValidationException("The row count could not be converted to integer", nfe);
    }
    return returnCount;
}
Also used : NumberValidationException(com.axway.ats.core.validation.exceptions.NumberValidationException) DbQuery(com.axway.ats.common.dbaccess.DbQuery) ArrayList(java.util.ArrayList)

Example 2 with NumberValidationException

use of com.axway.ats.core.validation.exceptions.NumberValidationException in project ats-framework by Axway.

the class CassandraDbProvider method rowCount.

@Override
public int rowCount(String tableName, String whereCondition) throws DbException, NumberValidationException {
    int returnCount;
    String sql = "SELECT " + " COUNT(*)" + " FROM " + tableName;
    if (whereCondition != null && whereCondition.length() > 0) {
        sql += " WHERE " + whereCondition;
    }
    DbRecordValuesList[] records = select(new DbQuery(sql, new ArrayList<Object>()), DbReturnModes.STRING);
    try {
        returnCount = records == null ? 0 : ((Long) records[0].get("count")).intValue();
    } catch (NumberFormatException nfe) {
        throw new NumberValidationException("The row count could not be converted to integer", nfe);
    }
    return returnCount;
}
Also used : NumberValidationException(com.axway.ats.core.validation.exceptions.NumberValidationException) DbQuery(com.axway.ats.common.dbaccess.DbQuery) DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) ArrayList(java.util.ArrayList)

Aggregations

DbQuery (com.axway.ats.common.dbaccess.DbQuery)2 NumberValidationException (com.axway.ats.core.validation.exceptions.NumberValidationException)2 ArrayList (java.util.ArrayList)2 DbRecordValuesList (com.axway.ats.core.dbaccess.DbRecordValuesList)1