Access Keys:
Skip to content (Access Key - 0)
Cancel    
Cancel   
 

Contents

JDBC Transport Reference

Introduction

The JDBC Transport allows you to send and receive messages with a database using the JDBC protocol. Common usage includes retrieving, inserting, updating, and deleting database records, as well as invoking stored procedures (e.g., to create new tables dynamically).

Some features are available only with the Mule Enterprise version of the JDBC transport, which is available with version 1.6 and later of Mule Enterprise. These enterprise-only features are noted below.

Transport Info

Transport

Doc

Inbound

Outbound

Request

Transactions

Streaming

Retries

MEP's

Default MEP

Maven Artifact

JDBC

JavaDoc
SchemaDoc

(tick)

(tick)

(tick)

(tick)(local,XA)

(error)

(tick)

one-way, request-response

one-way

org.mule.transport:mule-transport-jdbc

 Legend

Transport - The name/protocol of the transport
Docs - Links to the JavaDoc and SchemaDoc for the transport
Inbound - Whether the transport can receive inbound events and can be used for an inbound endpoint
Outbound - Whether the transport can produce outbound events and be used with an outbound endpoint
Request - Whether this endpoint can be queried directly with a request call (via MuleClinet or the EventContext)
Transactions - Whether transactions are supported by the transport. Transports that support transactions can be configured in either local or distributed two-phase commit (XA) transaction.
Streaming - Whether this transport can process messages that come in on an input stream. This allows for very efficient processing of large data. For more information, see Streaming.
Retry - Whether this transport supports retry policies. Note that all transports can be configured with Retry policies, but only the ones marked here are officially supported by MuleSoft
MEPs - Message Exchange Patterns supported by this transport
Default MEP - The default MEP for endpoints that use this transport that do not explicitly configure a MEP
Maven Artifact - The group name a artifact name for this transport in Maven

Namespace and Syntax

XML namespace (CE version):

XML namespace (EE version):

XML Schema location (CE version):

XML Schema location (EE version):

For CE or EE, if you create the Spring bean right in the Mule configuration file, you must include the following namespaces:

Connector syntax (CE version):

Connector syntax (EE version):

Endpoint syntax:
Inbound endpoints:
You can define your endpoints 2 different ways:

  1. Prefixed endpoint (valid for both CE and EE jdbc endpoints):

  2. Non-prefixed URI:

Outbound endpoints:

  1. Prefixed endpoint (valid for both CE and EE jdbc endpoints):

  2. Non-prefixed URI:

Considerations

Using the JDBC transport is a good idea if you don't already have a database abstraction layer defined for your application. It saves you trouble of writing your own database client code and will be more portable if you decide to change databases in the future. If your application uses a database abstraction layer, then it is usually preferable to use that instead of the JDBC transport.

Features

The Mule Enterprise JDBC Transport provides key functionality, performance improvements, transformers, and examples not available in the Mule community release. The following table summarizes the feature differences.

Feature

Summary

Mule Community

Mule Enterprise

Inbound SELECT Queries

Retrieve records using the SQL SELECT statement configured on inbound endpoints.

x

x

Large Dataset Retrieval

Enables retrieval arbitrarily large datasets by consuming records in smaller batches.

 

x

Acknowledgment Statements

Supports ACK SQL statements that update the source or other table after a record is read.

x

x

Basic Insert/Update/Delete Statements

Individual SQL INSERT, UPDATE, and DELETE queries specified on outbound endpoints. One statement is executed at a time.

x

x

Batch Insert/Update/Delete Statements

Support for JDBC batch INSERT, UPDATE, and DELETE statements, so that many statements can be executed together.

 

x

Advanced JDBC-related Transformers

XML and CSV transformers for easily converting to and from datasets in these common formats.

 

x

Outbound SELECT Queries

Retrieve records using SQL SELECT statement configured on outbound endpoints. Supports synchronous queries with dynamic runtime parameters.

X

x

Outbound Stored Procedure Support - Basic

Ability to invoke stored procedures on outbound endpoints. Supports IN parameters but not OUT parameters.

x

x

Outbound Stored Procedure Support - Advanced

Same as Basic but includes both IN and OUT parameter support. OUT parameters can be simple data types or cursors

 

x

Unnamed Queries

Queries that can be invoked programmatically from within components or other Java code. This is the most flexible option, but also requires writing code.

x

x

Flexible Data Source Configuration

Support for configuration of data sources through JNDI, XAPool, or Spring.

x

x

Transactions

Support for transactions via underlying Transaction Manager.

x

x

Within this features section, items identified by theEnterprise Edition marker indicate features available only in the Enterprise Edition.

Inbound SELECT Queries

Inbound SELECT queries are queries that are executed periodically (according to the pollingFrequency set on the connector).

Here is an example:

In this example, the selectLoadedMules ❶ would be invoked every 10 seconds (pollingFrequency=10000 ms) ❷. Each record from the result set is converted into a Map (consisting of column/value pairs).

Inbound SELECT queries are limited because (1) generally, they cannot be called synchronously (unnamed queries are an exception), and (2) they do not support runtime parameters.

Large Dataset Retrieval

Enterprise Edition

Overview

