cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [11/17] clean up storage related coded
Date Thu, 30 May 2013 01:06:31 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplateDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDetailsDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDetailsDaoImpl.java
index 04b553c..33b96c4 100644
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDetailsDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDetailsDaoImpl.java
@@ -31,69 +31,69 @@ import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 
 @Component
-@Local(value=VMTemplateDetailsDao.class)
+@Local(value = VMTemplateDetailsDao.class)
 public class VMTemplateDetailsDaoImpl extends GenericDaoBase<VMTemplateDetailVO, Long> implements VMTemplateDetailsDao {
 
     protected final SearchBuilder<VMTemplateDetailVO> TemplateSearch;
     protected final SearchBuilder<VMTemplateDetailVO> DetailSearch;
-    
-	public VMTemplateDetailsDaoImpl() {
-		TemplateSearch = createSearchBuilder();
-		TemplateSearch.and("templateId", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplateSearch.done();
-		
-		DetailSearch = createSearchBuilder();
+
+    public VMTemplateDetailsDaoImpl() {
+        TemplateSearch = createSearchBuilder();
+        TemplateSearch.and("templateId", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateSearch.done();
+
+        DetailSearch = createSearchBuilder();
         DetailSearch.and("templateId", DetailSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
         DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
         DetailSearch.done();
-	}
-	
-	@Override
-	public void deleteDetails(long templateId) {
+    }
+
+    @Override
+    public void deleteDetails(long templateId) {
         SearchCriteria<VMTemplateDetailVO> sc = TemplateSearch.create();
         sc.setParameters("templateId", templateId);
-        
+
         List<VMTemplateDetailVO> results = search(sc, null);
         for (VMTemplateDetailVO result : results) {
-        	remove(result.getId());
-        }		
-	}
+            remove(result.getId());
+        }
+    }
 
-	@Override
-	public VMTemplateDetailVO findDetail(long templateId, String name) {
+    @Override
+    public VMTemplateDetailVO findDetail(long templateId, String name) {
         SearchCriteria<VMTemplateDetailVO> sc = DetailSearch.create();
         sc.setParameters("templateId", templateId);
         sc.setParameters("name", name);
-		
+
         return findOneBy(sc);
-	}
+    }
 
-	@Override
-	public Map<String, String> findDetails(long templateId) {
+    @Override
+    public Map<String, String> findDetails(long templateId) {
         SearchCriteria<VMTemplateDetailVO> sc = TemplateSearch.create();
         sc.setParameters("templateId", templateId);
-        
+
         List<VMTemplateDetailVO> results = search(sc, null);
         Map<String, String> details = new HashMap<String, String>(results.size());
         for (VMTemplateDetailVO result : results) {
             details.put(result.getName(), result.getValue());
         }
-        
+
         return details;
-	}
+    }
 
-	@Override
-	public void persist(long templateId, Map<String, String> details) {
+    @Override
+    public void persist(long templateId, Map<String, String> details) {
         Transaction txn = Transaction.currentTxn();
         txn.start();
         SearchCriteria<VMTemplateDetailVO> sc = TemplateSearch.create();
         sc.setParameters("templateId", templateId);
         expunge(sc);
-        
+
         for (Map.Entry<String, String> detail : details.entrySet()) {
             VMTemplateDetailVO vo = new VMTemplateDetailVO(templateId, detail.getKey(), detail.getValue());
             persist(vo);
         }
-        txn.commit();		
-	}
+        txn.commit();
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDao.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDao.java
index 23241cd..72072fa 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDao.java
@@ -26,28 +26,31 @@ import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
 import com.cloud.utils.db.GenericDao;
 import com.cloud.utils.fsm.StateDao;
 
-public interface VMTemplateHostDao extends GenericDao<VMTemplateHostVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
+public interface VMTemplateHostDao extends GenericDao<VMTemplateHostVO, Long>,
+        StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
     List<VMTemplateHostVO> listByHostId(long id);
 
     List<VMTemplateHostVO> listByTemplateId(long templateId);
-    
+
     List<VMTemplateHostVO> listByOnlyTemplateId(long templateId);
 
     VMTemplateHostVO findByHostTemplate(long hostId, long templateId);
-    
+
     VMTemplateHostVO findByTemplateId(long templateId);
 
     VMTemplateHostVO findByHostTemplate(long hostId, long templateId, boolean lock);
 
     List<VMTemplateHostVO> listByHostTemplate(long hostId, long templateId);
 
-    void update(VMTemplateHostVO instance);    
+    void update(VMTemplateHostVO instance);
 
     List<VMTemplateHostVO> listByTemplateStatus(long templateId, VMTemplateHostVO.Status downloadState);
 
-    List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, VMTemplateHostVO.Status downloadState);
+    List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId,
+            VMTemplateHostVO.Status downloadState);
 
-    List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateHostVO.Status downloadState);
+    List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId,
+            VMTemplateHostVO.Status downloadState);
 
     List<VMTemplateHostVO> listByTemplateStates(long templateId, VMTemplateHostVO.Status... states);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java
index 7f35eab..85d8348 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java
@@ -50,67 +50,61 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.UpdateBuilder;
 
 @Component
