Skip navigation.
Downloads | Product Documentation | Support

Building Queries and Data Views

# Introduction

This section introduces the Data View Builder, a programming tool you can use to plan, design, build, and test queries using BEA Liquid Data for WebLogic.

The following topics are covered:

- Data View Builder Overview
- Key Concepts of Query Building
- Next Steps

The Liquid Data Data View Builder is a major component in an end-to-end query development and testing system. The Data View Builder is ideal for trying out and refining queries in relationship to target XML schemas, or more usually referred to as target schemas, that provide additional, needed instructions as to how the results of your query should be represented.

For the complete overview of the Liquid Data system see the Concepts Guide.

# Data View Builder Overview

The Data View Builder is a GUI-based tool for designing and generating target schemas and XQueries (in W3C XQuery syntax). You can then run the queries against multiple diverse data sources to retrieve and consolidate data. The Data View Builder provides a graphical, drag-and-drop mapping approach to query design and construction. You can use it to free yourself from having to manage the intricacies of query languages such as SQL while allowing you to give full attention to:

- Information design
- The conceptual synthesis of information coming from multiple sources
- The content and shape of the information you want in the query result.
- Using Liquid Data, you can directly access distributed, heterogeneous data sources as integrated logical views and build up a picture of how you want that consolidated information to be structured.

## Benefits of the Data View Builder

The Data View Builder lets you create queries using an intuitive, drag-and-drop mapping strategy. The XML schema representations and mappings of source and target data are packaged and saved as a project. Using Liquid Data projects you can retrieve the full picture of the query, complete with source schemas and target mappings. Queries can also be stored as data views that can be treated as data sources themselves in Liquid Data and re-used.

## How the Data View Builder Works

Once a data source has been configured in Liquid Data using the Liquid Data node of the WebLogic Administration Console (see the Liquid Data Administration Guide), it becomes available to the Data View Builder. The structure of the data stored in relational databases, Web services, application views, data views, delimited files, and XML files themselves are all represented as XML schemas.

Figure 1-1 Sample Relational and XML Source Schema

By representing disparate data sources as XML schemas, Data View Builder makes it easy for you to represent relationships among different types of data sources.

To build up your query you simply drag and drop elements and attributes among XML schema representations of data sources to create joins, unions, and so on. The default source condition is a join. It uses a built-in equality [`eq`] function; more complex XQuery functions are also available.

You can also map elements from source schemas to a target schema to shape the structure of the query. Target schemas can be created "on the fly" from existing data source representations or created externally. Optimization hints can be added to queries to improve query performance.

Queries can be automatically generated at any point in the development process. When you run the query the underlying data sources are accessed and the results appear in tree-view or XML. The query can also be deployed for use in BEA WebLogic Workshop web applications, among other technologies.

# Key Concepts of Query Building

The following terms and concepts are introduced here:

- Data Sources
- Source and Target Schemas
- Queries and Query Joins, Unions, Aggregates, and Functions
- Stored Queries
- Ad Hoc Queries
- Query Plans

## Data Sources

Liquid Data supports multiple types of data sources in addition to RDBMS (relational database management systems) including:

- XML Files
- Web Services
- Application Views
- Data Views
- SQL Calls
- Delimited Files

See Data Sources, for a complete survey.

## Source and Target Schemas

XML schemas are used in Liquid Data to describe the hierarchical structure of the various data sets. The Data View Builder uses XML schema representations as follows:

- Source Schemas. XML schemas that describe the structure of the source data.
- Target Schemas. An XML schema that describes the structure of the target data; that is, the structure of the query result.

Liquid Data queries require identified data sources. Each data source requires an associated schema. For relational databases, the schema is automatically created based on the metadata available through the database JDBC driver. For XML files, Views, Complex Parameter Types, Stored Procedures, or Web Services, you specify the schema when you define the data source to Liquid Data.

For more information on source and target schemas in Liquid Data, see Source and Target Schemas.

## Queries and Query Joins, Unions, Aggregates, and Functions

A query can be thought of as a way of filtering through large amounts of data or information to extract only the specifics relevant to a particular problem.

A number of tools and techniques are available to develop or expand business logic around the data base schemas. These tools and techniques include:

- Joins
- Unions
- XQuery Functions
- Query Parameters
- Constants

### Joins

A query with a join operation combines information in two data source schemas when there is a match on a common field.

