Package net.viralpatel.contact.dao

Source Code of net.viralpatel.contact.dao.ContactDAOImpl

package net.viralpatel.contact.dao;

import java.util.List;

import net.viralpatel.contact.form.Contact;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ContactDAOImpl implements ContactDAO {

  @Autowired
  private SessionFactory sessionFactory;

  public void addContact(Contact contact) {
    sessionFactory.getCurrentSession().save(contact);
  }

  public List<Contact> listContact() {

    return sessionFactory.getCurrentSession().createQuery("from Contact")
        .list();
  }

  public void removeContact(Integer id) {
    Contact contact = (Contact) sessionFactory.getCurrentSession().load(
        Contact.class, id);
    if (null != contact) {
      sessionFactory.getCurrentSession().delete(contact);
    }

  }
}
TOP

Related Classes of net.viralpatel.contact.dao.ContactDAOImpl

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.