Skip to content

Commit e285a77

Browse files
author
GutoVeronezi
committed
Undo unnecessary changes
1 parent acec300 commit e285a77

4 files changed

Lines changed: 41 additions & 126 deletions

File tree

engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import javax.inject.Inject;
2727
import javax.naming.ConfigurationException;
2828

29-
import com.cloud.utils.Pair;
3029
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
3130
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
3231
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
@@ -91,76 +90,89 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
9190
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
9291
super.configure(name, params);
9392

94-
Pair<String, SearchCriteria.Op> storeIdEq = new Pair<>(STORE_ID, SearchCriteria.Op.EQ);
95-
Pair<String, SearchCriteria.Op> storeRoleEq = new Pair<>(STORE_ROLE, SearchCriteria.Op.EQ);
96-
Pair<String, SearchCriteria.Op> stateEq = new Pair<>(STATE, SearchCriteria.Op.EQ);
97-
Pair<String, SearchCriteria.Op> stateNeq = new Pair<>(STATE, SearchCriteria.Op.NEQ);
98-
Pair<String, SearchCriteria.Op> stateIn = new Pair<>(STATE, SearchCriteria.Op.IN);
99-
Pair<String, SearchCriteria.Op> refCntNeq = new Pair<>(REF_CNT, SearchCriteria.Op.NEQ);
100-
Pair<String, SearchCriteria.Op> idEq = new Pair<>(ID, SearchCriteria.Op.EQ);
101-
Pair<String, SearchCriteria.Op> updateCountEq = new Pair<>(UPDATED_COUNT, SearchCriteria.Op.EQ);
102-
Pair<String, SearchCriteria.Op> snapshotIdEq = new Pair<>(SNAPSHOT_ID, SearchCriteria.Op.EQ);
103-
Pair<String, SearchCriteria.Op> volumeIdEq = new Pair<>(VOLUME_ID, SearchCriteria.Op.EQ);
104-
Pair<String, SearchCriteria.Op> createdBetween = new Pair<>(CREATED, SearchCriteria.Op.BETWEEN);
105-
93+
// Note that snapshot_store_ref stores snapshots on primary as well as
94+
// those on secondary, so we need to
95+
// use (store_id, store_role) to search
10696
storeSearch = createSearchBuilder();
107-
storeSearch.addAndConditions(storeIdEq, storeRoleEq, stateNeq);
97+
storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
98+
storeSearch.and("store_role", storeSearch.entity().getRole(), SearchCriteria.Op.EQ);
99+
storeSearch.and("state", storeSearch.entity().getState(), SearchCriteria.Op.NEQ);
108100
storeSearch.done();
109101

