use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class FunctionDAOImpl method deleteEventFunctionMapping.
/**
* {@inheritDoc}
*/
@Override
public void deleteEventFunctionMapping(String userName, Event event, String functionName) throws APIMgtDAOException {
if (userName == null) {
throw new IllegalArgumentException("Username must not be null");
}
if (event == null) {
throw new IllegalArgumentException("Event must not be null");
}
if (functionName == null) {
throw new IllegalArgumentException("Function name must not be null");
}
final String sqlQuery = "DELETE FROM AM_EVENT_FUNCTION_MAPPING " + "WHERE EVENT = ? AND FUNCTION_ID = " + "(SELECT FUNCTION_ID " + "FROM AM_LAMBDA_FUNCTION " + "WHERE USER_NAME = ? AND FUNCTION_NAME = ?)";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
preparedStatement.setString(1, event.getEventAsString());
preparedStatement.setString(2, userName);
preparedStatement.setString(3, functionName);
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new APIMgtDAOException("Error deleting event function mapping -event: " + event + " -function: " + functionName + " -user: " + userName, e);
}
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class FunctionDAOImpl method getTriggersForUserFunction.
/**
* {@inheritDoc}
*/
@Override
public List<Event> getTriggersForUserFunction(String userName, String functionName) throws APIMgtDAOException {
if (userName == null) {
throw new IllegalArgumentException("Username must not be null");
}
if (functionName == null) {
throw new IllegalArgumentException("Function name must not be null");
}
List<Event> events = new ArrayList<>();
final String sqlQuery = "SELECT EVENT " + "FROM AM_LAMBDA_FUNCTION JOIN AM_EVENT_FUNCTION_MAPPING " + "ON AM_LAMBDA_FUNCTION.FUNCTION_ID = AM_EVENT_FUNCTION_MAPPING.FUNCTION_ID " + "WHERE USER_NAME = ? AND FUNCTION_NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
preparedStatement.setString(1, userName);
preparedStatement.setString(2, functionName);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
events.add(Event.valueOf(resultSet.getString("EVENT")));
}
}
} catch (SQLException e) {
throw new APIMgtDAOException("Error retrieving triggers for function: " + functionName + " of user: " + userName, e);
}
return events;
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method updateApplication.
/**
* Update an existing Application
*
* @param appID The UUID of the Application that needs to be updated
* @param updatedApp Substitute {@link Application} object that will replace the existing Application
* @throws APIMgtDAOException If failed to update applications.
*/
@Override
public void updateApplication(String appID, Application updatedApp) throws APIMgtDAOException {
final String updateAppQuery = "UPDATE AM_APPLICATION SET NAME=?, APPLICATION_POLICY_ID=" + "?, DESCRIPTION=?, APPLICATION_STATUS=?, UPDATED_BY=?, LAST_UPDATED_TIME=? WHERE UUID=?";
try (Connection conn = DAOUtil.getConnection()) {
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(updateAppQuery)) {
ps.setString(1, updatedApp.getName());
ps.setString(2, updatedApp.getPolicy().getUuid());
ps.setString(3, updatedApp.getDescription());
ps.setString(4, updatedApp.getStatus());
ps.setString(5, updatedApp.getUpdatedUser());
ps.setTimestamp(6, Timestamp.valueOf(updatedApp.getUpdatedTime()));
ps.setString(7, appID);
ps.executeUpdate();
updateApplicationPermission(conn, updatedApp.getPermissionMap(), updatedApp.getId());
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application: " + appID, ex);
} finally {
conn.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating application: " + appID, ex);
}
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method deleteApplication.
/**
* Remove an existing Application
*
* @param appID The UUID of the Application that needs to be deleted
* @throws APIMgtDAOException If failed to delete application.
*/
@Override
public void deleteApplication(String appID) throws APIMgtDAOException {
final String appDeleteQuery = "DELETE FROM AM_APPLICATION WHERE UUID = ?";
try (Connection conn = DAOUtil.getConnection()) {
boolean originalAutoCommitState = conn.getAutoCommit();
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(appDeleteQuery)) {
ps.setString(1, appID);
ps.execute();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting application: " + appID, ex);
} finally {
conn.setAutoCommit(originalAutoCommitState);
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting application: " + appID, ex);
}
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class DAOFactory method getAPISubscriptionDAO.
public static APISubscriptionDAO getAPISubscriptionDAO() throws APIMgtDAOException {
APISubscriptionDAO apiSubscriptionDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else if (driverName.contains(POSTGRE)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else if (driverName.contains(ORACLE)) {
apiSubscriptionDAO = new APISubscriptionDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting APISubscriptionDAO", e);
}
setup();
return apiSubscriptionDAO;
}
Aggregations