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 |
|---|---|---|---|
|
|
|
(required) |
The Pricefx object type to fetch from. |
|
|
|
-- |
Name of the filter bean for the query. |
|
|
|
-- |
SQL-like syntax alternative to filter. Example: |
|
|
|
-- |
Advanced filter expression for comparing columns instead of values. |
|
|
|
|
Enable batched fetching for large data sets. |
|
|
|
|
Number of rows per batch when batchedMode is enabled. |
|
|
|
-- |
Start row for pagination. |
|
|
|
-- |
End row for pagination. |
|
|
|
-- |
If true, return only the row count, not data. |
|
|
|
-- |
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. |
|
|
|
-- |
Comma-separated field names for server-side projection (better performance). Result is a list of field values, not a Map. |
|
|
|
-- |
Sort-by clause. Overrides any sortBy defined in the filter. |
|
|
|
|
Add DISTINCT clause to the search query. |
|
|
|
|
Whether null fields should be returned. |
|
|
|
-- |
Output format: JSON, CSV, EXCEL, PDF, JSON_DETAIL, PDF_DETAIL, EXCEL_DETAIL. |
|
|
|
|
Use human-readable column names in CSV output. |
|
|
|
-- |
Unique name of a Data Source or Datamart (required for DMDS, DM). |
|
|
|
-- |
Pricefx connection bean name. |
|
|
|
-- |
Where to store the result: |
|
|
|
-- |
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:
<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:
<to uri="pfx-api:fetch?objectType=P&filter=activeProductsFilter"/>
Inline SQL Syntax
Use the sql parameter with a SQL-like query (the FROM clause is omitted):
<to uri="pfx-api:fetch?objectType=P&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:
<to uri="pfx-api:fetch?objectType=DMDS&dsUniqueName=MyDS&filter=myFilter&batchedMode=true&batchSize=10000"/>
When batchedMode=true:
-
The first call to
fetchretrieves the first batch and stores iteration state in the exchange -
Use
pfx-api:fetchIteratorin a loop to retrieve subsequent batches -
The iterator returns
null(or empty) when all data has been fetched
Batched Mode with Split
<route>
<from uri="direct:fetchLargeDataset"/>
<to uri="pfx-api:fetch?objectType=DMDS&dsUniqueName=MyDS&filter=myFilter&batchedMode=true&batchSize=10000"/>
<split>
<simple>${body}</simple>
<to uri="direct:processRecord"/>
</split>
<loop doWhile="true">
<simple>${body} != null && ${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
<to uri="pfx-api:fetch?objectType=P&filter=myFilter&resultFields=sku,attribute1,attribute2"/>
Result: [{"sku": "ABC", "attribute1": "val1", "attribute2": "val2"}, ...]
valueFields Example
<to uri="pfx-api:fetch?objectType=P&filter=myFilter&valueFields=sku,attribute1,attribute2"/>
Result: [["ABC", "val1", "val2"], ...]
Sorting
Use sortBy to control the order of results:
<to uri="pfx-api:fetch?objectType=P&filter=myFilter&sortBy=sku ASC"/>
The sortBy parameter overrides any sortBy defined in the filter bean.
Examples
Fetch All Products
<route>
<from uri="direct:fetchProducts"/>
<to uri="pfx-api:fetch?objectType=P&filter=allProductsFilter"/>
</route>
Fetch with SQL and Pagination
<route>
<from uri="direct:fetchFiltered"/>
<to uri="pfx-api:fetch?objectType=P&sql=SELECT sku, attribute1 WHERE attribute2 > 100 ORDER BY sku ASC&startRow=0&endRow=1000"/>
</route>
Fetch with CSV Output
<route>
<from uri="direct:fetchCsv"/>
<to uri="pfx-api:fetch?objectType=P&filter=myFilter&output=CSV&useColumnNames=true"/>
</route>
Fetch Data Source with Batched Mode
<route>
<from uri="direct:fetchDS"/>
<to uri="pfx-api:fetch?objectType=DMDS&dsUniqueName=MyDS&filter=myFilter&batchedMode=true&batchSize=10000"/>
</route>
Fetch Count Only
<route>
<from uri="direct:countProducts"/>
<to uri="pfx-api:fetch?objectType=P&filter=myFilter&countOnly=true"/>
<log message="Total products: ${body}"/>
</route>
Fetch with Distinct Results
<route>
<from uri="direct:fetchDistinct"/>
<to uri="pfx-api:fetch?objectType=P&filter=myFilter&valueFields=attribute1&distinctResults=true"/>
</route>
Headers Produced
|
Header |
Type |
Description |
|---|---|---|
|
|
|
Signals that the fetch preview result is Base64-encoded. |
Common Pitfalls
-
Not using batchedMode for large data -- Fetching millions of rows without batchedMode will load everything into memory at once, causing OutOfMemoryError. Always use
batchedMode=truefor large datasets. -
Confusing resultFields and valueFields --
resultFieldsreturns Maps with named keys;valueFieldsreturns arrays of values. If your downstream processing expects Maps, do not use valueFields. -
Missing dsUniqueName for DMDS/DM -- When fetching from a Data Source or Datamart,
dsUniqueNameis required. -
SQL syntax pitfalls -- The
sqlparameter does not support a FROM clause. Only SELECT, WHERE, and ORDER BY are supported. Complex joins are not available. -
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.
-
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.