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:org.openmeetings.app.data.conference.PollManagement.java

public PollType getPollType(Long typeId) {
    TypedQuery<PollType> q = em.createQuery("SELECT pt FROM PollType pt WHERE pt.pollTypesId = :pollTypesId",
            PollType.class);
    q.setParameter("pollTypesId", typeId);
    return q.getSingleResult();
}

From source file:eu.domibus.common.dao.MessageLogDao.java

public List<String> getUndownloadedUserMessagesOlderThan(Date date, String mpc) {
    final TypedQuery<String> query = em
            .createNamedQuery("MessageLogEntry.findUndownloadedUserMessagesOlderThan", String.class);
    query.setParameter("DATE", date);
    query.setParameter("MPC", mpc);
    try {//from   w  w w .  j  a  va2 s.  c  o m
        return query.getResultList();
    } catch (NoResultException e) {
        return Collections.EMPTY_LIST;
    }
}

From source file:org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl.java

public List<LdapConfig> getActiveLdapConfigs() {
    try {// www  .j  a v  a2s .c o  m
        log.debug("selectMaxFromConfigurations ");

        String hql = "select c from LdapConfig c " + "where c.deleted LIKE 'false' "
                + "AND c.isActive = :isActive ";

        //get all users
        TypedQuery<LdapConfig> query = em.createQuery(hql, LdapConfig.class);
        query.setParameter("isActive", true);
        List<LdapConfig> ll = query.getResultList();

        return ll;
    } catch (Exception ex2) {
        log.error("[getActiveLdapConfigs] ", ex2);
    }
    return null;
}

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

/**
 * Gets all UUIDs for {@code T} type lexica owned by the given owner.
 * @param em the {@link EntityManager} to use.
 * @param ownerId the ID of the owner./*from   w w  w . j  a  v a  2  s  . c o  m*/
 * @param entityClass the specific type of lexica to be retrieved; must be annotated with the {@link Entity} annotation.
 * @return a {@link List} containing {@link String} representations of the UUIDs.
 */
public <T extends Lexicon> List<String> getAllLexica(EntityManager em, String ownerId, Class<T> entityClass) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");
    Validate.notNull(ownerId, CannedMessages.NULL_ARGUMENT, "ownerId");
    Validate.notNull(entityClass, CannedMessages.NULL_ARGUMENT, "entityClass");

    TypedQuery<byte[]> query = em.createQuery("SELECT lex.id FROM Lexicon lex " + "WHERE lex.ownerId=:ownerId "
            + "AND TYPE(lex)=:type AND (lex.baseStore IS NULL "
            + "OR lex.baseStore IN (SELECT d FROM DocumentCorpus d))", byte[].class);
    query.setParameter("ownerId", ownerId).setParameter("type", entityClass);

    List<byte[]> results = query.getResultList();
    return Lists.newArrayList(Iterables.transform(results, UuidUtils.uuidBytesToStringFunction()));
}

From source file:eu.domibus.common.dao.MessageLogDao.java

