Example usage for javax.persistence TypedQuery setParameter

List of usage examples for javax.persistence TypedQuery setParameter

Introduction

In this page you can find the example usage for javax.persistence TypedQuery setParameter.

Prototype

TypedQuery<X> setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

From source file:cz.muni.fi.anatomytutor.backend.dao.impl.AuthUserDaoImplJPA.java

@Override
public boolean isEmailAlreadyUsed(String email) {
    TypedQuery<Long> query;
    AuthUser returnedUser;/*from w  w w.  ja va  2  s  . co  m*/
    query = em.createQuery("SELECT COUNT(tbl.email) FROM AuthUser tbl " + " WHERE tbl.email = :uemail",
            Long.class);
    query.setParameter("uemail", email);
    Long result = query.getSingleResult();
    if (result == 0) {
        return false;
    } else if (result == 1) {
        return true;
    }
    throw new RuntimeException("There are more than one identical email in the database.");
}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllWinsForPlayerVersusPlayer(Player p, Player o) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllWinsForPlayerVersusPlayer", Long.class);
    query.setParameter("player", p);
    query.setParameter("opponent", o);
    return query.getSingleResult();
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.CheckDocumentRepositoryImplementation.java

@Override
public CheckDocument findByVacancy(Vacancy vacancy) {
    EntityManager em = entityManagerFactory.createEntityManager();

    CheckDocument checkDocument = null;//  w ww. j  a va 2s .  c om
    try {
        em.getTransaction().begin();

        TypedQuery<CheckDocument> query = em.createNamedQuery("CheckDocument.findByVacancy",
                CheckDocument.class);
        query.setParameter("vacancy", vacancy);
        checkDocument = query.getSingleResult();

        em.getTransaction().commit();
    } catch (RuntimeException e) {
        Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }

    return checkDocument;
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaAccountDao.java

private List<Account> getSearchResultList(String searchTerm, int count, int offset) {
    String qlString = "SELECT a FROM Account a WHERE a.accountPath like :q "
            + "OR a.owner.name like :q OR a.owner.email like :q";

    List<Account> accounts = null;
    try {/* ww  w .  j  av  a 2s.  c  o m*/
        TypedQuery<Account> query = em.createQuery(qlString, Account.class);
        query.setParameter("q", searchTerm);
        query.setMaxResults(count);
        query.setFirstResult(offset);

        accounts = query.getResultList();
    } catch (NoResultException e) {
        // Do nothing;
    }
    return accounts;

}

From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java

@Override
public long getCountAllLosesForPlayerVersusPlayer(Player p, Player o) {
    TypedQuery<Long> query = entityManager.createNamedQuery("countAllLosesForPlayerVersusPlayer", Long.class);
    query.setParameter("player", p);
    query.setParameter("opponent", o);
    return query.getSingleResult();
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.CheckDocumentRepositoryImplementation.java

@Override
public CheckDocument findByEmployee(Employee employee) {
    EntityManager em = entityManagerFactory.createEntityManager();

    CheckDocument checkDocument = null;/* w w w .  j  a v a2  s  . co m*/
    try {
        em.getTransaction().begin();

        TypedQuery<CheckDocument> query = em.createNamedQuery("CheckDocument.findByEmployee",
                CheckDocument.class);
        query.setParameter("employee", employee);
        checkDocument = query.getSingleResult();

        em.getTransaction().commit();
    } catch (RuntimeException e) {
        Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }

    return checkDocument;
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryMaintenanceImpl.java

protected void purgeDeletedCollections(EntityManager em, final Date nowDatePurge) {
    em.getTransaction().begin();/* w  w w  .  ja  v  a  2  s.co  m*/
    TypedQuery<VirtualCollection> q = em.createNamedQuery("VirtualCollection.findAllByState",
            VirtualCollection.class);
    q.setParameter("state", VirtualCollection.State.DELETED);
    q.setParameter("date", nowDatePurge);
    q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
    for (VirtualCollection vc : q.getResultList()) {
        vc.setState(VirtualCollection.State.DEAD);
        em.remove(vc);
        logger.debug("purged virtual collection (id={})", vc.getId());
    }
    em.getTransaction().commit();
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryMaintenanceImpl.java

protected void handleCollectionsInError(EntityManager em, final Date nowDateError) {
    em.getTransaction().begin();// w ww  . ja v  a  2s .c  o m
    TypedQuery<VirtualCollection> q = em.createNamedQuery("VirtualCollection.findAllByState",
            VirtualCollection.class);
    q.setParameter("state", VirtualCollection.State.ERROR);
    q.setParameter("date", nowDateError);
    q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
    for (VirtualCollection vc : q.getResultList()) {
        VirtualCollection.State currentState = vc.getState();
        logger.info("Found [{}] in error state.", vc.getName(), currentState);
        //TODO: handle virtual collections in error state
    }
    em.getTransaction().commit();
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.CheckDocumentRepositoryImplementation.java

@Override
public List<CheckDocument> findAllForEmployer(Employer employer) {
    EntityManager em = entityManagerFactory.createEntityManager();
    List<CheckDocument> list = new LinkedList<>();
    try {/*from  ww w.  j a v a  2s. c om*/
        em.getTransaction().begin();

        TypedQuery<CheckDocument> query = em.createNamedQuery("CheckDocument.findAllForEmployer",
                CheckDocument.class);
        query.setParameter("employer", employer);
        list = query.getResultList();

        em.getTransaction().commit();
    } catch (RuntimeException e) {
        Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }

    return list;
}

From source file:it.volaconnoi.bean.RouteManagerBean.java

@Override
public List<Route> getRoutesByInputParameters(String source, String destination, String date,
        String travel_class, String date_flexi) {
    TypedQuery<Route> query = em.createNamedQuery("Route.findByInputParameters", Route.class);

    List<Route> routes_list = query.setParameter("source", StringUtils.trim(WordUtils.capitalizeFully(source)))
            .setParameter("dest", StringUtils.trim(WordUtils.capitalizeFully(destination)))
            .setParameter("startDate",
                    utilBean.getFormattedDate(date, "00", "00", !StringUtils.isNotEmpty(date_flexi) ? 0 : +2),
                    TemporalType.TIMESTAMP)
            .setParameter("endDate",
                    utilBean.getFormattedDate(date, "23", "59", !StringUtils.isNotEmpty(date_flexi) ? 0 : +2),
                    TemporalType.TIMESTAMP)
            .setParameter("travel_class", travel_class).getResultList();

    //la flessibilit si intende due giorni avanti la data inserita dall'utente

    return routes_list;
}