Sensor series
This commit is contained in:
snoop 2017-06-09 16:01:30 +09:00
parent 278a31cc44
commit 79d1e64a3a
15 changed files with 301 additions and 9 deletions

View File

@ -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<Sensor> implements SensorDao {
public List<Sensor> 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<Sensor> sensors = null;
try {
sensors = (List<Sensor>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return sensors;
}
}
}

View File

@ -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<SensorItem> implements SensorItemDao {
public List<SensorItem> 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<SensorItem> sensorItems = null;
try {
sensorItems = (List<SensorItem>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return sensorItems;
}
}
}

View File

@ -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<SensorItemMapping> implements SensorItemMappingDao {
public List<SensorItemMapping> 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<SensorItemMapping> sensorItemMappings = null;
try {
sensorItemMappings = (List<SensorItemMapping>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return sensorItemMappings;
}
}
}

View File

@ -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<Sensor> {
List<Sensor> findAllByAgentID(Agent agent);
}

View File

@ -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<SensorItem>{
List<SensorItem> findAllByCrawlerID(Crawler crawler);
}

View File

@ -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<SensorItemMapping> {
List<SensorItemMapping> findAllBySensorID(Sensor sensor);
}

View File

@ -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() {

View File

@ -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;

View File

@ -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() {

View File

@ -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

View File

@ -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()
}
}

View File

@ -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);
}
}

View File

@ -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<SensorItem> is = this.sensorItemDao.findAllByCrawlerID(crawler);
System.out.println(is.size());
}
}

View File

@ -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<SensorItemMapping> ml = this.sensorItemMappingDao.findAllBySensorID(sensor);
System.out.println(ml.size());
}
}

View File

@ -12,6 +12,12 @@
<class>com.loafle.overflow.crawler.model.Crawler</class>
<class>com.loafle.overflow.crawler.model.CrawlerInputItem</class>
<class>com.loafle.overflow.crawler.model.CrawlerInputItemMapping</class>
<class>com.loafle.overflow.sensor.model.Sensor</class>
<class>com.loafle.overflow.sensor.model.SensorItem</class>
<class>com.loafle.overflow.sensor.model.SensorItemMapping</class>
<class>com.loafle.overflow.sensor.model.SensorItemCategory</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.1.106:5432/postgres" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />