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.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ad74a.model.DocTemporales;
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;

/**
 * DocTemporalesDaoImpl generated by UDA, 26-jul-2023 9:44:11.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class DocTemporalesDaoImpl implements DocTemporalesDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDDOCTEMPORAL72", "FOLDERID72", "IDTIPODOC72",
			"NOMBREDOC72", "RUTAPIF72", "OID72", "EXTERNO72", "USUAPORTACION72" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_DOC_TEMPORALES = "SEQ_DOC_TEMPORALES";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<DocTemporales> rwMap = new RowMapper<DocTemporales>() {
		public DocTemporales mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new DocTemporales(UtilSQL.getLong(resultSet, "IDDOCTEMPORAL72"), resultSet.getString("FOLDERID72"),
					resultSet.getLong("IDTIPODOC72"), resultSet.getString("NOMBREDOC72"),
					resultSet.getString("RUTAPIF72"), resultSet.getString("OID72"), resultSet.getString("OIDDOKUSI72"),
					UtilSQL.getInt(resultSet, "EXTERNO72"), resultSet.getString("USUAPORTACION72"));
		}
	};

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

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

			DocTemporales doctemporales = new DocTemporales(UtilSQL.getLong(resultSet, "IDDOCTEMPORAL72"),
					resultSet.getString("FOLDERID72"), resultSet.getLong("IDTIPODOC72"),
					resultSet.getString("NOMBREDOC72"), resultSet.getString("RUTAPIF72"), resultSet.getString("OID72"),
					resultSet.getString("OIDDOKUSI72"), UtilSQL.getInt(resultSet, "EXTERNO72"),
					resultSet.getString("USUAPORTACION72"));

			JerarquiaDto<DocTemporales> jerarquia = new JerarquiaDto<DocTemporales>();
			jerarquia.setModel(doctemporales);
			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 DocTemporales table.
	 *
	 * @param doctemporales DocTemporales
	 * @return DocTemporales
	 */
	public DocTemporales add(DocTemporales doctemporales) {

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO DOC_TEMPORALES (ID_DOC_TEMPORAL_72, FOLDERID_72, ID_TIPO_DOC_72, NOMBRE_DOC_72, RUTAPIF_72, OID_72,OID_DOKUSI_72 , EXTERNO_72, USU_APORTACION_72) "
				+ "VALUES (" + SEQUENCE_DOC_TEMPORALES
				+ ".NEXTVAL,:folderId,:idTipoDoc,:nombreDoc,:rutaPif,:oid,:oidDokusi72,:externo,:usuApor)";

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("folderId", doctemporales.getFolderId72())
				.addValue("idTipoDoc", doctemporales.getIdTipoDoc72())
				.addValue("nombreDoc", doctemporales.getNombreDoc72()).addValue("rutaPif", doctemporales.getRutapif72())
				.addValue("oid", doctemporales.getOid72()).addValue("oidDokusi72", doctemporales.getOidDokusi72())
				.addValue("externo", doctemporales.getExterno72())
				.addValue("usuApor", doctemporales.getUsuAportacion72());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_DOC_TEMPORAL_72" });
		doctemporales.setIdDocTemporal72(generatedKeyHolder.getKey().longValue());

		return doctemporales;
	}

	/**
	 * Updates a single row in the DocTemporales table.
	 *
	 * @param doctemporales DocTemporales
	 * @return DocTemporales
	 */
	public DocTemporales update(DocTemporales doctemporales) {
		String query = "UPDATE DOC_TEMPORALES SET FOLDERID_72=?, ID_TIPO_DOC_72=?, NOMBRE_DOC_72=?, RUTAPIF_72=?, OID_72 = ?,OID_DOKUSI_72 = ?, EXTERNO_72 = ?, USU_APORTACION_72=? WHERE ID_DOC_TEMPORAL_72=?";
		this.jdbcTemplate.update(query, doctemporales.getFolderId72(), doctemporales.getIdTipoDoc72(),
				doctemporales.getNombreDoc72(), doctemporales.getRutapif72(), doctemporales.getOid72(),
				doctemporales.getOidDokusi72(), doctemporales.getExterno72(), doctemporales.getUsuAportacion72(),
				doctemporales.getIdDocTemporal72());
		return doctemporales;
	}

	/**
	 * Finds a single row in the DocTemporales table.
	 *
	 * @param doctemporales DocTemporales
	 * @return DocTemporales
	 */
	@Transactional(readOnly = true)
	public DocTemporales find(DocTemporales doctemporales) {
		String query = "SELECT t1.ID_DOC_TEMPORAL_72 IDDOCTEMPORAL72, t1.FOLDERID_72 FOLDERID72, t1.ID_TIPO_DOC_72 IDTIPODOC72, t1.NOMBRE_DOC_72 NOMBREDOC72, t1.RUTAPIF_72 RUTAPIF72, t1.OID_72 OID72,t1.OID_DOKUSI_72 OIDDOKUSI72, t1.EXTERNO_72 EXTERNO72, t1.USU_APORTACION_72 USUAPORTACION72 FROM DOC_TEMPORALES t1  WHERE t1.ID_DOC_TEMPORAL_72 = ?  ";

		List<DocTemporales> doctemporalesList = this.jdbcTemplate.query(query, this.rwMap,
				doctemporales.getIdDocTemporal72());
		return (DocTemporales) DataAccessUtils.uniqueResult(doctemporalesList);
	}

	/**
	 * Removes a single row in the DocTemporales table.
	 *
	 * @param doctemporales DocTemporales
	 * @return
	 */
	public void remove(DocTemporales doctemporales) {
		String query = "DELETE FROM DOC_TEMPORALES WHERE ID_DOC_TEMPORAL_72=?";
		this.jdbcTemplate.update(query, doctemporales.getIdDocTemporal72());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_TEMPORAL_72 IDDOCTEMPORAL72, t1.FOLDERID_72 FOLDERID72, t1.ID_TIPO_DOC_72 IDTIPODOC72, t1.NOMBRE_DOC_72 NOMBREDOC72, t1.RUTAPIF_72 RUTAPIF72, t1.OID_72 OID72, t1.EXTERNO_72 EXTERNO72, t1.USU_APORTACION_72 USUAPORTACION72");
		query.append(" FROM DOC_TEMPORALES t1  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterDocTemporales, 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, DocTemporales.class, params,
				"ID_DOC_TEMPORAL_72");
		where.append(sbMultipleSQL);

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

	/**
	 * Finds a list of rows in the DocTemporales table.
	 *
	 * @param doctemporales   DocTemporales
	 * @param tableRequestDto TableRequestDto
	 * @return List<DocTemporales>
	 */
	@Transactional(readOnly = true)
	public List<DocTemporales> findAll(DocTemporales doctemporales, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DOC_TEMPORAL_72 IDDOCTEMPORAL72,t1.FOLDERID_72 FOLDERID72,t1.ID_TIPO_DOC_72 IDTIPODOC72,t1.NOMBRE_DOC_72 NOMBREDOC72,t1.RUTAPIF_72 RUTAPIF72,t1.OID_72 OID72,t1.OID_DOKUSI_72 OIDDOKUSI72, t1.EXTERNO_72 EXTERNO72, t1.USU_APORTACION_72 USUAPORTACION72 ");
		query.append("FROM DOC_TEMPORALES t1 ");

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

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

	/**
	 * Finds rows in the DocTemporales table using like.
	 *
	 * @param doctemporales   DocTemporales
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<DocTemporales>
	 */
	@Transactional(readOnly = true)
	public List<DocTemporales> findAllLike(DocTemporales doctemporales, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_DOC_TEMPORAL_72 IDDOCTEMPORAL72,t1.FOLDERID_72 FOLDERID72,t1.ID_TIPO_DOC_72 IDTIPODOC72,t1.NOMBRE_DOC_72 NOMBREDOC72,t1.RUTAPIF_72 RUTAPIF72,t1.OID_72 OID72,t1.OID_DOKUSI_72 OIDDOKUSI72, t1.EXTERNO_72 EXTERNO72, t1.USU_APORTACION_72 USUAPORTACION72 ");
		query.append("FROM DOC_TEMPORALES t1 ");

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(doctemporales, 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 DocTemporales selected for rup_table
	 *
	 * @param doctemporales   DocTemporales
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<DocTemporales>>
	 */
	@Override
	public List<TableRowDto<DocTemporales>> reorderSelection(DocTemporales doctemporales,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_TEMPORAL_72 IDDOCTEMPORAL72,t1.FOLDERID_72 FOLDERID72,t1.ID_TIPO_DOC_72 IDTIPODOC72,t1.NOMBRE_DOC_72 NOMBREDOC72,t1.RUTAPIF_72 RUTAPIF72,t1.OID_72 OID72,t1.OID_DOKUSI_72 OIDDOKUSI72, t1.EXTERNO_72 EXTERNO72, t1.USU_APORTACION_72 USUAPORTACION72 ");
		// FROM
		query.append("FROM DOC_TEMPORALES t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(doctemporales, 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, DocTemporales.class,
				filterParamList, "IDDOCTEMPORAL72");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    DocTemporales
	 * @param searchParams    DocTemporales
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<DocTemporales>>
	 */
	@Override
	public List<TableRowDto<DocTemporales>> search(DocTemporales filterParams, DocTemporales searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_TEMPORAL_72 IDDOCTEMPORAL72,t1.FOLDERID_72 FOLDERID72,t1.ID_TIPO_DOC_72 IDTIPODOC72,t1.NOMBRE_DOC_72 NOMBREDOC72,t1.RUTAPIF_72 RUTAPIF72,t1.OID_72 OID72,t1.OID_DOKUSI_72 OIDDOKUSI72, t1.EXTERNO_72 EXTERNO72, t1.USU_APORTACION_72 USUAPORTACION72 ");
		// FROM
		query.append("FROM DOC_TEMPORALES 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, DocTemporales.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDDOCTEMPORAL72");

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

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

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

	/**
	 * Filter in the hierarchical DocTemporales table.
	 *
	 * @param filterDocTemporales DocTemporales
	 * @param tableRequestDto     TableRequestDto
	 * @return List<JerarquiaDto<DocTemporales>>
	 */
	@Override
	public List<JerarquiaDto<DocTemporales>> findAllLikeJerarquia(DocTemporales filterDocTemporales,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_DOC_TEMPORAL_72 IDDOCTEMPORAL72,t1.FOLDERID_72 FOLDERID72,t1.ID_TIPO_DOC_72 IDTIPODOC72,t1.NOMBRE_DOC_72 NOMBREDOC72,t1.RUTAPIF_72 RUTAPIF72,t1.OID_72 OID72,t1.OID_DOKUSI_72 OIDDOKUSI72, t1.EXTERNO_72 EXTERNO72, t1.USU_APORTACION_72 USUAPORTACION72 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM DOC_TEMPORALES t1 ");
		List<String> from = new ArrayList<String>();
		from.add("DOC_TEMPORALES");
		// 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(filterDocTemporales, false);

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

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

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

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

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

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

	/*
	 * MÉTODOS PRIVADOS
	 */

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

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

		if (doctemporales != null && doctemporales.getIdDocTemporal72() != null) {
			where.append(" AND t1.ID_DOC_TEMPORAL_72 = ?");
			params.add(doctemporales.getIdDocTemporal72());
		}
		if (doctemporales != null && doctemporales.getFolderId72() != null) {
			where.append(" AND t1.FOLDERID_72 = ?");
			params.add(doctemporales.getFolderId72());
		}
		if (doctemporales != null && doctemporales.getIdTipoDoc72() != null) {
			where.append(" AND t1.ID_TIPO_DOC_72 = ?");
			params.add(doctemporales.getIdTipoDoc72());
		}
		if (doctemporales != null && doctemporales.getNombreDoc72() != null) {
			where.append(" AND t1.NOMBRE_DOC_72 = ?");
			params.add(doctemporales.getNombreDoc72());
		}
		if (doctemporales != null && doctemporales.getRutapif72() != null) {
			where.append(" AND t1.RUTAPIF_72 = ?");
			params.add(doctemporales.getRutapif72());
		}
		if (doctemporales != null && doctemporales.getOid72() != null) {
			where.append(" AND t1.OID_72 = ?");
			params.add(doctemporales.getOid72());
		}
		if (doctemporales != null && doctemporales.getExterno72() != null) {
			where.append(" AND t1.EXTERNO_72 = ?");
			params.add(doctemporales.getExterno72());
		}
		if (doctemporales != null && doctemporales.getUsuAportacion72() != null) {
			where.append(" AND t1.USU_APORTACION_72 = ?");
			params.add(doctemporales.getUsuAportacion72());
		}
		if (doctemporales != null && doctemporales.getOidDokusi72() != null) {
			where.append(" AND t1.OID_DOKUSI_72 = ?");
			params.add(doctemporales.getOidDokusi72());
		}

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

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

		if (doctemporales != null && doctemporales.getIdDocTemporal72() != null) {
			where.append(" AND t1.ID_DOC_TEMPORAL_72 = ?");
			params.add(doctemporales.getIdDocTemporal72());
		}

		if (doctemporales != null && doctemporales.getFolderId72() != null) {
			where.append(" AND UPPER(t1.FOLDERID_72) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(doctemporales.getFolderId72().toUpperCase() + "%");
			} else {
				params.add("%" + doctemporales.getFolderId72().toUpperCase() + "%");
			}
			where.append(" AND t1.FOLDERID_72 IS NOT NULL");
		}

		if (doctemporales != null && doctemporales.getIdTipoDoc72() != null) {
			where.append(" AND t1.ID_TIPO_DOC_72 = ?");
			params.add(doctemporales.getIdTipoDoc72());
		}
		if (doctemporales != null && doctemporales.getNombreDoc72() != null) {
			where.append(" AND UPPER(t1.NOMBRE_DOC_72) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(doctemporales.getNombreDoc72().toUpperCase() + "%");
			} else {
				params.add("%" + doctemporales.getNombreDoc72().toUpperCase() + "%");
			}
			where.append(" AND t1.NOMBRE_DOC_72 IS NOT NULL");
		}
		if (doctemporales != null && doctemporales.getRutapif72() != null) {
			where.append(" AND UPPER(t1.RUTAPIF_72) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(doctemporales.getRutapif72().toUpperCase() + "%");
			} else {
				params.add("%" + doctemporales.getRutapif72().toUpperCase() + "%");
			}
			where.append(" AND t1.RUTAPIF_72 IS NOT NULL");
		}
		if (doctemporales != null && doctemporales.getOid72() != null) {
			where.append(" AND UPPER(t1.OID_72) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(doctemporales.getOid72().toUpperCase() + "%");
			} else {
				params.add("%" + doctemporales.getOid72().toUpperCase() + "%");
			}
			where.append(" AND t1.OID_72 IS NOT NULL");
		}
		if (doctemporales != null && doctemporales.getExterno72() != null) {
			where.append(" AND t1.EXTERNO_72 = ?");
			params.add(doctemporales.getExterno72());
		}

		if (doctemporales != null && doctemporales.getUsuAportacion72() != null) {
			where.append(" AND UPPER(t1.USU_APORTACION_72) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(doctemporales.getUsuAportacion72().toUpperCase() + "%");
			} else {
				params.add("%" + doctemporales.getUsuAportacion72().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_APORTACION_72 IS NOT NULL");
		}

		if (doctemporales != null && doctemporales.getOidDokusi72() != null) {
			where.append(" AND UPPER(t1.OID_DOKUSI_72) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(doctemporales.getOidDokusi72().toUpperCase() + "%");
			} else {
				params.add("%" + doctemporales.getOidDokusi72().toUpperCase() + "%");
			}
			where.append(" AND t1.OID_DOKUSI_72 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;
}
