Skip to main content

8.3 Core APIs

The engine uses these objects for configuration, compilation and execution:

HostConfiguration → QueryManager → QueryBuilder → Query → QueryResult

Responsibilities​

TypeResponsibilityCommon entry points
HostConfigurationImplements HostContext; holds loaders, imports, fragments and application objectsaddImport, addFragment, addAttachment
HostContextSupplies object lookup, loaders and application objects registered by typefindBean, findFragmentProcess, getAttachment
QueryManagerShares one HostContext across new query buildersnewBuilder()
QueryBuilderConfigures queries, parses scripts and creates QIL or Query instancesparserQuery, compilerQuery, createQuery
QueryExecutes compiled scripts with supplied parametersexecute
QueryResultHolds the return value, result code and durationgetData, getCode, executionTime

QueryModel is the parsed syntax tree; QIL contains compiled instructions. Use createQuery(script) for ordinary calls. For separate compilation steps, see Standalone usage.

Shared variables​

Declare shared variables before compilation and reference them by name. Supply call parameters during execution and read them through ${...}:

import java.util.Map;
import net.hasor.dataql.host.HostConfiguration;
import net.hasor.dataql.host.Query;
import net.hasor.dataql.host.QueryBuilder;
import net.hasor.dataql.host.QueryManager;

QueryBuilder builder = new QueryManager(new HostConfiguration()).newBuilder();
builder.addShareVar("application", () -> "orders");
Query query = builder.createQuery("return application + ':' + ${name};");
System.out.println(query.execute(Map.of("name", "Alice")).getData().unwrap());

The output is orders:Alice. Suppliers run when a Query is created. Update an existing variable through query.addShareVar(name, value); adding a new variable name requires recompilation.

Hints​

QueryBuilder.setHint(name, value) supplies defaults for new queries. Query.setHint(name, value) overrides them, and removeHint(name) removes an option. Explicit script settings take precedence during execution.

import net.hasor.dataql.host.HostConfiguration;
import net.hasor.dataql.host.Query;
import net.hasor.dataql.host.QueryBuilder;
import net.hasor.dataql.host.QueryManager;

QueryBuilder builder = new QueryManager(new HostConfiguration()).newBuilder();
builder.setHint("INDEX_OVERFLOW", "near");
Query query = builder.createQuery("var values = [10,20]; return values[5];");
query.setHint("INDEX_OVERFLOW", "null");
Object result = query.execute().getData().unwrap(); // null

setHint(name, Object) can carry application objects. Copying Hints or cloning a Query preserves their references. Each execution uses a separate Hint container; script changes do not write back to the Query.

See the Hint reference for syntax and options, and Custom functions for reading these objects from a UDF.

Extension registration​

Use the existing implementation guides and register extensions directly when running the engine independently:

ExtensionEngine registrationImplementation guide
UDFbuilder.addShareVar(name, () -> udf)Custom functions
Libraries and application objectshost.addImport(name, supplier)Function libraries, Application imports
External fragmentshost.addFragment(name, supplier)Fragment processors
Findernew HostConfiguration(finder)Finder
Application resourceshost.addAttachment(type, instance)Engine and query configuration
Parameter scopesquery.execute(customizeScope)Custom scopes; Dataway's merging rules apply only within Dataway

QueryWrap delegates to a Query. Subclass it and override execute(CustomizeScope) to add execution logic. The other execute overloads call this method.