public class SearchSQL
extends java.lang.Object
SearchScope.fetchObjects
and SearchScope.fetchRows
methods to perform a query.
The SearchSQL
class can be used in either of the following ways:
setFromClauseInitialValue
to set the name of the class
being searched, setSelectList
to set the names of the properties to include, and
setWhereClause
to specify what to search for. When the SearchSQL
instance
is passed in as an argument to SearchScope.fetchRows
, the complete SQL statement string is constructed
out of the parts supplied by the calls to the SearchSQL helper methods. You also can get the complete SQL statement
string constructed by calling the toString
method.setQueryString
method or the SearchSQL(String)
constructor. The SearchSQL
instance is then complete, and no other SearchSQL
method can
be called on this instance.The settings for the following properties can directly affect the search behavior:
ObjectStore.DefaultQueryTimeLimit
ObjectStore.MaxQueryTimeLimit
ObjectStore.QueryDatabaseTimeout
ServerCacheConfiguration.QueryPageMaxSize
ServerCacheConfiguration.QueryPageDefaultSize
ServerCacheConfiguration.NonPagedQueryMaxSize
ServerCacheConfiguration.QueryCountDefaultSize
ServerCacheConfiguration.QueryCountMaxSize
Note: Date/Time values in queries are evaluated with respect to the Content Engine server clock. If the client and server clocks are not in sync, be careful when translating relative time concepts into absolute times. For example, specifying a value that means "within the last 5 minutes" on the client will translate to a comparison to an absolute time in the SQL query, which may not mean "within the last 5 minutes" relative to the server clock.
Constructor and Description |
---|
SearchSQL()
Use this when you are going to build the SQL statement using the
SearchSQL helper methods, rather
than passing in the complete SQL statement. |
SearchSQL(java.lang.String queryString)
Specify the complete SQL statement as a string.
|
Modifier and Type | Method and Description |
---|---|
void |
setAll()
Specifies that duplicate rows can be returned in the result set.
|
void |
setContainsRestriction(java.lang.String symbolicClassName,
java.lang.String searchExpression)
Restricts the query to return only items where the text in the content element or elements matches the specified
string.
|
void |
setContainsRestriction(java.lang.String symbolicClassName,
java.lang.String searchExpression,
java.lang.String searchDialect)
Restricts the query to return only items where the text in the content element or elements matches the specified
string.
|
void |
setDistinct()
Restricts the query to return only distinct rows.
|
void |
setFolderRestriction(java.lang.String symbolicClassName,
java.lang.String folderName)
Restricts the query to return only items from the specified class within the specified folder.
|
void |
setFreetextRestriction(java.lang.String symbolicClassName,
java.lang.String searchExpression)
Deprecated.
As of release 5.2.0
|
void |
setFromClauseAdditionalJoin(JoinOperator joinOperator,
java.lang.String symbolicClassName,
java.lang.String aliasName,
java.lang.String joinVar1,
JoinComparison joinComparison,
java.lang.String joinVar2,
boolean includeSubclasses)
Adds another class to the FROM clause used in the SQL statement.
|
void |
setFromClauseInitialValue(java.lang.String symbolicClassName,
java.lang.String aliasName,
boolean includeSubclasses)
Sets the first class to be used in the FROM clause for the statement.
|
void |
setMaxRecords(int maxRecords)
Sets the maximum number of rows that can be returned in the result set.
|
void |
setOrderByClause(java.lang.String orderByClause)
Sets the ORDER BY clause to be used for the SQL statement to the specified string.
|
void |
setQueryString(java.lang.String queryString)
Specifies the complete SQL statement.
|
void |
setSelectList(java.lang.String selectList)
Sets the SELECT list for SQL statement to the string specified.
|
void |
setTimeLimit(int timeLimit)
Sets the maximum duration the query runs on the server, in seconds.
|
void |
setWhereClause(java.lang.String whereClause)
Sets the WHERE clause to be used for the SQL statement to the specified string.
|
java.lang.String |
toString()
Returns either the SQL statement constructed using the helper methods (in this case,
setFromClauseInitialValue must have been called prior to this method), or the SQL statement specified
in its entirety using either setQueryString or the SearchSQL(String) constructor. |
public SearchSQL()
SearchSQL
helper methods, rather
than passing in the complete SQL statement.public SearchSQL(java.lang.String queryString)
SearchSQL
methods. Calling any of methods on this instance will either overwrite or nullify the SQL statement
specified here.
No SQL validation is performed on the specified string.
queryString
- A String
containing he complete SQL statement to use.setQueryString(String)
,
SQL Syntax Referencepublic void setSelectList(java.lang.String selectList)
setFromClauseAdditionalJoin
.selectList
- A String
containing the query SELECT list.EngineRuntimeException
- Thrown when the parameter is null
or invalid.public void setFromClauseInitialValue(java.lang.String symbolicClassName, java.lang.String aliasName, boolean includeSubclasses)
symbolicClassName
- A String
containing the symbolic name of the class.aliasName
- A String
containing the alias name of the class. This can be null
.
Note: Alias names cannot be used when EngineObject
objects are to be returned by the query
operation.
includeSubclasses
- A boolean
value of true if the FROM clause should include any subclasses
of the class specified in symbolicClassName
; false otherwise.EngineRuntimeException
- Thrown when a required parameter is null
or invalid.public void setFromClauseAdditionalJoin(JoinOperator joinOperator, java.lang.String symbolicClassName, java.lang.String aliasName, java.lang.String joinVar1, JoinComparison joinComparison, java.lang.String joinVar2, boolean includeSubclasses)
joinOperator
- A JoinOperator
instance specifying the type of join to use for the additional
class.symbolicClassName
- A String
containing the symbolic name of the class.aliasName
- A String
containing the alias name of the class. This can be null
.
Note: Alias names cannot be used when EngineObject
objects are to be returned by the query
operation.joinVar1
- A String
containing the name of a property on the initial class specified in
setFromClauseInitialValue
. In tandem with the property specified in joinVar2
, this
property specifies the ON clause constituents of the join.joinComparison
- A JoinComparison
instance specifying the comparison to use for the constituents of the ON
clause (joinVar1
and joinVar2
).joinVar2
- A String
containing the name of a property on the class specified in
symbolicClassName
. In tandem with the property specified in joinVar1
, this property
specifies the ON clause constituents of the join.includeSubclasses
- A boolean
value of true if the FROM clause should include any subclasses
of the class specified in symbolicClassName
; false otherwise.EngineRuntimeException
- Thrown when a required parameter is null
or invalid.public void setWhereClause(java.lang.String whereClause)
whereClause
- A String
containing the WHERE clause to use.EngineRuntimeException
- Thrown when the parameter is null
or invalid.public void setOrderByClause(java.lang.String orderByClause)
orderByClause
- A String
containing the property or properties to use for the ORDER BY clause.
You can specify multiple property names separated by commas.EngineRuntimeException
- Thrown when the parameter is null
or invalid.public void setFolderRestriction(java.lang.String symbolicClassName, java.lang.String folderName)
symbolicClassName
- A String
containing the symbolic name of the class.folderName
- A String
containing the name of the folder storing the class.EngineRuntimeException
- Thrown when the parameters are null
or invalid.public void setFreetextRestriction(java.lang.String symbolicClassName, java.lang.String searchExpression)
The FREETEXT function searches all content on all CBR-enabled properties on the supported content elements. To
search content on a single CBR-enabled property, use setContainsRestriction
.
symbolicClassName
- A String
containing the symbolic name of the class.searchExpression
- A String
containing the search text to use for the FREETEXT function.EngineRuntimeException
- Thrown when the parameters are null
or invalid.setContainsRestriction(java.lang.String, java.lang.String)
,
The FREETEXT Function in the SQL Syntax Referencepublic void setContainsRestriction(java.lang.String symbolicClassName, java.lang.String searchExpression)
The CONTAINS function can perform the search on CBR-enabled properties for the supported content elements in any of the following ways:
symbolicClassName
- A String
containing the symbolic name of the class.searchExpression
- A String
containing the search text to use for the CONTAINS function.EngineRuntimeException
- Thrown when the parameters are null
or invalid.setFreetextRestriction(java.lang.String, java.lang.String)
,
The CONTAINS Function in the SQL Syntax Referencepublic void setContainsRestriction(java.lang.String symbolicClassName, java.lang.String searchExpression, java.lang.String searchDialect)
The CONTAINS function can perform the search on CBR-enabled properties for the supported content elements in any of the following ways:
symbolicClassName
- A String
containing the symbolic name of the class.searchExpression
- A String
containing the search text to use for the CONTAINS function.searchDialect
- A String
containing the search dialect to use which can be Lucene, K2VQL or null.E_NULL_OR_INVALID_PARAM_VALUE
- If symbolicClassName
or searchExpression
is null
or has a length of zero.CBR_INVALID_SEARCH_DIALECT
- If searchDialect
is not null and neither Lucene nor K2VQL.setFreetextRestriction(java.lang.String, java.lang.String)
,
The CONTAINS Function in the SQL Syntax Referencepublic void setDistinct()
setOrderByClause(java.lang.String)
public void setAll()
public void setMaxRecords(int maxRecords)
ServerCacheConfiguration
property NonPagedQueryMaxSize
.maxRecords
- An integer specifying the maximum number of rows to be returned. If unspecified,
the limit is determined by ServerCacheConfiguration.NonPagedQueryMaxSize
.EngineRuntimeException
- Thrown when the parameter is invalid.ServerCacheConfiguration.get_QueryPageDefaultSize
,
ServerCacheConfiguration.get_QueryPageMaxSize
,
ServerCacheConfiguration.get_NonPagedQueryMaxSize
public void setTimeLimit(int timeLimit)
ObjectStore
property DefaultQueryTimeLimit
is used.
Warning: Date/Time values in queries are evaluated with respect to the Content Engine server clock. If the client and server clocks are not in sync, be careful when translating relative time concepts into absolute times. For example, specifying a value that means "within the last 5 minutes" on the client will translate to a comparison to an absolute time in the SQL query, which may not mean "within the last 5 minutes" relative to the server clock.
timeLimit
- An integer specifying the maximum duration of the query. If unspecified,
ObjectStore.DefaultQueryTimeLimit
is used.EngineRuntimeException
- Thrown when the parameter is invalid.ObjectStore.get_DefaultQueryTimeLimit
public void setQueryString(java.lang.String queryString)
SearchSQL
set method (such as, setMaxRecords
),
then calling this method will overwrite or nullify the value initially set.SearchSQL
set method will overwrite or nullify the
SQL statement specified here.No SQL validation is performed on the specified string.
queryString
- A String
containing the SQL statement to use.public java.lang.String toString()
setFromClauseInitialValue
must have been called prior to this method), or the SQL statement specified
in its entirety using either setQueryString
or the SearchSQL(String)
constructor.toString
in class java.lang.Object
String
containing the SQL statement used for this instance.EngineRuntimeException
- Thrown when the SQL statement is null. Either the SQL statement was not set
(constructed or specified in its entirety), or was nullified by calling one of the SearchSQL
methods
subsequent to using either setQueryString
or the SearchSQL(String)
constructor.setFromClauseInitialValue(java.lang.String, java.lang.String, boolean)
,
setQueryString(java.lang.String)
© Copyright IBM Corporation 2006, 2015. All rights reserved.