|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface QueryEngine<ID,REC>
A QueryEngine
provides query functionality across one or more QueryRepository
s
that have homogeneous key and value types.
QueryEngine
implementations may support multiple
Nested Class Summary | |
---|---|
static class |
QueryEngine.BackgroundIndexingPolicy
Enumerates valid background indexing policies. |
Method Summary | ||
---|---|---|
void |
addRepository(QueryRepository<ID,REC> repository,
String alias)
Adds a repository to the QueryEngine with the given alias. |
|
void |
close()
Closes this QueryEngine . |
|
|
createIndex(IdxField<REC,T> field,
boolean unique)
Adds an index to this QueryEngine 's repositories. |
|
|
createIndex(IdxField<REC,T> field,
boolean unique,
String name)
Adds an index to this QueryEngine 's repositories. |
|
|
createIndex(String columnDefinition,
boolean unique)
Parses a field using the QueryEngine 's XPQL query syntax and creates an
index for it. |
|
Query<REC> |
createQuery()
Creates an empty Query that can be executed against this QueryEngine . |
|
Query<REC> |
createQuery(String xpql)
Creates a Query corresponding to the provided SELECT statement. |
|
boolean |
dropIndex(IdxField<REC,?> field)
Drops a previously created index for this QueryRepository . |
|
boolean |
dropIndex(String indexName)
Drops a previously created indexes on each of this QueryEngine 's QueryRepository s. |
|
QueryResultSet<REC> |
execute(Query<REC> query)
Executes a Query against this QueryEngine . |
|
QueryResultSet<REC> |
execute(String xpql)
Executes an xpql query against this QueryEngine . |
|
Object |
executeStatement(String sql)
Executes the XPQL Query or DDL statement. |
|
double |
getFetchRatioThreshold()
Indicate the minimum proportion of an index's keys that qualify the index to be used in a Query . |
|
|
getField(String columnDefinition)
Parses a field using the query engine's parser. |
|
Set<IdxField<REC,?>> |
getIndexedFields()
Retrieve the set of the fields that are being indexed by this QueryEngine 's
QueryRepository s |
|
Collection<? extends QueryRepository<ID,REC>> |
getRepositories()
Gets this QueryEngine 's current QueryRepository s. |
|
void |
removeRepository(String alias)
Removes a QueryRepository from the QueryEngine . |
|
void |
setAutoIndexing(boolean autoIndex)
Indicates whether or not automatic index creation should be performed for fields referenced by queries. |
|
void |
setAutoIndexLimit(int autoIndexLimit)
Indicate the number of fields that should be indexed when auto-indexing is enabled. |
|
void |
setBackgroundIndexingPolicy(QueryEngine.BackgroundIndexingPolicy policy)
Sets the policy to use for background index creation. |
|
void |
setDefaultIndexing(boolean defaultIndexing)
Enable or disable the automatic creation of default indexes. |
|
void |
setDefaultPackage(Package pkg)
Specify the Package within which to find classes that are used in queries. |
|
void |
setFetchRatioThreshold(double threshold)
Indicate the minimum proportion of an index's keys that qualify the index to be used in a Query . |
|
void |
setQueryStatGeneration(boolean generateStats)
Enable or disable the generation of QueryStats for Queries that are executed going forward. |
|
void |
setSortAreaInMemoryCardinality(int maxCardinality)
Indicate the maximum number of records a SortArea-backed data structure can hold before it is moved to a disk-based data structure. |
|
void |
waitForBackgroundIndexing()
Waits for any background indexing to complete |
Methods inherited from interface com.neeve.query.index.IdxFieldResolver |
---|
getField, getField, getField |
Method Detail |
---|
void addRepository(QueryRepository<ID,REC> repository, String alias)
QueryEngine
with the given alias. Future queries can
then reference this QueryRepository
in the from clause using this QueryRepository
,
its alias, or its name as returned by QueryRepository.getName()
This is equivalent to calling addRepository(QueryRepository, String)
with a
null
alias.
Adding a QueryRepository
multiple times with a different alias has the effect of
registering multiple alias for the QueryRepository
. Adding a new QueryRepository
with an already used alias replaces the current alias with the new QueryRepository
.
repository
- The repository to add.Query.from(String)
void removeRepository(String alias)
QueryRepository
from the QueryEngine
. It will be unavailable to
future Query
s that reference it. If the QueryRepository
was added with
one or more aliases these aliases will be unregistered as well.
alias
- The alias with which the QueryRepository
was added.Collection<? extends QueryRepository<ID,REC>> getRepositories()
QueryEngine
's current QueryRepository
s. The returned
Collection
should be considered immutable.
QueryEngine
's current QueryRepository
s.void setDefaultPackage(Package pkg)
Package
within which to find classes that are used in queries.
pkg
- The default package to use when an a field's container type is unqualified.void setAutoIndexing(boolean autoIndex)
autoIndex
- True to dynamically create indexes.Query<REC> createQuery()
Query
that can be executed against this QueryEngine
.
Query
.Query<REC> createQuery(String xpql) throws QueryParseException
Query
corresponding to the provided SELECT statement.
xpql
- The query string
QueryParseException
QueryResultSet<REC> execute(String xpql)
QueryEngine
.
xpql
- The SELECT statement to execute.
QueryResult
.QueryResultSet<REC> execute(Query<REC> query)
Query
against this QueryEngine
.
query
- The Query
to execute.
QueryResult
.Object executeStatement(String sql) throws QueryException, QueryParseException
QueryResultSet
if the provided sql is a SELECT statement.
sql
- The statement to execute.
QueryException
- If there is an error executing the statement.
QueryParseException
- If there is an error parsing the statement.void close() throws Exception
QueryEngine
. A close on the database
will interrupt and cleanly shutdown any ongoing indexing
operations
Exception
<T> IdxField<REC,T> getField(String columnDefinition) throws QueryException, QueryParseException
columnDefinition
- A field.
QueryParseException
- if the columnDefinition can't be parsed as a valid column name
QueryException
- if there is an error resolving the field<T> boolean createIndex(String columnDefinition, boolean unique) throws QueryException, QueryParseException
QueryEngine
's XPQL query syntax and creates an
index for it. This is equivalent to calling getField(String)
and using the
result with createIndex(IdxField, boolean)
columnDefinition
- The field defined in XPQLunique
- Whether or not the index is guaranteed to be unique.
QueryParseException
- if the fieldDef can't be parsed as a valid column name
QueryException
- if there is an error creating the index.getField(String)
<T> boolean createIndex(IdxField<REC,T> field, boolean unique) throws QueryException
QueryEngine
's repositories. An index must be declared as
either unique or non-unique. This decision determines whether the particular
field is unique across all Object
in this repository.
This equivalent to calling createIndex(IdxField, boolean, String)
with a
value of null for the name.
field
- The IdxField
to index.unique
- Whether or not the index is guaranteed to be unique.
QueryException
- if there is an error creating the index.<T> boolean createIndex(IdxField<REC,T> field, boolean unique, String name) throws QueryException
QueryEngine
's repositories. An index must be declared as
either unique or non-unique. This decision determines whether the particular
field is unique across all Object
on a per QueryRepository
basis.
If the name provided is null or empty then the name of the name
will be the name of the field as returned by IdxField.getName()
If a repository already has the index then this operation will not have any effect unless the existing index has a name different from this field's name in which case it will result in the index being renamed.
If a repository already has an index with this name, but corresponding to a different field then the existing index will be dropped and replaced by this index.
If this QueryEngine
currently has no open repositories an exception is thrown.
If this QueryEngine
has been closed an exception is thrown
field
- The IdxField
to index.unique
- Whether or not the index is guaranteed to be unique.name
- A name for the index. If null the name of the field will be used.
QueryException
- If there is an error creating the indexvoid setBackgroundIndexingPolicy(QueryEngine.BackgroundIndexingPolicy policy)
policy
- The indexing policy to use.void waitForBackgroundIndexing() throws InterruptedException
InterruptedException
- If the current thread is interrupted while waiting
for background index creationboolean dropIndex(IdxField<REC,?> field) throws QueryException
QueryRepository
. If there
is no such index this method simply does nothing.
If this QueryEngine
currently has no open repositories an exception is thrown.
If this QueryEngine
has been closed an exception is thrown
field
- The IdxField
to stop indexing.
QueryException
- If there is an error dropping the indexboolean dropIndex(String indexName) throws QueryException
QueryEngine
's QueryRepository
s.
If there are no indexed with the given name this method does nothing.
Any QueryResultSet
or QueryResult
that depends on an index that is dropped
is invalidated when an index is dropped.
If this QueryEngine
currently has no open repositories an exception is thrown.
If this QueryEngine
has been closed an exception is thrown
indexName
- The name of the index to drop.
QueryException
- If there is an error dropping the indexSet<IdxField<REC,?>> getIndexedFields()
QueryEngine
's
QueryRepository
s
Set
of the fields indexed for this QueryEngine
's
QueryRepository
svoid setFetchRatioThreshold(double threshold)
Query
.
A value of 0.0 indicates that an index should only be used if it would return no results from the
repository, e.g. WHERE someField = 'non-existent value'.
A value of 0.1 would indicate that indexes should only be used if they would return 10% or less of the
indexed field values, e.g. WHERE Person.age >= 85
A value of 1.0 would indicate that any usable indexes should be considered, even if this would result
in reading the entire index only to then read the entire repository, e.g. WHERE Person.age < 120.
threshold
- must be between 0.0 and 1.0.double getFetchRatioThreshold()
Query
.
A value of 0.0 indicates that an index should only be used if it would return no results from the
repository, e.g. WHERE someField = 'non-existent value'.
void setDefaultIndexing(boolean defaultIndexing)
defaultIndexing
- A boolean value that enables/disables this functionality.void setQueryStatGeneration(boolean generateStats)
generateStats
- Whether or not to enables stats collectionvoid setAutoIndexLimit(int autoIndexLimit)
autoIndexLimit
- void setSortAreaInMemoryCardinality(int maxCardinality)
maxCardinality
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |