@Transactional private VolumeSnapshotStruct newChain(VolumeSnapshotVO vo, boolean fullsnapshot) { VolumeSnapshotTreeVO chain = new VolumeSnapshotTreeVO(); chain.setCurrent(true); chain.setVolumeUuid(vo.getVolumeUuid()); chain.setUuid(Platform.getUuid()); chain = dbf.getEntityManager().merge(chain); logger.debug(String.format("created new volume snapshot tree[tree uuid:%s, volume uuid:%s, full snapshot uuid:%s]", chain.getUuid(), vo.getVolumeUuid(), vo.getUuid())); vo.setTreeUuid(chain.getUuid()); vo.setDistance(fullsnapshot ? 0 : 1); vo.setParentUuid(null); vo.setLatest(true); vo.setFullSnapshot(fullsnapshot); dbf.getEntityManager().persist(vo); dbf.getEntityManager().flush(); dbf.getEntityManager().refresh(vo); VolumeSnapshotStruct struct = new VolumeSnapshotStruct(); struct.setCurrent(VolumeSnapshotInventory.valueOf(vo)); struct.setFullSnapshot(fullsnapshot); return struct; }
TypedQuery<VolumeSnapshotVO> q = dbf.getEntityManager().createQuery(sql, VolumeSnapshotVO.class); q.setParameter("volUuid", vo.getVolumeUuid()); q.setParameter("chainUuid", chain.getUuid()); VolumeSnapshotVO latest = q.getSingleResult();
public static VolumeSnapshotTreeInventory valueOf(VolumeSnapshotTreeVO vo) { VolumeSnapshotTreeInventory inv = new VolumeSnapshotTreeInventory(); inv.setCreateDate(vo.getCreateDate()); inv.setCurrent(vo.isCurrent()); inv.setLastOpDate(vo.getLastOpDate()); inv.setUuid(vo.getUuid()); inv.setVolumeUuid(vo.getVolumeUuid()); return inv; }
VolumeSnapshotTreeInventory inv = VolumeSnapshotTreeInventory.valueOf(vo); SimpleQuery<VolumeSnapshotVO> sq = dbf.createQuery(VolumeSnapshotVO.class); sq.add(VolumeSnapshotVO_.treeUuid, Op.EQ, vo.getUuid()); List<VolumeSnapshotVO> vos = sq.list(); VolumeSnapshotTree tree = VolumeSnapshotTree.fromVOs(vos);