package com.bizofficer.admin.country;



import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.TypedQuery;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException;
import org.springframework.stereotype.Service;

import com.bizofficer.hibernate.entity.PgprepCountry;
import com.bizofficer.hibernate.repository.PgprepAdministratorRepository;


@Service
public class CountryAdService{
	
	@Autowired
	EntityManagerFactory entityManagerFactory;
	
	@Autowired
	PgprepAdministratorRepository adminRepo;
	
	public Object execute(Object obj) throws NotFoundException{
		List<CountryAdResponseBean> list = new ArrayList<CountryAdResponseBean>();
		
		try {
			
			EntityManager entityManager = entityManagerFactory.createEntityManager();
			entityManager.getTransaction().begin();
			
			TypedQuery<PgprepCountry> query = (TypedQuery<PgprepCountry>) entityManager.createQuery("from "+PgprepCountry.class.getName()+" order by country ", PgprepCountry.class);
			List<?> resultListCat = query.getResultList();
			Iterator<?> iteratorCat=resultListCat.iterator();	
			CountryAdResponseBean subObj;
			while(iteratorCat.hasNext()){
				PgprepCountry myObj = (PgprepCountry)iteratorCat.next();
				subObj = new CountryAdResponseBean();
				subObj.setCountry(myObj.getCountry());
				list.add(subObj);
			}

				
			entityManager.getTransaction().commit();
			entityManager.close();
			
		        
		}catch(Exception e) {
			e.getStackTrace();
		}
		
		
		return list;
	}
	

	
	

	
	
}
