mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fixing searchAndCount searchAndDistinctCount when sc is null (#4374)
This commit is contained in:
parent
1bbb29d034
commit
aab8df09aa
@ -165,7 +165,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||||||
|
|
||||||
HostTypeCountSearch = createSearchBuilder();
|
HostTypeCountSearch = createSearchBuilder();
|
||||||
HostTypeCountSearch.and("type", HostTypeCountSearch.entity().getType(), SearchCriteria.Op.EQ);
|
HostTypeCountSearch.and("type", HostTypeCountSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||||
HostTypeCountSearch.and("removed", HostTypeCountSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
|
|
||||||
HostTypeCountSearch.done();
|
HostTypeCountSearch.done();
|
||||||
|
|
||||||
HostTypeZoneCountSearch = createSearchBuilder();
|
HostTypeZoneCountSearch = createSearchBuilder();
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public class AutoScaleVmGroupVmMapDaoImpl extends GenericDaoBase<AutoScaleVmGrou
|
|||||||
|
|
||||||
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
|
||||||
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
|
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
|
||||||
return getCount(sc);
|
return getCountIncludingRemoved(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -189,7 +189,6 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
|||||||
public Integer countAllByRole(final Role role) {
|
public Integer countAllByRole(final Role role) {
|
||||||
final SearchCriteria<DomainRouterVO> sc = createSearchCriteria();
|
final SearchCriteria<DomainRouterVO> sc = createSearchCriteria();
|
||||||
sc.addAnd("role", SearchCriteria.Op.EQ, role);
|
sc.addAnd("role", SearchCriteria.Op.EQ, role);
|
||||||
sc.addAnd("removed", Op.NULL);
|
|
||||||
return getCount(sc);
|
return getCount(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -117,7 +117,6 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
|
|||||||
public Integer countAllImageStores() {
|
public Integer countAllImageStores() {
|
||||||
SearchCriteria<ImageStoreVO> sc = createSearchCriteria();
|
SearchCriteria<ImageStoreVO> sc = createSearchCriteria();
|
||||||
sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.Image);
|
sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.Image);
|
||||||
sc.addAnd("removed", SearchCriteria.Op.NULL);
|
|
||||||
return getCount(sc);
|
return getCount(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -344,23 +344,13 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||||||
|
|
||||||
@DB()
|
@DB()
|
||||||
protected List<T> search(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache) {
|
protected List<T> search(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache) {
|
||||||
if (_removed != null) {
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
if (sc == null) {
|
|
||||||
sc = createSearchCriteria();
|
|
||||||
}
|
|
||||||
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
|
||||||
}
|
|
||||||
return searchIncludingRemoved(sc, filter, lock, cache);
|
return searchIncludingRemoved(sc, filter, lock, cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB()
|
@DB()
|
||||||
protected List<T> search(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache, final boolean enableQueryCache) {
|
protected List<T> search(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache, final boolean enableQueryCache) {
|
||||||
if (_removed != null) {
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
if (sc == null) {
|
|
||||||
sc = createSearchCriteria();
|
|
||||||
}
|
|
||||||
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
|
||||||
}
|
|
||||||
return searchIncludingRemoved(sc, filter, lock, cache, enableQueryCache);
|
return searchIncludingRemoved(sc, filter, lock, cache, enableQueryCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,7 +509,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||||||
if (_removed != null) {
|
if (_removed != null) {
|
||||||
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return customSearchIncludingRemoved(sc, filter);
|
return customSearchIncludingRemoved(sc, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -911,26 +900,20 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DB()
|
@DB()
|
||||||
public T findOneBy(final SearchCriteria<T> sc) {
|
public T findOneBy(SearchCriteria<T> sc) {
|
||||||
if (_removed != null) {
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
|
||||||
}
|
|
||||||
return findOneIncludingRemovedBy(sc);
|
return findOneIncludingRemovedBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB()
|
@DB()
|
||||||
protected List<T> listBy(final SearchCriteria<T> sc, final Filter filter) {
|
protected List<T> listBy(SearchCriteria<T> sc, final Filter filter) {
|
||||||
if (_removed != null) {
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
|
||||||
}
|
|
||||||
return listIncludingRemovedBy(sc, filter);
|
return listIncludingRemovedBy(sc, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DB()
|
@DB()
|
||||||
protected List<T> listBy(final SearchCriteria<T> sc, final Filter filter, final boolean enableQueryCache) {
|
protected List<T> listBy(SearchCriteria<T> sc, final Filter filter, final boolean enableQueryCache) {
|
||||||
if (_removed != null) {
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
|
||||||
}
|
|
||||||
return listIncludingRemovedBy(sc, filter, enableQueryCache);
|
return listIncludingRemovedBy(sc, filter, enableQueryCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1935,7 +1918,22 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SearchCriteria<T> checkAndSetRemovedIsNull(SearchCriteria<T> sc) {
|
||||||
|
if (_removed != null) {
|
||||||
|
if (sc == null) {
|
||||||
|
sc = createSearchCriteria();
|
||||||
|
}
|
||||||
|
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
||||||
|
}
|
||||||
|
return sc;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getDistinctCount(SearchCriteria<T> sc) {
|
public Integer getDistinctCount(SearchCriteria<T> sc) {
|
||||||
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
|
return getDistinctCountIncludingRemoved(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDistinctCountIncludingRemoved(SearchCriteria<T> sc) {
|
||||||
String clause = sc != null ? sc.getWhereClause() : null;
|
String clause = sc != null ? sc.getWhereClause() : null;
|
||||||
if (clause != null && clause.length() == 0) {
|
if (clause != null && clause.length() == 0) {
|
||||||
clause = null;
|
clause = null;
|
||||||
@ -1994,6 +1992,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDistinctCount(SearchCriteria<T> sc, String[] distinctColumns) {
|
public Integer getDistinctCount(SearchCriteria<T> sc, String[] distinctColumns) {
|
||||||
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
|
return getDistinctCountIncludingRemoved(sc, distinctColumns);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDistinctCountIncludingRemoved(SearchCriteria<T> sc, String[] distinctColumns) {
|
||||||
String clause = sc != null ? sc.getWhereClause() : null;
|
String clause = sc != null ? sc.getWhereClause() : null;
|
||||||
if (Strings.isNullOrEmpty(clause)) {
|
if (Strings.isNullOrEmpty(clause)) {
|
||||||
clause = null;
|
clause = null;
|
||||||
@ -2040,15 +2043,15 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer countAll() {
|
public Integer countAll() {
|
||||||
SearchCriteria<T> sc = null;
|
return getCount(null);
|
||||||
if (_removed != null) {
|
|
||||||
sc = createSearchCriteria();
|
|
||||||
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
|
|
||||||
}
|
|
||||||
return getCount(sc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getCount(SearchCriteria<T> sc) {
|
public Integer getCount(SearchCriteria<T> sc) {
|
||||||
|
sc = checkAndSetRemovedIsNull(sc);
|
||||||
|
return getCountIncludingRemoved(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCountIncludingRemoved(SearchCriteria<T> sc) {
|
||||||
String clause = sc != null ? sc.getWhereClause() : null;
|
String clause = sc != null ? sc.getWhereClause() : null;
|
||||||
if (clause != null && clause.length() == 0) {
|
if (clause != null && clause.length() == 0) {
|
||||||
clause = null;
|
clause = null;
|
||||||
|
|||||||
@ -503,7 +503,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBaseWithTagInformation<Templa
|
|||||||
@Override
|
@Override
|
||||||
public Pair<List<TemplateJoinVO>, Integer> searchIncludingRemovedAndCount(final SearchCriteria<TemplateJoinVO> sc, final Filter filter) {
|
public Pair<List<TemplateJoinVO>, Integer> searchIncludingRemovedAndCount(final SearchCriteria<TemplateJoinVO> sc, final Filter filter) {
|
||||||
List<TemplateJoinVO> objects = searchIncludingRemoved(sc, filter, null, false);
|
List<TemplateJoinVO> objects = searchIncludingRemoved(sc, filter, null, false);
|
||||||
Integer count = getCount(sc);
|
Integer count = getCountIncludingRemoved(sc);
|
||||||
return new Pair<List<TemplateJoinVO>, Integer>(objects, count);
|
return new Pair<List<TemplateJoinVO>, Integer>(objects, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user