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

/**
 * TerminalesDaoImpl generated by UDA, 21-mar-2023 11:41:04.
 * 
 * @author UDA
 */

@Repository
@Transactional
public class TerminalesDaoImpl implements TerminalesDao {

	public static final String[] ORDER_BY_WHITE_LIST = new String[] { "IDTERMINAL34", "DESCES34", "DESCEU34",
			"DIGITAL34", "FALTA34", "USUALTA34" };

	private JdbcTemplate jdbcTemplate;

	public static final String SEQUENCE_TERMINALES = "SEQ_TERMINALES";

	/*
	 * ROW_MAPPERS
	 */
	private RowMapper<Terminales> rwMap = new RowMapper<Terminales>() {
		public Terminales mapRow(ResultSet resultSet, int rowNum) throws SQLException {
			return new Terminales(UtilSQL.getLong(resultSet, "IDTERMINAL34"), resultSet.getString("DESCES34"),
					resultSet.getString("DESCEU34"), UtilSQL.getInt(resultSet, "DIGITAL34"),
					resultSet.getString("USUALTA34"), resultSet.getDate("FALTA34"));
		}
	};

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

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

			Terminales terminales = new Terminales(UtilSQL.getLong(resultSet, "IDTERMINAL34"),
					resultSet.getString("DESCES34"), resultSet.getString("DESCEU34"),
					UtilSQL.getInt(resultSet, "DIGITAL34"), resultSet.getString("USUALTA34"),
					resultSet.getDate("FALTA34"));

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

		GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();

		String query = "INSERT INTO TERMINALES (ID_TERMINAL_34, DESC_ES_34, DESC_EU_34, DIGITAL_34, USU_ALTA_34, F_ALTA_34) "
				+ "VALUES (" + SEQUENCE_TERMINALES + ".NEXTVAL,:descEs,:descEu,:digital,:usuAlta,sysdate)";

		MapSqlParameterSource parameters = new MapSqlParameterSource().addValue("descEs", terminales.getDescEs34())
				.addValue("descEu", terminales.getDescEu34()).addValue("digital", terminales.getDigital34())
				.addValue("usuAlta", terminales.getUsuAlta34());

		NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
		namedParameterJdbcTemplate.update(query, parameters, generatedKeyHolder, new String[] { "ID_TERMINAL_34" });
		terminales.setIdTerminal34(generatedKeyHolder.getKey().longValue());

