mirror of https://github.com/apache/cloudstack.git
Updated VMSnapshotDetails* to match *Details* pattern (e.g. UserVMDetails*)
Signed-off-by: Edison Su <sudison@gmail.com>
This commit is contained in:
parent
d0123f9594
commit
aef633f203
|
|
@ -18,27 +18,25 @@
|
|||
*/
|
||||
package com.cloud.vm.snapshot;
|
||||
|
||||
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;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import org.apache.cloudstack.api.ResourceDetail;
|
||||
|
||||
@Entity
|
||||
@Table(name = "vm_snapshot_details")
|
||||
public class VMSnapshotDetailsVO implements InternalIdentity {
|
||||
public class VMSnapshotDetailsVO implements ResourceDetail {
|
||||
@Id
|
||||
@TableGenerator(name = "vm_snapshot_details_seq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "vm_snapshot_details_seq", allocationSize = 1)
|
||||
@GeneratedValue(strategy = GenerationType.TABLE)
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private long id;
|
||||
|
||||
@Column(name = "vm_snapshot_id")
|
||||
Long vmSnapshotId;
|
||||
private long resourceId;
|
||||
|
||||
@Column(name = "name")
|
||||
String name;
|
||||
|
|
@ -50,38 +48,34 @@ public class VMSnapshotDetailsVO implements InternalIdentity {
|
|||
|
||||
}
|
||||
|
||||
public VMSnapshotDetailsVO(Long vmSnapshotId, String name, String value) {
|
||||
this.vmSnapshotId = vmSnapshotId;
|
||||
public VMSnapshotDetailsVO(long vmSnapshotId, String name, String value) {
|
||||
this.resourceId = vmSnapshotId;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Long getVmSnapshotId() {
|
||||
return this.vmSnapshotId;
|
||||
}
|
||||
|
||||
public void setVmSnapshotId(Long vmSnapshotId) {
|
||||
this.vmSnapshotId = vmSnapshotId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,10 @@
|
|||
*/
|
||||
package com.cloud.vm.snapshot.dao;
|
||||
|
||||
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.snapshot.VMSnapshotDetailsVO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface VMSnapshotDetailsDao extends GenericDao<VMSnapshotDetailsVO, Long> {
|
||||
Map<String, String> getDetails(Long vmSnapshotId);
|
||||
public interface VMSnapshotDetailsDao extends GenericDao<VMSnapshotDetailsVO, Long>, ResourceDetailsDao<VMSnapshotDetailsVO> {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,35 +18,14 @@
|
|||
*/
|
||||
package com.cloud.vm.snapshot.dao;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
|
||||
|
||||
import com.cloud.vm.snapshot.VMSnapshotDetailsVO;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
public class VMSnapshotDetailsDaoImpl extends ResourceDetailsDaoBase<VMSnapshotDetailsVO> implements VMSnapshotDetailsDao {
|
||||
|
||||
public class VMSnapshotDetailsDaoImpl extends GenericDaoBase<VMSnapshotDetailsVO, Long> implements VMSnapshotDetailsDao {
|
||||
protected final SearchBuilder<VMSnapshotDetailsVO> searchDetails;
|
||||
|
||||
protected VMSnapshotDetailsDaoImpl() {
|
||||
super();
|
||||
searchDetails = createSearchBuilder();
|
||||
searchDetails.and("vmsnapshotId", searchDetails.entity().getVmSnapshotId(), SearchCriteria.Op.EQ);
|
||||
searchDetails.done();
|
||||
}
|
||||
@Override
|
||||
public Map<String, String> getDetails(Long vmSnapshotId) {
|
||||
SearchCriteria<VMSnapshotDetailsVO> sc = searchDetails.create();
|
||||
sc.setParameters("vmsnapshotId", vmSnapshotId);
|
||||
|
||||
List<VMSnapshotDetailsVO> details = listBy(sc);
|
||||
Map<String, String> detailsMap = new HashMap<String, String>();
|
||||
for (VMSnapshotDetailsVO detail : details) {
|
||||
detailsMap.put(detail.getName(), detail.getValue());
|
||||
}
|
||||
|
||||
return detailsMap;
|
||||
public void addDetail(long resourceId, String key, String value) {
|
||||
super.addDetail(new VMSnapshotDetailsVO(resourceId, key, value));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,16 +18,19 @@
|
|||
*/
|
||||
package com.cloud.vm.snapshot.dao;
|
||||
|
||||
import com.cloud.vm.snapshot.VMSnapshotDetailsVO;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.cloudstack.storage.test.CloudStackTestNGBase;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
import com.cloud.vm.snapshot.VMSnapshotDetailsVO;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath:/storageContext.xml")
|
||||
|
|
@ -39,7 +42,7 @@ public class VmSnapshotDaoTest extends CloudStackTestNGBase {
|
|||
public void testVmSnapshotDetails() {
|
||||
VMSnapshotDetailsVO detailsVO = new VMSnapshotDetailsVO(1L, "test", "foo");
|
||||
vmsnapshotDetailsDao.persist(detailsVO);
|
||||
Map<String, String> details = vmsnapshotDetailsDao.getDetails(1L);
|
||||
Map<String, String> details = vmsnapshotDetailsDao.listDetailsKeyPairs(1L);
|
||||
Assert.assertTrue(details.containsKey("test"));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue