package org.zstack.header.storage.snapshot;

import org.zstack.header.identity.OwnedByAccount;
import org.zstack.header.storage.primary.PrimaryStorageVO;
import org.zstack.header.storage.snapshot.group.VolumeSnapshotGroupRefVO;
import org.zstack.header.vo.BaseResource;
import org.zstack.header.vo.EO;
import org.zstack.header.vo.EntityGraph;
import org.zstack.header.vo.NoView;
import org.zstack.header.volume.VolumeVO;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 */
@Entity
@Table
@EO(EOClazz = VolumeSnapshotEO.class)
@BaseResource
@EntityGraph(
        parents = {
                @EntityGraph.Neighbour(type = VolumeVO.class, myField = "volumeUuid", targetField = "uuid"),
                @EntityGraph.Neighbour(type = VolumeSnapshotTreeVO.class, myField = "treeUuid", targetField = "uuid"),
                @EntityGraph.Neighbour(type = PrimaryStorageVO.class, myField = "primaryStorageUuid", targetField = "uuid"),
        }
)
public class VolumeSnapshotVO extends VolumeSnapshotAO implements OwnedByAccount {
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "volumeSnapshotUuid", insertable = false, updatable = false)
    @NoView
    private List<VolumeSnapshotBackupStorageRefVO> backupStorageRefs = new ArrayList<VolumeSnapshotBackupStorageRefVO>();


    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "uuid", referencedColumnName = "volumeSnapshotUuid", insertable = false, updatable = false)
    @NoView
    private VolumeSnapshotGroupRefVO groupRef;

    @Transient
    private String accountUuid;

    @Override
    public String getAccountUuid() {
        return accountUuid;
    }

    @Override
    public void setAccountUuid(String accountUuid) {
        this.accountUuid = accountUuid;
    }

    public List<VolumeSnapshotBackupStorageRefVO> getBackupStorageRefs() {
        return backupStorageRefs;
    }

    public void setBackupStorageRefs(List<VolumeSnapshotBackupStorageRefVO> backupStorageRefs) {
        this.backupStorageRefs = backupStorageRefs;
    }

    public VolumeSnapshotGroupRefVO getGroupRef() {
        return groupRef;
    }

    public void setGroupRef(VolumeSnapshotGroupRefVO groupRef) {
        this.groupRef = groupRef;
    }
}

@@ -1341,32 +1341,63 @@
  FetchType.EAGER
+, cascade = %7BCascadeType.MERGE%7D
 )%0A    @JoinColum
@@ -1470,35 +1470,16 @@
 rtable =
- false, updatable =
  false)%0A
@@ -2246,11 +2246,304 @@
 f;%0A    %7D
+%0A%0A    @Override%0A    public void setPrimaryStorageInstallPath(String primaryStorageInstallPath) %7B%0A        super.setPrimaryStorageInstallPath(primaryStorageInstallPath);%0A        if (groupRef != null) %7B%0A            groupRef.setVolumeSnapshotInstallPath(primaryStorageInstallPath);%0A        %7D%0A    %7D
 %0A%7D%0A

update snapshot group ref install path too when update snapshot installPath Resovles ZSTAC-22700