You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/04/09 01:18:28 UTC

[1/2] add DeleteImageStoreCmd Api.

Updated Branches:
  refs/heads/object_store 7f64b61cb -> 74880fa26


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreVO.java b/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreVO.java
deleted file mode 100755
index b27a4ba..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreVO.java
+++ /dev/null
@@ -1,348 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
-
-import com.cloud.storage.Storage;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.fsm.StateObject;
-
-/**
- * Join table for image_data_store and volumes
- *
- */
-@Entity
-@Table(name="volume_store_ref")
-public class VolumeDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
-	@Id
-	@GeneratedValue(strategy=GenerationType.IDENTITY)
-	Long id;
-
-	@Column(name="store_id")
-	private long dataStoreId;
-
-	@Column(name="volume_id")
-	private long volumeId;
-
-	@Column(name="zone_id")
-	private long zoneId;
-
-	@Column(name=GenericDaoBase.CREATED_COLUMN)
-	private Date created = null;
-
-	@Column(name="last_updated")
-	@Temporal(value=TemporalType.TIMESTAMP)
-	private Date lastUpdated = null;
-
-	@Column (name="download_pct")
-	private int downloadPercent;
-
-	@Column (name="size")
-	private long size;
-
-	@Column (name="physical_size")
-	private long physicalSize;
-
-	@Column (name="download_state")
-	@Enumerated(EnumType.STRING)
-	private Status downloadState;
-
-    @Column(name="checksum")
-    private String checksum;
-
-	@Column (name="local_path")
-	private String localDownloadPath;
-
-	@Column (name="error_str")
-	private String errorString;
-
-	@Column (name="job_id")
-	private String jobId;
-
-	@Column (name="install_path")
-    private String installPath;
-
-	@Column (name="url")
-	private String downloadUrl;
-
-	@Column(name="format")
-    private Storage.ImageFormat format;
-
-    @Column(name="destroyed")
-    boolean destroyed = false;
-
-    @Column(name="update_count", updatable = true, nullable=false)
-    protected long updatedCount;
-
-    @Column(name = "updated")
-    @Temporal(value = TemporalType.TIMESTAMP)
-    Date updated;
-
-    @Column(name = "state")
-    @Enumerated(EnumType.STRING)
-    ObjectInDataStoreStateMachine.State state;
-
-    public String getInstallPath() {
-		return installPath;
-	}
-
-	public long getDataStoreId() {
-		return dataStoreId;
-	}
-
-	public void setHostId(long hostId) {
-		this.dataStoreId = hostId;
-	}
-
-
-    public long getVolumeId() {
-		return volumeId;
-	}
-
-
-    public void setVolumeId(long volumeId) {
-		this.volumeId = volumeId;
-	}
-
-
-    public long getZoneId() {
-		return zoneId;
-	}
-
-	public void setZoneId(long zoneId) {
-		this.zoneId = zoneId;
-	}
-
-	public int getDownloadPercent() {
-		return downloadPercent;
-	}
-
-
-    public void setDownloadPercent(int downloadPercent) {
-		this.downloadPercent = downloadPercent;
-	}
-
-
-    public void setDownloadState(Status downloadState) {
-		this.downloadState = downloadState;
-	}
-
-
-    public long getId() {
-		return id;
-	}
-
-
-    public Date getCreated() {
-		return created;
-	}
-
-
-    public Date getLastUpdated() {
-		return lastUpdated;
-	}
-
-
-    public void setLastUpdated(Date date) {
-	    lastUpdated = date;
-	}
-
-
-    public void setInstallPath(String installPath) {
-	    this.installPath = installPath;
-	}
-
-
-    public Status getDownloadState() {
-		return downloadState;
-	}
-
-	public String getChecksum() {
-		return checksum;
-	}
-
-	public void setChecksum(String checksum) {
-		this.checksum = checksum;
-	}
-
-	public VolumeDataStoreVO(long hostId, long volumeId) {
-		super();
-		this.dataStoreId = hostId;
-		this.volumeId = volumeId;
-		this.state = ObjectInDataStoreStateMachine.State.Allocated;
-	}
-
-	public VolumeDataStoreVO(long hostId, long volumeId, long zoneId, Date lastUpdated,
-			int downloadPercent, Status downloadState,
-			String localDownloadPath, String errorString, String jobId,
-			String installPath, String downloadUrl, String checksum, ImageFormat format) {
-		//super();
-		this.dataStoreId = hostId;
-		this.volumeId = volumeId;
-		this.zoneId = zoneId;
-		this.lastUpdated = lastUpdated;
-		this.downloadPercent = downloadPercent;
-		this.downloadState = downloadState;
-		this.localDownloadPath = localDownloadPath;
-		this.errorString = errorString;
-		this.jobId = jobId;
-		this.installPath = installPath;
-		this.setDownloadUrl(downloadUrl);
-		this.checksum = checksum;
-		this.format = format;
-	}
-
-	protected VolumeDataStoreVO() {
-
-	}
-
-
-    public void setLocalDownloadPath(String localPath) {
-		this.localDownloadPath = localPath;
-	}
-
-
-    public String getLocalDownloadPath() {
-		return localDownloadPath;
-	}
-
-
-    public void setErrorString(String errorString) {
-		this.errorString = errorString;
-	}
-
-
-    public String getErrorString() {
-		return errorString;
-	}
-
-
-    public void setJobId(String jobId) {
-		this.jobId = jobId;
-	}
-
-
-    public String getJobId() {
-		return jobId;
-	}
-
-
-	public boolean equals(Object obj) {
-		if (obj instanceof VolumeDataStoreVO) {
-			VolumeDataStoreVO other = (VolumeDataStoreVO)obj;
-			return (this.volumeId==other.getVolumeId() && this.dataStoreId==other.getDataStoreId());
-		}
-		return false;
-	}
-
-
-	public int hashCode() {
-		Long tid = new Long(volumeId);
-		Long hid = new Long(dataStoreId);
-		return tid.hashCode()+hid.hashCode();
-	}
-
-    public void setSize(long size) {
-        this.size = size;
-    }
-
-    public long getSize() {
-        return size;
-    }
-
-
-    public void setPhysicalSize(long physicalSize) {
-        this.physicalSize = physicalSize;
-    }
-
-    public long getPhysicalSize() {
-        return physicalSize;
-    }
-
-    public void setDestroyed(boolean destroyed) {
-    	this.destroyed = destroyed;
-    }
-
-    public boolean getDestroyed() {
-    	return destroyed;
-    }
-
-	public void setDownloadUrl(String downloadUrl) {
-		this.downloadUrl = downloadUrl;
-	}
-
-	public String getDownloadUrl() {
-		return downloadUrl;
-	}
-
-    public Storage.ImageFormat getFormat() {
-		return format;
-	}
-
-	public void setFormat(Storage.ImageFormat format) {
-		this.format = format;
-	}
-
-	public long getVolumeSize() {
-	    return -1;
-	}
-
-
-    public String toString() {
-	    return new StringBuilder("VolumeHost[").append(id).append("-").append(volumeId).append("-").append(dataStoreId).append(installPath).append("]").toString();
-	}
-
-    public long getUpdatedCount() {
-        return this.updatedCount;
-    }
-
-    public void incrUpdatedCount() {
-        this.updatedCount++;
-    }
-
-    public void decrUpdatedCount() {
-        this.updatedCount--;
-    }
-
-    public Date getUpdated() {
-        return updated;
-    }
-
-    @Override
-    public ObjectInDataStoreStateMachine.State getState() {
-        // TODO Auto-generated method stub
-        return this.state;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
index 30ebd1d..eb26404 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
@@ -23,10 +23,10 @@ import java.util.Map;
 
 import javax.inject.Inject;
 
-import org.apache.cloudstack.storage.image.db.ImageStoreDao;
-import org.apache.cloudstack.storage.image.db.ImageStoreDetailVO;
-import org.apache.cloudstack.storage.image.db.ImageStoreDetailsDao;
-import org.apache.cloudstack.storage.image.db.ImageStoreVO;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailVO;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.springframework.stereotype.Component;
 
 import com.cloud.storage.ImageStore;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDao.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDao.java
deleted file mode 100644
index 18841bc..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDao.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.image.db;
-
-import com.cloud.utils.db.GenericDao;
-
-public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
-    public ImageStoreVO findByName(String name);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
index 60d414c..2becada 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.storage.image.db;
 
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.springframework.stereotype.Component;
 
 import com.cloud.utils.db.GenericDaoBase;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailVO.java
deleted file mode 100644
index 3afddaa..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailVO.java
+++ /dev/null
@@ -1,83 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.image.db;
-
-import org.apache.cloudstack.api.InternalIdentity;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity
-@Table(name="image_store_details")
-public class ImageStoreDetailVO implements InternalIdentity {
-    @Id
-    @GeneratedValue(strategy=GenerationType.IDENTITY)
-    @Column(name="id")
-    long id;
-
-    @Column(name="store_id")
-    long storeId;
-
-    @Column(name="name")
-    String name;
-
-    @Column(name="value")
-    String value;
-
-    public ImageStoreDetailVO() {
-    }
-
-    public ImageStoreDetailVO(long storeId, String name, String value) {
-        this.storeId = storeId;
-        this.name = name;
-        this.value = value;
-    }
-
-    public long getId() {
-        return id;
-    }
-
-    public long getStoreId() {
-        return storeId;
-    }
-
-    public void setStoreId(long storeId) {
-        this.storeId = storeId;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getValue() {
-        return value;
-    }
-
-    public void setValue(String value) {
-        this.value = value;
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDao.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDao.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDao.java
deleted file mode 100644
index 9867290..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDao.java
+++ /dev/null
@@ -1,28 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.image.db;
-
-import java.util.Map;
-
-
-import com.cloud.utils.db.GenericDao;
-
-public interface ImageStoreDetailsDao extends GenericDao<ImageStoreDetailVO, Long> {
-
-    void update(long storeId, Map<String, String> details);
-    Map<String, String> getDetails(long storeId);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDaoImpl.java
index e96d6fd..8f711c6 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDetailsDaoImpl.java
@@ -22,8 +22,11 @@ import java.util.Map;
 
 import javax.ejb.Local;
 
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailVO;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
 import org.springframework.stereotype.Component;
 
+import com.cloud.host.DetailVO;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
@@ -70,4 +73,18 @@ public class ImageStoreDetailsDaoImpl extends GenericDaoBase<ImageStoreDetailVO,
 
     	return detailsMap;
     }
+
+    @Override
+    public void deleteDetails(long storeId) {
+        SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
+        sc.setParameters("store", storeId);
+
+        List<ImageStoreDetailVO> results = search(sc, null);
+        for (ImageStoreDetailVO result : results) {
+            remove(result.getId());
+        }
+
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreVO.java
deleted file mode 100644
index 36d05e5..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreVO.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.image.db;
-
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.TableGenerator;
-
-
-
-import com.cloud.storage.ImageStore;
-import com.cloud.storage.ScopeType;
-import com.cloud.utils.db.GenericDao;
-
-@Entity
-@Table(name = "image_store")
-public class ImageStoreVO implements ImageStore {
-    @Id
-    @TableGenerator(name = "image_store_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_store_seq", allocationSize = 1)
-    @Column(name = "id", nullable = false)
-    private long id;
-
-    @Column(name = "name", nullable = false)
-    private String name;
-
-    @Column(name = "uuid", nullable = false)
-    private String uuid;
-
-    @Column(name = "protocol", nullable = false)
-    private String protocol;
-
-    @Column(name = "url", nullable = false)
-    private String url;
-
-    @Column(name = "image_provider_name", nullable = false)
-    private String providerName;
-
-    @Column(name = "data_center_id")
-    private long dcId;
-
-    @Column(name = "state")
-    @Enumerated(value = EnumType.STRING)
-    private State state;
-
-    @Column(name = "scope")
-    @Enumerated(value = EnumType.STRING)
-    private ScopeType scope;
-
-    @Column(name=GenericDao.CREATED_COLUMN)
-    private Date created;
-
-    @Column(name=GenericDao.REMOVED_COLUMN)
-    private Date removed;
-
-    public long getId() {
-        return this.id;
-    }
-
-    public String getName() {
-        return this.name;
-    }
-
-    public String getProviderName() {
-        return this.providerName;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public void setProviderName(String provider) {
-        this.providerName = provider;
-    }
-
-    public void setProtocol(String protocol) {
-        this.protocol = protocol;
-    }
-
-    public String getProtocol() {
-        return this.protocol;
-    }
-
-    public void setDataCenterId(long dcId) {
-        this.dcId = dcId;
-    }
-
-    public Long getDataCenterId() {
-        return this.dcId;
-    }
-
-    public ScopeType getScope() {
-        return this.scope;
-    }
-
-    public void setScope(ScopeType scope) {
-        this.scope = scope;
-    }
-
-    public void setUuid(String uuid) {
-        this.uuid = uuid;
-    }
-
-    public String getUuid() {
-        return this.uuid;
-    }
-
-    public String getUrl() {
-        return url;
-    }
-
-    public void setUrl(String url) {
-        this.url = url;
-    }
-
-    public Date getCreated() {
-        return created;
-    }
-
-    public void setCreated(Date created) {
-        this.created = created;
-    }
-
-    public Date getRemoved() {
-        return removed;
-    }
-
-    public void setRemoved(Date removed) {
-        this.removed = removed;
-    }
-
-    public State getState() {
-        return state;
-    }
-
-    public void setState(State state) {
-        this.state = state;
-    }
-
-
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
new file mode 100644
index 0000000..1fed791
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
@@ -0,0 +1,130 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.image.db;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.storage.StoragePoolHostVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.UpdateBuilder;
+
+@Component
+public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO, Long> implements SnapshotDataStoreDao {
+    private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreDaoImpl.class);
+    private SearchBuilder<SnapshotDataStoreVO> updateStateSearch;
+    private SearchBuilder<SnapshotDataStoreVO> storeSearch;
+    private SearchBuilder<SnapshotDataStoreVO> liveStoreSearch;
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+    	super.configure(name, params);
+
+    	storeSearch = createSearchBuilder();
+        storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        storeSearch.done();
+
+        liveStoreSearch = createSearchBuilder();
+        liveStoreSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        liveStoreSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
+        liveStoreSearch.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();
+        return true;
+    }
+
+    @Override
+    public boolean updateState(State currentState, Event event,
+            State nextState, SnapshotDataStoreVO dataObj, Object data) {
+        Long oldUpdated = dataObj.getUpdatedCount();
+        Date oldUpdatedTime = dataObj.getUpdated();
+
+
+        SearchCriteria<SnapshotDataStoreVO> sc = updateStateSearch.create();
+        sc.setParameters("id", dataObj.getId());
+        sc.setParameters("state", currentState);
+        sc.setParameters("updatedCount", dataObj.getUpdatedCount());
+
+        dataObj.incrUpdatedCount();
+
+        UpdateBuilder builder = getUpdateBuilder(dataObj);
+        builder.set(dataObj, "state", nextState);
+        builder.set(dataObj, "updated", new Date());
+
+        int rows = update(dataObj, sc);
+        if (rows == 0 && s_logger.isDebugEnabled()) {
+            SnapshotDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
+            if (dbVol != null) {
+                StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
+                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(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
+                        .append("; updatedTime=").append(dataObj.getUpdated());
+                str.append(": stale Data={id=").append(dataObj.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=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
+            }
+        }
+        return rows > 0;
+    }
+
+    @Override
+    public List<SnapshotDataStoreVO> listByStoreId(long id) {
+        SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<SnapshotDataStoreVO> listLiveByStoreId(long id) {
+        SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        sc.setParameters("destroyed", false);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public void deletePrimaryRecordsForStore(long id) {
+        SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        remove(sc);
+        txn.commit();
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
new file mode 100644
index 0000000..2066c5d
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
@@ -0,0 +1,127 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.image.db;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.UpdateBuilder;
+
+@Component
+public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO, Long> implements TemplateDataStoreDao {
+    private static final Logger s_logger = Logger.getLogger(TemplateDataStoreDaoImpl.class);
+    private SearchBuilder<TemplateDataStoreVO> updateStateSearch;
+    private SearchBuilder<TemplateDataStoreVO> storeSearch;
+    private SearchBuilder<TemplateDataStoreVO> liveStoreSearch;
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+    	super.configure(name, params);
+
+        storeSearch = createSearchBuilder();
+        storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        storeSearch.done();
+
+        liveStoreSearch = createSearchBuilder();
+        liveStoreSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+        liveStoreSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
+        liveStoreSearch.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();
+        return true;
+    }
+
+    @Override
+    public boolean updateState(State currentState, Event event,
+            State nextState, TemplateDataStoreVO dataObj, Object data) {
+        Long oldUpdated = dataObj.getUpdatedCount();
+        Date oldUpdatedTime = dataObj.getUpdated();
+
+
+        SearchCriteria<TemplateDataStoreVO> sc = updateStateSearch.create();
+        sc.setParameters("id", dataObj.getId());
+        sc.setParameters("state", currentState);
+        sc.setParameters("updatedCount", dataObj.getUpdatedCount());
+
+        dataObj.incrUpdatedCount();
+
+        UpdateBuilder builder = getUpdateBuilder(dataObj);
+        builder.set(dataObj, "state", nextState);
+        builder.set(dataObj, "updated", new Date());
+
+        int rows = update(dataObj, sc);
+        if (rows == 0 && s_logger.isDebugEnabled()) {
+            TemplateDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
+            if (dbVol != null) {
+                StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
+                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(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
+                        .append("; updatedTime=").append(dataObj.getUpdated());
+                str.append(": stale Data={id=").append(dataObj.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=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
+            }
+        }
+        return rows > 0;
+    }
+
+    @Override
+    public List<TemplateDataStoreVO> listByStoreId(long id) {
+        SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        return listIncludingRemovedBy(sc);
+    }
+    @Override
+    public List<TemplateDataStoreVO> listLiveByStoreId(long id) {
+        SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        sc.setParameters("destroyed", false);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public void deletePrimaryRecordsForStore(long id) {
+        SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        remove(sc);
+        txn.commit();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
new file mode 100644
index 0000000..34de3f2
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
@@ -0,0 +1,118 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.image.db;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
+import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.UpdateBuilder;
+
+@Component
+public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Long> implements VolumeDataStoreDao {
+    private static final Logger s_logger = Logger.getLogger(VolumeDataStoreDaoImpl.class);
+    private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
+    private SearchBuilder<VolumeDataStoreVO> storeSearch;
+    private SearchBuilder<VolumeDataStoreVO> liveStoreSearch;
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+    	super.configure(name, params);
+
+        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();
+        return true;
+    }
+    @Override
+    public boolean updateState(State currentState, Event event,
+            State nextState, VolumeDataStoreVO dataObj, Object data) {
+        Long oldUpdated = dataObj.getUpdatedCount();
+        Date oldUpdatedTime = dataObj.getUpdated();
+
+
+        SearchCriteria<VolumeDataStoreVO> sc = updateStateSearch.create();
+        sc.setParameters("id", dataObj.getId());
+        sc.setParameters("state", currentState);
+        sc.setParameters("updatedCount", dataObj.getUpdatedCount());
+
+        dataObj.incrUpdatedCount();
+
+        UpdateBuilder builder = getUpdateBuilder(dataObj);
+        builder.set(dataObj, "state", nextState);
+        builder.set(dataObj, "updated", new Date());
+
+        int rows = update(dataObj, sc);
+        if (rows == 0 && s_logger.isDebugEnabled()) {
+            VolumeDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
+            if (dbVol != null) {
+                StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
+                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(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
+                        .append("; updatedTime=").append(dataObj.getUpdated());
+                str.append(": stale Data={id=").append(dataObj.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=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
+            }
+        }
+        return rows > 0;
+    }
+
+    @Override
+    public List<VolumeDataStoreVO> listByStoreId(long id) {
+        SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        return listIncludingRemovedBy(sc);
+    }
+    @Override
+    public List<VolumeDataStoreVO> listLiveByStoreId(long id) {
+        SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        sc.setParameters("destroyed", false);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public void deletePrimaryRecordsForStore(long id) {
+        SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", id);
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        remove(sc);
+        txn.commit();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/volume/db/PrimaryDataStoreDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/db/PrimaryDataStoreDetailsDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/db/PrimaryDataStoreDetailsDaoImpl.java
new file mode 100644
index 0000000..b0a387a
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/db/PrimaryDataStoreDetailsDaoImpl.java
@@ -0,0 +1,74 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.volume.db;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDetailVO;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDetailsDao;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+public class PrimaryDataStoreDetailsDaoImpl extends GenericDaoBase<PrimaryDataStoreDetailVO, Long> implements PrimaryDataStoreDetailsDao {
+    
+    protected final SearchBuilder<PrimaryDataStoreDetailVO> PoolSearch = null;
+    
+    protected PrimaryDataStoreDetailsDaoImpl() {
+        /*
+        super();
+        PoolSearch = createSearchBuilder();
+        PoolSearch.and("pool", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
+        PoolSearch.done();
+        */
+    }
+    
+    @Override
+    public void update(long poolId, Map<String, String> details) {
+        Transaction txn = Transaction.currentTxn();
+        SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
+        sc.setParameters("pool", poolId);
+        
+        txn.start();
+        expunge(sc);
+        for (Map.Entry<String, String> entry : details.entrySet()) {
+            PrimaryDataStoreDetailVO detail = new PrimaryDataStoreDetailVO(poolId, entry.getKey(), entry.getValue());
+            persist(detail);
+        }
+        txn.commit();
+    }
+    
+    @Override
+    public Map<String, String> getDetails(long poolId) {
+    	SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
+    	sc.setParameters("pool", poolId);
+    	
+    	List<PrimaryDataStoreDetailVO> details = listBy(sc);
+    	Map<String, String> detailsMap = new HashMap<String, String>();
+    	for (PrimaryDataStoreDetailVO detail : details) {
+    		detailsMap.put(detail.getName(), detail.getValue());
+    	}
+    	
+    	return detailsMap;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java
index fbd9909..922205a 100644
--- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java
+++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java
@@ -29,10 +29,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
-import org.apache.cloudstack.storage.image.db.ImageStoreDao;
-import org.apache.cloudstack.storage.image.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
 import org.apache.log4j.Logger;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java
index 7d22df5..c384356 100644
--- a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java
+++ b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java
@@ -30,10 +30,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
-import org.apache.cloudstack.storage.image.db.ImageStoreDao;
-import org.apache.cloudstack.storage.image.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
 import org.apache.log4j.Logger;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java
index 8c61f03..fbe9f19 100644
--- a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java
+++ b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java
@@ -24,10 +24,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
-import org.apache.cloudstack.storage.image.db.ImageStoreDao;
-import org.apache.cloudstack.storage.image.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
 
 import com.cloud.agent.api.StoragePoolInfo;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java
index 62dbfae..799d4e0 100644
--- a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java
+++ b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java
@@ -29,10 +29,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
-import org.apache.cloudstack.storage.image.db.ImageStoreDao;
-import org.apache.cloudstack.storage.image.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle;
 import org.apache.log4j.Logger;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 88b1a52..c9f97be 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -64,8 +64,17 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.framework.async.AsyncCallFuture;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
+import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -78,6 +87,7 @@ import com.cloud.agent.api.ManageSnapshotCommand;
 import com.cloud.agent.api.StoragePoolInfo;
 import com.cloud.agent.api.storage.DeleteTemplateCommand;
 import com.cloud.agent.api.storage.DeleteVolumeCommand;
+import com.cloud.agent.manager.AgentAttache;
 import com.cloud.agent.manager.Commands;
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiDBUtils;
@@ -125,6 +135,7 @@ import com.cloud.org.Grouping;
 import com.cloud.org.Grouping.AllocationState;
 import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ResourceState;
+import com.cloud.resource.ResourceStateAdapter;
 import com.cloud.server.ManagementServer;
 import com.cloud.server.StatsCollector;
 import com.cloud.service.dao.ServiceOfferingDao;
@@ -175,6 +186,7 @@ import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.UserVmManager;
 import com.cloud.vm.VMInstanceVO;
@@ -243,6 +255,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
     @Inject
     protected PrimaryDataStoreDao _storagePoolDao = null;
     @Inject
+    protected ImageStoreDao _imageStoreDao = null;
+    @Inject
+    protected ImageStoreDetailsDao _imageStoreDetailsDao = null;
+    @Inject
+    protected SnapshotDataStoreDao _snapshotStoreDao = null;
+    @Inject
+    protected TemplateDataStoreDao _templateStoreDao = null;
+    @Inject
+    protected VolumeDataStoreDao _volumeStoreDao = null;
+    @Inject
     protected CapacityDao _capacityDao;
     @Inject
     protected CapacityManager _capacityMgr;
@@ -1949,10 +1971,44 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
 
         return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
     }
+
     @Override
     public boolean deleteImageStore(DeleteImageStoreCmd cmd) {
-        // TODO Auto-generated method stub
-        return false;
+        long storeId = cmd.getId();
+        User caller = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());
+        // Verify that image store exists
+        ImageStoreVO store = _imageStoreDao.findById(storeId);
+        if (store == null) {
+            throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
+        }
+        _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), store.getDataCenterId());
+
+        // Verify that there are no live snapshot, template, volume on the image store to be deleted
+        List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listLiveByStoreId(storeId);
+        if ( snapshots != null && snapshots.size() > 0 ){
+            throw new CloudRuntimeException("Cannot delete image store with active snapshots backup!");
+        }
+        List<VolumeDataStoreVO> volumes = _volumeStoreDao.listLiveByStoreId(storeId);
+        if ( volumes != null && volumes.size() > 0 ){
+            throw new CloudRuntimeException("Cannot delete image store with active volumes backup!");
+        }
+        List<TemplateDataStoreVO> templates = _templateStoreDao.listLiveByStoreId(storeId);
+        if ( templates != null && templates.size() > 0 ){
+            throw new CloudRuntimeException("Cannot delete image store with active templates backup!");
+        }
+
+        // ready to delete
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        // first delete from image_store_details table, we need to do that since we are not actually deleting record from main
+        // image_data_store table, so delete cascade will not work
+        _imageStoreDetailsDao.deleteDetails(storeId);
+        _snapshotStoreDao.deletePrimaryRecordsForStore(storeId);
+        _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
+        _templateStoreDao.deletePrimaryRecordsForStore(storeId);
+        _imageStoreDao.remove(storeId);
+        txn.commit();
+        return true;
     }
 
 


[2/2] git commit: updated refs/heads/object_store to 74880fa

Posted by mc...@apache.org.
add DeleteImageStoreCmd Api.

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/74880fa2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/74880fa2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/74880fa2

Branch: refs/heads/object_store
Commit: 74880fa26f4dcf5248e66e1e4517af2cb95376c5
Parents: 7f64b61
Author: Min Chen <mi...@citrix.com>
Authored: Mon Apr 8 16:18:06 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Mon Apr 8 16:18:06 2013 -0700

----------------------------------------------------------------------
 .../datastore/db/DataStoreProviderDaoImpl.java     |   38 --
 .../storage/datastore/db/ImageStoreDao.java        |   25 +
 .../storage/datastore/db/ImageStoreDetailVO.java   |   83 ++++
 .../storage/datastore/db/ImageStoreDetailsDao.java |   31 ++
 .../storage/datastore/db/ImageStoreVO.java         |  163 +++++++
 .../db/PrimaryDataStoreDetailsDaoImpl.java         |   71 ---
 .../storage/datastore/db/SnapshotDataStoreDao.java |   35 ++
 .../storage/datastore/db/SnapshotDataStoreVO.java  |  242 ++++++++++
 .../storage/datastore/db/TemplateDataStoreDao.java |   33 ++
 .../storage/datastore/db/TemplateDataStoreVO.java  |  310 +++++++++++++
 .../storage/datastore/db/VolumeDataStoreDao.java   |   34 ++
 .../storage/datastore/db/VolumeDataStoreVO.java    |  348 +++++++++++++++
 .../manager/ImageStoreProviderManagerImpl.java     |    4 +-
 .../storage/image/store/ImageStoreImpl.java        |    2 +-
 .../storage/db/DataStoreProviderDaoImpl.java       |   40 ++
 .../storage/db/SnapshotDataStoreDao.java           |   27 --
 .../storage/db/SnapshotDataStoreDaoImpl.java       |   86 ----
 .../cloudstack/storage/db/SnapshotDataStoreVO.java |  242 ----------
 .../storage/db/TemplateDataStoreDao.java           |   27 --
 .../storage/db/TemplateDataStoreDaoImpl.java       |   86 ----
 .../cloudstack/storage/db/TemplateDataStoreVO.java |  310 -------------
 .../cloudstack/storage/db/VolumeDataStoreDao.java  |   27 --
 .../storage/db/VolumeDataStoreDaoImpl.java         |   86 ----
 .../cloudstack/storage/db/VolumeDataStoreVO.java   |  348 ---------------
 .../storage/image/datastore/ImageStoreHelper.java  |    8 +-
 .../cloudstack/storage/image/db/ImageStoreDao.java |   25 -
 .../storage/image/db/ImageStoreDaoImpl.java        |    2 +
 .../storage/image/db/ImageStoreDetailVO.java       |   83 ----
 .../storage/image/db/ImageStoreDetailsDao.java     |   28 --
 .../storage/image/db/ImageStoreDetailsDaoImpl.java |   17 +
 .../cloudstack/storage/image/db/ImageStoreVO.java  |  163 -------
 .../storage/image/db/SnapshotDataStoreDaoImpl.java |  130 ++++++
 .../storage/image/db/TemplateDataStoreDaoImpl.java |  127 ++++++
 .../storage/image/db/VolumeDataStoreDaoImpl.java   |  118 +++++
 .../volume/db/PrimaryDataStoreDetailsDaoImpl.java  |   74 +++
 .../CloudStackImageStoreLifeCycleImpl.java         |    4 +-
 .../lifecycle/S3ImageStoreLifeCycleImpl.java       |    4 +-
 .../lifecycle/SampleImageStoreLifeCycleImpl.java   |    4 +-
 .../lifecycle/SwiftImageStoreLifeCycleImpl.java    |    4 +-
 .../src/com/cloud/storage/StorageManagerImpl.java  |   60 +++-
 40 files changed, 1885 insertions(+), 1664 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java
deleted file mode 100644
index ccb6b48..0000000
--- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.datastore.db;
-
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchCriteria2;
-import com.cloud.utils.db.SearchCriteriaService;
-import com.cloud.utils.db.SearchCriteria.Op;
-
-@Component
-class DataStoreProviderDaoImpl extends GenericDaoBase<DataStoreProviderVO, Long> implements DataStoreProviderDao {
-
-    @Override
-    public DataStoreProviderVO findByName(String name) {
-        SearchCriteriaService<DataStoreProviderVO, DataStoreProviderVO> sc = SearchCriteria2.create(DataStoreProviderVO.class);
-        sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
-        return sc.find();
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
new file mode 100644
index 0000000..a81fa9c
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.db;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> {
+    public ImageStoreVO findByName(String name);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailVO.java
new file mode 100644
index 0000000..63ac9e4
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailVO.java
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="image_store_details")
+public class ImageStoreDetailVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    long id;
+
+    @Column(name="store_id")
+    long storeId;
+
+    @Column(name="name")
+    String name;
+
+    @Column(name="value")
+    String value;
+
+    public ImageStoreDetailVO() {
+    }
+
+    public ImageStoreDetailVO(long storeId, String name, String value) {
+        this.storeId = storeId;
+        this.name = name;
+        this.value = value;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getStoreId() {
+        return storeId;
+    }
+
+    public void setStoreId(long storeId) {
+        this.storeId = storeId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDao.java
new file mode 100644
index 0000000..033a818
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDao.java
@@ -0,0 +1,31 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.Map;
+
+
+import com.cloud.utils.db.GenericDao;
+
+public interface ImageStoreDetailsDao extends GenericDao<ImageStoreDetailVO, Long> {
+
+    void update(long storeId, Map<String, String> details);
+
+    Map<String, String> getDetails(long storeId);
+
+    void deleteDetails(long storeId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
new file mode 100644
index 0000000..62c1be0
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+
+
+
+import com.cloud.storage.ImageStore;
+import com.cloud.storage.ScopeType;
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = "image_store")
+public class ImageStoreVO implements ImageStore {
+    @Id
+    @TableGenerator(name = "image_store_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_store_seq", allocationSize = 1)
+    @Column(name = "id", nullable = false)
+    private long id;
+
+    @Column(name = "name", nullable = false)
+    private String name;
+
+    @Column(name = "uuid", nullable = false)
+    private String uuid;
+
+    @Column(name = "protocol", nullable = false)
+    private String protocol;
+
+    @Column(name = "url", nullable = false)
+    private String url;
+
+    @Column(name = "image_provider_name", nullable = false)
+    private String providerName;
+
+    @Column(name = "data_center_id")
+    private long dcId;
+
+    @Column(name = "state")
+    @Enumerated(value = EnumType.STRING)
+    private State state;
+
+    @Column(name = "scope")
+    @Enumerated(value = EnumType.STRING)
+    private ScopeType scope;
+
+    @Column(name=GenericDao.CREATED_COLUMN)
+    private Date created;
+
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+
+    public long getId() {
+        return this.id;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public String getProviderName() {
+        return this.providerName;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setProviderName(String provider) {
+        this.providerName = provider;
+    }
+
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
+    }
+
+    public String getProtocol() {
+        return this.protocol;
+    }
+
+    public void setDataCenterId(long dcId) {
+        this.dcId = dcId;
+    }
+
+    public Long getDataCenterId() {
+        return this.dcId;
+    }
+
+    public ScopeType getScope() {
+        return this.scope;
+    }
+
+    public void setScope(ScopeType scope) {
+        this.scope = scope;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    public String getUuid() {
+        return this.uuid;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+
+    public void setCreated(Date created) {
+        this.created = created;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+
+    public void setRemoved(Date removed) {
+        this.removed = removed;
+    }
+
+    public State getState() {
+        return state;
+    }
+
+    public void setState(State state) {
+        this.state = state;
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java
deleted file mode 100644
index 59c488c..0000000
--- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.datastore.db;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.Transaction;
-
-@Component
-public class PrimaryDataStoreDetailsDaoImpl extends GenericDaoBase<PrimaryDataStoreDetailVO, Long> implements PrimaryDataStoreDetailsDao {
-    
-    protected final SearchBuilder<PrimaryDataStoreDetailVO> PoolSearch = null;
-    
-    protected PrimaryDataStoreDetailsDaoImpl() {
-        /*
-        super();
-        PoolSearch = createSearchBuilder();
-        PoolSearch.and("pool", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
-        PoolSearch.done();
-        */
-    }
-    
-    @Override
-    public void update(long poolId, Map<String, String> details) {
-        Transaction txn = Transaction.currentTxn();
-        SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
-        sc.setParameters("pool", poolId);
-        
-        txn.start();
-        expunge(sc);
-        for (Map.Entry<String, String> entry : details.entrySet()) {
-            PrimaryDataStoreDetailVO detail = new PrimaryDataStoreDetailVO(poolId, entry.getKey(), entry.getValue());
-            persist(detail);
-        }
-        txn.commit();
-    }
-    
-    @Override
-    public Map<String, String> getDetails(long poolId) {
-    	SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
-    	sc.setParameters("pool", poolId);
-    	
-    	List<PrimaryDataStoreDetailVO> details = listBy(sc);
-    	Map<String, String> detailsMap = new HashMap<String, String>();
-    	for (PrimaryDataStoreDetailVO detail : details) {
-    		detailsMap.put(detail.getName(), detail.getValue());
-    	}
-    	
-    	return detailsMap;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
new file mode 100644
index 0000000..4d92fd3
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
@@ -0,0 +1,35 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+
+public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, SnapshotDataStoreVO>  {
+
+    public List<SnapshotDataStoreVO> listByStoreId(long id);
+
+    public List<SnapshotDataStoreVO> listLiveByStoreId(long id);
+
+    public void deletePrimaryRecordsForStore(long id);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java
new file mode 100644
index 0000000..0f9c95a
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java
@@ -0,0 +1,242 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+
+import com.cloud.storage.Storage;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.fsm.StateObject;
+
+/**
+ * Join table for image_data_store and snapshots
+ *
+ */
+@Entity
+@Table(name="snapshot_store_ref")
+public class SnapshotDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	Long id;
+
+	@Column(name="store_id")
+	private long dataStoreId;
+
+	@Column(name="snapshot_id")
+	private long snapshotId;
+
+	@Column(name=GenericDaoBase.CREATED_COLUMN)
+	private Date created = null;
+
+	@Column(name="last_updated")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date lastUpdated = null;
+
+
+	@Column (name="size")
+	private long size;
+
+	@Column (name="physical_size")
+	private long physicalSize;
+
+
+	@Column (name="job_id")
+	private String jobId;
+
+	@Column (name="install_path")
+    private String installPath;
+
+
+    @Column(name="destroyed")
+    boolean destroyed = false;
+
+    @Column(name="update_count", updatable = true, nullable=false)
+    protected long updatedCount;
+
+    @Column(name = "updated")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date updated;
+
+    @Column(name = "state")
+    @Enumerated(EnumType.STRING)
+    ObjectInDataStoreStateMachine.State state;
+
+    public String getInstallPath() {
+		return installPath;
+	}
+
+	public long getDataStoreId() {
+		return dataStoreId;
+	}
+
+	public void setHostId(long hostId) {
+		this.dataStoreId = hostId;
+	}
+
+
+    public long getSnapshotId() {
+		return snapshotId;
+	}
+
+
+    public void setSnapshotId(long snapshotId) {
+		this.snapshotId = snapshotId;
+	}
+
+
+
+
+    public long getId() {
+		return id;
+	}
+
+
+    public Date getCreated() {
+		return created;
+	}
+
+
+    public Date getLastUpdated() {
+		return lastUpdated;
+	}
+
+
+    public void setLastUpdated(Date date) {
+	    lastUpdated = date;
+	}
+
+
+    public void setInstallPath(String installPath) {
+	    this.installPath = installPath;
+	}
+
+
+
+	public SnapshotDataStoreVO(long hostId, long snapshotId) {
+		super();
+		this.dataStoreId = hostId;
+		this.snapshotId = snapshotId;
+		this.state = ObjectInDataStoreStateMachine.State.Allocated;
+	}
+
+
+
+	protected SnapshotDataStoreVO() {
+
+	}
+
+
+
+
+    public void setJobId(String jobId) {
+		this.jobId = jobId;
+	}
+
+
+    public String getJobId() {
+		return jobId;
+	}
+
+
+	public boolean equals(Object obj) {
+		if (obj instanceof SnapshotDataStoreVO) {
+			SnapshotDataStoreVO other = (SnapshotDataStoreVO)obj;
+			return (this.snapshotId==other.getSnapshotId() && this.dataStoreId==other.getDataStoreId());
+		}
+		return false;
+	}
+
+
+	public int hashCode() {
+		Long tid = new Long(snapshotId);
+		Long hid = new Long(dataStoreId);
+		return tid.hashCode()+hid.hashCode();
+	}
+
+    public void setSize(long size) {
+        this.size = size;
+    }
+
+    public long getSize() {
+        return size;
+    }
+
+
+    public void setPhysicalSize(long physicalSize) {
+        this.physicalSize = physicalSize;
+    }
+
+    public long getPhysicalSize() {
+        return physicalSize;
+    }
+
+    public void setDestroyed(boolean destroyed) {
+    	this.destroyed = destroyed;
+    }
+
+    public boolean getDestroyed() {
+    	return destroyed;
+    }
+
+	public long getVolumeSize() {
+	    return -1;
+	}
+
+
+    public String toString() {
+	    return new StringBuilder("VolumeHost[").append(id).append("-").append(snapshotId).append("-").append(dataStoreId).append(installPath).append("]").toString();
+	}
+
+    public long getUpdatedCount() {
+        return this.updatedCount;
+    }
+
+    public void incrUpdatedCount() {
+        this.updatedCount++;
+    }
+
+    public void decrUpdatedCount() {
+        this.updatedCount--;
+    }
+
+    public Date getUpdated() {
+        return updated;
+    }
+
+    @Override
+    public ObjectInDataStoreStateMachine.State getState() {
+        // TODO Auto-generated method stub
+        return this.state;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
new file mode 100644
index 0000000..591b84c
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
@@ -0,0 +1,33 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+
+public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, TemplateDataStoreVO>  {
+
+    public List<TemplateDataStoreVO> listByStoreId(long id);
+
+    public List<TemplateDataStoreVO> listLiveByStoreId(long id);
+
+    public void deletePrimaryRecordsForStore(long id);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java
new file mode 100755
index 0000000..4e48437
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java
@@ -0,0 +1,310 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+
+import com.cloud.storage.VMTemplateStorageResourceAssoc;
+import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.fsm.StateObject;
+
+/**
+ * Join table for image_data_store and templates
+ *
+ */
+@Entity
+@Table(name="template_store_ref")
+public class TemplateDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	Long id;
+
+	@Column(name="store_id")
+	private long dataStoreId;
+
+	@Column(name="template_id")
+	private long templateId;
+
+	@Column(name=GenericDaoBase.CREATED_COLUMN)
+	private Date created = null;
+
+	@Column(name="last_updated")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date lastUpdated = null;
+
+	@Column (name="download_pct")
+	private int downloadPercent;
+
+	@Column (name="size")
+	private long size;
+
+	@Column (name="physical_size")
+	private long physicalSize;
+
+	@Column (name="download_state")
+	@Enumerated(EnumType.STRING)
+	private Status downloadState;
+
+	@Column (name="local_path")
+	private String localDownloadPath;
+
+	@Column (name="error_str")
+	private String errorString;
+
+	@Column (name="job_id")
+	private String jobId;
+
+	@Column (name="install_path")
+    private String installPath;
+
+	@Column (name="url")
+	private String downloadUrl;
+
+	@Column(name="is_copy")
+	private boolean isCopy = false;
+
+    @Column(name="destroyed")
+    boolean destroyed = false;
+
+    @Column(name="update_count", updatable = true, nullable=false)
+    protected long updatedCount;
+
+    @Column(name = "updated")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date updated;
+
+    @Column(name = "state")
+    @Enumerated(EnumType.STRING)
+    ObjectInDataStoreStateMachine.State state;
+
+
+	@Override
+    public String getInstallPath() {
+		return installPath;
+	}
+
+
+	public long getDataStoreId() {
+		return dataStoreId;
+	}
+
+	public void setHostId(long hostId) {
+		this.dataStoreId = hostId;
+	}
+
+    public long getTemplateId() {
+		return templateId;
+	}
+
+    public void setTemplateId(long templateId) {
+		this.templateId = templateId;
+	}
+
+    public int getDownloadPercent() {
+		return downloadPercent;
+	}
+
+    public void setDownloadPercent(int downloadPercent) {
+		this.downloadPercent = downloadPercent;
+	}
+
+    public void setDownloadState(Status downloadState) {
+		this.downloadState = downloadState;
+	}
+
+    public long getId() {
+		return id;
+	}
+
+    public Date getCreated() {
+		return created;
+	}
+
+    public Date getLastUpdated() {
+		return lastUpdated;
+	}
+
+    public void setLastUpdated(Date date) {
+	    lastUpdated = date;
+	}
+
+    public void setInstallPath(String installPath) {
+	    this.installPath = installPath;
+	}
+
+    public Status getDownloadState() {
+		return downloadState;
+	}
+
+	public TemplateDataStoreVO(long hostId, long templateId) {
+		super();
+		this.dataStoreId = hostId;
+		this.templateId = templateId;
+		this.state = ObjectInDataStoreStateMachine.State.Allocated;
+	}
+
+	public TemplateDataStoreVO(long hostId, long templateId, Date lastUpdated,
+			int downloadPercent, Status downloadState,
+			String localDownloadPath, String errorString, String jobId,
+			String installPath, String downloadUrl) {
+		super();
+		this.dataStoreId = hostId;
+		this.templateId = templateId;
+		this.lastUpdated = lastUpdated;
+		this.downloadPercent = downloadPercent;
+		this.downloadState = downloadState;
+		this.localDownloadPath = localDownloadPath;
+		this.errorString = errorString;
+		this.jobId = jobId;
+		this.installPath = installPath;
+		this.setDownloadUrl(downloadUrl);
+	}
+
+	protected TemplateDataStoreVO() {
+
+	}
+
+
+    public void setLocalDownloadPath(String localPath) {
+		this.localDownloadPath = localPath;
+	}
+
+    public String getLocalDownloadPath() {
+		return localDownloadPath;
+	}
+
+    public void setErrorString(String errorString) {
+		this.errorString = errorString;
+	}
+
+    public String getErrorString() {
+		return errorString;
+	}
+
+    public void setJobId(String jobId) {
+		this.jobId = jobId;
+	}
+
+    public String getJobId() {
+		return jobId;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (obj instanceof TemplateDataStoreVO) {
+			TemplateDataStoreVO other = (TemplateDataStoreVO)obj;
+			return (this.templateId==other.getTemplateId() && this.dataStoreId==other.getDataStoreId());
+		}
+		return false;
+	}
+
+	@Override
+	public int hashCode() {
+		Long tid = new Long(templateId);
+		Long hid = new Long(dataStoreId);
+		return tid.hashCode()+hid.hashCode();
+	}
+
+    public void setSize(long size) {
+        this.size = size;
+    }
+
+    public long getSize() {
+        return size;
+    }
+
+
+    public void setPhysicalSize(long physicalSize) {
+        this.physicalSize = physicalSize;
+    }
+
+    public long getPhysicalSize() {
+        return physicalSize;
+    }
+
+    public void setDestroyed(boolean destroyed) {
+    	this.destroyed = destroyed;
+    }
+
+    public boolean getDestroyed() {
+    	return destroyed;
+    }
+
+	public void setDownloadUrl(String downloadUrl) {
+		this.downloadUrl = downloadUrl;
+	}
+
+	public String getDownloadUrl() {
+		return downloadUrl;
+	}
+
+	public void setCopy(boolean isCopy) {
+		this.isCopy = isCopy;
+	}
+
+	public boolean isCopy() {
+		return isCopy;
+	}
+
+    public long getTemplateSize() {
+	    return -1;
+	}
+
+	@Override
+    public String toString() {
+	    return new StringBuilder("TmplHost[").append(id).append("-").append(templateId).append("-").append(dataStoreId).append(installPath).append("]").toString();
+	}
+
+    @Override
+    public ObjectInDataStoreStateMachine.State getState() {
+        // TODO Auto-generated method stub
+        return this.state;
+    }
+
+    public long getUpdatedCount() {
+        return this.updatedCount;
+    }
+
+    public void incrUpdatedCount() {
+        this.updatedCount++;
+    }
+
+    public void decrUpdatedCount() {
+        this.updatedCount--;
+    }
+
+    public Date getUpdated() {
+        return updated;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java
new file mode 100644
index 0000000..709097e
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java
@@ -0,0 +1,34 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+
+public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, VolumeDataStoreVO>  {
+
+    public List<VolumeDataStoreVO> listByStoreId(long id);
+
+    public List<VolumeDataStoreVO> listLiveByStoreId(long id);
+
+    public void deletePrimaryRecordsForStore(long id);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
new file mode 100755
index 0000000..1fb6184
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
@@ -0,0 +1,348 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+
+import com.cloud.storage.Storage;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.fsm.StateObject;
+
+/**
+ * Join table for image_data_store and volumes
+ *
+ */
+@Entity
+@Table(name="volume_store_ref")
+public class VolumeDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	Long id;
+
+	@Column(name="store_id")
+	private long dataStoreId;
+
+	@Column(name="volume_id")
+	private long volumeId;
+
+	@Column(name="zone_id")
+	private long zoneId;
+
+	@Column(name=GenericDaoBase.CREATED_COLUMN)
+	private Date created = null;
+
+	@Column(name="last_updated")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date lastUpdated = null;
+
+	@Column (name="download_pct")
+	private int downloadPercent;
+
+	@Column (name="size")
+	private long size;
+
+	@Column (name="physical_size")
+	private long physicalSize;
+
+	@Column (name="download_state")
+	@Enumerated(EnumType.STRING)
+	private Status downloadState;
+
+    @Column(name="checksum")
+    private String checksum;
+
+	@Column (name="local_path")
+	private String localDownloadPath;
+
+	@Column (name="error_str")
+	private String errorString;
+
+	@Column (name="job_id")
+	private String jobId;
+
+	@Column (name="install_path")
+    private String installPath;
+
+	@Column (name="url")
+	private String downloadUrl;
+
+	@Column(name="format")
+    private Storage.ImageFormat format;
+
+    @Column(name="destroyed")
+    boolean destroyed = false;
+
+    @Column(name="update_count", updatable = true, nullable=false)
+    protected long updatedCount;
+
+    @Column(name = "updated")
+    @Temporal(value = TemporalType.TIMESTAMP)
+    Date updated;
+
+    @Column(name = "state")
+    @Enumerated(EnumType.STRING)
+    ObjectInDataStoreStateMachine.State state;
+
+    public String getInstallPath() {
+		return installPath;
+	}
+
+	public long getDataStoreId() {
+		return dataStoreId;
+	}
+
+	public void setHostId(long hostId) {
+		this.dataStoreId = hostId;
+	}
+
+
+    public long getVolumeId() {
+		return volumeId;
+	}
+
+
+    public void setVolumeId(long volumeId) {
+		this.volumeId = volumeId;
+	}
+
+
+    public long getZoneId() {
+		return zoneId;
+	}
+
+	public void setZoneId(long zoneId) {
+		this.zoneId = zoneId;
+	}
+
+	public int getDownloadPercent() {
+		return downloadPercent;
+	}
+
+
+    public void setDownloadPercent(int downloadPercent) {
+		this.downloadPercent = downloadPercent;
+	}
+
+
+    public void setDownloadState(Status downloadState) {
+		this.downloadState = downloadState;
+	}
+
+
+    public long getId() {
+		return id;
+	}
+
+
+    public Date getCreated() {
+		return created;
+	}
+
+
+    public Date getLastUpdated() {
+		return lastUpdated;
+	}
+
+
+    public void setLastUpdated(Date date) {
+	    lastUpdated = date;
+	}
+
+
+    public void setInstallPath(String installPath) {
+	    this.installPath = installPath;
+	}
+
+
+    public Status getDownloadState() {
+		return downloadState;
+	}
+
+	public String getChecksum() {
+		return checksum;
+	}
+
+	public void setChecksum(String checksum) {
+		this.checksum = checksum;
+	}
+
+	public VolumeDataStoreVO(long hostId, long volumeId) {
+		super();
+		this.dataStoreId = hostId;
+		this.volumeId = volumeId;
+		this.state = ObjectInDataStoreStateMachine.State.Allocated;
+	}
+
+	public VolumeDataStoreVO(long hostId, long volumeId, long zoneId, Date lastUpdated,
+			int downloadPercent, Status downloadState,
+			String localDownloadPath, String errorString, String jobId,
+			String installPath, String downloadUrl, String checksum, ImageFormat format) {
+		//super();
+		this.dataStoreId = hostId;
+		this.volumeId = volumeId;
+		this.zoneId = zoneId;
+		this.lastUpdated = lastUpdated;
+		this.downloadPercent = downloadPercent;
+		this.downloadState = downloadState;
+		this.localDownloadPath = localDownloadPath;
+		this.errorString = errorString;
+		this.jobId = jobId;
+		this.installPath = installPath;
+		this.setDownloadUrl(downloadUrl);
+		this.checksum = checksum;
+		this.format = format;
+	}
+
+	protected VolumeDataStoreVO() {
+
+	}
+
+
+    public void setLocalDownloadPath(String localPath) {
+		this.localDownloadPath = localPath;
+	}
+
+
+    public String getLocalDownloadPath() {
+		return localDownloadPath;
+	}
+
+
+    public void setErrorString(String errorString) {
+		this.errorString = errorString;
+	}
+
+
+    public String getErrorString() {
+		return errorString;
+	}
+
+
+    public void setJobId(String jobId) {
+		this.jobId = jobId;
+	}
+
+
+    public String getJobId() {
+		return jobId;
+	}
+
+
+	public boolean equals(Object obj) {
+		if (obj instanceof VolumeDataStoreVO) {
+			VolumeDataStoreVO other = (VolumeDataStoreVO)obj;
+			return (this.volumeId==other.getVolumeId() && this.dataStoreId==other.getDataStoreId());
+		}
+		return false;
+	}
+
+
+	public int hashCode() {
+		Long tid = new Long(volumeId);
+		Long hid = new Long(dataStoreId);
+		return tid.hashCode()+hid.hashCode();
+	}
+
+    public void setSize(long size) {
+        this.size = size;
+    }
+
+    public long getSize() {
+        return size;
+    }
+
+
+    public void setPhysicalSize(long physicalSize) {
+        this.physicalSize = physicalSize;
+    }
+
+    public long getPhysicalSize() {
+        return physicalSize;
+    }
+
+    public void setDestroyed(boolean destroyed) {
+    	this.destroyed = destroyed;
+    }
+
+    public boolean getDestroyed() {
+    	return destroyed;
+    }
+
+	public void setDownloadUrl(String downloadUrl) {
+		this.downloadUrl = downloadUrl;
+	}
+
+	public String getDownloadUrl() {
+		return downloadUrl;
+	}
+
+    public Storage.ImageFormat getFormat() {
+		return format;
+	}
+
+	public void setFormat(Storage.ImageFormat format) {
+		this.format = format;
+	}
+
+	public long getVolumeSize() {
+	    return -1;
+	}
+
+
+    public String toString() {
+	    return new StringBuilder("VolumeHost[").append(id).append("-").append(volumeId).append("-").append(dataStoreId).append(installPath).append("]").toString();
+	}
+
+    public long getUpdatedCount() {
+        return this.updatedCount;
+    }
+
+    public void incrUpdatedCount() {
+        this.updatedCount++;
+    }
+
+    public void decrUpdatedCount() {
+        this.updatedCount--;
+    }
+
+    public Date getUpdated() {
+        return updated;
+    }
+
+    @Override
+    public ObjectInDataStoreStateMachine.State getState() {
+        // TODO Auto-generated method stub
+        return this.state;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
index 7ea68dc..9694a4c 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
@@ -29,11 +29,11 @@ import javax.inject.Inject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
-import org.apache.cloudstack.storage.image.db.ImageStoreDao;
-import org.apache.cloudstack.storage.image.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
 import org.springframework.stereotype.Component;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
index 60c71f0..17f2b89 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
@@ -32,9 +32,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
+import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
-import org.apache.cloudstack.storage.image.db.ImageStoreVO;
 
 import com.cloud.storage.ImageStore;
 import com.cloud.storage.dao.VMTemplateDao;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/DataStoreProviderDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/DataStoreProviderDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/db/DataStoreProviderDaoImpl.java
new file mode 100644
index 0000000..fce716a
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/db/DataStoreProviderDaoImpl.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.db;
+
+import org.apache.cloudstack.storage.datastore.db.DataStoreProviderDao;
+import org.apache.cloudstack.storage.datastore.db.DataStoreProviderVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria2;
+import com.cloud.utils.db.SearchCriteriaService;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+class DataStoreProviderDaoImpl extends GenericDaoBase<DataStoreProviderVO, Long> implements DataStoreProviderDao {
+
+    @Override
+    public DataStoreProviderVO findByName(String name) {
+        SearchCriteriaService<DataStoreProviderVO, DataStoreProviderVO> sc = SearchCriteria2.create(DataStoreProviderVO.class);
+        sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
+        return sc.find();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDao.java b/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDao.java
deleted file mode 100644
index 8a62766..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDao.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-
-
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
-
-import com.cloud.utils.db.GenericDao;
-import com.cloud.utils.fsm.StateDao;
-
-public interface SnapshotDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, VolumeDataStoreVO>  {
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDaoImpl.java
deleted file mode 100644
index 1c291db..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreDaoImpl.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-import java.util.Date;
-import java.util.Map;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.UpdateBuilder;
-
-@Component
-public class SnapshotDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Long> implements VolumeDataStoreDao {
-    private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreDaoImpl.class);
-    private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-    	super.configure(name, params);
-
-        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();
-        return true;
-    }
-    @Override
-    public boolean updateState(State currentState, Event event,
-            State nextState, VolumeDataStoreVO dataObj, Object data) {
-        Long oldUpdated = dataObj.getUpdatedCount();
-        Date oldUpdatedTime = dataObj.getUpdated();
-
-
-        SearchCriteria<VolumeDataStoreVO> sc = updateStateSearch.create();
-        sc.setParameters("id", dataObj.getId());
-        sc.setParameters("state", currentState);
-        sc.setParameters("updatedCount", dataObj.getUpdatedCount());
-
-        dataObj.incrUpdatedCount();
-
-        UpdateBuilder builder = getUpdateBuilder(dataObj);
-        builder.set(dataObj, "state", nextState);
-        builder.set(dataObj, "updated", new Date());
-
-        int rows = update(dataObj, sc);
-        if (rows == 0 && s_logger.isDebugEnabled()) {
-            VolumeDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
-            if (dbVol != null) {
-                StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
-                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(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
-                        .append("; updatedTime=").append(dataObj.getUpdated());
-                str.append(": stale Data={id=").append(dataObj.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=" + dataObj.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/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreVO.java b/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreVO.java
deleted file mode 100644
index 527385f..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/SnapshotDataStoreVO.java
+++ /dev/null
@@ -1,242 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
-
-import com.cloud.storage.Storage;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.fsm.StateObject;
-
-/**
- * Join table for image_data_store and snapshots
- *
- */
-@Entity
-@Table(name="snapshot_store_ref")
-public class SnapshotDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
-	@Id
-	@GeneratedValue(strategy=GenerationType.IDENTITY)
-	Long id;
-
-	@Column(name="store_id")
-	private long dataStoreId;
-
-	@Column(name="snapshot_id")
-	private long snapshotId;
-
-	@Column(name=GenericDaoBase.CREATED_COLUMN)
-	private Date created = null;
-
-	@Column(name="last_updated")
-	@Temporal(value=TemporalType.TIMESTAMP)
-	private Date lastUpdated = null;
-
-
-	@Column (name="size")
-	private long size;
-
-	@Column (name="physical_size")
-	private long physicalSize;
-
-
-	@Column (name="job_id")
-	private String jobId;
-
-	@Column (name="install_path")
-    private String installPath;
-
-
-    @Column(name="destroyed")
-    boolean destroyed = false;
-
-    @Column(name="update_count", updatable = true, nullable=false)
-    protected long updatedCount;
-
-    @Column(name = "updated")
-    @Temporal(value = TemporalType.TIMESTAMP)
-    Date updated;
-
-    @Column(name = "state")
-    @Enumerated(EnumType.STRING)
-    ObjectInDataStoreStateMachine.State state;
-
-    public String getInstallPath() {
-		return installPath;
-	}
-
-	public long getDataStoreId() {
-		return dataStoreId;
-	}
-
-	public void setHostId(long hostId) {
-		this.dataStoreId = hostId;
-	}
-
-
-    public long getSnapshotId() {
-		return snapshotId;
-	}
-
-
-    public void setSnapshotId(long snapshotId) {
-		this.snapshotId = snapshotId;
-	}
-
-
-
-
-    public long getId() {
-		return id;
-	}
-
-
-    public Date getCreated() {
-		return created;
-	}
-
-
-    public Date getLastUpdated() {
-		return lastUpdated;
-	}
-
-
-    public void setLastUpdated(Date date) {
-	    lastUpdated = date;
-	}
-
-
-    public void setInstallPath(String installPath) {
-	    this.installPath = installPath;
-	}
-
-
-
-	public SnapshotDataStoreVO(long hostId, long snapshotId) {
-		super();
-		this.dataStoreId = hostId;
-		this.snapshotId = snapshotId;
-		this.state = ObjectInDataStoreStateMachine.State.Allocated;
-	}
-
-
-
-	protected SnapshotDataStoreVO() {
-
-	}
-
-
-
-
-    public void setJobId(String jobId) {
-		this.jobId = jobId;
-	}
-
-
-    public String getJobId() {
-		return jobId;
-	}
-
-
-	public boolean equals(Object obj) {
-		if (obj instanceof SnapshotDataStoreVO) {
-			SnapshotDataStoreVO other = (SnapshotDataStoreVO)obj;
-			return (this.snapshotId==other.getSnapshotId() && this.dataStoreId==other.getDataStoreId());
-		}
-		return false;
-	}
-
-
-	public int hashCode() {
-		Long tid = new Long(snapshotId);
-		Long hid = new Long(dataStoreId);
-		return tid.hashCode()+hid.hashCode();
-	}
-
-    public void setSize(long size) {
-        this.size = size;
-    }
-
-    public long getSize() {
-        return size;
-    }
-
-
-    public void setPhysicalSize(long physicalSize) {
-        this.physicalSize = physicalSize;
-    }
-
-    public long getPhysicalSize() {
-        return physicalSize;
-    }
-
-    public void setDestroyed(boolean destroyed) {
-    	this.destroyed = destroyed;
-    }
-
-    public boolean getDestroyed() {
-    	return destroyed;
-    }
-
-	public long getVolumeSize() {
-	    return -1;
-	}
-
-
-    public String toString() {
-	    return new StringBuilder("VolumeHost[").append(id).append("-").append(snapshotId).append("-").append(dataStoreId).append(installPath).append("]").toString();
-	}
-
-    public long getUpdatedCount() {
-        return this.updatedCount;
-    }
-
-    public void incrUpdatedCount() {
-        this.updatedCount++;
-    }
-
-    public void decrUpdatedCount() {
-        this.updatedCount--;
-    }
-
-    public Date getUpdated() {
-        return updated;
-    }
-
-    @Override
-    public ObjectInDataStoreStateMachine.State getState() {
-        // TODO Auto-generated method stub
-        return this.state;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDao.java b/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDao.java
deleted file mode 100644
index 2faf3c7..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDao.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
-
-import com.cloud.utils.db.GenericDao;
-import com.cloud.utils.fsm.StateDao;
-
-public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, TemplateDataStoreVO>  {
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDaoImpl.java
deleted file mode 100644
index c40b8ba..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreDaoImpl.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-import java.util.Date;
-import java.util.Map;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.UpdateBuilder;
-
-@Component
-public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO, Long> implements TemplateDataStoreDao {
-    private static final Logger s_logger = Logger.getLogger(TemplateDataStoreDaoImpl.class);
-    private SearchBuilder<TemplateDataStoreVO> updateStateSearch;
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-    	super.configure(name, params);
-
-        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();
-        return true;
-    }
-    @Override
-    public boolean updateState(State currentState, Event event,
-            State nextState, TemplateDataStoreVO dataObj, Object data) {
-        Long oldUpdated = dataObj.getUpdatedCount();
-        Date oldUpdatedTime = dataObj.getUpdated();
-
-
-        SearchCriteria<TemplateDataStoreVO> sc = updateStateSearch.create();
-        sc.setParameters("id", dataObj.getId());
-        sc.setParameters("state", currentState);
-        sc.setParameters("updatedCount", dataObj.getUpdatedCount());
-
-        dataObj.incrUpdatedCount();
-
-        UpdateBuilder builder = getUpdateBuilder(dataObj);
-        builder.set(dataObj, "state", nextState);
-        builder.set(dataObj, "updated", new Date());
-
-        int rows = update(dataObj, sc);
-        if (rows == 0 && s_logger.isDebugEnabled()) {
-            TemplateDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
-            if (dbVol != null) {
-                StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
-                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(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
-                        .append("; updatedTime=").append(dataObj.getUpdated());
-                str.append(": stale Data={id=").append(dataObj.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=" + dataObj.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/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreVO.java b/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreVO.java
deleted file mode 100755
index af393a5..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/TemplateDataStoreVO.java
+++ /dev/null
@@ -1,310 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
-
-import com.cloud.storage.VMTemplateStorageResourceAssoc;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.fsm.StateObject;
-
-/**
- * Join table for image_data_store and templates
- *
- */
-@Entity
-@Table(name="template_store_ref")
-public class TemplateDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
-	@Id
-	@GeneratedValue(strategy=GenerationType.IDENTITY)
-	Long id;
-
-	@Column(name="store_id")
-	private long dataStoreId;
-
-	@Column(name="template_id")
-	private long templateId;
-
-	@Column(name=GenericDaoBase.CREATED_COLUMN)
-	private Date created = null;
-
-	@Column(name="last_updated")
-	@Temporal(value=TemporalType.TIMESTAMP)
-	private Date lastUpdated = null;
-
-	@Column (name="download_pct")
-	private int downloadPercent;
-
-	@Column (name="size")
-	private long size;
-
-	@Column (name="physical_size")
-	private long physicalSize;
-
-	@Column (name="download_state")
-	@Enumerated(EnumType.STRING)
-	private Status downloadState;
-
-	@Column (name="local_path")
-	private String localDownloadPath;
-
-	@Column (name="error_str")
-	private String errorString;
-
-	@Column (name="job_id")
-	private String jobId;
-
-	@Column (name="install_path")
-    private String installPath;
-
-	@Column (name="url")
-	private String downloadUrl;
-
-	@Column(name="is_copy")
-	private boolean isCopy = false;
-
-    @Column(name="destroyed")
-    boolean destroyed = false;
-
-    @Column(name="update_count", updatable = true, nullable=false)
-    protected long updatedCount;
-
-    @Column(name = "updated")
-    @Temporal(value = TemporalType.TIMESTAMP)
-    Date updated;
-
-    @Column(name = "state")
-    @Enumerated(EnumType.STRING)
-    ObjectInDataStoreStateMachine.State state;
-
-
-	@Override
-    public String getInstallPath() {
-		return installPath;
-	}
-
-
-	public long getDataStoreId() {
-		return dataStoreId;
-	}
-
-	public void setHostId(long hostId) {
-		this.dataStoreId = hostId;
-	}
-
-    public long getTemplateId() {
-		return templateId;
-	}
-
-    public void setTemplateId(long templateId) {
-		this.templateId = templateId;
-	}
-
-    public int getDownloadPercent() {
-		return downloadPercent;
-	}
-
-    public void setDownloadPercent(int downloadPercent) {
-		this.downloadPercent = downloadPercent;
-	}
-
-    public void setDownloadState(Status downloadState) {
-		this.downloadState = downloadState;
-	}
-
-    public long getId() {
-		return id;
-	}
-
-    public Date getCreated() {
-		return created;
-	}
-
-    public Date getLastUpdated() {
-		return lastUpdated;
-	}
-
-    public void setLastUpdated(Date date) {
-	    lastUpdated = date;
-	}
-
-    public void setInstallPath(String installPath) {
-	    this.installPath = installPath;
-	}
-
-    public Status getDownloadState() {
-		return downloadState;
-	}
-
-	public TemplateDataStoreVO(long hostId, long templateId) {
-		super();
-		this.dataStoreId = hostId;
-		this.templateId = templateId;
-		this.state = ObjectInDataStoreStateMachine.State.Allocated;
-	}
-
-	public TemplateDataStoreVO(long hostId, long templateId, Date lastUpdated,
-			int downloadPercent, Status downloadState,
-			String localDownloadPath, String errorString, String jobId,
-			String installPath, String downloadUrl) {
-		super();
-		this.dataStoreId = hostId;
-		this.templateId = templateId;
-		this.lastUpdated = lastUpdated;
-		this.downloadPercent = downloadPercent;
-		this.downloadState = downloadState;
-		this.localDownloadPath = localDownloadPath;
-		this.errorString = errorString;
-		this.jobId = jobId;
-		this.installPath = installPath;
-		this.setDownloadUrl(downloadUrl);
-	}
-
-	protected TemplateDataStoreVO() {
-
-	}
-
-
-    public void setLocalDownloadPath(String localPath) {
-		this.localDownloadPath = localPath;
-	}
-
-    public String getLocalDownloadPath() {
-		return localDownloadPath;
-	}
-
-    public void setErrorString(String errorString) {
-		this.errorString = errorString;
-	}
-
-    public String getErrorString() {
-		return errorString;
-	}
-
-    public void setJobId(String jobId) {
-		this.jobId = jobId;
-	}
-
-    public String getJobId() {
-		return jobId;
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (obj instanceof TemplateDataStoreVO) {
-			TemplateDataStoreVO other = (TemplateDataStoreVO)obj;
-			return (this.templateId==other.getTemplateId() && this.dataStoreId==other.getDataStoreId());
-		}
-		return false;
-	}
-
-	@Override
-	public int hashCode() {
-		Long tid = new Long(templateId);
-		Long hid = new Long(dataStoreId);
-		return tid.hashCode()+hid.hashCode();
-	}
-
-    public void setSize(long size) {
-        this.size = size;
-    }
-
-    public long getSize() {
-        return size;
-    }
-
-
-    public void setPhysicalSize(long physicalSize) {
-        this.physicalSize = physicalSize;
-    }
-
-    public long getPhysicalSize() {
-        return physicalSize;
-    }
-
-    public void setDestroyed(boolean destroyed) {
-    	this.destroyed = destroyed;
-    }
-
-    public boolean getDestroyed() {
-    	return destroyed;
-    }
-
-	public void setDownloadUrl(String downloadUrl) {
-		this.downloadUrl = downloadUrl;
-	}
-
-	public String getDownloadUrl() {
-		return downloadUrl;
-	}
-
-	public void setCopy(boolean isCopy) {
-		this.isCopy = isCopy;
-	}
-
-	public boolean isCopy() {
-		return isCopy;
-	}
-
-    public long getTemplateSize() {
-	    return -1;
-	}
-
-	@Override
-    public String toString() {
-	    return new StringBuilder("TmplHost[").append(id).append("-").append(templateId).append("-").append(dataStoreId).append(installPath).append("]").toString();
-	}
-
-    @Override
-    public ObjectInDataStoreStateMachine.State getState() {
-        // TODO Auto-generated method stub
-        return this.state;
-    }
-
-    public long getUpdatedCount() {
-        return this.updatedCount;
-    }
-
-    public void incrUpdatedCount() {
-        this.updatedCount++;
-    }
-
-    public void decrUpdatedCount() {
-        this.updatedCount--;
-    }
-
-    public Date getUpdated() {
-        return updated;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDao.java b/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDao.java
deleted file mode 100644
index e687d88..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDao.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-
-
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
-
-import com.cloud.utils.db.GenericDao;
-import com.cloud.utils.fsm.StateDao;
-
-public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>, StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, VolumeDataStoreVO>  {
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/74880fa2/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDaoImpl.java
deleted file mode 100644
index 1f7b278..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/db/VolumeDataStoreDaoImpl.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.storage.db;
-import java.util.Date;
-import java.util.Map;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.UpdateBuilder;
-
-@Component
-public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Long> implements VolumeDataStoreDao {
-    private static final Logger s_logger = Logger.getLogger(VolumeDataStoreDaoImpl.class);
-    private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-    	super.configure(name, params);
-
-        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();
-        return true;
-    }
-    @Override
-    public boolean updateState(State currentState, Event event,
-            State nextState, VolumeDataStoreVO dataObj, Object data) {
-        Long oldUpdated = dataObj.getUpdatedCount();
-        Date oldUpdatedTime = dataObj.getUpdated();
-
-
-        SearchCriteria<VolumeDataStoreVO> sc = updateStateSearch.create();
-        sc.setParameters("id", dataObj.getId());
-        sc.setParameters("state", currentState);
-        sc.setParameters("updatedCount", dataObj.getUpdatedCount());
-
-        dataObj.incrUpdatedCount();
-
-        UpdateBuilder builder = getUpdateBuilder(dataObj);
-        builder.set(dataObj, "state", nextState);
-        builder.set(dataObj, "updated", new Date());
-
-        int rows = update(dataObj, sc);
-        if (rows == 0 && s_logger.isDebugEnabled()) {
-            VolumeDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
-            if (dbVol != null) {
-                StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
-                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(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
-                        .append("; updatedTime=").append(dataObj.getUpdated());
-                str.append(": stale Data={id=").append(dataObj.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=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
-            }
-        }
-        return rows > 0;
-    }
-
-}