JBoss.orgCommunity Documentation

Chapter 4. Command Language

4.1. Language Interfaces
4.1.1. Expressions
4.1.2. Criteria
4.1.3. Joins
4.1.4. IQuery Structure
4.1.5. IUnion Structure
4.1.6. IInsert Structure
4.1.7. IUpdate Structure
4.1.8. IDelete Structure
4.1.9. IProcedure Structure
4.1.10. IBulkInsert Structure
4.1.11. IBatchedUpdate Structure
4.2. Language Utilities
4.2.1. Data Types
4.2.2. Language Manipulation
4.3. Runtime Metadata
4.3.1. Language Objects
4.3.2. Access to Runtime Metadata
4.4. Language Visitors
4.4.1. Framework
4.4.2. Provided Visitors
4.4.3. Writing a Visitor
4.5. Connector Capabilities
4.5.1. Capability Scope
4.5.2. Execution Modes
4.5.3. Capabilities
4.5.4. Command Form
4.5.5. Scalar Functions
4.5.6. Physical Limits

Teiid sends commands to your connector in object form. The interfaces for these objects are all defined in the com.metamatrix.data.language package. These interfaces can be combined to represent any possible command that Teiid may send to the connector. However, it is possible to notify the Teiid Server that your connector can only accept certain kinds of commands via the ConnectorCapabilities class. See the section on using Connector Capabilities for more information.

The language interfaces all extend from the main interface, ILanguageObject. They are composed in a tree where each node is a language object that has zero or more child language objects of types that are dependent on the current node.

All commands sent to your connector are in the form of these language trees, where the root of the tree is a subclass of ICommand. ICommand has several sub-interfaces, namely: IQuery, IInsert, IUpdate, IDelete, and IProcedure.  These represent the query in SQL form. Important components of these commands are expressions, criteria, and joins, which are examined in closer detail below.

This section covers utilities available when using, creating, and manipulating the language interfaces.

Teiid uses a library of metadata, known as “runtime metadata” for each virtual database that is deployed in the Teiid Server. The runtime metadata is a subset of metadata as defined by models in the Teiid models that compose the virtual database.  

Connectors can access runtime metadata by using the interfaces defined in com.metamatrix.data.metadata.runtime.  This class defines interfaces representing a MetadataID, a MetadataObject, and ways to navigate those IDs and objects.

The Connector API provides a language visitor framework in the com.metamatrix.data.visitor.framework package.   The framework provides utilities useful in navigating and extracting information from trees of language objects.  This diagram describes the relationships of the various classes in the framework:


The visitor framework is a variant of the Visitor design pattern, which is documented in several popular design pattern references.  The visitor pattern encompasses two primary operations: traversing the nodes of a graph (also known as iteration) and performing some action at each node of the graph.  In this case, the nodes are language interface objects and the graph is really a tree rooted at some node.  The provided framework allows for customization of both aspects of visiting.

The base LanguageObjectVisitor class defines the visit methods for all leaf language interfaces that can exist in the tree.  The LanguageObject interface defines an acceptVisitor() method – this method will call back on the visit method of the visitor to complete the contract.  A base class with empty visit methods is provided as AbstractLanguageVisitor.  The AbstractLanguageVisitor is just a visitor shell – it performs no actions when visiting nodes and does not provide any iteration.

The HierarchyVisitor provides the basic code for walking a language object tree.  The HierarchyVisitor performs no action as it walks the tree – it just encapsulates the knowledge of how to walk it.  If your connector wants to provide a custom iteration that walks the objects in a special order (to exclude nodes, include nodes multiple times, conditionally include nodes, etc) then you must either extend HierarchyVisitor or build your own iteration visitor.  In general, that is not necessary.

The DelegatingHierarchyVisitor is a special subclass of the HierarchyVisitor that provides the ability to perform a different visitor’s processing before and after iteration.  This allows users of this class to implement either pre- or post-order processing based on the HierarchyVisitor.  Two helper methods are provided on DelegatingHierarchyVisitor to aid in executing pre- and post-order visitors.  

All connectors must return a ConnectorCapabilities class from the Connection.getCapabilities() method. This class is used by the Connector Manager to determine what kinds of commands the connector is capable of executing. A basic implementation of the ConnectorCapabilities interface is supplied at com.metamatrix.data.basic.BasicConnectorCapabilities. This capabilities class specifies that the connector only executes queries and does not support any capability. Teiid recommends that you extend this class and override the necessary methods to specify which capabilities your connector supports.  

The following table lists the capabilities that can be specified in the ConnectorCapabilities class.

Table 4.2. Available Connector Capabilities

Capability

Requires

Description

SelectDistinct

Connector can support SELECT DISTINCT in queries.

Joins

Connector can support joins.

