/* * (non-Javadoc) * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[]) */ @Override public Object execute(Object[] parameters) { ParametersParameterAccessor accessor = new ParametersParameterAccessor(method.getParameters(), parameters); QueryString query = (isUserDefinedQuery() ? this.query : this.query.forRegion( method.getEntityInformation().getJavaType(), template.getRegion())); for (Integer index : query.getInParameterIndexes()) { query = query.bindIn(toCollection(accessor.getBindableValue(index - 1))); } Collection<?> result = toCollection(template.find(query.toString(), parameters)); if (method.isCollectionQuery()) { return result; } else if (method.isQueryForEntity()) { if (result.isEmpty()) { return null; } else if (result.size() == 1) { return result.iterator().next(); } else { throw new IncorrectResultSizeDataAccessException(1, result.size()); } } else { throw new IllegalStateException("Unsupported query: " + query.toString()); } }
/** * Creates a new {@link StringBasedGemfireRepositoryQuery} using the given query {@link String}, * {@link GemfireQueryMethod} and {@link GemfireTemplate}. * * @param query will fall back to the query annotated to the given {@link GemfireQueryMethod} if * {@literal null}. * @param method must not be {@literal null}. * @param template must not be {@literal null}. */ public StringBasedGemfireRepositoryQuery( String query, GemfireQueryMethod method, GemfireTemplate template) { super(method); Assert.notNull(template); this.userDefinedQuery |= !StringUtils.hasText(query); this.query = new QueryString(StringUtils.hasText(query) ? query : method.getAnnotatedQuery()); this.method = method; this.template = template; if (method.isPageQuery() || method.isModifyingQuery()) { throw new IllegalStateException(INVALID_QUERY); } }
/** * Creates a new {@link StringBasedGemfireRepositoryQuery} using the given {@link * GemfireQueryMethod} and {@link GemfireTemplate}. The actual query {@link String} will be looked * up from the query method. * * @param method must not be {@literal null}. * @param template must not be {@literal null}. */ public StringBasedGemfireRepositoryQuery(GemfireQueryMethod method, GemfireTemplate template) { this(method.getAnnotatedQuery(), method, template); }