5252@ Component
5353public class SnapshotDataStoreDaoImpl extends GenericDaoBase <SnapshotDataStoreVO , Long > implements SnapshotDataStoreDao {
5454 private static final Logger s_logger = Logger .getLogger (SnapshotDataStoreDaoImpl .class );
55+ private static final String STORE_ID = "store_id" ;
56+ private static final String STORE_ROLE = "store_role" ;
57+ private static final String STATE = "state" ;
58+ private static final String REF_CNT = "ref_cnt" ;
59+ private static final String ID = "id" ;
60+ private static final String UPDATED_COUNT = "updatedCount" ;
61+ private static final String SNAPSHOT_ID = "snapshot_id" ;
62+ private static final String VOLUME_ID = "volume_id" ;
63+ private static final String CREATED = "created" ;
5564 private SearchBuilder <SnapshotDataStoreVO > updateStateSearch ;
5665 private SearchBuilder <SnapshotDataStoreVO > storeSearch ;
5766 private SearchBuilder <SnapshotDataStoreVO > storeStateSearch ;
@@ -82,17 +91,17 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
8291 public boolean configure (String name , Map <String , Object > params ) throws ConfigurationException {
8392 super .configure (name , params );
8493
85- Pair <String , SearchCriteria .Op > storeIdEq = new Pair <>("store_id" , SearchCriteria .Op .EQ );
86- Pair <String , SearchCriteria .Op > storeRoleEq = new Pair <>("store_role" , SearchCriteria .Op .EQ );
87- Pair <String , SearchCriteria .Op > stateEq = new Pair <>("state" , SearchCriteria .Op .EQ );
88- Pair <String , SearchCriteria .Op > stateNeq = new Pair <>("state" , SearchCriteria .Op .NEQ );
89- Pair <String , SearchCriteria .Op > stateIn = new Pair <>("state" , SearchCriteria .Op .IN );
90- Pair <String , SearchCriteria .Op > refCntNeq = new Pair <>("ref_cnt" , SearchCriteria .Op .NEQ );
91- Pair <String , SearchCriteria .Op > idEq = new Pair <>("id" , SearchCriteria .Op .EQ );
92- Pair <String , SearchCriteria .Op > updateCountEq = new Pair <>("updatedCount" , SearchCriteria .Op .EQ );
93- Pair <String , SearchCriteria .Op > snapshotIdEq = new Pair <>("snapshot_id" , SearchCriteria .Op .EQ );
94- Pair <String , SearchCriteria .Op > volumeIdEq = new Pair <>("volume_id" , SearchCriteria .Op .EQ );
95- Pair <String , SearchCriteria .Op > createdBetween = new Pair <>("created" , SearchCriteria .Op .BETWEEN );
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 );
96105
97106 storeSearch = createSearchBuilder ();
98107 storeSearch .addAndConditions (storeIdEq , storeRoleEq , stateNeq );
@@ -164,14 +173,14 @@ public boolean updateState(State currentState, Event event, State nextState, Dat
164173 Date oldUpdatedTime = dataObj .getUpdated ();
165174
166175 SearchCriteria <SnapshotDataStoreVO > sc = updateStateSearch .create ();
167- sc .setParameters ("id" , dataObj .getId ());
168- sc .setParameters ("state" , currentState );
169- sc .setParameters ("updatedCount" , dataObj .getUpdatedCount ());
176+ sc .setParameters (ID , dataObj .getId ());
177+ sc .setParameters (STATE , currentState );
178+ sc .setParameters (UPDATED_COUNT , dataObj .getUpdatedCount ());
170179
171180 dataObj .incrUpdatedCount ();
172181
173182 UpdateBuilder builder = getUpdateBuilder (dataObj );
174- builder .set (dataObj , "state" , nextState );
183+ builder .set (dataObj , STATE , nextState );
175184 builder .set (dataObj , "updated" , new Date ());
176185
177186 if (update (dataObj , sc ) > 0 ) {
@@ -196,41 +205,41 @@ public boolean updateState(State currentState, Event event, State nextState, Dat
196205 @ Override
197206 public List <SnapshotDataStoreVO > listByStoreId (long id , DataStoreRole role ) {
198207 SearchCriteria <SnapshotDataStoreVO > sc = storeSearch .create ();
199- sc .setParameters ("store_id" , id );
200- sc .setParameters ("store_role" , role );
201- sc .setParameters ("state" , ObjectInDataStoreStateMachine .State .Destroyed );
208+ sc .setParameters (STORE_ID , id );
209+ sc .setParameters (STORE_ROLE , role );
210+ sc .setParameters (STATE , ObjectInDataStoreStateMachine .State .Destroyed );
202211 return listBy (sc );
203212 }
204213
205214 @ Override
206215 public List <SnapshotDataStoreVO > listByStoreIdAndState (long id , ObjectInDataStoreStateMachine .State state ) {
207216 SearchCriteria <SnapshotDataStoreVO > sc = storeStateSearch .create ();
208- sc .setParameters ("store_id" , id );
209- sc .setParameters ("state" , state );
217+ sc .setParameters (STORE_ID , id );
218+ sc .setParameters (STATE , state );
210219 return listBy (sc );
211220 }
212221
213222 @ Override
214223 public void deletePrimaryRecordsForStore (long id , DataStoreRole role ) {
215224 SearchCriteria <SnapshotDataStoreVO > sc = storeSearch .create ();
216- sc .setParameters ("store_id" , id );
217- sc .setParameters ("store_role" , role );
225+ sc .setParameters (STORE_ID , id );
226+ sc .setParameters (STORE_ROLE , role );
218227 remove (sc );
219228 }
220229
221230 @ Override
222231 public void deleteSnapshotRecordsOnPrimary () {
223232 SearchCriteria <SnapshotDataStoreVO > sc = storeSearch .create ();
224- sc .setParameters ("store_role" , DataStoreRole .Primary );
233+ sc .setParameters (STORE_ROLE , DataStoreRole .Primary );
225234 remove (sc );
226235 }
227236
228237 @ Override
229238 public SnapshotDataStoreVO findByStoreSnapshot (DataStoreRole role , long storeId , long snapshotId ) {
230239 SearchCriteria <SnapshotDataStoreVO > sc = storeSnapshotSearch .create ();
231- sc .setParameters ("store_id" , storeId );
232- sc .setParameters ("snapshot_id" , snapshotId );
233- sc .setParameters ("store_role" , role );
240+ sc .setParameters (STORE_ID , storeId );
241+ sc .setParameters (SNAPSHOT_ID , snapshotId );
242+ sc .setParameters (STORE_ROLE , role );
234243 return findOneBy (sc );
235244 }
236245
@@ -275,12 +284,12 @@ public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long vol
275284 }
276285
277286 SearchCriteria <SnapshotDataStoreVO > sc = parentSnapshotSearch .create ();
278- sc .setParameters ("volume_id" , volumeId );
279- sc .setParameters ("store_role" , role .toString ());
280- sc .setParameters ("state" , ObjectInDataStoreStateMachine .State .Ready .name ());
281- sc .setParameters ("store_id" , storeId );
287+ sc .setParameters (VOLUME_ID , volumeId );
288+ sc .setParameters (STORE_ROLE , role .toString ());
289+ sc .setParameters (STATE , ObjectInDataStoreStateMachine .State .Ready .name ());
290+ sc .setParameters (STORE_ID , storeId );
282291
283- List <SnapshotDataStoreVO > snapshotList = listBy (sc , new Filter (SnapshotDataStoreVO .class , "created" , false , null , null ));
292+ List <SnapshotDataStoreVO > snapshotList = listBy (sc , new Filter (SnapshotDataStoreVO .class , CREATED , false , null , null ));
284293 if (CollectionUtils .isNotEmpty (snapshotList )) {
285294 return snapshotList .get (0 );
286295 }
@@ -290,65 +299,65 @@ public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long vol
290299 @ Override
291300 public SnapshotDataStoreVO findBySnapshot (long snapshotId , DataStoreRole role ) {
292301 SearchCriteria <SnapshotDataStoreVO > sc = createSearchCriteriaBySnapshotIdAndStoreRole (snapshotId , role );
293- sc .setParameters ("state" , State .Ready );
302+ sc .setParameters (STATE , State .Ready );
294303 return findOneBy (sc );
295304 }
296305
297306 @ Override
298307 public SnapshotDataStoreVO findBySourceSnapshot (long snapshotId , DataStoreRole role ) {
299308 SearchCriteria <SnapshotDataStoreVO > sc = createSearchCriteriaBySnapshotIdAndStoreRole (snapshotId , role );
300- sc .setParameters ("state" , State .Migrating );
309+ sc .setParameters (STATE , State .Migrating );
301310 return findOneBy (sc );
302311 }
303312
304313 @ Override
305314 public List <SnapshotDataStoreVO > listAllByVolumeAndDataStore (long volumeId , DataStoreRole role ) {
306315 SearchCriteria <SnapshotDataStoreVO > sc = volumeSearch .create ();
307- sc .setParameters ("volume_id" , volumeId );
308- sc .setParameters ("store_role" , role );
316+ sc .setParameters (VOLUME_ID , volumeId );
317+ sc .setParameters (STORE_ROLE , role );
309318 return listBy (sc );
310319 }
311320
312321 @ Override
313322 public SnapshotDataStoreVO findByVolume (long volumeId , DataStoreRole role ) {
314323 SearchCriteria <SnapshotDataStoreVO > sc = volumeSearch .create ();
315- sc .setParameters ("volume_id" , volumeId );
316- sc .setParameters ("store_role" , role );
324+ sc .setParameters (VOLUME_ID , volumeId );
325+ sc .setParameters (STORE_ROLE , role );
317326 return findOneBy (sc );
318327 }
319328
320329 @ Override
321330 public SnapshotDataStoreVO findByVolume (long snapshotId , long volumeId , DataStoreRole role ) {
322331 SearchCriteria <SnapshotDataStoreVO > sc = volumeSearch .create ();
323- sc .setParameters ("snapshot_id" , snapshotId );
324- sc .setParameters ("volume_id" , volumeId );
325- sc .setParameters ("store_role" , role );
332+ sc .setParameters (SNAPSHOT_ID , snapshotId );
333+ sc .setParameters (VOLUME_ID , volumeId );
334+ sc .setParameters (STORE_ROLE , role );
326335 return findOneBy (sc );
327336 }
328337
329338 @ Override
330339 public List <SnapshotDataStoreVO > findBySnapshotId (long snapshotId ) {
331340 SearchCriteria <SnapshotDataStoreVO > sc = snapshotIdSearch .create ();
332- sc .setParameters ("snapshot_id" , snapshotId );
341+ sc .setParameters (SNAPSHOT_ID , snapshotId );
333342 return listBy (sc );
334343 }
335344
336345 @ Override
337346 public List <SnapshotDataStoreVO > listDestroyed (long id ) {
338347 SearchCriteria <SnapshotDataStoreVO > sc = destroyedSearch .create ();
339- sc .setParameters ("store_id" , id );
340- sc .setParameters ("store_role" , DataStoreRole .Image );
341- sc .setParameters ("state" , ObjectInDataStoreStateMachine .State .Destroyed );
348+ sc .setParameters (STORE_ID , id );
349+ sc .setParameters (STORE_ROLE , DataStoreRole .Image );
350+ sc .setParameters (STATE , ObjectInDataStoreStateMachine .State .Destroyed );
342351 return listBy (sc );
343352 }
344353
345354 @ Override
346355 public List <SnapshotDataStoreVO > listActiveOnCache (long id ) {
347356 SearchCriteria <SnapshotDataStoreVO > sc = cacheSearch .create ();
348- sc .setParameters ("store_id" , id );
349- sc .setParameters ("store_role" , DataStoreRole .ImageCache );
350- sc .setParameters ("state" , ObjectInDataStoreStateMachine .State .Destroyed );
351- sc .setParameters ("ref_cnt" , 0 );
357+ sc .setParameters (STORE_ID , id );
358+ sc .setParameters (STORE_ROLE , DataStoreRole .ImageCache );
359+ sc .setParameters (STATE , ObjectInDataStoreStateMachine .State .Destroyed );
360+ sc .setParameters (REF_CNT , 0 );
352361 return listBy (sc );
353362 }
354363
@@ -358,7 +367,7 @@ public List<SnapshotDataStoreVO> listActiveOnCache(long id) {
358367 @ Override
359368 public void duplicateCacheRecordsOnRegionStore (long storeId ) {
360369 SearchCriteria <SnapshotDataStoreVO > sc = storeSnapshotSearch .create ();
361- sc .setParameters ("store_role" , DataStoreRole .ImageCache );
370+ sc .setParameters (STORE_ROLE , DataStoreRole .ImageCache );
362371 sc .setParameters ("destroyed" , false );
363372 List <SnapshotDataStoreVO > snapshots = listBy (sc );
364373
@@ -398,24 +407,24 @@ public void duplicateCacheRecordsOnRegionStore(long storeId) {
398407 @ Override
399408 public SnapshotDataStoreVO findReadyOnCache (long snapshotId ) {
400409 SearchCriteria <SnapshotDataStoreVO > sc = storeSnapshotSearch .create ();
401- sc .setParameters ("snapshot_id" , snapshotId );
402- sc .setParameters ("store_role" , DataStoreRole .ImageCache );
403- sc .setParameters ("state" , ObjectInDataStoreStateMachine .State .Ready );
410+ sc .setParameters (SNAPSHOT_ID , snapshotId );
411+ sc .setParameters (STORE_ROLE , DataStoreRole .ImageCache );
412+ sc .setParameters (STATE , ObjectInDataStoreStateMachine .State .Ready );
404413 return findOneIncludingRemovedBy (sc );
405414 }
406415
407416 @ Override
408417 public List <SnapshotDataStoreVO > listOnCache (long snapshotId ) {
409418 SearchCriteria <SnapshotDataStoreVO > sc = storeSnapshotSearch .create ();
410- sc .setParameters ("snapshot_id" , snapshotId );
411- sc .setParameters ("store_role" , DataStoreRole .ImageCache );
419+ sc .setParameters (SNAPSHOT_ID , snapshotId );
420+ sc .setParameters (STORE_ROLE , DataStoreRole .ImageCache );
412421 return search (sc , null );
413422 }
414423
415424 @ Override
416425 public void updateStoreRoleToCache (long storeId ) {
417426 SearchCriteria <SnapshotDataStoreVO > sc = storeSearch .create ();
418- sc .setParameters ("store_id" , storeId );
427+ sc .setParameters (STORE_ID , storeId );
419428 sc .setParameters ("destroyed" , false );
420429 List <SnapshotDataStoreVO > snaps = listBy (sc );
421430 if (snaps != null ) {
@@ -431,7 +440,7 @@ public void updateStoreRoleToCache(long storeId) {
431440 @ Override
432441 public void updateVolumeIds (long oldVolId , long newVolId ) {
433442 SearchCriteria <SnapshotDataStoreVO > sc = volumeIdSearch .create ();
434- sc .setParameters ("volume_id" , oldVolId );
443+ sc .setParameters (VOLUME_ID , oldVolId );
435444 SnapshotDataStoreVO snapshot = createForUpdate ();
436445 snapshot .setVolumeId (newVolId );
437446 UpdateBuilder ub = getUpdateBuilder (snapshot );
@@ -441,23 +450,23 @@ public void updateVolumeIds(long oldVolId, long newVolId) {
441450 @ Override
442451 public List <SnapshotDataStoreVO > listByState (ObjectInDataStoreStateMachine .State ... states ) {
443452 SearchCriteria <SnapshotDataStoreVO > sc = stateSearch .create ();
444- sc .setParameters ("state" , (Object [])states );
453+ sc .setParameters (STATE , (Object [])states );
445454 return listBy (sc , null );
446455 }
447456
448457 @ Override
449458 public List <SnapshotDataStoreVO > findSnapshots (Long storeId , Date start , Date end ) {
450459 SearchCriteria <SnapshotDataStoreVO > sc = snapshotCreatedSearch .create ();
451- sc .setParameters ("store_id" , storeId );
460+ sc .setParameters (STORE_ID , storeId );
452461 if (start != null && end != null ) {
453- sc .setParameters ("created" , start , end );
462+ sc .setParameters (CREATED , start , end );
454463 }
455464 return search (sc , null );
456465 }
457466
458467 public SnapshotDataStoreVO findDestroyedReferenceBySnapshot (long snapshotId , DataStoreRole role ) {
459468 SearchCriteria <SnapshotDataStoreVO > sc = createSearchCriteriaBySnapshotIdAndStoreRole (snapshotId , role );
460- sc .setParameters ("state" , State .Destroyed );
469+ sc .setParameters (STATE , State .Destroyed );
461470 return findOneBy (sc );
462471 }
463472
@@ -467,14 +476,14 @@ public SnapshotDataStoreVO findDestroyedReferenceBySnapshot(long snapshotId, Dat
467476 */
468477 protected SearchCriteria <SnapshotDataStoreVO > createSearchCriteriaBySnapshotIdAndStoreRole (long snapshotId , DataStoreRole role ) {
469478 SearchCriteria <SnapshotDataStoreVO > sc = snapshotSearch .create ();
470- sc .setParameters ("snapshot_id" , snapshotId );
471- sc .setParameters ("store_role" , role );
479+ sc .setParameters (SNAPSHOT_ID , snapshotId );
480+ sc .setParameters (STORE_ROLE , role );
472481 return sc ;
473482 }
474483
475484 protected boolean isSnapshotChainingRequired (long volumeId ) {
476485 SearchCriteria <SnapshotVO > sc = snapshotVOSearch .create ();
477- sc .setParameters ("volume_id" , volumeId );
486+ sc .setParameters (VOLUME_ID , volumeId );
478487
479488 SnapshotVO snapshot = snapshotDao .findOneBy (sc );
480489
@@ -490,8 +499,8 @@ public boolean expungeReferenceBySnapshotIdAndDataStoreRole(long snapshotId, Dat
490499 @ Override
491500 public List <SnapshotDataStoreVO > listReadyByVolumeId (long volumeId ) {
492501 SearchCriteria <SnapshotDataStoreVO > sc = volumeIdAndStateReadySearch .create ();
493- sc .setParameters ("volume_id" , volumeId );
494- sc .setParameters ("state" , State .Ready );
502+ sc .setParameters (VOLUME_ID , volumeId );
503+ sc .setParameters (STATE , State .Ready );
495504 return listBy (sc );
496505 }
497506}
0 commit comments