package com.javahonk;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.javahonk.model.Person;
import com.javahonk.service.PersonService;

public class SpringHibernateTest {
	
	public static void main(String[] args) {
		
		ApplicationContext appContext = 
				new ClassPathXmlApplicationContext(
						"spring/applicationContext.xml");

		PersonService personService = (PersonService) appContext
				.getBean("personService");

		//Insert Person
		Person person = new Person();
		person.setCity("NY");
		person.setFirstName("Java");
		person.setLastName("Honk");
		person.setState("NY");
		person.setZip("12345");		
		personService.insertPerson(person);
		
		//Select Person		
		List<Person> listPerson = personService.findAllPerson();
		for (Person person2 : listPerson) {
			System.out.println("First Name: "+person2.getFirstName()
					+" Last Name: "+person2.getLastName()
					+" City: "+person2.getCity()
					+" State: "+person2.getState()
					+" Zip: "+person2.getZip());
		}
		
		//Update Person
		personService.updatePerson(1);
		
		//Delete Person
		personService.deletePerson(1);
		
		((AbstractApplicationContext)appContext).close();
		
	}
}