For example, you could specify first and last names of all customers in two data sources — BroadBand and Wireless — and they use a join to limit the output (query result described by the target schema) to the subset of those customers with matching customer IDs in both source schemas.

### Unions

Union operations enable you to combine data from multiple sources into a single set of results described by the structure of the target schema. Even though the content of the source schemas can be the same, or different, you can use a union type query to consolidate elements in source schemas into a tailored view of the data. For example, you could construct a query that reports all customer orders from multiple sources into a single result. This is a very typical use of Liquid Data target schemas.

### XQuery Functions

Liquid Data provides a large number of XQuery functions. These built-in functions can by used by any Liquid Data query.

#### Aggregates

You can create queries in Liquid Data that aggregate query results, providing summary information on a set of data. Typical aggregate functions are average [`avg`], `count`, maximum [`max`], minimum [`min`], and `sum`. You can use aggregate operations to perform various business calculations such as finding the total number of customers, calculating purchases by a single customer, calculating the average salary of workers, and so on.

#### Other Built-in Functions

All conditions are set through functions. The default function for a simple equality function [`eq`[. If you drag and drop one data source element onto another you have created a simple join using the equals function with two parameters (the two data source elements) which gets expressed as `value1` `eq` `value2` in the Data View Builder-generated XQuery.

For information on W3C standard functions supported by Liquid Data, see Functions Reference in the XQuery Reference Guide.

You can also create and use custom functions. See Configuring Access to Custom Functions in the Liquid Data Administration Guide.

### Query Parameters

There are two types of query parameters:

- A function may have parameters that become elements in a source schema.
- You can define generic placeholders for a variable value and specify that value at query run time. For example, a query parameter could be defined as lastname, which is a placeholder for a real last name that you identify when the query runs.

### Constants

Although not as flexible as query parameters, numeric and string constants are easily created and used.

## Stored Queries

A stored query is a query that has been saved to the `stored_queries` folder Liquid Data repository. Queries must be saved with a `.xq` extension to be recognized as stored queries in Liquid Data.

The query result for a stored query can be cached.

Caching of query results for stored queries is configurable through the Liquid Data node of the WebLogic Administration Console (see Configuring the Query Results Cache in the Liquid Data Administration Guide). Using this feature, you can specify whether or not to cache query results for stored queries.

## Ad Hoc Queries

An ad hoc query is a query that has not been stored in the Liquid Data repository, but rather is passed to the Liquid Data server at run time.

## Query Plans

A query plan is a compiled query. Before a query is run, Liquid Data compiles the XQuery into an optimized query plan. Optionally, you can compile the query plan without running the query.

At runtime, Liquid Data executes the query plan against physical data sources and returns the query results.

# How This Book is Organized

Building Queries and Data Views can be thought of as having several sections:

Focus | Chapters
--- | ---
Introduction | Introduction Data View Builder GUI Reference
Query Components | Data Sources Schemas and Namespaces in Liquid Data
Query Design | Building Queries Running, Saving, and Deploying Queries Building Queries Analyzing and Optimizing Queries
Special Data Sources | Using Data Views Using Complex Parameter Types in Queries Accessing SQL Calls: Stored Procedures and SQL Queries

This book does assume some familiarity with the purpose and operation of the Liquid Data graphical query development tool called Data View Builder. You can familiarize yourself with this tool in several ways:

- Getting Started provides a details, stepped example showing how to set up both the Data View Builder and Liquid Data node of the WebLogic Administration Console.
- A Getting Started Demo can be found on the Liquid Data Demo page. This animated demo runs 10-15 minutes and shows the development of a sample Liquid Data query and web application that uses that query.

# Next Steps

- If you have not already done so, try working through the steps in Getting Started, which takes you through the basic tasks of configuring some data sources and using the Data View Builder to design a query using an Order Query example.
- To learn how to start the Data View Builder and understand the GUI tools and views, see Data View Builder GUI Reference.
- To learn more about planning and designing queries and using the Data View Builder to build them, see Building Queries.
- For information on query optimization and performance, see Analyzing and Optimizing Queries.
- For information on defining stored procedures to Liquid Data, see Accessing SQL Calls: Stored Procedures and SQL Queries.
- For details on creating queries by using custom functions, see Using Custom Functions in the Application Developer's Guide.
- For numerous examples of building different types of queries using advanced functions and tools, see Liquid Data by Example.