OuterJoins

Joins

Connector can support LEFT and RIGHT OUTER JOIN.

FullOuterJoins

Joins, OuterJoins

Connector can support FULL OUTER JOIN.

AliasedGroup

Connector can support groups in the FROM clause that have an alias.

SelfJoins

Joins, AliasedGroups

Connector can support a self join between two aliased versions of the same group.

InlineViews

AliasedGroup

Connector can support a named subquery in the FROM clause.

Criteria

Connector can support WHERE and HAVING clauses.

RowLimit

 

Connector can support the limit portion of the limit clause

RowOffset

 

Connector can support the offset portion of the limit clause

AndCriteria

Criteria

Connector can support AND criteria in join conditions of the FROM clause, the WHERE clause, and the HAVING clause.

OrCriteria

Criteria

Connector can support the OR logical criteria.

NotCriteria

Criteria

Connector can support the NOT logical criteria.

BetweenCriteria

Criteria

Connector can support the BETWEEN predicate criteria.

CompareCriteria

Criteria

Connector can support comparison criteria such as “age > 10”.  

CompareCriteriaEquals

Criteria, CompareCriteria

Connector can support comparison criteria with the operator “=”.

CompareCriteriaGreaterThan

Criteria, CompareCriteria

Connector can support comparison criteria with the operator “>”.

CompareCriteriaGreaterThanOrEqual

Criteria, CompareCriteria

Connector can support comparison criteria with the operator “>=”.

CompareCriteriaLessThan

Criteria, CompareCriteria

Connector can support comparison criteria with the operator “<”.

CompareCriteriaLessThanOrEqual

Criteria, CompareCriteria

Connector can support comparison criteria with the operator “<=”.

CompareCriteriaNotEquals

Criteria, CompareCriteria

Connector can support comparison criteria with the operator “<>”.

ExistsCriteria

Criteria

Connector can support EXISTS predicate criteria.

InCriteria

Criteria

Connector can support IN predicate criteria.

InCriteriaSubquery

Criteria, InCriteria

Connector can support IN predicate criteria where values are supplied by a subquery.

IsNullCriteria

Criteria

Connector can support IS NULL predicate criteria.

LikeCriteria

Criteria

Connector can support LIKE criteria.

LikeCriteriaEscapeCharacter

Criteria, LikeCriteria

Connector can support LIKE criteria with an ESCAPE character clause.

QuantifiedCompareCriteria

Criteria, CompareCriteria

Connector can support a quantified comparison criteria with a subquery on the right side.

QuantifiedCompareCriteriaAll

Criteria, CompareCriteria, QuantifiedCompareCriteria

Connector can support a quantified comparison criteria using the ALL quantifier.

QuantifiedCompareCriteriaSome

Criteria, CompareCriteria, QuantifiedCompareCriteria

Connector can support a quantified comparison criteria using the SOME or ANY quantifier.

OrderBy

Connector can support the ORDER BY clause in queries.

Aggregates

Connector can support GROUP BY and HAVING clauses in queries.

AggregatesAvg

Aggregates

Connector can support the AVG aggregate function.

AggregatesCount

Aggregates

Connector can support the COUNT aggregate function.

AggregatesCountStar

Aggregates, AggregatesCount

Connector can support the COUNT(*) aggregate function.

AggregatesDistinct

Aggregates

Connector can support the keyword DISTINCT inside an aggregate function.  This keyword indicates that duplicate values within a group of rows will be ignored.

AggregatesMax

Aggregates

Connector can support the MAX aggregate function.

AggregatesMin

Aggregates

Connector can support the MIN aggregate function.

AggregatesSum

Aggregates

Connector can support the SUM aggregate function.

ScalarFunctions

Connector can support scalar functions wherever expressions are accepted.

CaseExpressions

Connector can support “unsearched” CASE expressions anywhere that expressions are accepted.

SearchedCaseExpressions

Connector can support “searched” CASE expressions anywhere that expressions are accepted.

ScalarSubqueries

Connector can support the use of a subquery in a scalar context (wherever an expression is valid).

CorrelatedSubqueries

ScalarSubqueries or QuantifiedCompareCriteria or ExistsCriteria or InCriteriaSubquery

Connector can support a correlated subquery that refers back to an element in the outer query.

SelectLiterals

Connector can support literals in the SELECT clause

Unions

Connector support UNIONs

Intersect

Connector supports INTERSECT

Except

Connector supports Except

SetQueryOrderBy

Unions, Intersect, or Except

Connector supports set queries with an ORDER BY

FunctionsInGroupBy

ScalarFunctions, Aggregates

Connector supports functions in the GROUP BY list

FunctionsInGroupBy

ScalarFunctions, Aggregates

Connector supports functions in the GROUP BY list