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:ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceTypeDomainService.java

public List<ResourceRelationTypeEntity> loadRelatedResourceTypeRelations(Integer resourceTypeId) {
    String sql = "select r from ResourceRelationTypeEntity r, ResourceTypeEntity t";
    sql += " where r.resourceTypeA.id = :resourceTypeId";
    sql += " and r.resourceTypeB.id = t.id";
    sql += " order by t.id";
    TypedQuery<ResourceRelationTypeEntity> query = entityManager.createQuery(sql,
            ResourceRelationTypeEntity.class);

    query.setParameter("resourceTypeId", resourceTypeId);
    return query.getResultList();

}

From source file:bq.jpa.demo.query.criteria.service.CriteriaService.java

/**
 * SELECT e FROM jpa_query_employee e WHERE e.name= :name
 *///from   www  . j a  v  a2  s.  c o m
@Transactional
public void doParameterQuery() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Employee> c = cb.createQuery(Employee.class);
    Root<Employee> e = c.from(Employee.class);

    // parameter, equal to ":name"
    ParameterExpression<String> paraName = cb.parameter(String.class, "name");

    // e.name = ":name"
    c.select(e).where(cb.equal(e.get("name"), paraName));

    // set param value
    TypedQuery<Employee> query = em.createQuery(c);
    query.setParameter("name", "employee_1");
    List<Employee> result = query.getResultList();
    ResultViewer.showResult(result, "criteria query : parameter query");
}

From source file:bzzAgent.BiteSizedBzzDaoJpa.java

@Override
public List<BiteSizedActivityEntity> search(BiteSizedActivitySearchParams params) {
    final LocalDate today = LocalDate.now();

    String activeQuery;// w  w  w.jav  a  2 s  .  c  o m
    if (params.isActive() != null) {
        if (params.isActive()) {
            activeQuery = "where bsae.endDate >= ? " + " or bsae.phaseInt < 6 "; //Launch(6, "General Launch")

        } else {
            activeQuery = "where bsae.endDate < ? " + " and bsae.phaseInt = 6 ";
        }
    } else {
        activeQuery = "";
    }

    String sql = "from BiteSizedActivityEntity bsae " + " left outer join fetch bsae.incentives incentive "
            + activeQuery + " order by bsae.startDate ASC";

    //sql += "order by ma.mam.id asc";
    TypedQuery<BiteSizedActivityEntity> query2 = em.createQuery(sql, BiteSizedActivityEntity.class)
            .setFirstResult(params.getOffset())
    //.setMaxResults(params.getLimit())
    ;
    if (params.isActive() != null) {
        query2.setParameter(1, today);
    }
    return query2.getResultList();
}

From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java

@Override
public List<OAuth2AccessTokenEntity> getAccessTokensForClient(ClientDetailsEntity client) {
    TypedQuery<OAuth2AccessTokenEntity> queryA = manager
            .createNamedQuery(OAuth2AccessTokenEntity.QUERY_BY_CLIENT, OAuth2AccessTokenEntity.class);
    queryA.setParameter(OAuth2AccessTokenEntity.PARAM_CLIENT, client);
    List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
    return accessTokens;
}

From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java

public List<VirtualMachine> findVirtualMachinesByDatacenter(final Integer datacenterId) {
    List<VirtualMachine> vmList = null;
    TypedQuery<VirtualMachine> query = getEntityManager().createNamedQuery("VIRTUAL_MACHINE.BY_DC",
            VirtualMachine.class);
    query.setParameter("datacenterId", datacenterId);
    vmList = query.getResultList();/*  w w  w .  j a  va 2  s.c o m*/

    return vmList;
}

From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java

public List<VirtualMachine> findByVirtualMachineTemplate(final Integer virtualMachineTemplateId) {
    List<VirtualMachine> vmList = null;
    TypedQuery<VirtualMachine> query = getEntityManager().createNamedQuery("VIRTUAL_MACHINE.BY_VMT",
            VirtualMachine.class);
    query.setParameter("virtualMachineTplId", virtualMachineTemplateId);
    vmList = query.getResultList();//www .j  a va 2 s  . co m

    return vmList;
}

From source file:net.nan21.dnet.core.business.service.entity.AbstractEntityReadService.java

/**
 * Find an entity of the specified class by its unique-key name.
 *//* w  w w . j a  v  a 2  s  . c o  m*/
public <T> T findByUk(String namedQueryName, Map<String, Object> params, Class<T> claz) {
    TypedQuery<T> q = this.getEntityManager().createNamedQuery(namedQueryName, claz);
    Set<String> keys = params.keySet();
    if (IModelWithClientId.class.isAssignableFrom(claz)) {
        q.setParameter("clientId", Session.user.get().getClient().getId());
    }
    for (String key : keys) {
        q.setParameter(key, params.get(key));
    }
    return (T) q.getSingleResult();
}

From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java

@Override
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken) {
    TypedQuery<OAuth2AccessTokenEntity> queryA = manager
            .createNamedQuery(OAuth2AccessTokenEntity.QUERY_BY_ID_TOKEN, OAuth2AccessTokenEntity.class);
    queryA.setParameter(OAuth2AccessTokenEntity.PARAM_ID_TOKEN, idToken);
    List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
    return JpaUtil.getSingleResult(accessTokens);
}

From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java

@Override
public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client) {
    TypedQuery<OAuth2RefreshTokenEntity> queryR = manager
            .createNamedQuery(OAuth2RefreshTokenEntity.QUERY_BY_CLIENT, OAuth2RefreshTokenEntity.class);
    queryR.setParameter(OAuth2RefreshTokenEntity.PARAM_CLIENT, client);
    List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
    return refreshTokens;
}

From source file:org.mitre.oauth2.repository.impl.JpaOAuth2TokenRepository.java

@Override
public Set<OAuth2AccessTokenEntity> getAccessTokensForResourceSet(ResourceSet rs) {
    TypedQuery<OAuth2AccessTokenEntity> query = manager
            .createNamedQuery(OAuth2AccessTokenEntity.QUERY_BY_RESOURCE_SET, OAuth2AccessTokenEntity.class);
    query.setParameter(OAuth2AccessTokenEntity.PARAM_RESOURCE_SET_ID, rs.getId());
    return new LinkedHashSet<>(query.getResultList());
}