Java Code Examples for javax.persistence.Query.getParameter()

The following are Jave code examples for showing how to use getParameter() of the javax.persistence.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: marathonv5   File: CumulativeLiveSalesFacadeREST.java   Source Code and License Vote up 6 votes
@GET
@Produces({"application/xml", "application/json"})
@Path("/region/{regionId}")
public List<TransitCumulativeSales> findAllRegion(@PathParam("regionId") Integer regionId) {       
    Query baseRangeQuery = em.createQuery(REGION_RANGE_QUERY); 
    Parameter<Integer> p1 = baseRangeQuery.getParameter("regionId", Integer.class);
    baseRangeQuery.setParameter(p1, regionId);
    
    List<TransitCumulativeSales> result = new ArrayList<TransitCumulativeSales>();
    List<Object[]> resultList = baseRangeQuery.getResultList();
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        TransitCumulativeSales t = new TransitCumulativeSales();
        t.setStartDailySalesId((Integer)o[0]);
        t.setEndDailySalesId((Integer)o[1]);
        t.setCost((Double)o[2]);
        t.setSales((Double) o[3]);
        t.setDate((Date)o[4]);
        result.add(t);
    }
    return result;
}
 
Example 2
Project: marathonv5   File: CumulativeLiveSalesFacadeREST.java   Source Code and License Vote up 6 votes
@GET
@Produces({"application/xml", "application/json"})
@Path("/region/{regionId}")
public List<TransitCumulativeSales> findAllRegion(@PathParam("regionId") Integer regionId) {       
    Query baseRangeQuery = em.createQuery(REGION_RANGE_QUERY); 
    Parameter<Integer> p1 = baseRangeQuery.getParameter("regionId", Integer.class);
    baseRangeQuery.setParameter(p1, regionId);
    
    List<TransitCumulativeSales> result = new ArrayList<TransitCumulativeSales>();
    List<Object[]> resultList = baseRangeQuery.getResultList();
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        TransitCumulativeSales t = new TransitCumulativeSales();
        t.setStartDailySalesId((Integer)o[0]);
        t.setEndDailySalesId((Integer)o[1]);
        t.setCost((Double)o[2]);
        t.setSales((Double) o[3]);
        t.setDate((Date)o[4]);
        result.add(t);
    }
    return result;
}
 
Example 3
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   Source Code and License Vote up 6 votes
private HashMap<String, Long> runBaseQuery(Date date){
    Calendar cal = Calendar.getInstance();
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_QUERY);
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    return result;
}
 
Example 4
Project: marathonv5   File: CumulativeLiveSalesFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/region/{from}/{to}")
@Produces({"application/xml", "application/json"})
public List<RegionTransitCumulativeSales> findRegionRange(@PathParam("from") String from, @PathParam("to") String to) throws ParseException {
    System.out.println("START findRegionRange (from="+from+" , to="+to+")");
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query q = getEntityManager().createQuery(REGION_SUM_QUERY);
    Parameter<Integer> p1 = q.getParameter("startId", Integer.class);
    q.setParameter(p1, Integer.parseInt(from));
    Parameter<Integer> p2 = q.getParameter("endId", Integer.class);
    q.setParameter(p2, Integer.parseInt(to));
    
    List<RegionTransitCumulativeSales> result = new ArrayList<RegionTransitCumulativeSales>();
    List<Object[]> resultList = q.getResultList();
    
    
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        RegionTransitCumulativeSales t = new RegionTransitCumulativeSales();
        t.setCost((Double)o[0]);
        t.setSales((Double) o[1]);
        t.setUnits((Long) o[2]);
        t.setRegion((Region) o[3]);
        result.add(t);
    }
    
    DIFF = (System.currentTimeMillis() - START_TIME);
    System.out.println("    TOTAL TIME = "+DIFF+"ms");
    
    return result;
}
 
Example 5
Project: marathonv5   File: CumulativeLiveSalesFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/state/{from}/{to}/{regionId}")
@Produces({"application/xml", "application/json"})
public List<StateTransitCumulativeSales> findStateRange(@PathParam("from") String from, @PathParam("to") String to, @PathParam("regionId") Integer regionId) {
    System.out.println("START findRegionRange (from="+from+" , to="+to+")");
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query q = getEntityManager().createQuery(STATE_SUM_QUERY);
    Parameter<Integer> p1 = q.getParameter("startId", Integer.class);
    q.setParameter(p1, Integer.parseInt(from));
    Parameter<Integer> p2 = q.getParameter("endId", Integer.class);
    q.setParameter(p2, Integer.parseInt(to));
    Parameter<Integer> p3 = q.getParameter("regionId", Integer.class);
    q.setParameter(p3, regionId);
    
    List<StateTransitCumulativeSales> result = new ArrayList<StateTransitCumulativeSales>();
    List<Object[]> resultList = q.getResultList();
    
    
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        StateTransitCumulativeSales t = new StateTransitCumulativeSales();
        t.setCost((Double)o[0]);
        t.setSales((Double) o[1]);
        t.setUnits((Long) o[2]);
        t.setState((String) o[3]);
        result.add(t);
    }
    
    DIFF = (System.currentTimeMillis() - START_TIME);
    System.out.println("    TOTAL TIME = "+DIFF+"ms");
    
    return result;
}
 
Example 6
Project: marathonv5   File: RegionFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/international/{international}")
@Produces({"application/xml", "application/json"})
public List<Region> findInternational(@PathParam("international")
Integer international) {
    Query q = getEntityManager().createNamedQuery("Region.findByInternational");
    Parameter<Integer> p = q.getParameter("international", Integer.class);
    q.setParameter(p, international);
    return q.getResultList();
}
 
