Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.springframework.data.gemfire.repository.query;
 
 
 
 import  com.gemstone.gemfire.cache.query.internal.ResultsBag;

GemfireRepositoryQuery using plain String based OQL queries.

Author(s):
Oliver Gierke
David Turanski
 
 
 	private static final String INVALID_EXECUTION = "Paging and modifying queries are not supported!";
 
 	private final QueryString query;
 	private final GemfireQueryMethod method;
 	private final GemfireTemplate template;

Creates a new StringBasedGemfireRepositoryQuery using the given GemfireQueryMethod and GemfireTemplate. The actual query String will be looked up from the query method.

Parameters:
method must not be null.
template must not be null.
 
 		this(method.getAnnotatedQuery(), methodtemplate);
 	}

Creates a new StringBasedGemfireRepositoryQuery using the given query String, GemfireQueryMethod and GemfireTemplate.

Parameters:
query will fall back to the query annotated to the given GemfireQueryMethod if null is given.
method must not be null.
template must not be null.
 
 
 		super(method);
 
 		Assert.notNull(template);
 
 		this. = new QueryString(StringUtils.hasText(query) ? query : method.getAnnotatedQuery());
 		this. = method;
 		this. = template;
 
 		if (method.isPageQuery() || method.isModifyingQuery()) {
 		}
 	}
 
 	/* 
 	 * (non-Javadoc)
 	 * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
 	 */
 	public Object execute(Object[] parameters) {
 
 
 		Iterator<Integerindexes = query.getInParameterIndexes().iterator();
 		while (indexes.hasNext()) {
 			query = query.bindIn(toCollection(accessor.getBindableValue(indexes.next() - 1)));
 		}
 
 		Collection<?> result = toCollection(.find(query.toString(), parameters));
 
 			return result;
 		} else if (.isQueryForEntity()) {
			if (result.isEmpty()) {
				return null;
else if (result.size() == 1) {
				return result.iterator().next();
else {
			}
else {
			throw new IllegalStateException("Unsupported query: " + query.toString());
		}
	}

Returns the given object as collection. Collections will be returned as is, Arrays will be converted into a collection and all other objects will be wrapped into a single-element collection.

Parameters:
source
Returns:
	private Collection<?> toCollection(Object source) {
		if (source instanceof ResultsBag) {
			ResultsBag bag = (ResultsBag) source;
			return bag.asList();
		}
		if (source instanceof Collection) {
			return (Collection<?>) source;
		}
		return source.getClass().isArray() ? CollectionUtils.arrayToList(source) : Collections.singleton(source);
	}
New to GrepCode? Check out our FAQ X