package com.song.dao; import java.util.List; import org.hibernate.SessionFactory; import org.hibernate.Session; import org.hibernate.Transaction; import com.song.Entity.Location; import com.song.Entity.Singer; import com.song.Entity.Song; import com.song.util.Page; public class SongDaoImpl implements SongDao { private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public int getcount() { Session session = sessionFactory.openSession(); Long count = (Long) session.createQuery("Select Count(*) From Song").uniqueResult(); session.close(); return count.intValue(); } public List getlist(Page page) { Session session = sessionFactory.openSession(); List list = session.createQuery("From Song") .setFirstResult(page.getStartRecord()) .setMaxResults(page.getPageSize()) .list(); return list; } public List getlocationlist() { Session session = sessionFactory.openSession(); List<Location> locationlist = session.createQuery("From Location").list(); return locationlist; } public List getsingerlist() { Session session = sessionFactory.openSession(); List<Singer> singerlist = session.createQuery("From Singer").list(); return singerlist; } public int doadd(Song song, String sid, String lid) { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Singer singer = (Singer) session.get(Singer.class, Integer.valueOf(sid)); Location location = (Location) session.get(Location.class, Integer.valueOf(lid)); song.setLocation(location); song.setSinger(singer); session.save(song); tx.commit(); return 1; } public Song getbyid(int id) { Session session = sessionFactory.openSession(); Song song = (Song) session.get(Song.class, id); return song; } public int doupdate(Song song, String sid, String lid) { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Singer singer = (Singer) session.get(Singer.class, Integer.valueOf(sid)); Location location = (Location) session.get(Location.class, Integer.valueOf(lid)); song.setSinger(singer); song.setLocation(location); session.update(song); tx.commit(); return 1; } public Song doDel(int id) { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Song song = (Song) session.get(Song.class, id); session.delete(song); tx.commit(); return song; } }
最近下载更多
lsglsg9 LV23
2021年11月24日
123456hdhdhdhd LV7
2020年8月20日
12345678fy LV1
2020年5月21日
i like you LV2
2020年4月26日
恣意ah LV7
2020年1月2日
wr463913813 LV5
2019年12月27日
zhengjin12 LV9
2019年12月19日
13148918399 LV9
2019年12月10日
渺无人烟 LV11
2019年11月6日
yuanchuang LV22
2019年10月8日