public MessageLogEntry findByMessageId(String messageId, MSHRole mshRole) {
    final TypedQuery<MessageLogEntry> query = this.em.createNamedQuery("MessageLogEntry.findByMessageId",
            MessageLogEntry.class);
    query.setParameter("MESSAGE_ID", messageId);
    query.setParameter("MSH_ROLE", mshRole);

    try {/*from   ww w .  j  a  v a 2  s  .  c  om*/
        return query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:net.triptech.metahive.model.Record.java

/**
 * Find record entries.// w  w  w . j  a va 2  s. co m
 *
 * @param filter the record filter
 * @param firstResult the first result
 * @param maxResults the max results
 * @return the list
 */
public static List<Record> findRecordEntries(final RecordFilter filter, final List<Definition> definitions,
        final UserRole userRole, final ApplicationContext context, final int firstResult,
        final int maxResults) {

    List<Record> records = new ArrayList<Record>();

    Map<String, Object> variables = new HashMap<String, Object>();

    Definition orderDefinition = null;
    if (filter.getOrderId() != null && filter.getOrderId() > 0) {
        orderDefinition = Definition.findDefinition(filter.getOrderId());
    }

    StringBuilder sql = new StringBuilder("SELECT DISTINCT r FROM Record r");

    if (orderDefinition != null && orderDefinition.getId() != null) {
        sql.append(" LEFT OUTER JOIN r.keyValues as o");
        sql.append(" WITH o.definition.id = :orderDefinitionId");

        variables.put("orderDefinitionId", orderDefinition.getId());
    }

    Map<String, Map<String, Object>> whereParameters = buildWhere(filter);

    if (whereParameters.size() > 0) {
        String sqlWhere = whereParameters.keySet().iterator().next();
        Map<String, Object> whereVariables = whereParameters.get(sqlWhere);

        for (String key : whereVariables.keySet()) {
            variables.put(key, whereVariables.get(key));
        }
        sql.append(sqlWhere);
    }

    String orderValueCol = "r.recordId";
    if (orderDefinition != null && orderDefinition.getId() != null) {
        orderValueCol = "o.doubleValue";
        if (orderDefinition.getDataType() == DataType.TYPE_STRING) {
            orderValueCol = "o.stringValue";
        }
        if (orderDefinition.getDataType() == DataType.TYPE_BOOLEAN) {
            orderValueCol = "o.booleanValue";
        }
    }

    sql.append(" ORDER BY " + orderValueCol);

    if (filter.isOrderDescending()) {
        sql.append(" DESC");
    } else {
        sql.append(" ASC");
    }

    if (orderDefinition != null && orderDefinition.getId() != null) {
        sql.append(", r.recordId ASC");
    }

    logger.info("SQL: " + sql.toString());

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

    if (maxResults > 0) {
        q.setFirstResult(firstResult).setMaxResults(maxResults);
    }

    for (String variable : variables.keySet()) {
        q.setParameter(variable, variables.get(variable));
    }

    for (Record record : q.getResultList()) {
        record.setKeyValues(KeyValue.findKeyValues(record, definitions), definitions, userRole, context);
        records.add(record);
    }
    return records;
}

From source file:com.github.peholmst.springsecuritydemo.services.impl.CategoryServiceImpl.java

@Override
@Transactional(readOnly = true)//from  w ww .  j a v  a2  s  . c o  m
public List<Category> getChildren(Category parent) {
    assert parent != null : "parent must not be null";
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieving children for category [" + parent + "]");
    }
    TypedQuery<Category> query = getEntityManager()
            .createQuery("SELECT c FROM Category c WHERE c.parent = :parent ORDER BY c.name", Category.class);
    query.setParameter("parent", parent);
    List<Category> result = query.getResultList();
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + result.size() + " children");
    }
    return Collections.unmodifiableList(result);
}

From source file:org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl.java

public LdapConfig getLdapConfigById(Long ldapConfigId) {
    try {//from   w  w w  .j a  v  a  2  s .c  o  m

        String hql = "select c from LdapConfig c " + "WHERE c.ldapConfigId = :ldapConfigId "
                + "AND c.deleted LIKE :deleted";

        TypedQuery<LdapConfig> query = em.createQuery(hql, LdapConfig.class);
        query.setParameter("ldapConfigId", ldapConfigId);
        query.setParameter("deleted", "false");

        LdapConfig ldapConfig = null;
        try {
            ldapConfig = query.getSingleResult();
        } catch (NoResultException ex) {
        }

        return ldapConfig;

    } catch (Exception ex2) {
        log.error("[getLdapConfigById]: ", ex2);
    }
    return null;
}

From source file:csns.model.core.dao.jpa.FileDaoImpl.java

@Override
@PreAuthorize("authenticated and (#parent == null or #owner.id == principal.id)")
public List<File> getFiles(User owner, File parent, String name, boolean isFolder) {
    String query = "from File where owner = :owner and name = :name "
            + "and folder = :isFolder and deleted = false and ";
    query += parent != null ? "parent = :parent" : "parent is null";

    TypedQuery<File> typedQuery = entityManager.createQuery(query, File.class).setParameter("owner", owner)
            .setParameter("name", name).setParameter("isFolder", isFolder);
    if (parent != null)
        typedQuery.setParameter("parent", parent);

    return typedQuery.getResultList();
}

From source file:csns.model.academics.dao.jpa.SectionDaoImpl.java

@Override
public List<Section> searchSections(String term, int maxResults) {
    TypedQuery<Section> query = entityManager.createNamedQuery("section.search", Section.class);
    if (maxResults > 0)
        query.setMaxResults(maxResults);
    return query.setParameter("term", term).getResultList();
}