This commit is contained in:
insanity 2017-06-05 18:21:30 +09:00
parent 3a2453f0c8
commit 42aee25f0c
4 changed files with 72 additions and 4 deletions

View File

@ -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<Agent> {
public List<Agent> findAgentListByMemberId(Member member);
}

View File

@ -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<Agent> implements AgentDAO {
public List<Agent> 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<Agent> list = new ArrayList<>();
try {
list = query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return list;
}
}
}

View File

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

View File

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