package com.jasamedika.medifirst2000.logging;

import java.util.List;

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

import com.jasamedika.medifirst2000.logging.dao.LoggingJdbcDaoImpl;
import com.jasamedika.medifirst2000.logging.entities.Logging;

/**
 * Kelas Test 
 * 
 * @author Roberto
 */
public class MainLoggingApp {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"classpath*:com/jasamedika/**/applicationContext.xml");

		LoggingJdbcDaoImpl loggingJDBCTemplate = (LoggingJdbcDaoImpl) context
				.getBean("loggingJdbcDaoImpl");

		System.out.println("------Records Creation--------");
		loggingJDBCTemplate.create("Nama 1", "Desc 1");
		loggingJDBCTemplate.create("Nama 2", "Desc 2");
		loggingJDBCTemplate.create("Nama 3", "Desc 3");

		System.out.println("------Listing Multiple Records--------");
		List<Logging> loggings = loggingJDBCTemplate.listLoggings();
		for (Logging record : loggings) {
			System.out.print("ID : " + record.getId());
			System.out.print(", Nama : " + record.getNama());
			System.out.println(", Deskripsi : " + record.getDeskripsi());
		}

		System.out.println("----Updating Record with ID = 2 -----");
		loggingJDBCTemplate.update(2, "Updated Nama 2", "Updated Desc");

		System.out.println("----Listing Record with ID = 2 -----");
		Logging logging = loggingJDBCTemplate.getLogging(2);
		System.out.print("ID : " + logging.getId());
		System.out.print(", Nama : " + logging.getNama());
		System.out.println(", Deskripsi : " + logging.getDeskripsi());

	}
}
