package com.ejie.ad74a.dao;

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.math.BigDecimal;
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.MaestroMotQueja;

/**
 * MaestroMotQuejaDaoImpl generated by UDA, 02-oct-2023 13:02:27.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class MaestroMotQuejaDaoImpl implements MaestroMotQuejaDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDMOTIVOQUEJA62", "DESCES62", "DESCEU62",
			"FALTA62", "USUALTA62", "FMODIF62", "USUMODIF62" };

	private JdbcTemplate jdbcTemplate;

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<MaestroMotQueja> rwMap = new RowMapper<MaestroMotQueja>() {
		public MaestroMotQueja mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MaestroMotQueja(resultSet.getLong("IDMOTIVOQUEJA62"), resultSet.getString("DESCES62"),
					resultSet.getString("DESCEU62"), resultSet.getDate("FALTA62"), resultSet.getString("USUALTA62"),
					resultSet.getDate("FMODIF62"), resultSet.getString("USUMODIF62"));
		}
	};

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

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

			MaestroMotQueja maestromotqueja = new MaestroMotQueja(resultSet.getLong("IDMOTIVOQUEJA62"),
					resultSet.getString("DESCES62"), resultSet.getString("DESCEU62"), resultSet.getDate("FALTA62"),
					resultSet.getString("USUALTA62"), resultSet.getDate("FMODIF62"), resultSet.getString("USUMODIF62"));

			JerarquiaDto<MaestroMotQueja> jerarquia = new JerarquiaDto<MaestroMotQueja>();
			jerarquia.setModel(maestromotqueja);
			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 MaestroMotQueja table.
	 *
	 * @param maestromotqueja MaestroMotQueja
	 * @return MaestroMotQueja
	 */
	public MaestroMotQueja add(MaestroMotQueja maestromotqueja) {
		String query = "INSERT INTO MAESTRO_MOT_QUEJA (ID_MOTIVO_QUEJA_62, DESC_ES_62, DESC_EU_62, F_ALTA_62, USU_ALTA_62, F_MODIF_62, USU_MODIF_62) VALUES (?,?,?,?,?,?,?)";
		this.jdbcTemplate.update(query, maestromotqueja.getIdMotivoQueja62(), maestromotqueja.getDescEs62(),
				maestromotqueja.getDescEu62(), maestromotqueja.getFAlta62(), maestromotqueja.getUsuAlta62(),
				maestromotqueja.getFModif62(), maestromotqueja.getUsuModif62());
		return maestromotqueja;
	}

	/**
	 * Updates a single row in the MaestroMotQueja table.
	 *
	 * @param maestromotqueja MaestroMotQueja
	 * @return MaestroMotQueja
	 */
	public MaestroMotQueja update(MaestroMotQueja maestromotqueja) {
		String query = "UPDATE MAESTRO_MOT_QUEJA SET DESC_ES_62=?, DESC_EU_62=?, F_ALTA_62=?, USU_ALTA_62=?, F_MODIF_62=?, USU_MODIF_62=? WHERE ID_MOTIVO_QUEJA_62=?";
		this.jdbcTemplate.update(query, maestromotqueja.getDescEs62(), maestromotqueja.getDescEu62(),
				maestromotqueja.getFAlta62(), maestromotqueja.getUsuAlta62(), maestromotqueja.getFModif62(),
				maestromotqueja.getUsuModif62(), maestromotqueja.getIdMotivoQueja62());
		return maestromotqueja;
	}

	/**
	 * Finds a single row in the MaestroMotQueja table.
	 *
	 * @param maestromotqueja MaestroMotQueja
	 * @return MaestroMotQueja
	 */
	@Transactional(readOnly = true)
	public MaestroMotQueja find(MaestroMotQueja maestromotqueja) {
		String query = "SELECT t1.ID_MOTIVO_QUEJA_62 IDMOTIVOQUEJA62, t1.DESC_ES_62 DESCES62, t1.DESC_EU_62 DESCEU62, t1.F_ALTA_62 FALTA62, t1.USU_ALTA_62 USUALTA62, t1.F_MODIF_62 FMODIF62, t1.USU_MODIF_62 USUMODIF62 FROM MAESTRO_MOT_QUEJA t1  WHERE t1.ID_MOTIVO_QUEJA_62 = ?  ";

		List<MaestroMotQueja> maestromotquejaList = this.jdbcTemplate.query(query, this.rwMap,
				maestromotqueja.getIdMotivoQueja62());
		return (MaestroMotQueja) DataAccessUtils.uniqueResult(maestromotquejaList);
	}

	/**
	 * Removes a single row in the MaestroMotQueja table.
	 *
	 * @param maestromotqueja MaestroMotQueja
	 * @return
	 */
	public void remove(MaestroMotQueja maestromotqueja) {
		String query = "DELETE FROM MAESTRO_MOT_QUEJA WHERE ID_MOTIVO_QUEJA_62=?";
		this.jdbcTemplate.update(query, maestromotqueja.getIdMotivoQueja62());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_QUEJA_62 IDMOTIVOQUEJA62, t1.DESC_ES_62 DESCES62, t1.DESC_EU_62 DESCEU62, t1.F_ALTA_62 FALTA62, t1.USU_ALTA_62 USUALTA62, t1.F_MODIF_62 FMODIF62, t1.USU_MODIF_62 USUMODIF62");
		query.append(" FROM MAESTRO_MOT_QUEJA t1  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterMaestroMotQueja, 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, MaestroMotQueja.class,
				params, "ID_MOTIVO_QUEJA_62");
		where.append(sbMultipleSQL);

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

	/**
	 * Finds a list of rows in the MaestroMotQueja table.
	 *
	 * @param maestromotqueja MaestroMotQueja
	 * @param tableRequestDto TableRequestDto
	 * @return List<MaestroMotQueja>
	 */
	@Transactional(readOnly = true)
	public List<MaestroMotQueja> findAll(MaestroMotQueja maestromotqueja, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOTIVO_QUEJA_62 IDMOTIVOQUEJA62,t1.DESC_ES_62 DESCES62,t1.DESC_EU_62 DESCEU62,t1.F_ALTA_62 FALTA62,t1.USU_ALTA_62 USUALTA62,t1.F_MODIF_62 FMODIF62,t1.USU_MODIF_62 USUMODIF62 ");
		query.append("FROM MAESTRO_MOT_QUEJA t1 ");

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

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

	/**
	 * Finds rows in the MaestroMotQueja table using like.
	 *
	 * @param maestromotqueja MaestroMotQueja
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<MaestroMotQueja>
	 */
	@Transactional(readOnly = true)
	public List<MaestroMotQueja> findAllLike(MaestroMotQueja maestromotqueja, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_MOTIVO_QUEJA_62 IDMOTIVOQUEJA62,t1.DESC_ES_62 DESCES62,t1.DESC_EU_62 DESCEU62,t1.F_ALTA_62 FALTA62,t1.USU_ALTA_62 USUALTA62,t1.F_MODIF_62 FMODIF62,t1.USU_MODIF_62 USUMODIF62 ");
		query.append("FROM MAESTRO_MOT_QUEJA t1 ");

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestromotqueja, 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 MaestroMotQueja selected for rup_table
	 *
	 * @param maestromotqueja MaestroMotQueja
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroMotQueja>>
	 */
	@Override
	public List<TableRowDto<MaestroMotQueja>> reorderSelection(MaestroMotQueja maestromotqueja,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_QUEJA_62 IDMOTIVOQUEJA62,t1.DESC_ES_62 DESCES62,t1.DESC_EU_62 DESCEU62,t1.F_ALTA_62 FALTA62,t1.USU_ALTA_62 USUALTA62,t1.F_MODIF_62 FMODIF62,t1.USU_MODIF_62 USUMODIF62 ");
		// FROM
		query.append("FROM MAESTRO_MOT_QUEJA t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestromotqueja, 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,
				MaestroMotQueja.class, filterParamList, "IDMOTIVOQUEJA62");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    MaestroMotQueja
	 * @param searchParams    MaestroMotQueja
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroMotQueja>>
	 */
	@Override
	public List<TableRowDto<MaestroMotQueja>> search(MaestroMotQueja filterParams, MaestroMotQueja searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_QUEJA_62 IDMOTIVOQUEJA62,t1.DESC_ES_62 DESCES62,t1.DESC_EU_62 DESCEU62,t1.F_ALTA_62 FALTA62,t1.USU_ALTA_62 USUALTA62,t1.F_MODIF_62 FMODIF62,t1.USU_MODIF_62 USUMODIF62 ");
		// FROM
		query.append("FROM MAESTRO_MOT_QUEJA 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, MaestroMotQueja.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDMOTIVOQUEJA62");

		return this.jdbcTemplate.query(sbReorderSelectionSQL.toString(),
				new RowNumResultSetExtractor<MaestroMotQueja>(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, MaestroMotQueja.class,
				"MAESTRO_MOT_QUEJA", new String[] { "IDMOTIVOQUEJA62" });

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

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

	/**
	 * Filter in the hierarchical MaestroMotQueja table.
	 *
	 * @param filterMaestroMotQueja MaestroMotQueja
	 * @param tableRequestDto       TableRequestDto
	 * @return List<JerarquiaDto<MaestroMotQueja>>
	 */
	@Override
	public List<JerarquiaDto<MaestroMotQueja>> findAllLikeJerarquia(MaestroMotQueja filterMaestroMotQueja,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_MOTIVO_QUEJA_62 IDMOTIVOQUEJA62,t1.DESC_ES_62 DESCES62,t1.DESC_EU_62 DESCEU62,t1.F_ALTA_62 FALTA62,t1.USU_ALTA_62 USUALTA62,t1.F_MODIF_62 FMODIF62,t1.USU_MODIF_62 USUMODIF62 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM MAESTRO_MOT_QUEJA t1 ");
		List<String> from = new ArrayList<String>();
		from.add("MAESTRO_MOT_QUEJA");
		// 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(filterMaestroMotQueja, false);

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

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

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

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

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

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

	/*
	 * MÉTODOS PRIVADOS
	 */

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

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

		if (maestromotqueja != null && maestromotqueja.getIdMotivoQueja62() != null) {
			where.append(" AND t1.ID_MOTIVO_QUEJA_62 = ?");
			params.add(maestromotqueja.getIdMotivoQueja62());
		}
		if (maestromotqueja != null && maestromotqueja.getDescEs62() != null) {
			where.append(" AND t1.DESC_ES_62 = ?");
			params.add(maestromotqueja.getDescEs62());
		}
		if (maestromotqueja != null && maestromotqueja.getDescEu62() != null) {
			where.append(" AND t1.DESC_EU_62 = ?");
			params.add(maestromotqueja.getDescEu62());
		}
		if (maestromotqueja != null && maestromotqueja.getFAlta62() != null) {
			where.append(" AND t1.F_ALTA_62 = ?");
			params.add(maestromotqueja.getFAlta62());
		}
		if (maestromotqueja != null && maestromotqueja.getUsuAlta62() != null) {
			where.append(" AND t1.USU_ALTA_62 = ?");
			params.add(maestromotqueja.getUsuAlta62());
		}
		if (maestromotqueja != null && maestromotqueja.getFModif62() != null) {
			where.append(" AND t1.F_MODIF_62 = ?");
			params.add(maestromotqueja.getFModif62());
		}
		if (maestromotqueja != null && maestromotqueja.getUsuModif62() != null) {
			where.append(" AND t1.USU_MODIF_62 = ?");
			params.add(maestromotqueja.getUsuModif62());
		}

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

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

		if (maestromotqueja != null && maestromotqueja.getIdMotivoQueja62() != null) {
			where.append(" AND t1.ID_MOTIVO_QUEJA_62 = ?");
			params.add(maestromotqueja.getIdMotivoQueja62());
		}
		if (maestromotqueja != null && maestromotqueja.getDescEs62() != null) {
			where.append(" AND UPPER(t1.DESC_ES_62) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotqueja.getDescEs62().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotqueja.getDescEs62().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_ES_62 IS NOT NULL");
		}
		if (maestromotqueja != null && maestromotqueja.getDescEu62() != null) {
			where.append(" AND UPPER(t1.DESC_EU_62) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotqueja.getDescEu62().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotqueja.getDescEu62().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_EU_62 IS NOT NULL");
		}
		if (maestromotqueja != null && maestromotqueja.getFAlta62() != null) {
			where.append(" AND t1.F_ALTA_62 = ?");
			params.add(maestromotqueja.getFAlta62());
		}
		if (maestromotqueja != null && maestromotqueja.getUsuAlta62() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_62) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotqueja.getUsuAlta62().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotqueja.getUsuAlta62().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_62 IS NOT NULL");
		}
		if (maestromotqueja != null && maestromotqueja.getFModif62() != null) {
			where.append(" AND t1.F_MODIF_62 = ?");
			params.add(maestromotqueja.getFModif62());
		}
		if (maestromotqueja != null && maestromotqueja.getUsuModif62() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_62) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestromotqueja.getUsuModif62().toUpperCase() + "%");
			} else {
				params.add("%" + maestromotqueja.getUsuModif62().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_62 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;
}
