Skip to content
Merged
Show file tree
Hide file tree
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 @@ -165,7 +165,6 @@ public void init() {

HostTypeCountSearch = createSearchBuilder();
HostTypeCountSearch.and("type", HostTypeCountSearch.entity().getType(), SearchCriteria.Op.EQ);
HostTypeCountSearch.and("removed", HostTypeCountSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
HostTypeCountSearch.done();

HostTypeZoneCountSearch = createSearchBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Integer countByGroup(long vmGroupId) {

SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
return getCount(sc);
return getCountIncludingRemoved(sc);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public List<DomainRouterVO> listByDataCenter(final long dcId) {
public Integer countAllByRole(final Role role) {
final SearchCriteria<DomainRouterVO> sc = createSearchCriteria();
sc.addAnd("role", SearchCriteria.Op.EQ, role);
sc.addAnd("removed", Op.NULL);
return getCount(sc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public List<ImageStoreVO> findImageCacheByScope(ZoneScope scope) {
public Integer countAllImageStores() {
SearchCriteria<ImageStoreVO> sc = createSearchCriteria();
sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.Image);
sc.addAnd("removed", SearchCriteria.Op.NULL);
return getCount(sc);
}

Expand Down
65 changes: 34 additions & 31 deletions framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,13 @@ public T lockOneRandomRow(final SearchCriteria<T> sc, final boolean exclusive) {

@DB()
protected List<T> search(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache) {
if (_removed != null) {
if (sc == null) {
sc = createSearchCriteria();
}
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
}
sc = checkAndSetRemovedIsNull(sc);
return searchIncludingRemoved(sc, filter, lock, cache);
}

@DB()
protected List<T> search(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache, final boolean enableQueryCache) {
if (_removed != null) {
if (sc == null) {
sc = createSearchCriteria();
}
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
}
sc = checkAndSetRemovedIsNull(sc);
return searchIncludingRemoved(sc, filter, lock, cache, enableQueryCache);
}

Expand Down Expand Up @@ -519,7 +509,6 @@ public <M> List<M> customSearch(SearchCriteria<M> sc, final Filter filter) {
if (_removed != null) {
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

can use checkAndSetRemovedIsNull() here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes it a bit difficult since it is of a different type M not T

Copy link
Contributor

Choose a reason for hiding this comment

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

}

return customSearchIncludingRemoved(sc, filter);
}

Expand Down Expand Up @@ -911,26 +900,20 @@ protected T findOneIncludingRemovedBy(final SearchCriteria<T> sc) {

@Override
@DB()
public T findOneBy(final SearchCriteria<T> sc) {
if (_removed != null) {
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
}
public T findOneBy(SearchCriteria<T> sc) {
sc = checkAndSetRemovedIsNull(sc);
return findOneIncludingRemovedBy(sc);
}

@DB()
protected List<T> listBy(final SearchCriteria<T> sc, final Filter filter) {
if (_removed != null) {
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
}
protected List<T> listBy(SearchCriteria<T> sc, final Filter filter) {
sc = checkAndSetRemovedIsNull(sc);
return listIncludingRemovedBy(sc, filter);
}

@DB()
protected List<T> listBy(final SearchCriteria<T> sc, final Filter filter, final boolean enableQueryCache) {
if (_removed != null) {
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
}
protected List<T> listBy(SearchCriteria<T> sc, final Filter filter, final boolean enableQueryCache) {
sc = checkAndSetRemovedIsNull(sc);
return listIncludingRemovedBy(sc, filter, enableQueryCache);
}

Expand Down Expand Up @@ -1935,7 +1918,22 @@ public SearchCriteria<T> createSearchCriteria() {
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) {
sc = checkAndSetRemovedIsNull(sc);
return getDistinctCountIncludingRemoved(sc);
}

public Integer getDistinctCountIncludingRemoved(SearchCriteria<T> sc) {
String clause = sc != null ? sc.getWhereClause() : null;
if (clause != null && clause.length() == 0) {
clause = null;
Expand Down Expand Up @@ -1994,6 +1992,11 @@ public Integer getDistinctCount(SearchCriteria<T> sc) {
}

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;
if (Strings.isNullOrEmpty(clause)) {
clause = null;
Expand Down Expand Up @@ -2040,15 +2043,15 @@ public Integer getDistinctCount(SearchCriteria<T> sc, String[] distinctColumns)
}

public Integer countAll() {
SearchCriteria<T> sc = null;
if (_removed != null) {
sc = createSearchCriteria();
sc.addAnd(_removed.second().field.getName(), SearchCriteria.Op.NULL);
}
return getCount(sc);
return getCount(null);
}

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;
if (clause != null && clause.length() == 0) {
clause = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public List<TemplateJoinVO> listActiveTemplates(long storeId) {
@Override
public Pair<List<TemplateJoinVO>, Integer> searchIncludingRemovedAndCount(final SearchCriteria<TemplateJoinVO> sc, final Filter filter) {
List<TemplateJoinVO> objects = searchIncludingRemoved(sc, filter, null, false);
Integer count = getCount(sc);
Integer count = getCountIncludingRemoved(sc);
return new Pair<List<TemplateJoinVO>, Integer>(objects, count);
}

Expand Down