commit 46a7351c379f3fbd5ae3f2561e6ccee97d7ad43f Author: snoop Date: Sun Jun 4 14:54:43 2017 +0900 first total dao commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ccc7c08 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.idea/ +*.iml +target/ \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ee1cd0f --- /dev/null +++ b/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + + com.loafle + maven_parent_jar + 1.0.0-RELEASE + + + com.loafle + overflow_jpa_dao + jar + 1.0.0-SNAPSHOT + com.loafle.overflow_jpa_dao + + + + + org.hibernate + hibernate-entitymanager + 5.2.10.Final + + + + com.loafle + overflow_member + 1.0.0-SNAPSHOT + + + + com.loafle + overflow_jpa_base_dao + 1.0.0-SNAPSHOT + + + + org.postgresql + postgresql + 9.4-1200-jdbc41 + + + + + + \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/agent/dao/AgentDAO.java b/src/main/java/com/loafle/overflow/agent/dao/AgentDAO.java new file mode 100644 index 0000000..7be627d --- /dev/null +++ b/src/main/java/com/loafle/overflow/agent/dao/AgentDAO.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.agent.dao; + +import com.loafle.overflow.agent.model.Agent; +import com.loafle.overflow.commons.dao.BaseDAO; + +/** + * Created by insanity on 17. 5. 29. + */ +public interface AgentDAO extends BaseDAO { +} diff --git a/src/main/java/com/loafle/overflow/agent/dao/JPAAgentDAO.java b/src/main/java/com/loafle/overflow/agent/dao/JPAAgentDAO.java new file mode 100644 index 0000000..6e6d882 --- /dev/null +++ b/src/main/java/com/loafle/overflow/agent/dao/JPAAgentDAO.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.agent.dao; + +import com.loafle.overflow.agent.model.Agent; +import com.loafle.overflow.commons.dao.JPABaseDAO; + + +/** + * Created by insanity on 17. 5. 29. + */ +public class JPAAgentDAO extends JPABaseDAO implements AgentDAO { +} diff --git a/src/main/java/com/loafle/overflow/agent/model/Agent.java b/src/main/java/com/loafle/overflow/agent/model/Agent.java new file mode 100644 index 0000000..0081efe --- /dev/null +++ b/src/main/java/com/loafle/overflow/agent/model/Agent.java @@ -0,0 +1,46 @@ +package com.loafle.overflow.agent.model; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * Created by insanity on 17. 5. 29. + */ + +@Entity(name="AGENT") +public class Agent implements Serializable { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="AUTHORIZED_DATE") + private Long authorizedDate; + + @Column(name="DESCRIPTION") + private String description; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getAuthorizedDate() { + return authorizedDate; + } + + public void setAuthorizedDate(Long authorizedDate) { + this.authorizedDate = authorizedDate; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/main/java/com/loafle/overflow/apikey/dao/ApiKeyDao.java b/src/main/java/com/loafle/overflow/apikey/dao/ApiKeyDao.java new file mode 100644 index 0000000..ad67497 --- /dev/null +++ b/src/main/java/com/loafle/overflow/apikey/dao/ApiKeyDao.java @@ -0,0 +1,12 @@ +package com.loafle.overflow.apikey.dao; + +import com.loafle.overflow.apikey.model.Apikey; +import com.loafle.overflow.commons.dao.BaseDAO; + + +/** + * Created by root on 17. 6. 1. + */ +public interface ApiKeyDao extends BaseDAO { + Apikey findByApiKey(Apikey apikey); +} diff --git a/src/main/java/com/loafle/overflow/apikey/dao/JPAApiKeyDao.java b/src/main/java/com/loafle/overflow/apikey/dao/JPAApiKeyDao.java new file mode 100644 index 0000000..6fdeb7a --- /dev/null +++ b/src/main/java/com/loafle/overflow/apikey/dao/JPAApiKeyDao.java @@ -0,0 +1,28 @@ +package com.loafle.overflow.apikey.dao; + +import com.loafle.overflow.apikey.model.Apikey; +import com.loafle.overflow.commons.dao.JPABaseDAO; + + +import javax.persistence.Query; + +/** + * Created by root on 17. 6. 1. + */ +public class JPAApiKeyDao extends JPABaseDAO implements ApiKeyDao { + public Apikey findByApiKey(Apikey apikey) { + + Query query = getEntityManager().createNativeQuery("SELECT ak.* FROM API_KEY ak WHERE ak.API_KEY = :apikey", Apikey.class); + query.setParameter("apikey", apikey.getApiKey()); + + Apikey ak = null; + try { + ak = (Apikey)query.getSingleResult(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return ak; + } + + } +} diff --git a/src/main/java/com/loafle/overflow/apikey/model/Apikey.java b/src/main/java/com/loafle/overflow/apikey/model/Apikey.java new file mode 100644 index 0000000..ef0a7db --- /dev/null +++ b/src/main/java/com/loafle/overflow/apikey/model/Apikey.java @@ -0,0 +1,61 @@ +package com.loafle.overflow.apikey.model; + +import com.loafle.overflow.member.model.Member; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 6. 1. + */ +@Entity +@Table(name ="API_KEY") +public class Apikey { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="API_KEY", unique=true, nullable=false) + private String apiKey; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CREATE_DATE", nullable=false) + private Date createDate; + + @ManyToOne + @JoinColumn(name = "MEMBER_ID", nullable=false) + private Member member; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + 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; + } +} diff --git a/src/main/java/com/loafle/overflow/member/dao/JPAMemberDAO.java b/src/main/java/com/loafle/overflow/member/dao/JPAMemberDAO.java new file mode 100644 index 0000000..9418773 --- /dev/null +++ b/src/main/java/com/loafle/overflow/member/dao/JPAMemberDAO.java @@ -0,0 +1,26 @@ +package com.loafle.overflow.member.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.member.model.Member; + +import javax.persistence.Query; + +/** + * Created by insanity on 17. 5. 25. + */ +public class JPAMemberDAO extends JPABaseDAO implements MemberDAO{ + public Member findByEmail(Member member) { + + Query query = getEntityManager().createNativeQuery("SELECT m.* FROM MEMBER m WHERE m.email = :email", Member.class); + query.setParameter("email", member.getEmail()); + + Member retMember = null; + try { + retMember = (Member)query.getSingleResult(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return retMember; + } + } +} diff --git a/src/main/java/com/loafle/overflow/member/dao/MemberDAO.java b/src/main/java/com/loafle/overflow/member/dao/MemberDAO.java new file mode 100644 index 0000000..5b910fe --- /dev/null +++ b/src/main/java/com/loafle/overflow/member/dao/MemberDAO.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.member.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.member.model.Member; + +/** + * Created by insanity on 17. 5. 25. + */ +public interface MemberDAO extends BaseDAO { + public Member findByEmail(Member member); +} diff --git a/src/main/java/com/loafle/overflow/member/model/Member.java b/src/main/java/com/loafle/overflow/member/model/Member.java new file mode 100644 index 0000000..f19a7bb --- /dev/null +++ b/src/main/java/com/loafle/overflow/member/model/Member.java @@ -0,0 +1,104 @@ +package com.loafle.overflow.member.model; + + +import javax.persistence.*; +import java.io.Serializable; + + +/** + * Created by insanity on 17. 5. 23. + */ + +@Entity +@Table(name="MEMBER") +public class Member implements Serializable { + @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 Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPwSalt() { + return pwSalt; + } + + public void setPwSalt(String pwSalt) { + this.pwSalt = pwSalt; + } + + public String getDigest() { + return digest; + } + + public void setDigest(String digest) { + this.digest = digest; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public Long getAuthorizedDate() { + return authorizedDate; + } + + public void setAuthorizedDate(Long authorizedDate) { + this.authorizedDate = authorizedDate; + } +} diff --git a/src/main/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAO.java b/src/main/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAO.java new file mode 100644 index 0000000..14f4dec --- /dev/null +++ b/src/main/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAO.java @@ -0,0 +1,42 @@ +package com.loafle.overflow.noauthagent.dao; + +import com.loafle.overflow.commons.dao.JPABaseDAO; +import com.loafle.overflow.noauthagent.model.NoAuthAgent; + +import javax.persistence.Query; +import java.util.List; + +/** + * Created by root on 17. 5. 30. + */ +public class JPANoAuthAgentDAO extends JPABaseDAO implements NoAuthAgentDao { + public NoAuthAgent findByTempKey(NoAuthAgent noAuthAgent) { + Query query = getEntityManager().createNativeQuery("SELECT na.* FROM NOAUTH_AGENT na WHERE na.TEMP_KEY = :tempkey", NoAuthAgent.class); + query.setParameter("tempkey", noAuthAgent.getTempKey()); + + NoAuthAgent authAgent = null; + try { + authAgent = (NoAuthAgent)query.getSingleResult(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return authAgent; + } + } + + public List findAllByNoAuth(NoAuthAgent noAuthAgent) { + + Query query = getEntityManager().createNativeQuery("SELECT na.* FROM NOAUTH_AGENT na WHERE na.AUTH_STATUS != :authStatus", NoAuthAgent.class); + query.setParameter("authStatus", noAuthAgent.getAuthStatus().toString()); + + List authAgentList = null; + try { + authAgentList = (List)query.getResultList(); + }catch(Exception e) { + e.printStackTrace(); + }finally { + return authAgentList; + } + + } +} diff --git a/src/main/java/com/loafle/overflow/noauthagent/dao/NoAuthAgentDao.java b/src/main/java/com/loafle/overflow/noauthagent/dao/NoAuthAgentDao.java new file mode 100644 index 0000000..d390ae9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/noauthagent/dao/NoAuthAgentDao.java @@ -0,0 +1,14 @@ +package com.loafle.overflow.noauthagent.dao; + +import com.loafle.overflow.commons.dao.BaseDAO; +import com.loafle.overflow.noauthagent.model.NoAuthAgent; + +import java.util.List; + +/** + * Created by root on 17. 5. 30. + */ +public interface NoAuthAgentDao extends BaseDAO { + NoAuthAgent findByTempKey(NoAuthAgent noAuthAgent); + List findAllByNoAuth(NoAuthAgent noAuthAgent); +} diff --git a/src/main/java/com/loafle/overflow/noauthagent/model/AuthType.java b/src/main/java/com/loafle/overflow/noauthagent/model/AuthType.java new file mode 100644 index 0000000..8a519c1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/noauthagent/model/AuthType.java @@ -0,0 +1,18 @@ +package com.loafle.overflow.noauthagent.model; + +/** + * Created by root on 17. 5. 31. + */ +public enum AuthType { + ACCEPT("ACT"), + REFUSE("RFE"), + WAIT("WIT"); + + private String stringValue; + AuthType(String string) {stringValue = string;} + + @Override + public String toString() { + return stringValue; + } +} diff --git a/src/main/java/com/loafle/overflow/noauthagent/model/NoAuthAgent.java b/src/main/java/com/loafle/overflow/noauthagent/model/NoAuthAgent.java new file mode 100644 index 0000000..c81c304 --- /dev/null +++ b/src/main/java/com/loafle/overflow/noauthagent/model/NoAuthAgent.java @@ -0,0 +1,93 @@ +package com.loafle.overflow.noauthagent.model; + +import javax.persistence.*; +import java.util.Date; + +/** + * Created by root on 17. 5. 30. + */ +@Entity +@Table(name = "NOAUTH_AGENT") +public class NoAuthAgent { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + @Column(name="TEMP_KEY", unique=true, nullable=false) + private String tempKey; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="DATE", nullable=false) + private Date date; + + @Column(name="API_KEY", nullable=false) + private String apiKey; + + @Column(name="AUTH_STATUS", nullable=false) + @Enumerated(EnumType.STRING) + private AuthType authStatus; + + @Column(name="LOCAL_IP", nullable=false) + private long localIP; + + @Column(name="HOST_NAME") + private String hostName; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTempKey() { + return tempKey; + } + + public void setTempKey(String tempKey) { + this.tempKey = tempKey; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + public AuthType getAuthStatus() { + return authStatus; + } + + public void setAuthStatus(AuthType authStatus) { + this.authStatus = authStatus; + } + + public long getLocalIP() { + return localIP; + } + + public void setLocalIP(long localIP) { + this.localIP = localIP; + } + + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } +} diff --git a/src/main/resources/_ b/src/main/resources/_ new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java b/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java new file mode 100644 index 0000000..d92c058 --- /dev/null +++ b/src/test/java/com/loafle/overflow/agent/dao/JPAAgentDAOTest.java @@ -0,0 +1,28 @@ +package com.loafle.overflow.agent.dao; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAAgentDAOTest { + + private JPAAgentDAO jpaAgentDAO = null; + + @Before + public void before() { + this.jpaAgentDAO = new JPAAgentDAO(); + } + + + @Test + public void createAgent() { + + + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/apikey/dao/JPAApiKeyDaoTest.java b/src/test/java/com/loafle/overflow/apikey/dao/JPAApiKeyDaoTest.java new file mode 100644 index 0000000..095d24a --- /dev/null +++ b/src/test/java/com/loafle/overflow/apikey/dao/JPAApiKeyDaoTest.java @@ -0,0 +1,52 @@ +package com.loafle.overflow.apikey.dao; + +import com.loafle.overflow.apikey.model.Apikey; +import com.loafle.overflow.member.model.Member; +import org.junit.Before; +import org.junit.Test; + +import java.util.Date; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAApiKeyDaoTest { + + private JPAApiKeyDao jpaApiKeyDao; + + @Before + public void Before() { + this.jpaApiKeyDao = new JPAApiKeyDao(); + } + + + @Test + public void findByApiKey() throws Exception { + + Apikey apikey = new Apikey(); + + apikey.setApiKey("1111111"); + + Apikey a = this.jpaApiKeyDao.findByApiKey(apikey); + + System.out.println(a.getId()); + + } + + @Test + public void createApiKey() { + Apikey apikey = new Apikey(); + + apikey.setApiKey("1111111"); + apikey.setCreateDate(new Date()); + Member member = new Member(); + member.setId((long)2); + apikey.setMember(member); + + + jpaApiKeyDao.create(apikey); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/member/dao/JPAMemberDAOTest.java b/src/test/java/com/loafle/overflow/member/dao/JPAMemberDAOTest.java new file mode 100644 index 0000000..755c700 --- /dev/null +++ b/src/test/java/com/loafle/overflow/member/dao/JPAMemberDAOTest.java @@ -0,0 +1,40 @@ +package com.loafle.overflow.member.dao; + +import com.loafle.overflow.member.model.Member; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 4. + */ +public class JPAMemberDAOTest { + + private JPAMemberDAO jpaMemberDAO = null; + + @Before + public void before() { + + this.jpaMemberDAO = new JPAMemberDAO(); + } + + @Test + public void findByEmail() throws Exception { + } + + @Test + public void createMember() { + Member m = new Member(); + + m.setName("insanity3"); + m.setCompany("loafle"); + m.setDigest("bbbbbbbbb"); + m.setPwSalt("salktttt"); + m.setPhone("000-000-0000"); + m.setEmail("insanity33@loafle.com"); + + this.jpaMemberDAO.create(m); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAOTest.java b/src/test/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAOTest.java new file mode 100644 index 0000000..584e221 --- /dev/null +++ b/src/test/java/com/loafle/overflow/noauthagent/dao/JPANoAuthAgentDAOTest.java @@ -0,0 +1,28 @@ +package com.loafle.overflow.noauthagent.dao; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by root on 17. 6. 4. + */ +public class JPANoAuthAgentDAOTest { + + private JPANoAuthAgentDAO jpaNoAuthAgentDAO = null; + + @Before + public void Before() { + this.jpaNoAuthAgentDAO = new JPANoAuthAgentDAO(); + } + + @Test + public void findByTempKey() throws Exception { + } + + @Test + public void findAllByNoAuth() throws Exception { + } + +} \ No newline at end of file diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml new file mode 100644 index 0000000..a27b373 --- /dev/null +++ b/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,21 @@ + + + + + com.loafle.overflow.member.com.loafle.overflow.member.model.Member + com.loafle.overflow.member.com.loafle.overflow.noauthagent.model.NoAuthAgent + com.loafle.overflow.member.com.loafle.overflow.apikey.model.Apikey + com.loafle.overflow.member.com.loafle.overflow.agent.model.Agent + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml new file mode 100644 index 0000000..a0d75a2 --- /dev/null +++ b/src/test/resources/logback.xml @@ -0,0 +1,17 @@ + + + overflow_jpa_dao + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n + + + + + + + + + \ No newline at end of file