From 71df148395d384698ffaa86fac106ca94cafd86d Mon Sep 17 00:00:00 2001 From: geek Date: Thu, 8 Jun 2017 18:58:20 +0900 Subject: [PATCH] crawler model dao add crawler test code add --- .../overflow/crawler/dao/CrawlerDAO.java | 3 +++ .../dao/CrawlerInputItemMappingDAO.java | 4 ++++ .../overflow/crawler/dao/JPACrawlerDAO.java | 17 +++++++++++++++++ .../dao/JPACrawlerInputItemMappingDAO.java | 19 +++++++++++++++++++ .../crawler/dao/JPACrawlerDAOTest.java | 5 +++++ .../JPACrawlerInputItemMappingDAOTest.java | 6 ++++++ 6 files changed, 54 insertions(+) diff --git a/src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java index aeccb0b..ed43969 100644 --- a/src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java +++ b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerDAO.java @@ -3,8 +3,11 @@ package com.loafle.overflow.crawler.dao; import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.crawler.model.Crawler; +import java.util.List; + /** * Created by geek@loafle.com on 17. 6. 8. */ public interface CrawlerDAO extends BaseDAO { + public List findAll(); } diff --git a/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java index 6d1f37a..88529bd 100644 --- a/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java +++ b/src/main/java/com/loafle/overflow/crawler/dao/CrawlerInputItemMappingDAO.java @@ -1,10 +1,14 @@ package com.loafle.overflow.crawler.dao; import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.crawler.model.Crawler; import com.loafle.overflow.crawler.model.CrawlerInputItemMapping; +import java.util.List; + /** * Created by geek@loafle.com on 17. 6. 8. */ public interface CrawlerInputItemMappingDAO extends BaseDAO { + public List findByCrawlerId(Crawler crawler); } diff --git a/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java index def8dc4..ee4c495 100644 --- a/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java +++ b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerDAO.java @@ -3,8 +3,25 @@ package com.loafle.overflow.crawler.dao; import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.crawler.model.Crawler; +import javax.persistence.Query; +import java.util.List; + /** * Created by geek@loafle.com on 17. 6. 8. */ public class JPACrawlerDAO extends JPABaseDAO implements CrawlerDAO { + @Override + public List findAll() { + Query query = getEntityManager().createNativeQuery("SELECT c.* FROM CRAWLER c ", Crawler.class); + + List crs = null; + + try { + crs = (List)query.getResultList(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + return crs; + } + } } diff --git a/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java index 47bc258..320dcdf 100644 --- a/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java +++ b/src/main/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAO.java @@ -1,10 +1,29 @@ package com.loafle.overflow.crawler.dao; import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.crawler.model.Crawler; import com.loafle.overflow.crawler.model.CrawlerInputItemMapping; +import javax.persistence.Query; +import java.util.List; + /** * Created by geek@loafle.com on 17. 6. 8. */ public class JPACrawlerInputItemMappingDAO extends JPABaseDAO implements CrawlerInputItemMappingDAO { + @Override + public List findByCrawlerId(Crawler crawler) { + Query query = getEntityManager().createNativeQuery("SELECT m.* FROM CRAWLER_INPUT_ITEM_MAPPING m WHERE m.crawler_id = :crawler_id", CrawlerInputItemMapping.class); + query.setParameter("crawler_id", crawler.getId()); + + List crs = null; + + try { + crs = (List)query.getResultList(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + return crs; + } + } } 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 ee496df..5cead64 100644 --- a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerDAOTest.java @@ -66,6 +66,11 @@ public class JPACrawlerDAOTest { } // TODO Crawler Select Test + @Test + public void TestListAll() { + List ls = this.jpaCrawlerDAO.findAll(); + System.out.println(ls.size()); + } // TODO Crawler Update Test // TODO Crawler Delete Test diff --git a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java index f92eec9..6328472 100644 --- a/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java +++ b/src/test/java/com/loafle/overflow/crawler/dao/JPACrawlerInputItemMappingDAOTest.java @@ -79,4 +79,10 @@ public class JPACrawlerInputItemMappingDAOTest { this.mappingDAO.createAll(crs); } + @Test + public void TestFindByCrawlerId() { + List ls = this.mappingDAO.findByCrawlerId(new Crawler((long)5)); + System.out.println(ls.size()); + } + } \ No newline at end of file