Large dataset retrieval is a strategy for retrieving large datasets by fetching records in smaller, more manageable batches. Mule Enterprise provides the key components and transformers needed to implement a wide range of these strategies.

When To Use It

  • When the dataset to be retrieved is large enough to overwhelm memory and connection resources.
  • When preserving the order of messages is important.
  • When resumable processing is desired (that is, retrieval of the dataset can pick up where it left off, even after service interruption).
  • When load balancing the data retrieval among clustered Mule nodes.

How It Works

Large dataset retrieval does not use conventional inbound SELECT queries to retrieve data. Instead, it uses a Batch Manager component to compute ID ranges for the next batch of records to be retrieved. An outbound SELECT query uses this range to actually fetch the records. The Batch Manager also controls batch processing flow to make sure that it does not process the next batch until the previous batch has finished processing.

Here is an example:

 

First you set up the file which will hold the starting point id for the next batch of records ❶. Next you define your BatchManager and set the idStore, batchSize and starting point ❷. Then you define a 'noArgsWrapper' spring bean and set a reference to the batch manager ❸. ❹ is where you define the component which will be called after the inbound endpoint is triggered. Your outbound endpoints can use

#[map-payload:lowerId]

and

#[map-payload:upperId]

to reference a batch of database rows.

Important Limitations

Large dataset retrieval requires that:

  1. The source data contains a unique, sequential numeric ID. Records should also be fetched in ascending order with respect to this ID.
  2. There are no large gaps in these IDs (no larger than the configured batch size).

In Combination with Batch Inserts

Combining large dataset retrieval with batch inserts can support simple but powerful ETL use cases.

Acknowledgment (ACK) Statements

ACK statements are optional SQL statements that are paired with inbound SELECT queries. When an inbound SELECT query is invoked by Mule, the ACK statement is invoked for each record returned by the query. Typically, the ACK statement is an UPDATE, INSERT, or DELETE.

An ACK statement would be configured as follows:

Notice the required convention of appending an ".ack" extension to the query name. This convention lets Mule know which inbound SELECT query to pair with the ACK statement.

