SortDAOHibernateImpl.java :  » Math » mathmodeling » com » beehive » db » dao » impl » resource » Java Open Source

Java Open Source » Math » mathmodeling 
mathmodeling » com » beehive » db » dao » impl » resource » SortDAOHibernateImpl.java
package com.beehive.db.dao.impl.resource;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;

import com.beehive.db.dao.resource.SortDAO;
import com.beehive.db.entity.resource.Sort;
@Component("sortDAO")
public class SortDAOHibernateImpl implements SortDAO{
  private SessionFactory sessionFactory;
  
  private Session getSession(){
    return sessionFactory.getCurrentSession();
  }

  public void delete(Sort sort) {
    getSession().delete(sort);
  }

  public void delete(long id) {
    delete(getByID(id));
  }

  public Sort getByID(long id) {
    return (Sort)getSession().get(Sort.class, id);
  }

  @SuppressWarnings("unchecked")
  public List<Sort> getByName(String name) {
    String hql = "from Sort where name = '" + name + "'";
    Query query = getSession().createQuery(hql);
    return query.list();
  }

  @SuppressWarnings("unchecked")
  public List<Sort> getMultiple(int first, int max) {
    String hql = "from Sort";
    Query query = getSession().createQuery(hql);
    query.setFirstResult(first);
    query.setMaxResults(max);
    return query.list();
  }

  public void save(Sort sort) {
    getSession().save(sort);
  }

  public void update(Sort sort) {
    getSession().update(sort);
  }

  public SessionFactory getSessionFactory() {
    return sessionFactory;
  }
  @Resource
  public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.