当前位置: 首页>>代码示例>>Java>>正文


Java Parameter类代码示例

本文整理汇总了Java中javax.persistence.Parameter的典型用法代码示例。如果您正苦于以下问题:Java Parameter类的具体用法?Java Parameter怎么用?Java Parameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Parameter类属于javax.persistence包,在下文中一共展示了Parameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generate

import javax.persistence.Parameter; //导入依赖的package包/类
private void generate(Date date){
    Parameter<Date> p1 = baseQuery.getParameter("date1", Date.class);
    baseQuery.setParameter(p1, date);
    List<Object[]> results = baseQuery.getResultList();
    for (Object[] result : results){
        DailySales hourlySales = new DailySales();
        hourlySales.setRegionId((Region)result[0]);
        //hourlySales.setEmployeeId(null);
        //hourlySales.setDealerId(null);
        hourlySales.setProductId((Product)result[1]);
        hourlySales.setStateProvCd((String)result[2]);
        hourlySales.setQuantity(((Long)result[3]).intValue());
        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(Calendar.YEAR, (Integer) result[4]);
        cal.set(Calendar.MONTH, (Integer) result[5]-1);
        cal.set(Calendar.DAY_OF_MONTH, (Integer) result[6]);
        hourlySales.setDate(cal.getTime());
        em.persist(hourlySales);
    }
    removeStaleEntries(date);
    
    
    
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:26,代码来源:DailySalesGenerator.java

示例2: findAllRegion

import javax.persistence.Parameter; //导入依赖的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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:23,代码来源:CumulativeLiveSalesFacadeREST.java

示例3: runBaseQuery

import javax.persistence.Parameter; //导入依赖的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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:29,代码来源:DailySalesHeatMapFacadeREST.java

示例4: setParameter

import javax.persistence.Parameter; //导入依赖的package包/类
@Override
public <T> Query setParameter(Parameter<T> par, T value) {
   query = query.setParameter(par, value);

   // try {
   // int position = -1;
   // String name = PARAMETER_NAME_PREFIX;
   // ParameterType ptype = ParameterType.JPA_NAMED_PARAMETER;
   // if (par.getPosition() != null) {
   // position = par.getPosition();
   // name = name + position;
   // ptype = ParameterType.JPA_INDEXED_PARAMETER;
   // } else if (par.getName() != null) {
   // name = par.getName();
   // }
   // ResourceParameter param = new ResourceParameter(name,
   // Object.class.getName(), value, ptype, position);
   // parameters.put(param.getName(), param);
   // } catch (IOException e) {
   // log.error(e.getMessage(), e);
   // throw new IllegalArgumentException(e.getMessage(), e);
   // }

   return this;
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:26,代码来源:CibetQuery.java

示例5: getPositionalParameters

import javax.persistence.Parameter; //导入依赖的package包/类
private static Object[] getPositionalParameters(Query jpaQuery) {
    if (jpaQuery.getParameters() == null) return null;

    int max = 0;
    List<Integer> positions = new ArrayList<>();
    for (Parameter parameter : jpaQuery.getParameters()) {
        if (parameter.getPosition() != null) {
            positions.add(parameter.getPosition());
            if (parameter.getPosition() > max) {
                max = parameter.getPosition();
            }
        }
    }

    if (positions.isEmpty()) return null;

    Object[] positionalParameters = new Object[max];
    positions.forEach(position -> positionalParameters[position - 1] = jpaQuery.getParameterValue(position));
    return positionalParameters;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:QueryKey.java

示例6: runLikeQuery

import javax.persistence.Parameter; //导入依赖的package包/类
@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public <T> List<T> runLikeQuery(Class<T> type, Map<String, Object> likeParam, Map.Entry<String, String> orderBy, EntityManager em) {
    String query = StringUtils.buildLikeQuery(type.getSimpleName(), likeParam, orderBy);

    TypedQuery<T> queryObj = em.createQuery(query, type);

    // 给参数赋值
    Set<Parameter<?>> parmSet = queryObj.getParameters();
    for ( Parameter parm : parmSet) {
        String parmName = parm.getName();
        Object parmValue = likeParam.get(parmName);

        queryObj.setParameter(parmName, parmValue);
    }

    // 执行查询
    List<T> entityList = queryObj
            //.setFirstResult(firstResult)
            //.setMaxResults(CollectionUtils.determineCapacity(capacity))
            .getResultList();

    return entityList;
}
 
开发者ID:wswenyue,项目名称:taolijie,代码行数:25,代码来源:DefaultSearchService.java

示例7: runAccurateQuery

import javax.persistence.Parameter; //导入依赖的package包/类
@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public <T> List<T> runAccurateQuery(Class<T> type, Map<String, Object> likeParam, Map.Entry<String, String> orderBy, EntityManager em) {
    String query = StringUtils.buildQuery("obj", type.getSimpleName(), likeParam, orderBy);

    TypedQuery<T> queryObj = em.createQuery(query, type);

    // 给参数赋值
    Set<Parameter<?>> parmSet = queryObj.getParameters();
    for ( Parameter parm : parmSet) {
        String parmName = parm.getName();
        Object parmValue = likeParam.get(parmName);

        queryObj.setParameter(parmName, parmValue);
    }

    // 执行查询
    List<T> entityList = queryObj
            //.setFirstResult(firstResult)
            //.setMaxResults(CollectionUtils.determineCapacity(capacity))
            .getResultList();

    return entityList;
}
 
开发者ID:wswenyue,项目名称:taolijie,代码行数:25,代码来源:DefaultSearchService.java

示例8: bind

import javax.persistence.Parameter; //导入依赖的package包/类
public static void bind(Query query, Map<String, ?> namedArgs, Object... args) {
	if (args != null) {
		for (int i = 0; i < args.length; i++) {
			query.setParameter(i + 1, args[i]);
		}
	}

	if (namedArgs != null) {
		for (Parameter<?> param : query.getParameters()) {
			String name = param.getName();
			if (U.notEmpty(name)) {
				U.must(namedArgs.containsKey(name), "A named argument wasn't specified for the named JPQL parameter: %s", name);
				query.setParameter(name, Cls.convert(namedArgs.get(name), param.getParameterType()));
			}
		}
	}
}
 
开发者ID:rapidoid,项目名称:rapidoid,代码行数:18,代码来源:JPA.java

示例9: shouldSetParameters

import javax.persistence.Parameter; //导入依赖的package包/类
@Test
public void shouldSetParameters() {
	Filter filter = new Filter();
	filter.addCondition("testKey", Operator.eq, "testValue");
	filter.addCondition("testKey1", Operator.eq, "testValue1");
	Path path = mock(Path.class);
	when(path.getJavaType()).thenReturn(String.class);
	filter.getConditions().get(0).setPath(path);
	filter.getConditions().get(1).setPath(path);
	Query query = mock(Query.class);
	Parameter param = mock(Parameter.class);
	when(param.getParameterType()).thenReturn(String.class);
	when(query.getParameter(anyString())).thenReturn(param);
	filter.setParameters(query);
	verify(query).setParameter("testKey", "testValue");
	verify(query).setParameter("testKey1", "testValue1");
}
 
开发者ID:ActiveJpa,项目名称:activejpa,代码行数:18,代码来源:FilterTest.java

示例10: removeStaleEntries

import javax.persistence.Parameter; //导入依赖的package包/类
private void removeStaleEntries(Date date){
    Parameter<Date> p1 = removeQuery.getParameter("date1", Date.class);
    removeQuery.setParameter(p1, date);
    for (SalesOrder so : removeQuery.getResultList()){
        for (SalesOrderLine sol : so.getSalesOrderLineCollection())
            em.remove(sol);
        em.remove(so);
    } 
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:10,代码来源:DailySalesGenerator.java

示例11: findRegionRange

import javax.persistence.Parameter; //导入依赖的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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:32,代码来源:CumulativeLiveSalesFacadeREST.java

示例12: findStateRange

import javax.persistence.Parameter; //导入依赖的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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:34,代码来源:CumulativeLiveSalesFacadeREST.java

示例13: findInternational

import javax.persistence.Parameter; //导入依赖的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();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:11,代码来源:RegionFacadeREST.java

示例14: findFrom

import javax.persistence.Parameter; //导入依赖的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();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:10,代码来源:LiveSalesListFacadeREST.java

示例15: runProductTypeQuery

import javax.persistence.Parameter; //导入依赖的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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:33,代码来源:DailySalesHeatMapFacadeREST.java


注:本文中的javax.persistence.Parameter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。