pfx-api:fetch

pfx-api:fetch

The primary export method. Fetch (query) data from any supported Pricefx object type with support for filters, SQL syntax, pagination, batched mode, field projection, sorting, and multiple output formats.


Overview

The fetch method retrieves data from Pricefx and places it into the exchange body. It supports:

  • Filtering via named filter beans or inline SQL syntax

  • Batched mode for large data sets (millions of rows)

  • Pagination with startRow/endRow

  • Field projection (resultFields for client-side, valueFields for server-side)

  • Sorting and distinct results

  • Multiple output formats: JSON, CSV, EXCEL, PDF, and detail variants

URI Format

pfx-api:fetch?objectType=P&filter=myFilter

Parameters

Parameter

Type

Default

Description

objectType

ObjectType

(required)

The Pricefx object type to fetch from.

filter

String

--

Name of the filter bean for the query.

sql

String

--

SQL-like syntax alternative to filter. Example: SELECT sku, attribute1 WHERE attribute2 > 100 ORDER BY sku ASC

customFilterExpression

String

--

Advanced filter expression for comparing columns instead of values.

batchedMode

Boolean

false

Enable batched fetching for large data sets.

batchSize

Integer

5000

Number of rows per batch when batchedMode is enabled.

startRow

Integer

--

Start row for pagination.

endRow

Integer

--

End row for pagination.

countOnly

Boolean

--

If true, return only the row count, not data.

resultFields

String

--

Comma-separated field names to include in the result (client-side projection). All fields are fetched from the DB; filtering happens in the response. Result is a Map.

valueFields

String

--

Comma-separated field names for server-side projection (better performance). Result is a list of field values, not a Map.

sortBy

String

--

Sort-by clause. Overrides any sortBy defined in the filter.

distinctResults

Boolean

false

Add DISTINCT clause to the search query.

enableNullFields

Boolean

false

Whether null fields should be returned.

output

OutputType

--

Output format: JSON, CSV, EXCEL, PDF, JSON_DETAIL, PDF_DETAIL, EXCEL_DETAIL.

useColumnNames

Boolean

false

Use human-readable column names in CSV output.

dsUniqueName

String

--

Unique name of a Data Source or Datamart (required for DMDS, DM).

connection

String

--

Pricefx connection bean name.

outputTarget

String

--

Where to store the result: body (default), header, or property.

outputTargetName

String

--

Name of the header/property when outputTarget is not body.


Filter vs SQL

You can specify the query in two ways:

Named Filter Bean

Define a filter in your Spring XML context:

XML
<pfx:filter id="activeProductsFilter" resultFields="sku,attribute1,attribute2" sortBy="sku">
    <pfx:and>
        <pfx:criterion fieldName="attribute1" operator="notNull"/>
        <pfx:criterion fieldName="attribute2" operator="greaterThan" value="100"/>
    </pfx:and>
</pfx:filter>

Reference it in the URI:

XML
<to uri="pfx-api:fetch?objectType=P&amp;filter=activeProductsFilter"/>

Inline SQL Syntax

Use the sql parameter with a SQL-like query (the FROM clause is omitted):

XML
<to uri="pfx-api:fetch?objectType=P&amp;sql=SELECT sku, attribute1 WHERE attribute2 > 100 ORDER BY sku ASC"/>

Batched Mode

For large data sets, enable batched mode to fetch data in chunks:

XML
<to uri="pfx-api:fetch?objectType=DMDS&amp;dsUniqueName=MyDS&amp;filter=myFilter&amp;batchedMode=true&amp;batchSize=10000"/>

When batchedMode=true:

  1. The first call to fetch retrieves the first batch and stores iteration state in the exchange

  2. Use pfx-api:fetchIterator in a loop to retrieve subsequent batches

  3. The iterator returns null (or empty) when all data has been fetched

Batched Mode with Split

