mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	removed unused code in snapshotDao (#2659)
* removed unused code * remove sql strings
This commit is contained in:
		
							parent
							
								
									1d05fead49
								
							
						
					
					
						commit
						d0d3895c39
					
				| @ -31,26 +31,14 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long>, StateDao<Snap | |||||||
| 
 | 
 | ||||||
|     List<SnapshotVO> listByVolumeId(Filter filter, long volumeId); |     List<SnapshotVO> listByVolumeId(Filter filter, long volumeId); | ||||||
| 
 | 
 | ||||||
|     SnapshotVO findNextSnapshot(long parentSnapId); |  | ||||||
| 
 |  | ||||||
|     long getLastSnapshot(long volumeId, DataStoreRole role); |     long getLastSnapshot(long volumeId, DataStoreRole role); | ||||||
| 
 | 
 | ||||||
|     List<SnapshotVO> listByVolumeIdType(long volumeId, Type type); |  | ||||||
| 
 |  | ||||||
|     List<SnapshotVO> listByVolumeIdTypeNotDestroyed(long volumeId, Type type); |     List<SnapshotVO> listByVolumeIdTypeNotDestroyed(long volumeId, Type type); | ||||||
| 
 | 
 | ||||||
|     List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId); |     List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId); | ||||||
| 
 | 
 | ||||||
|     List<SnapshotVO> listByBackupUuid(long volumeId, String backupUuid); |  | ||||||
| 
 |  | ||||||
|     long updateSnapshotVersion(long volumeId, String from, String to); |  | ||||||
| 
 |  | ||||||
|     List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version); |     List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version); | ||||||
| 
 | 
 | ||||||
|     Long getSecHostId(long volumeId); |  | ||||||
| 
 |  | ||||||
|     long updateSnapshotSecHost(long dcId, long secHostId); |  | ||||||
| 
 |  | ||||||
|     public Long countSnapshotsForAccount(long accountId); |     public Long countSnapshotsForAccount(long accountId); | ||||||
| 
 | 
 | ||||||
|     List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... status); |     List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... status); | ||||||
|  | |||||||
| @ -55,16 +55,10 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements | |||||||
|     // TODO: we should remove these direct sqls |     // TODO: we should remove these direct sqls | ||||||
|     private static final String GET_LAST_SNAPSHOT = |     private static final String GET_LAST_SNAPSHOT = | ||||||
|         "SELECT snapshots.id FROM snapshot_store_ref, snapshots where snapshots.id = snapshot_store_ref.snapshot_id AND snapshosts.volume_id = ? AND snapshot_store_ref.role = ? ORDER BY created DESC"; |         "SELECT snapshots.id FROM snapshot_store_ref, snapshots where snapshots.id = snapshot_store_ref.snapshot_id AND snapshosts.volume_id = ? AND snapshot_store_ref.role = ? ORDER BY created DESC"; | ||||||
|     private static final String UPDATE_SNAPSHOT_VERSION = "UPDATE snapshots SET version = ? WHERE volume_id = ? AND version = ?"; |  | ||||||
|     private static final String GET_SECHOST_ID = |  | ||||||
|         "SELECT store_id FROM snapshots, snapshot_store_ref where snapshots.id = snapshot_store_ref.snapshot_id AND volume_id = ? AND backup_snap_id IS NOT NULL AND sechost_id IS NOT NULL LIMIT 1"; |  | ||||||
|     private static final String UPDATE_SECHOST_ID = "UPDATE snapshots SET sechost_id = ? WHERE data_center_id = ?"; |  | ||||||
| 
 | 
 | ||||||
