package org.sistema.hibernate.events.listeners;

import org.hibernate.event.spi.PreDeleteEvent;
import org.hibernate.event.spi.PreDeleteEventListener;
import org.sistema.hibernate.events.models.Sale;

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

	public boolean onPreDelete(PreDeleteEvent preDeleteEvent) {
		Object entity = preDeleteEvent.getEntity();
		if (entity instanceof Sale) {
			Sale sale = (Sale) entity;
			System.out.println("The following sale made on ["
					+ sale.getSalesDate() + "] is about to be deleted, id="
					+ sale.getId());
		}
		return false;
	}

}
