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:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public List<SubscribedResource> readSubscribedResources(int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM SubscribedResource m");
    q.setFirstResult(firstResult);/*from  w ww .  j  a v  a 2  s  .c  om*/
    q.setMaxResults(maxResults);
    return q.getResultList();
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public List<DeploymentDescriptor> readDeploymentDescriptors(int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM DeploymentDescriptor m  ORDER BY m.id");
    q.setFirstResult(firstResult);/*from   w w  w  . j a  va 2 s. c  o m*/
    q.setMaxResults(maxResults);
    return q.getResultList();
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

@SuppressWarnings("unchecked")
public List<InstalledBun> readInstalledBuns(int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM InstalledBun m");
    q.setFirstResult(firstResult);//from w  w w  . j  a  va  2  s. com
    q.setMaxResults(maxResults);
    return q.getResultList();
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

@SuppressWarnings("unchecked")
public List<BakerUser> readUsers(int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM BakerUser m");
    q.setFirstResult(firstResult);/*from  w w w  .  j a v a2s. c  o m*/
    q.setMaxResults(maxResults);
    return q.getResultList();
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public List<BakerProperty> readProperties(int firstResult, int maxResults) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    Query q = entityManager.createQuery("SELECT m FROM BakerProperty m  ORDER BY m.id");
    q.setFirstResult(firstResult);/*  w w  w  . ja v  a 2  s  .  com*/
    q.setMaxResults(maxResults);
    return q.getResultList();

}

From source file:com.jada.admin.site.SiteLoader.java

public void loadShippingType() throws Exception {
    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    String sql = "from ShippingType where siteId = :siteId order by shippingTypeId";
    Query query = em.createQuery(sql);
    query.setParameter("siteId", Constants.SITE_SYSTEM);
    Iterator<?> iterator = query.getResultList().iterator();
    while (iterator.hasNext()) {
        ShippingType master = (ShippingType) iterator.next();
        ShippingType shippingType = new ShippingType();
        PropertyUtils.copyProperties(shippingType, master);
        shippingType.setSite(site);/* w ww. ja  va  2 s.co m*/
        shippingType.setRecUpdateBy(userId);
        shippingType.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
        shippingType.setRecCreateBy(userId);
        shippingType.setRecCreateDatetime(new Date(System.currentTimeMillis()));
        shippingType.setShippingMethodRegionTypes(null);
        shippingTypes.add(shippingType);
        em.persist(shippingType);
    }
}

From source file:com.jada.admin.site.SiteLoader.java

public void loadCountry() throws Exception {
    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    String sql = "from Country country where siteId = :siteId order by countryCode";
    Query query = em.createQuery(sql);
    query.setParameter("siteId", Constants.SITE_SYSTEM);
    Iterator<?> iterator = query.getResultList().iterator();
    while (iterator.hasNext()) {
        Country master = (Country) iterator.next();
        Country country = new Country();
        PropertyUtils.copyProperties(country, master);
        country.setSite(site);// w  w w  .  j ava  2s .  c  om
        country.setCountryId(null);
        country.setRecUpdateBy(userId);
        country.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
        country.setRecCreateBy(userId);
        country.setRecCreateDatetime(new Date(System.currentTimeMillis()));
        country.setShippingRegion(null);
        country.setStates(null);
        country.setTaxes(null);
        em.persist(country);
    }
}

From source file:info.dolezel.jarss.rest.v1.FeedsService.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from  w w w . j  a  va 2 s.  com
@Path("tree")
public Response getFeedsTree(@Context SecurityContext securityContext) {
    EntityManager em;
    User user = (User) securityContext.getUserPrincipal();
    JsonArrayBuilder jsonBuilder;
    List<FeedCategory> fcs;
    List<Feed> rootFeeds;

    em = HibernateUtil.getEntityManager();

    jsonBuilder = Json.createArrayBuilder();

    try {
        fcs = em.createQuery("select fc from FeedCategory fc where fc.user = :user order by fc.name asc")
                .setParameter("user", user).getResultList();

        for (FeedCategory fc : fcs) {
            JsonObjectBuilder obj = getFeedCategory(em, fc);
            jsonBuilder.add(obj);
        }

        rootFeeds = em.createQuery(
                "select f from Feed f where f.user = :user and f.feedCategory is null order by f.name asc")
                .setParameter("user", user).getResultList();
        for (Feed feed : rootFeeds) {
            JsonObjectBuilder obj = getFeed(em, feed);
            jsonBuilder.add(obj);
        }

        return Response.ok(jsonBuilder.build().toString()).build();
    } finally {
        em.close();
    }
}

From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.jpa.NewsHandler.java

/**
 * gets the category for its fs_id./*  w w w .j a va2  s  .  c o  m*/
 *
 * @param fs_id    The fs_id
 * @param language the language
 * @param em       the em
 * @return the NewsCategory instance
 */
private NewsCategory getNewsCategory(Long fs_id, String language, EntityManager em) {

    boolean close = false;
    try {
        if (em == null) {
            em = emf.createEntityManager();
            close = true;
        }

        Query categoryQuery = em.createQuery(new StringBuilder()
                .append("SELECT x FROM category x WHERE x.fs_id = :fs_id AND x.language = :language")
                .toString()); // or fsidindex2?
        categoryQuery.setParameter("fs_id", fs_id);
        categoryQuery.setParameter("language", language);

        if (categoryQuery.getResultList().size() > 0) {
            return (NewsCategory) categoryQuery.getSingleResult();
        }

        return null;
    } finally {
        if (close && em != null) {
            em.close();
        }
    }
}

From source file:com.jada.admin.site.SiteLoader.java

public void loadState() throws Exception {
    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    String sql = "from State state where state.country.site.siteId = :siteId order by stateCode";
    Query query = em.createQuery(sql);
    query.setParameter("siteId", Constants.SITE_SYSTEM);
    Iterator<?> iterator = query.getResultList().iterator();
    while (iterator.hasNext()) {
        State master = (State) iterator.next();
        State state = new State();
        PropertyUtils.copyProperties(state, master);
        state.setStateId(null);/*from  w w w .  j a v  a2  s .  co  m*/
        state.setRecUpdateBy(userId);
        state.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
        state.setRecCreateBy(userId);
        state.setRecCreateDatetime(new Date(System.currentTimeMillis()));
        state.setShippingRegion(null);
        Country mc = master.getCountry();
        Country country = null;
        if (mc != null) {
            country = CountryDAO.loadByCountryName(site.getSiteId(), mc.getCountryName());
        }
        state.setCountry(country);
        state.setTaxes(null);
        em.persist(state);
    }
}