URLReportFacade.java :  » Google-tech » dexter » ejb » Java Open Source

Java Open Source » Google tech » dexter 
dexter » ejb » URLReportFacade.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ejb;

import entity.URL;
import entity.URLReport;
import entity.User;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author rahul
 */
@Stateless
public class URLReportFacade implements URLReportFacadeRemote {
    @PersistenceContext
    private EntityManager em;

    public void create(URLReport uRLReport) {
        em.persist(uRLReport);
    }

    public void edit(URLReport uRLReport) {
        em.merge(uRLReport);
    }

    public void remove(URLReport uRLReport) {
        em.remove(em.merge(uRLReport));
    }

    public URLReport find(Object id) {
        return em.find(URLReport.class, id);
    }

    public List<URLReport> findAll() {
        return em.createQuery("select object(o) from URL_REPORT_TABLE as o").getResultList();
    }
    public boolean ifURLReportedByUser(User user,URL url){
        if(em.createQuery("select u from URL_REPORT_TABLE u where REPORTED_BY=?1 AND REPORTED_URL_ID=?2").setParameter(1, user.getUserId()).setParameter(2, url.getId()).getResultList().isEmpty())
            return false;
        else
            return true;
        
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.