From 9c74f4ae762e3c09b6251633790447082e5b920f Mon Sep 17 00:00:00 2001 From: insanity Date: Fri, 27 Apr 2018 14:53:59 +0900 Subject: [PATCH] prePersist: count=0 --- .../loafle/overflow/model/probe/Probe.java | 26 ++++++++++--------- .../loafle/overflow/model/sensor/Sensor.java | 8 ++++-- .../loafle/overflow/model/target/Target.java | 9 +++++-- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/loafle/overflow/model/probe/Probe.java b/src/main/java/com/loafle/overflow/model/probe/Probe.java index 1f3384c..81d473d 100644 --- a/src/main/java/com/loafle/overflow/model/probe/Probe.java +++ b/src/main/java/com/loafle/overflow/model/probe/Probe.java @@ -4,6 +4,8 @@ import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.member.Member; import com.loafle.overflow.model.meta.MetaProbeStatus; +import org.hibernate.annotations.ColumnDefault; + import javax.persistence.*; import java.util.Date; @@ -25,8 +27,7 @@ public class Probe { private String cidr; private Date authorizeDate; private Member authorizeMember; - private int targetCount = 0; - + private int targetCount; public Probe() { @@ -37,7 +38,7 @@ public class Probe { } @Id - @GeneratedValue(strategy= GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.IDENTITY) public long getId() { return id; } @@ -56,7 +57,6 @@ public class Probe { this.status = status; } - @Column(name = "DESCRIPTION", nullable = true, length = 50) public String getDescription() { return description; @@ -86,7 +86,6 @@ public class Probe { this.domain = domain; } - @Column(name = "PROBE_KEY", nullable = false, unique = true) public String getProbeKey() { return probeKey; @@ -96,7 +95,6 @@ public class Probe { this.probeKey = probeKey; } - @Column(name = "ENCRYPTION_KEY", nullable = false, length = 100, unique = true) public String getEncryptionKey() { return encryptionKey; @@ -144,14 +142,18 @@ public class Probe { this.authorizeMember = authorizeMember; } - @Column(name = "TARGET_COUNT", nullable = false) - public int getTargetCount() { - return targetCount; - } + public int getTargetCount() { + return targetCount; + } - public void setTargetCount(int targetCount) { - this.targetCount = targetCount; + public void setTargetCount(int targetCount) { + this.targetCount = targetCount; + } + + @PrePersist + void preInsert() { + this.targetCount = 0; } } diff --git a/src/main/java/com/loafle/overflow/model/sensor/Sensor.java b/src/main/java/com/loafle/overflow/model/sensor/Sensor.java index 852706b..dba092e 100644 --- a/src/main/java/com/loafle/overflow/model/sensor/Sensor.java +++ b/src/main/java/com/loafle/overflow/model/sensor/Sensor.java @@ -115,8 +115,12 @@ public class Sensor { public void setDisplayName(String displayName) { this.displayName = displayName; - } - + } + + @PrePersist + void preInsert() { + this.itemCount = 0; + } @Transient public List getSensorItems() { diff --git a/src/main/java/com/loafle/overflow/model/target/Target.java b/src/main/java/com/loafle/overflow/model/target/Target.java index 055aaee..f74472a 100644 --- a/src/main/java/com/loafle/overflow/model/target/Target.java +++ b/src/main/java/com/loafle/overflow/model/target/Target.java @@ -18,7 +18,7 @@ public class Target { private Date createDate; private String displayName; private String description; - private int sensorCount = 0; + private int sensorCount; // Transient property private List sensors; @@ -79,7 +79,12 @@ public class Target { public void setSensors(List sensors) { this.sensors = sensors; - } + } + + @PrePersist + void preInsert() { + this.sensorCount = 0; + } // @ManyToOne