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

/**
 * MaestroTramitesDaoImpl generated by UDA, 22-mar-2023 17:10:15.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class MaestroTramitesDaoImpl implements MaestroTramitesDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDTRAMITE37", "DESCES37", "DESCEU37" };

	private JdbcTemplate jdbcTemplate;

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<MaestroTramites> rwMap = new RowMapper<MaestroTramites>() {
		public MaestroTramites mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new MaestroTramites(UtilSQL.getLong(resultSet, "IDTRAMITE37"), resultSet.getString("DESCES37"),
					resultSet.getString("DESCEU37"));
		}
	};

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

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

			MaestroTramites maestrotramites = new MaestroTramites(UtilSQL.getLong(resultSet, "IDTRAMITE37"),
					resultSet.getString("DESCES37"), resultSet.getString("DESCEU37"));

			JerarquiaDto<MaestroTramites> jerarquia = new JerarquiaDto<MaestroTramites>();
			jerarquia.setModel(maestrotramites);
			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 MaestroTramites table.
	 *
	 * @param maestrotramites MaestroTramites
	 * @return MaestroTramites
	 */
	public MaestroTramites add(MaestroTramites maestrotramites) {
		String query = "INSERT INTO MAESTRO_TRAMITES (ID_TRAMITE_37, DESC_ES_37, DESC_EU_37) VALUES (?,?,?)";
		this.jdbcTemplate.update(query, maestrotramites.getIdTramite37(), maestrotramites.getDescEs37(),
				maestrotramites.getDescEu37());
		return maestrotramites;
	}

	/**
	 * Updates a single row in the MaestroTramites table.
	 *
	 * @param maestrotramites MaestroTramites
	 * @return MaestroTramites
	 */
	public MaestroTramites update(MaestroTramites maestrotramites) {
		String query = "UPDATE MAESTRO_TRAMITES SET DESC_ES_37=?, DESC_EU_37=? WHERE ID_TRAMITE_37=?";
		this.jdbcTemplate.update(query, maestrotramites.getDescEs37(), maestrotramites.getDescEu37(),
				maestrotramites.getIdTramite37());
		return maestrotramites;
	}

	/**
	 * Finds a single row in the MaestroTramites table.
	 *
	 * @param maestrotramites MaestroTramites
	 * @return MaestroTramites
	 */
	@Transactional(readOnly = true)
	public MaestroTramites find(MaestroTramites maestrotramites) {
		String query = "SELECT t1.ID_TRAMITE_37 IDTRAMITE37, t1.DESC_ES_37 DESCES37, t1.DESC_EU_37 DESCEU37 FROM MAESTRO_TRAMITES t1  WHERE t1.ID_TRAMITE_37 = ?  ";

		List<MaestroTramites> maestrotramitesList = this.jdbcTemplate.query(query, this.rwMap,
				maestrotramites.getIdTramite37());
		return (MaestroTramites) DataAccessUtils.uniqueResult(maestrotramitesList);
	}

	/**
	 * Removes a single row in the MaestroTramites table.
	 *
	 * @param maestrotramites MaestroTramites
	 * @return
	 */
	public void remove(MaestroTramites maestrotramites) {
		String query = "DELETE FROM MAESTRO_TRAMITES WHERE ID_TRAMITE_37=?";
		this.jdbcTemplate.update(query, maestrotramites.getIdTramite37());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_37 IDTRAMITE37, t1.DESC_ES_37 DESCES37, t1.DESC_EU_37 DESCEU37");
		query.append(" FROM MAESTRO_TRAMITES t1  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterMaestroTramites, 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, MaestroTramites.class,
				params, "ID_TRAMITE_37");
		where.append(sbMultipleSQL);

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

	/**
	 * Finds a list of rows in the MaestroTramites table.
	 *
	 * @param maestrotramites MaestroTramites
	 * @param tableRequestDto TableRequestDto
	 * @return List<MaestroTramites>
	 */
	@Transactional(readOnly = true)
	public List<MaestroTramites> findAll(MaestroTramites maestrotramites, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TRAMITE_37 IDTRAMITE37,t1.DESC_ES_37 DESCES37,t1.DESC_EU_37 DESCEU37 ");
		query.append("FROM MAESTRO_TRAMITES t1 ");

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

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

	/**
	 * Finds rows in the MaestroTramites table using like.
	 *
	 * @param maestrotramites MaestroTramites
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<MaestroTramites>
	 */
	@Transactional(readOnly = true)
	public List<MaestroTramites> findAllLike(MaestroTramites maestrotramites, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TRAMITE_37 IDTRAMITE37,t1.DESC_ES_37 DESCES37,t1.DESC_EU_37 DESCEU37 ");
		query.append("FROM MAESTRO_TRAMITES t1 ");

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestrotramites, 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 MaestroTramites selected for rup_table
	 *
	 * @param maestrotramites MaestroTramites
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroTramites>>
	 */
	@Override
	public List<TableRowDto<MaestroTramites>> reorderSelection(MaestroTramites maestrotramites,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_37 IDTRAMITE37,t1.DESC_ES_37 DESCES37,t1.DESC_EU_37 DESCEU37 ");
		// FROM
		query.append("FROM MAESTRO_TRAMITES t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(maestrotramites, 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,
				MaestroTramites.class, filterParamList, "IDTRAMITE37");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    MaestroTramites
	 * @param searchParams    MaestroTramites
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<MaestroTramites>>
	 */
	@Override
	public List<TableRowDto<MaestroTramites>> search(MaestroTramites filterParams, MaestroTramites searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_37 IDTRAMITE37,t1.DESC_ES_37 DESCES37,t1.DESC_EU_37 DESCEU37 ");
		// FROM
		query.append("FROM MAESTRO_TRAMITES 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, MaestroTramites.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDTRAMITE37");

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

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

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

	/**
	 * Filter in the hierarchical MaestroTramites table.
	 *
	 * @param filterMaestroTramites MaestroTramites
	 * @param tableRequestDto       TableRequestDto
	 * @return List<JerarquiaDto<MaestroTramites>>
	 */
	@Override
	public List<JerarquiaDto<MaestroTramites>> findAllLikeJerarquia(MaestroTramites filterMaestroTramites,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TRAMITE_37 IDTRAMITE37,t1.DESC_ES_37 DESCES37,t1.DESC_EU_37 DESCEU37 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM MAESTRO_TRAMITES t1 ");
		List<String> from = new ArrayList<String>();
		from.add("MAESTRO_TRAMITES");
		// 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(filterMaestroTramites, false);

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

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

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

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

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

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

	/*
	 * MÉTODOS PRIVADOS
	 */

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

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

		if (maestrotramites != null && maestrotramites.getIdTramite37() != null) {
			where.append(" AND t1.ID_TRAMITE_37 = ?");
			params.add(maestrotramites.getIdTramite37());
		}
		if (maestrotramites != null && maestrotramites.getDescEs37() != null) {
			where.append(" AND t1.DESC_ES_37 = ?");
			params.add(maestrotramites.getDescEs37());
		}
		if (maestrotramites != null && maestrotramites.getDescEu37() != null) {
			where.append(" AND t1.DESC_EU_37 = ?");
			params.add(maestrotramites.getDescEu37());
		}

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

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

		if (maestrotramites != null && maestrotramites.getIdTramite37() != null) {
			where.append(" AND t1.ID_TRAMITE_37 = ?");
			params.add(maestrotramites.getIdTramite37());
		}
		if (maestrotramites != null && maestrotramites.getDescEs37() != null) {
			where.append(" AND UPPER(t1.DESC_ES_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestrotramites.getDescEs37().toUpperCase() + "%");
			} else {
				params.add("%" + maestrotramites.getDescEs37().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_ES_37 IS NOT NULL");
		}
		if (maestrotramites != null && maestrotramites.getDescEu37() != null) {
			where.append(" AND UPPER(t1.DESC_EU_37) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(maestrotramites.getDescEu37().toUpperCase() + "%");
			} else {
				params.add("%" + maestrotramites.getDescEu37().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_EU_37 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;
}
