package jp.co.y_net.amm.dao;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Order;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

/**
 * LocalestringDaoImpl
 *
 * @version 1.0.0
 */
@Component("localestringDao")
public class LocalestringDaoImpl extends AbstractDao implements LocalestringDao {

    @Override
    public List<Localestring> get(Localestring item) {
        HibernateTemplate hibernateTemplate = getHibernateTemplate();
        DetachedCriteria dc = DetachedCriteria.forClass(Localestring.class);
        dc.add(Example.create(item));
        dc.addOrder(Order.asc("num"));
        @SuppressWarnings("unchecked")
        List<Localestring> list = (List<Localestring>) hibernateTemplate.findByCriteria(dc);
        hibernateTemplate.clear();
        return list;

    }
    @Override
    public void add(Localestring item) {
        try {
            HibernateTemplate hibernateTemplate = getHibernateTemplate();
            hibernateTemplate.save(item);
            hibernateTemplate.flush();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    public void update(Localestring item) {
        try {
            HibernateTemplate hibernateTemplate = getHibernateTemplate();

            hibernateTemplate.update(item);
            hibernateTemplate.flush();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    public void remove(Localestring item) {
        try {
            HibernateTemplate hibernateTemplate = getHibernateTemplate();
            hibernateTemplate.delete(item);
            hibernateTemplate.flush();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
