Package com.ptc.core.query.common

Describes the interfaces and relationships for specifying type based queries of Windchill persistent data.

See:
          Description

Interface Summary
CriteriaAugmentor This interface specifies methods that augment the criteria that are used in the query.
ResultSpec This interface provides the abstraction for specifying the results of a type based query.
TypePagingSession This interface provides the abstraction for information used in paging.
 

Class Summary
BasicResultSpec This class provides a basic implementation of a result specification.
CriteriaHelper This helper class provides static methods for constructing criteria objects that can be used for queries.
DefaultResultSpec This class provides a default "wrapper" implementation based on an existing AttributeTypeIdentiferList.
 

Exception Summary
QueryException This class is used for Exceptions related to query processing.
 

Package com.ptc.core.query.common Description

Describes the interfaces and relationships for specifying type based queries of Windchill persistent data.

Query Specification

Queries are specified by the ResultSpec, AttributeContainerSet (criteria), and SortSpec. Only the ResultSpec is required. Each specification object uses AttributeTypeIdentifiers to reference attributes of types. The actual TypeInstances that are returned by the query are inferred from the AttributeTypeIdentifiers.

Result Specification

The ResultSpec is a list of AttributeTypeIdentifiers that specify the attributes that should be returned by the query. Each AttributeTypeIdentifier can be associated with a function that specifies additional processing for the attribute. The DefaultResultSpec and BasicResultSpec are concrete classes that can be used directly. The DefaultResultSpec is used as a simple wrapper of an AttributeTypeIdentifierList. The BasicResultSpec provides additional capabilities for specifying functions. The following code snippets show how these capabitlities are used.

        BasicResultSpec resultSpec = new BasicResultSpec();

        // Specify non-persisted derived attribute
        NonPersistedAttributeTypeIdentifier location = ..;
        DerivedAttributeContainerFunction locationFunction = new DerivedAttributeContainerFunction("location");
        resultSpec.putEntry(location, locationFunction);

        // Specify non-persisted function
        AttributeTypeIdentifier name = ..;
        NonPersistedAttributeTypeIdentifier lowerCaseName = ..;
        DataStoreAttributeContainerFunction lowerFunction = new DataStoreAttributeContainerFunction(SQLFunction.LOWER);
        lowerFunction.setArgumentAt(name, 0);
        resultSpec.putEntry(lowerCaseName, lowerFunction);

Criteria Specification

Query criteria are specified using AttributeContainerSet and AttributeContainerFunction classes from the Meta Container package. These criteria restrict or filter the TypeInstances (AttributeContainers) that are returned as results. The AttributeContainerSet represents either a single condition or a number of conditions combined together using a logical operator (i.e. AND or OR). AttributeContainerSets support arbitrary nesting of conditions so complex criteria trees are possible.

Consider the criteria tree,

An overall logical OR of two conditions is used. One of these conditions is itself a logical AND composite of two other conditions. The leaf conditions in the criteria tree specify filtering conditions on AttributeTypeIdentifiers. An AttributeContainerFunction is used to hold the AttributeTypeIdentifier and represents a boolean expression that is evaluated as part of the criteria processing. The most often used boolean expression is a comparison of AttributeTypeIdentifier values and a DataSet. The following table describes how DataSet implementations are used to specify filtering criteria. See the Meta package for complete details on these classes.

DataSet Implementation

Description

SQL Equivalent

AnalogSet

Used for describing value ranges (including unbounded ranges)

between, greater than, less than

WildcardSet

Pattern matching for String values

like

EmptySet

Absence or existence of a value

is null, is not null

DiscreteSet

List of values

in, equals

EnumeratedSet

List of EnumeratedType values

in, equals

To simplify building criteria using AttributeContainerSets and AttributeContainerFunctions, the helper class, CriteriaHelper, is provided. It contains static methods that will construct an AttributeContainerSet for a specified condition. The following sample code shows how the example criteria tree above can be constructed.

        AttributeContainerSet[] conditions;
        AttributeTypeIdentifier name = ..;
        AttributeTypeIdentifier width = ..;
        AttributeTypeIdentifier length = ..;

        conditions = new AttributeContainerSet[2];
        conditions[0] = CriteriaHelper.newCriteria(name, WildcardSet.CONTAINS, "bolt", true /* Negate */);
        conditions[1] = CriteriaHelper.newCriteria(width, new Integer(100), new Integer(500));
        CompositeAttributeContainerSet andCondition = new CompositeAttributeContainerSet(conditions, false /* Intersect(AND) */);

        conditions = new AttributeContainerSet[2];
        conditions[0] = CriteriaHelper.newCriteria(length, new Integer(1234), false /* Do not negate */);
        conditions[1] = andCondition;
        CompositeAttributeContainerSet orCondition = new CompositeAttributeContainerSet(conditions, true /* Union(OR) */);

Sort Specification

The SortSpec is an ordered list of AttributeTypeIdentifiers that is used to specify the order of the TypeInstances returned by the query. This interface and implementations are defined in the Meta package. The sort order is based on the index of the AttributeTypeIdentifiers. For example, the AttributeTypeIdentifier at index zero is the primary sort order, the AttributeTypeIdentifier at index one is the secondary sort order, and so on. Each AttributeTypeIdentifier has associated boolean "ascending" and "case sensitive" attributes. If the ascending attribute is true, then the values specified by the associated AttributeTypeIdentifier are sorted in ascending order instead of descending order. The case sensitive attribute applies only to AttributeTypeIdentifiers for character data and indicates whether upper or lower case should be considered when sorting those values.

Sorting is always performed with respect to the Locale specified in the Query Command.

Attribute Details

Typically, attributes are defined with respect to a given type and all of its sub-types. However, in some cases, a query may involve types that are not necessarily related through inheritance. In this case, some attributes exist on some of the types and other attributes exist on different types. All queries are executed within the context of a set of target types. The target types can be derived from the contexts of the AttributeTypeIdentifiers that specify the attributes, or the target types can be specified explicitly as a list of TypeIdentifiers. The implicit derivation uses introspection to determine the sub-types where the attributes are defined. The list of sub-types is then combined to form the set of target types. The explicit target types are specified as an attribute of the ResultSpec.

The entire query is executed using all of the target types. For each target type, a given attribute may not exist. In this case, the attribute is treated as if it exists, but has a null value.

For results, a null value is not returned in the result TypeInstance.

For critiera, an expression containing a null value has the following evaluatation rules.

The possible operator based expression values are True, False and Null. The entire set of criteria is evaluated in conjunction with logical operators. The evaluation rules are as follows: The implications of these rules are that if an attribute is used in a criteria and that attribute does not exist on a target type, then that type will not be returned. If the intent is to always return TypeInstances for a target type if the attribute does not exist, then the original criteria should be OR-ed with an EmptySet criterion using a CompositeAttributeContainerSet.

For sorting, attributes that do not exist for a given target type are treated as null values. Ascending sort places null values at the end. Descending sort places null values at the beginning.

Query Command

Queries are executed via the Command subsystem and query specific commands are located in the Query Command package.