Example 7
Project: marathonv5   File: LiveSalesListFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/date/{from}")
@Produces({"application/xml", "application/json"})
public List<LiveSalesList> findFrom(@PathParam("from") Integer from) {
    Query q = getEntityManager().createNamedQuery("LiveSalesList.findFromOrderLineId");
    Parameter<Integer> p = q.getParameter("orderLineId", Integer.class);
    q.setParameter(p, from);
    return q.getResultList();
}
 
Example 8
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   Source Code and License Vote up 5 votes
private HashMap<String, Long> runBaseQuery(Date date){
    Calendar cal = Calendar.getInstance();
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_QUERY);
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    return result;
}
 
Example 9
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   Source Code and License Vote up 5 votes
private HashMap<String, Long> runProductTypeQuery(Date date1, Integer productTypeId){
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_TYPE_QUERY);
    Calendar cal = Calendar.getInstance();
    
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date1);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());
        Parameter<Integer> p3 = baseQuery.getParameter("productTypeId", Integer.class);
        baseQuery.setParameter(p3, productTypeId);

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    
    return result;
}
 
Example 10
Project: marathonv5   File: CumulativeLiveSalesFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/region/{from}/{to}")
@Produces({"application/xml", "application/json"})
public List<RegionTransitCumulativeSales> findRegionRange(@PathParam("from") String from, @PathParam("to") String to) throws ParseException {
    System.out.println("START findRegionRange (from="+from+" , to="+to+")");
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query q = getEntityManager().createQuery(REGION_SUM_QUERY);
    Parameter<Integer> p1 = q.getParameter("startId", Integer.class);
    q.setParameter(p1, Integer.parseInt(from));
    Parameter<Integer> p2 = q.getParameter("endId", Integer.class);
    q.setParameter(p2, Integer.parseInt(to));
    
    List<RegionTransitCumulativeSales> result = new ArrayList<RegionTransitCumulativeSales>();
    List<Object[]> resultList = q.getResultList();
    
    
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        RegionTransitCumulativeSales t = new RegionTransitCumulativeSales();
        t.setCost((Double)o[0]);
        t.setSales((Double) o[1]);
        t.setUnits((Long) o[2]);
        t.setRegion((Region) o[3]);
        result.add(t);
    }
    
    DIFF = (System.currentTimeMillis() - START_TIME);
    System.out.println("    TOTAL TIME = "+DIFF+"ms");
    
    return result;
}
 
Example 11
Project: marathonv5   File: CumulativeLiveSalesFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/state/{from}/{to}/{regionId}")
@Produces({"application/xml", "application/json"})
public List<StateTransitCumulativeSales> findStateRange(@PathParam("from") String from, @PathParam("to") String to, @PathParam("regionId") Integer regionId) {
    System.out.println("START findRegionRange (from="+from+" , to="+to+")");
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query q = getEntityManager().createQuery(STATE_SUM_QUERY);
    Parameter<Integer> p1 = q.getParameter("startId", Integer.class);
    q.setParameter(p1, Integer.parseInt(from));
    Parameter<Integer> p2 = q.getParameter("endId", Integer.class);
    q.setParameter(p2, Integer.parseInt(to));
    Parameter<Integer> p3 = q.getParameter("regionId", Integer.class);
    q.setParameter(p3, regionId);
    
    List<StateTransitCumulativeSales> result = new ArrayList<StateTransitCumulativeSales>();
    List<Object[]> resultList = q.getResultList();
    
    
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        StateTransitCumulativeSales t = new StateTransitCumulativeSales();
        t.setCost((Double)o[0]);
        t.setSales((Double) o[1]);
        t.setUnits((Long) o[2]);
        t.setState((String) o[3]);
        result.add(t);
    }
    
    DIFF = (System.currentTimeMillis() - START_TIME);
    System.out.println("    TOTAL TIME = "+DIFF+"ms");
    
    return result;
}
 
Example 12
Project: marathonv5   File: RegionFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/international/{international}")
@Produces({"application/xml", "application/json"})
public List<Region> findInternational(@PathParam("international")
Integer international) {
    Query q = getEntityManager().createNamedQuery("Region.findByInternational");
    Parameter<Integer> p = q.getParameter("international", Integer.class);
    q.setParameter(p, international);
    return q.getResultList();
}
 
Example 13
Project: marathonv5   File: LiveSalesListFacadeREST.java   Source Code and License Vote up 5 votes
@GET
@Path("/date/{from}")
@Produces({"application/xml", "application/json"})
public List<LiveSalesList> findFrom(@PathParam("from") Integer from) {
    Query q = getEntityManager().createNamedQuery("LiveSalesList.findFromOrderLineId");
    Parameter<Integer> p = q.getParameter("orderLineId", Integer.class);
    q.setParameter(p, from);
    return q.getResultList();
}
 
Example 14
Project: marathonv5   File: DailySalesHeatMapFacadeREST.java   Source Code and License Vote up 5 votes
private HashMap<String, Long> runProductTypeQuery(Date date1, Integer productTypeId){
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_TYPE_QUERY);
    Calendar cal = Calendar.getInstance();
    
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date1);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());
        Parameter<Integer> p3 = baseQuery.getParameter("productTypeId", Integer.class);
        baseQuery.setParameter(p3, productTypeId);

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    
    return result;
}