惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园 - 司徒正美
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Palo Alto Networks Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
小众软件
小众软件
T
Threatpost
Latest news
Latest news
J
Java Code Geeks
博客园 - Franky
博客园 - 三生石上(FineUI控件)
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
Simon Willison's Weblog
Simon Willison's Weblog
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
人人都是产品经理
人人都是产品经理
S
Schneier on Security
T
The Blog of Author Tim Ferriss
V
V2EX
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
罗磊的独立博客
IT之家
IT之家
雷峰网
雷峰网
H
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
C
Cybersecurity and Infrastructure Security Agency CISA
I
InfoQ
GbyAI
GbyAI
博客园 - 叶小钗
PCI Perspectives
PCI Perspectives
The GitHub Blog
The GitHub Blog
Martin Fowler
Martin Fowler
H
Heimdal Security Blog
Spread Privacy
Spread Privacy
博客园_首页
A
About on SuperTechFans
T
Tailwind CSS Blog
The Register - Security
The Register - Security

博客园 - sunliho

Java ClassLoader and Context ClassLoader find flow scope varibles in spring web flow Building Liferay on Tomcat Debugging Liferay in Eclipse ssl 服务器证书,客户端信任证书 相对路径与绝对路径 - sunliho - 博客园 db2 command 标准sql Linux系统下架设APACHE SVN服务器全过程 修改ip地址 mysql in linux network configuration in linux Linux系统信息查看命令大全 linux常用命令 Permission denied in linux install jdk in linux hibernate.cfg.xml 配置(摘录) - sunliho - 博客园 hibernate 配置文件(摘录) - sunliho - 博客园 web.xml配置详解(摘录)
generic dao
sunliho · 2010-08-10 · via 博客园 - sunliho

package flight.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.hibernate.Query;
import org.hibernate.SessionFactory;


public class GenericDao<T> {
 private SessionFactory sessionFactory ;

 public void setSessionFactory(SessionFactory sessionFactory) {
  this.sessionFactory = sessionFactory;
 }
 
 @SuppressWarnings("unchecked")
 public  T get(Serializable id,Class<T> type){
  return (T) this.sessionFactory.getCurrentSession().get(type.getClass(), id);
 }
 
 public Serializable save(T t){
  return this.sessionFactory.getCurrentSession().save(t) ;
 }
 
 public void persist(T t){
  this.sessionFactory.getCurrentSession().persist(t) ;
 }
 
 public void delete(T t){
  this.sessionFactory.getCurrentSession().delete(t);
 }
 
 public void update(T t){
  this.sessionFactory.getCurrentSession().update(t);
 }
 
 @SuppressWarnings("unchecked")
 public List<Object> findByNamedQuery(String namedQueryName){
  return this.sessionFactory.getCurrentSession().getNamedQuery(namedQueryName).list();
 }
 
 @SuppressWarnings("unchecked")
 public List<Object> findByNamedQuery(String namedQueryName,int resultLimit){
  return this.sessionFactory.getCurrentSession()
  .getNamedQuery(namedQueryName).setMaxResults(resultLimit).list();
 }
 
 public List<Object> findByNamedQuery(String namedQueryName,
   Map<String, Object> parameters) {
  return this.findByNamedQuery(namedQueryName, parameters,0, 0);
 }
 
 @SuppressWarnings("unchecked")
 public List<Object> findByNamedQuery(String namedQueryName,
   Map<String, Object> parameters,int startIndex,int resultLimit) {
  Query query = this.sessionFactory.getCurrentSession().getNamedQuery(
    namedQueryName);
  Set<Entry<String, Object>> rawParameters = parameters.entrySet();

  for (Entry<String, Object> entry : rawParameters) {
   query.setParameter(entry.getKey(), entry.getValue());
  }
  
  if (startIndex != 0)
   query.setFirstResult(startIndex);
  
  if(resultLimit > 0)
   query.setMaxResults(resultLimit);
  
  return query.list();
 }
 
 
 
 
 

}