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; package com.loafle.overflow.sensor.dao;
import com.loafle.overflow.agent.model.Agent;
import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.commons.dao.JPABaseDAO;
import com.loafle.overflow.sensor.model.Sensor; import com.loafle.overflow.sensor.model.Sensor;
import javax.persistence.Query;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
public class JPASensorDao extends JPABaseDAO<Sensor> implements SensorDao { 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; package com.loafle.overflow.sensor.dao;
import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.commons.dao.JPABaseDAO;
import com.loafle.overflow.crawler.model.Crawler;
import com.loafle.overflow.sensor.model.SensorItem; import com.loafle.overflow.sensor.model.SensorItem;
import javax.persistence.Query;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
public class JPASensorItemDao extends JPABaseDAO<SensorItem> implements SensorItemDao { 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; package com.loafle.overflow.sensor.dao;
import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.commons.dao.JPABaseDAO;
import com.loafle.overflow.sensor.model.Sensor;
import com.loafle.overflow.sensor.model.SensorItemMapping; import com.loafle.overflow.sensor.model.SensorItemMapping;
import javax.persistence.Query;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
public class JPASensorItemMappingDao extends JPABaseDAO<SensorItemMapping> implements SensorItemMappingDao { 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; package com.loafle.overflow.sensor.dao;
import com.loafle.overflow.agent.model.Agent;
import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.commons.dao.BaseDAO;
import com.loafle.overflow.sensor.model.Sensor; import com.loafle.overflow.sensor.model.Sensor;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
public interface SensorDao extends BaseDAO<Sensor> { public interface SensorDao extends BaseDAO<Sensor> {
List<Sensor> findAllByAgentID(Agent agent);
} }

View File

@ -1,10 +1,16 @@
package com.loafle.overflow.sensor.dao; package com.loafle.overflow.sensor.dao;
import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.commons.dao.BaseDAO;
import com.loafle.overflow.crawler.model.Crawler;
import com.loafle.overflow.sensor.model.SensorItem; import com.loafle.overflow.sensor.model.SensorItem;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
public interface SensorItemDao extends BaseDAO<SensorItem>{ public interface SensorItemDao extends BaseDAO<SensorItem>{
List<SensorItem> findAllByCrawlerID(Crawler crawler);
} }

View File

@ -1,10 +1,16 @@
package com.loafle.overflow.sensor.dao; package com.loafle.overflow.sensor.dao;
import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.commons.dao.BaseDAO;
import com.loafle.overflow.sensor.model.Sensor;
import com.loafle.overflow.sensor.model.SensorItemMapping; import com.loafle.overflow.sensor.model.SensorItemMapping;
import java.util.List;
/** /**
* Created by root on 17. 6. 9. * Created by root on 17. 6. 9.
*/ */
public interface SensorItemMappingDao extends BaseDAO<SensorItemMapping> { public interface SensorItemMappingDao extends BaseDAO<SensorItemMapping> {
List<SensorItemMapping> findAllBySensorID(Sensor sensor);
} }

View File

@ -26,11 +26,11 @@ public class Sensor {
private Date createDate; private Date createDate;
@ManyToOne @ManyToOne
@Column(name = "TARGET_ID", nullable = false) @JoinColumn(name = "TARGET_ID", nullable = false)
private Target target; private Target target;
@ManyToOne @ManyToOne
@Column(name = "CRAWLER_ID", nullable = false) @JoinColumn(name = "CRAWLER_ID", nullable = false)
private Crawler crawler; private Crawler crawler;
public Long getId() { public Long getId() {

View File

@ -28,11 +28,11 @@ public class SensorItem {
private Date createDate; private Date createDate;
@ManyToOne @ManyToOne
@Column(name="CRAWLER_ID",nullable=false) @JoinColumn(name="CRAWLER_ID",nullable=false)
private Crawler crawler; private Crawler crawler;
@ManyToOne @ManyToOne
@Column(name="SENSOR_ITEM_CATEGORY_ID",nullable=false) @JoinColumn(name="SENSOR_ITEM_CATEGORY_ID",nullable=false)
private SensorItemCategory sensorItemCategory; private SensorItemCategory sensorItemCategory;

View File

@ -17,11 +17,11 @@ public class SensorItemMapping {
private Date createDate; private Date createDate;
@ManyToOne @ManyToOne
@Column(name = "SENSOR_ID", nullable = false) @JoinColumn(name = "SENSOR_ID", nullable = false)
private Sensor sensor; private Sensor sensor;
@ManyToOne @ManyToOne
@Column(name = "SENSOR_ITEM_ID", nullable = false) @JoinColumn(name = "SENSOR_ITEM_ID", nullable = false)
private SensorItem sensorItem; private SensorItem sensorItem;
public Long getId() { public Long getId() {

View File

@ -61,9 +61,9 @@ public class JPACrawlerDAOTest {
@Test @Test
public void TestInsert() { public void TestInsert() {
Crawler crawler = new Crawler(); Crawler crawler = new Crawler();
crawler.setName("SQL Crawler"); crawler.setName("Mysql Crawler");
crawler.setDescription("SQL Crawler"); crawler.setDescription("Mysql Crawler");
crawler.setCrawlerType("Java"); crawler.setCrawlerType("MysqlCrawler");
this.jpaCrawlerDAO.create(crawler); this.jpaCrawlerDAO.create(crawler);
} }
// TODO Crawler Select Test // 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.Crawler</class>
<class>com.loafle.overflow.crawler.model.CrawlerInputItem</class> <class>com.loafle.overflow.crawler.model.CrawlerInputItem</class>
<class>com.loafle.overflow.crawler.model.CrawlerInputItemMapping</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> <properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.1.106:5432/postgres" /> <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" /> <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />