Adds parameterised query with given name into collection. Throws
exception if duplicate name is provided.

@param queryName
query name.
@param query
named/native query.
@param isNativeQuery
true, if it is a namednativequery.
339602
public void addQueryToCollection(String queryName, String query, boolean isNativeQuery, Class clazz)
    {
        if (namedNativeQueries == null)
        {
            namedNativeQueries = new ConcurrentHashMap<String, QueryWrapper>();
        }
        if (!namedNativeQueries.containsKey(queryName))
        {
            namedNativeQueries.put(queryName, new QueryWrapper(queryName, query, isNativeQuery, clazz));
        }
        // No null check made as it will never hold null value
        else if (queryName != null && !getQuery(queryName).equals(query))
        {
            logger.error("Duplicate named/native query with name:" + queryName
                    + "found! Already there is a query with same name:" + namedNativeQueries.get(queryName));
            throw new ApplicationLoaderException("Duplicate named/native query with name:" + queryName
                    + "found! Already there is a query with same name:" + namedNativeQueries.get(queryName));
        }
    }
586170
public Api getQueryResult(String query) throws Exception {
    Api result = this.getActionResult("query", query, null, null);
    return result;
  }
1319662
@Override
    public final Query createNativeQuery(String sqlString, Class resultClass)
    {
        checkClosed();
        checkTransactionNeeded();

        return getPersistenceDelegator().createNativeQuery(sqlString, resultClass);
    }
178348
@Override
    public final Query createNativeQuery(String sqlString)
    {
        checkClosed();
        return getPersistenceDelegator().createQuery(sqlString, getPersistenceUnit());
    }
482090
public SQLQuery getQueryInstance(String nativeQuery, EntityMetadata m)
    {
        s = getStatelessSession();

        SQLQuery q = s.createSQLQuery(nativeQuery).addEntity(m.getEntityClazz());

        List<String> relations = m.getRelationNames();
        if (relations != null)
        {
            for (String r : relations)
            {
                Relation rel = m.getRelation(m.getFieldName(r));
                String name = MetadataUtils.getMappedName(m, m.getRelation(r), kunderaMetadata);
                if (!((AbstractAttribute) m.getIdAttribute()).getJPAColumnName().equalsIgnoreCase(
                        name != null ? name : r)
                        && rel != null
                        && !rel.getProperty().isAnnotationPresent(ManyToMany.class)
                        && !rel.getProperty().isAnnotationPresent(OneToMany.class)
                        && (rel.getProperty().isAnnotationPresent(OneToOne.class)
                                && StringUtils.isBlank(rel.getMappedBy()) || rel.getProperty().isAnnotationPresent(
                                ManyToOne.class)))
                {
                    q.addScalar(name != null ? name : r);
                }
            }
        }
        return q;
    }
1304723
public void setQuery( String query )
    {
        _parameters = null;

        if ( query == null || query.length() == 0 ) { return; }

        for ( StringTokenizer tok = new StringTokenizer( query, "&" ); tok.hasMoreElements(); )
        {
            String queryItem = tok.nextToken();

            if ( queryItem.startsWith( "amp;" ) )
            {
                queryItem = queryItem.substring( 4 );
            }

            int eq = queryItem.indexOf( '=' );
            if ( eq != -1 )
            {
                addParameter( queryItem.substring( 0, eq ) , queryItem.substring( eq + 1 ), true );
            }
            else
            {
                addParameter( queryItem, null, true );
            }
        }
    }
1141654
public ApiResponse<QueryResponse> executeQueryPostWithHttpInfo(Query query) throws ApiException {
        com.squareup.okhttp.Call call = executeQueryPostValidateBeforeCall(query, null, null);
        Type localVarReturnType = new TypeToken<QueryResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
982656
private void addNamedNativeQueryMetadata(Class clazz)
    {
        ApplicationMetadata appMetadata = kunderaMetadata.getApplicationMetadata();
        String name, query = null;
        if (clazz.isAnnotationPresent(NamedQuery.class))
        {
            NamedQuery ann = (NamedQuery) clazz.getAnnotation(NamedQuery.class);
            appMetadata.addQueryToCollection(ann.name(), ann.query(), false, clazz);
        }

        if (clazz.isAnnotationPresent(NamedQueries.class))
        {
            NamedQueries ann = (NamedQueries) clazz.getAnnotation(NamedQueries.class);

            NamedQuery[] anns = ann.value();
            for (NamedQuery a : anns)
            {
                appMetadata.addQueryToCollection(a.name(), a.query(), false, clazz);
            }
        }

        if (clazz.isAnnotationPresent(NamedNativeQuery.class))
        {
            NamedNativeQuery ann = (NamedNativeQuery) clazz.getAnnotation(NamedNativeQuery.class);
            appMetadata.addQueryToCollection(ann.name(), ann.query(), true, clazz);
        }

        if (clazz.isAnnotationPresent(NamedNativeQueries.class))
        {
            NamedNativeQueries ann = (NamedNativeQueries) clazz.getAnnotation(NamedNativeQueries.class);

            NamedNativeQuery[] anns = ann.value();
            for (NamedNativeQuery a : anns)
            {
                appMetadata.addQueryToCollection(a.name(), a.query(), true, clazz);
            }
        }
    }
587444
@Override
  protected void configureQuery(@SuppressWarnings("rawtypes") AbstractQuery query, Resource resource) {
    Context.getCommandContext()
      .getAuthorizationManager()
      .configureQuery(query, resource);
  }
653270
public void setQuery(String query) {

        try {
            m_parameters.setQuery(CmsEncoder.decodeParameter(query));
        } catch (CmsIllegalArgumentException iae) {
            m_lastException = iae;
        }
        resetLastResult();
    }
227380
@NonNull
    public Expression match(@NonNull String query) {
        if (query == null) {
            throw new IllegalArgumentException("query is null.");
        }
        return new FullTextMatchExpression(this.name, query);
    }
252418
private void processQuery() throws SQLException {
		if (preparedStatement != null) {
			return;
		}

		if (query == null) {
			throw new RuntimeException("Invalid NamedParameterStatement: no query!");
		}

		logger.debug("Orig Query: {}", query);
		StringBuffer builder = new StringBuffer();

		String queryByPlugin = query;
		for (INpsPlugin plugin : plugins) {
			queryByPlugin = plugin.process(queryByPlugin, params);
			if (logger.isDebugEnabled()) {
				logger.debug("Apply plugin: name=[{}] query=[{}] params={}",
					plugin.getClass().getSimpleName(), queryByPlugin, params);
			}
		}

		Matcher matcher = PARAM_PATTERN.matcher(queryByPlugin);
		int noOfParams = 0;
		while (matcher.find()) {
			if (matcher.group(4) != null) {
				noOfParams++;
				String param = matcher.group("PARAM");
				logger.debug("Param: {}", param);
				if (!paramsPlacement.containsKey(param)) {
					paramsPlacement.put(param, new ArrayList<>());
				}
				paramsPlacement.get(param).add(noOfParams);

				Object paramValue = params.get(param);
				StringBuilder paramReplacementBuilder = new StringBuilder("?");
				if (paramValue != null && (paramValue instanceof Collection || paramValue.getClass().isArray())) {
					int size = paramValue instanceof Collection ?
						((Collection) paramValue).size() :
						((Object[]) paramValue).length;
					for (int i = 1; i < size; i++) {
						paramReplacementBuilder.append(",?");
					}
				}
				matcher.appendReplacement(builder, paramReplacementBuilder.toString());
			}
		}
		matcher.appendTail(builder);
		finalQuery = builder.toString();

		logger.debug("Final SQL: {}", finalQuery);
		logger.debug("Number of params: {}", noOfParams);

		if (!ignoreExtraPassedParam) {
			for (String param : params.keySet()) {
				if (!paramsPlacement.containsKey(param)) {
					throw new SQLException("Passed parameter not found: " + param);
				}
			}
		}

		preparedStatement = connection.prepareStatement(finalQuery);
		if (fetchSize != null) {
			preparedStatement.setFetchSize(fetchSize);
		}

		if (queryTimeout != null) {
			preparedStatement.setQueryTimeout(queryTimeout);
		}

		if (maxRows != null) {
			preparedStatement.setMaxRows(maxRows);
		}

		builder = new StringBuffer();
		matcher = PARAM_Q_MARK_PATTERN.matcher(finalQuery);
		int idx = 1;
		while (matcher.find()) {
			if (matcher.group("QMARK") != null) {
				String replacement = String.format(" ?%s ", idx++);
				matcher.appendReplacement(builder, replacement);
			}
		}
		matcher.appendTail(builder);

		finalIndexedQuery = builder.toString();
	}
728175
@Override
    public synchronized int executeUpdate(final String query) throws DatabaseEngineException {
        Statement s = null;
        try {
            getConnection();
            s = conn.createStatement();
            return s.executeUpdate(query);
        } catch (final Exception ex) {
            throw new DatabaseEngineException("Error handling native query", ex);
        } finally {
            if (s != null) {
                try {
                    s.close();
                } catch (final Exception e) {
                    logger.trace("Error closing statement.", e);
                }
            }
        }
    }
982398
public URIBuilder setQuery(final String query) {
		 this.queryParams = parseQuery(query, Consts.UTF_8);
		 this.encodedQuery = null;
		 this.encodedSchemeSpecificPart = null;
		 return this;
	 }
21567
public void addNamedQueryParameter(String name, Object value) {
        parameters.put(checkNotNull(name), checkNotNull(value));
    }
6830
public SparqlResult runQuery(String endpoint, String query) {
    return SparqlClient.execute(endpoint, query, username, password);
  }
53218
public List queryMultiObject(Collection queryParams, String sqlquery) throws Exception {
		JdbcTemp jdbcTemp = new JdbcTemp(dataSource);
		return jdbcTemp.queryMultiObject(queryParams, sqlquery);
	}