Example usage for javax.persistence Query getResultList

List of usage examples for javax.persistence Query getResultList

Introduction

In this page you can find the example usage for javax.persistence Query getResultList.

Prototype

List getResultList();

Source Link

Document

Execute a SELECT query and return the query results as an untyped List.

Usage

From source file:org.chtijbug.drools.platform.persistence.SessionExecutionRepositoryImpl.java

/**
 * @param ruleBaseID//from w  w w  .  ja  va2 s .com
 * @param sessionId
 * @return
 * @Query("select s from SessionExecution s " +
 * "where s.platformRuntimeInstance.ruleBaseID= :ruleBaseID and s.sessionId = :sessionId  "+
 * "and s.platformRuntimeInstance.endDate is null  ")
 */

@Override
public SessionExecution findByRuleBaseIDAndSessionIdAndEndDateIsNull(@Param("ruleBaseID") Long ruleBaseID,
        @Param("sessionId") Long sessionId) {
    logger.debug(">> findByRuleBaseIDAndSessionIdAndEndDateIsNull");
    SessionExecution sessionExecutionFound = null;
    try {
        String jpaQuery = "SELECT s.id, s.enddate, s.sessionexecutionstatus, s.sessionid, s.startdate, s.starteventid, \n"
                + "  s.stopeventid, s.platform_runtime_instance_id\n"
                + "  FROM session_execution s, platform_runtime_instance p \n"
                + "  where s.platform_runtime_instance_id = p.id\n" + "  and s.sessionid=:sessionid\n"
                + "  and p.rulebaseid = :rulebaseID\n" + "  and p.enddate is null";
        //___ Append other filters
        Query query = entityManager.createNativeQuery(jpaQuery, SessionExecution.class);
        query.setParameter("rulebaseID", ruleBaseID);
        query.setParameter("sessionid", sessionId);
        List<SessionExecution> result = query.getResultList();
        if (result.size() == 1) {
            sessionExecutionFound = result.get(0);
        }

        return sessionExecutionFound;
    } finally {
        logger.debug("<< findByRuleBaseIDAndSessionIdAndEndDateIsNull()");
    }
}

From source file:org.simbasecurity.core.domain.repository.RuleDatabaseRepository.java

@SuppressWarnings("unchecked")
@Override/*from  w  w w  .ja va  2s. c  o  m*/
public Collection<Rule> findNotLinked(Policy policy) {
    Query query = entityManager.createQuery(
            "SELECT r FROM RuleEntity r " + "WHERE :policy != r.policy " + "OR r.policy = null order by r.name")
            .setParameter(POLICY, policy);

    return query.getResultList();
}

From source file:com.appdynamicspilot.persistence.CartPersistence.java

/**
 * Get all the items from cart based on user
 *
 * @param userId//  w  w  w.ja  v a 2  s  .  c  o m
 * @return List of items
 */
public List<Item> getAllItemsByUser(Long userId) {
    Query q = getEntityManager().createQuery("SELECT c FROM Cart c where c.user.id = :userid");
    q.setParameter("userid", userId);
    List<Cart> carts = q.getResultList();
    if ((carts == null) || (carts.size() == 0)) {
        return Collections.EMPTY_LIST;
    }

    Cart cart = carts.get(0);
    return cart.getItems();
}

From source file:com.expressui.core.dao.ReferenceEntityDao.java

/**
 * Finds all reference entities of given type ordered by com.expressui.core.entity.ReferenceEntity.ORDER_BY_PROPERTY
 * and com.expressui.core.entity.ReferenceEntity.DISPLAY_PROPERTY.
 *
 * @param entityType type of entity//  w  w w  .j  a  va 2  s  . com
 * @param <T>        type of entity
 * @return all reference entities
 */
@Override
public <T> List<T> findAll(Class<? extends T> entityType) {
    Query query = getEntityManager().createQuery("SELECT e FROM " + entityType.getSimpleName() + " e"
            + " ORDER BY e." + ReferenceEntity.ORDER_BY_PROPERTY + ", e." + ReferenceEntity.DISPLAY_PROPERTY);

    setReadOnly(query);

    return query.getResultList();
}

