Example usage for javax.persistence EntityManager createNamedQuery

List of usage examples for javax.persistence EntityManager createNamedQuery

Introduction

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

Prototype

public Query createNamedQuery(String name);

Source Link

Document

Create an instance of Query for executing a named query (in the Java Persistence query language or in native SQL).

Usage

From source file:org.apache.falcon.jdbc.BacklogMetricStore.java

public Map<Entity, List<MetricInfo>> getAllInstances() throws FalconException {
    EntityManager entityManager = getEntityManager();
    Query q = entityManager.createNamedQuery(PersistenceConstants.GET_ALL_BACKLOG_INSTANCES);
    List<BacklogMetricBean> result = q.getResultList();

    try {// ww w . j a  v  a 2s  . co  m
        if (CollectionUtils.isEmpty(result)) {
            return null;
        }
    } finally {
        entityManager.close();
    }

    Map<Entity, List<MetricInfo>> backlogMetrics = new HashMap<>();
    for (BacklogMetricBean backlogMetricBean : result) {
        Entity entity = EntityUtil.getEntity(backlogMetricBean.getEntityType(),
                backlogMetricBean.getEntityName());
        if (!backlogMetrics.containsKey(entity)) {
            backlogMetrics.put(entity, new ArrayList<MetricInfo>());
        }
        List<MetricInfo> metrics = backlogMetrics.get(entity);
        MetricInfo metricInfo = new MetricInfo(
                BacklogMetricEmitterService.DATE_FORMAT.get().format(backlogMetricBean.getNominalTime()),
                backlogMetricBean.getClusterName());
        metrics.add(metricInfo);
        backlogMetrics.put(entity, metrics);
    }
    return backlogMetrics;
}

From source file:de.zib.gndms.dspace.slice.service.globus.resource.ExtSliceResourceHome.java

@NotNull
public Query getListAllQuery(final @NotNull EntityManager em) {
    return em.createNamedQuery("listAllSliceIds");
}

From source file:view.TimelinePanel.java

private String getJsonConfig() {
    EntityManager em = ApplicationController.getEnitityManager();
    TypedQuery<Tasks> queryTasks = (TypedQuery<Tasks>) em.createNamedQuery("Tasks.findByProjectId");
    Integer proId = ApplicationController.getCurrentProject().getId();
    List<Tasks> tasks = queryTasks.setParameter("projectId", proId).getResultList();
    return tasks.get(0).getTaskName();
}

From source file:org.nuxeo.ecm.platform.uidgen.service.UIDSequencerImpl.java

public int getNext(EntityManager em, String key) {
    UIDSequenceBean seq;//w ww  .j av a2  s  . c o m
    try {
        seq = (UIDSequenceBean) em.createNamedQuery("UIDSequence.findByKey").setParameter("key", key)
                .getSingleResult();
        // createQuery("FROM UIDSequenceBean seq WHERE seq.key = :key")
    } catch (NoResultException e) {
        seq = new UIDSequenceBean(key);
        em.persist(seq);
    }
    return seq.nextIndex();
}

From source file:es.alvsanand.webpage.db.dao.DAOHelper.java

protected Query getNamedQuery(EntityManager entityManager, String queryName, QueryBean queryBean) {
    Query q = entityManager.createNamedQuery(queryName);

    if (queryBean != null) {
        if (queryBean.getLimit() > 0) {
            q.setMaxResults(queryBean.getLimit());
        }//w  ww  . ja v a2 s  . c  o m
        if (queryBean.getOffset() > 0) {
            q.setFirstResult(queryBean.getOffset());
        }
    }

    return q;
}

From source file:de.zib.gndms.GORFX.context.service.globus.resource.ExtTaskResourceHome.java

@NotNull
public Query getListAllQuery(@NotNull EntityManager em) {
    return em.createNamedQuery("listAllTaskIds");
}

From source file:de.berlios.jhelpdesk.dao.jpa.TicketDAOJpa.java

public List<Ticket> getTicketsByStatus(final TicketStatus ticketStatus, final int howMuch) throws DAOException {
    try {/*  www.ja  v  a2s  .c om*/
        return this.jpaTemplate.executeFind(new JpaCallback() {
            public Object doInJpa(EntityManager em) throws PersistenceException {
                Query query = em.createNamedQuery("Ticket.byStatusOrderByCreateDateDESC");
                query.setParameter(1, ticketStatus.toInt());
                query.setMaxResults(howMuch);
                return query.getResultList();
            }
        });
    } catch (DataAccessException dae) {
        throw new DAOException(dae);
    }
}

From source file:org.apache.falcon.jdbc.BacklogMetricStore.java

public void deleteEntityBackLogInstances(String entityName, String entityType) {
    EntityManager entityManager = getEntityManager();
    beginTransaction(entityManager);/*from   w w  w. ja v a  2 s.  c  o  m*/
    Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_ALL_BACKLOG_ENTITY_INSTANCES);
    q.setParameter("entityName", entityName);
    q.setParameter("entityType", entityType);
    try {
        q.executeUpdate();
    } finally {
        commitAndCloseTransaction(entityManager);
    }
}

From source file:com.romb.hashfon.helper.Helper.java

public boolean isKompanijaLogged(String[] token) {
    try {/*ww w  .j  a va 2  s  .  com*/
        EntityManager em = getEntityManager();
        if (token[1].equals("KOMPANIJA")) {
            Hr hr = (Hr) em.createNamedQuery("Hr.findById").setParameter("id", Long.parseLong(token[2]))
                    .getSingleResult();
            return hr != null;
        } else {
            return false;
        }
    } catch (Exception e) {
        return false;
    }
}

From source file:org.apache.falcon.jdbc.BacklogMetricStore.java

public synchronized void deleteMetricInstance(String entityName, String cluster, Date nominalTime,
        EntityType entityType) {//from  ww w. jav  a  2  s .  c o m
    EntityManager entityManager = getEntityManager();
    beginTransaction(entityManager);
    Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_BACKLOG_METRIC_INSTANCE);
    q.setParameter("entityName", entityName);
    q.setParameter("clusterName", cluster);
    q.setParameter("nominalTime", nominalTime);
    q.setParameter("entityType", entityType.name());
    try {
        q.executeUpdate();
    } finally {
        commitAndCloseTransaction(entityManager);
    }
}