add target

This commit is contained in:
snoop 2017-06-22 12:49:29 +09:00
parent 4008097387
commit 19beb1b529
5 changed files with 214 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package com.loafle.overflow.dao.target.dao;
import com.loafle.overflow.commons.dao.JPABaseDAO;
import com.loafle.overflow.dao.target.model.Target;
import javax.persistence.Query;
import java.util.List;
/**
* Created by root on 17. 6. 5.
*/
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

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

View File

@ -0,0 +1,130 @@
package com.loafle.overflow.dao.target.model;
import com.loafle.overflow.dao.member.model.Member;
import com.loafle.overflow.dao.target.type.PortType;
import com.loafle.overflow.dao.target.type.TargetType;
import javax.persistence.*;
import java.util.Date;
/**
* Created by root on 17. 6. 5.
*/
@Entity
public class Target {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
@Column(name="IP", nullable=false)
private long ip;
@Column(name="PORT")
private int port;
@Column(name="TARGET_TYPE")
@Enumerated(EnumType.STRING)
private TargetType targetType;
@Column(name="VENDOR_NAME")
private String vendorName;
@Column(name="KINDS")
private String kinds;
@Column(name="VERSION")
private String version;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="CREATE_DATE", nullable=false , columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false)
private Date createDate;
@Column(name="PORT_TYPE")
@Enumerated(EnumType.STRING)
private PortType portType;
@ManyToOne
@JoinColumn(name = "MEMBER_ID", nullable=false)
private Member member;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public long getIp() {
return ip;
}
public void setIp(long ip) {
this.ip = ip;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public TargetType getTargetType() {
return targetType;
}
public void setTargetType(TargetType targetType) {
this.targetType = targetType;
}
public String getVendorName() {
return vendorName;
}
public void setVendorName(String vendorName) {
this.vendorName = vendorName;
}
public String getKinds() {
return kinds;
}
public void setKinds(String kinds) {
this.kinds = kinds;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Member getMember() {
return member;
}
public void setMember(Member member) {
this.member = member;
}
public PortType getPortType() {
return portType;
}
public void setPortType(PortType portType) {
this.portType = portType;
}
}

View File

@ -0,0 +1,19 @@
package com.loafle.overflow.dao.target.type;
/**
* Created by root on 17. 6. 7.
*/
public enum PortType {
TCP("TCP"),
UDP("UDP");
private String stringValue;
PortType(String string) {stringValue = string;}
@Override
public String toString() {
return stringValue;
}
}

View File

@ -0,0 +1,21 @@
package com.loafle.overflow.dao.target.type;
/**
* Created by root on 17. 6. 5.
*/
public enum TargetType {
MACHINE("MACHINE"),
DATABASE("DATABASE"),
WAS("WAS"),
OTHER("OTHER");
private String stringValue;
TargetType(String string) {stringValue = string;}
@Override
public String toString() {
return stringValue;
}
}