package com.gpc.tams.repository.common; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** * */ @Repository public class StoreProfileDAO { private boolean refreshNeeded; private boolean refreshed; @PersistenceContext private EntityManager entityManager; @Transactional(propagation=Propagation.REQUIRED, readOnly=true) public StoreProfile find() { final Query selectQuery = entityManager.createNamedQuery("StoreProfile.selectAll"); if (refreshNeeded) { refreshNeeded = false; refreshed = true; entityManager.clear(); } return (StoreProfile) selectQuery.getSingleResult(); } public synchronized StoreProfile refreshStoreProfile() { this.refreshNeeded = true; return find(); } public synchronized boolean refreshed() { if (refreshed) { refreshed = false; return true; } return false; } }