use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiDAOImpl method getDedicatedGateway.
/**
* @see ApiDAO#getDedicatedGateway(String)
*/
@Override
public DedicatedGateway getDedicatedGateway(String apiId) throws APIMgtDAOException {
final String query = "SELECT HAS_OWN_GATEWAY FROM AM_API WHERE UUID = ?";
DedicatedGateway dedicatedGateway;
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
statement.setString(1, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(rs.getBoolean(ContainerBasedGatewayConstants.IS_DEDICATED_GATEWAY_ENABLED));
return dedicatedGateway;
} else {
throw new APIMgtDAOException("Couldn't Find Dedicated Gateway details ", ExceptionCodes.DEDICATED_GATEWAY_DETAILS_NOT_FOUND);
}
}
} catch (SQLException e) {
String errorMessage = "Error while retrieving dedicated gateway details of API : " + apiId;
throw new APIMgtDAOException(errorMessage, e);
}
} catch (SQLException e) {
String message = "Error while creating database connection/prepared-statement";
throw new APIMgtDAOException(message, e);
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiDAOImpl method isAPIVersionsExist.
@Override
public boolean isAPIVersionsExist(String apiName) throws APIMgtDAOException {
final String query = "SELECT COUNT (NAME) FROM AM_API WHERE NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiName);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next() && rs.getInt(1) > 1) {
return true;
} else {
return false;
}
}
} catch (SQLException e) {
String errorMessage = "getting existence of versioned API: " + apiName;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiDAOImpl method getCompositeAPIs.
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<CompositeAPI> getCompositeAPIs(Set<String> roles, String user, int offset, int limit) throws APIMgtDAOException {
// TODO: 6/5/17 Implement pagination support when implementing pagination support for
// other list operations.
final String query = COMPOSITE_API_SUMMARY_SELECT + " WHERE API_TYPE_ID = " + "(SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?) AND PROVIDER = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, ApiType.COMPOSITE.toString());
statement.setString(2, user);
return getCompositeAPISummaryList(connection, statement);
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Composite APIs", e);
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiDAOImpl method getAPIsByStatus.
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<API> getAPIsByStatus(List<String> gatewayLabels, String status) throws APIMgtDAOException {
final String query = "SELECT DISTINCT UUID, PROVIDER, A.NAME, CONTEXT, VERSION, DESCRIPTION, CURRENT_LC_STATUS," + " LIFECYCLE_INSTANCE_ID, LC_WORKFLOW_STATUS, SECURITY_SCHEME FROM AM_API A INNER JOIN " + " AM_API_LABEL_MAPPING M ON A.UUID" + " = M.API_ID INNER JOIN AM_LABELS L ON L.LABEL_ID = M.LABEL_ID WHERE L.TYPE_NAME='GATEWAY' " + "AND L.NAME" + " " + "IN" + " " + "(" + DAOUtil.getParameterString(gatewayLabels.size()) + ") AND A" + ".CURRENT_LC_STATUS=?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
int i = 0;
for (String label : gatewayLabels) {
statement.setString(++i, label);
}
statement.setString(++i, status);
return constructAPISummaryList(connection, statement);
} catch (SQLException e) {
String msg = "getting APIs for given gateway labels: " + gatewayLabels.toString() + " with status: " + status;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
}
}
use of org.wso2.carbon.apimgt.core.exception.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiDAOImpl method deleteComment.
@Override
public void deleteComment(String commentId, String apiId) throws APIMgtDAOException {
final String deleteCommentQuery = "DELETE FROM AM_API_COMMENTS WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(deleteCommentQuery)) {
try {
connection.setAutoCommit(false);
statement.setString(1, commentId);
statement.setString(2, apiId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
Aggregations