use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiDAOImpl method constructRatingFromResultSet.
/**
* Constructs a Rating object from a result set
*
* @param rs the result set retrieved from db
* @return Rating constructed from result set
* @throws APIMgtDAOException if result set access fails
*/
private Rating constructRatingFromResultSet(ResultSet rs) throws APIMgtDAOException {
Rating rating = new Rating();
try {
rating.setUuid(rs.getString("UUID"));
rating.setRating((int) Double.parseDouble(rs.getString("RATING")));
rating.setApiId(rs.getString("API_ID"));
rating.setUsername(rs.getString("USER_IDENTIFIER"));
rating.setCreatedUser(rs.getString("CREATED_BY"));
rating.setCreatedTime(rs.getTimestamp("CREATED_TIME").toLocalDateTime());
rating.setLastUpdatedUser(rs.getString("UPDATED_BY"));
rating.setLastUpdatedTime(rs.getTimestamp("LAST_UPDATED_TIME").toLocalDateTime());
} catch (SQLException e) {
String errorMessage = "constructing Rating from ResultSet";
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
return rating;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class EntityDAO method getLastUpdatedTimeOfResourceByName.
/**
* Returns the last access time of the given entity identified by the NAME field.
*
* @param resourceTableName Table name of the entity
* @param name value in the NAME field of the entity
* @return Last access time of the requested resource
* @throws APIMgtDAOException
*/
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
static String getLastUpdatedTimeOfResourceByName(String resourceTableName, String name) throws APIMgtDAOException {
final String query = "SELECT LAST_UPDATED_TIME FROM " + resourceTableName + " WHERE NAME = ?";
String lastUpdatedTime = null;
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, name);
try (ResultSet rs = statement.executeQuery()) {
if (rs.next()) {
lastUpdatedTime = rs.getString("LAST_UPDATED_TIME");
}
}
return lastUpdatedTime;
} catch (SQLException e) {
throw new APIMgtDAOException("Error while retrieving last access time from table : " + resourceTableName + " and entity " + name, e);
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class FunctionDAOImpl method getUserDeployedFunctions.
/**
* {@inheritDoc}
*/
@Override
public List<Function> getUserDeployedFunctions(String userName) throws APIMgtDAOException {
if (userName == null) {
throw new IllegalArgumentException("Username must not be null");
}
List<Function> functions = new ArrayList<>();
final String sqlQuery = "SELECT FUNCTION_NAME, FUNCTION_URI " + "FROM AM_LAMBDA_FUNCTION " + "WHERE USER_NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
preparedStatement.setString(1, userName);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String functionName = resultSet.getString("FUNCTION_NAME");
URI endpointURI = new URI(resultSet.getString("FUNCTION_URI"));
functions.add(new Function(functionName, endpointURI));
}
} catch (URISyntaxException e) {
throw new APIMgtDAOException("Not a URI", e);
}
} catch (SQLException e) {
throw new APIMgtDAOException("Error retrieving functions of user: " + userName, e);
}
return functions;
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method addApplicationKeys.
@Override
public void addApplicationKeys(String appId, String keyType, String consumerKey) throws APIMgtDAOException {
final String addApplicationKeysQuery = "INSERT INTO AM_APP_KEY_MAPPING (APPLICATION_ID, CLIENT_ID, KEY_TYPE) " + "VALUES (?, ?, ?)";
try (Connection conn = DAOUtil.getConnection()) {
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(addApplicationKeysQuery)) {
ps.setString(1, appId);
ps.setString(2, consumerKey);
ps.setString(3, keyType);
ps.executeUpdate();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding application keys(appId: " + appId + ")", ex);
} finally {
conn.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding application keys(appId: " + appId + ")", ex);
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method updateApplicationState.
@Override
public void updateApplicationState(String appID, String state) throws APIMgtDAOException {
final String updateAppQuery = "UPDATE AM_APPLICATION SET APPLICATION_STATUS=?, LAST_UPDATED_TIME=? " + "WHERE UUID = ?";
try (Connection conn = DAOUtil.getConnection()) {
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(updateAppQuery)) {
ps.setString(1, state);
ps.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now()));
ps.setString(3, appID);
ps.executeUpdate();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application state(appId: " + appID + ", state: " + state + ")", ex);
} finally {
conn.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application state(appId: " + appID + ", state: " + state + ")", ex);
}
}
Aggregations