Get the MetadataQueryRRLoadBalancer.

@param query
the ServiceInstanceQuery.
@return
the MetadataQueryRRLoadBalancer.
966923
public MetadataQueryRRLoadBalancer getMetadataQueryRRLoadBalancer(
            ServiceInstanceQuery query) {
        for (MetadataQueryRRLoadBalancer lb : metaQueryLBList) {
            if (lb.getServiceInstanceQuery().equals(query)) {
                return lb;
            }
        }
        MetadataQueryRRLoadBalancer lb = new MetadataQueryRRLoadBalancer(
                lookupService, query);
        metaQueryLBList.add(lb);
        return lb;
    }
1146540
public static DateTime getUniversalTimestamp(final GroupByQuery query)
  {
    final Granularity gran = query.getGranularity();
    final String timestampStringFromContext = query.getContextValue(CTX_KEY_FUDGE_TIMESTAMP, "");

    if (!timestampStringFromContext.isEmpty()) {
      return DateTimes.utc(Long.parseLong(timestampStringFromContext));
    } else if (Granularities.ALL.equals(gran)) {
      final DateTime timeStart = query.getIntervals().get(0).getStart();
      return gran.getIterable(new Interval(timeStart, timeStart.plus(1))).iterator().next().getStart();
    } else {
      return null;
    }
  }
1077179
@Override
    public Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception
    {
        return queryForInstances(name, null);
    }
671824
public static ElDescriptor analyzeQuery(final GenericsContext genericsContext, final String query) {
        final List<String> vars = ElUtils.findVars(query);
        ElDescriptor descriptor = null;
        if (!vars.isEmpty()) {
            descriptor = new ElDescriptor(vars);
            checkGenericVars(descriptor, genericsContext);
        }
        return descriptor;
    }
478774
public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
    {
        ClassDescriptor cld = getClassDescriptor(query.getSearchClass());
        return getReportQueryIteratorFromQuery(query, cld);
    }
753292
@Override
    public Map<String, DbColumnType> getQueryMetadata(Expression query) throws DatabaseEngineException {
        final String queryString = translate(query);
        logger.trace(queryString);
        return getQueryMetadata(queryString);
    }
547840
public static Collection<MonetaryAmountFactory<?>> getAmountFactories(MonetaryAmountFactoryQuery query) {
        return Optional.ofNullable(monetaryAmountsSingletonQuerySpi()).orElseThrow(() -> new MonetaryException(
                "No MonetaryAmountsSingletonQuerySpi loaded, query functionality is not available."))
                .getAmountFactories(query);
    }
1303602
@Override
    public final Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(
            Map<String, List<Object>> query) {
        Validate.notNull(query, "query may not be null.");

        // Generate the query to pass to the subclass
        final LocalAccountQuery queryBuilder = this.generateQuery(query);
        if (queryBuilder == null) {
            this.logger.debug(
                    "No queryBuilder was generated for query " + query + ", null will be returned");

            return null;
        }

        // Get the username from the query, if specified
        final IUsernameAttributeProvider usernameAttributeProvider =
                this.getUsernameAttributeProvider();

        // Execute the query in the subclass
        final List<ILocalAccountPerson> unmappedPeople = localAccountDao.getPeople(queryBuilder);
        if (unmappedPeople == null) {
            return null;
        }

        // Map the attributes of the found people according to resultAttributeMapping if it is set
        final Set<IPersonAttributes> mappedPeople = new LinkedHashSet<IPersonAttributes>();
        for (final ILocalAccountPerson unmappedPerson : unmappedPeople) {
            final IPersonAttributes mappedPerson = this.mapPersonAttributes(unmappedPerson);
            mappedPeople.add(mappedPerson);
        }

        return Collections.unmodifiableSet(mappedPeople);
    }
129296
protected long getCacheDurationForServiceProvider(final SamlRegisteredService service, final MetadataResolver chainingMetadataResolver) {
        try {
            val set = new CriteriaSet();
            set.add(new EntityIdCriterion(service.getServiceId()));
            set.add(new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME));
            val entitySp = chainingMetadataResolver.resolveSingle(set);
            if (entitySp != null && entitySp.getCacheDuration() != null) {
                LOGGER.debug("Located cache duration [{}] specified in SP metadata for [{}]", entitySp.getCacheDuration(), entitySp.getEntityID());
                return TimeUnit.MILLISECONDS.toNanos(entitySp.getCacheDuration());
            }

            set.clear();
            set.add(new EntityIdCriterion(service.getServiceId()));
            val entity = chainingMetadataResolver.resolveSingle(set);
            if (entity != null && entity.getCacheDuration() != null) {
                LOGGER.debug("Located cache duration [{}] specified in entity metadata for [{}]", entity.getCacheDuration(), entity.getEntityID());
                return TimeUnit.MILLISECONDS.toNanos(entity.getCacheDuration());
            }
        } catch (final Exception e) {
            LOGGER.debug(e.getMessage(), e);
        }
        return -1;
    }
