Github user alexandrelimassantana commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1516#discussion_r60852850
  
    --- Diff: engine/schema/src/com/cloud/capacity/dao/CapacityDaoImpl.java ---
    @@ -962,35 +962,59 @@ public boolean removeBy(Short capacityType, Long 
zoneId, Long podId, Long cluste
         }
     
         @Override
    -    public void updateCapacityState(Long dcId, Long podId, Long clusterId, 
Long hostId, String capacityState) {
    +    public void updateCapacityState(Long dcId, Long podId, Long clusterId, 
Long hostId, String capacityState, short[] capacityType) {
             TransactionLegacy txn = TransactionLegacy.currentTxn();
             StringBuilder sql = new StringBuilder(UPDATE_CAPACITY_STATE);
             List<Long> resourceIdList = new ArrayList<Long>();
    +        StringBuilder where = new StringBuilder();
     
             if (dcId != null) {
    -            sql.append(" data_center_id = ?");
    +            where.append(" data_center_id = ? ");
                 resourceIdList.add(dcId);
             }
             if (podId != null) {
    -            sql.append(" pod_id = ?");
    +            where.append((where.length() > 0) ? " and pod_id = ? " : " 
pod_id = ? ");
                 resourceIdList.add(podId);
             }
             if (clusterId != null) {
    -            sql.append(" cluster_id = ?");
    +            where.append((where.length() > 0) ? " and cluster_id = ? " : " 
cluster_id = ? ");
                 resourceIdList.add(clusterId);
             }
             if (hostId != null) {
    -            sql.append(" host_id = ?");
    +            where.append((where.length() > 0) ? " and host_id = ? " : " 
host_id = ? ");
                 resourceIdList.add(hostId);
             }
     
    +        if (capacityType != null && capacityType.length > 0) {
    +            where.append((where.length() > 0) ? " and capacity_type in " : 
" capacity_type in ");
    +
    +            StringBuilder builder = new StringBuilder();
    +            for( int i = 0 ; i < capacityType.length; i++ ) {
    +                if(i==0){
    +                    builder.append(" (? ");
    --- End diff --
    
    You can extract the if(i==0) code from the for and write it before the 
loop. That way you don`t need to check anything inside the loop


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to