@@ -56,6 +56,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
5656 protected SearchBuilder <IPAddressVO > VlanDbIdSearchUnallocated ;
5757 protected GenericSearchBuilder <IPAddressVO , Integer > AllIpCount ;
5858 protected GenericSearchBuilder <IPAddressVO , Integer > AllocatedIpCount ;
59+ protected GenericSearchBuilder <IPAddressVO , Integer > AllocatedIpCountForDc ;
5960 protected GenericSearchBuilder <IPAddressVO , Integer > AllIpCountForDashboard ;
6061 protected SearchBuilder <IPAddressVO > DeleteAllExceptGivenIp ;
6162 protected GenericSearchBuilder <IPAddressVO , Long > AllocatedIpCountForAccount ;
@@ -107,6 +108,12 @@ public void init() {
107108 AllocatedIpCount .and ("allocated" , AllocatedIpCount .entity ().getAllocatedTime (), Op .NNULL );
108109 AllocatedIpCount .done ();
109110
111+ AllocatedIpCountForDc = createSearchBuilder (Integer .class );
112+ AllocatedIpCountForDc .select (null , Func .COUNT , AllocatedIpCountForDc .entity ().getAddress ());
113+ AllocatedIpCountForDc .and ("dc" , AllocatedIpCountForDc .entity ().getDataCenterId (), Op .EQ );
114+ AllocatedIpCountForDc .and ("allocated" , AllocatedIpCountForDc .entity ().getAllocatedTime (), Op .NNULL );
115+ AllocatedIpCountForDc .done ();
116+
110117 AllIpCountForDashboard = createSearchBuilder (Integer .class );
111118 AllIpCountForDashboard .select (null , Func .COUNT , AllIpCountForDashboard .entity ().getAddress ());
112119 AllIpCountForDashboard .and ("dc" , AllIpCountForDashboard .entity ().getDataCenterId (), Op .EQ );
@@ -281,6 +288,14 @@ public IPAddressVO findByVmIp(String vmIp) {
281288 return findOneBy (sc );
282289 }
283290
291+ @ Override
292+ public int countIPs (long dcId , boolean onlyCountAllocated ) {
293+ SearchCriteria <Integer > sc = onlyCountAllocated ? AllocatedIpCount .create () : AllIpCount .create ();
294+ sc .setParameters ("dc" , dcId );
295+
296+ return customSearch (sc , null ).get (0 );
297+ }
298+
284299 @ Override
285300 public int countIPs (long dcId , long vlanId , boolean onlyCountAllocated ) {
286301 SearchCriteria <Integer > sc = onlyCountAllocated ? AllocatedIpCount .create () : AllIpCount .create ();
0 commit comments