crawler model dao add

crawler test code add
This commit is contained in:
geek 2017-06-08 18:58:20 +09:00
parent ea3935251b
commit 71df148395
6 changed files with 54 additions and 0 deletions

View File

@ -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<Crawler> {
public List<Crawler> findAll();
}

View File

@ -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<CrawlerInputItemMapping> {
public List<CrawlerInputItemMapping> findByCrawlerId(Crawler crawler);
}

View File

@ -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<Crawler> implements CrawlerDAO {
@Override
public List<Crawler> findAll() {
Query query = getEntityManager().createNativeQuery("SELECT c.* FROM CRAWLER c ", Crawler.class);
List<Crawler> crs = null;
try {
crs = (List<Crawler>)query.getResultList();
} catch (Exception e) {
e.printStackTrace();
} finally {
return crs;
}
}
}

View File

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

View File

@ -66,6 +66,11 @@ public class JPACrawlerDAOTest {
}
// TODO Crawler Select Test
@Test
public void TestListAll() {
List<Crawler> ls = this.jpaCrawlerDAO.findAll();
System.out.println(ls.size());
}
// TODO Crawler Update Test
// TODO Crawler Delete Test

View File

@ -79,4 +79,10 @@ public class JPACrawlerInputItemMappingDAOTest {
this.mappingDAO.createAll(crs);
}
@Test
public void TestFindByCrawlerId() {
List<CrawlerInputItemMapping> ls = this.mappingDAO.findByCrawlerId(new Crawler((long)5));
System.out.println(ls.size());
}
}