@@ -105,6 +105,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
105105 protected SearchBuilder <VMInstanceVO > VmsNotInClusterUsingPool ;
106106 protected SearchBuilder <VMInstanceVO > IdsPowerStateSelectSearch ;
107107 GenericSearchBuilder <VMInstanceVO , Integer > CountByOfferingId ;
108+ GenericSearchBuilder <VMInstanceVO , Integer > CountUserVmNotInDomain ;
108109
109110 @ Inject
110111 ResourceTagDao tagsDao ;
@@ -350,6 +351,13 @@ protected void init() {
350351 CountByOfferingId .select (null , Func .COUNT , CountByOfferingId .entity ().getId ());
351352 CountByOfferingId .and ("serviceOfferingId" , CountByOfferingId .entity ().getServiceOfferingId (), Op .EQ );
352353 CountByOfferingId .done ();
354+
355+ CountUserVmNotInDomain = createSearchBuilder (Integer .class );
356+ CountUserVmNotInDomain .select (null , Func .COUNT , CountUserVmNotInDomain .entity ().getId ());
357+ CountUserVmNotInDomain .and ("serviceOfferingId" , CountUserVmNotInDomain .entity ().getServiceOfferingId (), Op .EQ );
358+ CountUserVmNotInDomain .and ("domainIdsNotIn" , CountUserVmNotInDomain .entity ().getDomainId (), Op .NIN );
359+ CountUserVmNotInDomain .done ();
360+
353361 }
354362
355363 @ Override
@@ -1241,4 +1249,16 @@ public int getVmCountByOfferingId(Long serviceOfferingId) {
12411249 List <Integer > count = customSearch (sc , null );
12421250 return count .get (0 );
12431251 }
1252+
1253+ @ Override
1254+ public int getVmCountByOfferingNotInDomain (Long serviceOfferingId , List <Long > domainIds ) {
1255+ if (serviceOfferingId == null || CollectionUtils .isEmpty (domainIds )) {
1256+ return 0 ;
1257+ }
1258+ SearchCriteria <Integer > sc = CountUserVmNotInDomain .create ();
1259+ sc .setParameters ("serviceOfferingId" , serviceOfferingId );
1260+ sc .setParameters ("domainIdsNotIn" , domainIds .toArray ());
1261+ List <Integer > count = customSearch (sc , null );
1262+ return count .get (0 );
1263+ }
12441264}
0 commit comments