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

net.yadaframework.security.persistence.repository.YadaSocialCredentialsDao 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.YadaSocialCredentials;
import net.yadaframework.security.persistence.entity.YadaUserCredentials;

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

	public List findBySocialIdAndType(String socialId, int type) {
		String sql = "from YadaSocialCredentials where socialId=:socialId and type=:type";
		return em.createQuery(sql, YadaSocialCredentials.class)
			.setParameter("socialId", socialId)
			.setParameter("type", type)
			.getResultList();
	}

	public List findByYadaUserCredentialsAndType(YadaUserCredentials yadaUserCredentials, int type) {
		String sql = "from YadaSocialCredentials where yadaUserCredentials=:yadaUserCredentials and type=:type";
		return em.createQuery(sql, YadaSocialCredentials.class)
				.setParameter("yadaUserCredentials", yadaUserCredentials)
				.setParameter("type", type)
				.getResultList();	
	}

    @Transactional(readOnly = false)
	public void deleteByYadaUserCredentialsAndType(YadaUserCredentials userCredentials, int facebookType) {
		String sql = "delete from YadaSocialCredentials e where e.yadaUserCredentials = :userCredentials and e.type = :facebookType";
		em.createQuery(sql)
			.setParameter("userCredentials", userCredentials)
			.setParameter("facebookType", facebookType)
			.executeUpdate();
	}

	@Transactional(readOnly = false)
	public YadaSocialCredentials save(YadaSocialCredentials 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