Package com.lgx8.gateway.dao.impl

Source Code of com.lgx8.gateway.dao.impl.AddressDao

package com.lgx8.gateway.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.transaction.annotation.Transactional;

import com.lgx8.common.dao.impl.BaseDao;
import com.lgx8.gateway.dao.IAddressDao;
import com.lgx8.gateway.entities.Address;

@SuppressWarnings("unchecked")
public class AddressDao extends BaseDao implements IAddressDao {

  @Transactional
  public void deleteAddress(Address addr) {
    this.getHibernateTemplate().delete(addr);
  }

  @Transactional
  public void save(Address addr) {
    this.getHibernateTemplate().persist(addr);
  }

  public List<Address> findAddress(final String hql, final Object[] values) {
    // TODO Auto-generated method stub
    List list = this.getHibernateTemplate().executeFind(
        new HibernateCallback() {
          public Object doInHibernate(Session session)
              throws HibernateException, SQLException {
            Query query = session.createQuery(hql);
            for (int i = 0; i < values.length; i++) {
              query.setParameter(i, values[i]);
            }
            return query.list();
          }
        });
    return list;
  }

  @Transactional
  public void updateAddress(Address addr) {
    this.getHibernateTemplate().update(addr);
  }

  @Transactional
  public void batchDeleteAddress(String[] ids) {
    for(String id : ids)
    {
      Address addr = getHibernateTemplate().get(Address.class, Integer.parseInt(id));
      getHibernateTemplate().delete(addr);
    }
  }

  public List<Address> findAddress(String hql) {
    return getHibernateTemplate().find(hql);
  }

}
TOP

Related Classes of com.lgx8.gateway.dao.impl.AddressDao

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.