package org.sistema.hibernate.events.listeners;

import org.hibernate.event.spi.PreInsertEvent;
import org.hibernate.event.spi.PreInsertEventListener;
import org.sistema.hibernate.events.models.Sale;

/**
 * Class that allows you to audit the transactions involving entities persisted in the database.
 * @author Eugenia Pérez Martínez
 * @email eugenia_perez@cuatrovientos.org
 */
public class PreInsertSaleListener implements PreInsertEventListener {

	public boolean onPreInsert(PreInsertEvent preInsertEvent) {
		Object entity = preInsertEvent.getEntity();
		if (entity instanceof Sale) {
			Sale sale = (Sale) entity;
			System.out.println("Sales has been inserted: " + sale.getTotal()
					+ "\non: " + sale.getSalesDate() + ", \nby \""
					+ sale.getSalesperson().getName() + "\"\n");
		}
		return false;
	}

}