From source file:org.kuali.mobility.push.dao.SenderDaoImpl.java

public List<Sender> findAllUnhiddenSenders() {
    Query query = entityManager.createQuery("select s from Sender s where s.hidden = 0 order by s.name");
    return query.getResultList();
}

From source file:org.syncope.core.persistence.dao.impl.RoleDAOImpl.java

@Override
public List<SyncopeRole> findChildren(final Long roleId) {
    Query query = entityManager.createQuery("SELECT r FROM SyncopeRole r WHERE " + "r.parent.id=:roleId");
    query.setParameter("roleId", roleId);
    return query.getResultList();
}

From source file:things.jpa.MysqlJpaConnector.java

@Override
public Observable<? extends Thing<?>> findThingsForTypeMatchingKey(String type, String key) {

    final Timer.Context context = find_matching_type_and_key_timer.time();

    try {/*from   w w  w . j  a  va2  s  .c  o  m*/

        String sqlQuery = "select * from things thing0_ where thing0_.thing_type = :thingType and thing0_.thing_key regexp :thingKey";

        Query q = entityManager.createNativeQuery(sqlQuery, Thing.class);
        q.setParameter("thingType", type);
        q.setParameter("thingKey", MatcherUtils.convertGlobToRegex(key));
        List<Thing<?>> result = q.getResultList();

        return Observable.from(result);
    } finally {
        context.stop();
    }

}

From source file:com.sapito.db.dao.AbstractDao.java

public List<T> findBySpecificField(String field, Object fieldContent, String predicates,
        LinkedHashMap<String, String> ordering, LinkedList<String> grouping) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery();
    Root<T> root = cq.from(entityClass);
    Predicate predicate = null;//  w ww.  j a  v a 2  s . c o  m

    if (predicates.equals("equal")) {
        predicate = cb.equal(root.get(field), fieldContent);
    } else if (predicates.equals("likelower")) {
        predicate = cb.like(cb.lower(root.<String>get(field)), fieldContent.toString());
    } else if (predicates.equals("like")) {
        predicate = cb.like(root.<String>get(field), "%" + fieldContent.toString() + "%");
    }

    cq.select(root);
    cq.where(predicate);

    if (ordering != null) {
        Set<String> set = ordering.keySet();
        List<Order> orders = new ArrayList<>();
        for (String orderingField : set) {
            Order order;
            if (ordering.get(orderingField).equals("ASC")) {
                order = cb.asc(root.get(orderingField));
            } else {
                order = cb.desc(root.get(orderingField));
            }
            orders.add(order);
        }
        cq.orderBy(orders);
    }

    if (grouping != null) {
        Iterator iterator = grouping.iterator();
        List<Expression> groups = new LinkedList<>();
        while (iterator.hasNext()) {
            groups.add(root.get(iterator.next().toString()));
        }
        cq.groupBy(groups);
    }

    Query query = entityManager.createQuery(cq);
    query.setMaxResults(MAX_RECORDS_RETURNED);

    return query.getResultList();
}

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

public List<String> findUnsentMessages() {

    final Query query = this.em.createNamedQuery("MessageLogEntry.findUnsentMessages");

    //noinspection unchecked
    return query.getResultList();
}

From source file:io.hops.hopsworks.common.dao.user.security.audit.AccountAuditFacade.java

public Userlogins getLastUserLogin(Users user) {
    Query query = em.createNamedQuery("Userlogins.findUserLast", Userlogins.class).setParameter("user", user)
            .setMaxResults(1);//from  w w  w . j  a v  a 2  s.  c o m
    List<Userlogins> logins = query.getResultList();
    //A user might have never logged in, so we need to check first
    if (!logins.isEmpty()) {
        return logins.get(0);
    }
    return null;
}