package org.zstack.storage.primary.local;

import org.zstack.header.host.HostEO;
import org.zstack.header.storage.primary.PrimaryStorageEO;
import org.zstack.header.vo.ForeignKey;
import org.zstack.header.vo.ForeignKey.ReferenceOption;
import org.zstack.header.vo.Index;

import javax.persistence.*;
import java.sql.Timestamp;

/**
 * Created by frank on 6/30/2015.
 */
@Entity
@Table
@PrimaryKeyJoinColumns({
        @PrimaryKeyJoinColumn(name = "hostUuid",
                referencedColumnName = "hostUuid"),
        @PrimaryKeyJoinColumn(name = "primaryStorageUuid",
                referencedColumnName = "primaryStorageUuid")
})
public class LocalStorageHostRefVO {
    @Column
    @ForeignKey(parentEntityClass = HostEO.class, onDeleteAction = ReferenceOption.CASCADE)
    private String hostUuid;

    @Column
    @ForeignKey(parentEntityClass = PrimaryStorageEO.class, onDeleteAction = ReferenceOption.CASCADE)
    private String primaryStorageUuid;

    @Column
    @Index
    private long totalCapacity;

    @Column
    @Index
    private long availableCapacity;

    @Column
    @Index
    private long totalPhysicalCapacity;

    @Column
    @Index
    private long availablePhysicalCapacity;

    @Column
    private long systemUsedCapacity;

    @Column
    private Timestamp createDate;

    @Column
    private Timestamp lastOpDate;

    @PreUpdate
    private void preUpdate() {
        lastOpDate = null;
    }

    public long getSystemUsedCapacity() {
        return systemUsedCapacity;
    }

    public void setSystemUsedCapacity(long systemUsedCapacity) {
        this.systemUsedCapacity = systemUsedCapacity;
    }

    public String getPrimaryStorageUuid() {
        return primaryStorageUuid;
    }

    public void setPrimaryStorageUuid(String primaryStorageUuid) {
        this.primaryStorageUuid = primaryStorageUuid;
    }

    public String getHostUuid() {
        return hostUuid;
    }

    public void setHostUuid(String hostUuid) {
        this.hostUuid = hostUuid;
    }

    public long getTotalCapacity() {
        return totalCapacity;
    }

    public void setTotalCapacity(long totalCapacity) {
        this.totalCapacity = totalCapacity;
    }

    public long getAvailableCapacity() {
        return availableCapacity;
    }

    public void setAvailableCapacity(long availableCapacity) {
        this.availableCapacity = availableCapacity;
    }

    public long getTotalPhysicalCapacity() {
        return totalPhysicalCapacity;
    }

    public void setTotalPhysicalCapacity(long totalPhysicalCapacity) {
        this.totalPhysicalCapacity = totalPhysicalCapacity;
    }

    public long getAvailablePhysicalCapacity() {
        return availablePhysicalCapacity;
    }

    public void setAvailablePhysicalCapacity(long availablePhysicalCapacity) {
        this.availablePhysicalCapacity = availablePhysicalCapacity;
    }

    public Timestamp getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Timestamp createDate) {
        this.createDate = createDate;
    }

    public Timestamp getLastOpDate() {
        return lastOpDate;
    }

    public void setLastOpDate(Timestamp lastOpDate) {
        this.lastOpDate = lastOpDate;
    }
}

@@ -367,145 +367,87 @@
  */%0A
-@Entity%0A@Table%0A@PrimaryKeyJoinColumns(%7B%0A        @PrimaryKeyJoinColumn(name = %22hostUuid%22,%0A                referencedColumnName = %22
+class CompositePrimaryKeyForLocalStorageHostRefVO %7B%0A    private String 
 hostUuid
 %22),%0A
@@ -446,133 +446,125 @@
 Uuid
-%22),
+;
 %0A    
-    @PrimaryKeyJoinColumn(name = %22primaryStorageUuid%22,%0A                referencedColumnName = %22primaryStorageUuid%22)%0A%7D
+private String primaryStorageUuid;%0A%7D%0A%0A@Entity%0A@Table%0A@IdClass(CompositePrimaryKeyForLocalStorageHostRefVO.class
 )%0Apu
@@ -602,32 +602,40 @@
 O %7B%0A    @Column%0A
+    @Id%0A
     @ForeignKey(
@@ -748,24 +748,32 @@
     @Column%0A
+    @Id%0A
     @Foreign

use composite primary key for localstoragehostrefvo