javax.persistence.Query.getParameters()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(420)

本文整理了Java中javax.persistence.Query.getParameters方法的一些代码示例,展示了Query.getParameters的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getParameters方法的具体详情如下:
包路径:javax.persistence.Query
类名称:Query
方法名:getParameters

Query.getParameters介绍

[英]Get the parameter objects corresponding to the declared parameters of the query. Returns empty set if the query has no parameters. This method is not required to be supported for native queries.
[中]获取与查询的已声明参数相对应的参数对象。如果查询没有参数,则返回空集。本机查询不需要支持此方法。

代码示例

代码示例来源:origin: spring-projects/spring-data-jpa

private boolean registerExcessParameters(Query query) {
  // DATAJPA-1172
  // Since EclipseLink doesn't reliably report whether a query has parameters
  // we simply try to set the parameters and ignore possible failures.
  // this is relevant for native queries with SpEL expressions, where the method parameters don't have to match the
  // parameters in the query.
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=521915
  return query.getParameters().size() == 0 && unwrapClass(query).getName().startsWith("org.eclipse");
}

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * Returns whether the given {@link Query} contains named parameters.
 *
 * @param query Must not be {@literal null}.
 * @return whether the given {@link Query} contains named parameters.
 */
public static boolean hasNamedParameter(Query query) {
  Assert.notNull(query, "Query must not be null!");
  for (Parameter<?> parameter : query.getParameters()) {
    String name = parameter.getName();
    // Hibernate 3 specific hack as it returns the index as String for the name.
    if (name != null && NO_DIGITS.matcher(name).find()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: rapidoid/rapidoid

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()));
      }
    }
  }
}

代码示例来源:origin: spring-projects/spring-data-jpa

&& (query.getParameters().size() >= parameter.getPosition() //
&& (query.getParameters().size() >= position //

代码示例来源:origin: Impetus/Kundera

@Override
public Set<Parameter<?>> getParameters()
{
  return query.getParameters();
}

代码示例来源:origin: my2iu/Jinq

private void logQuery(String queryString, Query q)
{
 if (hints.queryLogger == null) return;
 Map<Integer, Object> positionParams = new HashMap<Integer, Object>();
 Map<String, Object> namedParams = new HashMap<String, Object>();
 for (Parameter<?> param: q.getParameters())
 {
   if (param.getName() != null)
    namedParams.put(param.getName(), q.getParameterValue(param));
   if (param.getPosition() != null)
    positionParams.put(param.getPosition(), q.getParameterValue(param));
 }
 hints.queryLogger.logQuery(queryString, positionParams, namedParams);
}

代码示例来源:origin: spring-projects/spring-integration

Set<Parameter<?>> parameters = query.getParameters();

代码示例来源:origin: de.mhus.lib/mhu-lib-persistence

/** {@inheritDoc} */
@Override
public Set<Parameter<?>> getParameters() {
  return query.getParameters();
}

代码示例来源:origin: org.apache.geronimo.modules/geronimo-persistence-jpa20

@Override
public Set<Parameter<?>> getParameters() {
  return query.getParameters();
}

代码示例来源:origin: org.evolvis.bsi/kolab-ws

@Override
public Set<Parameter<?>>
getParameters()
{
  return delegate.getParameters();
}

代码示例来源:origin: Blazebit/blaze-persistence

@Override
public Set<Parameter<?>> getParameters() {
  return query.getParameters();
}

代码示例来源:origin: com.kumuluz.ee/kumuluzee-jpa-common

@Override
public Set<Parameter<?>> getParameters() {
  return query.getParameters();
}

代码示例来源:origin: kumuluz/kumuluzee

@Override
public Set<Parameter<?>> getParameters() {
  return query.getParameters();
}

代码示例来源:origin: org.wildfly/wildfly-jpa

@Override
public Set<Parameter<?>> getParameters() {
  return underlyingQuery.getParameters();
}

代码示例来源:origin: org.polyforms/polyforms-repository

private javax.persistence.Parameter<?>[] getQueryParameters(final Query query) {
  final javax.persistence.Parameter<?>[] parameters = query.getParameters().toArray(EMPTY_QUERY_PARAMETERS);
  Arrays.sort(parameters, COMPARATOR);
  return parameters;
}

代码示例来源:origin: org.springframework.data/spring-data-jpa

private boolean registerExcessParameters(Query query) {
  // DATAJPA-1172
  // Since EclipseLink doesn't reliably report whether a query has parameters
  // we simply try to set the parameters and ignore possible failures.
  // this is relevant for native queries with SpEL expressions, where the method parameters don't have to match the
  // parameters in the query.
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=521915
  return query.getParameters().size() == 0 && unwrapClass(query).getName().startsWith("org.eclipse");
}

代码示例来源:origin: Blazebit/blaze-persistence

private void bindListParameters(Query q) {
    for (Parameter<?> parameter : q.getParameters()) {
      Collection<?> value = listParameters.get(parameter.getName());
      if (value != null) {
        q.setParameter((Parameter) parameter, value);
      }
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

private static Map<String, Object> getNamedParameters(Query jpaQuery) {
  if (jpaQuery.getParameters() == null) return null;
  List<String> names = new ArrayList<>();
  Map<String, Object> namedParameters = new LinkedHashMap<>();
  jpaQuery.getParameters().stream()
      .filter(parameter -> parameter.getName() != null)
      .forEach(parameter -> names.add(parameter.getName()));
  if (names.isEmpty()) return null;
  names.stream()
      .sorted()
      .forEach(name -> namedParameters.put(name, jpaQuery.getParameterValue(name)));
  return namedParameters;
}

代码示例来源:origin: org.glassfish.main.common/container-common

public Set<Parameter<?>> getParameters() {
  try {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryStart(EntityManagerQueryMethod.GET_PARAMETERS);
    }
    return queryDelegate.getParameters();
  } finally {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryEnd();
    }
  }
}

代码示例来源:origin: org.glassfish.common/container-common

public Set<Parameter<?>> getParameters() {
  try {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryStart(EntityManagerQueryMethod.GET_PARAMETERS);
    }
    Query delegate = getQueryDelegate();
    return delegate.getParameters();
  } finally {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerQueryEnd();
    }
  }
}

相关文章