From 42aee25f0c34a9ae10637d46334b00378d38f210 Mon Sep 17 00:00:00 2001 From: insanity Date: Mon, 5 Jun 2017 18:21:30 +0900 Subject: [PATCH] agent --- .../loafle/overflow/agent/dao/AgentDAO.java | 4 +++ .../overflow/agent/dao/JPAAgentDAO.java | 21 +++++++++++ .../loafle/overflow/agent/model/Agent.java | 36 +++++++++++++++++++ .../overflow/agent/dao/JPAAgentDAOTest.java | 15 +++++--- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/loafle/overflow/agent/dao/AgentDAO.java b/src/main/java/com/loafle/overflow/agent/dao/AgentDAO.java index 7be627d..65747ff 100644 --- a/src/main/java/com/loafle/overflow/agent/dao/AgentDAO.java +++ b/src/main/java/com/loafle/overflow/agent/dao/AgentDAO.java @@ -2,9 +2,13 @@ package com.loafle.overflow.agent.dao; import com.loafle.overflow.agent.model.Agent; import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.member.model.Member; + +import java.util.List; /** * Created by insanity on 17. 5. 29. */ public interface AgentDAO extends BaseDAO { + public List findAgentListByMemberId(Member member); } diff --git a/src/main/java/com/loafle/overflow/agent/dao/JPAAgentDAO.java b/src/main/java/com/loafle/overflow/agent/dao/JPAAgentDAO.java index 6e6d882..53752d7 100644 --- a/src/main/java/com/loafle/overflow/agent/dao/JPAAgentDAO.java +++ b/src/main/java/com/loafle/overflow/agent/dao/JPAAgentDAO.java @@ -2,10 +2,31 @@ package com.loafle.overflow.agent.dao; import com.loafle.overflow.agent.model.Agent; import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.member.model.Member; + +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.List; /** * Created by insanity on 17. 5. 29. */ public class JPAAgentDAO extends JPABaseDAO implements AgentDAO { + + public List findAgentListByMemberId(Member member) { + Query query = getEntityManager() + .createNativeQuery("SELECT agt.* FROM AGENT agt WHERE agt.MEMBER_ID = :member", Agent.class); + query.setParameter("member", member.getId()); + + List list = new ArrayList<>(); + try { + list = query.getResultList(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return list; + } + } + } diff --git a/src/main/java/com/loafle/overflow/agent/model/Agent.java b/src/main/java/com/loafle/overflow/agent/model/Agent.java index 0081efe..4e7273f 100644 --- a/src/main/java/com/loafle/overflow/agent/model/Agent.java +++ b/src/main/java/com/loafle/overflow/agent/model/Agent.java @@ -1,5 +1,7 @@ package com.loafle.overflow.agent.model; +import com.loafle.overflow.member.model.Member; + import javax.persistence.*; import java.io.Serializable; @@ -13,12 +15,22 @@ public class Agent implements Serializable { @GeneratedValue(strategy= GenerationType.IDENTITY) private Long id; + @ManyToOne + @JoinColumn(name = "MEMBER_ID", nullable=false) + private Member member; + @Column(name="AUTHORIZED_DATE") private Long authorizedDate; @Column(name="DESCRIPTION") private String description; + @Column(name="LAST_POLLING_DATE") + private Long lastPollingDate; + + @Column(name="STATUS") + private String status; + public Long getId() { return id; @@ -28,6 +40,14 @@ public class Agent implements Serializable { this.id = id; } + public Member getMember() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } + public Long getAuthorizedDate() { return authorizedDate; } @@ -43,4 +63,20 @@ public class Agent implements Serializable { public void setDescription(String description) { this.description = description; } + + public Long getLastPollingDate() { + return lastPollingDate; + } + + public void setLastPollingDate(Long lastPollingDate) { + this.lastPollingDate = lastPollingDate; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } } diff --git a/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java b/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java index d92c058..7813609 100644 --- a/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java +++ b/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java @@ -1,13 +1,15 @@ package com.loafle.overflow.agent.dao; +import com.loafle.overflow.agent.model.Agent; +import com.loafle.overflow.member.model.Member; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; - /** * Created by root on 17. 6. 4. */ +@Ignore public class JPAAgentDAOTest { private JPAAgentDAO jpaAgentDAO = null; @@ -20,9 +22,14 @@ public class JPAAgentDAOTest { @Test public void createAgent() { + Member m = new Member(); + m.setId(Long.valueOf(1)); + Agent agent = new Agent(); + agent.setDescription("test agent"); + agent.setMember(m); + Agent savedAgent = jpaAgentDAO.create(agent); - - + System.out.println(savedAgent.getDescription()); } } \ No newline at end of file