Also, note that the ACK statement supports parameters. These parameters are bound to any of the column values from the inbound SELECT query (such as #[map-payload:ID] in the case above).

ACK statements are useful when you want an inbound SELECT query to retrieve records from a source table no more than once. Be careful, however, when using ACK statements with larger result sets. As mentioned earlier, an ACK statement gets issued for each record retrieved, and this can be very resource-intensive for even a modest number of records per second (> 100).

Basic Insert/Update/Delete Statements

SQL INSERT, UPDATE, and DELETE statements are specified on outbound endpoints. These statements are typically configured with parameters, which are bound with values passed along to the outbound endpoint from an upstream component.

Basic statements execute just one statement at a time, as opposed to batch statements, which execute multiple statements at a time. Basic statements are appropriate for low-volume record processing (<20 records per second), while batch statements are appropriate for high-volume record processing (thousands of records per second).

For example, when a message with a java.util.Map payload is sent to a basic insert/update/delete endpoint, the parameters in the statement are bound with corresponding entries in the Map. In the configuration below, if the message contains a Map payload with {ID=1,TYPE=1,DATA=hello,ACK=0}, the following insert will be issued: "INSERT INTO TEST (ID,TYPE,DATA,ACK) values (1,1,'hello',0)".

Batch Insert/Update/Delete Statements

Enterprise Edition

As mentioned above, batch statements represent a significant performance improvement over their basic counterparts. Records can be inserted at a rate of thousands per second with this feature.

Usage of batch INSERT, UPDATE, and DELETE statements is the same as for basic statements, except the payload sent to the VM endpoint should be a List of Maps, instead of just a single Map.

Batch Callable Statements are also supported. Usage is identical to Batch Insert/Update/Delete.

Advanced JDBC-related Transformers

Enterprise Edition

Common integration use cases involve moving CSV and XML data from files to databases and back. This section describes the transformers that perform these actions. These transformers are available in Mule Enterprise only.

XML-JDBC Transformer

The XML Transformer converts between XML and JDBC-format Maps. The JDBC-format Maps can be used by JDBC outbound endpoints (for select, insert, update, or delete operations).

Transformer Details:

Name

Class

Input

Output

XML -> Maps

com.mulesoft.mule.transport.jdbc.transformers.XMLToMapsTransformer

java.lang.String (XML)

java.util.List
(List of Maps. Each Map corresponds to a "record" in the XML.)

Maps -> XML

com.mulesoft.mule.transport.jdbc.transformers.MapsToXMLTransformer

java.util.List
(List of Maps. Each Map will be converted into a "record" in the XML)

java.lang.String (XML)

Also, the XML message payload (passed in or out as a String) must adhere to a particular schema format:

Here is an example of a valid XML instance:

The transformer converts each "record" element to a Map of column/value pairs using "fields". The collection of Maps is returned in a List.

The following will return any processed rows in xml format when you go to 'http://localhost:8080/first20' in your browser:

CSV-JDBC Transformer

The CSV Transformer converts between CSV data and JDBC-format Maps. The JDBC-format Maps can be used by JDBC outbound endpoints (for select, insert, update, or delete operations).

Transformer Details:

Name

Class

Input

Output

CSV -> Maps

com.mulesoft.mule.transport.jdbc.transformers.CSVToMapsTransformer

java.lang.String
(CSV data)

java.util.List
(List of Maps. Each Map corresponds to a "record" in the CSV)

Maps -> CSV

com.mulesoft.mule.transport.jdbc.transformers.MapsToCSVTransformer

java.util.List
(List of Maps. Each Map will be converted into a "record" in the CSV)

java.lang.String
(CSV data)

The following table summarizes the properties that can be set on this transformer:

Property

Description

delimiter

The delimiter character used in the CSV file. Defaults to comma.

qualifier

The qualifier character used in the CSV file. Used to signify if text contains the delimiter character.Defaults to double quote.

ignoreFirstRecord

Instructs transformer to ignore the first record. Use this if your first row is a list of column names. Defaults to false.

mappingFile

Location of Mapping file. Required. Can either be physical file location or classpath resource name. The DTD format of the Mapping File can be found at: http://flatpack.sourceforge.net/flatpack.dtd. For examples of this format, see http://flatpack.sourceforge.net/documentation/index.html.

This configuration loads a csv file in the 'mule_source' table of a database

Outbound SELECT Queries

An inbound SELECT query is invoked on an inbound endpoint according to a specified polling frequency. A major improvement to the inbound SELECT query is the outbound SELECT query, which can be invoked on an outbound endpoint. As a result, the outbound SELECT query can do many things that the inbound SELECT query cannot, such as:

  1. Support synchronous invocation of queries. For example, you can implement the classic use case of a web page that serves content from a database using an HTTP inbound endpoint and an outbound SELECT query endpoint.
  2. Allows parameters so that values can be bound to the query at runtime. This requires that the message contain a Map payload containing key names that match the parameter names. For example, the following configuration could be used to retrieve an outbound SELECT query:

In this scenario, if hit the 'http://localhost:8080/getMules?max=3' url, then the following query is executed:

The database rows are transformed into xml which you will see in your browser.

Outbound Stored Procedure Support - Basic

Stored procedures are supported on outbound endpoints in Mule. Like any other query, stored procedure queries can be listed in the queries map. Following is an example of how stored procedure queries could be defined:

To denote that we are going to execute a stored procedure and not a simple SQL query, we must start off the query by the text CALL followed by the name of the stored procedure.

Parameters to stored procedures can be forwarded by either passing static parameters in the configuration or using the same syntax as for SQL queries (see "Passing in Parameters" below). For example:

If you do not want to poll the database, you can write a stored procedure that uses HTTP to start a Mule flow. The stored procedure can be called from an Oracle trigger. If you take this approach, make sure the exchange pattern is 'one-way'. Otherwise, the trigger/transaction won't commit until the HTTP post returns.

Note that stored procedures are only supported on outbound endpoints. If you want to set up a flow that calls a stored procedure at a regular interval, you can define a Quartz inbound endpoint and then define the stored procedure call in the outbound endpoint. For information on using Quartz to trigger flows, see the following blog post.

Passing in Parameters

To pass in parameter values and get returned values to/from stored procedures or stored functions in Oracle, you declare the parameter name, direction, and type in the JDBC query key/value pairs on JDBC connectors using the following syntax:

where $PARAMn is specified using the following syntax:

For example:

This SQL statement calls a stored procedure TEST_CURSOR in the package of MULEPACK, specifying an out parameter whose name is "mules" of type java.sql.ResultSet.

Here is another example:

This SQL statement calls a stored function CHECK_IF_MSG_IS_HANDLED_FNC in the package of ITCPACK, assigning a return value of integer to the parameter whose name is "mules" while specifying other parameters, e.g., parameter "mules2" is a out string parameter.

Stored procedures/functions can only be called on JDBC outbound endpoints. Once the values are returned from the database, they are put in a java.util.HashMap with key/value pairs. The keys are the parameter names, e.g., "mules2", while the values are the Java data values (Integer, String, etc.). This hash map is the payload of MuleMessage either returned to the caller or sent to the next endpoint depending on the Mule configuration.

Outbound Stored Procedure Support - Advanced

Enterprise Edition

Mule Enterprise provides advanced stored procedure support for outbound endpoints beyond what is available in the Mule community release. This section describes the advanced support.

OUT Parameters

In Mule Enterprise, you can execute your stored procedures with out and inout scalar parameters. The syntax for such parameters is:

You must specify the type of each output parameter (OUT, INOUT) and its data type (int, string, etc.). The result of such stored procedures is a map containing (out parameter name, value) entries.

Oracle Cursor Support

For Oracle databases only, an OUT parameter can return a cursor. The following example shows how this works.

If you want to handle the cursor as a java.sql.ResultSet, see the "cursorOutputAsResultSet" flow below, which uses the "MapLookup" transformer to return the ResultSet.

If you want to handle the cursor by fetching the java.sql.ResultSet to a collection of Map objects, see the "cursorOutputAsMaps" flow below, which uses both the "MapLookup" and "ResultSet2Maps" transformers to achieve this result.

In the above example, note that it is also possible to call a function that returns a cursor ref. For example, if TEST_CURSOR2() returns a cursor ref, the following statement could be used to get that cursor as a ResultSet:

Important note on transactions: When calling stored procedures or functions that return cursors (ResultSet), it is recommended that you process the ResultSet within a transaction.

Unnamed Queries

SQL statements can also be executed without configuring queries in the Mule configuration file. For a given endpoint, the query to execute can be specified as the address of the URI.

Flexible Data Source Configuration

You can use any JDBC data source library with the JDBC Connector. The "myDataSource" reference below refers to a DataSource bean created in Spring:

You can also create a JDBC connection pool so that you don't create a new connection to the database for each message. You can easily create a pooled data source in Spring using xapool. The following example shows how to create the Spring bean right in the Mule configuration file.

If you need more control over the configuration of the pool, you can use the standard JDBC classes. For example, you could create the following bean in the Spring configuration file (you could also create them in the Mule configuration file by prefixing everything with the Spring namespace):

You could then reference the c3p0DataSource bean in your Mule configuration:

Or you could call it from your application as follows:

To retrieve the data source from a JNDI repository, you would configure the connector as follows:

Transactions

Transactions are supported on JDBC endpoints. See Transaction Management for details.

Usage

Copy your JDBC client jar to the <MULE_HOME>/lib/user directory of your installation.

If you want to include the JDBC transport in your configuration, these are the namespaces you need to define:

For the enterprise version of the JDBC transport:

Then you need to define a connector:

Finally, you define an inbound or outbound endpoint.

  • Use an inbound endpoint if you want changes to your database to trigger a Mule flow
  • Use an outbound endpoint to make changes to the database data or to return database data to an inbound endpoint, such as using an http endpoint to display database data.

Endpoints look like this:
Inbound endpoints:

Outbound endpoints:

If you are using Mule Enterprise edition, then you must use the EE version of the JDBC transport. Therefore, if you are migrating from CE to EE, you will need to update the namespace and schemaLocation declarations to the EE versions as described above.

Exchange patterns

one-way and request-response exchange patterns are supported. If an exchange pattern is not defined, 'one-way' is the default.

Polling transport

The inbound endpoint for JDBC transport uses polling to look for new data. The default is to check every second, but it can be changed via the 'pollingFrequency' attribute on the connector.

Features supported by this module: Transactions, reconnect, expressions, etc.

Most standard transport features are supported for the jdbc transport: transactions, retry, expressions, etc. Streaming is not supported for the JDBC transport.

Example Configurations

The following example demonstrates how you would write rows in a database to their own files.

Writing database rows to their own files

The database authentication information is stored in a properties file named 'db.properties' ❶. For a MySQL database, the file would look similar to this:
database.driver=com.mysql.jdbc.Driver
database.connection=jdbc:mysql://localhost/test?user=<user>&password=<password>

The values in the property file are used in ❷ and ❸ to configure the data source bean. The jdbc connector references the data source ❹ and defines a couple of queries (❺ and ❻) which the inbound endpoint will use. The 'read' query checks the database for rows which have a 'type' column set to 1. The 'read.ack' query is automatically run for every new record found and sets the 'type' column to 2 so it will not be picked up again by the indound endpoint. A file connector is defined at ❼ to write each row found to a file with a date stamp name. Next, the flow is defined which calls the jdbc 'read' query on the inbound endpoint ❽. New database rows are then processed by the object-to-string transformer ❾ and finally written to the '/tmp/rows' directory ❿.

This example shows how to display database rows in a browser:

Display database rows in a browser

This example requires Mule Enterprise Edition to run. ❶ defines a select database query using the 'max' parameter which will be passed in the requesting url. We define some transformers at ❷ and ❸ to turn the database row into xml and set the correct Content-type for the browser to display it correctly. ❹ declares the http inbound endpoint with a url of 'http://localhost:8080/rows'. Since we are using an inbound parameter in the select query, we also need to include the 'max' parameter on the requesting url, i.e. http://localhost:8080/rows?max=5. ❺ is where the jdbc outbound endpoint will call the 'selectRows' query after the http endpoint is triggered.

Configuration Reference

Community edition:

 

Connector

Attributes of <connector...>

Name

Type

Required

Default

Description

name

name (no spaces)

yes

 

Identifies the connector so that other elements can reference it.

name

name (no spaces)

yes

 

Identifies the connector so that other elements can reference it.

dynamicNotification

boolean

no

false

Enables dynamic notifications for notifications fired by this connector. This allows listeners to be registered dynamically at runtime via the MuleContext, and the configured notification can be changed. This overrides the default value defined in the 'configuration' element.

validateConnections

boolean

no

true

Causes Mule to validate connections before use. Note that this is only a configuration hint, transport implementations may or may not make an extra effort to validate the connection. Default is true.

dispatcherPoolFactory-ref

string

no

 

Allows Spring beans to be defined as a dispatcher pool factory

pollingFrequency

long

no

 

The delay in milliseconds that will be used during two subsequent polls to the database. This is only applied to queries configured on inbound endpoints.

dataSource-ref

string

yes

 

Reference to the JDBC DataSource object. This object is typically created using Spring. When using XA transactions, an XADataSource object must be provided.

queryRunner-ref

string

no

 

Reference to the QueryRunner object, which is the object that actually runs the Query. This object is typically created using Spring. Default is org.apache.commons.dbutils.QueryRunner.

resultSetHandler-ref

string

no

 

Reference to the ResultSetHandler object, which is the object that determines which java.sql.ResultSet gets handled. This object is typically created using Spring. Default is org.apache.commons.dbutils.handlers.MapListHandler, which steps through the ResultSet and stores records as Map objects on a List.

transactionPerMessage

boolean

no

 

Whether each database record should be received in a separate transaction. If false, there will be a single transaction for the entire result set. Default is true.

queryTimeout

int

no

-1

The timeout in seconds that will be used as a query timeout for the SQL statement

Child Elements of <connector...>

Name

Cardinality

Description

spring:property

0..*

 

receiver-threading-profile

0..1

The threading profile to use when a connector receives messages.

dispatcher-threading-profile

0..1

The threading profile to use when a connector dispatches messages.

abstract-reconnection-strategy

0..1

Reconnection strategy that defines how Mule should handle a connection failure. A placeholder for a reconnection strategy element. Reconnection strategies define how Mule should attempt to handle a connection failure.

service-overrides

0..1

Service overrides allow the connector to be further configured/customized by allowing parts of the transport implementation to be overridden, for example, the message receiver or dispatcher implementation, or the message adaptor that is used.

abstract-sqlStatementStrategyFactory

0..1

The factory that determines the execution strategy based on the SQL provided.

abstract-query

0..*

Defines a set of queries. Each query has a key and a value (SQL statement). Queries are later referenced by key.

Inbound endpoint Receives or fetches data from a database. You can reference SQL select statements or call stored procedures on inbound endpoints. Statements on the inbound endpoint get invoked periodically according to the pollingInterval. Statements that contain an insert, update, or delete are not allowed.

Attributes of <inbound-endpoint...>

Name

Type

Required

Default

Description

name

name (no spaces)

no

 

Identifies the endpoint in the registry. There is no need to set the 'name' attribute on inbound or outbound endpoints, only on global endpoints.

name

name (no spaces)

no

 

Identifies the endpoint in the registry. There is no need to set the 'name' attribute on inbound or outbound endpoints, only on global endpoints.

ref

string

no

 

A reference to a global endpoint, which is used as a template to construct this endpoint. A template fixes the address (protocol, path, host, etc.), and may specify initial values for various properties, but further properties can be defined locally (as long as they do not change the address in any way).

address

string

no

 

The generic address for this endpoint. If this attribute is used, the protocol must be specified as part of the URI. Alternatively, most transports provide their own attributes for specifying the address (path, host, etc.). Note that the address attribute cannot be combined with 'ref' or with the transport-provided alternative attributes.

responseTimeout

integer

no

 

The timeout for a response if making a synchronous endpoint call

encoding

string

no

 

String encoding used for messages.

connector-ref

string

no

 

The name of the connector associated with this endpoint. This must be specified if more than one connector is defined for this transport.

transformer-refs

list of names

no

 

A list of the transformers that will be applied (in order) to the message before it is delivered to the component.

responseTransformer-refs

list of names

no

 

A list of the transformers that will be applied (in order) to the synchronous response before it is returned via the transport.

disableTransportTransformer

boolean

no

 

Don't use the default inbound/outbound/response transformer which corresponds to this endpoint's transport, if any.

mimeType

string

no

 

The mime type, e.g. text/plain or application/json

exchange-pattern

one-way/request-response

no

 

queryTimeout

int

no

-1

The timeout in seconds that will be used as a query timeout for the SQL statement

queryKey

string

no

 

The key of the query to use.

pollingFrequency

long

no

 

The delay in milliseconds that will be used during two subsequent polls to the database.

Child Elements of <inbound-endpoint...>

Name

Cardinality

Description

response

0..1

 

abstract-transaction

0..1

A placeholder for transaction elements. Transactions allow a series of operations to be grouped together.

abstract-xa-transaction

0..1

A placeholder for XA transaction elements. XA transactions allow a series of operations to be grouped together spanning different transports, such as JMS and JDBC.

abstract-transformer

0..1

A placeholder for transformer elements. Transformers convert message payloads.

abstract-filter

0..1

A placeholder for filter elements, which control which messages are handled.

abstract-security-filter

0..1

A placeholder for security filter elements, which control access to the system.

abstract-intercepting-message-processor

0..1

A placeholder for intercepting router elements.

abstract-observer-message-processor

0..1

A placeholder for message processors that observe the message but do not mutate it used for exmaple for logging.

processor

0..1

A reference to a message processor defined elsewhere.

custom-processor

0..1

 

property

0..*

Sets a Mule property. This is a name/value pair that can be set on components, services, etc., and which provide a generic way of configuring the system. Typically, you shouldn't need to use a generic property like this, since almost all functionality is exposed via dedicated elements. However, it can be useful in configuring obscure or overlooked options and in configuring transports from the generic endpoint elements.

properties

0..1

A map of Mule properties.

abstract-query

0..*

 

 

 

Outbound endpoint You can reference any SQL statement or call a stored procedure on outbound endpoints. Statements on the outbound endpoint get invoked synchronously. SQL select statements or stored procedures may return output that is handled by the ResultSetHandler and then attached to the message as the payload.

Attributes of <outbound-endpoint...>

Name

Type

Required

Default

Description

name

name (no spaces)

no

 

Identifies the endpoint in the registry. There is not need to set the 'name' attribute on inbound or outbound endpoints, only on global endpoints.

name

name (no spaces)

no

 

Identifies the endpoint in the registry. There is not need to set the 'name' attribute on inbound or outbound endpoints, only on global endpoints.

exchange-pattern

one-way/request-response

no

 

ref

string

no

 

A reference to a global endpoint, which is used as a template to construct this endpoint. A template fixes the address (protocol, path, host, etc.), and may specify initial values for various properties, but further properties can be defined locally (as long as they do not change the address in any way).

address

string

no

 

The generic address for this endpoint. If this attribute is used, the protocol must be specified as part of the URI. Alternatively, most transports provide their own attributes for specifying the address (path, host, etc.). Note that the address attribute cannot be combined with 'ref' or with the transport-provided alternative attributes.

responseTimeout

integer

no

 

The timeout for a response if making a synchronous endpoint call

encoding

string

no

 

String encoding used for messages.

connector-ref

string

no

 

The name of the connector associated with this endpoint. This must be specified if more than one connector is defined for this transport.

transformer-refs

list of names

no

 

A list of the transformers that will be applied (in order) to the message before it is delivered to the component.

responseTransformer-refs

list of names

no

 

A list of the transformers that will be applied (in order) to the synchronous response before it is returned via the transport.

disableTransportTransformer

boolean

no

 

Don't use the default inbound/outbound/response transformer which corresponds to this endpoint's transport, if any.

mimeType

string

no

 

The mime type, e.g. text/plain or application/json

queryTimeout

int

no

-1

The timeout in seconds that will be used as a query timeout for the SQL statement

queryKey

string

no

 

The key of the query to use.

pollingFrequency

long

no

 

The delay in milliseconds that will be used during two subsequent polls to the database.

Child Elements of <outbound-endpoint...>

Name

Cardinality

Description

response

0..1

 

abstract-transaction

0..1

A placeholder for transaction elements. Transactions allow a series of operations to be grouped together.

abstract-xa-transaction

0..1

A placeholder for XA transaction elements. XA transactions allow a series of operations to be grouped together spanning different transports, such as JMS and JDBC.

abstract-transformer

0..1

A placeholder for transformer elements. Transformers convert message payloads.

abstract-filter

0..1

A placeholder for filter elements, which control which messages are handled.

abstract-security-filter

0..1

A placeholder for security filter elements, which control access to the system.

abstract-intercepting-message-processor

0..1

A placeholder for intercepting router elements.

abstract-observer-message-processor

0..1

A placeholder for message processors that observe the message but do not mutate it used for exmaple for logging.

processor

0..1

A reference to a message processor defined elsewhere.

custom-processor

0..1

 

property

0..*

Sets a Mule property. This is a name/value pair that can be set on components, services, etc., and which provide a generic way of configuring the system. Typically, you shouldn't need to use a generic property like this, since almost all functionality is exposed via dedicated elements. However, it can be useful in configuring obscure or overlooked options and in configuring transports from the generic endpoint elements.

properties

0..1

A map of Mule properties.

abstract-query

0..*

 

 

Enterprise edition:

 

Connector

Attributes of <connector...>

Name

Type

Required

Default

Description

name

name (no spaces)

yes

 

Identifies the connector so that other elements can reference it.

name

name (no spaces)

yes

 

Identifies the connector so that other elements can reference it.

dynamicNotification

boolean

no

false

Enables dynamic notifications for notifications fired by this connector. This allows listeners to be registered dynamically at runtime via the MuleContext, and the configured notification can be changed. This overrides the default value defined in the 'configuration' element.

validateConnections

boolean

no

true

Causes Mule to validate connections before use. Note that this is only a configuration hint, transport implementations may or may not make an extra effort to validate the connection. Default is true.

dispatcherPoolFactory-ref

string

no

 

Allows Spring beans to be defined as a dispatcher pool factory

name

name (no spaces)

yes

 

Identifies the connector so that other elements can reference it.

name

name (no spaces)

yes

 

Identifies the connector so that other elements can reference it.

dynamicNotification

boolean

no

false

Enables dynamic notifications for notifications fired by this connector. This allows listeners to be registered dynamically at runtime via the MuleContext, and the configured notification can be changed. This overrides the default value defined in the 'configuration' element.

validateConnections

boolean

no

true

Causes Mule to validate connections before use. Note that this is only a configuration hint, transport implementations may or may not make an extra effort to validate the connection. Default is true.

dispatcherPoolFactory-ref

string

no

 

Allows Spring beans to be defined as a dispatcher pool factory

createMultipleTransactedReceivers

boolean

no

 

Whether to create multiple concurrent receivers for this connector. This property is used by transports that support transactions, specifically receivers that extend the TransactedPollingMessageReceiver, and provides better throughput.

numberOfConcurrentTransactedReceivers

integer

no

 

If createMultipleTransactedReceivers is set to true, the number of concurrent receivers that will be launched.

pollingFrequency

long

no

 

The delay in milliseconds that will be used during two subsequent polls to the database. This is only applied to queries configured on inbound endpoints.

dataSource-ref

string

yes

 

Reference to the JDBC DataSource object. This object is typically created using Spring. When using XA transactions, an XADataSource object must be provided.

queryRunner-ref

string

no

 

Reference to the QueryRunner object, which is the object that actually runs the Query. This object is typically created using Spring. Default is org.apache.commons.dbutils.QueryRunner.

resultSetHandler-ref

string

no

 

Reference to the ResultSetHandler object, which is the object that determines which java.sql.ResultSet gets handled. This object is typically created using Spring. Default is org.apache.commons.dbutils.handlers.MapListHandler, which steps through the ResultSet and stores records as Map objects on a List.

transactionPerMessage

boolean

no

 

Whether each database record should be received in a separate transaction. If false, there will be a single transaction for the entire result set. Default is true.

queryTimeout

integer

no

-1

The timeout in seconds that will be used as a query timeout for the SQL statement

Child Elements of <connector...>

Name

Cardinality

Description

spring:property

0..*

 

receiver-threading-profile

0..1

The threading profile to use when a connector receives messages.

dispatcher-threading-profile

0..1

The threading profile to use when a connector dispatches messages.

abstract-reconnection-strategy

0..1

Reconnection strategy that defines how Mule should handle a connection failure. A placeholder for a reconnection strategy element. Reconnection strategies define how Mule should attempt to handle a connection failure.

service-overrides

0..1

Service overrides allow the connector to be further configured/customized by allowing parts of the transport implementation to be overridden, for example, the message receiver or dispatcher implementation, or the message adaptor that is used.

spring:property

0..*

 

receiver-threading-profile

0..1

The threading profile to use when a connector receives messages.

dispatcher-threading-profile

0..1

The threading profile to use when a connector dispatches messages.

abstract-reconnection-strategy

0..1

Reconnection strategy that defines how Mule should handle a connection failure. A placeholder for a reconnection strategy element. Reconnection strategies define how Mule should attempt to handle a connection failure.

service-overrides

0..1

Service overrides allow the connector to be further configured/customized by allowing parts of the transport implementation to be overridden, for example, the message receiver or dispatcher implementation, or the message adaptor that is used.

abstract-sqlStatementStrategyFactory

0..1

The factory that determines the execution strategy based on the SQL provided.

abstract-query

0..*

Defines a set of queries. Each query has a key and a value (SQL statement). Queries are later referenced by key.

sqlCommandExecutorFactory

0..1

The factory that creates the command executor for the read SQL statement.

ackSqlCommandExecutorFactory

0..1

The factory that creates the command executor for the acknowledge SQL statement.

sqlCommandRetryPolicyFactory

0..1

The factory that creates the retry policies which decide if a SQL statements must be re executed in case of errors.

Inbound endpoint

Child Elements of <inbound-endpoint...>

Name

Cardinality

Description

 

 

Outbound endpoint

Child Elements of <outbound-endpoint...>

Name

Cardinality

Description

 

NOTE: The XSLT has been modified so that you can set the top level wiki header. In this example, the topstylelevel is set to 3, enabling you to generate element docs from here without rupturing the logic of your other header styles.

Transformers

The following transformers can be found in the enterprise version of the jdbc transport:

 

Maps to xml transformer Converts a List of Map objects to XML. The Map List is the same as what you get from using the default ResultSetHandler. The XML schema format is provided in the documentation.

Child Elements of <maps-to-xml-transformer...>

Name

Cardinality

Description

Xml to maps transformer Converts XML to a List of Map objects. The Map List is the same as what you get from using the default ResultSetHandler. The XML schema format is provided in the documentation.

Child Elements of <xml-to-maps-transformer...>

Name

Cardinality

Description

 

 

Maps to csv transformer Converts a List of Map objects to a CSV file. The Map List is the same as what you get from using the default ResultSetHandler.

Attributes of <maps-to-csv-transformer...>

Name

Type

Required

Default

Description

name

name (no spaces)

no

 

Identifies the transformer so that other elements can reference it. Required if the transformer is defined at the global level.

returnClass

string

no

 

The class of the message generated by the transformer. This is used if transformers are auto-selected and to validate that the transformer returns the correct type. Note that if you need to specify an array type you need postfix the class name with '[]'. For example, if you want return a an Orange[], you set the return class to 'org.mule.tck.testmodels.fruit.Orange[]'.

ignoreBadInput

boolean

no

 

Many transformers only accept certain classes. Such transformers are never called with inappropriate input (whatever the value of this attribute). If a transformer forms part of a chain and cannot accept the current message class, this flag controls whether the remaining part of the chain is evaluated. If true, the next transformer is called. If false the chain ends, keeping the result generated up to that point.

encoding

string

no

 

String encoding used for transformer output.

mimeType

string

no

 

The mime type, e.g. text/plain or application/json

delimiter

string

no

 

Delimiter used in CSV file. Default is comma.

mappingFile

string

no

 

Name of the "mapping file" used to describe the CSV file. See

http://flatpack.sourceforge.net

for details.

ignoreFirstRecord

boolean

no

 

Whether to ignore the first record. If the first record is a header, you should ignore it.

qualifier

string

no

 

The character used to escape text that contains the delimiter.

Child Elements of <maps-to-csv-transformer...>

Name

Cardinality

Description

 

 

Csv to maps transformer Converts a CSV file to a List of Map objects. The Map List is the same as what you get from using the default ResultSetHandler.

Attributes of <csv-to-maps-transformer...>

Name

Type

Required

Default

Description

name

name (no spaces)

no

 

Identifies the transformer so that other elements can reference it. Required if the transformer is defined at the global level.

returnClass

string

no

 

The class of the message generated by the transformer. This is used if transformers are auto-selected and to validate that the transformer returns the correct type. Note that if you need to specify an array type you need postfix the class name with '[]'. For example, if you want return a an Orange[], you set the return class to 'org.mule.tck.testmodels.fruit.Orange[]'.

ignoreBadInput

boolean

no

 

Many transformers only accept certain classes. Such transformers are never called with inappropriate input (whatever the value of this attribute). If a transformer forms part of a chain and cannot accept the current message class, this flag controls whether the remaining part of the chain is evaluated. If true, the next transformer is called. If false the chain ends, keeping the result generated up to that point.

encoding

string

no

 

String encoding used for transformer output.

mimeType

string

no

 

The mime type, e.g. text/plain or application/json

delimiter

string

no

 

Delimiter used in CSV file. Default is comma.

mappingFile

string

no

 

Name of the "mapping file" used to describe the CSV file. See

http://flatpack.sourceforge.net

for details.

ignoreFirstRecord

boolean

no

 

Whether to ignore the first record. If the first record is a header, you should ignore it.

qualifier

string

no

 

The character used to escape text that contains the delimiter.

Child Elements of <csv-to-maps-transformer...>

Name

Cardinality

Description

 

 

Resultset to maps transformer Transforms a java.sql.ResultSet to a List of Map objects just like the default ResultSetHandler. Useful with Oracle stored procedures that return cursors (ResultSets).

Child Elements of <resultset-to-maps-transformer...>

Name

Cardinality

Description

 

Filters

Others

NOTE: Transports may have associated transformers, filters, etc. Provide listings for all of these as well.

Schema

You can view the full schema for the JDBC transport here . The enterprise version of the schema docs is not available.

Javadoc API Reference

 

Javadoc for JDBC Transport

Refer to the EE distrobution for the enterprise version of the jdbc transport javadocs.

Maven

The JDBC transport is implemented by the mule-transport-jdbc module. You can find the source for the jdbc transport under transports/jdbc.

If you are using maven to build your application, use the following dependency snippet to include the JDBC transport in your project:
Community version:

Enterprise version:

Read more about Mule-Maven dependencies.

 

Best Practices

  • Put your database connection and credential information in a separate properties file. This allows your port you configuration file to different environments. See Example Configurations or the JDBC Transport Example for an example on how this is done

Data Source Configuration

Data source configuration has become much simpler. Previously, a data source had to be configured with Spring:

Now this is greatly simplified:

Data sources

The following elements can be used with all the database-specific data sources listed below:

Attribute

Description

loginTimeout

Login timeout.

transactionIsolation

Transaction isolation level to set on the newly created javax.sql.Connection object.

Derby

Derby data sources are created as embedded data sources. So the definition of user and password is not required.

Tip

Use the jdbc:derby-data-source configuration element to configure Derby. If you use a regular bean, you may receive errors when undeploying or redeploying the application.

Example:

The following attributes are available on the derby-data-source element:

Attribute

Description

create

If true the database will be created upon first access. See the Derby documentation for details.

database

Name of the database to connect to. This attribute cannot be used together with the url attribute.

name

Unique identifier of the data source. Use this name to reference the data source from the JDBC connector.

url

JDBC URL to use when connecting to the database. This attribute cannot be used together with the database attribute.

MySQL

Example:

The following attributes are available on the mysql-data-source element:

Attribute

Description

database

Name of the database to connect to. This attribute cannot be used together with the url attribute.

host

Database host to connect to. This attribute cannot be used together with the url attribute.

name

Unique identifier of the data source. Use this name to reference the data source from the JDBC connector.

password

Password for connecting to the database. This attribute is required.

port

Database port to connect to. This attribute cannot be used together with the url attribute.

url

JDBC URL to use when connecting to the database. This attribute cannot be used together with the database, host or port attribute.

user

User for connecting to the database. This attribute is required.

Oracle

Example:

The following attributes are available on the oracle-data-source element:

Attribute

Description

host

Database host to connect to. This attribute cannot be used together with the url attribute.

instance

Oracle Instance to connect to. This attribute cannot be used together with the url attribute.

name

Unique identifier of the data source. Use this name to reference the data source from the JDBC connector.

password

Password for connecting to the database. This attribute is required.

port

Database port to connect to. This attribute cannot be used together with the url attribute.

url

JDBC URL to use when connecting to the database. This attribute cannot be used together with the instance, host or port attribute.

user

User for connecting to the database. This attribute is required.

Postgresql

Example:

The following attributes are available on the mysql-data-source element:

Attribute

Description

database

Name of the database to connect to. This attribute cannot be used together with the url attribute.

host

Database host to connect to. This attribute cannot be used together with the url attribute.

name

Unique identifier of the data source. Use this name to reference the data source from the JDBC connector.

password

Password for connecting to the database. This attribute is required.

port

Database port to connect to. This attribute cannot be used together with the url attribute.

url

JDBC URL to use when connecting to the database. This attribute cannot be used together with the database, host or port attribute.

user

User for connecting to the database. This attribute is required.