Source:
<code>public VirtConsumerMap getGuestConsumersMap(Owner owner, Set<String> guestIds) { VirtConsumerMap guestConsumersMap = new VirtConsumerMap(); if (guestIds.size() == 0) { return guestConsumersMap; } List<String> possibleGuestIds = Util.getPossibleUuids(guestIds.toArray( new String [guestIds.size()])); String sql = "select cp_consumer.uuid from cp_consumer " + "inner join cp_consumer_facts " + "on cp_consumer.id = cp_consumer_facts.cp_consumer_id " + "where cp_consumer_facts.mapkey = 'virt.uuid' and " + "lower(cp_consumer_facts.element) in (:guestids) " + "and cp_consumer.owner_id = :ownerid " + "order by cp_consumer.updated desc"; Query q = currentSession().createSQLQuery(sql); List<String> consumerUuids = new ArrayList<String>(); int fromIndex = 0; int toIndex = fromIndex + MAX_IN_QUERY_LENGTH; <START> int count = 0; <END> while (fromIndex < possibleGuestIds.size()) { if (toIndex > possibleGuestIds.size()) { toIndex = possibleGuestIds.size(); } List<String> subList = possibleGuestIds.subList(fromIndex, toIndex); q.setParameterList("guestids", subList); q.setParameter("ownerid", owner.getId()); consumerUuids.addAll(q.list()); fromIndex = toIndex; toIndex += MAX_IN_QUERY_LENGTH; } if (consumerUuids == null || consumerUuids.size() == 0) { return guestConsumersMap; } List<Consumer> guestConsumersWithDupes = findByUuidsAndOwner(consumerUuids, owner); for (Consumer c : guestConsumersWithDupes) { String virtUuid = c.getFact("virt.uuid").toLowerCase(); if (guestConsumersMap.get(virtUuid) == null) { guestConsumersMap.add(virtUuid, c); } } return guestConsumersMap; }</code><technical_language>count is unused now. good otherwise</technical_language>

Target:
public VirtConsumerMap getGuestConsumersMap(Owner owner, Set<String> guestIds) { VirtConsumerMap guestConsumersMap = new VirtConsumerMap(); if (guestIds.size() == 0) { return guestConsumersMap; } List<String> possibleGuestIds = Util.getPossibleUuids(guestIds.toArray( new String [guestIds.size()])); String sql = "select cp_consumer.uuid from cp_consumer " + "inner join cp_consumer_facts " + "on cp_consumer.id = cp_consumer_facts.cp_consumer_id " + "where cp_consumer_facts.mapkey = 'virt.uuid' and " + "lower(cp_consumer_facts.element) in (:guestids) " + "and cp_consumer.owner_id = :ownerid " + "order by cp_consumer.updated desc"; Query q = currentSession().createSQLQuery(sql); List<String> consumerUuids = new ArrayList<String>(); int fromIndex = 0; int toIndex = fromIndex + MAX_IN_QUERY_LENGTH; while (fromIndex < possibleGuestIds.size()) { if (toIndex > possibleGuestIds.size()) { toIndex = possibleGuestIds.size(); } List<String> subList = possibleGuestIds.subList(fromIndex, toIndex); q.setParameterList("guestids", subList); q.setParameter("ownerid", owner.getId()); consumerUuids.addAll(q.list()); fromIndex = toIndex; toIndex += MAX_IN_QUERY_LENGTH; } if (consumerUuids == null || consumerUuids.size() == 0) { return guestConsumersMap; } List<Consumer> guestConsumersWithDupes = findByUuidsAndOwner(consumerUuids, owner); for (Consumer c : guestConsumersWithDupes) { String virtUuid = c.getFact("virt.uuid").toLowerCase(); if (guestConsumersMap.get(virtUuid) == null) { guestConsumersMap.add(virtUuid, c); } } return guestConsumersMap; }