-@Local(value={VMTemplateHostDao.class})
+@Local(value = { VMTemplateHostDao.class })
 public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long> implements VMTemplateHostDao {
-	public static final Logger s_logger = Logger.getLogger(VMTemplateHostDaoImpl.class.getName());
+    public static final Logger s_logger = Logger.getLogger(VMTemplateHostDaoImpl.class.getName());
     @Inject
-    HostDao   _hostDao;
-	protected final SearchBuilder<VMTemplateHostVO> HostSearch;
-	protected final SearchBuilder<VMTemplateHostVO> TemplateSearch;
-	protected final SearchBuilder<VMTemplateHostVO> HostTemplateSearch;
-	protected final SearchBuilder<VMTemplateHostVO> HostTemplateStateSearch;
-	protected final SearchBuilder<VMTemplateHostVO> HostDestroyedSearch;
-	protected final SearchBuilder<VMTemplateHostVO> TemplateStatusSearch;
-	protected final SearchBuilder<VMTemplateHostVO> TemplateStatesSearch;
-	protected final SearchBuilder<VMTemplateHostVO> updateStateSearch;
-	protected SearchBuilder<VMTemplateHostVO> ZONE_TEMPLATE_SEARCH;
-	protected SearchBuilder<VMTemplateHostVO> LOCAL_SECONDARY_STORAGE_SEARCH;
-
-	
-	protected static final String UPDATE_TEMPLATE_HOST_REF =
-		"UPDATE template_host_ref SET download_state = ?, download_pct= ?, last_updated = ? "
-	+   ", error_str = ?, local_path = ?, job_id = ? "
-	+   "WHERE host_id = ? and type_id = ?";
-			
-	protected static final String DOWNLOADS_STATE_DC=
-		"SELECT t.id, t.host_id, t.template_id, t.created, t.last_updated, t.job_id, " 
-	+   "t.download_pct, t.size, t.physical_size, t.download_state, t.error_str, t.local_path, "
-	+   "t.install_path, t.url, t.destroyed, t.is_copy FROM template_host_ref t, host h " 
-	+   "where t.host_id = h.id and h.data_center_id=? "
-	+	" and t.template_id=? and t.download_state = ?" ;
-	
-	protected static final String DOWNLOADS_STATE_DC_POD=
-		"SELECT * FROM template_host_ref t, host h where t.host_id = h.id and h.data_center_id=? and h.pod_id=? "
-	+	" and t.template_id=? and t.download_state=?" ;
-	
-	protected static final String DOWNLOADS_STATE=
-		"SELECT * FROM template_host_ref t "
-	+	" where t.template_id=? and t.download_state=?";
-	
-	public VMTemplateHostDaoImpl () {
-		HostSearch = createSearchBuilder();
-		HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
-		HostSearch.done();
-		
-		TemplateSearch = createSearchBuilder();
-		TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplateSearch.and("destroyed", TemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
-		TemplateSearch.done();
-		
-		HostTemplateSearch = createSearchBuilder();
-		HostTemplateSearch.and("host_id", HostTemplateSearch.entity().getHostId(), SearchCriteria.Op.EQ);
-		HostTemplateSearch.and("template_id", HostTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+    HostDao _hostDao;
+    protected final SearchBuilder<VMTemplateHostVO> HostSearch;
+    protected final SearchBuilder<VMTemplateHostVO> TemplateSearch;
+    protected final SearchBuilder<VMTemplateHostVO> HostTemplateSearch;
+    protected final SearchBuilder<VMTemplateHostVO> HostTemplateStateSearch;
+    protected final SearchBuilder<VMTemplateHostVO> HostDestroyedSearch;
+    protected final SearchBuilder<VMTemplateHostVO> TemplateStatusSearch;
+    protected final SearchBuilder<VMTemplateHostVO> TemplateStatesSearch;
+    protected final SearchBuilder<VMTemplateHostVO> updateStateSearch;
+    protected SearchBuilder<VMTemplateHostVO> ZONE_TEMPLATE_SEARCH;
+    protected SearchBuilder<VMTemplateHostVO> LOCAL_SECONDARY_STORAGE_SEARCH;
+
+    protected static final String UPDATE_TEMPLATE_HOST_REF = "UPDATE template_host_ref SET download_state = ?, download_pct= ?, last_updated = ? "
+            + ", error_str = ?, local_path = ?, job_id = ? " + "WHERE host_id = ? and type_id = ?";
+
+    protected static final String DOWNLOADS_STATE_DC = "SELECT t.id, t.host_id, t.template_id, t.created, t.last_updated, t.job_id, "
+            + "t.download_pct, t.size, t.physical_size, t.download_state, t.error_str, t.local_path, "
+            + "t.install_path, t.url, t.destroyed, t.is_copy FROM template_host_ref t, host h "
+            + "where t.host_id = h.id and h.data_center_id=? " + " and t.template_id=? and t.download_state = ?";
+
+    protected static final String DOWNLOADS_STATE_DC_POD = "SELECT * FROM template_host_ref t, host h where t.host_id = h.id and h.data_center_id=? and h.pod_id=? "
+            + " and t.template_id=? and t.download_state=?";
+
+    protected static final String DOWNLOADS_STATE = "SELECT * FROM template_host_ref t "
+            + " where t.template_id=? and t.download_state=?";
+
+    public VMTemplateHostDaoImpl() {
+        HostSearch = createSearchBuilder();
+        HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
+        HostSearch.done();
+
+        TemplateSearch = createSearchBuilder();
+        TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateSearch.and("destroyed", TemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
+        TemplateSearch.done();
+
+        HostTemplateSearch = createSearchBuilder();
+        HostTemplateSearch.and("host_id", HostTemplateSearch.entity().getHostId(), SearchCriteria.Op.EQ);
+        HostTemplateSearch.and("template_id", HostTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
         HostTemplateSearch.and("destroyed", HostTemplateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
         HostTemplateSearch.done();
-		
-		HostDestroyedSearch = createSearchBuilder();
-		HostDestroyedSearch.and("host_id", HostDestroyedSearch.entity().getHostId(), SearchCriteria.Op.EQ);
-		HostDestroyedSearch.and("destroyed", HostDestroyedSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
-		HostDestroyedSearch.done();		
-		
-		TemplateStatusSearch = createSearchBuilder();
-		TemplateStatusSearch.and("template_id", TemplateStatusSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplateStatusSearch.and("download_state", TemplateStatusSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
+
+        HostDestroyedSearch = createSearchBuilder();
+        HostDestroyedSearch.and("host_id", HostDestroyedSearch.entity().getHostId(), SearchCriteria.Op.EQ);
+        HostDestroyedSearch.and("destroyed", HostDestroyedSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
+        HostDestroyedSearch.done();
+
+        TemplateStatusSearch = createSearchBuilder();
+        TemplateStatusSearch.and("template_id", TemplateStatusSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateStatusSearch.and("download_state", TemplateStatusSearch.entity().getDownloadState(),
+                SearchCriteria.Op.EQ);
         TemplateStatusSearch.and("destroyed", TemplateStatusSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
         TemplateStatusSearch.done();
 
@@ -121,12 +115,14 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
         TemplateStatesSearch.done();
 
         HostTemplateStateSearch = createSearchBuilder();
-        HostTemplateStateSearch.and("template_id", HostTemplateStateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        HostTemplateStateSearch.and("template_id", HostTemplateStateSearch.entity().getTemplateId(),
+                SearchCriteria.Op.EQ);
         HostTemplateStateSearch.and("host_id", HostTemplateStateSearch.entity().getHostId(), SearchCriteria.Op.EQ);
-        HostTemplateStateSearch.and("states", HostTemplateStateSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
+        HostTemplateStateSearch
+                .and("states", HostTemplateStateSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
         HostTemplateStateSearch.and("destroyed", HostTemplateStateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
         HostTemplateStateSearch.done();
-        
+
         updateStateSearch = this.createSearchBuilder();
         updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
         updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
@@ -134,187 +130,196 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
         updateStateSearch.done();
 
     }
-	
-	@Override
-	public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-	    boolean result = super.configure(name, params);
-	    ZONE_TEMPLATE_SEARCH = createSearchBuilder();
-	    ZONE_TEMPLATE_SEARCH.and("template_id", ZONE_TEMPLATE_SEARCH.entity().getTemplateId(), SearchCriteria.Op.EQ);
-	    ZONE_TEMPLATE_SEARCH.and("state", ZONE_TEMPLATE_SEARCH.entity().getDownloadState(), SearchCriteria.Op.EQ);
-	    SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder();
-	    hostSearch.and("zone_id", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
-	    ZONE_TEMPLATE_SEARCH.join("tmplHost", hostSearch, hostSearch.entity().getId(), ZONE_TEMPLATE_SEARCH.entity().getHostId(), JoinBuilder.JoinType.INNER);
-	    ZONE_TEMPLATE_SEARCH.done();
-	    
-	    LOCAL_SECONDARY_STORAGE_SEARCH = createSearchBuilder();
-	    LOCAL_SECONDARY_STORAGE_SEARCH.and("template_id", LOCAL_SECONDARY_STORAGE_SEARCH.entity().getTemplateId(), SearchCriteria.Op.EQ);
-	    LOCAL_SECONDARY_STORAGE_SEARCH.and("state", LOCAL_SECONDARY_STORAGE_SEARCH.entity().getDownloadState(), SearchCriteria.Op.EQ);
-	    SearchBuilder<HostVO> localSecondaryHost = _hostDao.createSearchBuilder();
-	    localSecondaryHost.and("private_ip_address", localSecondaryHost.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ);
-	    localSecondaryHost.and("state", localSecondaryHost.entity().getStatus(), SearchCriteria.Op.EQ);
-	    localSecondaryHost.and("data_center_id", localSecondaryHost.entity().getDataCenterId(), SearchCriteria.Op.EQ);
-	    localSecondaryHost.and("type", localSecondaryHost.entity().getType(), SearchCriteria.Op.EQ);
-	    LOCAL_SECONDARY_STORAGE_SEARCH.join("host", localSecondaryHost, localSecondaryHost.entity().getId(), LOCAL_SECONDARY_STORAGE_SEARCH.entity().getHostId(), JoinBuilder.JoinType.INNER);
-	    LOCAL_SECONDARY_STORAGE_SEARCH.done();
-	    
-	    return result;
-	}
-	@Override
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        boolean result = super.configure(name, params);
+        ZONE_TEMPLATE_SEARCH = createSearchBuilder();
+        ZONE_TEMPLATE_SEARCH.and("template_id", ZONE_TEMPLATE_SEARCH.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        ZONE_TEMPLATE_SEARCH.and("state", ZONE_TEMPLATE_SEARCH.entity().getDownloadState(), SearchCriteria.Op.EQ);
+        SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder();
+        hostSearch.and("zone_id", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        ZONE_TEMPLATE_SEARCH.join("tmplHost", hostSearch, hostSearch.entity().getId(), ZONE_TEMPLATE_SEARCH.entity()
+                .getHostId(), JoinBuilder.JoinType.INNER);
+        ZONE_TEMPLATE_SEARCH.done();
+
+        LOCAL_SECONDARY_STORAGE_SEARCH = createSearchBuilder();
+        LOCAL_SECONDARY_STORAGE_SEARCH.and("template_id", LOCAL_SECONDARY_STORAGE_SEARCH.entity().getTemplateId(),
+                SearchCriteria.Op.EQ);
+        LOCAL_SECONDARY_STORAGE_SEARCH.and("state", LOCAL_SECONDARY_STORAGE_SEARCH.entity().getDownloadState(),
+                SearchCriteria.Op.EQ);
+        SearchBuilder<HostVO> localSecondaryHost = _hostDao.createSearchBuilder();
+        localSecondaryHost.and("private_ip_address", localSecondaryHost.entity().getPrivateIpAddress(),
+                SearchCriteria.Op.EQ);
+        localSecondaryHost.and("state", localSecondaryHost.entity().getStatus(), SearchCriteria.Op.EQ);
+        localSecondaryHost.and("data_center_id", localSecondaryHost.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        localSecondaryHost.and("type", localSecondaryHost.entity().getType(), SearchCriteria.Op.EQ);
+        LOCAL_SECONDARY_STORAGE_SEARCH.join("host", localSecondaryHost, localSecondaryHost.entity().getId(),
+                LOCAL_SECONDARY_STORAGE_SEARCH.entity().getHostId(), JoinBuilder.JoinType.INNER);
+        LOCAL_SECONDARY_STORAGE_SEARCH.done();
+
+        return result;
+    }
+
+    @Override
     public void update(VMTemplateHostVO instance) {
         Transaction txn = Transaction.currentTxn();
-		PreparedStatement pstmt = null;
-		try {
-			Date now = new Date();
-			String sql = UPDATE_TEMPLATE_HOST_REF;
-			pstmt = txn.prepareAutoCloseStatement(sql);
-			pstmt.setString(1, instance.getDownloadState().toString());
-			pstmt.setInt(2, instance.getDownloadPercent());
-			pstmt.setString(3, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), now));
-			pstmt.setString(4, instance.getErrorString());
-			pstmt.setString(5, instance.getLocalDownloadPath());
-			pstmt.setString(6, instance.getJobId());
-			pstmt.setLong(7, instance.getHostId());
-			pstmt.setLong(8, instance.getTemplateId());
-			pstmt.executeUpdate();
-		} catch (Exception e) {
-			s_logger.warn("Exception: ", e);
-		}
-	}	
-
-	@Override
-	public List<VMTemplateHostVO> listByHostId(long id) {
-	    SearchCriteria<VMTemplateHostVO> sc = HostSearch.create();
-	    sc.setParameters("host_id", id);
-	    return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public List<VMTemplateHostVO> listByTemplateId(long templateId) {
-	    SearchCriteria<VMTemplateHostVO> sc = TemplateSearch.create();
-	    sc.setParameters("template_id", templateId);
-	    sc.setParameters("destroyed", false);
-	    return listIncludingRemovedBy(sc);
-	}
-	
-	
-	@Override
-	public List<VMTemplateHostVO> listByOnlyTemplateId(long templateId) {
-	    SearchCriteria<VMTemplateHostVO> sc = TemplateSearch.create();
+        PreparedStatement pstmt = null;
+        try {
+            Date now = new Date();
+            String sql = UPDATE_TEMPLATE_HOST_REF;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setString(1, instance.getDownloadState().toString());
+            pstmt.setInt(2, instance.getDownloadPercent());
+            pstmt.setString(3, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), now));
+            pstmt.setString(4, instance.getErrorString());
+            pstmt.setString(5, instance.getLocalDownloadPath());
+            pstmt.setString(6, instance.getJobId());
+            pstmt.setLong(7, instance.getHostId());
+            pstmt.setLong(8, instance.getTemplateId());
+            pstmt.executeUpdate();
+        } catch (Exception e) {
+            s_logger.warn("Exception: ", e);
+        }
+    }
+
+    @Override
+    public List<VMTemplateHostVO> listByHostId(long id) {
+        SearchCriteria<VMTemplateHostVO> sc = HostSearch.create();
+        sc.setParameters("host_id", id);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateHostVO> listByTemplateId(long templateId) {
+        SearchCriteria<VMTemplateHostVO> sc = TemplateSearch.create();
         sc.setParameters("template_id", templateId);
         sc.setParameters("destroyed", false);
-	    return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public VMTemplateHostVO findByHostTemplate(long hostId, long templateId) {
-		SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
-	    sc.setParameters("host_id", hostId);
-	    sc.setParameters("template_id", templateId);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateHostVO> listByOnlyTemplateId(long templateId) {
+        SearchCriteria<VMTemplateHostVO> sc = TemplateSearch.create();
+        sc.setParameters("template_id", templateId);
+        sc.setParameters("destroyed", false);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public VMTemplateHostVO findByHostTemplate(long hostId, long templateId) {
+        SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
+        sc.setParameters("host_id", hostId);
+        sc.setParameters("template_id", templateId);
         sc.setParameters("destroyed", false);
         return findOneIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public VMTemplateHostVO findByTemplateId(long templateId) {
-	    SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
-	    sc.setParameters("template_id", templateId);
-	    sc.setParameters("destroyed", false);
-	    return findOneIncludingRemovedBy(sc);
-	}
-	
-	@Override
-	public List<VMTemplateHostVO> listByTemplateStatus(long templateId, VMTemplateHostVO.Status downloadState) {
-		SearchCriteria<VMTemplateHostVO> sc = TemplateStatusSearch.create();
-		sc.setParameters("template_id", templateId);
-		sc.setParameters("download_state", downloadState.toString());
+    }
+
+    @Override
+    public VMTemplateHostVO findByTemplateId(long templateId) {
+        SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
+        sc.setParameters("template_id", templateId);
+        sc.setParameters("destroyed", false);
+        return findOneIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateHostVO> listByTemplateStatus(long templateId, VMTemplateHostVO.Status downloadState) {
+        SearchCriteria<VMTemplateHostVO> sc = TemplateStatusSearch.create();
+        sc.setParameters("template_id", templateId);
+        sc.setParameters("download_state", downloadState.toString());
         sc.setParameters("destroyed", false);
         return listIncludingRemovedBy(sc);
-	}
-	
-	@Override
-	public List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, VMTemplateHostVO.Status downloadState) {
+    }
+
+    @Override
+    public List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId,
+            VMTemplateHostVO.Status downloadState) {
         Transaction txn = Transaction.currentTxn();
-		PreparedStatement pstmt = null;
-		List<VMTemplateHostVO> result = new ArrayList<VMTemplateHostVO>();
-		try {
-			String sql = DOWNLOADS_STATE_DC;
-			pstmt = txn.prepareAutoCloseStatement(sql);
-			pstmt.setLong(1, datacenterId);
-			pstmt.setLong(2, templateId);
-			pstmt.setString(3, downloadState.toString());
-			ResultSet rs = pstmt.executeQuery();
-			while (rs.next()) {
+        PreparedStatement pstmt = null;
+        List<VMTemplateHostVO> result = new ArrayList<VMTemplateHostVO>();
+        try {
+            String sql = DOWNLOADS_STATE_DC;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setLong(1, datacenterId);
+            pstmt.setLong(2, templateId);
+            pstmt.setString(3, downloadState.toString());
+            ResultSet rs = pstmt.executeQuery();
+            while (rs.next()) {
                 result.add(toEntityBean(rs, false));
             }
-		} catch (Exception e) {
-			s_logger.warn("Exception: ", e);
-		}
-		return result;
-	}
+        } catch (Exception e) {
+            s_logger.warn("Exception: ", e);
+        }
+        return result;
+    }
 
     @Override
-    public List<VMTemplateHostVO> listByTemplateHostStatus(long templateId, long hostId, VMTemplateHostVO.Status... states) {       
+    public List<VMTemplateHostVO> listByTemplateHostStatus(long templateId, long hostId,
+            VMTemplateHostVO.Status... states) {
         SearchCriteria<VMTemplateHostVO> sc = HostTemplateStateSearch.create();
         sc.setParameters("template_id", templateId);
         sc.setParameters("host_id", hostId);
-        sc.setParameters("states", (Object[])states);
+        sc.setParameters("states", (Object[]) states);
         return search(sc, null);
     }
-	   
-	@Override
-	public List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateHostVO.Status downloadState) {
+
+    @Override
+    public List<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId,
+            VMTemplateHostVO.Status downloadState) {
         Transaction txn = Transaction.currentTxn();
-		PreparedStatement pstmt = null;
-		List<VMTemplateHostVO> result = new ArrayList<VMTemplateHostVO>();
-		ResultSet rs = null;
-		try {
-			String sql = DOWNLOADS_STATE_DC_POD;
-			pstmt = txn.prepareStatement(sql);
-			
-			pstmt.setLong(1, datacenterId);
-			pstmt.setLong(2, podId);
-			pstmt.setLong(3, templateId);
-			pstmt.setString(4, downloadState.toString());
-			rs = pstmt.executeQuery();
-			while (rs.next()) {
-                // result.add(toEntityBean(rs, false)); TODO: this is buggy in GenericDaoBase for hand constructed queries
-				long id = rs.getLong(1); //ID column
-				result.add(findById(id));
+        PreparedStatement pstmt = null;
+        List<VMTemplateHostVO> result = new ArrayList<VMTemplateHostVO>();
+        ResultSet rs = null;
+        try {
+            String sql = DOWNLOADS_STATE_DC_POD;
+            pstmt = txn.prepareStatement(sql);
+
+            pstmt.setLong(1, datacenterId);
+            pstmt.setLong(2, podId);
+            pstmt.setLong(3, templateId);
+            pstmt.setString(4, downloadState.toString());
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                // result.add(toEntityBean(rs, false)); TODO: this is buggy in
+                // GenericDaoBase for hand constructed queries
+                long id = rs.getLong(1); // ID column
+                result.add(findById(id));
             }
-		} catch (Exception e) {
-			s_logger.warn("Exception: ", e);
-		} finally {
-			try {
-				if (rs != null) {
-					rs.close();
-				}
-				if (pstmt != null) {
-					pstmt.close();
-				}
-			} catch (SQLException e) {
-			}
-		}
-		return result;
-
-	}
-
-	@Override
-	public boolean templateAvailable(long templateId, long hostId) {
-		VMTemplateHostVO tmpltHost = findByHostTemplate(hostId, templateId);
-		if (tmpltHost == null)
-		  return false;
-		
-		return tmpltHost.getDownloadState()==Status.DOWNLOADED;
-	}
-
-	@Override
-	public List<VMTemplateHostVO> listByTemplateStates(long templateId, VMTemplateHostVO.Status... states) {
-    	SearchCriteria<VMTemplateHostVO> sc = TemplateStatesSearch.create();
-    	sc.setParameters("states", (Object[])states);
-		sc.setParameters("template_id", templateId);
+        } catch (Exception e) {
+            s_logger.warn("Exception: ", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        return result;
+
+    }
+
+    @Override
+    public boolean templateAvailable(long templateId, long hostId) {
+        VMTemplateHostVO tmpltHost = findByHostTemplate(hostId, templateId);
+        if (tmpltHost == null)
+            return false;
+
+        return tmpltHost.getDownloadState() == Status.DOWNLOADED;
+    }
+
+    @Override
+    public List<VMTemplateHostVO> listByTemplateStates(long templateId, VMTemplateHostVO.Status... states) {
+        SearchCriteria<VMTemplateHostVO> sc = TemplateStatesSearch.create();
+        sc.setParameters("states", (Object[]) states);
+        sc.setParameters("template_id", templateId);
         sc.setParameters("destroyed", false);
         return search(sc, null);
-	}
+    }
 
     @Override
     public List<VMTemplateHostVO> listByState(VMTemplateHostVO.Status state) {
@@ -324,14 +329,14 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
         return search(sc, null);
     }
 
-	@Override
-	public List<VMTemplateHostVO> listByHostTemplate(long hostId, long templateId) {
-		SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
-	    sc.setParameters("host_id", hostId);
+    @Override
+    public List<VMTemplateHostVO> listByHostTemplate(long hostId, long templateId) {
+        SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
+        sc.setParameters("host_id", hostId);
         sc.setParameters("template_id", templateId);
         sc.setParameters("destroyed", false);
         return listIncludingRemovedBy(sc);
-	}
+    }
 
     @Override
     public List<VMTemplateHostVO> listByZoneTemplate(long dcId, long templateId, boolean readyOnly) {
@@ -340,61 +345,61 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
         sc.setJoinParameters("tmplHost", "zone_id", dcId);
         if (readyOnly) {
             sc.setParameters("state", VMTemplateHostVO.Status.DOWNLOADED);
-        } 
+        }
         return listBy(sc);
     }
-	
-	@Override
-	public List<VMTemplateHostVO> listDestroyed(long hostId) {
-		SearchCriteria<VMTemplateHostVO> sc = HostDestroyedSearch.create();
-		sc.setParameters("host_id", hostId);
-		sc.setParameters("destroyed", true);
-		return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public VMTemplateHostVO findByHostTemplate(long hostId, long templateId, boolean lock) {
-		SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
-	    sc.setParameters("host_id", hostId);
-	    sc.setParameters("template_id", templateId);
+
+    @Override
+    public List<VMTemplateHostVO> listDestroyed(long hostId) {
+        SearchCriteria<VMTemplateHostVO> sc = HostDestroyedSearch.create();
+        sc.setParameters("host_id", hostId);
+        sc.setParameters("destroyed", true);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public VMTemplateHostVO findByHostTemplate(long hostId, long templateId, boolean lock) {
+        SearchCriteria<VMTemplateHostVO> sc = HostTemplateSearch.create();
+        sc.setParameters("host_id", hostId);
+        sc.setParameters("template_id", templateId);
         sc.setParameters("destroyed", false);
-	    if (!lock)
-	    	return findOneIncludingRemovedBy(sc);
-	    else
-	    	return lockOneRandomRow(sc, true);
-	}
-	
-	//Based on computing node host id, and template id, find out the corresponding template_host_ref, assuming local secondary storage and computing node is in the same zone, and private ip
-	@Override 
-	public VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId) {
-	    HostVO computingHost = _hostDao.findById(hostId);
-	    SearchCriteria<VMTemplateHostVO> sc = LOCAL_SECONDARY_STORAGE_SEARCH.create();
-	    sc.setJoinParameters("host", "private_ip_address", computingHost.getPrivateIpAddress());
-	    sc.setJoinParameters("host", "state", com.cloud.host.Status.Up);
-	    sc.setJoinParameters("host", "data_center_id", computingHost.getDataCenterId());
-	    sc.setJoinParameters("host", "type", Host.Type.LocalSecondaryStorage);
-	    sc.setParameters("template_id", templateId);
-	    sc.setParameters("state", VMTemplateHostVO.Status.DOWNLOADED);
+        if (!lock)
+            return findOneIncludingRemovedBy(sc);
+        else
+            return lockOneRandomRow(sc, true);
+    }
+
+    // Based on computing node host id, and template id, find out the
+    // corresponding template_host_ref, assuming local secondary storage and
+    // computing node is in the same zone, and private ip
+    @Override
+    public VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId) {
+        HostVO computingHost = _hostDao.findById(hostId);
+        SearchCriteria<VMTemplateHostVO> sc = LOCAL_SECONDARY_STORAGE_SEARCH.create();
+        sc.setJoinParameters("host", "private_ip_address", computingHost.getPrivateIpAddress());
+        sc.setJoinParameters("host", "state", com.cloud.host.Status.Up);
+        sc.setJoinParameters("host", "data_center_id", computingHost.getDataCenterId());
+        sc.setJoinParameters("host", "type", Host.Type.LocalSecondaryStorage);
+        sc.setParameters("template_id", templateId);
+        sc.setParameters("state", VMTemplateHostVO.Status.DOWNLOADED);
         sc.setParameters("destroyed", false);
-	    return findOneBy(sc);
-	}
+        return findOneBy(sc);
+    }
 
     @Override
     public void deleteByHost(Long hostId) {
         List<VMTemplateHostVO> tmpltHosts = listByHostId(hostId);
-        for (VMTemplateHostVO tmpltHost : tmpltHosts ) {
+        for (VMTemplateHostVO tmpltHost : tmpltHosts) {
             remove(tmpltHost.getId());
         }
     }
-    
+
     @Override
-    public boolean updateState(State currentState, Event event,
-            State nextState, DataObjectInStore vo, Object data) {
-        VMTemplateHostVO templateHost = (VMTemplateHostVO)vo;
+    public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
+        VMTemplateHostVO templateHost = (VMTemplateHostVO) vo;
         Long oldUpdated = templateHost.getUpdatedCount();
         Date oldUpdatedTime = templateHost.getUpdated();
-    
-        
+
         SearchCriteria<VMTemplateHostVO> sc = updateStateSearch.create();
         sc.setParameters("id", templateHost.getId());
         sc.setParameters("state", currentState);
@@ -411,14 +416,19 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
             VMTemplateHostVO dbVol = findByIdIncludingRemoved(templateHost.getId());
             if (dbVol != null) {
                 StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
-                str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
+                str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState())
+                        .append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
                         .append(dbVol.getUpdated());
-                str.append(": New Data={id=").append(templateHost.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(templateHost.getUpdatedCount())
-                        .append("; updatedTime=").append(templateHost.getUpdated());
-                str.append(": stale Data={id=").append(templateHost.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated)
+                str.append(": New Data={id=").append(templateHost.getId()).append("; state=").append(nextState)
+                        .append("; event=").append(event).append("; updatecount=")
+                        .append(templateHost.getUpdatedCount()).append("; updatedTime=")
+                        .append(templateHost.getUpdated());
+                str.append(": stale Data={id=").append(templateHost.getId()).append("; state=").append(currentState)
+                        .append("; event=").append(event).append("; updatecount=").append(oldUpdated)
                         .append("; updatedTime=").append(oldUpdatedTime);
             } else {
-                s_logger.debug("Unable to update objectIndatastore: id=" + templateHost.getId() + ", as there is no such object exists in the database anymore");
+                s_logger.debug("Unable to update objectIndatastore: id=" + templateHost.getId()
+                        + ", as there is no such object exists in the database anymore");
             }
         }
         return rows > 0;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDao.java b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDao.java
index 501c3ca..7e6360b 100644
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDao.java
@@ -25,25 +25,29 @@ import com.cloud.storage.VMTemplateStoragePoolVO;
 import com.cloud.utils.db.GenericDao;
 import com.cloud.utils.fsm.StateDao;
 
-public interface VMTemplatePoolDao extends GenericDao<VMTemplateStoragePoolVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
-	public List<VMTemplateStoragePoolVO> listByPoolId(long id);
-	
-	public List<VMTemplateStoragePoolVO> listByTemplateId(long templateId);
-	
-	public VMTemplateStoragePoolVO findByPoolTemplate(long poolId, long templateId);
+public interface VMTemplatePoolDao extends GenericDao<VMTemplateStoragePoolVO, Long>,
+        StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
+    public List<VMTemplateStoragePoolVO> listByPoolId(long id);
 
-	public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, VMTemplateStoragePoolVO.Status downloadState);
-	
-    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId,  VMTemplateStoragePoolVO.Status downloadState, long poolId);
+    public List<VMTemplateStoragePoolVO> listByTemplateId(long templateId);
 
-	public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, VMTemplateStoragePoolVO.Status downloadState);
-	
-	public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateStoragePoolVO.Status downloadState);
+    public VMTemplateStoragePoolVO findByPoolTemplate(long poolId, long templateId);
 
-	public List<VMTemplateStoragePoolVO> listByTemplateStates(long templateId, VMTemplateStoragePoolVO.Status ... states);
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId,
+            VMTemplateStoragePoolVO.Status downloadState);
 
-	
-	boolean templateAvailable(long templateId, long poolId);
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId,
+            VMTemplateStoragePoolVO.Status downloadState, long poolId);
 
-	public VMTemplateStoragePoolVO findByHostTemplate(Long hostId, Long templateId);
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId,
+            VMTemplateStoragePoolVO.Status downloadState);
+
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId,
+            VMTemplateStoragePoolVO.Status downloadState);
+
+    public List<VMTemplateStoragePoolVO> listByTemplateStates(long templateId, VMTemplateStoragePoolVO.Status... states);
+
+    boolean templateAvailable(long templateId, long poolId);
+
+    public VMTemplateStoragePoolVO findByHostTemplate(Long hostId, Long templateId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java
index 5f212eb..ba8135b 100644
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java
@@ -42,105 +42,104 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.UpdateBuilder;
 
 @Component
-@Local(value={VMTemplatePoolDao.class})
+@Local(value = { VMTemplatePoolDao.class })
 public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolVO, Long> implements VMTemplatePoolDao {
-	public static final Logger s_logger = Logger.getLogger(VMTemplatePoolDaoImpl.class.getName());
-	
-	protected final SearchBuilder<VMTemplateStoragePoolVO> PoolSearch;
-	protected final SearchBuilder<VMTemplateStoragePoolVO> TemplateSearch;
-	protected final SearchBuilder<VMTemplateStoragePoolVO> PoolTemplateSearch;
-	protected final SearchBuilder<VMTemplateStoragePoolVO> TemplateStatusSearch;
+    public static final Logger s_logger = Logger.getLogger(VMTemplatePoolDaoImpl.class.getName());
+
+    protected final SearchBuilder<VMTemplateStoragePoolVO> PoolSearch;
+    protected final SearchBuilder<VMTemplateStoragePoolVO> TemplateSearch;
+    protected final SearchBuilder<VMTemplateStoragePoolVO> PoolTemplateSearch;
+    protected final SearchBuilder<VMTemplateStoragePoolVO> TemplateStatusSearch;
     protected final SearchBuilder<VMTemplateStoragePoolVO> TemplatePoolStatusSearch;
-	protected final SearchBuilder<VMTemplateStoragePoolVO> TemplateStatesSearch;
-	protected final SearchBuilder<VMTemplateStoragePoolVO> updateStateSearch;
-	
-	protected static final String UPDATE_TEMPLATE_HOST_REF =
-		"UPDATE template_spool_ref SET download_state = ?, download_pct= ?, last_updated = ? "
-	+   ", error_str = ?, local_path = ?, job_id = ? "
-	+   "WHERE pool_id = ? and template_id = ?";
-	
-	protected static final String DOWNLOADS_STATE_DC=
-		"SELECT * FROM template_spool_ref t, storage_pool p where t.pool_id = p.id and p.data_center_id=? "
-	+	" and t.template_id=? and t.download_state = ?" ;
-	
-	protected static final String DOWNLOADS_STATE_DC_POD=
-		"SELECT * FROM template_spool_ref tp, storage_pool_host_ref ph, host h where tp.pool_id = ph.pool_id and ph.host_id = h.id and h.data_center_id=? and h.pod_id=? "
-	+	" and tp.template_id=? and tp.download_state=?" ;
-	
-	protected static final String HOST_TEMPLATE_SEARCH=
-		"SELECT * FROM template_spool_ref tp, storage_pool_host_ref ph, host h where tp.pool_id = ph.pool_id and ph.host_id = h.id and h.id=? "
-	+	" and tp.template_id=? " ;
-	
-	
-	public VMTemplatePoolDaoImpl () {
-		PoolSearch = createSearchBuilder();
-		PoolSearch.and("pool_id", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
-		PoolSearch.done();
-		
-		TemplateSearch = createSearchBuilder();
-		TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplateSearch.done();
-		
-		PoolTemplateSearch = createSearchBuilder();
-		PoolTemplateSearch.and("pool_id", PoolTemplateSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
-		PoolTemplateSearch.and("template_id", PoolTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		PoolTemplateSearch.done();
-		
-		TemplateStatusSearch = createSearchBuilder();
-		TemplateStatusSearch.and("template_id", TemplateStatusSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplateStatusSearch.and("download_state", TemplateStatusSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
-		TemplateStatusSearch.done();
-
-		TemplatePoolStatusSearch = createSearchBuilder();
-		TemplatePoolStatusSearch.and("pool_id", TemplatePoolStatusSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
-		TemplatePoolStatusSearch.and("template_id", TemplatePoolStatusSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplatePoolStatusSearch.and("download_state", TemplatePoolStatusSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
-		TemplatePoolStatusSearch.done();
+    protected final SearchBuilder<VMTemplateStoragePoolVO> TemplateStatesSearch;
+    protected final SearchBuilder<VMTemplateStoragePoolVO> updateStateSearch;
+
+    protected static final String UPDATE_TEMPLATE_HOST_REF = "UPDATE template_spool_ref SET download_state = ?, download_pct= ?, last_updated = ? "
+            + ", error_str = ?, local_path = ?, job_id = ? " + "WHERE pool_id = ? and template_id = ?";
+
+    protected static final String DOWNLOADS_STATE_DC = "SELECT * FROM template_spool_ref t, storage_pool p where t.pool_id = p.id and p.data_center_id=? "
+            + " and t.template_id=? and t.download_state = ?";
+
+    protected static final String DOWNLOADS_STATE_DC_POD = "SELECT * FROM template_spool_ref tp, storage_pool_host_ref ph, host h where tp.pool_id = ph.pool_id and ph.host_id = h.id and h.data_center_id=? and h.pod_id=? "
+            + " and tp.template_id=? and tp.download_state=?";
+
+    protected static final String HOST_TEMPLATE_SEARCH = "SELECT * FROM template_spool_ref tp, storage_pool_host_ref ph, host h where tp.pool_id = ph.pool_id and ph.host_id = h.id and h.id=? "
+            + " and tp.template_id=? ";
+
+    public VMTemplatePoolDaoImpl() {
+        PoolSearch = createSearchBuilder();
+        PoolSearch.and("pool_id", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
+        PoolSearch.done();
+
+        TemplateSearch = createSearchBuilder();
+        TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateSearch.done();
+
+        PoolTemplateSearch = createSearchBuilder();
+        PoolTemplateSearch.and("pool_id", PoolTemplateSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
+        PoolTemplateSearch.and("template_id", PoolTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        PoolTemplateSearch.done();
+
+        TemplateStatusSearch = createSearchBuilder();
+        TemplateStatusSearch.and("template_id", TemplateStatusSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateStatusSearch.and("download_state", TemplateStatusSearch.entity().getDownloadState(),
+                SearchCriteria.Op.EQ);
+        TemplateStatusSearch.done();
+
+        TemplatePoolStatusSearch = createSearchBuilder();
+        TemplatePoolStatusSearch.and("pool_id", TemplatePoolStatusSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
+        TemplatePoolStatusSearch.and("template_id", TemplatePoolStatusSearch.entity().getTemplateId(),
+                SearchCriteria.Op.EQ);
+        TemplatePoolStatusSearch.and("download_state", TemplatePoolStatusSearch.entity().getDownloadState(),
+                SearchCriteria.Op.EQ);
+        TemplatePoolStatusSearch.done();
 
         TemplateStatesSearch = createSearchBuilder();
-		TemplateStatesSearch.and("template_id", TemplateStatesSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplateStatesSearch.and("states", TemplateStatesSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
-		TemplateStatesSearch.done();
-
-		updateStateSearch = this.createSearchBuilder();
-		updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
-		updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
-		updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
-		updateStateSearch.done();
-	}
-
-	@Override
-	public List<VMTemplateStoragePoolVO> listByPoolId(long id) {
-	    SearchCriteria<VMTemplateStoragePoolVO> sc = PoolSearch.create();
-	    sc.setParameters("pool_id", id);
-	    return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public List<VMTemplateStoragePoolVO> listByTemplateId(long templateId) {
-	    SearchCriteria<VMTemplateStoragePoolVO> sc = TemplateSearch.create();
-	    sc.setParameters("template_id", templateId);
-	    return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public VMTemplateStoragePoolVO findByPoolTemplate(long hostId, long templateId) {
-		SearchCriteria<VMTemplateStoragePoolVO> sc = PoolTemplateSearch.create();
-	    sc.setParameters("pool_id", hostId);
-	    sc.setParameters("template_id", templateId);
-	    return findOneIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, VMTemplateStoragePoolVO.Status downloadState) {
-		SearchCriteria<VMTemplateStoragePoolVO> sc = TemplateStatusSearch.create();
-		sc.setParameters("template_id", templateId);
-		sc.setParameters("download_state", downloadState.toString());
-		return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, VMTemplateStoragePoolVO.Status downloadState, long poolId) {
+        TemplateStatesSearch.and("template_id", TemplateStatesSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateStatesSearch.and("states", TemplateStatesSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
+        TemplateStatesSearch.done();
+
+        updateStateSearch = this.createSearchBuilder();
+        updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
+        updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
+        updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ);
+        updateStateSearch.done();
+    }
+
+    @Override
+    public List<VMTemplateStoragePoolVO> listByPoolId(long id) {
+        SearchCriteria<VMTemplateStoragePoolVO> sc = PoolSearch.create();
+        sc.setParameters("pool_id", id);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateStoragePoolVO> listByTemplateId(long templateId) {
+        SearchCriteria<VMTemplateStoragePoolVO> sc = TemplateSearch.create();
+        sc.setParameters("template_id", templateId);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public VMTemplateStoragePoolVO findByPoolTemplate(long hostId, long templateId) {
+        SearchCriteria<VMTemplateStoragePoolVO> sc = PoolTemplateSearch.create();
+        sc.setParameters("pool_id", hostId);
+        sc.setParameters("template_id", templateId);
+        return findOneIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId,
+            VMTemplateStoragePoolVO.Status downloadState) {
+        SearchCriteria<VMTemplateStoragePoolVO> sc = TemplateStatusSearch.create();
+        sc.setParameters("template_id", templateId);
+        sc.setParameters("download_state", downloadState.toString());
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId,
+            VMTemplateStoragePoolVO.Status downloadState, long poolId) {
         SearchCriteria<VMTemplateStoragePoolVO> sc = TemplatePoolStatusSearch.create();
         sc.setParameters("pool_id", poolId);
         sc.setParameters("template_id", templateId);
@@ -148,130 +147,133 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolV
         return listIncludingRemovedBy(sc);
     }
 
-	@Override
-	public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, VMTemplateStoragePoolVO.Status downloadState) {
+    @Override
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId,
+            VMTemplateStoragePoolVO.Status downloadState) {
         Transaction txn = Transaction.currentTxn();
-		PreparedStatement pstmt = null;
-		List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
-		try {
-			String sql = DOWNLOADS_STATE_DC;
-			pstmt = txn.prepareAutoCloseStatement(sql);
-			pstmt.setLong(1, datacenterId);
-			pstmt.setLong(2, templateId);
-			pstmt.setString(3, downloadState.toString());
-			ResultSet rs = pstmt.executeQuery();
-			while (rs.next()) {
+        PreparedStatement pstmt = null;
+        List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
+        try {
+            String sql = DOWNLOADS_STATE_DC;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setLong(1, datacenterId);
+            pstmt.setLong(2, templateId);
+            pstmt.setString(3, downloadState.toString());
+            ResultSet rs = pstmt.executeQuery();
+            while (rs.next()) {
                 result.add(toEntityBean(rs, false));
             }
-		} catch (Exception e) {
-			s_logger.warn("Exception: ", e);
-		}
-		return result;
-
-	}
-	
-	@Override
-	public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateStoragePoolVO.Status downloadState) {
+        } catch (Exception e) {
+            s_logger.warn("Exception: ", e);
+        }
+        return result;
+
+    }
+
+    @Override
+    public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId,
+            VMTemplateStoragePoolVO.Status downloadState) {
         Transaction txn = Transaction.currentTxn();
-		PreparedStatement pstmt = null;
-		List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
-		ResultSet rs = null;
-		try {
-			String sql = DOWNLOADS_STATE_DC_POD;
-			pstmt = txn.prepareStatement(sql);
-			
-			pstmt.setLong(1, datacenterId);
-			pstmt.setLong(2, podId);
-			pstmt.setLong(3, templateId);
-			pstmt.setString(4, downloadState.toString());
-			rs = pstmt.executeQuery();
-			while (rs.next()) {
-                // result.add(toEntityBean(rs, false)); TODO: this is buggy in GenericDaoBase for hand constructed queries
-				long id = rs.getLong(1); //ID column
-				result.add(findById(id));
+        PreparedStatement pstmt = null;
+        List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
+        ResultSet rs = null;
+        try {
+            String sql = DOWNLOADS_STATE_DC_POD;
+            pstmt = txn.prepareStatement(sql);
+
+            pstmt.setLong(1, datacenterId);
+            pstmt.setLong(2, podId);
+            pstmt.setLong(3, templateId);
+            pstmt.setString(4, downloadState.toString());
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                // result.add(toEntityBean(rs, false)); TODO: this is buggy in
+                // GenericDaoBase for hand constructed queries
+                long id = rs.getLong(1); // ID column
+                result.add(findById(id));
             }
-		} catch (Exception e) {
-			s_logger.warn("Exception: ", e);
-		} finally {
-			try {
-				if (rs != null) {
-					rs.close();
-				}
-				if (pstmt != null) {
-					pstmt.close();
-				}
-			} catch (SQLException e) {
-			}
-		}
-		return result;
-
-	}
-	
-	public List<VMTemplateStoragePoolVO> listByHostTemplate(long hostId, long templateId) {
+        } catch (Exception e) {
+            s_logger.warn("Exception: ", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        return result;
+
+    }
+
+    public List<VMTemplateStoragePoolVO> listByHostTemplate(long hostId, long templateId) {
         Transaction txn = Transaction.currentTxn();
-		PreparedStatement pstmt = null;
-		List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
-		ResultSet rs = null;
-		try {
-			String sql = HOST_TEMPLATE_SEARCH;
-			pstmt = txn.prepareStatement(sql);
-			
-			pstmt.setLong(1, hostId);
-			pstmt.setLong(2, templateId);
-			rs = pstmt.executeQuery();
-			while (rs.next()) {
-                // result.add(toEntityBean(rs, false)); TODO: this is buggy in GenericDaoBase for hand constructed queries
-				long id = rs.getLong(1); //ID column
-				result.add(findById(id));
+        PreparedStatement pstmt = null;
+        List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
+        ResultSet rs = null;
+        try {
+            String sql = HOST_TEMPLATE_SEARCH;
+            pstmt = txn.prepareStatement(sql);
+
+            pstmt.setLong(1, hostId);
+            pstmt.setLong(2, templateId);
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                // result.add(toEntityBean(rs, false)); TODO: this is buggy in
+                // GenericDaoBase for hand constructed queries
+                long id = rs.getLong(1); // ID column
+                result.add(findById(id));
             }
-		} catch (Exception e) {
-			s_logger.warn("Exception: ", e);
-		} finally {
-			try {
-				if (rs != null) {
-					rs.close();
-				}
-				if (pstmt != null) {
-					pstmt.close();
-				}
-			} catch (SQLException e) {
-			}
-		}
-		return result;
-
-	}
-
-	@Override
-	public boolean templateAvailable(long templateId, long hostId) {
-		VMTemplateStorageResourceAssoc tmpltPool = findByPoolTemplate(hostId, templateId);
-		if (tmpltPool == null)
-		  return false;
-		
-		return tmpltPool.getDownloadState()==Status.DOWNLOADED;
-	}
-
-	@Override
-	public List<VMTemplateStoragePoolVO> listByTemplateStates(long templateId, VMTemplateStoragePoolVO.Status... states) {
-    	SearchCriteria<VMTemplateStoragePoolVO> sc = TemplateStatesSearch.create();
-    	sc.setParameters("states", (Object[])states);
-		sc.setParameters("template_id", templateId);
-
-	  	return search(sc, null);
-	}
-
-	@Override
-	public VMTemplateStoragePoolVO findByHostTemplate(Long hostId, Long templateId) {
-		List<VMTemplateStoragePoolVO> result = listByHostTemplate(hostId, templateId);
-		return (result.size() == 0)?null:result.get(1);
-	}
+        } catch (Exception e) {
+            s_logger.warn("Exception: ", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        return result;
+
+    }
+
+    @Override
+    public boolean templateAvailable(long templateId, long hostId) {
+        VMTemplateStorageResourceAssoc tmpltPool = findByPoolTemplate(hostId, templateId);
+        if (tmpltPool == null)
+            return false;
+
+        return tmpltPool.getDownloadState() == Status.DOWNLOADED;
+    }
 
     @Override
-    public boolean updateState(State currentState, Event event,
-            State nextState, DataObjectInStore vo, Object data) {
-        VMTemplateStoragePoolVO templatePool = (VMTemplateStoragePoolVO)vo;
+    public List<VMTemplateStoragePoolVO> listByTemplateStates(long templateId, VMTemplateStoragePoolVO.Status... states) {
+        SearchCriteria<VMTemplateStoragePoolVO> sc = TemplateStatesSearch.create();
+        sc.setParameters("states", (Object[]) states);
+        sc.setParameters("template_id", templateId);
+
+        return search(sc, null);
+    }
+
+    @Override
+    public VMTemplateStoragePoolVO findByHostTemplate(Long hostId, Long templateId) {
+        List<VMTemplateStoragePoolVO> result = listByHostTemplate(hostId, templateId);
+        return (result.size() == 0) ? null : result.get(1);
+    }
+
+    @Override
+    public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
+        VMTemplateStoragePoolVO templatePool = (VMTemplateStoragePoolVO) vo;
         Long oldUpdated = templatePool.getUpdatedCount();
         Date oldUpdatedTime = templatePool.getUpdated();
-    
+
         SearchCriteria<VMTemplateStoragePoolVO> sc = updateStateSearch.create();
         sc.setParameters("id", templatePool.getId());
         sc.setParameters("state", currentState);
@@ -288,14 +290,19 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolV
             VMTemplateStoragePoolVO dbVol = findByIdIncludingRemoved(templatePool.getId());
             if (dbVol != null) {
                 StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
-                str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
+                str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState())
+                        .append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
                         .append(dbVol.getUpdated());
-                str.append(": New Data={id=").append(templatePool.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(templatePool.getUpdatedCount())
-                        .append("; updatedTime=").append(templatePool.getUpdated());
-                str.append(": stale Data={id=").append(templatePool.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated)
+                str.append(": New Data={id=").append(templatePool.getId()).append("; state=").append(nextState)
+                        .append("; event=").append(event).append("; updatecount=")
+                        .append(templatePool.getUpdatedCount()).append("; updatedTime=")
+                        .append(templatePool.getUpdated());
+                str.append(": stale Data={id=").append(templatePool.getId()).append("; state=").append(currentState)
+                        .append("; event=").append(event).append("; updatecount=").append(oldUpdated)
                         .append("; updatedTime=").append(oldUpdatedTime);
             } else {
-                s_logger.debug("Unable to update objectIndatastore: id=" + templatePool.getId() + ", as there is no such object exists in the database anymore");
+                s_logger.debug("Unable to update objectIndatastore: id=" + templatePool.getId()
+                        + ", as there is no such object exists in the database anymore");
             }
         }
         return rows > 0;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplateS3DaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateS3DaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateS3DaoImpl.java
index 7cfd3b5..d49645d 100644
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateS3DaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateS3DaoImpl.java
@@ -34,8 +34,7 @@ import java.util.List;
 
 @Component
 @Local(VMTemplateS3Dao.class)
-public class VMTemplateS3DaoImpl extends GenericDaoBase<VMTemplateS3VO, Long>
-        implements VMTemplateS3Dao {
+public class VMTemplateS3DaoImpl extends GenericDaoBase<VMTemplateS3VO, Long> implements VMTemplateS3Dao {
 
     private final SearchBuilder<VMTemplateS3VO> searchBuilder;
 
@@ -44,19 +43,15 @@ public class VMTemplateS3DaoImpl extends GenericDaoBase<VMTemplateS3VO, Long>
         super();
 
         this.searchBuilder = createSearchBuilder();
-        this.searchBuilder
-                .and(S3_ID_COLUMN_NAME, this.searchBuilder.entity().getS3Id(),
-                        EQ)
-                .and(TEMPLATE_ID_COLUMN_NAME,
-                        this.searchBuilder.entity().getTemplateId(), EQ).done();
+        this.searchBuilder.and(S3_ID_COLUMN_NAME, this.searchBuilder.entity().getS3Id(), EQ)
+                .and(TEMPLATE_ID_COLUMN_NAME, this.searchBuilder.entity().getTemplateId(), EQ).done();
 
     }
 
     @Override
     public List<VMTemplateS3VO> listByS3Id(final long s3id) {
 
-        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder
-                .create();
+        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder.create();
 
         criteria.setParameters(S3_ID_COLUMN_NAME, s3id);
 
@@ -67,8 +62,7 @@ public class VMTemplateS3DaoImpl extends GenericDaoBase<VMTemplateS3VO, Long>
     @Override
     public VMTemplateS3VO findOneByTemplateId(final long templateId) {
 
-        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder
-                .create();
+        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder.create();
 
         criteria.setParameters(TEMPLATE_ID_COLUMN_NAME, templateId);
 
@@ -77,11 +71,9 @@ public class VMTemplateS3DaoImpl extends GenericDaoBase<VMTemplateS3VO, Long>
     }
 
     @Override
-    public VMTemplateS3VO findOneByS3Template(final long s3Id,
-            final long templateId) {
+    public VMTemplateS3VO findOneByS3Template(final long s3Id, final long templateId) {
 
-        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder
-                .create();
+        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder.create();
 
         criteria.setParameters(S3_ID_COLUMN_NAME, s3Id);
         criteria.setParameters(TEMPLATE_ID_COLUMN_NAME, templateId);
@@ -93,8 +85,7 @@ public class VMTemplateS3DaoImpl extends GenericDaoBase<VMTemplateS3VO, Long>
     @Override
     public void expungeAllByTemplateId(long templateId) {
 
-        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder
-                .create();
+        final SearchCriteria<VMTemplateS3VO> criteria = this.searchBuilder.create();
 
         criteria.setParameters(TEMPLATE_ID_COLUMN_NAME, templateId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
index 27e05c9..67f7c3f 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
@@ -22,11 +22,11 @@ import com.cloud.storage.VMTemplateZoneVO;
 import com.cloud.utils.db.GenericDao;
 
 public interface VMTemplateZoneDao extends GenericDao<VMTemplateZoneVO, Long> {
-	public List<VMTemplateZoneVO> listByZoneId(long id);
+    public List<VMTemplateZoneVO> listByZoneId(long id);
 
-	public List<VMTemplateZoneVO> listByTemplateId(long templateId);
+    public List<VMTemplateZoneVO> listByTemplateId(long templateId);
 
-	public VMTemplateZoneVO findByZoneTemplate(long zoneId, long templateId);
+    public VMTemplateZoneVO findByZoneTemplate(long zoneId, long templateId);
 
     public List<VMTemplateZoneVO> listByZoneTemplate(Long zoneId, long templateId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
index 27b554c..c4a4dc7 100644
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
@@ -20,7 +20,6 @@ import java.util.List;
 
 import javax.ejb.Local;
 
-import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -31,63 +30,60 @@ import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 
 @Component
-@Local(value={VMTemplateZoneDao.class})
+@Local(value = { VMTemplateZoneDao.class })
 public class VMTemplateZoneDaoImpl extends GenericDaoBase<VMTemplateZoneVO, Long> implements VMTemplateZoneDao {
-	public static final Logger s_logger = Logger.getLogger(VMTemplateZoneDaoImpl.class.getName());
-
-	protected final SearchBuilder<VMTemplateZoneVO> ZoneSearch;
-	protected final SearchBuilder<VMTemplateZoneVO> TemplateSearch;
-	protected final SearchBuilder<VMTemplateZoneVO> ZoneTemplateSearch;
-
-
-	public VMTemplateZoneDaoImpl () {
-		ZoneSearch = createSearchBuilder();
-		ZoneSearch.and("zone_id", ZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
-		ZoneSearch.done();
-
-		TemplateSearch = createSearchBuilder();
-		TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		TemplateSearch.done();
-
-		ZoneTemplateSearch = createSearchBuilder();
-		ZoneTemplateSearch.and("zone_id", ZoneTemplateSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
-		ZoneTemplateSearch.and("template_id", ZoneTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
-		ZoneTemplateSearch.done();
-	}
-
-
-	@Override
-	public List<VMTemplateZoneVO> listByZoneId(long id) {
-	    SearchCriteria<VMTemplateZoneVO> sc = ZoneSearch.create();
-	    sc.setParameters("zone_id", id);
-	    return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public List<VMTemplateZoneVO> listByTemplateId(long templateId) {
-	    SearchCriteria<VMTemplateZoneVO> sc = TemplateSearch.create();
-	    sc.setParameters("template_id", templateId);
-	    return listIncludingRemovedBy(sc);
-	}
-
-	@Override
-	public VMTemplateZoneVO findByZoneTemplate(long zoneId, long templateId) {
-		SearchCriteria<VMTemplateZoneVO> sc = ZoneTemplateSearch.create();
-	    sc.setParameters("zone_id", zoneId);
-	    sc.setParameters("template_id", templateId);
-	    return findOneIncludingRemovedBy(sc);
-	}
-
-	@Override
+    public static final Logger s_logger = Logger.getLogger(VMTemplateZoneDaoImpl.class.getName());
+
+    protected final SearchBuilder<VMTemplateZoneVO> ZoneSearch;
+    protected final SearchBuilder<VMTemplateZoneVO> TemplateSearch;
+    protected final SearchBuilder<VMTemplateZoneVO> ZoneTemplateSearch;
+
+    public VMTemplateZoneDaoImpl() {
+        ZoneSearch = createSearchBuilder();
+        ZoneSearch.and("zone_id", ZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
+        ZoneSearch.done();
+
+        TemplateSearch = createSearchBuilder();
+        TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        TemplateSearch.done();
+
+        ZoneTemplateSearch = createSearchBuilder();
+        ZoneTemplateSearch.and("zone_id", ZoneTemplateSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
+        ZoneTemplateSearch.and("template_id", ZoneTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
+        ZoneTemplateSearch.done();
+    }
+
+    @Override
+    public List<VMTemplateZoneVO> listByZoneId(long id) {
+        SearchCriteria<VMTemplateZoneVO> sc = ZoneSearch.create();
+        sc.setParameters("zone_id", id);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<VMTemplateZoneVO> listByTemplateId(long templateId) {
+        SearchCriteria<VMTemplateZoneVO> sc = TemplateSearch.create();
+        sc.setParameters("template_id", templateId);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public VMTemplateZoneVO findByZoneTemplate(long zoneId, long templateId) {
+        SearchCriteria<VMTemplateZoneVO> sc = ZoneTemplateSearch.create();
+        sc.setParameters("zone_id", zoneId);
+        sc.setParameters("template_id", templateId);
+        return findOneIncludingRemovedBy(sc);
+    }
+
+    @Override
     public List<VMTemplateZoneVO> listByZoneTemplate(Long zoneId, long templateId) {
-		SearchCriteria<VMTemplateZoneVO> sc = ZoneTemplateSearch.create();
+        SearchCriteria<VMTemplateZoneVO> sc = ZoneTemplateSearch.create();
         if (zoneId != null) {
             sc.setParameters("zone_id", zoneId);
         }
-	    sc.setParameters("template_id", templateId);
-	    return listBy(sc);
-	}
-
+        sc.setParameters("template_id", templateId);
+        return listBy(sc);
+    }
 
     @Override
     public void deletePrimaryRecordsForTemplate(long templateId) {
@@ -100,5 +96,4 @@ public class VMTemplateZoneDaoImpl extends GenericDaoBase<VMTemplateZoneVO, Long
 
     }
 
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
index 2513181..79c0dc3 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
@@ -62,7 +62,7 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
 
     List<VolumeVO> findUsableVolumesForInstance(long instanceId);
 
-    Long countAllocatedVolumesForAccount(long accountId); 
+    Long countAllocatedVolumesForAccount(long accountId);
 
     HypervisorType getHypervisorType(long volumeId);
 
@@ -76,15 +76,16 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
 
     /**
      * Gets the Total Primary Storage space allocated for an account
-     *
+     * 
      * @param account
      * @return total Primary Storage space (in bytes) used
      */
     long primaryStorageUsedForAccount(long accountId);
 
     /**
-     * Gets the Total Secondary Storage space used by volumes allocated for an account
-     *
+     * Gets the Total Secondary Storage space used by volumes allocated for an
+     * account
+     * 
      * @param account
      * @return total Secondary Storage space (in bytes) used
      */


Mime
View raw message