本文整理汇总了Java中javax.persistence.Query.getParameter方法的典型用法代码示例。如果您正苦于以下问题:Java Query.getParameter方法的具体用法?Java Query.getParameter怎么用?Java Query.getParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.Query
的用法示例。
在下文中一共展示了Query.getParameter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAllRegion
import javax.persistence.Query; //导入方法依赖的package包/类
@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;
}
示例2: runBaseQuery
import javax.persistence.Query; //导入方法依赖的package包/类
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;
}
示例3: findRegionRange
import javax.persistence.Query; //导入方法依赖的package包/类
@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;
}
示例4: findStateRange
import javax.persistence.Query; //导入方法依赖的package包/类
@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;
}
示例5: findInternational
import javax.persistence.Query; //导入方法依赖的package包/类
@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();
}
示例6: findFrom
import javax.persistence.Query; //导入方法依赖的package包/类
@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();
}
示例7: runProductTypeQuery
import javax.persistence.Query; //导入方法依赖的package包/类
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;
}