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.MaestroActores;
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;

/**
 * MaestroActoresDaoImpl generated by UDA, 12-may-2023 11:16:38.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class MaestroActoresDaoImpl implements MaestroActoresDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDACTOR42", "DESCES42", "DESCEU42",
			"DESCSORT42" };

	private JdbcTemplate jdbcTemplate;

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<MaestroActores> rwMap = new RowMapper<MaestroActores>() {
		public MaestroActores mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MaestroActores(UtilSQL.getLong(resultSet, "IDACTOR42"), resultSet.getString("DESCES42"),
					resultSet.getString("DESCEU42"), resultSet.getString("DESCSORT42"));
		}
	};

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

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

			MaestroActores maestroactores = new MaestroActores(UtilSQL.getLong(resultSet, "IDACTOR42"),
					resultSet.getString("DESCES42"), resultSet.getString("DESCEU42"),
					resultSet.getString("DESCSORT42"));

			JerarquiaDto<MaestroActores> jerarquia = new JerarquiaDto<MaestroActores>();
			jerarquia.setModel(maestroactores);
			jerarquia.setLevel((int) UtilSQL.getInt(resultSet, "LEVEL"));
			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 MaestroActores table.
	 *
	 * @param maestroactores MaestroActores
	 * @return MaestroActores
	 */
	public MaestroActores add(MaestroActores maestroactores) {
		String query = "INSERT INTO MAESTRO_ACTORES (ID_ACTOR_42, DESC_ES_42, DESC_EU_42, DESC_SORT_42) VALUES (?,?,?,?)";
		this.jdbcTemplate.update(query, maestroactores.getIdActor42(), maestroactores.getDescEs42(),
				maestroactores.getDescEu42(), maestroactores.getDescSort42());
		return maestroactores;
	}

	/**
	 * Updates a single row in the MaestroActores table.
	 *
	 * @param maestroactores MaestroActores
	 * @return MaestroActores
	 */
	public MaestroActores update(MaestroActores maestroactores) {
		String query = "UPDATE MAESTRO_ACTORES SET DESC_ES_42=?, DESC_EU_42=?, DESC_SORT_42=? WHERE ID_ACTOR_42=?";
		this.jdbcTemplate.update(query, maestroactores.getDescEs42(), maestroactores.getDescEu42(),
				maestroactores.getDescSort42(), maestroactores.getIdActor42());
		return maestroactores;
	}

	/**
	 * Finds a single row in the MaestroActores table.
	 *
	 * @param maestroactores MaestroActores
	 * @return MaestroActores
	 */
	@Transactional(readOnly = true)
	public MaestroActores find(MaestroActores maestroactores) {
		String query = "SELECT t1.ID_ACTOR_42 IDACTOR42, t1.DESC_ES_42 DESCES42, t1.DESC_EU_42 DESCEU42, t1.DESC_SORT_42 DESCSORT42 FROM MAESTRO_ACTORES t1  WHERE t1.ID_ACTOR_42 = ?  ";

		List<MaestroActores> maestroactoresList = this.jdbcTemplate.query(query, this.rwMap,
				maestroactores.getIdActor42());
		return (MaestroActores) DataAccessUtils.uniqueResult(maestroactoresList);
	}

	/**
	 * Removes a single row in the MaestroActores table.
	 *
	 * @param maestroactores MaestroActores
	 * @return
	 */
	public void remove(MaestroActores maestroactores) {
		String query = "DELETE FROM MAESTRO_ACTORES WHERE ID_ACTOR_42=?";
		this.jdbcTemplate.update(query, maestroactores.getIdActor42());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_ACTOR_42 IDACTOR42, t1.DESC_ES_42 DESCES42, t1.DESC_EU_42 DESCEU42, t1.DESC_SORT_42 DESCSORT42");
		query.append(" FROM MAESTRO_ACTORES t1  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterMaestroActores, 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, MaestroActores.class, params,
				"ID_ACTOR_42");
		where.append(sbMultipleSQL);

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

	/**
	 * Finds a list of rows in the MaestroActores table.
	 *
	 * @param maestroactores  MaestroActores
	 * @param tableRequestDto TableRequestDto
	 * @return List<MaestroActores>
	 */
	@Transactional(readOnly = true)
	public List<MaestroActores> findAll(MaestroActores maestroactores, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_ACTOR_42 IDACTOR42,t1.DESC_ES_42 DESCES42,t1.DESC_EU_42 DESCEU42,t1.DESC_SORT_42 DESCSORT42 ");
		query.append("FROM MAESTRO_ACTORES t1 ");

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

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

	@Transactional(readOnly = true)
	public List<MaestroActores> findNoSSB(MaestroActores maestroactores, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_ACTOR_42 IDACTOR42,t1.DESC_ES_42 DESCES42,t1.DESC_EU_42 DESCEU42,t1.DESC_SORT_42 DESCSORT42 ");
		query.append("FROM MAESTRO_ACTORES t1 ");

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

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

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

		return (List<MaestroActores>) this.jdbcTemplate.query(query.toString(), this.rwMap);
	}

	@Transactional(readOnly = true)
	public List<MaestroActores> findNoAuto(MaestroActores maestroactores, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_ACTOR_42 IDACTOR42,t1.DESC_ES_42 DESCES42,t1.DESC_EU_42 DESCEU42,t1.DESC_SORT_42 DESCSORT42 ");
		query.append("FROM MAESTRO_ACTORES t1 ");

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

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

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

		return (List<MaestroActores>) this.jdbcTemplate.query(query.toString(), this.rwMap);
	}

	/**
	 * Finds rows in the MaestroActores table using like.
	 *
	 * @param maestroactores  MaestroActores
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<MaestroActores>
	 */
	@Transactional(readOnly = true)
	public List<MaestroActores> findAllLike(MaestroActores maestroactores, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_ACTOR_42 IDACTOR42,t1.DESC_ES_42 DESCES42,t1.DESC_EU_42 DESCEU42,t1.DESC_SORT_42 DESCSORT42 ");
		query.append("FROM MAESTRO_ACTORES t1 ");

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestroactores, 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 MaestroActores selected for rup_table
	 *
	 * @param maestroactores  MaestroActores
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroActores>>
	 */
	@Override
	public List<TableRowDto<MaestroActores>> reorderSelection(MaestroActores maestroactores,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_ACTOR_42 IDACTOR42,t1.DESC_ES_42 DESCES42,t1.DESC_EU_42 DESCEU42,t1.DESC_SORT_42 DESCSORT42 ");
		// FROM
		query.append("FROM MAESTRO_ACTORES t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestroactores, 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, MaestroActores.class,
				filterParamList, "IDACTOR42");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    MaestroActores
	 * @param searchParams    MaestroActores
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroActores>>
	 */
	@Override
	public List<TableRowDto<MaestroActores>> search(MaestroActores filterParams, MaestroActores searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_ACTOR_42 IDACTOR42,t1.DESC_ES_42 DESCES42,t1.DESC_EU_42 DESCEU42,t1.DESC_SORT_42 DESCSORT42 ");
		// FROM
		query.append("FROM MAESTRO_ACTORES 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, MaestroActores.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDACTOR42");

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

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

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

	/**
	 * Filter in the hierarchical MaestroActores table.
	 *
	 * @param filterMaestroActores MaestroActores
	 * @param tableRequestDto      TableRequestDto
	 * @return List<JerarquiaDto<MaestroActores>>
	 */
	@Override
	public List<JerarquiaDto<MaestroActores>> findAllLikeJerarquia(MaestroActores filterMaestroActores,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_ACTOR_42 IDACTOR42,t1.DESC_ES_42 DESCES42,t1.DESC_EU_42 DESCEU42,t1.DESC_SORT_42 DESCSORT42 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM MAESTRO_ACTORES t1 ");
		List<String> from = new ArrayList<String>();
		from.add("MAESTRO_ACTORES");
		// 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(filterMaestroActores, false);

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

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

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

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

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

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

	/*
	 * MÉTODOS PRIVADOS
	 */

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

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

		if (maestroactores != null && maestroactores.getIdActor42() != null) {
			where.append(" AND t1.ID_ACTOR_42 = ?");
			params.add(maestroactores.getIdActor42());
		}
		if (maestroactores != null && maestroactores.getDescEs42() != null) {
			where.append(" AND t1.DESC_ES_42 = ?");
			params.add(maestroactores.getDescEs42());
		}
		if (maestroactores != null && maestroactores.getDescEu42() != null) {
			where.append(" AND t1.DESC_EU_42 = ?");
			params.add(maestroactores.getDescEu42());
		}
		if (maestroactores != null && maestroactores.getDescSort42() != null) {
			where.append(" AND t1.DESC_SORT_42 = ?");
			params.add(maestroactores.getDescSort42());
		}

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

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

		if (maestroactores != null && maestroactores.getIdActor42() != null) {
			where.append(" AND t1.ID_ACTOR_42 = ?");
			params.add(maestroactores.getIdActor42());
		}
		if (maestroactores != null && maestroactores.getDescEs42() != null) {
			where.append(" AND UPPER(t1.DESC_ES_42) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestroactores.getDescEs42().toUpperCase() + "%");
			} else {
				params.add("%" + maestroactores.getDescEs42().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_ES_42 IS NOT NULL");
		}
		if (maestroactores != null && maestroactores.getDescEu42() != null) {
			where.append(" AND UPPER(t1.DESC_EU_42) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestroactores.getDescEu42().toUpperCase() + "%");
			} else {
				params.add("%" + maestroactores.getDescEu42().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_EU_42 IS NOT NULL");
		}
		if (maestroactores != null && maestroactores.getDescSort42() != null) {
			where.append(" AND UPPER(t1.DESC_SORT_42) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestroactores.getDescSort42().toUpperCase() + "%");
			} else {
				params.add("%" + maestroactores.getDescSort42().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_SORT_42 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;
}