193178
public MtasSpanQuery getQuery() throws ParseException {
    simplify();
    if (isBasic()) {
      MtasSpanQuery query;
      if (basicSentence == null) {
        throw new ParseException("no condition");
      } else if (basicSentence.isOptional()) {
        List<MtasSpanSequenceItem> clauses = new ArrayList<MtasSpanSequenceItem>();
        clauses.add(new MtasSpanSequenceItem(basicSentence.getQuery(),
            basicSentence.isOptional()));
        query = new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength);
        if (maximumOccurence > 1) {
          query = new MtasSpanRecurrenceQuery(query, minimumOccurence,
              maximumOccurence, ignore, maximumIgnoreLength);
        }
      } else {
        query = basicSentence.getQuery();
        if (maximumOccurence > 1) {
          query = new MtasSpanRecurrenceQuery(query, minimumOccurence,
              maximumOccurence, ignore, maximumIgnoreLength);
        }
      }
      return query;
    } else if (sequenceList.isEmpty()) {
      throw new ParseException("no condition");
    } else if (isSingle()) {
      return createQuery(sequenceList.get(0));
    } else {
      List<MtasSpanQuery> clauses = new ArrayList<MtasSpanQuery>();
      for (List<MtasCQLParserSentenceCondition> sentenceSequence : sequenceList) {
        clauses.add(createQuery(sentenceSequence));
      }
      return new MtasSpanOrQuery(
          clauses.toArray(new MtasSpanQuery[clauses.size()]));
    }
  }
641282
public String query(String query) {
        try {
            Connection conn = this.tx().getConnection();
            ObjectNode result = this.mapper.createObjectNode();
            ArrayNode dataNode = this.mapper.createArrayNode();
            ArrayNode metaNode = this.mapper.createArrayNode();
            Statement statement = conn.createStatement();
            if (logger.isDebugEnabled()) {
                logger.debug(query);
            }
            ResultSet rs = statement.executeQuery(query);
            ResultSetMetaData rsmd = rs.getMetaData();
            boolean first = true;
            while (rs.next()) {
                int numColumns = rsmd.getColumnCount();
                ObjectNode obj = this.mapper.createObjectNode();
                for (int i = 1; i < numColumns + 1; i++) {
                    String columnName = rsmd.getColumnLabel(i);
                    int type = rsmd.getColumnType(i);
                    //make sure to obtain array using getArray()
                    //At least in H2, this makes a difference...
                    Object o = type == Types.ARRAY ? rs.getArray(i) : rs.getObject(i);
                    this.sqlDialect.putJsonObject(obj, columnName, type, o);
                    if (first) {
                        this.sqlDialect.putJsonMetaObject(this.mapper, metaNode, columnName, type, o);
                    }
                }
                first = false;
                dataNode.add(obj);
            }
            result.set("data", dataNode);
            result.set("meta", metaNode);
            return result.toString();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            this.tx().rollback();
        }
    }
911355
public CqlQuery<K, N, V> setQuery(String query) {
    this.query = StringSerializer.get().toByteBuffer(query);
    return this;
  }
465139
public Object getObjectByQuery(Query query) throws PersistenceBrokerException
    {
        Object result = null;
        if (query instanceof QueryByIdentity)
        {
            // example obj may be an entity or an Identity
            Object obj = query.getExampleObject();
            if (obj instanceof Identity)
            {
                Identity oid = (Identity) obj;
                result = getObjectByIdentity(oid);
            }
            else
            {
                // TODO: This workaround doesn't allow 'null' for PK fields
                if (!serviceBrokerHelper().hasNullPKField(getClassDescriptor(obj.getClass()), obj))
                {
                    Identity oid = serviceIdentity().buildIdentity(obj);
                    result = getObjectByIdentity(oid);
                }
            }
        }
        else
        {
            Class itemClass = query.getSearchClass();
            ClassDescriptor cld = getClassDescriptor(itemClass);
            /*
            use OJB intern Iterator, thus we are able to close used
            resources instantly
            */
            OJBIterator it = getIteratorFromQuery(query, cld);
            /*
            arminw:
            patch by Andre Clute, instead of taking the first found result
            try to get the first found none null result.
            He wrote:
            I have a situation where an item with a certain criteria is in my
            database twice -- once deleted, and then a non-deleted version of it.
            When I do a PB.getObjectByQuery(), the RsIterator get's both results
            from the database, but the first row is the deleted row, so my RowReader
            filters it out, and do not get the right result.
            */
            try
            {
                while (result==null && it.hasNext())
                {
                    result = it.next();
                }
            } // make sure that we close the used resources
            finally
            {
                if(it != null) it.releaseDbResources();
            }
        }
        return result;
    }
