Package com.blazebit.query
Interface QuerySession
- All Superinterfaces:
AutoCloseable
A session within which queries can be executed against schema object data.
QuerySession stores schema object data against which queries run, and if necessary,
fetches data by invoking the
DataFetcher
registered for a schema object.
When the application has finished using the QuerySession, the application should close the QuerySession.
Once a QuerySession has been closed, all its Query
objects become unusable.
The object is not thread-safe.- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the schema object data fetched byDataFetcher
instances.void
close()
Closes the QuerySession to free up resources.default TypedQuery<Object[]>
createQuery
(String queryString) Creates an executable query associated to this QuerySession.default <T> TypedQuery<T>
createQuery
(String queryString, Class<T> resultClass) Creates an executable query associated to this QuerySession.<T> TypedQuery<T>
Creates an executable query associated to this QuerySession.default TypedQuery<Object[]>
createQuery
(String queryString, Map<String, Object> properties) Creates an executable query associated to this QuerySession.<T> List<? extends T>
Returns the schema object data for the given schema object type stored in this QuerySession, ornull
if there is none.Returns theQueryContext
that created this QuerySession.Set<SchemaObjectType<?>>
Returns the schema object types for which data is stored in this QuerySession.<T> List<? extends T>
getOrFetch
(Class<T> schemaObjectType) Returns the schema object data for the given schema object type stored in this QuerySession, fetching and storing the data by calling the underlyingDataFetcher
if necessary.Returns the properties and hints and associated values that are in effect for the QuerySession.boolean
isOpen()
Determine whether the entity manager is open.<T> List<? extends T>
Stores the given schema objects for the given schema object type in this QuerySession and returns the previously stored schema object data stored, ornull
if there was none.default <T> List<? extends T>
Refreshes the schema object data for the given schema object type by fetching data again through the underlyingDataFetcher
.<T> List<? extends T>
Removes the schema objects for the given schema object type from this QuerySession and returns the previously stored schema object data stored, ornull
if there was none.void
setProperty
(String propertyName, Object value) Set aQuerySession
property or hint.<T> T
Return an object of the specified type to allow access to the provider-specific API.
-
Method Details
-
getContext
QueryContext getContext()Returns theQueryContext
that created this QuerySession.- Returns:
- the
QueryContext
that created this QuerySession - Throws:
IllegalStateException
- if the QuerySession is closed
-
createQuery
Creates an executable query associated to this QuerySession.- Parameters:
queryString
- A Blaze-Query query string- Returns:
- a new query instance
- Throws:
IllegalArgumentException
- If the query string is invalidIllegalStateException
- if the QuerySession is closed
-
createQuery
Creates an executable query associated to this QuerySession.- Parameters:
queryString
- A Blaze-Query query stringproperties
- The properties for the query, which should override QuerySession properties- Returns:
- a new query instance
- Throws:
IllegalArgumentException
- If the query string is invalidIllegalStateException
- if the QuerySession is closed
-
createQuery
Creates an executable query associated to this QuerySession.- Type Parameters:
T
- The result type- Parameters:
queryString
- A Blaze-Query query stringresultClass
- The result class- Returns:
- a new query instance
- Throws:
IllegalArgumentException
- If the query string is invalidIllegalStateException
- if the QuerySession is closed
-
createQuery
<T> TypedQuery<T> createQuery(String queryString, Class<T> resultClass, Map<String, Object> properties) Creates an executable query associated to this QuerySession.- Type Parameters:
T
- The result type- Parameters:
queryString
- A Blaze-Query query stringresultClass
- The result classproperties
- The properties for the query, which should override QuerySession properties- Returns:
- a new query instance
- Throws:
IllegalArgumentException
- If the query string is invalidIllegalStateException
- if the QuerySession is closed
-
get
Returns the schema object data for the given schema object type stored in this QuerySession, ornull
if there is none.- Type Parameters:
T
- The schema object type- Parameters:
schemaObjectType
- The schema object type- Returns:
- the schema object data, or
null
- Throws:
IllegalArgumentException
- If the schema object type is not knownIllegalStateException
- if the QuerySession is closed
-
getOrFetch
Returns the schema object data for the given schema object type stored in this QuerySession, fetching and storing the data by calling the underlyingDataFetcher
if necessary.- Type Parameters:
T
- The schema object type- Parameters:
schemaObjectType
- The schema object type- Returns:
- the schema object data
- Throws:
IllegalArgumentException
- If the schema object type is not knownIllegalStateException
- if the QuerySession is closedDataFetcherException
- when an exception occurs during data fetching
-
put
Stores the given schema objects for the given schema object type in this QuerySession and returns the previously stored schema object data stored, ornull
if there was none.- Type Parameters:
T
- The schema object type- Parameters:
schemaObjectType
- The schema object typeschemaObjects
- The new schema object data to store- Returns:
- the previous schema object data, or
null
- Throws:
IllegalArgumentException
- If the schema object type is not knownIllegalStateException
- if the QuerySession is closed
-
remove
Removes the schema objects for the given schema object type from this QuerySession and returns the previously stored schema object data stored, ornull
if there was none.- Type Parameters:
T
- The schema object type- Parameters:
schemaObjectType
- The schema object type- Returns:
- the previous schema object data, or
null
- Throws:
IllegalArgumentException
- If the schema object type is not knownIllegalStateException
- if the QuerySession is closed
-
refresh
Refreshes the schema object data for the given schema object type by fetching data again through the underlyingDataFetcher
.- Type Parameters:
T
- The schema object type- Parameters:
schemaObjectType
- The schema object type- Returns:
- the refreshed schema object data
- Throws:
IllegalArgumentException
- If the schema object type is not knownIllegalStateException
- if the QuerySession is closedDataFetcherException
- when an exception occurs during data fetching
-
getFetchedSchemaObjectTypes
Set<SchemaObjectType<?>> getFetchedSchemaObjectTypes()Returns the schema object types for which data is stored in this QuerySession.- Returns:
- the schema object types for which data is stored in this QuerySession
- Throws:
IllegalStateException
- if the QuerySession is closed
-
clear
void clear()Clears the schema object data fetched byDataFetcher
instances.- Throws:
IllegalStateException
- if the QuerySession is closed
-
setProperty
Set aQuerySession
property or hint. If a vendor-specific property or hint is not recognized, it is silently ignored.- Parameters:
propertyName
- name of property or hintvalue
- value for property or hint- Throws:
IllegalArgumentException
- if the second argument is not valid for the implementationIllegalStateException
- if the QuerySession is closed
-
getProperties
Returns the properties and hints and associated values that are in effect for the QuerySession. Changing the contents of the map does not change the configuration in effect.- Returns:
- map of properties and hints in effect for the QuerySession
- Throws:
IllegalStateException
- if the QuerySession is closed
-
unwrap
Return an object of the specified type to allow access to the provider-specific API. If the implementation does not support the specified class, theIllegalArgumentException
is thrown.- Type Parameters:
T
- The return type- Parameters:
cls
- the class of the object to be returned- Returns:
- The unwrapped object
- Throws:
IllegalArgumentException
- if the type is not supportedIllegalStateException
- if the QuerySession is closed
-
isOpen
boolean isOpen()Determine whether the entity manager is open.- Returns:
- true until the entity manager has been closed
-
close
void close()Closes the QuerySession to free up resources.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IllegalStateException
- if the QuerySession is closed
-