package dao;

import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;

import common.dao.GenericDAO;
import common.dao.IDAO;

public class SicuraDAO<T, ID extends Serializable>  extends GenericDAO<T, ID> implements IDAO<T, ID> {
	
	public final Integer K_RECORD_MODIFICATO=4;
	public final Integer K_RECORD_ELIMINATO=5;
	
	public Integer checkRecord(String SecurityUserId, String guid, String entityName, Integer id, byte[] lastSaved, String idFieldName) 
		throws Exception{
		/*
		 CREATE PROCEDURE [dbo].[spCheckRecord]
			@SecurityUserId VARCHAR(15),
			@SecurityGuid UNIQUEIDENTIFIER,
		
			@TableName	varchar(255),
			@ID	int,
			@LastSaved	timestamp,
			@CampoID varchar(20)
		 */
		
		Integer res = null;
		try {
			Connection connection = getConnection();
			
			CallableStatement proc;
			proc = connection.prepareCall("{? = call spCheckRecord(?,?,?,?,?,?)}");
			
			proc.registerOutParameter(1, Types.VARCHAR);
			proc.setString(2, SecurityUserId);
			proc.setString(3, guid);
			proc.setString(4, entityName);
			proc.setObject(5, id);
			proc.setBytes(6, lastSaved);
			proc.setString(7, idFieldName);
			
			proc.execute();
			proc.getMoreResults();
				
			res = proc.getInt(1);
		}catch (Exception ex) {
			throw ex;
		}	

		return res;
	}

}
