package ua.avk.rest.dao;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ua.avk.rest.entity.Contact;

import java.util.List;

/**
 * @author Alex Kononenko
 * @version 1.0.0
 *
 * The Contact dao realization with contact dao interface.
 */
@Service
@Transactional
class ContactDao implements IContactDao {

    @Autowired
    SessionFactory sessionFactory;

    /**
     * Get list of the contact by limits from database
     *
     * @param startId long contact id
     * @param count long count row
     * @return list of the contact
     */
    public List<Contact> getContactByLimit(long startId, long count){
        List<Contact> contactList = null;
        //contactList = sessionFactory.getCurrentSession().createCriteria(Contact.class).list();
        //contactList = (List<Contact>) sessionFactory.getCurrentSession().createSQLQuery("SELECT * FROM Contact");
        //contactList = (List<Contact>) sessionFactory.getCurrentSession().getNamedQuery(Contact.GET_ALL_CONTACT_FROM_DATABASE_QUERY).list();
        contactList = (List<Contact>) sessionFactory.getCurrentSession().getNamedQuery(Contact.GET_CONTACT_BY_LIMIT).setParameter("id", startId).setParameter("counter",startId+count).list();
        return contactList;
    }

    /**
     * Get all contacts from database
     *
     * @return list of the contacts
     */
    public List<Contact> getAllContacts(){
        List<Contact> contactList = null;
        contactList = sessionFactory.getCurrentSession().createCriteria(Contact.class).list();
        return contactList;
    }
}

@@ -63,54 +63,8 @@
 y;%0D%0A
-import org.hibernate.criterion.Restrictions;%0D%0A
 impo
@@ -127,58 +127,8 @@
 d;%0D%0A
-import org.springframework.stereotype.Component;%0D%0A
 impo
@@ -354,20 +354,43 @@
 .0.0%0D%0A *
-%0D%0A *
+          %3Cp/%3E%0D%0A *         
  The Con
@@ -701,16 +701,18 @@
 m count 
+  
 long cou
@@ -832,16 +832,17 @@
 g count)
+ 
 %7B%0D%0A     
@@ -883,366 +883,8 @@
 l;%0D%0A
-        //contactList = sessionFactory.getCurrentSession().createCriteria(Contact.class).list();%0D%0A        //contactList = (List%3CContact%3E) sessionFactory.getCurrentSession().createSQLQuery(%22SELECT * FROM Contact%22);%0D%0A        //contactList = (List%3CContact%3E) sessionFactory.getCurrentSession().getNamedQuery(Contact.GET_ALL_CONTACT_FROM_DATABASE_QUERY).list();%0D%0A
     
@@ -1051,16 +1051,19 @@
 er%22,
+ 
 startId
-+
+ + 
 coun
@@ -1255,16 +1255,17 @@
 ntacts()
+ 
 %7B%0D%0A     

Update ContactDao.java