package com.ejie.ab79.dao.actuaciones;

import com.ejie.ab79.model.actuaciones.DesResAct;
import com.ejie.x38.dao.RowNumResultSetExtractor;
import com.ejie.x38.dto.JerarquiaDto;
import com.ejie.x38.dto.TableManager;
import com.ejie.x38.dto.TableManagerJerarquia;
import com.ejie.x38.dto.TableRequestDto;
import com.ejie.x38.dto.TableRowDto;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * DesResActDaoImpl  
 * 
 *  
 */

@Repository
@Transactional
public class DesResActDaoImpl implements DesResActDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDDESRESACT", "DESCRIPCIONCASTELLANO",
			"DESCRIPCIONEUSKERA", "BAJA", "FECHAREGISTRO", "USUARIOREGISTRO", "FECHAULTMODIFICACION",
			"USUARIOULTMODIFICACION" };

	private JdbcTemplate jdbcTemplate;

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<DesResAct> rwMap = new RowMapper<DesResAct>() {
		public DesResAct mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new DesResAct(resultSet.getInt("IDDESRESACT"), resultSet.getString("DESCRIPCIONCASTELLANO"),
					resultSet.getString("DESCRIPCIONEUSKERA"), resultSet.getDate("FECHAREGISTRO"),
					resultSet.getString("USUARIOREGISTRO"));
		}
	};

	private RowMapper<DesResAct> rwMapPK = new RowMapper<DesResAct>() {
		public DesResAct mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new DesResAct(resultSet.getInt("IDDESRESACT"));
		}
	};

	/**
	 * Rowmapper para Jerarquía
	 *
	 * @param dataSource
	 *            DataSource
	 * @return
	 */
	private RowMapper<JerarquiaDto<DesResAct>> rwMapJerarquia = new RowMapper<JerarquiaDto<DesResAct>>() {
		public JerarquiaDto<DesResAct> mapRow(ResultSet resultSet, int rowNum) throws SQLException {

			DesResAct desresact = new DesResAct(resultSet.getInt("IDDESRESACT"),
					resultSet.getString("DESCRIPCIONCASTELLANO"), resultSet.getString("DESCRIPCIONEUSKERA"),
					resultSet.getDate("FECHAREGISTRO"), resultSet.getString("USUARIOREGISTRO"));

			JerarquiaDto<DesResAct> jerarquia = new JerarquiaDto<DesResAct>();
			jerarquia.setModel(desresact);
			jerarquia.setLevel(resultSet.getBigDecimal("LEVEL").intValue());
			jerarquia.setParentNodes(resultSet.getString("PARENTNODES"));
			jerarquia.setIsLeaf(Boolean.parseBoolean(resultSet.getString("ISLEAF")));
			jerarquia.setFilter(Boolean.parseBoolean(resultSet.getString("FILTER")));
			return jerarquia;
		}
	};

	/**
	 * Method use to set the datasource.
	 *
	 * @param dataSource
	 *            DataSource
	 * @return
	 */
	@Resource
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	/*
	 * OPERACIONES CRUD
	 */

	/**
	 * Inserts a single row in the DesResAct table.
	 *
	 * @param desresact
	 *            DesResAct
	 * @return DesResAct
	 */
	public DesResAct add(DesResAct desresact) {
		String query = "INSERT INTO DES_RES_ACT (ID_DES_RES_ACT, DESCRIPCION_CASTELLANO, DESCRIPCION_EUSKERA, FECHA_REGISTRO, USUARIO_REGISTRO) VALUES (S_AB7925T00.NEXTVAL,?,?,sysdate,?)";
		this.jdbcTemplate.update(query, desresact.getDescripcionCastellano(), desresact.getDescripcionEuskera(),
				desresact.getUsuarioRegistro());
		return desresact;
	}

	/**
	 * Updates a single row in the DesResAct table.
	 *
	 * @param desresact
	 *            DesResAct
	 * @return DesResAct
	 */
	public DesResAct update(DesResAct desresact) {
		String query = "UPDATE DES_RES_ACT SET DESCRIPCION_CASTELLANO=?, DESCRIPCION_EUSKERA=?, FECHA_REGISTRO=?, USUARIO_REGISTRO=? WHERE ID_DES_RES_ACT=?";
		this.jdbcTemplate.update(query, desresact.getDescripcionCastellano(), desresact.getDescripcionEuskera(),
				desresact.getFechaRegistro(), desresact.getUsuarioRegistro(), desresact.getIdDesResAct());
		return desresact;
	}

	/**
	 * Finds a single row in the DesResAct table.
	 *
	 * @param desresact
	 *            DesResAct
	 * @return DesResAct
	 */
	@Transactional(readOnly = true)
	public DesResAct find(DesResAct desresact) {
		String query = "SELECT t1.ID_DES_RES_ACT IDDESRESACT, t1.DESCRIPCION_CASTELLANO DESCRIPCIONCASTELLANO, t1.DESCRIPCION_EUSKERA DESCRIPCIONEUSKERA, t1.FECHA_REGISTRO FECHAREGISTRO FROM DES_RES_ACT t1  WHERE t1.ID_DES_RES_ACT = ?  ";

		List<DesResAct> desresactList = this.jdbcTemplate.query(query, this.rwMap, desresact.getIdDesResAct());
		return (DesResAct) DataAccessUtils.uniqueResult(desresactList);
	}

	/**
	 * Removes a single row in the DesResAct table.
	 *
	 * @param desresact
	 *            DesResAct
	 * @return
	 */
	public void remove(DesResAct desresact) {
		String query = "DELETE FROM DES_RES_ACT WHERE ID_DES_RES_ACT=?";
		this.jdbcTemplate.update(query, desresact.getIdDesResAct());
	}

	/**
	 * Exporta Datos al clipBoard
	 *
	 */
	public List<DesResAct> getMultiple(DesResAct filterDesResAct, TableRequestDto tableRequestDto, Boolean startsWith) {

		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterDesResAct, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));

		@SuppressWarnings("unchecked")
		List<Object> params = (List<Object>) mapaWhere.get("params");

		StringBuilder sbMultipleSQL = TableManager.getSelectMultipleQuery(tableRequestDto, DesResAct.class, params,
				"ID_DES_RES_ACT");

		return this.jdbcTemplate.query(sbMultipleSQL.toString(), this.rwMap, params.toArray());
	}

	/**
	 * Finds a list of rows in the DesResAct table.
	 *
	 * @param desresact
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @return List<DesResAct>
	 */
	@Transactional(readOnly = true)
	public List<DesResAct> findAll(DesResAct desresact, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DES_RES_ACT IDDESRESACT,t1.DESCRIPCION_CASTELLANO DESCRIPCIONCASTELLANO,t1.DESCRIPCION_EUSKERA DESCRIPCIONEUSKERA,t1.FECHA_REGISTRO FECHAREGISTRO,t1.USUARIO_REGISTRO USUARIOREGISTRO ");
		query.append("FROM DES_RES_ACT t1 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(desresact);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		if (tableRequestDto != null) {
			query = TableManager.getPaginationQuery(tableRequestDto, query, DesResActDaoImpl.ORDER_BY_WHITE_LIST);
		}

		return (List<DesResAct>) this.jdbcTemplate.query(query.toString(), this.rwMap, params.toArray());
	}

	/**
	 * Finds rows in the DesResAct table using like.
	 *
	 * @param desresact
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<DesResAct>
	 */
	@Transactional(readOnly = true)
	public List<DesResAct> findAllLike(DesResAct desresact, TableRequestDto tableRequestDto, Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DES_RES_ACT IDDESRESACT,t1.DESCRIPCION_CASTELLANO DESCRIPCIONCASTELLANO,t1.DESCRIPCION_EUSKERA DESCRIPCIONEUSKERA,t1.FECHA_REGISTRO FECHAREGISTRO,t1.USUARIO_REGISTRO USUARIOREGISTRO ");
		query.append("FROM DES_RES_ACT t1 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(desresact, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		if (tableRequestDto != null) {
			query = TableManager.getPaginationQuery(tableRequestDto, query, DesResActDaoImpl.ORDER_BY_WHITE_LIST);
		}

		return (List<DesResAct>) this.jdbcTemplate.query(query.toString(), this.rwMap, params.toArray());
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */

	/**
	 * Counts rows in the DesResAct table.
	 *
	 * @param desresact
	 *            DesResAct
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllCount(DesResAct desresact) {
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM DES_RES_ACT t1 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(desresact);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Counts rows in the DesResAct table using like.
	 *
	 * @param desresact
	 *            DesResAct
	 * @param startsWith
	 *            Boolean
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllLikeCount(DesResAct desresact, Boolean startsWith) {
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM DES_RES_ACT t1 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(desresact, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Reorder the data list of DesResAct selected for rup_table
	 *
	 * @param desresact
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<DesResAct>>
	 */
	@Override
	public List<TableRowDto<DesResAct>> reorderSelection(DesResAct desresact, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DES_RES_ACT IDDESRESACT,t1.DESCRIPCION_CASTELLANO DESCRIPCIONCASTELLANO,t1.DESCRIPCION_EUSKERA DESCRIPCIONEUSKERA,t1.FECHA_REGISTRO FECHAREGISTRO,t1.USUARIO_REGISTRO USUARIOREGISTRO ");
		// FROM
		query.append("FROM DES_RES_ACT t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(desresact, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		// Parámetros de filtrado
		@SuppressWarnings("unchecked")
		List<Object> filterParamList = (List<Object>) mapaWhere.get("params");

		// SQL para la reordenación
		StringBuilder sbReorderSelectionSQL = TableManager.getReorderQuery(query, tableRequestDto, DesResAct.class,
				filterParamList, "ID_DES_RES_ACT");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<DesResAct>(this.rwMapPK, tableRequestDto), filterParamList.toArray());
	}

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams
	 *            DesResAct
	 * @param searchParams
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 * @return List<TableRowDto<DesResAct>>
	 */
	@Override
	public List<TableRowDto<DesResAct>> search(DesResAct filterParams, DesResAct searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DES_RES_ACT IDDESRESACT,t1.DESCRIPCION_CASTELLANO DESCRIPCIONCASTELLANO,t1.DESCRIPCION_EUSKERA DESCRIPCIONEUSKERA,t1.FECHA_REGISTRO FECHAREGISTRO,t1.USUARIO_REGISTRO USUARIOREGISTRO ");
		// FROM
		query.append("FROM DES_RES_ACT t1 ");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// FILTRADO
		Map<String, ?> mapaWhereFilter = this.getWhereLikeMap(filterParams, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhereFilter.get("query"));
		query.append(where);
		// Filter params
		@SuppressWarnings("unchecked")
		List<Object> filterParamList = (List<Object>) mapaWhereFilter.get("params");

		// BUSQUEDA
		Map<String, Object> mapaWhereSearch = this.getWhereLikeMap(searchParams, startsWith);
		String searchSQL = ((StringBuilder) mapaWhereSearch.get("query")).toString();
		// Search params
		@SuppressWarnings("unchecked")
		List<Object> searchParamList = (List<Object>) mapaWhereSearch.get("params");

		// SQL
		StringBuilder sbReorderSelectionSQL = TableManager.getSearchQuery(query, tableRequestDto, DesResAct.class,
				filterParamList, searchSQL, searchParamList, from_alias, "ID_DES_RES_ACT");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<DesResAct>(this.rwMapPK, tableRequestDto), filterParamList.toArray());
	}

	/**
	 * Remove multiple method for rup_table
	 *
	 * @param filterdesresact
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @param startsWith
	 *            Boolean
	 */
	@Override
	public void removeMultiple(DesResAct filterdesresact, TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		/** TODO: select por clave */
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DES_RES_ACT IDDESRESACT,t1.DESCRIPCION_CASTELLANO DESCRIPCIONCASTELLANO,t1.DESCRIPCION_EUSKERA DESCRIPCIONEUSKERA,t1.FECHA_REGISTRO FECHAREGISTRO,t1.USUARIO_REGISTRO USUARIOREGISTRO ");
		// FROM
		query.append("FROM DES_RES_ACT t1 ");

		// WHERE
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterdesresact, startsWith);
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		where.append(mapaWhere.get("query"));
		query.append(where);

		@SuppressWarnings("unchecked")
		List<Object> params = (List<Object>) mapaWhere.get("params");

		StringBuilder sbRemoveMultipleSQL = TableManager.getRemoveMultipleQuery(tableRequestDto, DesResAct.class, query,
				params, "ID_DES_RES_ACT");
		this.jdbcTemplate.update(sbRemoveMultipleSQL.toString(), params.toArray());
	}

	/**
	 * Filter in the hierarchical DesResAct table.
	 *
	 * @param filterDesResAct
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @return List<JerarquiaDto<DesResAct>>
	 */
	@Override
	public List<JerarquiaDto<DesResAct>> findAllLikeJerarquia(DesResAct filterDesResAct,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DES_RES_ACT IDDESRESACT,t1.DESCRIPCION_CASTELLANO DESCRIPCIONCASTELLANO,t1.DESCRIPCION_EUSKERA DESCRIPCIONEUSKERA,t1.FECHA_REGISTRO FECHAREGISTRO,t1.USUARIO_REGISTRO USUARIOREGISTRO ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM DES_RES_ACT t1 ");
		List<String> from = new ArrayList<String>();
		from.add("DES_RES_ACT");
		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// JOINS TABLAS
		/*
		 * Ejemplo de como indicar joins entre las tablas de la query
		 */
		/*
		 * StringBuilder joins = new StringBuilder("");
		 * joins.append("AND T1.ID=T2.ID_T1");
		 */

		// CONDICIONES (negocio)
		/*
		 * Ejemplo de como incluir condiciones de negocio en la consulta de la
		 * jerarquía
		 */
		/*
		 * StringBuilder businessFilters = new StringBuilder(); List<Object>
		 * businessParams = new ArrayList<Object>();
		 * businessFilters.append("   AND t1.EJIE = ?  ");
		 * businessParams.add("1");
		 */

		// FILTRO
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterDesResAct, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada
		// por defecto (ID_PADRE)
		query = TableManagerJerarquia.getQuery(tableRequestDto, query, mapaWhere, "ID_DES_RES_ACT", "ID_PADRE",
				"NOMBRE", from, from_alias);

		/*
		 * Ejemplo de llamada en caso de indicar joins entre tablas y
		 * condiciones de negocio
		 */
		// query = TableManagerJerarquia.getQuery(tableRequestDto, query,
		// mapaWhere, "ID", "ID_PADRE", "NOMBRE", from, from_alias, joins,
		// businessFilters, businessParams);

		// PAGINACION
		if (tableRequestDto != null) {
			query = TableManagerJerarquia.getPaginationQuery(tableRequestDto, query,
					DesResActDaoImpl.ORDER_BY_WHITE_LIST);
		}

		List<?> params = (List<?>) mapaWhere.get("params");
		return this.jdbcTemplate.query(query.toString(), this.rwMapJerarquia, params.toArray());
	}

	/**
	 * Count rows in hierarchy
	 *
	 * @param filterDesResAct
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @return Long
	 */
	@Override
	public Long findAllLikeCountJerarquia(DesResAct filterDesResAct, TableRequestDto tableRequestDto) {
		// FROM
		// StringBuilder from = new StringBuilder("FROM DES_RES_ACT t1 ");
		List<String> from = new ArrayList<String>();
		from.add("DES_RES_ACT");

		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// JOINS TABLAS
		/*
		 * Ejemplo de como indicar joins entre las tablas de la query
		 */
		/*
		 * StringBuilder joins = new StringBuilder("");
		 * joins.append("AND T1.ID=T2.ID_T1");
		 */

		// CONDICIONES (negocio)
		/*
		 * Ejemplo de como incluir condiciones de negocio en la consulta de la
		 * jerarquía
		 */
		/*
		 * StringBuilder businessFilters = new StringBuilder(); List<Object>
		 * businessParams = new ArrayList<Object>();
		 * businessFilters.append("   AND t1.EJIE = ?  ");
		 * businessParams.add("1");
		 */

		// FILTRO
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterDesResAct, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada
		// por defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryCount(tableRequestDto, mapaWhere, "ID_DES_RES_ACT",
				"ID_PADRE", from, from_alias);

		/*
		 * Ejemplo de llamada en caso de indicar joins entre tablas y
		 * condiciones de negocio
		 */
		// StringBuilder query =
		// TableManagerJerarquia.getQueryCount(tableRequestDto, mapaWhere, "ID",
		// "ID_PADRE", from, from_alias, joins, businessFilters,
		// businessParams);

		List<?> params = (List<?>) mapaWhere.get("params");
		return this.jdbcTemplate.queryForObject(query.toString(), params.toArray(), Long.class);
	}

	/**
	 * Find dependent hierarchical rows
	 *
	 * @param filterDesResAct
	 *            DesResAct
	 * @param tableRequestDto
	 *            TableRequestDto
	 * @return List<TableRowDto<DesResAct>>
	 */
	@Override
	public List<TableRowDto<DesResAct>> findAllChild(DesResAct filterDesResAct, TableRequestDto tableRequestDto) {

		// FROM
		// StringBuilder from = new StringBuilder("FROM DES_RES_ACT t1 ");
		List<String> from = new ArrayList<String>();
		from.add("DES_RES_ACT");

		// TABLAS_ALIAS
		List<String> from_alias = new ArrayList<String>();
		from_alias.add(" t1 ");

		// JOINS TABLAS
		/*
		 * Ejemplo de como indicar joins entre las tablas de la query
		 */
		/*
		 * StringBuilder joins = new StringBuilder("");
		 * joins.append("AND T1.ID=T2.ID_T1");
		 */

		// CONDICIONES (negocio)
		/*
		 * Ejemplo de como incluir condiciones de negocio en la consulta de la
		 * jerarquía
		 */
		/*
		 * StringBuilder businessFilters = new StringBuilder(); List<Object>
		 * businessParams = new ArrayList<Object>();
		 * businessFilters.append("   AND t1.EJIE = ?  ");
		 * businessParams.add("1");
		 */

		// FILTRO
		Map<String, ?> mapaWhere = this.getWhereLikeMap(filterDesResAct, false);

		// MULTISELECCION
		// Especificar la columna padre correspondiente en lugar de la generada
		// por defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryChildren(tableRequestDto, mapaWhere, "ID_DES_RES_ACT",
				"ID_PADRE", from, from_alias);

		/*
		 * Ejemplo de llamada en caso de indicar joins entre tablas y
		 * condiciones de negocio
		 */
		// StringBuilder query =
		// TableManagerJerarquia.getQueryChildren(tableRequestDto, mapaWhere,
		// "ID", "ID_PADRE", from, from_alias, joins, businessFilters,
		// businessParams);

		List<?> params = (List<?>) mapaWhere.get("params");

		return this.jdbcTemplate.query(query.toString(),
				new RowNumResultSetExtractor<DesResAct>(this.rwMapPK, "ID_DES_RES_ACT"), params.toArray());
	}

	/*
	 * MÉTODOS PRIVADOS
	 */

	/**
	 * Returns a map with the needed value to create the conditions to filter by
	 * the DesResAct entity
	 *
	 * @param desresact
	 *            DesResAct Bean with the criteria values to filter by.
	 * @return Map created with two keys key query stores the sql query syntax
	 *         key params stores the parameter values to be used in the
	 *         condition sentence.
	 */
	// CHECKSTYLE:OFF CyclomaticComplexity - Generación de código de UDA
	private Map<String, ?> getWhereMap(DesResAct desresact) {

		StringBuilder where = new StringBuilder(DesResActDaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (desresact != null && desresact.getIdDesResAct() != null) {
			where.append(" AND t1.ID_DES_RES_ACT = ?");
			params.add(desresact.getIdDesResAct());
		}
		if (desresact != null && desresact.getDescripcionCastellano() != null) {
			where.append(" AND t1.DESCRIPCION_CASTELLANO = ?");
			params.add(desresact.getDescripcionCastellano());
		}
		if (desresact != null && desresact.getDescripcionEuskera() != null) {
			where.append(" AND t1.DESCRIPCION_EUSKERA = ?");
			params.add(desresact.getDescripcionEuskera());
		}
		if (desresact != null && desresact.getFechaRegistro() != null) {
			where.append(" AND t1.FECHA_REGISTRO = ?");
			params.add(desresact.getFechaRegistro());
		}
		if (desresact != null && desresact.getUsuarioRegistro() != null) {
			where.append(" AND t1.USUARIO_REGISTRO = ?");
			params.add(desresact.getUsuarioRegistro());
		}

		Map<String, Object> mapWhere = new HashMap<String, Object>();
		mapWhere.put("query", where);
		mapWhere.put("params", params);

		return mapWhere;
	}
	// CHECKSTYLE:ON CyclomaticComplexity - Generación de código de UDA

	/**
	 * Returns a map with the needed value to create the conditions to filter by
	 * the DesResAct entity
	 *
	 * @param desresact
	 *            DesResAct Bean with the criteria values to filter by.
	 * @param startsWith
	 *            Boolean
	 * @return Map created with two keys key query stores the sql query syntax
	 *         key params stores the parameter values to be used in the
	 *         condition sentence.
	 */
	// CHECKSTYLE:OFF CyclomaticComplexity - Generación de código de UDA
	private Map<String, Object> getWhereLikeMap(DesResAct desresact, Boolean startsWith) {

		StringBuilder where = new StringBuilder(DesResActDaoImpl.STRING_BUILDER_INIT);
		List<Object> params = new ArrayList<Object>();

		if (desresact != null && desresact.getIdDesResAct() != null) {
			where.append(" AND t1.ID_DES_RES_ACT = ?");
			params.add(desresact.getIdDesResAct());
		}
		if (desresact != null && desresact.getDescripcionCastellano() != null) {
			where.append(" AND UPPER(t1.DESCRIPCION_CASTELLANO) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(desresact.getDescripcionCastellano().toUpperCase() + "%");
			} else {
				params.add("%" + desresact.getDescripcionCastellano().toUpperCase() + "%");
			}
			where.append(" AND t1.DESCRIPCION_CASTELLANO IS NOT NULL");
		}
		if (desresact != null && desresact.getDescripcionEuskera() != null) {
			where.append(" AND UPPER(t1.DESCRIPCION_EUSKERA) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(desresact.getDescripcionEuskera().toUpperCase() + "%");
			} else {
				params.add("%" + desresact.getDescripcionEuskera().toUpperCase() + "%");
			}
			where.append(" AND t1.DESCRIPCION_EUSKERA IS NOT NULL");
		}
		if (desresact != null && desresact.getFechaRegistro() != null) {
			where.append(" AND t1.FECHA_REGISTRO = ?");
			params.add(desresact.getFechaRegistro());
		}
		if (desresact != null && desresact.getUsuarioRegistro() != null) {
			where.append(" AND UPPER(t1.USUARIO_REGISTRO) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(desresact.getUsuarioRegistro().toUpperCase() + "%");
			} else {
				params.add("%" + desresact.getUsuarioRegistro().toUpperCase() + "%");
			}
			where.append(" AND t1.USUARIO_REGISTRO IS NOT NULL");
		}

		Map<String, Object> mapWhere = new HashMap<String, Object>();
		mapWhere.put("query", where);
		mapWhere.put("params", params);

		return mapWhere;
	}
	// CHECKSTYLE:ON CyclomaticComplexity - Generación de código de UDA

	/**
	 * StringBuilder initilization value
	 */
	public static final int STRING_BUILDER_INIT = 4096;
}
