From 95d3cacd41f6410348fa644603456dded751b38f Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 22 Jun 2017 19:09:10 +0900 Subject: [PATCH] model --- .../com/loafle/overflow/models/TblMember.java | 146 ------------------ .../overflow/module/apikey/model/Apikey.java | 2 - .../module/email/model/EmailAuth.java | 2 - .../overflow/module/member/dao/MemberDAO.java | 1 - .../overflow/module/member/model/Member.java | 122 ++++++++------- .../module/target/dao/JPATargetDao.java | 29 ---- .../overflow/module/target/dao/TargetDAO.java | 12 ++ .../overflow/module/target/dao/TargetDao.java | 13 -- .../com/loafle/overflow/proxy/db/DBProxy.java | 11 +- src/test/java/com/loafle/TestClient.java | 1 - .../overflow/agent/dao/JPAAgentDAOTest.java | 12 +- .../module/member/dao/MemberDAOTest.java | 3 - .../overflow/target/dao/JPATargetDaoTest.java | 36 +++++ 13 files changed, 123 insertions(+), 267 deletions(-) delete mode 100644 src/main/java/com/loafle/overflow/models/TblMember.java delete mode 100644 src/main/java/com/loafle/overflow/module/target/dao/JPATargetDao.java create mode 100644 src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java delete mode 100644 src/main/java/com/loafle/overflow/module/target/dao/TargetDao.java create mode 100644 src/test/java/com/loafle/overflow/target/dao/JPATargetDaoTest.java diff --git a/src/main/java/com/loafle/overflow/models/TblMember.java b/src/main/java/com/loafle/overflow/models/TblMember.java deleted file mode 100644 index 81e6fa8..0000000 --- a/src/main/java/com/loafle/overflow/models/TblMember.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.loafle.overflow.models; - -import javax.persistence.*; -import java.sql.Timestamp; - -/** - * Created by root on 17. 6. 22. - */ -@Entity -@Table(name = "TBL_MEMBER", schema = "public", catalog = "postgres") -public class TblMember { - private long id; - private String email; - private String pw; - private String pwSalt; - private String name; - private String phone; - private String companyName; - private Timestamp createDate; - private short statusId; - - @Id - @Column(name = "ID", nullable = false) - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @Basic - @Column(name = "EMAIL", nullable = false, length = 50) - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - @Basic - @Column(name = "PW", nullable = true, length = 32) - public String getPw() { - return pw; - } - - public void setPw(String pw) { - this.pw = pw; - } - - @Basic - @Column(name = "PW_SALT", nullable = true, length = 32) - public String getPwSalt() { - return pwSalt; - } - - public void setPwSalt(String pwSalt) { - this.pwSalt = pwSalt; - } - - @Basic - @Column(name = "NAME", nullable = true, length = 50) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Basic - @Column(name = "PHONE", nullable = true, length = 50) - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - @Basic - @Column(name = "COMPANY_NAME", nullable = true, length = 50) - public String getCompanyName() { - return companyName; - } - - public void setCompanyName(String companyName) { - this.companyName = companyName; - } - - @Basic - @Column(name = "CREATE_DATE", nullable = true) - public Timestamp getCreateDate() { - return createDate; - } - - public void setCreateDate(Timestamp createDate) { - this.createDate = createDate; - } - - @Basic - @Column(name = "STATUS_ID", nullable = false) - public short getStatusId() { - return statusId; - } - - public void setStatusId(short statusId) { - this.statusId = statusId; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - TblMember tblMember = (TblMember) o; - - if (id != tblMember.id) return false; - if (statusId != tblMember.statusId) return false; - if (email != null ? !email.equals(tblMember.email) : tblMember.email != null) return false; - if (pw != null ? !pw.equals(tblMember.pw) : tblMember.pw != null) return false; - if (pwSalt != null ? !pwSalt.equals(tblMember.pwSalt) : tblMember.pwSalt != null) return false; - if (name != null ? !name.equals(tblMember.name) : tblMember.name != null) return false; - if (phone != null ? !phone.equals(tblMember.phone) : tblMember.phone != null) return false; - if (companyName != null ? !companyName.equals(tblMember.companyName) : tblMember.companyName != null) - return false; - if (createDate != null ? !createDate.equals(tblMember.createDate) : tblMember.createDate != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = (int) (id ^ (id >>> 32)); - result = 31 * result + (email != null ? email.hashCode() : 0); - result = 31 * result + (pw != null ? pw.hashCode() : 0); - result = 31 * result + (pwSalt != null ? pwSalt.hashCode() : 0); - result = 31 * result + (name != null ? name.hashCode() : 0); - result = 31 * result + (phone != null ? phone.hashCode() : 0); - result = 31 * result + (companyName != null ? companyName.hashCode() : 0); - result = 31 * result + (createDate != null ? createDate.hashCode() : 0); - result = 31 * result + (int) statusId; - return result; - } -} diff --git a/src/main/java/com/loafle/overflow/module/apikey/model/Apikey.java b/src/main/java/com/loafle/overflow/module/apikey/model/Apikey.java index 19507b1..0060ed6 100644 --- a/src/main/java/com/loafle/overflow/module/apikey/model/Apikey.java +++ b/src/main/java/com/loafle/overflow/module/apikey/model/Apikey.java @@ -1,7 +1,5 @@ package com.loafle.overflow.module.apikey.model; -import com.loafle.overflow.module.member.model.Member; - import javax.persistence.*; import java.util.Date; diff --git a/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java b/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java index e4eaa39..2c92d51 100644 --- a/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java +++ b/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java @@ -1,7 +1,5 @@ package com.loafle.overflow.module.email.model; -import com.loafle.overflow.module.member.model.Member; - import javax.persistence.*; import java.io.Serializable; import java.util.Date; diff --git a/src/main/java/com/loafle/overflow/module/member/dao/MemberDAO.java b/src/main/java/com/loafle/overflow/module/member/dao/MemberDAO.java index 45f6c76..7269864 100644 --- a/src/main/java/com/loafle/overflow/module/member/dao/MemberDAO.java +++ b/src/main/java/com/loafle/overflow/module/member/dao/MemberDAO.java @@ -1,6 +1,5 @@ package com.loafle.overflow.module.member.dao; -import com.loafle.overflow.module.member.model.Member; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/com/loafle/overflow/module/member/model/Member.java b/src/main/java/com/loafle/overflow/module/member/model/Member.java index 435df24..8e646ab 100644 --- a/src/main/java/com/loafle/overflow/module/member/model/Member.java +++ b/src/main/java/com/loafle/overflow/module/member/model/Member.java @@ -1,58 +1,38 @@ package com.loafle.overflow.module.member.model; +import com.loafle.overflow.meta.MetaMemberStatus; import javax.persistence.*; -import java.io.Serializable; - +import java.sql.Timestamp; /** - * Created by insanity on 17. 5. 23. + * Created by root on 17. 6. 22. */ - @Entity -@Table(name="MEMBER") -public class Member implements Serializable { +@Table(name = "TBL_MEMBER", schema = "public", catalog = "postgres") +public class Member { + private long id; + private String email; + private String pw; + private String pwSalt; + private String name; + private String phone; + private String companyName; + private Timestamp createDate; + private MetaMemberStatus status; + @Id @GeneratedValue(strategy= GenerationType.IDENTITY) - private Long id; - - @Column(name="EMAIL", unique=true, nullable=false) - private String email; - - @Column(name="PW_SALT", nullable=false) - private String pwSalt; - - @Column(name="DIGEST", nullable=false) - private String digest; - - @Column(name="NAME", nullable=false) - private String name; - - @Column(name="COMPANY", nullable=false) - private String company; - - @Column(name="PHONE") - private String phone; - - @Column(name="AUTHORIZED_DATE") - private Long authorizedDate; - - - public Member() { - - } - - public Member(Long id) { - this.id = id; - } - public Long getId() { + public long getId() { return id; } - public void setId(Long id) { + public void setId(long id) { this.id = id; } + @Basic + @Column(name = "EMAIL", nullable = false, length = 50) public String getEmail() { return email; } @@ -61,6 +41,18 @@ public class Member implements Serializable { this.email = email; } + @Basic + @Column(name = "PW", nullable = true, length = 32) + public String getPw() { + return pw; + } + + public void setPw(String pw) { + this.pw = pw; + } + + @Basic + @Column(name = "PW_SALT", nullable = true, length = 32) public String getPwSalt() { return pwSalt; } @@ -69,14 +61,8 @@ public class Member implements Serializable { this.pwSalt = pwSalt; } - public String getDigest() { - return digest; - } - - public void setDigest(String digest) { - this.digest = digest; - } - + @Basic + @Column(name = "NAME", nullable = true, length = 50) public String getName() { return name; } @@ -85,14 +71,8 @@ public class Member implements Serializable { this.name = name; } - public String getCompany() { - return company; - } - - public void setCompany(String company) { - this.company = company; - } - + @Basic + @Column(name = "PHONE", nullable = true, length = 50) public String getPhone() { return phone; } @@ -101,11 +81,35 @@ public class Member implements Serializable { this.phone = phone; } - public Long getAuthorizedDate() { - return authorizedDate; + @Basic + @Column(name = "COMPANY_NAME", nullable = true, length = 50) + public String getCompanyName() { + return companyName; } - public void setAuthorizedDate(Long authorizedDate) { - this.authorizedDate = authorizedDate; + public void setCompanyName(String companyName) { + this.companyName = companyName; } + + @Basic + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) + public Timestamp getCreateDate() { + return createDate; + } + + public void setCreateDate(Timestamp createDate) { + this.createDate = createDate; + } + + @ManyToMany + @JoinColumn(name = "STATUS_ID", nullable = false) + public MetaMemberStatus getStatus() { + return status; + } + + public void setStatus(MetaMemberStatus status) { + this.status = status; + } + + } diff --git a/src/main/java/com/loafle/overflow/module/target/dao/JPATargetDao.java b/src/main/java/com/loafle/overflow/module/target/dao/JPATargetDao.java deleted file mode 100644 index 8168058..0000000 --- a/src/main/java/com/loafle/overflow/module/target/dao/JPATargetDao.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.loafle.overflow.module.target.dao; - -import com.loafle.overflow.commons.dao.JPABaseDAO; - -import javax.persistence.Query; -import java.util.List; - -/** - * Created by root on 17. 6. 5. - */ -public class JPATargetDao extends JPABaseDAO implements TargetDao { - - public List 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 targets = null; - try { - targets = (List)query.getResultList(); - }catch(Exception e) { - e.printStackTrace(); - }finally { - return targets; - } - - - } -} diff --git a/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java b/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java new file mode 100644 index 0000000..d10563f --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/target/dao/TargetDAO.java @@ -0,0 +1,12 @@ +package com.loafle.overflow.module.target.dao; + +import com.loafle.overflow.module.target.model.Target; +import org.springframework.data.jpa.repository.JpaRepository; + + +/** + * Created by root on 17. 6. 5. + */ +public interface TargetDAO extends JpaRepository { + +} diff --git a/src/main/java/com/loafle/overflow/module/target/dao/TargetDao.java b/src/main/java/com/loafle/overflow/module/target/dao/TargetDao.java deleted file mode 100644 index 43ec2ea..0000000 --- a/src/main/java/com/loafle/overflow/module/target/dao/TargetDao.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.loafle.overflow.module.target.dao; - -import com.loafle.overflow.commons.dao.BaseDAO; - -import java.util.List; - -/** - * Created by root on 17. 6. 5. - */ -public interface TargetDao extends BaseDAO { - - List findAll(Target target); -} diff --git a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java index b917a7d..a261979 100644 --- a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java +++ b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java @@ -3,7 +3,7 @@ package com.loafle.overflow.proxy.db; import com.loafle.overflow.db.api.DBGrpc; import com.loafle.overflow.db.api.DBInput; import com.loafle.overflow.db.api.DBOutput; -import com.loafle.overflow.module.agent.dao.AgentDAO; +import com.loafle.overflow.module.probe.dao.AgentDAO; import com.loafle.overflow.module.apikey.dao.ApiKeyDao; import com.loafle.overflow.module.crawler.dao.CrawlerDAO; import com.loafle.overflow.module.crawler.dao.CrawlerInputItemDAO; @@ -13,6 +13,7 @@ import com.loafle.overflow.module.member.dao.MemberDAO; import com.loafle.overflow.module.noauthagent.dao.NoAuthAgentDao; import com.loafle.overflow.module.sensor.dao.SensorDao; import com.loafle.overflow.module.sensor.dao.SensorItemDao; +import com.loafle.overflow.module.target.dao.TargetDAO; import io.grpc.ServerBuilder; import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; @@ -53,8 +54,8 @@ public class DBProxy { @Autowired private EmailAuthDAO emailAuthDAO; -// @Autowired -// private TargetDao targetDao; + @Autowired + private TargetDAO targetDAO; @Autowired private CrawlerDAO crawlerDAO; @@ -81,11 +82,11 @@ public class DBProxy { daoMap = new ConcurrentHashMap(); daoMap.put("member", memberDAO); - daoMap.put("agent", agentDAO); + daoMap.put("probe", agentDAO); daoMap.put("noauthAgent", noAuthAgentDAO); daoMap.put("apiKey", apiKeyDao); daoMap.put("emailAuth", emailAuthDAO); -// daoMap.put("target", targetDao); +// daoMap.put("target", targetDAO); daoMap.put("crawler", crawlerDAO); daoMap.put("crawlerInputItem", crawlerInputItemDAO); daoMap.put("crawlerInputItemMapping", crawlerInputItemMappingDAO); diff --git a/src/test/java/com/loafle/TestClient.java b/src/test/java/com/loafle/TestClient.java index 232e5fb..f248e19 100644 --- a/src/test/java/com/loafle/TestClient.java +++ b/src/test/java/com/loafle/TestClient.java @@ -4,7 +4,6 @@ package com.loafle; import com.loafle.overflow.db.api.DBGrpc; import com.loafle.overflow.db.api.DBInput; import com.loafle.overflow.db.api.DBOutput; -import com.loafle.overflow.module.member.model.Member; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.StatusRuntimeException; 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 f2604fa..701644c 100644 --- a/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java +++ b/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java @@ -1,7 +1,7 @@ //package com.loafle.overflow.agent.dao; // -//import com.loafle.overflow.module.agent.dao.JPAAgentDAO; -//import com.loafle.overflow.module.agent.model.Agent; +//import com.loafle.overflow.module.probe.dao.JPAAgentDAO; +//import com.loafle.overflow.module.probe.model.Agent; //import com.loafle.overflow.module.member.model.Member; //import org.junit.Before; //import org.junit.Ignore; @@ -25,10 +25,10 @@ // 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); +// Agent probe = new Agent(); +// probe.setDescription("test probe"); +// probe.setMember(m); +// Agent savedAgent = jpaAgentDAO.create(probe); // // System.out.println(savedAgent.getDescription()); // } diff --git a/src/test/java/com/loafle/overflow/module/member/dao/MemberDAOTest.java b/src/test/java/com/loafle/overflow/module/member/dao/MemberDAOTest.java index 4bfe07b..d481054 100644 --- a/src/test/java/com/loafle/overflow/module/member/dao/MemberDAOTest.java +++ b/src/test/java/com/loafle/overflow/module/member/dao/MemberDAOTest.java @@ -2,15 +2,12 @@ package com.loafle.overflow.module.member.dao; import com.loafle.overflow.AppConfig; import com.loafle.overflow.JdbcConfiguration; -import com.loafle.overflow.module.member.model.Member; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.*; - /** * Created by root on 17. 6. 22. */ diff --git a/src/test/java/com/loafle/overflow/target/dao/JPATargetDaoTest.java b/src/test/java/com/loafle/overflow/target/dao/JPATargetDaoTest.java new file mode 100644 index 0000000..dac6b3d --- /dev/null +++ b/src/test/java/com/loafle/overflow/target/dao/JPATargetDaoTest.java @@ -0,0 +1,36 @@ +package com.loafle.overflow.target.dao; + +import com.loafle.overflow.module.infra.Infra; +import com.loafle.overflow.module.target.dao.TargetDAO; +import com.loafle.overflow.module.target.model.Target; +import com.loafle.overflow.module.probe.model.Probe; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.sql.Timestamp; +import java.util.Date; + +public class JPATargetDaoTest { + + @Autowired + private TargetDAO repo; + + + @Test + public void create() { + Target t = new Target(); + t.setCreateDate(new Timestamp(new Date().getTime())); + + Infra i = new Infra(); + i.setId(1); + t.setInfra(i); + + Probe p = new Probe(); + p.setId(1); + + Target ret = repo.save(t); + + } + + +} \ No newline at end of file