Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
+ "GROUP BY host_id "
+ "HAVING tag_count = %s ";
private static final String SEPARATOR = ",";
private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join host_tags on host.id = host_tags.host_id and host_tags.tag = ?";
private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join ( %s ) AS selected_hosts ON host.id = selected_hosts.host_id";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should %s be replaced with ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhtyd It seems, all the tags are part of the sub-query stmt "LIST_HOST_IDS_BY_COMPUTETAGS" and the returned hosts from that sub-query were considered from further filtering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should %s be replaced with ?

@rhtyd
see suresh's comment above.

String sql = this.LIST_CLUSTERID_FOR_HOST_TAG;
PreparedStatement pstmt = null;
List<Long> result = new ArrayList();
List<String> tags = Arrays.asList(computeOfferingTags.split(this.SEPARATOR));
String subselect = getHostIdsByComputeTags(tags);
sql = String.format(sql, subselect);

an example of final sql is (if there are 3 tags)

select distinct cluster_id from host join 
( SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count FROM (SELECT host_id, tag FROM host_tags GROUP BY host_id,tag) AS filtered WHERE tag IN(?,?,?) GROUP BY host_id HAVING tag_count = 3  ) AS selected_hosts 
ON host.id = selected_hosts.host_id;

private static final String GET_HOSTS_OF_ACTIVE_VMS = "select h.id " +
"from vm_instance vm " +
"join host h on (vm.host_id=h.id) " +
Expand Down