Java Code Examples for javax.persistence.Query#getParameter()
The following examples show how to use
javax.persistence.Query#getParameter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CumulativeLiveSalesFacadeREST.java From marathonv5 with Apache License 2.0 | 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
Source File: CumulativeLiveSalesFacadeREST.java From marathonv5 with Apache License 2.0 | 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
Source File: CumulativeLiveSalesFacadeREST.java From marathonv5 with Apache License 2.0 | 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 4
Source File: CumulativeLiveSalesFacadeREST.java From marathonv5 with Apache License 2.0 | 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 5
Source File: RegionFacadeREST.java From marathonv5 with Apache License 2.0 | 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 6
Source File: LiveSalesListFacadeREST.java From marathonv5 with Apache License 2.0 | 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 7
Source File: DailySalesHeatMapFacadeREST.java From marathonv5 with Apache License 2.0 | 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 8
Source File: DailySalesHeatMapFacadeREST.java From marathonv5 with Apache License 2.0 | 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 9
Source File: CumulativeLiveSalesFacadeREST.java From marathonv5 with Apache License 2.0 | 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 10
Source File: CumulativeLiveSalesFacadeREST.java From marathonv5 with Apache License 2.0 | 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 11
Source File: RegionFacadeREST.java From marathonv5 with Apache License 2.0 | 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 12
Source File: LiveSalesListFacadeREST.java From marathonv5 with Apache License 2.0 | 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 13
Source File: DailySalesHeatMapFacadeREST.java From marathonv5 with Apache License 2.0 | 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 14
Source File: DailySalesHeatMapFacadeREST.java From marathonv5 with Apache License 2.0 | 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 15
Source File: JpaCmpEngine.java From tomee with Apache License 2.0 | 5 votes |
private List<Object> executeSelectQuery(final Query query, Object[] args) { // process args if (args == null) { args = NO_ARGS; } for (int i = 0; i < args.length; i++) { Object arg = args[i]; // ejb proxies need to be swapped out for real instance classes if (arg instanceof EJBObject) { arg = Cmp2Util.getEntityBean((EJBObject) arg); } if (arg instanceof EJBLocalObject) { arg = Cmp2Util.getEntityBean((EJBLocalObject) arg); } try { query.getParameter(i + 1); } catch (final IllegalArgumentException e) { // IllegalArgumentException means that the parameter with the // specified position does not exist continue; } query.setParameter(i + 1, arg); } // todo results should not be iterated over, but should instead // perform all work in a wrapper list on demand by the application code final List results = query.getResultList(); for (final Object value : results) { if (value instanceof EntityBean) { // todo don't activate beans already activated final EntityBean entity = (EntityBean) value; cmpCallback.setEntityContext(entity); cmpCallback.ejbActivate(entity); } } //noinspection unchecked return results; }