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:net.triptech.metahive.model.Submission.java

/**
 * Count the submissions./*ww  w.  j a  va2s .c o  m*/
 *
 * @param filter the filter
 * @return the long
 */
public static long countSubmissions(final SubmissionFilter filter) {

    StringBuilder sql = new StringBuilder("SELECT COUNT(s) FROM Submission s");
    sql.append(buildWhere(filter));

    TypedQuery<Long> q = entityManager().createQuery(sql.toString(), Long.class);

    HashMap<String, Long> variables = buildVariables(filter);
    for (String variable : variables.keySet()) {
        q.setParameter(variable, variables.get(variable));
    }

    return q.getSingleResult();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findAllDedupConfigs() {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName = :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.getResultList();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findDedupConfigEntries(int firstResult, int maxResults) {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName = :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static long countDedupConfigs() {
    TypedQuery<Long> q = entityManager().createQuery(
            "SELECT COUNT(o) FROM Configuration AS o WHERE o.authorityFileName = :authorityFileName",
            Long.class);
    q.setParameter("authorityFileName", "");
    return q.getSingleResult();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findAllMatchConfigs() {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName != :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.getResultList();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static List<Configuration> findMatchConfigEntries(int firstResult, int maxResults) {
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.authorityFileName != :authorityFileName",
            Configuration.class);
    q.setParameter("authorityFileName", "");
    return q.setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static long countMatchConfigs() {
    TypedQuery<Long> q = entityManager().createQuery(
            "SELECT COUNT(o) FROM Configuration AS o WHERE o.authorityFileName != :authorityFileName",
            Long.class);
    q.setParameter("authorityFileName", "");
    return q.getSingleResult();
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static TypedQuery<Configuration> findDedupConfigsByNameEquals(String name) {
    if (name == null || name.length() == 0)
        throw new IllegalArgumentException("The name argument is required");
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.name = :name AND o.authorityFileName = :authorityFileName",
            Configuration.class);
    q.setParameter("name", name);
    q.setParameter("authorityFileName", "");
    return q;//from   www. ja va 2s.c om
}

From source file:org.kew.rmf.matchconf.Configuration.java

public static TypedQuery<Configuration> findMatchConfigsByNameEquals(String name) {
    if (name == null || name.length() == 0)
        throw new IllegalArgumentException("The name argument is required");
    EntityManager em = Configuration.entityManager();
    TypedQuery<Configuration> q = em.createQuery(
            "SELECT o FROM Configuration AS o WHERE o.name = :name AND o.authorityFileName != :authorityFileName",
            Configuration.class);
    q.setParameter("name", name);
    q.setParameter("authorityFileName", "");
    return q;//from www.  j  ava 2  s.  c  o  m
}

From source file:net.triptech.buildulator.model.Person.java

/**
 * Find a person by their email address. If none is found null is returned.
 *
 * @param emailAddress the email address
 * @return the person//w w w  .j av  a 2s .c om
 */
public static Person findByEmailAddress(final String emailAddress) {

    Person person = null;

    if (StringUtils.isBlank(emailAddress)) {
        throw new IllegalArgumentException("The email address argument is required");
    }

    TypedQuery<Person> q = entityManager().createQuery(
            "SELECT p FROM Person" + " AS p WHERE LOWER(p.emailAddress) = LOWER(:emailAddress)", Person.class);
    q.setParameter("emailAddress", emailAddress);

    List<Person> people = q.getResultList();

    if (people != null && people.size() > 0) {
        person = people.get(0);
    }
    return person;
}