diff --git a/src/main/java/com/example/cosmos_serversb/entities/Group.java b/src/main/java/com/example/cosmos_serversb/entities/Group.java index 524fa87..8d0bdfb 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/Group.java +++ b/src/main/java/com/example/cosmos_serversb/entities/Group.java @@ -3,45 +3,34 @@ import java.util.ArrayList; -import static com.example.cosmos_serversb.models.Users.*; - public class Group { - private Long id; - private String gId, uri, name; + private Long gId; + private String uri, name; private ArrayList members; private ArrayList requests; - private Group(){ + public Group(){ } public Group(String gId, String uri, String name, String uId){ - this.gId = gId; - //setGid(gId); - setUri(uri); - setName(name); - this.members.add(getUserById(uId)); - this.requests = null; + this.gId = Long.parseLong(gId); + this.uri = uri; + this.name = name; } - //hibernate用 - public Long getId() { - return id; - } - - private void setId(Long id) { - this.id = id; - } - - - private void setGid(String gId){ - this.gId = gId; - } - - public String getGid(){ + public Long getgId() { return gId; } + private void setgId(Long gId) { + this.gId = gId; + } + + public String getUri() { + return uri; + } + private void setUri(String uri){ this.uri = uri; } @@ -54,6 +43,10 @@ this.name = name; } + public String getName(){ + return name; + } + public String getNameByGid(String gId){ return name; } diff --git a/src/main/java/com/example/cosmos_serversb/entities/Request.java b/src/main/java/com/example/cosmos_serversb/entities/Request.java index 40246a2..786f167 100644 --- a/src/main/java/com/example/cosmos_serversb/entities/Request.java +++ b/src/main/java/com/example/cosmos_serversb/entities/Request.java @@ -2,33 +2,35 @@ package com.example.cosmos_serversb.entities; public class Request { - private String rId, uri, date, IssuerUid, product, deadline; + private Long rId; + private String uri, date, IssuerUid, product, deadline; private int location;// YahooローカルサーチAPIの業種コード private boolean done = false; - private Request(){ + public Request(){ } public Request(String rId, String uri, String date, String IssuerUid, String product, String deadline, int location){ - setRid(rId); + //setrId(rId); + this.rId = Long.parseLong(rId); setUri(uri); setDate(date); setIssuerUid(IssuerUid); setProduct(product); setDeadline(deadline); setLocation(location); - this.done = false; + //this.done = false; } - private void setRid(String rId){ - this.rId = rId; - } - - public String getRid(){ + public Long getrId() { return rId; } + private void setrId(Long gId) { + this.rId = rId; + } + private void setUri(String uri){ this.uri = uri; } diff --git a/src/main/java/com/example/cosmos_serversb/models/Groups.java b/src/main/java/com/example/cosmos_serversb/models/Groups.java index 9986a26..4912efd 100644 --- a/src/main/java/com/example/cosmos_serversb/models/Groups.java +++ b/src/main/java/com/example/cosmos_serversb/models/Groups.java @@ -2,13 +2,13 @@ import java.util.*; import javax.inject.Singleton; -import javax.persistence.Column; + import com.example.cosmos_serversb.entities.*; @Singleton public class Groups { - private static Groups thaInstance = null; + private static Groups theInstance = null; private static ArrayList groups = new ArrayList<>(); private Groups(){ @@ -16,10 +16,10 @@ } public static Groups getInstance(){ - if(thaInstance == null){ - thaInstance = new Groups(); + if(theInstance == null){ + theInstance = new Groups(); } - return thaInstance; + return theInstance; } public static HashMap getGroupsListByUid(String uId){ @@ -37,7 +37,7 @@ Group editGroup; for (int i = 0; i < groups.size(); i++) { editGroup = groups.get(i); - if (editGroup.getGid().equals(gId)) { + if (editGroup.getgId().equals(gId)) { return editGroup; } } diff --git a/src/main/resources/Group.hbm.xml b/src/main/resources/Group.hbm.xml new file mode 100644 index 0000000..8e0333c --- /dev/null +++ b/src/main/resources/Group.hbm.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/src/main/resources/Request.hbm.xml b/src/main/resources/Request.hbm.xml new file mode 100644 index 0000000..4adea89 --- /dev/null +++ b/src/main/resources/Request.hbm.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml new file mode 100644 index 0000000..e6d6025 --- /dev/null +++ b/src/main/resources/hibernate.cfg.xml @@ -0,0 +1,42 @@ + + + + + + + + + + org.h2.Driver + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE + sa + + + + 1 + + + org.hibernate.dialect.H2Dialect + + + org.hibernate.cache.internal.NoCacheProvider + + + true + + + create + + + + + + + \ No newline at end of file diff --git a/src/test/java/hibernateTest/entities/Event.java b/src/test/java/hibernateTest/entities/Event.java index 2a6df8a..e2dd0cc 100644 --- a/src/test/java/hibernateTest/entities/Event.java +++ b/src/test/java/hibernateTest/entities/Event.java @@ -26,7 +26,7 @@ import java.util.Date; public class Event { - private Long id; + private Long id;//Longじゃないと,デフォルトでは動かなさそう。 private String title; private Date date; diff --git a/src/test/java/hibernateTest/entities/Group.java b/src/test/java/hibernateTest/entities/Group.java new file mode 100644 index 0000000..e1c4111 --- /dev/null +++ b/src/test/java/hibernateTest/entities/Group.java @@ -0,0 +1,72 @@ +//このクラスは仮です +package hibernateTest.entities; + +import java.util.ArrayList; + +public class Group { + private Long gId; + private String uri, name; + //private ArrayList members; + private ArrayList requests; + + public Group(){ + + } + + public Group(String gId, String uri, String name, String uId){ + this.gId = Long.parseLong(gId); + this.uri = uri; + this.name = name; + } + + public Long getgId() { + return gId; + } + + private void setgId(Long gId) { + this.gId = gId; + } + + public String getUri() { + return uri; + } + + private void setUri(String uri){ + this.uri = uri; + } + + public String getUriByGid(String gId){ + return uri; + } + + private void setName(String name){ + this.name = name; + } + + public String getName(){ + return name; + } + + public String getNameByGid(String gId){ + return name; + } + + /*メンバー*/ + //public ArrayList getMembersList(){ + // return null; + //} + + //public void addMemberByUid(String uId){ + // + // members.add(user); + //} + + //public DeleteResult deleteMember(String uid){ + // members.remove(members.indexOf(uid)); + // return null; + //} + + /*リクエスト*/ + +} + diff --git a/src/test/java/hibernateTest/entities/Request.java b/src/test/java/hibernateTest/entities/Request.java new file mode 100644 index 0000000..27b16a8 --- /dev/null +++ b/src/test/java/hibernateTest/entities/Request.java @@ -0,0 +1,95 @@ +//このクラスは仮です +package hibernateTest.entities; + +public class Request { + private Long rId; + private String uri, date, IssuerUid, product, deadline; + private int location;// YahooローカルサーチAPIの業種コード + private boolean done = false; + + public Request(){ + + } + + public Request(String rId, String uri, String date, String IssuerUid, String product, String deadline, int location){ + //setrId(rId); + this.rId = Long.parseLong(rId); + setUri(uri); + setDate(date); + setIssuerUid(IssuerUid); + setProduct(product); + setDeadline(deadline); + setLocation(location); + this.done = false; + } + + + private void setrId(Long rId){ + this.rId = rId; + } + + public Long getrId(){ + return rId; + } + + private void setUri(String uri){ + this.uri = uri; + } + + public String getUri(){ + return uri; + } + + private void setDate(String date){ + this.date = date; + } + + public String getDate() { + return date; + } + + private void setIssuerUid(String IssuerUid){ + this.IssuerUid = IssuerUid; + } + + public String getIssuerUid(){ + return IssuerUid; + } + + public String getProduct() { + return product; + } + + public void setProduct(String product) { + this.product = product; + } + + public String getDeadline() { + return deadline; + } + + public void setDeadline(String deadline) { + this.deadline = deadline; + } + + public int getLocation() { + return location; + } + + public void setLocation(int location) { + this.location = location; + } + + public boolean isDone() { + return done; + } + + public boolean getDone() { + return done; + } + + + public void setDone(boolean done) { + this.done = done; + } +} diff --git a/src/test/java/hibernateTest/models/Main.java b/src/test/java/hibernateTest/models/Main.java index e081e4c..22f26f6 100644 --- a/src/test/java/hibernateTest/models/Main.java +++ b/src/test/java/hibernateTest/models/Main.java @@ -2,6 +2,7 @@ import org.hibernate.SessionFactory; +//このメインクラスを実行すると、Hibernateのテストが行えます。 public class Main { public static void main(String args[]){ NativeApiIllustrationTest test = new NativeApiIllustrationTest(); diff --git a/src/test/java/hibernateTest/models/NativeApiIllustrationTest.java b/src/test/java/hibernateTest/models/NativeApiIllustrationTest.java index 76a87a1..c9c97c3 100644 --- a/src/test/java/hibernateTest/models/NativeApiIllustrationTest.java +++ b/src/test/java/hibernateTest/models/NativeApiIllustrationTest.java @@ -27,6 +27,8 @@ import java.util.List; import hibernateTest.entities.Event; +import hibernateTest.entities.Group; +import hibernateTest.entities.Request; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataSources; @@ -74,16 +76,30 @@ session.beginTransaction(); session.save( new Event( "Our very first event!", new Date() ) ); session.save( new Event( "A follow up event", new Date() ) ); + session.save( new Group("111", "http://test1", "famiry", "011" ) ); + session.save( new Group("222", "http://test2", "friend", "022" ) ); + session.save( new Request("111", "http://test01", "1999.01.01", "011", "ice", "1999.04.10",011)); + session.save( new Request("222", "http://test01", "1999.01.01", "022", "milk", "1999.04.10",011)); session.getTransaction().commit(); session.close(); // now lets pull events from the database and list them session = sessionFactory.openSession(); session.beginTransaction(); + List result = session.createQuery( "from Event" ).list(); for ( Event event : (List) result ) { System.out.println( "Event (" + event.getDate() + ") : " + event.getTitle() ); } + List groupResult = session.createQuery( "from Group" ).list(); + for ( Group group : (List) groupResult ) { + System.out.println( "Group (" + group.getgId() + ") : " + group.getUri() + ": " + group.getName()); + } + List requestResult = session.createQuery( "from Request" ).list(); + for ( Request request : (List) requestResult ) { + System.out.println( "Request (" + request.getrId() + ") : " + request.getUri() + ": " + request.getDate() + ": " + request.isDone()); + } + session.getTransaction().commit(); session.close(); } diff --git a/src/test/resources/Group.hbm.xml b/src/test/resources/Group.hbm.xml new file mode 100644 index 0000000..4576193 --- /dev/null +++ b/src/test/resources/Group.hbm.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/src/test/resources/Request.hbm.xml b/src/test/resources/Request.hbm.xml new file mode 100644 index 0000000..4184b20 --- /dev/null +++ b/src/test/resources/Request.hbm.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/hibernate.cfg.xml b/src/test/resources/hibernate.cfg.xml index 68e7f3f..f590b6b 100644 --- a/src/test/resources/hibernate.cfg.xml +++ b/src/test/resources/hibernate.cfg.xml @@ -35,6 +35,9 @@ create + + +