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

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

There is a newer version: 0.7.7.R4
Show newest version
package net.yadaframework.security.persistence.repository;

import java.util.Date;
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.core.YadaRegistrationType;
import net.yadaframework.security.persistence.entity.YadaRegistrationRequest;

@Repository
@Transactional(readOnly = true) 
public class YadaRegistrationRequestDao {
	
	@PersistenceContext EntityManager em;

	public  List findByIdAndTokenOrderByTimestampDesc(long id, long token, Class type) {
		String sql = "from " + type.getSimpleName() + " where id=:id and token=:token order by timestamp desc";
		return em.createQuery(sql, type)
			.setParameter("id", id)
			.setParameter("token", token)
			.getResultList();
	}

	public  List findByEmailAndRegistrationType(String email, YadaRegistrationType registrationType, Class type) {
		String sql = "from " + type.getSimpleName() + " where email=:email and registrationType=:registrationType";
		return em.createQuery(sql, type)
			.setParameter("email", email)
			.setParameter("registrationType", registrationType)
			.getResultList();
	}

	/**
	 * Trova tutti gli elementi con timestamp antecedente la data indicata
	 * @param upperLimit
	 * @return
	 */
	public List findByTimestampBefore(Date upperLimit) {
		String sql = "from YadaRegistrationRequest where timestamp < :upperLimit";
		return em.createQuery(sql, YadaRegistrationRequest.class)
			.setParameter("upperLimit", upperLimit)
			.getResultList();
	}

	@Transactional(readOnly = false)
	public void delete(YadaRegistrationRequest registrationRequest) {
		registrationRequest = em.merge(registrationRequest);
		em.remove(registrationRequest);
	}

	@Transactional(readOnly = false)
	public YadaRegistrationRequest save(YadaRegistrationRequest entity) {
		if (entity==null) {
			return null;
		}
		if (entity.getId()==null) {
			em.persist(entity);
			return entity;
		}
		return em.merge(entity);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy