Target
This commit is contained in:
snoop 2017-06-05 12:19:27 +09:00
parent 3015734837
commit 3a2453f0c8
4 changed files with 104 additions and 3 deletions

View File

@ -3,8 +3,28 @@ package com.loafle.overflow.target.dao;
import com.loafle.overflow.commons.dao.JPABaseDAO; import com.loafle.overflow.commons.dao.JPABaseDAO;
import com.loafle.overflow.target.model.Target; import com.loafle.overflow.target.model.Target;
import javax.persistence.Query;
import java.util.List;
/** /**
* Created by root on 17. 6. 5. * Created by root on 17. 6. 5.
*/ */
public class JPATargetDao extends JPABaseDAO<Target> implements TargetDao { public class JPATargetDao extends JPABaseDAO<Target> implements TargetDao {
public List<Target> findAll(Target target) {
Query query = getEntityManager().createNativeQuery("SELECT tg.* FROM Target tg WHERE tg.MEMBER_ID = :memberId", Target.class);
query.setParameter("memberId", target.getMember().getId());
List<Target> targets = null;
try {
targets = (List<Target>)query.getResultList();
}catch(Exception e) {
e.printStackTrace();
}finally {
return targets;
}
}
} }

View File

@ -3,8 +3,12 @@ package com.loafle.overflow.target.dao;
import com.loafle.overflow.commons.dao.BaseDAO; import com.loafle.overflow.commons.dao.BaseDAO;
import com.loafle.overflow.target.model.Target; import com.loafle.overflow.target.model.Target;
import java.util.List;
/** /**
* Created by root on 17. 6. 5. * Created by root on 17. 6. 5.
*/ */
public interface TargetDao extends BaseDAO<Target> { public interface TargetDao extends BaseDAO<Target> {
List<Target> findAll(Target target);
} }

View File

@ -1,5 +1,6 @@
package com.loafle.overflow.target.model; package com.loafle.overflow.target.model;
import com.loafle.overflow.member.model.Member;
import com.loafle.overflow.target.type.TargetType; import com.loafle.overflow.target.type.TargetType;
import javax.persistence.*; import javax.persistence.*;
@ -19,7 +20,7 @@ public class Target {
private long ip; private long ip;
@Column(name="PORT", nullable=false) @Column(name="PORT", nullable=false)
private long port; private int port;
@Column(name="TARGET_TYPE", nullable=false) @Column(name="TARGET_TYPE", nullable=false)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@ -38,6 +39,9 @@ public class Target {
@Column(name="CREATE_DATE", nullable=false , columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false) @Column(name="CREATE_DATE", nullable=false , columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false)
private Date createDate; private Date createDate;
@ManyToOne
@JoinColumn(name = "MEMBER_ID", nullable=false)
private Member member;
public Long getId() { public Long getId() {
return id; return id;
@ -55,11 +59,11 @@ public class Target {
this.ip = ip; this.ip = ip;
} }
public long getPort() { public int getPort() {
return port; return port;
} }
public void setPort(long port) { public void setPort(int port) {
this.port = port; this.port = port;
} }
@ -102,4 +106,12 @@ public class Target {
public void setCreateDate(Date createDate) { public void setCreateDate(Date createDate) {
this.createDate = createDate; this.createDate = createDate;
} }
public Member getMember() {
return member;
}
public void setMember(Member member) {
this.member = member;
}
} }

View File

@ -0,0 +1,65 @@
package com.loafle.overflow.target.dao;
import com.loafle.overflow.member.model.Member;
import com.loafle.overflow.target.model.Target;
import com.loafle.overflow.target.type.TargetType;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.*;
/**
* Created by root on 17. 6. 5.
*/
public class JPATargetDaoTest {
private JPATargetDao jpaTargetDao = null;
@Before
public void before() {
this.jpaTargetDao = new JPATargetDao();
}
@Test
public void testCreate() {
Target target = new Target();
target.setIp(3232235882L);
target.setPort(5432);
target.setTargetType(TargetType.DATABASE);
target.setKinds("PostgreSQL");
target.setVersion("9.5.0");
target.setVendorName("PostgreSQL 9.5.0");
Member member = new Member();
member.setId(1L);
target.setMember(member);
this.jpaTargetDao.create(target);
}
@Test
public void list() {
Target target = new Target();
Member member = new Member();
member.setId(1L);
target.setMember(member);
List<Target> targets = this.jpaTargetDao.findAll(target);
System.out.println(targets.size());
}
}