use of com.axway.ats.action.exceptions.DatabaseOperationsException in project ats-framework by Axway.
the class DatabaseOperations method getValue.
/**
* Gets a single value from a database. </br>
* It returns the first value of the first returned row.
*
* <p><strong>Note</strong>: If the selected DB object is array - BLOB, LONG BLOB ... we return it this way:
* <code>[ 10, 24, -35]</code>
* </p>
*
* @param sqlQuery the SQL query to run
* @return
*/
@PublicAtsApi
public String getValue(String sqlQuery) {
try {
log.debug("Executing query: " + sqlQuery);
DbRecordValuesList[] rsList = dbProvider.select(sqlQuery);
if (rsList != null && rsList.length > 0) {
if (rsList.length > 1) {
log.warn("SQL query '" + sqlQuery + "' returned " + rsList.length + " rows of results");
}
if (rsList[0].size() > 1) {
log.warn("SQL query '" + sqlQuery + "' returned " + rsList[0].size() + " values per row");
}
return rsList[0].get(0).getValueAsString();
}
} catch (DbException e) {
throw new DatabaseOperationsException("Error getting value from DB with query '" + sqlQuery + "'", e);
}
return null;
}
use of com.axway.ats.action.exceptions.DatabaseOperationsException in project ats-framework by Axway.
the class DatabaseOperations method updateValue.
/**
* Run update query.
*
* @param sqlQuery the SQL query to run
* @return the number of updated rows
*/
@PublicAtsApi
public int updateValue(String sqlQuery) {
int rowsUpdated;
try {
log.debug("Executing update query: '" + sqlQuery + "'");
rowsUpdated = dbProvider.executeUpdate(sqlQuery);
if (!(dbProvider instanceof CassandraDbProvider)) {
if (rowsUpdated == 0) {
log.warn("SQL query '" + sqlQuery + "' updated 0 rows");
} else {
log.debug("SQL query '" + sqlQuery + "' updated '" + rowsUpdated + "' rows");
}
}
} catch (DbException e) {
throw new DatabaseOperationsException("Error executing update query '" + sqlQuery + "'", e);
}
return rowsUpdated;
}
Aggregations