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:eu.domibus.common.dao.ErrorLogDao.java

public List<ErrorLogEntry> getUnnotifiedErrorsForMessage(String messageId) {
    final TypedQuery<ErrorLogEntry> query = this.em
            .createNamedQuery("ErrorLogEntry.findUnnotifiedErrorsByMessageId", ErrorLogEntry.class);
    query.setParameter("MESSAGE_ID", messageId);
    return query.getResultList();
}

From source file:org.openmeetings.app.data.calendar.daos.AppointmentReminderTypDaoImpl.java

public List<AppointmentReminderTyps> getAppointmentReminderTypList() {
    log.debug("getAppointmenetReminderTypList");

    try {//from   w ww.  j  av  a  2s  .c  o m

        String hql = "select a from AppointmentReminderTyps a " + "WHERE a.deleted <> :deleted ";

        TypedQuery<AppointmentReminderTyps> query = em.createQuery(hql, AppointmentReminderTyps.class);
        query.setParameter("deleted", "true");

        List<AppointmentReminderTyps> listAppointmentReminderTyp = query.getResultList();

        return listAppointmentReminderTyp;
    } catch (Exception ex2) {
        log.error("[getAppointmentReminderTypList]: " + ex2);
    }
    return null;
}

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

@Override
public List<BasicSkill> getSkillsNotInEmployee(Employee employee) {
    EntityManager em = entityManagerFactory.createEntityManager();
    List<BasicSkill> list = new LinkedList<>();
    try {//w  ww . j a  v  a 2s .c  o  m
        em.getTransaction().begin();

        TypedQuery<BasicSkill> query = em.createNamedQuery("BasicSkill.findSkillsNotInEmployee",
                BasicSkill.class);
        query.setParameter("employee", employee);
        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:org.openmeetings.app.data.calendar.daos.AppointmentReminderTypDaoImpl.java

public AppointmentReminderTyps getAppointmentReminderTypById(Long typId) {
    try {//from w  w  w.ja v a  2 s  .c  o m
        log.debug("AppointmentReminderTypById: " + typId);

        String hql = "select app from AppointmentReminderTyps app " + "WHERE app.deleted <> :deleted "
                + "AND app.typId = :typId";

        TypedQuery<AppointmentReminderTyps> query = em.createQuery(hql, AppointmentReminderTyps.class);
        query.setParameter("deleted", "true");
        query.setParameter("typId", typId);

        AppointmentReminderTyps appointmentReminderTyps = null;
        try {
            appointmentReminderTyps = query.getSingleResult();
        } catch (NoResultException ex) {
        }

        return appointmentReminderTyps;
    } catch (Exception ex2) {
        log.error("[getAppointmentReminderTypsById]: " + ex2);
    }
    return null;
}

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

/**
 *
 * @param name//w  ww  . j  a va2  s .  co m
 * @param password
 * @return
 */
@Override
public User getByNameAndPassword(String name, String password) {
    EntityManager em = entityManagerFactory.createEntityManager();
    User user = null;
    boolean exists = false;

    try {
        em.getTransaction().begin();

        TypedQuery<User> query = em.createNamedQuery("User.findByUserLoginAndPassword", User.class);
        query.setParameter("login", name);
        query.setParameter("password", encryptionService.encrypt(password));

        user = query.getSingleResult();

        em.getTransaction().commit();
        exists = true;
    } catch (NoResultException ex) {
        Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(ex);
        exists = false;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }

    if (exists) {
        return user;
    } else {
        return null;
    }

}

From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.DocumentSetCoverController.java

/**
 * Gets the size of a set cover (number of covered documents).
 * @param em the {@link EntityManager} to use.
 * @param setCover the {@link DocumentSetCover} whose size is required.
 * @return the {@link Long} count of documents.
 */// w w w.  j  ava2  s  .c  o m
public long getCoverSize(EntityManager em, DocumentSetCover setCover) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");
    Validate.notNull(setCover, CannedMessages.NULL_ARGUMENT, "setCover");

    TypedQuery<byte[]> query = em.createQuery(
            "SELECT scd.id FROM SetCoverDocument scd " + "WHERE scd.store=:sc " + "AND scd.flag=true",
            byte[].class);
    query.setParameter("sc", setCover);

    return query.getResultList().size();
}

From source file:com.siriusit.spezg.multilib.storage.jpa.JpaUnitRepository.java

@Override
public BinaryAttachment findAttachmentByType(String unitId, String attachmentType) {
    TypedQuery<BinaryAttachmentDomainObject> query = entityManager
            .createNamedQuery("findAttachmentByUnitAndType", BinaryAttachmentDomainObject.class);
    query.setParameter("unitId", Integer.parseInt(unitId));
    query.setParameter("type", attachmentType);
    List<BinaryAttachmentDomainObject> resultList = query.getResultList();
    if (resultList.size() == 1)
        return resultList.get(0);
    return null;/*w w w .  j  a  va  2  s  . com*/
}

From source file:csns.model.survey.dao.jpa.SurveyDaoImpl.java

@Override
@PreAuthorize("principal.isFaculty(#department.abbreviation)")
public List<Survey> searchSurveys(Department department, String term, int maxResults) {
    TypedQuery<Survey> query = entityManager.createNamedQuery("survey.search", Survey.class);
    if (maxResults > 0)
        query.setMaxResults(maxResults);
    return query.setParameter("departmentId", department.getId()).setParameter("term", term).getResultList();
}

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

@Override
public List<Match> getAllWinsForPlayer(Player p) {
    TypedQuery<Match> query = entityManager.createNamedQuery("allWinsForPlayer", Match.class);
    query.setParameter("player", p);
    return query.getResultList();
}

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

@Override
public List<Match> getAllLosesForPlayer(Player p) {
    TypedQuery<Match> query = entityManager.createNamedQuery("allLosesForPlayer", Match.class);
    query.setParameter("player", p);
    return query.getResultList();
}