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

/**
 * MaestroTipoAlarmaDaoImpl generated by UDA, 10-jul-2023 9:33:38.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class MaestroTipoAlarmaDaoImpl implements MaestroTipoAlarmaDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDTIPOALARMA48", "DESCES48", "DESCEU48",
			"FALTA48", "USUALTA48", "FMODIF48", "USUMODIF48" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_MAESTRO_TIPO_ALARMA = "SEQ_MAESTRO_TIPO_ALARMA";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<MaestroTipoAlarma> rwMap = new RowMapper<MaestroTipoAlarma>() {
		public MaestroTipoAlarma mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MaestroTipoAlarma(UtilSQL.getLong(resultSet, "IDTIPOALARMA48"), resultSet.getString("DESCES48"),
					resultSet.getString("DESCEU48"), resultSet.getDate("FALTA48"), resultSet.getString("USUALTA48"),
					resultSet.getDate("FMODIF48"), resultSet.getString("USUMODIF48"));
		}
	};

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

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

			MaestroTipoAlarma maestrotipoalarma = new MaestroTipoAlarma(UtilSQL.getLong(resultSet, "IDTIPOALARMA48"),
					resultSet.getString("DESCES48"), resultSet.getString("DESCEU48"), resultSet.getDate("FALTA48"),
					resultSet.getString("USUALTA48"), resultSet.getDate("FMODIF48"), resultSet.getString("USUMODIF48"));

			JerarquiaDto<MaestroTipoAlarma> jerarquia = new JerarquiaDto<MaestroTipoAlarma>();
			jerarquia.setModel(maestrotipoalarma);
			jerarquia.setLevel(UtilSQL.getLong(resultSet, "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 MaestroTipoAlarma table.
	 *
	 * @param maestrotipoalarma MaestroTipoAlarma
	 * @return MaestroTipoAlarma
	 */
	public MaestroTipoAlarma add(MaestroTipoAlarma maestrotipoalarma) {
		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO MAESTRO_TIPO_ALARMA (ID_TIPO_ALARMA_48, DESC_ES_48, DESC_EU_48, F_ALTA_48, USU_ALTA_48, F_MODIF_48, USU_MODIF_48) "
				+ "VALUES (" + SEQUENCE_MAESTRO_TIPO_ALARMA
				+ ".NEXTVAL,:descEs,:descEu,:fAlta,:usuAlta,:fModif,:usuModif)";

		MapSqlParameterSource parameters = new MapSqlParameterSource()
				.addValue("descEs", maestrotipoalarma.getDescEs48()).addValue("descEu", maestrotipoalarma.getDescEu48())
				.addValue("fAlta", maestrotipoalarma.getfAlta48()).addValue("usuAlta", maestrotipoalarma.getUsuAlta48())
				.addValue("fModif", maestrotipoalarma.getfModif48())
				.addValue("usuModif", maestrotipoalarma.getUsuModif48());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_TIPO_ALARMA_48" });
		maestrotipoalarma.setIdTipoAlarma48(generatedKeyHolder.getKey().longValue());

		return maestrotipoalarma;
	}

	/**
	 * Updates a single row in the MaestroTipoAlarma table.
	 *
	 * @param maestrotipoalarma MaestroTipoAlarma
	 * @return MaestroTipoAlarma
	 */
	public MaestroTipoAlarma update(MaestroTipoAlarma maestrotipoalarma) {
		String query = "UPDATE MAESTRO_TIPO_ALARMA SET DESC_ES_48=?, DESC_EU_48=?, F_MODIF_48=?, USU_MODIF_48=? WHERE ID_TIPO_ALARMA_48=?";
		this.jdbcTemplate.update(query, maestrotipoalarma.getDescEs48(), maestrotipoalarma.getDescEu48(),
				maestrotipoalarma.getfModif48(), maestrotipoalarma.getUsuModif48(),
				maestrotipoalarma.getIdTipoAlarma48());
		return maestrotipoalarma;
	}

	/**
	 * Finds a single row in the MaestroTipoAlarma table.
	 *
	 * @param maestrotipoalarma MaestroTipoAlarma
	 * @return MaestroTipoAlarma
	 */
	@Transactional(readOnly = true)
	public MaestroTipoAlarma find(MaestroTipoAlarma maestrotipoalarma) {
		String query = "SELECT t1.ID_TIPO_ALARMA_48 IDTIPOALARMA48, t1.DESC_ES_48 DESCES48, t1.DESC_EU_48 DESCEU48, t1.F_ALTA_48 FALTA48, t1.USU_ALTA_48 USUALTA48, t1.F_MODIF_48 FMODIF48, t1.USU_MODIF_48 USUMODIF48 FROM MAESTRO_TIPO_ALARMA t1  WHERE t1.ID_TIPO_ALARMA_48 = ?  ";

		List<MaestroTipoAlarma> maestrotipoalarmaList = this.jdbcTemplate.query(query, this.rwMap,
				maestrotipoalarma.getIdTipoAlarma48());
		return (MaestroTipoAlarma) DataAccessUtils.uniqueResult(maestrotipoalarmaList);
	}

	/**
	 * Removes a single row in the MaestroTipoAlarma table.
	 *
	 * @param maestrotipoalarma MaestroTipoAlarma
	 * @return
	 */
	public void remove(MaestroTipoAlarma maestrotipoalarma) {
		String query = "DELETE FROM MAESTRO_TIPO_ALARMA WHERE ID_TIPO_ALARMA_48=?";
		this.jdbcTemplate.update(query, maestrotipoalarma.getIdTipoAlarma48());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TIPO_ALARMA_48 IDTIPOALARMA48, t1.DESC_ES_48 DESCES48, t1.DESC_EU_48 DESCEU48, t1.F_ALTA_48 FALTA48, t1.USU_ALTA_48 USUALTA48, t1.F_MODIF_48 FMODIF48, t1.USU_MODIF_48 USUMODIF48");
		query.append(" FROM MAESTRO_TIPO_ALARMA t1  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterMaestroTipoAlarma, 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, MaestroTipoAlarma.class,
				params, "ID_TIPO_ALARMA_48");
		where.append(sbMultipleSQL);

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

	/**
	 * Finds a list of rows in the MaestroTipoAlarma table.
	 *
	 * @param maestrotipoalarma MaestroTipoAlarma
	 * @param tableRequestDto   TableRequestDto
	 * @return List<MaestroTipoAlarma>
	 */
	@Transactional(readOnly = true)
	public List<MaestroTipoAlarma> findAll(MaestroTipoAlarma maestrotipoalarma, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TIPO_ALARMA_48 IDTIPOALARMA48,t1.DESC_ES_48 DESCES48,t1.DESC_EU_48 DESCEU48,t1.F_ALTA_48 FALTA48,t1.USU_ALTA_48 USUALTA48,t1.F_MODIF_48 FMODIF48,t1.USU_MODIF_48 USUMODIF48 ");
		query.append("FROM MAESTRO_TIPO_ALARMA t1 ");

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

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

	/**
	 * Finds rows in the MaestroTipoAlarma table using like.
	 *
	 * @param maestrotipoalarma MaestroTipoAlarma
	 * @param tableRequestDto   TableRequestDto
	 * @param startsWith        Boolean
	 * @return List<MaestroTipoAlarma>
	 */
	@Transactional(readOnly = true)
	public List<MaestroTipoAlarma> findAllLike(MaestroTipoAlarma maestrotipoalarma, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TIPO_ALARMA_48 IDTIPOALARMA48,t1.DESC_ES_48 DESCES48,t1.DESC_EU_48 DESCEU48,t1.F_ALTA_48 FALTA48,t1.USU_ALTA_48 USUALTA48,t1.F_MODIF_48 FMODIF48,t1.USU_MODIF_48 USUMODIF48 ");
		query.append("FROM MAESTRO_TIPO_ALARMA t1 ");

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestrotipoalarma, 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 MaestroTipoAlarma selected for rup_table
	 *
	 * @param maestrotipoalarma MaestroTipoAlarma
	 * @param tableRequestDto   TableRequestDto
	 * @param startsWith        Boolean
	 * @return List<TableRowDto<MaestroTipoAlarma>>
	 */
	@Override
	public List<TableRowDto<MaestroTipoAlarma>> reorderSelection(MaestroTipoAlarma maestrotipoalarma,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TIPO_ALARMA_48 IDTIPOALARMA48,t1.DESC_ES_48 DESCES48,t1.DESC_EU_48 DESCEU48,t1.F_ALTA_48 FALTA48,t1.USU_ALTA_48 USUALTA48,t1.F_MODIF_48 FMODIF48,t1.USU_MODIF_48 USUMODIF48 ");
		// FROM
		query.append("FROM MAESTRO_TIPO_ALARMA t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestrotipoalarma, 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,
				MaestroTipoAlarma.class, filterParamList, "IDTIPOALARMA48");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    MaestroTipoAlarma
	 * @param searchParams    MaestroTipoAlarma
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroTipoAlarma>>
	 */
	@Override
	public List<TableRowDto<MaestroTipoAlarma>> search(MaestroTipoAlarma filterParams, MaestroTipoAlarma searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TIPO_ALARMA_48 IDTIPOALARMA48,t1.DESC_ES_48 DESCES48,t1.DESC_EU_48 DESCEU48,t1.F_ALTA_48 FALTA48,t1.USU_ALTA_48 USUALTA48,t1.F_MODIF_48 FMODIF48,t1.USU_MODIF_48 USUMODIF48 ");
		// FROM
		query.append("FROM MAESTRO_TIPO_ALARMA 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,
				MaestroTipoAlarma.class, filterParamList, searchSQL, searchParamList, from_alias, "IDTIPOALARMA48");

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

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

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

	/**
	 * Filter in the hierarchical MaestroTipoAlarma table.
	 *
	 * @param filterMaestroTipoAlarma MaestroTipoAlarma
	 * @param tableRequestDto         TableRequestDto
	 * @return List<JerarquiaDto<MaestroTipoAlarma>>
	 */
	@Override
	public List<JerarquiaDto<MaestroTipoAlarma>> findAllLikeJerarquia(MaestroTipoAlarma filterMaestroTipoAlarma,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TIPO_ALARMA_48 IDTIPOALARMA48,t1.DESC_ES_48 DESCES48,t1.DESC_EU_48 DESCEU48,t1.F_ALTA_48 FALTA48,t1.USU_ALTA_48 USUALTA48,t1.F_MODIF_48 FMODIF48,t1.USU_MODIF_48 USUMODIF48 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM MAESTRO_TIPO_ALARMA t1 ");
		List<String> from = new ArrayList<String>();
		from.add("MAESTRO_TIPO_ALARMA");
		// 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(filterMaestroTipoAlarma, false);

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

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

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

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

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

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

	/*
	 * MÉTODOS PRIVADOS
	 */

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

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

		if (maestrotipoalarma != null && maestrotipoalarma.getIdTipoAlarma48() != null) {
			where.append(" AND t1.ID_TIPO_ALARMA_48 = ?");
			params.add(maestrotipoalarma.getIdTipoAlarma48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getDescEs48() != null) {
			where.append(" AND t1.DESC_ES_48 = ?");
			params.add(maestrotipoalarma.getDescEs48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getDescEu48() != null) {
			where.append(" AND t1.DESC_EU_48 = ?");
			params.add(maestrotipoalarma.getDescEu48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getfAlta48() != null) {
			where.append(" AND t1.F_ALTA_48 = ?");
			params.add(maestrotipoalarma.getfAlta48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getUsuAlta48() != null) {
			where.append(" AND t1.USU_ALTA_48 = ?");
			params.add(maestrotipoalarma.getUsuAlta48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getfModif48() != null) {
			where.append(" AND t1.F_MODIF_48 = ?");
			params.add(maestrotipoalarma.getfModif48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getUsuModif48() != null) {
			where.append(" AND t1.USU_MODIF_48 = ?");
			params.add(maestrotipoalarma.getUsuModif48());
		}

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

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

		if (maestrotipoalarma != null && maestrotipoalarma.getIdTipoAlarma48() != null) {
			where.append(" AND t1.ID_TIPO_ALARMA_48 = ?");
			params.add(maestrotipoalarma.getIdTipoAlarma48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getDescEs48() != null) {
			where.append(" AND UPPER(t1.DESC_ES_48) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestrotipoalarma.getDescEs48().toUpperCase() + "%");
			} else {
				params.add("%" + maestrotipoalarma.getDescEs48().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_ES_48 IS NOT NULL");
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getDescEu48() != null) {
			where.append(" AND UPPER(t1.DESC_EU_48) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestrotipoalarma.getDescEu48().toUpperCase() + "%");
			} else {
				params.add("%" + maestrotipoalarma.getDescEu48().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_EU_48 IS NOT NULL");
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getfAlta48() != null) {
			where.append(" AND t1.F_ALTA_48 = ?");
			params.add(maestrotipoalarma.getfAlta48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getUsuAlta48() != null) {
			where.append(" AND UPPER(t1.USU_ALTA_48) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestrotipoalarma.getUsuAlta48().toUpperCase() + "%");
			} else {
				params.add("%" + maestrotipoalarma.getUsuAlta48().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_ALTA_48 IS NOT NULL");
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getfModif48() != null) {
			where.append(" AND t1.F_MODIF_48 = ?");
			params.add(maestrotipoalarma.getfModif48());
		}
		if (maestrotipoalarma != null && maestrotipoalarma.getUsuModif48() != null) {
			where.append(" AND UPPER(t1.USU_MODIF_48) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestrotipoalarma.getUsuModif48().toUpperCase() + "%");
			} else {
				params.add("%" + maestrotipoalarma.getUsuModif48().toUpperCase() + "%");
			}
			where.append(" AND t1.USU_MODIF_48 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;
}
