Example usage for javax.persistence EntityManager createQuery

List of usage examples for javax.persistence EntityManager createQuery

Introduction

In this page you can find the example usage for javax.persistence EntityManager createQuery.

Prototype

public Query createQuery(CriteriaDelete deleteQuery);

Source Link

Document

Create an instance of Query for executing a criteria delete query.

Usage

From source file:com.busimu.core.dao.impl.UserMngDaoPolicyJpaImpl.java

private License getLicenseByCode(EntityManager em, String licenseCode) {
    Query q = em.createQuery("select l from License l where l.licenseCode = '" + licenseCode + "'");
    List<?> resultList = q.getResultList();
    return resultList.size() == 0 ? null : (License) resultList.get(0);
}

From source file:edu.csueb.cs6320.utils.UserService.java

public boolean isValidPassword(String email, String password) {
    EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager();

    User u = (User) em.createQuery("SELECT u FROM User u WHERE u.email = :inEmail")
            .setParameter("inEmail", email).setMaxResults(1).getSingleResult();

    if (u == null) {
        return false;
    }/*ww w.  j a  v a 2 s.  c  o  m*/

    try {
        return Auth.isCorrectPassword(password, u.getSalt(), u.getSaltedHashedPassword());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:de.iai.ilcd.model.dao.AbstractDao.java

/**
 * Get all data sets in the persistence unit of the represented type T
 * //from   w w  w . j  a va  2  s .  co m
 * @return all data sets in the persistence unit of the represented type T
 */
@SuppressWarnings("unchecked")
public List<T> getAll() {
    EntityManager em = PersistenceUtil.getEntityManager();
    return em.createQuery("select a from " + this.jpaName + " a").getResultList();
}

From source file:de.iai.ilcd.model.dao.AbstractDao.java

/**
 * Get <code>pageSize</code> items starting on <code>startIndex</code>
 * /*  w w w .j av a 2 s.  co  m*/
 * @param startIndex
 *            start index
 * @param pageSize
 *            page size
 * @return list of matching elements
 */
@SuppressWarnings("unchecked")
public List<T> get(int startIndex, int pageSize) {
    EntityManager em = PersistenceUtil.getEntityManager();
    return em.createQuery("select a from " + this.jpaName + " a").setFirstResult(startIndex)
            .setMaxResults(pageSize).getResultList();
}

From source file:fr.amapj.service.services.saisiepermanence.PermanenceService.java

private List<DatePermanenceUtilisateur> getAllDateDistriUtilisateur(EntityManager em, DatePermanence d) {
    Query q = em.createQuery("select du from DatePermanenceUtilisateur du " + "WHERE du.datePermanence=:d "
            + "ORDER BY du.utilisateur.nom,du.utilisateur.prenom");
    q.setParameter("d", d);

    List<DatePermanenceUtilisateur> us = q.getResultList();
    return us;/*  w  ww.j av a  2  s  . c o  m*/
}

From source file:de.iai.ilcd.model.dao.AbstractDao.java

/**
 * Get the count of elements in the database for type T
 * /*from   w  w w .ja  v a 2 s. c  o m*/
 * @return count of elements in the database for type T
 */
public Long getAllCount() {
    EntityManager em = PersistenceUtil.getEntityManager();
    return (Long) em.createQuery("select count(a) from " + this.jpaName + " a").getSingleResult();
}

From source file:de.iai.ilcd.model.dao.CommonDataStockDao.java

/**
 * Get a data stock by name/* w  ww. ja v  a2s  . c  o  m*/
 * 
 * @param name
 *            name of data stock to load
 * @return
 */
@SuppressWarnings("unchecked")
private <T extends AbstractDataStock> T getDataStockByName(String name, String jpaName, Class<T> type) {
    EntityManager em = PersistenceUtil.getEntityManager();
    T stock = null;
    try {
        stock = (T) em.createQuery("SELECT a FROM " + jpaName + " a WHERE a.name=:name")
                .setParameter("name", name).getSingleResult();
    } catch (NoResultException e) {
        // do nothing; we just return null
    }
    return stock;
}

From source file:de.iai.ilcd.model.dao.CommonDataStockDao.java

/**
 * Get a data stock by name/*  ww  w. jav  a  2  s  . c o  m*/
 * 
 * @param name
 *            name of data stock to load
 * @return
 */
@SuppressWarnings("unchecked")
public <T extends AbstractDataStock> T getDataStockByUuid(String uuid) {
    EntityManager em = PersistenceUtil.getEntityManager();
    T stock = null;
    try {
        stock = (T) em.createQuery("SELECT a FROM " + this.getJpaName() + " a WHERE a.uuid.uuid=:uuid")
                .setParameter("uuid", uuid).getSingleResult();
    } catch (NoResultException e) {
        // do nothing; we just return null
    }
    return stock;
}

From source file:com.easyjf.core.dao.impl.GenericDAOImpl.java

public int batchUpdate(final String jpql, final Object[] params) {
    Object ret = this.getJpaTemplate().execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query query = em.createQuery(jpql);
            int parameterIndex = 1;
            if (params != null && params.length > 0) {
                for (Object obj : params) {
                    query.setParameter(parameterIndex++, obj);
                }/*from   w  ww .j ava2s . c o m*/
            }
            return query.executeUpdate();
        }
    });
    return (Integer) ret;
}

From source file:com.soen.ebanking.dao.ObjectDao.java

public List getAllObjects(Class<T> ClassName, String tableName) {
    EntityManager em = this.getEMF().createEntityManager();
    CriteriaBuilder qb = em.getCriteriaBuilder();
    CriteriaQuery<T> query = qb.createQuery(ClassName);
    //Root<T> entities = query.from(ClassName);
    List<T> result = em.createQuery(query).getResultList();

    return result;
}