Skip to content

Commit 0043540

Browse files
authored
Use join instead of views (apache#8321)
1 parent ffd5972 commit 0043540

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1592
-575
lines changed

api/src/main/java/com/cloud/offering/ServiceOffering.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ enum StorageType {
102102

103103
boolean getDefaultUse();
104104

105-
String getSystemVmType();
105+
String getVmType();
106106

107107
String getDeploymentPlanner();
108108

api/src/main/java/org/apache/cloudstack/acl/RoleService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public interface RoleService {
3838
* Moreover, we will check if the requested role is of 'Admin' type; roles with 'Admin' type should only be visible to 'root admins'.
3939
* Therefore, if a non-'root admin' user tries to search for an 'Admin' role, this method will return null.
4040
*/
41-
Role findRole(Long id, boolean removePrivateRoles);
41+
Role findRole(Long id, boolean ignorePrivateRoles);
42+
43+
List<Role> findRoles(List<Long> ids, boolean ignorePrivateRoles);
4244

4345
Role findRole(Long id);
4446

api/src/main/java/org/apache/cloudstack/api/InternalIdentity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,18 @@
2525

2626
public interface InternalIdentity extends Serializable {
2727
long getId();
28+
29+
/*
30+
Helper method to add conditions in joins where some column name is equal to a string value
31+
*/
32+
default Object setString(String str) {
33+
return null;
34+
}
35+
36+
/*
37+
Helper method to add conditions in joins where some column name is equal to a long value
38+
*/
39+
default Object setLong(Long l) {
40+
return null;
41+
}
2842
}

engine/schema/src/main/java/com/cloud/service/ServiceOfferingVO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public ServiceOfferingVO(ServiceOfferingVO offering) {
194194
limitCpuUse = offering.getLimitCpuUse();
195195
volatileVm = offering.isVolatileVm();
196196
hostTag = offering.getHostTag();
197-
vmType = offering.getSystemVmType();
197+
vmType = offering.getVmType();
198198
systemUse = offering.isSystemUse();
199199
dynamicScalingEnabled = offering.isDynamicScalingEnabled();
200200
diskOfferingStrictness = offering.diskOfferingStrictness;
@@ -278,7 +278,7 @@ public String getHostTag() {
278278
}
279279

280280
@Override
281-
public String getSystemVmType() {
281+
public String getVmType() {
282282
return vmType;
283283
}
284284

engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ public interface RoleDao extends GenericDao<RoleVO, Long> {
3737
Pair<List<RoleVO>, Integer> findAllByRoleType(RoleType type, Long offset, Long limit, boolean showPrivateRole);
3838

3939
Pair<List<RoleVO>, Integer> listAllRoles(Long startIndex, Long limit, boolean showPrivateRole);
40+
41+
List<RoleVO> searchByIds(Long... ids);
4042
}

engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
import org.apache.commons.lang3.StringUtils;
2929
import org.springframework.stereotype.Component;
3030

31+
import java.util.Collections;
3132
import java.util.List;
3233

3334
@Component
3435
public class RoleDaoImpl extends GenericDaoBase<RoleVO, Long> implements RoleDao {
36+
37+
private final SearchBuilder<RoleVO> RoleByIdsSearch;
3538
private final SearchBuilder<RoleVO> RoleByNameSearch;
3639
private final SearchBuilder<RoleVO> RoleByTypeSearch;
3740
private final SearchBuilder<RoleVO> RoleByNameAndTypeSearch;
@@ -40,6 +43,10 @@ public class RoleDaoImpl extends GenericDaoBase<RoleVO, Long> implements RoleDao
4043
public RoleDaoImpl() {
4144
super();
4245

46+
RoleByIdsSearch = createSearchBuilder();
47+
RoleByIdsSearch.and("idIN", RoleByIdsSearch.entity().getId(), SearchCriteria.Op.IN);
48+
RoleByIdsSearch.done();
49+
4350
RoleByNameSearch = createSearchBuilder();
4451
RoleByNameSearch.and("roleName", RoleByNameSearch.entity().getName(), SearchCriteria.Op.LIKE);
4552
RoleByNameSearch.and("isPublicRole", RoleByNameSearch.entity().isPublicRole(), SearchCriteria.Op.EQ);
@@ -116,6 +123,16 @@ public Pair<List<RoleVO>, Integer> listAllRoles(Long startIndex, Long limit, boo
116123
return searchAndCount(sc, new Filter(RoleVO.class, "id", true, startIndex, limit));
117124
}
118125

126+
@Override
127+
public List<RoleVO> searchByIds(Long... ids) {
128+
if (ids == null || ids.length == 0) {
129+
return Collections.emptyList();
130+
}
131+
SearchCriteria<RoleVO> sc = RoleByIdsSearch.create();
132+
sc.setParameters("idIN", ids);
133+
return listBy(sc);
134+
}
135+
119136
public void filterPrivateRolesIfNeeded(SearchCriteria<RoleVO> sc, boolean showPrivateRole) {
120137
if (!showPrivateRole) {
121138
sc.setParameters("isPublicRole", true);

engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public String getName() {
6565
return name;
6666
}
6767

68+
public void setName(String name) {
69+
this.name = name;
70+
}
71+
6872
@Override
6973
public String getValue() {
7074
return value;

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
5151
ImageStoreVO findOneByZoneAndProtocol(long zoneId, String protocol);
5252

5353
List<ImageStoreVO> listImageStoresByZoneIds(Long... zoneIds);
54+
55+
List<ImageStoreVO> listByIds(List<Long> ids);
5456
}

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDaoImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
*/
1919
package org.apache.cloudstack.storage.datastore.db;
2020

21+
import java.util.Collections;
2122
import java.util.List;
2223
import java.util.Map;
2324

2425
import javax.naming.ConfigurationException;
2526

2627
import com.cloud.utils.db.Filter;
28+
import org.apache.commons.collections.CollectionUtils;
2729
import org.springframework.stereotype.Component;
2830

2931
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
@@ -44,6 +46,7 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implem
4446
private SearchBuilder<ImageStoreVO> zoneProtocolSearch;
4547

4648
private SearchBuilder<ImageStoreVO> zonesInSearch;
49+
private SearchBuilder<ImageStoreVO> IdsSearch;
4750

4851
public ImageStoreDaoImpl() {
4952
super();
@@ -62,6 +65,9 @@ public ImageStoreDaoImpl() {
6265
zonesInSearch.and("zonesIn", zonesInSearch.entity().getDcId(), SearchCriteria.Op.IN);
6366
zonesInSearch.done();
6467

68+
IdsSearch = createSearchBuilder();
69+
IdsSearch.and("ids", IdsSearch.entity().getId(), SearchCriteria.Op.IN);
70+
IdsSearch.done();
6571
}
6672
@Override
6773
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@@ -206,4 +212,14 @@ public List<ImageStoreVO> listImageStoresByZoneIds(Long... zoneIds) {
206212
sc.setParametersIfNotNull("zonesIn", zoneIds);
207213
return listBy(sc);
208214
}
215+
216+
@Override
217+
public List<ImageStoreVO> listByIds(List<Long> ids) {
218+
if (CollectionUtils.isEmpty(ids)) {
219+
return Collections.emptyList();
220+
}
221+
SearchCriteria<ImageStoreVO> sc = IdsSearch.create();
222+
sc.setParameters("ids", ids.toArray());
223+
return listBy(sc);
224+
}
209225
}

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2323
import com.cloud.storage.ScopeType;
2424
import com.cloud.storage.StoragePoolStatus;
25+
import com.cloud.utils.Pair;
26+
import com.cloud.utils.db.Filter;
2527
import com.cloud.utils.db.GenericDao;
2628

2729
/**
@@ -139,4 +141,10 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
139141
List<StoragePoolVO> findPoolsByStorageType(String storageType);
140142

141143
List<StoragePoolVO> listStoragePoolsWithActiveVolumesByOfferingId(long offeringid);
144+
145+
Pair<List<Long>, Integer> searchForIdsAndCount(Long storagePoolId, String storagePoolName, Long zoneId,
146+
String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status,
147+
String keyword, Filter searchFilter);
148+
149+
List<StoragePoolVO> listByIds(List<Long> ids);
142150
}

0 commit comments

Comments
 (0)