cascade delete

This commit is contained in:
insanity 2017-06-26 21:21:59 +09:00
parent ab91e2e648
commit cc21e6ce6d
5 changed files with 19 additions and 3 deletions

View File

@ -3,6 +3,8 @@ package com.loafle.overflow.module.sensor.model;
import com.loafle.overflow.meta.model.MetaCrawler;
import com.loafle.overflow.meta.model.MetaSensorStatus;
import com.loafle.overflow.module.target.model.Target;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import javax.persistence.*;
import java.util.Date;
@ -61,6 +63,7 @@ public class Sensor {
}
@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "TARGET_ID", nullable = false)
public Target getTarget() {
return target;

View File

@ -1,6 +1,8 @@
package com.loafle.overflow.module.sensor.model;
import com.loafle.overflow.meta.model.MetaSensorItem;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import javax.persistence.*;
import java.util.Date;
@ -28,6 +30,7 @@ public class SensorItem {
@ManyToOne
@JoinColumn(name = "SENSOR_ID", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
public Sensor getSensor() {
return this.sensor;
}

View File

@ -2,6 +2,8 @@ package com.loafle.overflow.module.target.model;
import com.loafle.overflow.module.infra.model.Infra;
import com.loafle.overflow.module.probe.model.Probe;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import javax.persistence.*;
import java.util.Date;
@ -40,6 +42,7 @@ public class Target {
@ManyToOne
@JoinColumn(name = "PROBE_ID", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
public Probe getProbe() {
return probe;
}

View File

@ -275,7 +275,7 @@ INSERT INTO public.sensor (id,crawler_input_items,create_date,description,crawle
INSERT INTO public.sensor (id,crawler_input_items,create_date,description,crawler_id,status,target_id) VALUES (
2,NULL,'2017-06-26 20:19:07.074','My sensor',1,1,1);
INSERT INTO public.sensor_item (id,create_date,item_id,sensor_id) VALUES (
INSERT INTO public.sensor_item (id,create_date,item_id,sensor_id) VALUES (
1,'2017-06-26 20:21:16.626',1,1);
INSERT INTO public.sensor_item (id,create_date,item_id,sensor_id) VALUES (
2,'2017-06-26 20:21:50.988',2,2);

View File

@ -16,7 +16,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Date;
import java.util.List;
@Ignore
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class})
public class TargetDAOTest {
@ -25,6 +24,7 @@ public class TargetDAOTest {
private TargetDAO repo;
@Test
@Ignore
public void create() {
Target t = new Target();
t.setCreateDate(new Date());
@ -43,6 +43,7 @@ public class TargetDAOTest {
}
@Test
@Ignore
public void list() {
Probe p = new Probe();
@ -51,5 +52,11 @@ public class TargetDAOTest {
Assert.assertNotNull(list);
}
@Test
@Ignore
public void delete() {
Target t = new Target();
t.setId(1);
repo.delete(t);
}
}