110102
storeStateSearch = createSearchBuilder();
111-
storeStateSearch.addAndConditions(storeIdEq, stateEq);
103+
storeStateSearch.and("store_id", storeStateSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
104+
storeStateSearch.and("state", storeStateSearch.entity().getState(), SearchCriteria.Op.EQ);
112105
storeStateSearch.done();
113106

114107
destroyedSearch = createSearchBuilder();
115-
destroyedSearch.addAndConditions(storeIdEq, storeRoleEq, stateEq);
108+
destroyedSearch.and("store_id", destroyedSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
109+
destroyedSearch.and("store_role", destroyedSearch.entity().getRole(), SearchCriteria.Op.EQ);
110+
destroyedSearch.and("state", destroyedSearch.entity().getState(), SearchCriteria.Op.EQ);
116111
destroyedSearch.done();
117112

118113
cacheSearch = createSearchBuilder();
119-
cacheSearch.addAndConditions(storeIdEq, storeRoleEq, stateNeq, refCntNeq);
114+
cacheSearch.and("store_id", cacheSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
115+
cacheSearch.and("store_role", cacheSearch.entity().getRole(), SearchCriteria.Op.EQ);
116+
cacheSearch.and("state", cacheSearch.entity().getState(), SearchCriteria.Op.NEQ);
117+
cacheSearch.and("ref_cnt", cacheSearch.entity().getRefCnt(), SearchCriteria.Op.NEQ);
120118
cacheSearch.done();
121119

122-
updateStateSearch = createSearchBuilder();
123-
updateStateSearch.addAndConditions(idEq, stateEq, updateCountEq);
120+
updateStateSearch = this.createSearchBuilder();
121+
updateStateSearch.and("id", updateStateSearch.entity().getId(), SearchCriteria.Op.EQ);
122+
updateStateSearch.and("state", updateStateSearch.entity().getState(), SearchCriteria.Op.EQ);
123+
updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), SearchCriteria.Op.EQ);
124124
updateStateSearch.done();
125125

126126
snapshotSearch = createSearchBuilder();
127-
snapshotSearch.addAndConditions(snapshotIdEq, storeRoleEq, stateEq);
127+
snapshotSearch.and("snapshot_id", snapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
128+
snapshotSearch.and("store_role", snapshotSearch.entity().getRole(), SearchCriteria.Op.EQ);
129+
snapshotSearch.and("state", snapshotSearch.entity().getState(), SearchCriteria.Op.EQ);
128130
snapshotSearch.done();
129131

130132
storeSnapshotSearch = createSearchBuilder();
131-
storeSnapshotSearch.addAndConditions(snapshotIdEq, storeIdEq, storeRoleEq, stateEq);
133+
storeSnapshotSearch.and("snapshot_id", storeSnapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
134+
storeSnapshotSearch.and("store_id", storeSnapshotSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
135+
storeSnapshotSearch.and("store_role", storeSnapshotSearch.entity().getRole(), SearchCriteria.Op.EQ);
136+
storeSnapshotSearch.and("state", storeSnapshotSearch.entity().getState(), SearchCriteria.Op.EQ);
132137
storeSnapshotSearch.done();
133138

134139
snapshotIdSearch = createSearchBuilder();
135-
snapshotIdSearch.addAndConditions(snapshotIdEq);
140+
snapshotIdSearch.and("snapshot_id", snapshotIdSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
136141
snapshotIdSearch.done();
137142

138143
volumeIdSearch = createSearchBuilder();
139-
volumeIdSearch.addAndConditions(volumeIdEq);
144+
volumeIdSearch.and("volume_id", volumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
140145
volumeIdSearch.done();
141146

142147
volumeSearch = createSearchBuilder();
143-
volumeSearch.addAndConditions(volumeIdEq, storeRoleEq, snapshotIdEq);
148+
volumeSearch.and("volume_id", volumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
149+
volumeSearch.and("store_role", volumeSearch.entity().getRole(), SearchCriteria.Op.EQ);
150+
volumeSearch.and("snapshot_id", volumeSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ);
144151
volumeSearch.done();
145152

146153
volumeIdAndStateReadySearch = createSearchBuilder();
147-
volumeIdAndStateReadySearch.addAndConditions(volumeIdEq, stateEq);
154+
volumeIdAndStateReadySearch.and("volume_id", volumeIdAndStateReadySearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
155+
volumeIdAndStateReadySearch.and("state", volumeIdAndStateReadySearch.entity().getState(), SearchCriteria.Op.EQ);
148156
volumeIdAndStateReadySearch.done();
149157

150158
stateSearch = createSearchBuilder();
151-
stateSearch.addAndConditions(stateIn);
159+
stateSearch.and("state", stateSearch.entity().getState(), SearchCriteria.Op.IN);
152160
stateSearch.done();
153161

154162
parentSnapshotSearch = createSearchBuilder();
155-
parentSnapshotSearch.addAndConditions(volumeIdEq, storeIdEq, storeRoleEq, stateEq);
163+
parentSnapshotSearch.and("volume_id", parentSnapshotSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
164+
parentSnapshotSearch.and("store_id", parentSnapshotSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
165+
parentSnapshotSearch.and("store_role", parentSnapshotSearch.entity().getRole(), SearchCriteria.Op.EQ);
166+
parentSnapshotSearch.and("state", parentSnapshotSearch.entity().getState(), SearchCriteria.Op.EQ);
156167
parentSnapshotSearch.done();
157168

158169
snapshotVOSearch = snapshotDao.createSearchBuilder();
159-
snapshotVOSearch.addAndConditions(volumeIdEq);
170+
snapshotVOSearch.and("volume_id", snapshotVOSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
160171
snapshotVOSearch.done();
161172

162173
snapshotCreatedSearch = createSearchBuilder();
163-
snapshotCreatedSearch.addAndConditions(storeIdEq, createdBetween);
174+
snapshotCreatedSearch.and("store_id", snapshotCreatedSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
175+
snapshotCreatedSearch.and("created", snapshotCreatedSearch.entity().getCreated(), SearchCriteria.Op.BETWEEN);
164176
snapshotCreatedSearch.done();
165177

166178
return true;

framework/db/src/main/java/com/cloud/utils/db/GenericSearchBuilder.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
import java.util.UUID;
2020

21-
import com.cloud.utils.Pair;
2221
import com.cloud.utils.db.SearchCriteria.Op;
23-
import org.apache.commons.lang3.ArrayUtils;
2422

2523
/**
2624
* GenericSearchBuilder is used to build a search based on a VO object. It
@@ -70,41 +68,6 @@ protected GenericSearchBuilder(Class<T> entityType, Class<K> resultType) {
7068
super(entityType, resultType);
7169
}
7270

73-
/**
74-
* Constructor used only for testing.
75-
*/
76-
protected GenericSearchBuilder() {
77-
super();
78-
}
79-
80-
/**
81-
* Adds n AND conditions according to the pairs of string and operation passed as parameter.
82-
*/
83-
public GenericSearchBuilder<T, K> addAndConditions(Pair<String, Op>... fieldsAndOperations) {
84-
if (ArrayUtils.isNotEmpty(fieldsAndOperations)) {
85-
for (Pair<String, SearchCriteria.Op> fieldsAndOperation : fieldsAndOperations) {
86-
if (fieldsAndOperation == null) {
87-
continue;
88-
}
89-
90-
this.and(fieldsAndOperation.first(), fieldsAndOperation.second());
91-
}
92-
}
93-
return this;
94-
}
95-
96-
/**
97-
* Adds an AND condition to the SearchBuilder.<br/><br/>
98-
* Facade to {@link GenericSearchBuilder#and(String, Object, Op)} without passing the second parameter due to it is not used in the method.
99-
*
100-
* @param name param name you will use later to set the values in this search condition.
101-
* @param op operation to apply to the field.
102-
* @return this
103-
*/
104-
public GenericSearchBuilder<T, K> and(String name, Op op) {
105-
return and(name, null, op);
106-
}
107-
10871
/**
10972
* Adds an AND condition to the SearchBuilder.
11073
*

framework/db/src/main/java/com/cloud/utils/db/SearchBase.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ public abstract class SearchBase<J extends SearchBase<?, T, K>, T, K> {
6666
protected SelectType _selectType;
6767
T _entity;
6868

69-
/**
70-
* Constructor used only for testing.
71-
*/
72-
protected SearchBase() {
73-
}
74-
7569
SearchBase(final Class<T> entityType, final Class<K> resultType) {
7670
init(entityType, resultType);
7771
}

framework/db/src/test/java/com/cloud/utils/db/GenericSearchBuilderTest.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)