diff --git a/src/main/java/com/loafle/overflow/sensor/dao/JPASensorDao.java b/src/main/java/com/loafle/overflow/sensor/dao/JPASensorDao.java index 6321dc0..4cc1324 100644 --- a/src/main/java/com/loafle/overflow/sensor/dao/JPASensorDao.java +++ b/src/main/java/com/loafle/overflow/sensor/dao/JPASensorDao.java @@ -1,10 +1,28 @@ package com.loafle.overflow.sensor.dao; +import com.loafle.overflow.agent.model.Agent; import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.sensor.model.Sensor; +import javax.persistence.Query; +import java.util.List; + /** * Created by root on 17. 6. 9. */ public class JPASensorDao extends JPABaseDAO implements SensorDao { + + public List findAllByAgentID(Agent agent) { + Query query = getEntityManager().createNativeQuery("SELECT s.* FROM Sensor s WHERE s.TARGET_ID = :memberId", Sensor.class); + query.setParameter("memberId", agent.getMember().getId()); + + List sensors = null; + try { + sensors = (List)query.getResultList(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return sensors; + } + } } diff --git a/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemDao.java b/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemDao.java index 4985882..d71d4df 100644 --- a/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemDao.java +++ b/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemDao.java @@ -1,10 +1,31 @@ package com.loafle.overflow.sensor.dao; import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.crawler.model.Crawler; import com.loafle.overflow.sensor.model.SensorItem; + +import javax.persistence.Query; +import java.util.List; + /** * Created by root on 17. 6. 9. */ public class JPASensorItemDao extends JPABaseDAO implements SensorItemDao { + + public List findAllByCrawlerID(Crawler crawler) { + + Query query = getEntityManager().createNativeQuery("SELECT si.* FROM SensorItem si WHERE si.CRAWLER_ID = :crawlerId", SensorItem.class); + query.setParameter("crawlerId", crawler.getId()); + + List sensorItems = null; + try { + sensorItems = (List)query.getResultList(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return sensorItems; + } + + } } diff --git a/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDao.java b/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDao.java index c410a39..cc92bbf 100644 --- a/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDao.java +++ b/src/main/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDao.java @@ -1,10 +1,30 @@ package com.loafle.overflow.sensor.dao; import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.sensor.model.Sensor; import com.loafle.overflow.sensor.model.SensorItemMapping; +import javax.persistence.Query; +import java.util.List; + /** * Created by root on 17. 6. 9. */ public class JPASensorItemMappingDao extends JPABaseDAO implements SensorItemMappingDao { + + public List findAllBySensorID(Sensor sensor) { + + Query query = getEntityManager().createNativeQuery("SELECT sim.* FROM SensorItemMapping sim WHERE sim.SENSOR_ID = :sensorId", SensorItemMapping.class); + query.setParameter("sensorId", sensor.getId()); + + List sensorItemMappings = null; + try { + sensorItemMappings = (List)query.getResultList(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return sensorItemMappings; + } + + } } diff --git a/src/main/java/com/loafle/overflow/sensor/dao/SensorDao.java b/src/main/java/com/loafle/overflow/sensor/dao/SensorDao.java index 9bd3105..5f8d699 100644 --- a/src/main/java/com/loafle/overflow/sensor/dao/SensorDao.java +++ b/src/main/java/com/loafle/overflow/sensor/dao/SensorDao.java @@ -1,10 +1,15 @@ package com.loafle.overflow.sensor.dao; +import com.loafle.overflow.agent.model.Agent; import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.sensor.model.Sensor; +import java.util.List; + /** * Created by root on 17. 6. 9. */ public interface SensorDao extends BaseDAO { + + List findAllByAgentID(Agent agent); } diff --git a/src/main/java/com/loafle/overflow/sensor/dao/SensorItemDao.java b/src/main/java/com/loafle/overflow/sensor/dao/SensorItemDao.java index f0d6070..08c55fa 100644 --- a/src/main/java/com/loafle/overflow/sensor/dao/SensorItemDao.java +++ b/src/main/java/com/loafle/overflow/sensor/dao/SensorItemDao.java @@ -1,10 +1,16 @@ package com.loafle.overflow.sensor.dao; import com.loafle.overflow.commons.dao.BaseDAO; + +import com.loafle.overflow.crawler.model.Crawler; import com.loafle.overflow.sensor.model.SensorItem; +import java.util.List; + /** * Created by root on 17. 6. 9. */ public interface SensorItemDao extends BaseDAO{ + + List findAllByCrawlerID(Crawler crawler); } diff --git a/src/main/java/com/loafle/overflow/sensor/dao/SensorItemMappingDao.java b/src/main/java/com/loafle/overflow/sensor/dao/SensorItemMappingDao.java index c7cb238..3bb3712 100644 --- a/src/main/java/com/loafle/overflow/sensor/dao/SensorItemMappingDao.java +++ b/src/main/java/com/loafle/overflow/sensor/dao/SensorItemMappingDao.java @@ -1,10 +1,16 @@ package com.loafle.overflow.sensor.dao; import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.sensor.model.Sensor; import com.loafle.overflow.sensor.model.SensorItemMapping; +import java.util.List; + /** * Created by root on 17. 6. 9. */ public interface SensorItemMappingDao extends BaseDAO { + + List findAllBySensorID(Sensor sensor); + } diff --git a/src/main/java/com/loafle/overflow/sensor/model/Sensor.java b/src/main/java/com/loafle/overflow/sensor/model/Sensor.java index bc73955..7c5fd68 100644 --- a/src/main/java/com/loafle/overflow/sensor/model/Sensor.java +++ b/src/main/java/com/loafle/overflow/sensor/model/Sensor.java @@ -26,11 +26,11 @@ public class Sensor { private Date createDate; @ManyToOne - @Column(name = "TARGET_ID", nullable = false) + @JoinColumn(name = "TARGET_ID", nullable = false) private Target target; @ManyToOne - @Column(name = "CRAWLER_ID", nullable = false) + @JoinColumn(name = "CRAWLER_ID", nullable = false) private Crawler crawler; public Long getId() { diff --git a/src/main/java/com/loafle/overflow/sensor/model/SensorItem.java b/src/main/java/com/loafle/overflow/sensor/model/SensorItem.java index 4c84216..60be7f1 100644 --- a/src/main/java/com/loafle/overflow/sensor/model/SensorItem.java +++ b/src/main/java/com/loafle/overflow/sensor/model/SensorItem.java @@ -28,11 +28,11 @@ public class SensorItem { private Date createDate; @ManyToOne - @Column(name="CRAWLER_ID",nullable=false) + @JoinColumn(name="CRAWLER_ID",nullable=false) private Crawler crawler; @ManyToOne - @Column(name="SENSOR_ITEM_CATEGORY_ID",nullable=false) + @JoinColumn(name="SENSOR_ITEM_CATEGORY_ID",nullable=false) private SensorItemCategory sensorItemCategory; diff --git a/src/main/java/com/loafle/overflow/sensor/model/SensorItemMapping.java b/src/main/java/com/loafle/overflow/sensor/model/SensorItemMapping.java index 49d62b9..d7a1d0e 100644 --- a/src/main/java/com/loafle/overflow/sensor/model/SensorItemMapping.java +++ b/src/main/java/com/loafle/overflow/sensor/model/SensorItemMapping.java @@ -17,11 +17,11 @@ public class SensorItemMapping { private Date createDate; @ManyToOne - @Column(name = "SENSOR_ID", nullable = false) + @JoinColumn(name = "SENSOR_ID", nullable = false) private Sensor sensor; @ManyToOne - @Column(name = "SENSOR_ITEM_ID", nullable = false) + @JoinColumn(name = "SENSOR_ITEM_ID", nullable = false) private SensorItem sensorItem; public Long getId() { diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java index f1cafbb..b9cae8a 100644 --- a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java @@ -61,9 +61,9 @@ public class JPACrawlerDAOTest { @Test public void TestInsert() { Crawler crawler = new Crawler(); - crawler.setName("SQL Crawler"); - crawler.setDescription("SQL Crawler"); - crawler.setCrawlerType("Java"); + crawler.setName("Mysql Crawler"); + crawler.setDescription("Mysql Crawler"); + crawler.setCrawlerType("MysqlCrawler"); this.jpaCrawlerDAO.create(crawler); } // TODO Crawler Select Test diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorDaoTest.java new file mode 100644 index 0000000..993bb99 --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorDaoTest.java @@ -0,0 +1,55 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.crawler.model.Crawler; +import com.loafle.overflow.sensor.model.Sensor; +import com.loafle.overflow.target.model.Target; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorDaoTest { + + private SensorDao sensorDao = null; + + @Before + public void before() { + this.sensorDao = new JPASensorDao(); + } + + @Test + public void findAllByAgentID() throws Exception { + } + + + @Test + public void create() { + + + Sensor sensor = new Sensor(); + + Crawler crawler = new Crawler(); + crawler.setId(1L); + + Target target = new Target(); + target.setId(1L); + + sensor.setCrawler(crawler); + sensor.setInterval(1); + sensor.setNotification("nothing"); + sensor.setTarget(target); + + this.sensorDao.create(sensor); + + } + + @Test + public void list() { + +// this.sensorDao.findAllByAgentID() + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemCategoryDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemCategoryDaoTest.java new file mode 100644 index 0000000..4ad3f98 --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemCategoryDaoTest.java @@ -0,0 +1,35 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.sensor.model.SensorItemCategory; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorItemCategoryDaoTest { + + private SensorItemCategoryDao sensorItemCategoryDao = null; + + @Before + public void before() { + + this.sensorItemCategoryDao = new JPASensorItemCategoryDao(); + } + + + @Test + public void create() { + + SensorItemCategory sensorItemCategory = new SensorItemCategory(); + + sensorItemCategory.setName("count"); + sensorItemCategory.setDescription("count !!!!"); + + this.sensorItemCategoryDao.create(sensorItemCategory); + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemDaoTest.java new file mode 100644 index 0000000..bd4da1e --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemDaoTest.java @@ -0,0 +1,60 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.crawler.model.Crawler; +import com.loafle.overflow.sensor.model.SensorItem; +import com.loafle.overflow.sensor.model.SensorItemCategory; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorItemDaoTest { + + private SensorItemDao sensorItemDao = null; + + @Before + public void before() { + this.sensorItemDao = new JPASensorItemDao(); + } + + @Test + public void create() { + + + SensorItem sensorItem = new SensorItem(); + + Crawler crawler = new Crawler(); + crawler.setId(1L); + + SensorItemCategory category = new SensorItemCategory(); + category.setId(1L); + + sensorItem.setCrawler(crawler); + sensorItem.setDataType("int"); + sensorItem.setDescription("count getget"); + sensorItem.setName("net.mysql.connection_count"); + sensorItem.setSensorItemCategory(category); + + this.sensorItemDao.create(sensorItem); + + } + + @Test + public void list() { + + Crawler crawler = new Crawler(); + crawler.setId(1L); + + List is = this.sensorItemDao.findAllByCrawlerID(crawler); + + + System.out.println(is.size()); + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDaoTest.java b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDaoTest.java new file mode 100644 index 0000000..7d52445 --- /dev/null +++ b/src/test/java/com/loafle/overflow/sensor/dao/JPASensorItemMappingDaoTest.java @@ -0,0 +1,60 @@ +package com.loafle.overflow.sensor.dao; + +import com.loafle.overflow.sensor.model.Sensor; +import com.loafle.overflow.sensor.model.SensorItem; +import com.loafle.overflow.sensor.model.SensorItemMapping; +import org.junit.Before; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 9. + */ +public class JPASensorItemMappingDaoTest { + + private SensorItemMappingDao sensorItemMappingDao = null; + + @Before + public void before() { + this.sensorItemMappingDao = new JPASensorItemMappingDao(); + } + + + @Test + public void create() { + + SensorItemMapping mapping = new SensorItemMapping(); + + Sensor sensor = new Sensor(); + + sensor.setId(1L); + + SensorItem sensorItem = new SensorItem(); + + sensorItem.setId(1L); + + mapping.setSensor(sensor); + + mapping.setSensorItem(sensorItem); + + this.sensorItemMappingDao.create(mapping); + + } + + @Test + public void list() { + + Sensor sensor = new Sensor(); + + sensor.setId(1L); + + List ml = this.sensorItemMappingDao.findAllBySensorID(sensor); + + System.out.println(ml.size()); + + } + +} \ No newline at end of file diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 07e69dd..b28c0de 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -12,6 +12,12 @@ com.loafle.overflow.crawler.model.Crawler com.loafle.overflow.crawler.model.CrawlerInputItem com.loafle.overflow.crawler.model.CrawlerInputItemMapping + + com.loafle.overflow.sensor.model.Sensor + com.loafle.overflow.sensor.model.SensorItem + com.loafle.overflow.sensor.model.SensorItemMapping + com.loafle.overflow.sensor.model.SensorItemCategory +