public class QueryString extends Object
QueryString is a base class used to construct and model syntactically valid Apache Geode
OQL query statements.
QueryString uses Pattern based recognition and matching to parse and modify
the OQL query statement.
This is an internal class used by the SDG Repository infrastructure extension.Matcher,
Pattern,
Region,
Sort,
OqlKeyword,
Repository| Modifier and Type | Field and Description |
|---|---|
protected static String |
COUNT_PROJECTION |
protected static String |
COUNT_QUERY
Deprecated.
use
COUNT_PROJECTION. |
protected static Pattern |
HINT_PATTERN |
protected static String |
HINTS_OQL_TEMPLATE |
protected static String |
IMPORT_OQL_TEMPLATE |
protected static Pattern |
IMPORT_PATTERN |
protected static String |
IN_PARAMETER_PATTERN |
protected static String |
IN_PATTERN |
protected static String |
IN_VALUES_TEMPLATE |
protected static String |
LIMIT_OQL_TEMPLATE |
protected static Pattern |
LIMIT_PATTERN |
protected static String |
REGION_PATTERN |
protected static String |
SELECT_OQL_TEMPLATE |
protected static String |
STAR_PROJECTION |
protected static String |
STAR_QUERY
Deprecated.
use
STAR_PROJECTION. |
protected static String |
TRACE_OQL_TEMPLATE |
protected static Pattern |
TRACE_PATTERN |
| Constructor and Description |
|---|
QueryString(Class<?> domainType)
Constructs a new instance of
QueryString initialized with the given
application domain model type used to construct an OQL SELECT query statement. |
QueryString(Class<?> domainType,
boolean asCountQuery)
Constructs a new instance of
QueryString initialized with the given
application domain model type, which is used to construct an OQL SELECT query statement. |
QueryString(String query)
Constructs a new instance of
QueryString initialized with the given OQL query. |
| Modifier and Type | Method and Description |
|---|---|
QueryString |
adjustLimit(Integer limit)
|
QueryString |
asDistinct()
Replaces an OQL SELECT query with an OQL SELECT DISTINCT query if the
query
is not already distinct; i.e. does not contain the DISTINCT OQL keyword. |
QueryString |
bindIn(Collection<?> values)
Binds the given
Collection of values into the first IN parameter of the OQL Query
(String) by expanding the given values into a comma-separated list. |
static QueryString |
count(Class<?> domainType)
Factory method used to construct a new instance of
QueryString that creates an OQL query
to count the number of objects of the specified application domain model type. |
static QueryString |
from(Class<?> domainType)
Factory method used to construct a new instance of
QueryString initialized with the given
application domain model type from which the OQL query will be created. |
QueryString |
fromRegion(Class<?> domainType,
org.apache.geode.cache.Region<?,?> region)
Deprecated.
|
QueryString |
fromRegion(org.apache.geode.cache.Region<?,?> region,
Class<?> domainType)
|
protected static String |
getDigitsOnly(String value)
Null-safe method used to extract digits from the given
String value as a whole number. |
Iterable<Integer> |
getInParameterIndexes()
Returns the parameter indexes used in this query.
|
int |
getLimit()
Gets the LIMIT number.
|
protected String |
getQuery()
Returns the
OQL query statement from which this QueryString was constructed. |
boolean |
isLimited()
Determines whether a LIMIT is present in the OQL query.
|
static QueryString |
of(String query)
Factory method used to construct a new instance of
QueryString initialized with
the given OQL query statement. |
QueryString |
orderBy(Sort sort)
Appends the
Sort order to this GemFire OQL Query string. |
String |
toString()
Returns a
String representation of this QueryString. |
QueryString |
withHints(String... hints)
Applies HINTS to the OQL Query.
|
QueryString |
withImport(String importExpression)
Applies an IMPORT to the OQL Query.
|
QueryString |
withLimit(Integer limit)
Applies a LIMIT to the OQL Query.
|
QueryString |
withTrace()
Applies TRACE logging to the OQL Query.
|
protected static final Pattern HINT_PATTERN
protected static final Pattern IMPORT_PATTERN
protected static final Pattern LIMIT_PATTERN
protected static final Pattern TRACE_PATTERN
protected static final String HINTS_OQL_TEMPLATE
protected static final String IMPORT_OQL_TEMPLATE
protected static final String LIMIT_OQL_TEMPLATE
protected static final String SELECT_OQL_TEMPLATE
protected static final String TRACE_OQL_TEMPLATE
protected static final String COUNT_PROJECTION
protected static final String IN_PATTERN
protected static final String IN_PARAMETER_PATTERN
protected static final String IN_VALUES_TEMPLATE
protected static final String REGION_PATTERN
protected static final String STAR_PROJECTION
@Deprecated protected static final String COUNT_QUERY
COUNT_PROJECTION.@Deprecated protected static final String STAR_QUERY
STAR_PROJECTION.public QueryString(@NonNull String query)
QueryString initialized with the given OQL query.query - String containing the OQL query.IllegalArgumentException - if query is null or empty.validateQuery(String),
Stringpublic QueryString(@NonNull Class<?> domainType)
QueryString initialized with the given
application domain model type used to construct an OQL SELECT query statement.domainType - application domain model type to query; must not be null.IllegalArgumentException - if the application domain model type is null.QueryString(Class, boolean)public QueryString(@NonNull Class<?> domainType, boolean asCountQuery)
QueryString initialized with the given
application domain model type, which is used to construct an OQL SELECT query statement.
asCountQuery is a Boolean flag indicating whether to select a count or select the contents
of the objects for the given applicatlion domain model type.domainType - application domain model type to query; must not be null.asCountQuery - boolean value to indicate if this is a select count query.IllegalArgumentException - if the application domain model type is null.asQuery(Class, boolean),
QueryString(String)public static QueryString of(@NonNull String query)
QueryString initialized with
the given OQL query statement.query - String containing the OQL query.QueryString initialized with the given query.IllegalArgumentException - if query is null or empty.QueryString(String)public static QueryString from(@NonNull Class<?> domainType)
QueryString initialized with the given
application domain model type from which the OQL query will be created.domainType - application domain model type for which the OQL query
will be created.QueryString for the given application domain model type.IllegalArgumentException - if application domain model type is null.QueryString(Class)public static QueryString count(Class<?> domainType)
QueryString that creates an OQL query
to count the number of objects of the specified application domain model type.domainType - application domain model type for which the OQL query will be created.QueryString.IllegalArgumentException - if application domain model type is null.QueryString(Class)protected static String getDigitsOnly(@Nullable String value)
String value as a whole number.value - String to evaluate.String value as a whole number
or an empty String if the given String is null, empty
or contains no digits.Stringpublic boolean isLimited()
getLimit()public Iterable<Integer> getInParameterIndexes()
public int getLimit()
isLimited() to determine whether the OQL query statement has a LIMIT.Integer value containing the LIMIT number or Integer.MAX_VALUE
if the OQL query statement is not limited.isLimited()@NonNull protected String getQuery()
OQL query statement from which this QueryString was constructed.OQL query; never null or empty.public QueryString adjustLimit(@Nullable Integer limit)
limit - Integer value specifying the new query LIMIT.QueryString with the adjusted query LIMIT.withLimit(Integer)public QueryString asDistinct()
query
is not already distinct; i.e. does not contain the DISTINCT OQL keyword.query if the query does not contain
the DISTINCT OQL keyword.asDistinct(String)@NonNull public QueryString bindIn(@NonNull Collection<?> values)
Collection of values into the first IN parameter of the OQL Query
(String) by expanding the given values into a comma-separated list.values - Collection of values to bind; must not be null or empty.QueryString having IN parameter bound with values
or returns this QueryString if the Collection of values is null or empty.Collectionpublic QueryString fromRegion(org.apache.geode.cache.Region<?,?> region, Class<?> domainType)
region - Region to query; must not be null.domainType - type of the persistent entity to query; must not be null.QueryString with an OQL SELECT statement having a FROM clause
based on the selected Region.Region,
Class@Deprecated public QueryString fromRegion(Class<?> domainType, org.apache.geode.cache.Region<?,?> region)
fromRegion(Region, Class).@NonNull public QueryString orderBy(@Nullable Sort sort)
Sort order to this GemFire OQL Query string.sort - Sort indicating the order of the query results.QueryString with an ORDER BY clause if Sort is not null,
or this QueryString as-is if Sort is null.Sort,
QueryString@NonNull public QueryString withHints(@NonNull String... hints)
hints - array of Strings containing query hints.QueryString if hints are not null or empty, or return this QueryString.@NonNull public QueryString withImport(@NonNull String importExpression)
importExpression - String containing the import clause.QueryString if an import was declared, or return this QueryString.@NonNull public QueryString withLimit(@NonNull Integer limit)
limit - Integer indicating the number of results to return from the query.QueryString if a limit was specified, or return this QueryString.@NonNull public QueryString withTrace()
QueryString with tracing enabled.public String toString()
toString in class ObjectString representation of this QueryString.Object.toString(),
StringCopyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.