org.hibernate.Query.getNamedParameters()方法的使用及代码示例

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

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

Query.getNamedParameters介绍

[英]Return the names of all named parameters of the query.
[中]返回查询的所有命名参数的名称。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

qu.getNamedParameters();

代码示例来源:origin: ezbz/projectx

@Override
public String[] getNamedParameters() throws HibernateException {
 return query.getNamedParameters();
}

代码示例来源:origin: riotfamily/riot

public String[] getNamedParameters() throws HibernateException {
  return query.getNamedParameters();
}

代码示例来源:origin: com.github.cafdataprocessing/corepolicy-hibernate

@Override
public String[] getNamedParameters() {
  return query.getNamedParameters();
}

代码示例来源:origin: mifos/head

private void setArgsOnNamedQuery(Object[] queryArgs, Query namedQuery) {
  if(queryArgs != null) {
    String[] namedParameters = namedQuery.getNamedParameters();
    for(int i = 0; i < queryArgs.length; i++) {
      Object arg = queryArgs[i];
      if(arg instanceof Collection) {
        namedQuery.setParameterList(namedParameters[i], (Collection) arg);
      } else {
        namedQuery.setParameter(namedParameters[i], arg);
      }
    }
  }
}

代码示例来源:origin: riotfamily/riot

@Override
protected void setQueryParameters(Query query, Object parent, 
    ListParams params) {
  
  super.setQueryParameters(query, parent, params);
  if (parent != null) {
    for (String param : query.getNamedParameters()) {
      Matcher m = Pattern.compile("parent(?:_(\\w+))?").matcher(param);
      if (m.matches()) {
        Object value = parent;
        String nested = m.group(1);
        if (nested != null) {
          value = PropertyUtils.getProperty(parent, nested);
        }
        query.setParameter(param, value);
      }
    }
  }
}

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

public static void setParams(Query query, Object beanOrMap) {
  String[] nps = query.getNamedParameters();
  if (nps != null) {
    Map<String, Object> params = toParams(beanOrMap);
    for (String key : nps) {
      Object arg = params.get(key);
      if (arg == null) {
        query.setParameter(key, null);
      } else if (arg.getClass().isArray()) {
        query.setParameterList(key, (Object[]) arg);
      } else if (arg instanceof Collection) {
        query.setParameterList(key, ((Collection) arg));
      } else if (arg.getClass().isEnum()) {
        query.setParameter(key, ((Enum) arg).ordinal());
      } else {
        query.setParameter(key, arg);
      }
    }
  }
}

代码示例来源:origin: riotfamily/riot

@Override
protected void setQueryParameters(Query query, Object parent, 
    ListParams params) {
  
  super.setQueryParameters(query, parent, params);
  if (parent != null) {
    for (String param : query.getNamedParameters()) {
      Matcher m = Pattern.compile("parent(?:_(\\w+))?").matcher(param);
      if (m.matches()) {
        Object value = parent;
        String nested = m.group(1);
        if (nested != null) {
          value = PropertyUtils.getProperty(parent, nested);
        }
        query.setParameter(param, value);
      }
    }
  }
}

代码示例来源:origin: com.github.vsspt/db-generic-dao-spring-hibernate

@Override
public List<?> executeQuery(final String queryId, final Parameter... params) {
 LOG.debug("Executing on [{}], Query with ID [{}].", className, queryId);
 final Query query = getSession().getNamedQuery(queryId);
 final List<String> parameters = Arrays.asList(query.getNamedParameters());
 for (final Parameter param : params) {
  if (parameters.contains(param.getKey())) {
   query.setParameter(param.getKey(), param.getValue());
  }
 }
 final List<?> results = query.list();
 LOG.debug("Query with ID [{}] returned [{}] results.", queryId, results.size());
 return results;
}

代码示例来源:origin: com.github.vsspt/db-generic-dao-spring-hibernate

@SuppressWarnings("unchecked")
@Override
public List<T> execute(final String queryId, final Parameter... params) {
 LOG.debug("Executing on [{}], Query with ID [{}].", className, queryId);
 final Query query = getSession().getNamedQuery(queryId);
 final List<String> parameters = Arrays.asList(query.getNamedParameters());
 for (final Parameter param : params) {
  if (parameters.contains(param.getKey())) {
   query.setParameter(param.getKey(), param.getValue());
  }
 }
 final List<T> results = query.list();
 LOG.debug("Query with ID [{}] returned [{}] results.", queryId, results.size());
 return results;
}

代码示例来源:origin: mifos/head

@Override
public List<T> execFindQuery(String qryMethodName, Object[] queryArgs) {
  Query namedQuery = getSession().getNamedQuery(type.getSimpleName() + "." + qryMethodName);
  if (namedQuery.getNamedParameters().length == 0) {
    setParamsOnNamedQuery(queryArgs, namedQuery);
  } else {
    setArgsOnNamedQuery(queryArgs, namedQuery);
  }
  return namedQuery.list();
}

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

if ( query.getNamedParameters().length>0 ) {
  query.setParameter( 
      query.getNamedParameters()[0], 
      id, 
      persister.getIdentifierType()

代码示例来源:origin: omero/server

+ e.getMessage());
String[] nParams = query.getNamedParameters();
for (int i = 0; i < nParams.length; i++) {
  String p = nParams[i];

相关文章