		return terminales;
	}

	/**
	 * Updates a single row in the Terminales table.
	 *
	 * @param terminales Terminales
	 * @return Terminales
	 */
	public Terminales update(Terminales terminales) {
		String query = "UPDATE TERMINALES SET DESC_ES_34=?, DESC_EU_34=?, DIGITAL_34=?, USU_ALTA_34 = ?, F_ALTA_34 = ? WHERE ID_TERMINAL_34=?";
		this.jdbcTemplate.update(query, terminales.getDescEs34(), terminales.getDescEu34(), terminales.getDigital34(),
				terminales.getIdTerminal34(), terminales.getUsuAlta34(), terminales.getfAlta34());
		return terminales;
	}

	/**
	 * Finds a single row in the Terminales table.
	 *
	 * @param terminales Terminales
	 * @return Terminales
	 */
	@Transactional(readOnly = true)
	public Terminales find(Terminales terminales) {
		String query = "SELECT t1.ID_TERMINAL_34 IDTERMINAL34, t1.DESC_ES_34 DESCES34, t1.DESC_EU_34 DESCEU34, t1.DIGITAL_34 DIGITAL34,  t1.USU_ALTA_34 USUALTA34, t1.F_ALTA_34 FALTA34 FROM TERMINALES t1  WHERE t1.ID_TERMINAL_34 = ?  ";

		List<Terminales> terminalesList = this.jdbcTemplate.query(query, this.rwMap, terminales.getIdTerminal34());
		return (Terminales) DataAccessUtils.uniqueResult(terminalesList);
	}

	/**
	 * Removes a single row in the Terminales table.
	 *
	 * @param terminales Terminales
	 * @return
	 */
	public void remove(Terminales terminales) {
		String query = "DELETE FROM TERMINALES WHERE ID_TERMINAL_34=?";
		this.jdbcTemplate.update(query, terminales.getIdTerminal34());
	}

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

		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TERMINAL_34 IDTERMINAL34, t1.DESC_ES_34 DESCES34, t1.DESC_EU_34 DESCEU34, t1.DIGITAL_34 DIGITAL34, t1.USU_ALTA_34 USUALTA34, t1.F_ALTA_34 FALTA34 ");
		query.append(" FROM TERMINALES t1  ");
		// Where clause & Params
		Map<String, Object> mapaWhere = this.getWhereLikeMap(filterTerminales, 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, Terminales.class, params,
				"ID_TERMINAL_34");
		where.append(sbMultipleSQL);

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

	/**
	 * Finds a list of rows in the Terminales table.
	 *
	 * @param terminales      Terminales
	 * @param tableRequestDto TableRequestDto
	 * @return List<Terminales>
	 */
	@Transactional(readOnly = true)
	public List<Terminales> findAll(Terminales terminales, TableRequestDto tableRequestDto) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TERMINAL_34 IDTERMINAL34,t1.DESC_ES_34 DESCES34,t1.DESC_EU_34 DESCEU34,t1.DIGITAL_34 DIGITAL34, t1.USU_ALTA_34 USUALTA34, t1.F_ALTA_34 FALTA34 ");
		query.append("FROM TERMINALES t1 ");

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

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

	/**
	 * Finds rows in the Terminales table using like.
	 *
	 * @param terminales      Terminales
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<Terminales>
	 */
	@Transactional(readOnly = true)
	public List<Terminales> findAllLike(Terminales terminales, TableRequestDto tableRequestDto, Boolean startsWith) {
		StringBuilder query = new StringBuilder(
				"SELECT  t1.ID_TERMINAL_34 IDTERMINAL34,t1.DESC_ES_34 DESCES34,t1.DESC_EU_34 DESCEU34,t1.DIGITAL_34 DIGITAL34,t1.USU_ALTA_34 USUALTA34, t1.F_ALTA_34 FALTA34 ");
		query.append("FROM TERMINALES t1 ");

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

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

	/*
	 * OPERACIONES RUP_TABLE
	 */

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

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

		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(terminales, 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 Terminales selected for rup_table
	 *
	 * @param terminales      Terminales
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<Terminales>>
	 */
	@Override
	public List<TableRowDto<Terminales>> reorderSelection(Terminales terminales, TableRequestDto tableRequestDto,
			Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TERMINAL_34 IDTERMINAL34,t1.DESC_ES_34 DESCES34,t1.DESC_EU_34 DESCEU34,t1.DIGITAL_34 DIGITAL34,t1.USU_ALTA_34 USUALTA34, t1.F_ALTA_34 FALTA34 ");
		// FROM
		query.append("FROM TERMINALES t1 ");
		// FILTRADO
		// Where clause & Params
		Map<String, ?> mapaWhere = this.getWhereLikeMap(terminales, 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, Terminales.class,
				filterParamList, "IDTERMINAL34");

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

	/**
	 * Search method for rup_table
	 *
	 * @param filterParams    Terminales
	 * @param searchParams    Terminales
	 * @param tableRequestDto TableRequestDto
	 * @param startsWith      Boolean
	 * @return List<TableRowDto<Terminales>>
	 */
	@Override
	public List<TableRowDto<Terminales>> search(Terminales filterParams, Terminales searchParams,
			TableRequestDto tableRequestDto, Boolean startsWith) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TERMINAL_34 IDTERMINAL34,t1.DESC_ES_34 DESCES34,t1.DESC_EU_34 DESCEU34,t1.DIGITAL_34 DIGITAL34,t1.USU_ALTA_34 USUALTA34, t1.F_ALTA_34 FALTA34 ");
		// FROM
		query.append("FROM TERMINALES 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, Terminales.class,
				filterParamList, searchSQL, searchParamList, from_alias, "IDTERMINAL34");

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

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

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

	/**
	 * Filter in the hierarchical Terminales table.
	 *
	 * @param filterTerminales Terminales
	 * @param tableRequestDto  TableRequestDto
	 * @return List<JerarquiaDto<Terminales>>
	 */
	@Override
	public List<JerarquiaDto<Terminales>> findAllLikeJerarquia(Terminales filterTerminales,
			TableRequestDto tableRequestDto) {
		// SELECT
		StringBuilder query = new StringBuilder(
				"SELECT t1.ID_TERMINAL_34 IDTERMINAL34,t1.DESC_ES_34 DESCES34,t1.DESC_EU_34 DESCEU34,t1.DIGITAL_34 DIGITAL34,t1.USU_ALTA_34 USUALTA34, t1.F_ALTA_34 FALTA34 ");
		// FROM
		// StringBuilder from = new StringBuilder("FROM TERMINALES t1 ");
		List<String> from = new ArrayList<String>();
		from.add("TERMINALES");
		// 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(filterTerminales, false);

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

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

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

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

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

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

	/*
	 * MÉTODOS PRIVADOS
	 */

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

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

		if (terminales != null && terminales.getIdTerminal34() != null) {
			where.append(" AND t1.ID_TERMINAL_34 = ?");
			params.add(terminales.getIdTerminal34());
		}
		if (terminales != null && terminales.getDescEs34() != null) {
			where.append(" AND t1.DESC_ES_34 = ?");
			params.add(terminales.getDescEs34());
		}
		if (terminales != null && terminales.getDescEu34() != null) {
			where.append(" AND t1.DESC_EU_34 = ?");
			params.add(terminales.getDescEu34());
		}
		if (terminales != null && terminales.getDigital34() != null) {
			where.append(" AND t1.DIGITAL_34 = ?");
			params.add(terminales.getDigital34());
		}
		if (terminales != null && terminales.getUsuAlta34() != null) {
			where.append(" AND t1.USU_ALTA_34 = ?");
			params.add(terminales.getUsuAlta34());
		}
		if (terminales != null && terminales.getfAlta34() != null) {
			where.append(" AND t1.F_ALTA_34 = ?");
			params.add(terminales.getfAlta34());
		}

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

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

		if (terminales != null && terminales.getIdTerminal34() != null) {
			where.append(" AND t1.ID_TERMINAL_34 = ?");
			params.add(terminales.getIdTerminal34());
		}
		if (terminales != null && terminales.getDescEs34() != null) {
			where.append(" AND UPPER(t1.DESC_ES_34) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(terminales.getDescEs34().toUpperCase() + "%");
			} else {
				params.add("%" + terminales.getDescEs34().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_ES_34 IS NOT NULL");
		}
		if (terminales != null && terminales.getDescEu34() != null) {
			where.append(" AND UPPER(t1.DESC_EU_34) like ? ESCAPE  '\\'");
			if (startsWith) {
				params.add(terminales.getDescEu34().toUpperCase() + "%");
			} else {
				params.add("%" + terminales.getDescEu34().toUpperCase() + "%");
			}
			where.append(" AND t1.DESC_EU_34 IS NOT NULL");
		}
		if (terminales != null && terminales.getDigital34() != null) {
			where.append(" AND t1.DIGITAL_34 = ?");
			params.add(terminales.getDigital34());
		}

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

		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;
}
