package com.ejie.ad74a.dao;

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;

import com.ejie.ad74a.model.MaestroMotDenegacion;
import com.ejie.ad74a.util.UtilSQL;
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;

/**
 * MaestroMotDenegacionDaoImpl generated by UDA, 30-oct-2023 14:41:18.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class MaestroMotDenegacionDaoImpl implements MaestroMotDenegacionDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDMOTIVODENEG59", "DESCES59", "DESCEU59",
			"IDPROCEDIMIENTO59", "FALTA59", "USUALTA59", "FMODIF59", "USUMODIF59" };

	private JdbcTemplate jdbcTemplate;

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<MaestroMotDenegacion> rwMap = new RowMapper<MaestroMotDenegacion>() {
		public MaestroMotDenegacion mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MaestroMotDenegacion(UtilSQL.getLong(resultSet, "IDMOTIVODENEG59"),
					resultSet.getString("DESCES59"), resultSet.getString("DESCEU59"),
					resultSet.getString("IDPROCEDIMIENTO59"), resultSet.getDate("FALTA59"),
					resultSet.getString("USUALTA59"), resultSet.getDate("FMODIF59"), resultSet.getString("USUMODIF59"));
		}
	};

	private RowMapper<MaestroMotDenegacion> rwMapPK = new RowMapper<MaestroMotDenegacion>() {
		public MaestroMotDenegacion mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MaestroMotDenegacion(UtilSQL.getLong(resultSet, "IDMOTIVODENEG59"));
		}
	};

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

			MaestroMotDenegacion maestromotdenegacion = new MaestroMotDenegacion(
					UtilSQL.getLong(resultSet, "IDMOTIVODENEG59"), resultSet.getString("DESCES59"),
					resultSet.getString("DESCEU59"), resultSet.getString("IDPROCEDIMIENTO59"),
					resultSet.getDate("FALTA59"), resultSet.getString("USUALTA59"), resultSet.getDate("FMODIF59"),
					resultSet.getString("USUMODIF59"));

			JerarquiaDto<MaestroMotDenegacion> jerarquia = new JerarquiaDto<MaestroMotDenegacion>();
			jerarquia.setModel(maestromotdenegacion);
			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 MaestroMotDenegacion table.
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @return MaestroMotDenegacion
	 */
	public MaestroMotDenegacion add(MaestroMotDenegacion maestromotdenegacion) {
		String query = "INSERT INTO MAESTRO_MOT_DENEGACION (ID_MOTIVO_DENEG_59, DESC_ES_59, DESC_EU_59, ID_PROCEDIMIENTO_59, F_ALTA_59, USU_ALTA_59, F_MODIF_59, USU_MODIF_59) VALUES (?,?,?,?,?,?,?,?)";
		this.jdbcTemplate.update(query, maestromotdenegacion.getIdMotivoDeneg59(), maestromotdenegacion.getDescEs59(),
				maestromotdenegacion.getDescEu59(), maestromotdenegacion.getIdProcedimiento59(),
				maestromotdenegacion.getfAlta59(), maestromotdenegacion.getUsuAlta59(),
				maestromotdenegacion.getFModif59(), maestromotdenegacion.getUsuModif59());
		return maestromotdenegacion;
	}

	/**
	 * Updates a single row in the MaestroMotDenegacion table.
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @return MaestroMotDenegacion
	 */
	public MaestroMotDenegacion update(MaestroMotDenegacion maestromotdenegacion) {
		String query = "UPDATE MAESTRO_MOT_DENEGACION SET DESC_ES_59=?, DESC_EU_59=?, ID_PROCEDIMIENTO_59 = ?, F_ALTA_59=?, USU_ALTA_59=?, F_MODIF_59=?, USU_MODIF_59=? WHERE ID_MOTIVO_DENEG_59=?";
		this.jdbcTemplate.update(query, maestromotdenegacion.getDescEs59(), maestromotdenegacion.getDescEu59(),
				maestromotdenegacion.getIdProcedimiento59(), maestromotdenegacion.getfAlta59(),
				maestromotdenegacion.getUsuAlta59(), maestromotdenegacion.getFModif59(),
				maestromotdenegacion.getUsuModif59(), maestromotdenegacion.getIdMotivoDeneg59());
		return maestromotdenegacion;
	}

	/**
	 * Finds a single row in the MaestroMotDenegacion table.
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @return MaestroMotDenegacion
	 */
	@Transactional(readOnly = true)
	public MaestroMotDenegacion find(MaestroMotDenegacion maestromotdenegacion) {
		String query = "SELECT t1.ID_MOTIVO_DENEG_59 IDMOTIVODENEG59, t1.DESC_ES_59 DESCES59, t1.DESC_EU_59 DESCEU59, t1.ID_PROCEDIMIENTO_59 IDPROCEDIMIENTO59, t1.F_ALTA_59 FALTA59, t1.USU_ALTA_59 USUALTA59, t1.F_MODIF_59 FMODIF59, t1.USU_MODIF_59 USUMODIF59 FROM MAESTRO_MOT_DENEGACION t1  WHERE t1.ID_MOTIVO_DENEG_59 = ?  ";

		List<MaestroMotDenegacion> maestromotdenegacionList = this.jdbcTemplate.query(query, this.rwMap,
				maestromotdenegacion.getIdMotivoDeneg59());
		return (MaestroMotDenegacion) DataAccessUtils.uniqueResult(maestromotdenegacionList);
	}

	/**
	 * Removes a single row in the MaestroMotDenegacion table.
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @return
	 */
	public void remove(MaestroMotDenegacion maestromotdenegacion) {
		String query = "DELETE FROM MAESTRO_MOT_DENEGACION WHERE ID_MOTIVO_DENEG_59=?";
		this.jdbcTemplate.update(query, maestromotdenegacion.getIdMotivoDeneg59());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_DENEG_59 IDMOTIVODENEG59, t1.DESC_ES_59 DESCES59, t1.DESC_EU_59 DESCEU59, t1.ID_PROCEDIMIENTO_59 IDPROCEDIMIENTO59, t1.F_ALTA_59 FALTA59, t1.USU_ALTA_59 USUALTA59, t1.F_MODIF_59 FMODIF59, t1.USU_MODIF_59 USUMODIF59");
		query.append(" FROM MAESTRO_MOT_DENEGACION t1  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterMaestroMotDenegacion, startsWith);
		StringBuilder where = new StringBuilder(query + " WHERE 1=1 ");
		where.append(mapaWhere.get("query"));

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

		StringBuilder sbMultipleSQL = TableManager.getSelectMultipleQuery(tableRequestDto, MaestroMotDenegacion.class,
				params, "ID_MOTIVO_DENEG_59");
		where.append(sbMultipleSQL);

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

	/**
	 * Finds a list of rows in the MaestroMotDenegacion table.
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @param tableRequestDto      TableRequestDto
	 * @return List<MaestroMotDenegacion>
	 */
	@Transactional(readOnly = true)
	public List<MaestroMotDenegacion> findAll(MaestroMotDenegacion maestromotdenegacion,
			TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOTIVO_DENEG_59 IDMOTIVODENEG59,t1.DESC_ES_59 DESCES59,t1.DESC_EU_59 DESCEU59,t1.ID_PROCEDIMIENTO_59 IDPROCEDIMIENTO59, t1.F_ALTA_59 FALTA59,t1.USU_ALTA_59 USUALTA59,t1.F_MODIF_59 FMODIF59,t1.USU_MODIF_59 USUMODIF59 ");
		query.append("FROM MAESTRO_MOT_DENEGACION t1 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(maestromotdenegacion);
		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,
					MaestroMotDenegacionDaoImpl.ORDER_BY_WHITE_LIST);
		}

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

	/**
	 * Finds rows in the MaestroMotDenegacion table using like.
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @param tableRequestDto      TableRequestDto
	 * @param startsWith           Boolean
	 * @return List<MaestroMotDenegacion>
	 */
	@Transactional(readOnly = true)
	public List<MaestroMotDenegacion> findAllLike(MaestroMotDenegacion maestromotdenegacion,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOTIVO_DENEG_59 IDMOTIVODENEG59,t1.DESC_ES_59 DESCES59,t1.DESC_EU_59 DESCEU59,t1.ID_PROCEDIMIENTO_59 IDPROCEDIMIENTO59, t1.F_ALTA_59 FALTA59,t1.USU_ALTA_59 USUALTA59,t1.F_MODIF_59 FMODIF59,t1.USU_MODIF_59 USUMODIF59 ");
		query.append("FROM MAESTRO_MOT_DENEGACION t1 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestromotdenegacion, 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,
					MaestroMotDenegacionDaoImpl.ORDER_BY_WHITE_LIST);
		}

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereMap(maestromotdenegacion);
		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 MaestroMotDenegacion table using like.
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @param startsWith           Boolean
	 * @return Long
	 */
	@Transactional(readOnly = true)
	public Long findAllLikeCount(MaestroMotDenegacion maestromotdenegacion, Boolean startsWith) {
		StringBuilder query = new StringBuilder("SELECT COUNT(1) FROM MAESTRO_MOT_DENEGACION t1 ");

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestromotdenegacion, 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 MaestroMotDenegacion selected for rup_table
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion
	 * @param tableRequestDto      TableRequestDto
	 * @param startsWith           Boolean
	 * @return List<TableRowDto<MaestroMotDenegacion>>
	 */
	@Override
	public List<TableRowDto<MaestroMotDenegacion>> reorderSelection(MaestroMotDenegacion maestromotdenegacion,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_DENEG_59 IDMOTIVODENEG59,t1.DESC_ES_59 DESCES59,t1.DESC_EU_59 DESCEU59,t1.ID_PROCEDIMIENTO_59 IDPROCEDIMIENTO59, t1.F_ALTA_59 FALTA59,t1.USU_ALTA_59 USUALTA59,t1.F_MODIF_59 FMODIF59,t1.USU_MODIF_59 USUMODIF59 ");
		// FROM
		query.append("FROM MAESTRO_MOT_DENEGACION t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestromotdenegacion, 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,
				MaestroMotDenegacion.class, filterParamList, "IDMOTIVODENEG59");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    MaestroMotDenegacion
	 * @param searchParams    MaestroMotDenegacion
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroMotDenegacion>>
	 */
	@Override
	public List<TableRowDto<MaestroMotDenegacion>> search(MaestroMotDenegacion filterParams,
			MaestroMotDenegacion searchParams, TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_DENEG_59 IDMOTIVODENEG59,t1.DESC_ES_59 DESCES59,t1.DESC_EU_59 DESCEU59,t1.ID_PROCEDIMIENTO_59 IDPROCEDIMIENTO59, t1.F_ALTA_59 FALTA59,t1.USU_ALTA_59 USUALTA59,t1.F_MODIF_59 FMODIF59,t1.USU_MODIF_59 USUMODIF59 ");
		// FROM
		query.append("FROM MAESTRO_MOT_DENEGACION 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,
				MaestroMotDenegacion.class, filterParamList, searchSQL, searchParamList, from_alias, "IDMOTIVODENEG59");

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

	/**
	 * Remove multiple method for rup_table
	 *
	 * @param tableRequestDto TableRequestDto
	 */
	@Override
	public void removeMultiple(TableRequestDto tableRequestDto) {
		StringBuilder sbRemoveMultipleSQL = TableManager.getRemoveMultipleQuery(tableRequestDto,
				MaestroMotDenegacion.class, "MAESTRO_MOT_DENEGACION", new String[] { "IDMOTIVODENEG59" });

		List<String> params = tableRequestDto.getMultiselection().getSelectedIds();

		this.jdbcTemplate.update(sbRemoveMultipleSQL.toString(), params.toArray());
	}

	/**
	 * Filter in the hierarchical MaestroMotDenegacion table.
	 *
	 * @param filterMaestroMotDenegacion MaestroMotDenegacion
	 * @param tableRequestDto            TableRequestDto
	 * @return List<JerarquiaDto<MaestroMotDenegacion>>
	 */
	@Override
	public List<JerarquiaDto<MaestroMotDenegacion>> findAllLikeJerarquia(
			MaestroMotDenegacion filterMaestroMotDenegacion, TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_DENEG_59 IDMOTIVODENEG59,t1.DESC_ES_59 DESCES59,t1.DESC_EU_59 DESCEU59,t1.ID_PROCEDIMIENTO_59 IDPROCEDIMIENTO59, t1.F_ALTA_59 FALTA59,t1.USU_ALTA_59 USUALTA59,t1.F_MODIF_59 FMODIF59,t1.USU_MODIF_59 USUMODIF59 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM MAESTRO_MOT_DENEGACION t1 ");
		List<String> from = new ArrayList<String>();
		from.add("MAESTRO_MOT_DENEGACION");
		// 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(filterMaestroMotDenegacion, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		query = TableManagerJerarquia.getQuery(tableRequestDto, query, mapaWhere, "IDMOTIVODENEG59", "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,
					MaestroMotDenegacionDaoImpl.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 filterMaestroMotDenegacion MaestroMotDenegacion
	 * @param tableRequestDto            TableRequestDto
	 * @return Long
	 */
	@Override
	public Long findAllLikeCountJerarquia(MaestroMotDenegacion filterMaestroMotDenegacion,
			TableRequestDto tableRequestDto) {
		// FROM
		// StringBuilder from = new StringBuilder("FROM MAESTRO_MOT_DENEGACION t1 ");
		List<String> from = new ArrayList<String>();
		from.add("MAESTRO_MOT_DENEGACION");

		// 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(filterMaestroMotDenegacion, false);

		// JERARQUIA
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryCount(tableRequestDto, mapaWhere, "IDMOTIVODENEG59",
				"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 filterMaestroMotDenegacion MaestroMotDenegacion
	 * @param tableRequestDto            TableRequestDto
	 * @return List<TableRowDto<MaestroMotDenegacion>>
	 */
	@Override
	public List<TableRowDto<MaestroMotDenegacion>> findAllChild(MaestroMotDenegacion filterMaestroMotDenegacion,
			TableRequestDto tableRequestDto) {

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

		// 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(filterMaestroMotDenegacion, false);

		// MULTISELECCION
		// Especificar la columna padre correspondiente en lugar de la generada por
		// defecto (ID_PADRE)
		StringBuilder query = TableManagerJerarquia.getQueryChildren(tableRequestDto, mapaWhere, "IDMOTIVODENEG59",
				"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<MaestroMotDenegacion>(this.rwMapPK, "IDMOTIVODENEG59"), params.toArray());
	}

	/*
	 * MÉTODOS PRIVADOS
	 */

	/**
	 * Returns a map with the needed value to create the conditions to filter by the
	 * MaestroMotDenegacion entity
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion 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(MaestroMotDenegacion maestromotdenegacion) {

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

		if (maestromotdenegacion != null && maestromotdenegacion.getIdMotivoDeneg59() != null) {
			where.append(" AND t1.ID_MOTIVO_DENEG_59 = ?");
			params.add(maestromotdenegacion.getIdMotivoDeneg59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getDescEs59() != null) {
			where.append(" AND t1.DESC_ES_59 = ?");
			params.add(maestromotdenegacion.getDescEs59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getDescEu59() != null) {
			where.append(" AND t1.DESC_EU_59 = ?");
			params.add(maestromotdenegacion.getDescEu59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getIdProcedimiento59() != null) {
			where.append(" AND t1.ID_PROCEDIMIENTO_59 = ?");
			params.add(maestromotdenegacion.getIdProcedimiento59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getfAlta59() != null) {
			where.append(" AND t1.F_ALTA_59 = ?");
			params.add(maestromotdenegacion.getfAlta59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getUsuAlta59() != null) {
			where.append(" AND t1.USU_ALTA_59 = ?");
			params.add(maestromotdenegacion.getUsuAlta59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getFModif59() != null) {
			where.append(" AND t1.F_MODIF_59 = ?");
			params.add(maestromotdenegacion.getFModif59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getUsuModif59() != null) {
			where.append(" AND t1.USU_MODIF_59 = ?");
			params.add(maestromotdenegacion.getUsuModif59());
		}

		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
	 * MaestroMotDenegacion entity
	 *
	 * @param maestromotdenegacion MaestroMotDenegacion 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(MaestroMotDenegacion maestromotdenegacion, Boolean startsWith) {

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

		if (maestromotdenegacion != null && maestromotdenegacion.getIdMotivoDeneg59() != null) {
			where.append(" AND t1.ID_MOTIVO_DENEG_59 = ?");
			params.add(maestromotdenegacion.getIdMotivoDeneg59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getDescEs59() != null) {
			where.append(" AND UPPER(t1.DESC_ES_59) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotdenegacion.getDescEs59().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotdenegacion.getDescEs59().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_ES_59 IS NOT NULL");
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getDescEu59() != null) {
			where.append(" AND UPPER(t1.DESC_EU_59) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotdenegacion.getDescEu59().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotdenegacion.getDescEu59().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_EU_59 IS NOT NULL");
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getIdProcedimiento59() != null) {
			where.append(" AND UPPER(t1.ID_PROCEDIMIENTO_59) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotdenegacion.getIdProcedimiento59().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotdenegacion.getIdProcedimiento59().toUpperCase() + "%");
			}
			where.append(" AND t1.ID_PROCEDIMIENTO_59 IS NOT NULL");
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getfAlta59() != null) {
			where.append(" AND t1.F_ALTA_59 = ?");
			params.add(maestromotdenegacion.getfAlta59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getUsuAlta59() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_59) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotdenegacion.getUsuAlta59().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotdenegacion.getUsuAlta59().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_59 IS NOT NULL");
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getFModif59() != null) {
			where.append(" AND t1.F_MODIF_59 = ?");
			params.add(maestromotdenegacion.getFModif59());
		}
		if (maestromotdenegacion != null && maestromotdenegacion.getUsuModif59() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_59) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotdenegacion.getUsuModif59().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotdenegacion.getUsuModif59().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_59 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;
}
