In this topic ...Related Topics ... |
Use this Builder to call a SQL statement and, optionally, transform its results into XML.
This high-level Builder encapsulates into a single entity the functionality of several low-level SQL Builders (SQL DataSource, SQL Statement, SQL Transform to XML, etc.). This enables you to add sophisticated database access capabilities to a model with a single Builder.
Database Explorer - Use the Database Explorer to search for tables, views, and stored procedures that can be used as targets for the "SQL Statement" input.
Enhance SQL readability - Enter your SQL statements using multiple lines to make the SQL statement easier to read.
Avoid Escape Characters - Do not use an escape character in front of quotes in SQL statements. For example, do not use:
select count(* ) \" Count\ " from sometable
Instead use:
select count(*) "Count" from mytable
If the JDBC Type Case of a positional parameter is set to "Automatic", a null input value for that parameter will likely cause an application error at runtime. The JDBC interface requires the specification of a JDBC type if explicitly setting a parameter to NULL, and a binding of "Automatic" will not provide the required type information at runtime. Therefore, you should either prevent null input values (by setting form fields to "required" or providing enumerated selection controls) or ensure that any positional parameter that might resolve to a null value is explicitly typed.
The SQL Call Builder takes the inputs described in the table below. For help on inputs common to many or all Builders such as those in the Properties and HTML Attributes input groups, see "Using the Builder Call Editor."
Input Name | Description |
---|---|
Name | Enter a name for this Builder call. The Designer displays
this name in the Builder Call List.
The name must begin with a letter or an underscore and contain only letters, digits, and underscores. This restriction allows the Builder to use the "Name" input to build additional WebApp artifacts that implement the core of this Builder s runtime functionality. |
Fetch DataSource Names | Press this button to fetch a list of JDBC DataSources
defined on the application server supporting the Designer. The list will
be inserted as choices for the "SQL DataSource" input. If no DataSource
names are listed in the "SQL DataSource" input, then the Designer may
not be properly configured to query an application server,
the server might not be running, or there are no DataSources defined by
the application server.
Any valid datasource name can be typed into the SQL Datasource builder input. The Fetch Datasource Names button, however, will only list those datasources whose full names begin with jdbc/, jdbc/v4/, or jdbc/v5/. If you know that there is a valid datasource with a name that does not match any of these patterns, type the name in. If the name is correct, it should work. Depending on the performance of the application server, it might take several seconds to load the list of datasource names. This button is not displayed if the Builder is configured to use an override SQL DataSource. See the section entitled "Using Override Builders" for more information. |
SQL DataSource | Open this list and select the JDBC DataSource to be
used by the SQL Call when it executes the SQL statement you will define
later in this Builder
This input will be displayed as a read-only prompt indicating the name of the override Builder if the SQL Call Builder has been configured to use a custom SQL DataSource Builder. See Using Override Builders for more information. |
Database Explorer Settings | |
Entity Type to Fetch | What type of entity to search for in the database
|
Catalog Pattern | Enter a name of the catalog to search for tables or
stored procedures. Leave blank to match all catalogs.
The following wildcards are supported:
Depending on the database and JDBC driver associated with the DataSource, this entry might be case sensitive. |
Schema Pattern | Enter an SQL schema pattern to use while searching for
tables or stored procedures. Typically this is the id of the database
user that owns the entity you are trying to find. Leave this input blank
to match all schemas.
The following wildcards are supported:
Depending upon the database and JDBC driver associated with the DataSource this entry may be case sensitive. |
Entity Pattern | Enter an entity name pattern (table or stored procedure
name) to use while searching for tables or stored procedures. Leave blank
to match all entities.
The following wildcards are supported:
Depending upon the database and JDBC driver associated with the DataSource this entry may be case sensitive. |
Fetch Entity Names | Press to fetch all of the entity names that match the
catalog, schema, and entity patterns you specified. The names will be
inserted as choices for the "Entity Name" input.
If no entity names are listed in the "Entity Name" input, the Designer may not be properly configured to query an application server, the server may not be running, or there are no entity names that match the patterns you defined. Depending on the performance of the application server, it might take several seconds to load the list of entity names. Tip - Review the "Explorer Status" panel for any warning or error messages. |
Entity Name | Select the name of the entity from the drop down list. The selected entity will be used by the Builder when you press the "Generate Sample SQL" button. |
Statement Type | Select the type of table-based SQL statement to be generated
when you press the "Generate Sample SQL" button. We can specify
the following type of statements:
This input will be displayed only if the "Entity Type to Fetch" input is set to "Tables". |
Generate Sample SQL | Press to have the Builder generate a sample SQL statement
in the "Sample SQL" input field and define positional parameters in the
"Sample Parameters" input.
If "Entity Type to Fetch" is set to "Tables", the statement will list every column for the table. If "Entity Type to Fetch" is set to "Stored Procedures", the statement will take the form of a JDBC stored procedure call where each input/output parameter is defined as a JDBC positional parameter. |
Sample SQL | The sample SQL statement generated by the Builder for
the entity selected by the "Entity Name" input.
The SQL displayed in this panel is editable. For example, we can edit a SELECT statement to return only the columns we need instead of all the columns defined for a table, view or alias. If you change the number of positional parameters make sure you also make appropriate changes to the "Sample Parameters" input before pressing the "Apply Sample SQL" button. |
Sample Parameters | Sample definitions for the JDBC positional parameters
defined in the "Sample SQL" input. Parameters
are defined by:
|
Apply Sample SQL | Press to copy the sample SQL statement and parameters to the Builder s actual inputs for these values. |
| |
SQL Statement | Enter an SQL statement with optional positional parameter
and indirect references. For example:
SELECT * from EMPLOYEES where SALARY | ? Alternately, we can use this Builder's Database Explorer to locate and generate some sample SQL. We can then edit that SQL as needed, and apply the edited SQL to this input. If you elect to override this input with an individual SQL Statement Builder, this input will be displayed as a read-only prompt indicating the name of the Builder being used to specify the statement. See Using Override Builders for more information. If you are using a SELECT statement, see Schema Generation Limitations below for limitations on generating an XML schema for the returned result set. |
| |
Parameter Binding | Choose one of the following parameter bindings to create
variables associated with this statement:
Here are some important points to keep in mind when making choices in this builder call input.
|
Parameters | Parameters can include:
|
Result Set Handling | |
Concurrency | Select a concurrency
mode for the Result Set generated by this statement. Modes are:
Some databases may not support updatable result sets. Check the documentation for your target database for detailed information about the types of result sets supported. |
Scroll Type | Select the type of scrolling used by the result set.
Types include:
Some databases may not support all of these scroll types. Check the documentation for your target database for detailed information about the types of result sets supported. |
Transform Result | Select the type of transform to be applied to the result
set or stored procedure output. Choices are:
If the resultset will contain BINARY or VARBINARY data types, click here for information about transforming these data types. |
Row Count Calculation | Indicate how the number of rows are calculated for the pageable result set.
The choices are:
|
Row Count | Provide an indirect reference to calculate
the number of rows for the data set. This input is available only when Use custom count is selected for
Row Count Calculation.
|
Top Element Name | This input is displayed when the Transform Result input
above is activated.
By default the SQL Call Builder returns a result with tag names "RowSet" and "Row." Use this input to provide an alternate name for the "RowSet" tag. You might want to do this if you have more than one SQL Call Builder in a model to differentiate between the transform results returned by each Builder. |
Row Element Name | This input is displayed when the Transform Result input
above is activated.
By default the SQL Call Builder returns a result with tag names "RowSet" and "Row." Use this input to provide an alternate name for the "Row" tag. You might want to do this if you have more than one SQL Call Builder in a model to differentiate between the transform results returned by each Builder. |
Schema Generation | Specify XML schema conditions. We can specify
|
Schema Location | Available when Use Existing URL/File/Variable is selected above. Indicates the URL, file path or variable name where the existing schema is located. |
Schema Import Rule | This input is displayed when "Use Existing URL/File/Variable
is selected as the Schema Generation input.
The import rule determines when a schema is imported. We can choose:
|
Schema Regen Time | This input is available when "From SQL Statement"
is selected as the Schema Generation input choice. USe this input to control
the generation behavior of the schema. We can choose:
|
Alternate SQL | This input is displayed only when From
Alternate SQL Statement above is selected for the "Schema
Generation" input.
Enter a SQL statement to be used for generating the XML schema that defines the result set produced by executing the "SQL Statement" input. |
Method Names | |
Note: These methods are optional and not all will appear in the webApp. The Builder decides when they are needed based upon its inputs. | |
Invoke Name | Enter a custom name that will be applied to this Builder-generated
method.
This is the name of the webApp method that must be called to execute the SQL statement defined by this Builder. If the Builder is configured to transform a result set or stored procedure output, then the method will return either an XML value or a paged data retriever. Otherwise the method will not return a value (such as when the SQL executes is DELETE). You might want to use a custom name so that methods generated by this Builder adhere to a naming convention you have established. |
Invoke with Params Name | Enter a custom name that will be applied to this Builder-generated
method.
This is the name of the webApp method that allows a caller to override the positional parameter bindings, if any, defined for the Builder. Calling this method causes the provided method parameters to be bound to the SQL statement's positional parameters before execution. If the Builder is configured to transform a result set or stored procedure output, then the method will return either an XML value or a paged data retriever. Otherwise the method will not return a value (such as when the SQL executes is DELETE). Enter a custom name that will be applied to this Builder-generated method. |
Get text by Index Name | Enter a custom name that will be applied to this Builder-generated
method.
This is the name of the WebApp method that can be used to extract textual stored procedure output using a zero-based index. When a stored procedure's output is transformed into XML all of the output parameters appear as elements in the transformed XML. This method allows you to access the text of those output values by index just as you would access the elements of a Java array by index. |
Get Text by Position Name | Enter a custom name that will be applied to this Builder-generated
method.
This is the name of the WebApp method that can be used to extract textual stored procedure output using parameter positions. When a stored procedure's output is transformed into XML all of the output parameters appear as elements in the transformed XML and their position in the SQL statement is remembered. This method allows you to access the values of those output parameters by specifying their position in the parameter list. Note that position numbers begin with one and may not be sequentially numbered. |
Get XML by Index Name | Enter a custom name that will be applied to this Builder-generated
method.
This is the name of the WebApp method that performs the same function as "Get Text by Index Name" but instead returns the XML of the output parameter rather just its text. |
Get XML by Position name | Enter a custom name that will be applied to this Builder-generated
method.
This is the name of the WebApp method that performs the same function as "Get Text by Position Name" but instead returns the XML of the output parameter rather just its text. |
Events, Statistics and Logging | |
Log SQL Statements | Enable this box to log all of the SQL statements prepared for execution by the Builder. The log message will include the actual values used for each positional parameter in the SQL. |
Log SQL Warnings | Enable this box to log any SQL warnings that are generated as a result of preparing the SQL statement for execution. |
Log Server Stats | Enable this box to generate server statistics for this Builder instance. |
Fire Events | Enable this check box to fire all events (database,
transform, etc.) related to this Builder's operation .
This feature is primarily useful for debugging purposes. |
Builder Override Definition | |
SQL DataSource | Use this list to select an existing SQL DataSource Builder to be used to override this Builder's internal SQL DataSource input. |
SQL Statement | Use this list to select an existing SQL Statement Builder to be used to override the this Builder's internal SQL Statement input. |
SQL Transform | Use this list to select an existing SQL Transform Builder to be used to override this Builder's internal SQL Transform. |
This Builder allows your model to obtain database connections from a local or remote JNDI-based DataSource. The DataSource is typically defined and managed by your application server and made available through a JNDI server provided as part of the application server s implementation. The DataSource created by the application server will usually provide a set of additional features beyond simply handing out JDBC connections for access to a database. Some of those features might include connection pooling, stale connection handling, and connection time outs.
This Builder is designed to use the authentication credentials in force on the JNDI connection. Thus requests from this Builder to the datasource are passed directly through the JNDI connection. This Builder does not provide inputs for user-specific credentials. However, If user-specific credentials are required, we can use a SQL DataSource Builder in the model to override the connection functionality provided by this Builder.
Use the Database Explorer if we need assistance in creating an SQL statement. We can browse entities in the database and construct the SQL statement on-the-fly. This is particularly useful if you are not an expert in using SQL. As you specify various inputs to the Explorer, you build a statement that can then be edited.
The SQL Call Builder leverages many of the low-level SQL Builders during its generation phase. These "internal" SQL Builders are configured by SQL Call to use input values that are appropriate for the majority of users. However, there may be scenarios where a user needs to apply a fine grain of control over how these "internal" Builders function at runtime. To make this fine grain of control possible the SQL Call Builder allows the user to override the "internal" SQL DataSource, SQL Statement, and/or SQL Transform Builders used by SQL Call during generation.
Under the group heading "Builder Override Definition" there are three inputs that list all of the SQL DataSource, SQL Statement, and SQL Transform Builders present in the model. Choosing a Builder name for one of these inputs causes the SQL Call Builder to use the selected Builder at generation and runtime rather than it s "internal" Builder. For example, if we needed the SQL DataSource to behave differently than the "internal" DataSource, then you would add a SQL DataSource Builder call to your model, configure it appropriately, when select it as the override for the "SQL DataSource" in the SQL Call Builder call. SQL Call will thereafter use the SQL DataSource Builder call that you added to the model.
When using the SQL Call Builder to execute a SELECT statement, there are two scenarios in which the SELECT statement as entered in the "SQL Statement" input cannot be used to generate an XML schema for the returned result set. The first scenario involves "SQL Statement" inputs that contain one or more indirect references. Because the Builder generates an XML schema for the result set at model regeneration time, the Builder needs to know the final form of the SELECT statement at regeneration. However, an indirect reference in the "SQL Statement" input implies that some part of the SELECT statement won't be determined until runtime. As a result, the SQL Call Builder does not allow a "SQL Statement" input with indirect references to be used for schema generation. We can work around this limitation by selecting "From Alternate SQL Statement" as the value of the "Schema Generation" input. Then enter into the "Alternate SQL" input a copy of your SELECT statement that does not contain any indirect references. When configured in this way, the SQL Call Builder will use the content of the "Alternate SQL" input to generated the XML schema at regen time and use the content of "SQL Statement" at model execution (runtime).
The second scenario involves "SQL Statement" inputs that use positional parameters that correspond to the JDBC column types of ARRAY, BLOB, CLOB, DATE, DISTINCT, JAVA_OBJECT, OTHER, REF, and STRUCT. At regeneration time the SQL Call Builder generates an XML schema for the SELECT's result set by generating and examining a small result set that has the same columns as the result set that will be generated at execution. The Builder attempts to create sample values for each positional parameter before generating this sample result set. However, it's not possible for the Builder to create sample values for the types listed. The solution to this problem is to select "From Alternate SQL Statement" as the value of the "Schema Generation" input. Then enter into the "Alternate SQL" input a copy of your SELECT statement that does not contain any positional parameters.
Some database columns are stored as binary fields even though the data they represent is simple strings. BINARY and VARBINARY are SQL types that SQL Transform will automatically attempt to convert into strings. This approach may or may not work, depending upon the content of the columns and the actual data. If you expect BINARY or VARBINARY results to be returned, keep in mind that these results will be converted into strings. If that's not appropriate for the data involved, you will need to add a custom transform for those columns.