199258
public static String getLuceneQueryFromJPAQuery(final KunderaQuery kunderaQuery,
            final KunderaMetadata kunderaMetadata)
    {

        LuceneQueryBuilder queryBuilder = new LuceneQueryBuilder();
        EntityMetadata metadata = kunderaQuery.getEntityMetadata();
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                metadata.getPersistenceUnit());
        Class valueClazz = null;
        EntityType entity = metaModel.entity(metadata.getEntityClazz());
        boolean partitionKeyCheck = true;

        for (Object object : kunderaQuery.getFilterClauseQueue())
        {
            if (object instanceof FilterClause)
            {
                FilterClause filter = (FilterClause) object;
                String property = filter.getProperty();
                String condition = filter.getCondition();
                String valueAsString = filter.getValue().get(0).toString();
                String fieldName = metadata.getFieldName(property);
                boolean isEmbeddedId = metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType());
                String idColumn = ((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName();
                valueClazz = getValueType(entity, fieldName);

                if (isEmbeddedId)
                {
                    if (idColumn.equals(property))
                    {
                        valueAsString = prepareCompositeKey(metadata.getIdAttribute(), metaModel, filter.getValue()
                                .get(0));
                        queryBuilder.appendIndexName(metadata.getIndexName()).appendPropertyName(idColumn)
                                .buildQuery(condition, valueAsString, valueClazz);
                    }
                    else
                    {
                        valueClazz = metadata.getIdAttribute().getBindableJavaType();
                        if (property.lastIndexOf('.') != property.indexOf('.') && partitionKeyCheck)
                        {
                            isCompletePartitionKeyPresentInQuery(kunderaQuery.getFilterClauseQueue(), metaModel,
                                    metadata);
                            partitionKeyCheck = false;
                        }

                        if (metaModel.isEmbeddable(filter.getValue().get(0).getClass()))
                        {
                            prepareLuceneQueryForPartitionKey(queryBuilder, filter.getValue().get(0), metaModel,
                                    metadata.getIndexName(), valueClazz);
                        }
                        else
                        {
                            property = property.substring(property.lastIndexOf(".") + 1);
                            queryBuilder.appendIndexName(metadata.getIndexName())
                                    .appendPropertyName(getPropertyName(metadata, property, kunderaMetadata))
                                    .buildQuery(condition, valueAsString, valueClazz);
                        }
                    }
                }
                else
                {
                    queryBuilder.appendIndexName(metadata.getIndexName())
                            .appendPropertyName(getPropertyName(metadata, property, kunderaMetadata))
                            .buildQuery(condition, valueAsString, valueClazz);
                }
            }
            else
            {
                queryBuilder.buildQuery(object.toString(), object.toString(), String.class);
            }
        }

        queryBuilder.appendEntityName(kunderaQuery.getEntityClass().getCanonicalName().toLowerCase());
        return queryBuilder.getQuery();
    }
990766
def query(self, query):
    '''
    '''
    self.logger.info('%s: query %s' % (self, query))
    return super(LoggingDatastore, self).query(query)
1146661
@Override
    public Collection<MonetaryRounding> getRoundings(RoundingQuery query) {
        List<MonetaryRounding> result = new ArrayList<>();
        Collection<String> providerNames = query.getProviderNames();
        if (providerNames == null || providerNames.isEmpty()) {
            providerNames = getDefaultProviderChain();
        }
        for (String providerName : providerNames) {
            Bootstrap.getServices(RoundingProviderSpi.class).stream()
                    .filter(prov -> providerName.equals(prov.getProviderName())).forEach(prov -> {
                try {
                    MonetaryRounding r = prov.getRounding(query);
                    if (r != null) {
                        result.add(r);
                    }
                } catch (Exception e) {
                    Logger.getLogger(DefaultMonetaryRoundingsSingletonSpi.class.getName())
                            .log(Level.SEVERE, "Error loading RoundingProviderSpi from provider: " + prov, e);
                }
            });
        }
        return result;
    }
738113
@Override
    public <T> T query(MonetaryQuery<T> query) {
        Objects.requireNonNull(query);
        try {
            return query.queryFrom(this);
        } catch (MonetaryException | ArithmeticException e) {
            throw e;
        } catch (Exception e) {
            throw new MonetaryException("Query failed: " + query, e);
        }
    }