|     private SearchBuilder<SnapshotVO> VolumeIdSearch; |     private SearchBuilder<SnapshotVO> VolumeIdSearch; | ||||||
|     private SearchBuilder<SnapshotVO> VolumeIdTypeSearch; |     private SearchBuilder<SnapshotVO> VolumeIdTypeSearch; | ||||||
|     private SearchBuilder<SnapshotVO> VolumeIdTypeNotDestroyedSearch; |     private SearchBuilder<SnapshotVO> VolumeIdTypeNotDestroyedSearch; | ||||||
|     private SearchBuilder<SnapshotVO> ParentIdSearch; |  | ||||||
|     private SearchBuilder<SnapshotVO> backupUuidSearch; |  | ||||||
|     private SearchBuilder<SnapshotVO> VolumeIdVersionSearch; |     private SearchBuilder<SnapshotVO> VolumeIdVersionSearch; | ||||||
|     private SearchBuilder<SnapshotVO> AccountIdSearch; |     private SearchBuilder<SnapshotVO> AccountIdSearch; | ||||||
|     private SearchBuilder<SnapshotVO> InstanceIdSearch; |     private SearchBuilder<SnapshotVO> InstanceIdSearch; | ||||||
| @ -78,25 +72,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements | |||||||
|     @Inject |     @Inject | ||||||
|     protected VolumeDao _volumeDao; |     protected VolumeDao _volumeDao; | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     public SnapshotVO findNextSnapshot(long snapshotId) { |  | ||||||
|         SearchCriteria<SnapshotVO> sc = ParentIdSearch.create(); |  | ||||||
|         sc.setParameters("prevSnapshotId", snapshotId); |  | ||||||
|         return findOneIncludingRemovedBy(sc); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |  | ||||||
|     public List<SnapshotVO> listByBackupUuid(long volumeId, String backupUuid) { |  | ||||||
|         SearchCriteria<SnapshotVO> sc = backupUuidSearch.create(); |  | ||||||
|         sc.setParameters("backupUuid", backupUuid); |  | ||||||
|         return listBy(sc, null); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |  | ||||||
|     public List<SnapshotVO> listByVolumeIdType(long volumeId, Type type) { |  | ||||||
|         return listByVolumeIdType(null, volumeId, type); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public List<SnapshotVO> listByVolumeIdTypeNotDestroyed(long volumeId, Type type) { |     public List<SnapshotVO> listByVolumeIdTypeNotDestroyed(long volumeId, Type type) { | ||||||
|         SearchCriteria<SnapshotVO> sc = VolumeIdTypeNotDestroyedSearch.create(); |         SearchCriteria<SnapshotVO> sc = VolumeIdTypeNotDestroyedSearch.create(); | ||||||
| @ -168,17 +143,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements | |||||||
|         VolumeIdVersionSearch.and("volumeId", VolumeIdVersionSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); |         VolumeIdVersionSearch.and("volumeId", VolumeIdVersionSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); | ||||||
|         VolumeIdVersionSearch.and("version", VolumeIdVersionSearch.entity().getVersion(), SearchCriteria.Op.EQ); |         VolumeIdVersionSearch.and("version", VolumeIdVersionSearch.entity().getVersion(), SearchCriteria.Op.EQ); | ||||||
|         VolumeIdVersionSearch.done(); |         VolumeIdVersionSearch.done(); | ||||||
|         /* | 
 | ||||||
|          * ParentIdSearch = createSearchBuilder(); |  | ||||||
|          * ParentIdSearch.and("prevSnapshotId", |  | ||||||
|          * ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ); |  | ||||||
|          * ParentIdSearch.done(); |  | ||||||
|          * |  | ||||||
|          * backupUuidSearch = createSearchBuilder(); |  | ||||||
|          * backupUuidSearch.and("backupUuid", |  | ||||||
|          * backupUuidSearch.entity().getBackupSnapshotId(), |  | ||||||
|          * SearchCriteria.Op.EQ); backupUuidSearch.done(); |  | ||||||
|          */ |  | ||||||
|         AccountIdSearch = createSearchBuilder(); |         AccountIdSearch = createSearchBuilder(); | ||||||
|         AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); |         AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); | ||||||
|         AccountIdSearch.done(); |         AccountIdSearch.done(); | ||||||
| @ -214,26 +179,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements | |||||||
|         InstanceIdSearch.done(); |         InstanceIdSearch.done(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     public Long getSecHostId(long volumeId) { |  | ||||||
| 
 |  | ||||||
|         TransactionLegacy txn = TransactionLegacy.currentTxn(); |  | ||||||
|         PreparedStatement pstmt = null; |  | ||||||
|         String sql = GET_SECHOST_ID; |  | ||||||
|         try { |  | ||||||
|             pstmt = txn.prepareAutoCloseStatement(sql); |  | ||||||
|             pstmt.setLong(1, volumeId); |  | ||||||
|             ResultSet rs = pstmt.executeQuery(); |  | ||||||
|             if (rs.next()) { |  | ||||||
|                 return rs.getLong(1); |  | ||||||
|             } |  | ||||||
|         } catch (Exception ex) { |  | ||||||
|             s_logger.info("[ignored]" |  | ||||||
|                     + "caught something while getting sec. host id: " + ex.getLocalizedMessage()); |  | ||||||
|         } |  | ||||||
|         return null; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public long getLastSnapshot(long volumeId, DataStoreRole role) { |     public long getLastSnapshot(long volumeId, DataStoreRole role) { | ||||||
|         TransactionLegacy txn = TransactionLegacy.currentTxn(); |         TransactionLegacy txn = TransactionLegacy.currentTxn(); | ||||||
| @ -253,41 +198,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements | |||||||
|         return 0; |         return 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     public long updateSnapshotVersion(long volumeId, String from, String to) { |  | ||||||
|         TransactionLegacy txn = TransactionLegacy.currentTxn(); |  | ||||||
|         PreparedStatement pstmt = null; |  | ||||||
|         String sql = UPDATE_SNAPSHOT_VERSION; |  | ||||||
|         try { |  | ||||||
|             pstmt = txn.prepareAutoCloseStatement(sql); |  | ||||||
|             pstmt.setString(1, to); |  | ||||||
|             pstmt.setLong(2, volumeId); |  | ||||||
|             pstmt.setString(3, from); |  | ||||||
|             pstmt.executeUpdate(); |  | ||||||
|             return 1; |  | ||||||
|         } catch (Exception ex) { |  | ||||||
|             s_logger.error("error getting last snapshot", ex); |  | ||||||
|         } |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |  | ||||||
|     public long updateSnapshotSecHost(long dcId, long secHostId) { |  | ||||||
|         TransactionLegacy txn = TransactionLegacy.currentTxn(); |  | ||||||
|         PreparedStatement pstmt = null; |  | ||||||
|         String sql = UPDATE_SECHOST_ID; |  | ||||||
|         try { |  | ||||||
|             pstmt = txn.prepareAutoCloseStatement(sql); |  | ||||||
|             pstmt.setLong(1, secHostId); |  | ||||||
|             pstmt.setLong(2, dcId); |  | ||||||
|             pstmt.executeUpdate(); |  | ||||||
|             return 1; |  | ||||||
|         } catch (Exception ex) { |  | ||||||
|             s_logger.error("error set secondary storage host id", ex); |  | ||||||
|         } |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public Long countSnapshotsForAccount(long accountId) { |     public Long countSnapshotsForAccount(long accountId) { | ||||||
|         SearchCriteria<Long> sc = CountSnapshotsByAccount.create(); |         SearchCriteria<Long> sc = CountSnapshotsByAccount.create(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user