use of org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_ID in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method deleteFileById.
@Override
public void deleteFileById(String resourceType, String resourceName, String fileId) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
boolean isOracleOrMssql = isOracleDB() || isMSSqlDB();
jdbcTemplate.withTransaction(template -> {
// Get resource id for the deleting file.
String sqlStmt = isH2DB() ? SQLConstants.GET_FILE_BY_ID_SQL_H2 : SQLConstants.GET_FILE_BY_ID_SQL;
String resourceId = template.fetchSingleRecord(sqlStmt, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_ID), preparedStatement -> {
preparedStatement.setString(1, fileId);
preparedStatement.setString(2, resourceName);
preparedStatement.setString(3, resourceType);
});
template.executeUpdate(DELETE_FILE_SQL, (preparedStatement -> preparedStatement.setString(1, fileId)));
List<String> availableFilesForTheResource = template.executeQuery(GET_FILES_BY_RESOURCE_ID_SQL, ((resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)), preparedStatement -> preparedStatement.setString(1, resourceId));
if (availableFilesForTheResource.isEmpty()) {
template.executeUpdate(UPDATE_HAS_FILE_SQL, preparedStatement -> {
if (isOracleOrMssql) {
preparedStatement.setInt(1, 0);
} else {
preparedStatement.setBoolean(1, false);
}
preparedStatement.setString(2, resourceId);
});
}
updateResourceLastModified(template, resourceId);
return null;
});
} catch (TransactionException e) {
throw handleServerException(ERROR_CODE_DELETE_FILE, fileId, e);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
}
}
Aggregations