XML
<route>
    <from uri="direct:fetchLargeDataset"/>
    <to uri="pfx-api:fetch?objectType=DMDS&amp;dsUniqueName=MyDS&amp;filter=myFilter&amp;batchedMode=true&amp;batchSize=10000"/>
    <split>
        <simple>${body}</simple>
        <to uri="direct:processRecord"/>
    </split>
    <loop doWhile="true">
        <simple>${body} != null &amp;&amp; ${body.size()} > 0</simple>
        <to uri="pfx-api:fetchIterator"/>
        <split>
            <simple>${body}</simple>
            <to uri="direct:processRecord"/>
        </split>
    </loop>
</route>

resultFields vs valueFields

  • resultFields: Client-side projection. All fields are fetched from the database, but only the specified fields are included in the result Map. Use when you need named fields.

  • valueFields: Server-side projection. Only the specified fields are fetched from the database. More efficient for large tables. The result is a list of values (not a Map), in the same order as the specified fields.

resultFields Example

XML
<to uri="pfx-api:fetch?objectType=P&amp;filter=myFilter&amp;resultFields=sku,attribute1,attribute2"/>

Result: [{"sku": "ABC", "attribute1": "val1", "attribute2": "val2"}, ...]

valueFields Example

XML
<to uri="pfx-api:fetch?objectType=P&amp;filter=myFilter&amp;valueFields=sku,attribute1,attribute2"/>

Result: [["ABC", "val1", "val2"], ...]


Sorting

Use sortBy to control the order of results:

XML
<to uri="pfx-api:fetch?objectType=P&amp;filter=myFilter&amp;sortBy=sku ASC"/>

The sortBy parameter overrides any sortBy defined in the filter bean.


Examples

Fetch All Products

XML
<route>
    <from uri="direct:fetchProducts"/>
    <to uri="pfx-api:fetch?objectType=P&amp;filter=allProductsFilter"/>
</route>

Fetch with SQL and Pagination

XML
<route>
    <from uri="direct:fetchFiltered"/>
    <to uri="pfx-api:fetch?objectType=P&amp;sql=SELECT sku, attribute1 WHERE attribute2 > 100 ORDER BY sku ASC&amp;startRow=0&amp;endRow=1000"/>
</route>

Fetch with CSV Output

XML
<route>
    <from uri="direct:fetchCsv"/>
    <to uri="pfx-api:fetch?objectType=P&amp;filter=myFilter&amp;output=CSV&amp;useColumnNames=true"/>
</route>

Fetch Data Source with Batched Mode

XML
<route>
    <from uri="direct:fetchDS"/>
    <to uri="pfx-api:fetch?objectType=DMDS&amp;dsUniqueName=MyDS&amp;filter=myFilter&amp;batchedMode=true&amp;batchSize=10000"/>
</route>

Fetch Count Only

XML
<route>
    <from uri="direct:countProducts"/>
    <to uri="pfx-api:fetch?objectType=P&amp;filter=myFilter&amp;countOnly=true"/>
    <log message="Total products: ${body}"/>
</route>

Fetch with Distinct Results

XML
<route>
    <from uri="direct:fetchDistinct"/>
    <to uri="pfx-api:fetch?objectType=P&amp;filter=myFilter&amp;valueFields=attribute1&amp;distinctResults=true"/>
</route>

Headers Produced

Header

Type

Description

FilePreviewResultAsBase64

Boolean

Signals that the fetch preview result is Base64-encoded.


Common Pitfalls

  1. Not using batchedMode for large data -- Fetching millions of rows without batchedMode will load everything into memory at once, causing OutOfMemoryError. Always use batchedMode=true for large datasets.

  2. Confusing resultFields and valueFields -- resultFields returns Maps with named keys; valueFields returns arrays of values. If your downstream processing expects Maps, do not use valueFields.

  3. Missing dsUniqueName for DMDS/DM -- When fetching from a Data Source or Datamart, dsUniqueName is required.

  4. SQL syntax pitfalls -- The sql parameter does not support a FROM clause. Only SELECT, WHERE, and ORDER BY are supported. Complex joins are not available.

  5. Filter bean not found -- If the named filter bean does not exist in the Spring context, the fetch will fail with a bean resolution error. Verify the filter ID matches exactly.

  6. sortBy override -- When both the filter bean and the URI parameter define sortBy, the URI parameter wins. This can be surprising if you expect the filter's sort order.