All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.yadaframework.security.persistence.repository.YadaTicketMessageDao Maven / Gradle / Ivy

The newest version!
package net.yadaframework.security.persistence.repository;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import net.yadaframework.security.persistence.entity.YadaTicket;
import net.yadaframework.security.persistence.entity.YadaTicketMessage;

@Repository
@Transactional(readOnly = true) 
public class YadaTicketMessageDao {
	
	@PersistenceContext
	EntityManager em;
	
	/**
	 * Find all YadaTicketMessage by one yadaTicket. Ordinato da dateSent descendente.
	 * @param yadaTicket
	 * @return
	 */
	public List findByYadaTicketOrderByCreatedDesc(YadaTicket yadaTicket) {
		String sql = "from YadaTicketMessage where yadaTicket=:yadaTicket order by created desc";
		return em.createQuery(sql, YadaTicketMessage.class)
			.setParameter("yadaTicket", yadaTicket)
			.getResultList();
}
	
	/**
	 * Find all YadaTicketMessage and Attachments by one yadaTicket. Order by modified ASC.
	 * @param yadaTicket
	 * @return
	 */
	public List findMessagesAndAttachmentByYadaTicketOrderByModifiedDesc(YadaTicket yadaTicket) {
		String sql = "select m from YadaTicket t join t.messages m left join fetch m.attachment a where t= :yadaTicket order by m.modified desc ";
		return em.createQuery(sql, YadaTicketMessage.class)
			.setParameter("yadaTicket", yadaTicket)
			.getResultList();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy