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:com.siberhus.ngai.core.CrudHelper.java

@SuppressWarnings("unchecked")
public final static List<Object> findByExample(EntityManager em, Class<?> entityClass, Object example) {
    if (em == null) {
        throw new IllegalArgumentException("EntityManager is null");
    }/*from ww  w  .  jav a 2 s . c  o m*/
    EntityInfo entityInfo = getEntityInfo(entityClass);
    List<Object> params = new ArrayList<Object>();
    StringBuilder sql = new StringBuilder(255);
    sql.append("from ").append(entityInfo.getEntityName()).append(" e where 1=1 ");
    try {
        for (Field field : entityInfo.getFieldSet()) {
            sql.append("and e.").append(field.getName()).append("=? ");
            params.add(field.get(example));
        }
    } catch (IllegalAccessException e) {
        throw new NgaiRuntimeException("Unable to get field value from example model: " + example, e);
    }
    Query query = em.createQuery(sql.toString());
    for (int i = 0; i < params.size(); i++) {
        query.setParameter(i + 1, params.get(i));
    }
    return query.getResultList();
}

From source file:ro.allevo.fintpws.security.RolesUtils.java

public static boolean hasReadAuthorityOnQueue(QueueEntity queueEntity) {
    EntityManagerFactory configEntityManagerFactory = Persistence.createEntityManagerFactory("fintpCFG");
    EntityManager entityManagerConfig = configEntityManagerFactory.createEntityManager();
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    UserEntity loggedUser = (UserEntity) authentication.getPrincipal();
    Query query = entityManagerConfig
            .createQuery("SELECT ur.roleid FROM UserRoleEntity ur, QueuesRoleMapEntity qr "
                    + "WHERE ur.roleid = qr.roleid " + "AND ur.userid=:userid " + "AND qr.queueid=:queueid");
    query.setParameter("userid", loggedUser.getUserid());
    query.setParameter("queueid", queueEntity.getGuid());
    List roles = query.getResultList();
    if (roles.isEmpty()) {
        return false;
    }/*from   w  w  w .  ja  va2 s  .  c  om*/
    return true;
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static List<UserDatabase> getAllUsers() {
    Logger.trace("Get All OnlineApplications from database.");

    List<UserDatabase> result;
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getAllUsers"));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;
    }/*from w ww .  java2  s.c  o  m*/
    return result;
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static List<UserDatabase> getAllNewUsers() {
    Logger.trace("Get all new Users from Database");

    List<UserDatabase> result;
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getAllNewUsers"));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;
    }/*from   w ww.  ja  v  a2 s.  c o  m*/
    return result;
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static MOAIDConfiguration getMOAIDConfiguration() {
    Logger.trace("Load MOAID Configuration from database.");

    List<MOAIDConfiguration> result;
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getMOAIDConfiguration"));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found. Create fresh instance.");
        return null;
    }//from   w w  w .j a v  a2s  .co m

    return (MOAIDConfiguration) result.get(0);
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static List<UserDatabase> getAllOpenUsersRequests() {
    Logger.trace("Get all new Users from Database");

    List<UserDatabase> result;
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getAllOpenUsersRequests"));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;
    }/*from w w  w.  j av a  2s .  c om*/
    return result;
}

From source file:com.autentia.common.util.ejb.EntityManagerUtils.java

/**
 * Devuelve una lista de entidades de tipo <code>T</code>, obtenida como resultado de ejectua la consulta
 * <code>query</code>, haciendo la susticucin de parmetros (la sustitucin de parmetros ser posicional).
 * // www.  j  av a  2 s .co m
 * @param <T> tipo de los objetos devueltos por la bsqueda.
 * @param query consulta que se quiere ejecutar.
 * @param queryParams parmetros de la consulta.
 * @return lista de entidades de tipo <code>T</code>.
 */
@SuppressWarnings("unchecked")
public static <T> List<T> find(Query query, Object... queryParams) {
    if (queryParams != null) {
        for (int position = 1, i = 0; i < queryParams.length; i++, position++) {
            query.setParameter(position, queryParams[i]);
        }
    }
    final List<T> entities = query.getResultList();

    if (log.isDebugEnabled())
        log.debug(entities.size() + " entities recovered.");

    return entities;
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static List<OnlineApplication> getAllOnlineApplications() {
    Logger.trace("Get All OnlineApplications from database.");

    List<OnlineApplication> result = null;
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getAllOnlineApplications"));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;
    }//from w  w  w  .j av a 2s. co  m
    return result;
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static List<OnlineApplication> getAllNewOnlineApplications() {
    Logger.trace("Get All OnlineApplications from database.");

    List<OnlineApplication> result;
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getAllNewOnlineApplications"));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        return null;
    }/*  ww  w. j  a va  2 s . c om*/
    return result;
}

From source file:at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead.java

public static List<OnlineApplication> getAllActiveOnlineApplications() {
    Logger.trace("Get All active OnlineApplications from database.");

    List<OnlineApplication> result;
    EntityManager session = ConfigurationDBUtils.getCurrentSession();

    javax.persistence.Query query = session.createQuery(QUERIES.get("getAllActiveOnlineApplications"));
    result = query.getResultList();

    Logger.trace("Found entries: " + result.size());

    if (result.size() == 0) {
        Logger.trace("No entries found.");
        result = new ArrayList<OnlineApplication>();

    }//  w  w  w  .  j av a  2  s . co  m
    return result;
}