List of usage examples for javax.persistence EntityManager createQuery
public Query createQuery(CriteriaDelete deleteQuery);
Query
for executing a criteria delete query. From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public Product readProductByUUID(String uuid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM Product m WHERE m.uuid='" + uuid + "'"); return (q.getResultList().size() == 0) ? null : (Product) q.getSingleResult(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public long countInstalledBuns() { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT COUNT(s) FROM InstalledBun s"); return (Long) q.getSingleResult(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public long countUsers() { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT COUNT(s) FROM FStoreUser s"); return (Long) q.getSingleResult(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public FStoreProperty readPropertyByName(String name) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM FStoreProperty m WHERE m.name='" + name + "'"); return (q.getResultList().size() == 0) ? null : (FStoreProperty) q.getSingleResult(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public List<Category> readCategories(int firstResult, int maxResults) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM Category m ORDER BY m.id"); q.setFirstResult(firstResult);//w ww. j a v a2s . c o m q.setMaxResults(maxResults); return q.getResultList(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public UserSession readUserBySessionId(String sessionId) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM UserSession m WHERE m.sessionId='" + sessionId + "'"); return (q.getResultList().size() == 0) ? null : (UserSession) q.getSingleResult(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
@SuppressWarnings("unchecked") public List<FStoreUser> readUsers(int firstResult, int maxResults) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM FStoreUser m"); q.setFirstResult(firstResult);/*from w ww. j a v a2s . com*/ q.setMaxResults(maxResults); return q.getResultList(); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public List<FStoreProperty> readProperties(int firstResult, int maxResults) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q = entityManager.createQuery("SELECT m FROM FStoreProperty m ORDER BY m.id"); q.setFirstResult(firstResult);//from w w w . j a v a2s .co m q.setMaxResults(maxResults); return q.getResultList(); }
From source file:com.creditcloud.common.entities.dao.AbstractReadDAO.java
public <K> T findBy(String fieldName, Object value, Class<K> valueClass) { EntityManager em = getEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(entityClass); Root<T> root = cq.from(entityClass); cq.select(root).where(cb.equal(root.get(fieldName).as(valueClass), value)); List<T> list = em.createQuery(cq).getResultList(); return list.isEmpty() ? null : list.get(0); }
From source file:eu.forgestore.ws.impl.FStoreJpaController.java
public List<Widget> readWidgetMetadataByOwnerId(int userid, int firstResult, int maxResults) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Query q;//w w w . ja v a2 s.c o m q = entityManager.createQuery("SELECT a FROM Widget a WHERE a.owner.id=" + userid + " ORDER BY a.id"); q.setFirstResult(firstResult); q.setMaxResults(maxResults); return q.getResultList(); }