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 java.util.List;
 
 
 import  com.gemstone.gemfire.cache.Region;

Value object to work with OQL query strings.

Author(s):
Oliver Gierke
David Turanski
 
 class QueryString {
 
 	private static final String REGION_PATTERN = "(?<=\\/)\\w+";
 	private static final String IN_PARAMETER_PATTERN = "(?<=IN (SET|LIST) \\$)\\d";
 	private static final String IN_PATTERN = "(?<=IN (SET|LIST) )\\$\\d";
 
 	private final String query;

Creates a QueryString from the given String query.

Parameters:
source
 
 	public QueryString(String source) {
 
 		Assert.hasText(source);
 		this. = source;
 	}

Creates a SELECT query for the given domain class.

Parameters:
domainClass must not be null.
 
 	public QueryString(Class<?> domainClass) {
 		this(domainClassfalse);
 	}

Creates a SELECT query for the given domain class.

Parameters:
domainClass must not be null.
isCountQuery indicates if this is a count query
 
 	public QueryString(Class<?> domainClassboolean isCountQuery) {
 		this(String
 				.format(isCountQuery ? "SELECT count(*) FROM /%s" : "SELECT * FROM /%s"domainClass.getSimpleName()));
 	}

Replaces the domain classes referenced inside the current query with the given Region.

Parameters:
domainClass must not be null.
region must not be null.
Returns:
 
 	public QueryString forRegion(Class<?> domainClass, Region<?, ?> region) {
 		return new QueryString(.replaceAll(region.getName()));
 	}

Binds the given values to the IN parameter keyword by expanding the given values into a comma-separated String.

Parameters:
values the values to bind, returns the QueryString as is if null is given.
Returns:
 
 	public QueryString bindIn(Collection<?> values) {
 
 		if (values == null) {
 			return this;
 		}
 
 		String valueString = StringUtils.collectionToDelimitedString(values", ""'""'");
 		return new QueryString(.replaceFirst(, String.format("(%s)"valueString)));
	}

Returns the parameter indexes used in this query.

Returns:
the parameter indexes used in this query or an empty Iterable if none are used.
		Pattern pattern = Pattern.compile();
		Matcher matcher = pattern.matcher();
		List<Integerresult = new ArrayList<Integer>();
		while (matcher.find()) {
			result.add(Integer.parseInt(matcher.group()));
		}
		return result;
	}
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return ;
	}
New to GrepCode? Check out our FAQ X