package com.ejie.ab39a.service;
import com.ejie.ab39a.dao.ElementosPeDao;
import com.ejie.x38.dto.JQGridRequestDto;
import com.ejie.x38.dto.JQGridResponseDto;
import com.ejie.x38.dto.TableRowDto;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ab39a.model.ElementosPe;

/**
 * ElementosPe.
 *  
 */
@Service(value = "elementosPeService")
public class ElementosPeServiceImpl implements ElementosPeService {

	@Autowired
	private ElementosPeDao elementosPeDao;

	/**
	 * Inserts a single row in the ElementosPe table.
	 *
	 * @param elementosPe ElementosPe
	 * @return ElementosPe
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public ElementosPe add(ElementosPe elementosPe) {
		return this.elementosPeDao.add(elementosPe);
	}

	/**
	 * Updates a single row in the ElementosPe table.
	 *
	 * @param elementosPe ElementosPe
	 * @return ElementosPe
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public ElementosPe update(ElementosPe elementosPe) {
		return this.elementosPeDao.update(elementosPe);
	 }

	/**
	 * Finds a single row in the ElementosPe table.
	 *
	 * @param elementosPe ElementosPe
	 * @return ElementosPe
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public ElementosPe find(ElementosPe elementosPe) {
		return this.elementosPeDao.find(elementosPe);
	}
	
	/**
	 * Deletes a single row in the ElementosPe table.
	 *
	 * @param elementosPe ElementosPe
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void remove(ElementosPe elementosPe) {
		this.elementosPeDao.remove(elementosPe);
	}

	/**
	 * Finds a list of rows in the ElementosPe table.
	 *
	 * @param elementosPe ElementosPe
	 * @param jqGridRequestDto JQGridRequestDto
	 * @return List<ElementosPe>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public List<ElementosPe> findAll(ElementosPe elementosPe, JQGridRequestDto jqGridRequestDto){
		return this.elementosPeDao.findAll(elementosPe, jqGridRequestDto);
	}
    
	/**
	 * Finds rows in the ElementosPe table using like.
	 *
	 * @param elementosPe ElementosPe
	 * @param jqGridRequestDto JQGridRequestDto
     * @param startsWith Boolean	 
	 * @return List<ElementosPe>
	 */
	@Override
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED) 
	public List<ElementosPe> findAllLike(ElementosPe elementosPe, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.elementosPeDao.findAllLike(elementosPe, jqGridRequestDto, startsWith);
	}

	/*
	 * OPERACIONES RUP_TABLE
	 */
	 
	/**
	 * Removes rows from the ElementosPe table.
	 *
	 * @param filterElementosPe ElementosPe
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 */	
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class)
	public void removeMultiple(ElementosPe filterElementosPe, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		this.elementosPeDao.removeMultiple(filterElementosPe, jqGridRequestDto, startsWith);
	}
        
	/**
	 * Filter method in the ElementosPe table.
	 *
	 * @param filterElementosPe ElementosPe
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return JQGridResponseDto<ElementosPe>
	 */
	@Override	
	@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
	public JQGridResponseDto< ElementosPe> filter(ElementosPe filterElementosPe, JQGridRequestDto jqGridRequestDto,  Boolean startsWith){
		List<ElementosPe> listaElementosPe =  this.elementosPeDao.findAllLike(filterElementosPe, jqGridRequestDto, false);
		Long recordNum =  this.elementosPeDao.findAllLikeCount(filterElementosPe != null ? filterElementosPe: new ElementosPe (),false);
		if (jqGridRequestDto.getMultiselection().getSelectedIds()!=null){
			List< TableRowDto< ElementosPe>> reorderSelection = this.elementosPeDao.reorderSelection(filterElementosPe, jqGridRequestDto, startsWith);
			return new JQGridResponseDto<ElementosPe>(jqGridRequestDto, recordNum, listaElementosPe, reorderSelection);
		}
		return new JQGridResponseDto<ElementosPe>(jqGridRequestDto, recordNum, listaElementosPe);   
	}
    
    /**
	 * Reorder the selection made in ElementosPe table.
	 *
	 * @param filterElementosPe ElementosPe
	 * @param jqGridRequestDto JQGridRequestDto
	 * @param startsWith Boolean
	 * @return Object
	 */	
	@Override
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED)
    public Object reorderSelection(ElementosPe filterElementosPe, JQGridRequestDto jqGridRequestDto, Boolean startsWith){
		return this.elementosPeDao.reorderSelection(filterElementosPe, jqGridRequestDto, startsWith);
	}
    	
}
