コード例 #1
0
 public boolean update(Member member) {
   SessionFactory sf = HibernateUtil.getSessionFactory();
   Session session = sf.getCurrentSession();
   session.beginTransaction();
   session.update(member);
   session.getTransaction().commit();
   return true;
 }
コード例 #2
0
 public Member loadByID(int id) {
   SessionFactory sf = HibernateUtil.getSessionFactory();
   Session session = sf.getCurrentSession();
   session.beginTransaction();
   Member member = (Member) session.get(Member.class, id);
   session.getTransaction().commit();
   return member;
 }
コード例 #3
0
 public List<Member> loadBySQL(String sql) {
   SessionFactory sf = HibernateUtil.getSessionFactory();
   Session session = sf.getCurrentSession();
   session.beginTransaction();
   SQLQuery q = session.createSQLQuery(sql);
   List<Member> list = q.addEntity(Member.class).list();
   session.getTransaction().commit();
   return list;
 }
コード例 #4
0
 public int countBySQL(String count_sql) {
   SessionFactory sf = HibernateUtil.getSessionFactory();
   Session session = sf.getCurrentSession();
   session.beginTransaction();
   SQLQuery q = session.createSQLQuery(count_sql);
   int ret = ((BigInteger) q.list().get(0)).intValue();
   session.getTransaction().commit();
   return ret;
 }
コード例 #5
0
 public boolean delete(int id) {
   String sql = "delete from member where id = " + id + ";";
   SessionFactory sf = HibernateUtil.getSessionFactory();
   Session session = sf.getCurrentSession();
   session.beginTransaction();
   SQLQuery q = session.createSQLQuery(sql);
   q.executeUpdate();
   session.getTransaction().commit();
   return true;
 }
コード例 #6
0
 public boolean memberExists(String name) {
   String sql = "select * from member where name='" + name + "';";
   boolean b = false;
   SessionFactory sf = HibernateUtil.getSessionFactory();
   Session session = sf.getCurrentSession();
   session.beginTransaction();
   SQLQuery q = session.createSQLQuery(sql);
   List<Member> list = q.addEntity(Member.class).list();
   if (list.size() > 0) b = true;
   session.getTransaction().commit();
   return b;
 }
コード例 #7
0
 public Member checkMember(String name, String password) {
   String sql = "select * from member where name='" + name + "' and password='******';";
   Member m = new Member();
   SessionFactory sf = HibernateUtil.getSessionFactory();
   Session session = sf.getCurrentSession();
   session.beginTransaction();
   SQLQuery q = session.createSQLQuery(sql);
   List<Member> list = q.addEntity(Member.class).list();
   if (list.size() > 0) m = (Member) list.get(0);
   session.getTransaction().commit();
   return m;
 }