diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index aa1757a22b..5ac087b64f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -908,63 +908,37 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } @Override - public List getTagIdsForTagNames(List tagNames, int tenantId) throws ApplicationManagementDAOException { + public List getTagIdsForTagNames(List tagNames, int tenantId) + throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get tag ids for given tag names"); } -// Connection conn; -// PreparedStatement stmt = null; -// ResultSet rs = null; try { Connection conn = this.getDBConnection(); int index = 1; List tagIds = new ArrayList<>(); -// String sql = "SELECT " -// + "AP_APP_TAG.ID AS ID " -// + "FROM AP_APP_TAG " -// + "WHERE AP_APP_TAG..NAME IN ( ? ) AND TENANT_ID = ?"; -// conn = this.getDBConnection(); - - // - StringJoiner joiner = new StringJoiner(",", "SELECT AP_APP_TAG.ID AS ID FROM AP_APP_TAG " - + "WHERE AP_APP_TAG.TAG IN (", ") AND TENANT_ID = ?"); + StringJoiner joiner = new StringJoiner(",", + "SELECT AP_APP_TAG.ID AS ID FROM AP_APP_TAG WHERE AP_APP_TAG.TAG IN (", ") AND TENANT_ID = ?"); tagNames.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) { -// for (int c = 0; c < tagNames.size(); c++) { -// ps.setObject(c + 1, tagNames.get(c)); -// } for (String tagName : tagNames) { ps.setObject(index++, tagName); } ps.setInt(index, tenantId); try (ResultSet rs = ps.executeQuery()) { - while(rs.next()){ + while (rs.next()) { tagIds.add(rs.getInt("ID")); } } } - // -// Array array = conn.createArrayOf("VARCHAR", new List[] { tagNames }); -// -// stmt = conn.prepareStatement(sql); -// stmt.setArray(1, array); -// stmt.setInt(2, tenantId); -// rs = stmt.executeQuery(); -// while(rs.next()){ -// tagIds.add(rs.getInt("ID")); -// } return tagIds; - } - catch (DBConnectionException e) { + } catch (DBConnectionException e) { throw new ApplicationManagementDAOException( "Error occurred while obtaining the DB connection when adding tags", e); } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while adding tags", e); } -// finally { -// Util.cleanupResources(stmt, rs); -// } } public void addTagMapping (List tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException {