Difference between revisions of "DataRetriever"

From GreenVulcano Wiki
Jump to: navigation, search
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
''DataRetriever'' defines a helper function.
+
==Description==
  
It is defined by four parameters:
+
The element ''DataRetriever'' allows to define a helper function.
  
* '''cacheable''' (true|false): If true the calculated function value, for the given parameters set, is cached for future access during the service processing.<br/> The cache is canceled at service end. <br/>  Default false.
+
=={{GVESB}} configuration==
  
* '''DataRetriever''': can contains the following placeholders:
+
The DataRetriever elements define helper functions used in data transformations for enriching XML products. Might contain [[placeholders]].
  
# fixed : a text string;
+
It is defined by the following parameters:
# <nowiki>${{propname}}</nowiki>      : a System property name;
+
{|class="gvtable"
# <nowiki>sp{{propname}}</nowiki>    : a System property name;
+
! Attribute !! Type !! Description
# <nowiki>@{{propname}}</nowiki>      : a inProperties property name;
+
|-
# <nowiki>timestamp{{pattern}}</nowiki> : return the current timestamp formatted as 'pattern'
+
| cacheable || optional || If true the calculated function value, for the given parameters set, is cached for future access during the service processing.<br/> The cache is cancelled at service end. <br/> Default false.
# <nowiki>dateformat{{date::source-pattern::dest-pattern}}</nowiki> : reformat 'date' from 'source-pattern' to 'dest-pattern'
+
|-
# <nowiki>decode{{field[::cond1::val1][::cond2::val2][cond...n::val...n]::default}}</nowiki> : evaluate as if-then-else; if 'field' is equal to cond1...n, return the value of val1...n, otherwise 'default'
+
| method || required || Helper function name.
# <nowiki>decodeL{{sep::field[::cond1::val1][::cond2::val2][cond...n::val...n]::default}}</nowiki> : is equivalent to 'decode', with the difference that 'condX' can be a list of values separated by 'sep'
+
|-
# <nowiki>js{{scope::script}}</nowiki> : evaluate a JavaScript script, using the scope 'scope'
+
| signature || optional || Comma-separated list of parameters name to be substituted in the function.
# <nowiki>sql{{conn::statement}}</nowiki>  : execute a select sql statement sql and return the value of the first field of the first selected record.<br/> The 'conn' parameter is the JNDI name of a DataSource
+
|}
# <nowiki>sqllist{{conn[::sep]::statement}}</nowiki>: execute a select sql statement sql and return the value of the first field of all selected records as a 'sep' separated list.<br/> The 'conn' parameter is the JNDI name of a DataSource<br/>  The 'sep' parameter defaults to comma
 
# <nowiki>sqltable{{conn::statement}}</nowiki>: executes a select sql statement and returns all values of returned cursor as an XML.<br/> The 'conn' parameter is the JNDI name of a DataSource
 
# <nowiki>ognl{{script}}</nowiki> : evaluate a OGNL script
 
  
* '''method''': Helper function name.
 
  
* '''signature''': Comma-separated list of parameters name to be substituted in the function.
+
===Examples of GenericRetriever functions===
 +
 
 +
Configuration examples.
 +
<syntaxhighlight lang="xml">
 +
<RetrieverConfig>
 +
    <GenericRetriever class="it.greenvulcano.gvesb.datahandling.utils.GenericRetriever"
 +
                        type="retriever">
 +
 
 +
        <DataRetriever cacheable="true" method="getCityID" signature="NAME">
 +
            select ID from CITY
 +
            where NAME='@{{NAME}}'
 +
        </DataRetriever>
 +
 
 +
        <DataRetriever cacheable="true" method="getCityName" signature="ID">
 +
            select NAME from CITY
 +
            where ID=@{{ID}}
 +
        </DataRetriever>
 +
 
 +
        <DataRetriever method="getPersonID" signature="NAME,CITY">
 +
            select ID from PERSON
 +
            where NAME='@{{NAME}}'
 +
            and ID_CITY=(select ID from CITY where NAME='@{{CITY}}')
 +
        </DataRetriever>
 +
 
 +
        <DataRetriever cacheable="true" method="getCardID" signature="NUMBER,ID_OWNER">
 +
            select ID from CREDIT_CARD
 +
            where CNUMBER='@{{NUMBER}}'
 +
            and ID_OWNER=@{{ID_OWNER}}
 +
        </DataRetriever>
 +
 
 +
        <DataRetriever method="getSeqVal">
 +
            select SEQ_PERSON_ID.nextval from dual
 +
        </DataRetriever>
 +
    </GenericRetriever>
 +
</RetrieverConfig>
 +
</syntaxhighlight>
 +
 
 +
Function description.
 +
{|class="gvtable"
 +
! Function !! Parameters !! Cacheable !! Description
 +
|-
 +
| getCityID || NAME || true || Returns the ID field of the first record of table CITY with field NAME equals to the passed parameter.<br/>The parameter is cacheable so, for the given parameter value, the subsequent call returns the same value.
 +
|-
 +
| getCityName || ID || true || Returns the NAME field of the first record of table CITY with field ID equals to the passed parameter.<br/>The parameter is cacheable so, for the given parameter value, the subsequent call returns the same value.
 +
|-
 +
| getPersonID || NAME,CITY || false || Returns the ID field of a record of table PERSON with field NAME equals to the first passed parameter and with an external reference to a record of table CITY with field NAME equals to the second passed parameter.
 +
|-
 +
| getCardID || NUMBER,ID_OWNER || true || Returns the ID field of the first record of table CREDIT_CARD with field CNUMBER equals to the first passed parameter and the field ID_OWNER equals to the second passed parameter.<br/>The parameter is cacheable so, for the given parameters value, the subsequent call returns the same value.
 +
|-
 +
| getSeqVal || || false || Returns the next sequence value.
 +
|}
 +
 
 +
Usage examples in XSL transformation. The examples use the calling procedure of Java classes of [http://xml.apache.org/xalan-j/extensions.html#ex-java-namespace Xalan-J XSLT Engine].
 +
<syntaxhighlight lang="xml">
 +
    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/CreditUpdate.xsl -->
 +
    <xsl:variable name="name" select="/PersonsData/PersonData/Name"/>
 +
    <xsl:variable name="city" select="/PersonsData/PersonData/City"/>
 +
    <xsl:element name="col">
 +
        <xsl:value-of 
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                      ('getPersonID',concat($name,',',$city))"/>
 +
    </xsl:element>
 +
 
 +
    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/PersonInsertFull.xsl -->
 +
    <xsl:template match="PersonData">
 +
        <xsl:variable name="PersonId" 
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                ('getPersonID', concat(Name, ',', City))"/>
 +
        <xsl:variable name="CityId"
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                ('getCityID', City)"/>
 +
    .....
 +
        <xsl:variable name="PersonId" 
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                ('getSeqVal', '')"/>
 +
    .....
 +
    <xsl:template match="CardData">
 +
        <xsl:param name="OwnerId"/>
 +
        <xsl:variable name="CardId"
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                ('getCardID', concat(Number, ',', $OwnerId))"/>
 +
</syntaxhighlight>
 +
 
 +
<div class="version_ge3.4.0.9">
 +
From 3.4.0.9 version the getData method can accept 3 parameters, in order to specify the DataRetriever's actual parameters value separator, useful if some parameter value contains a comma.
 +
<syntaxhighlight lang="xml">
 +
    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/CreditUpdate.xsl -->
 +
    <xsl:variable name="name" select="/PersonsData/PersonData/Name"/>
 +
    <xsl:variable name="city" select="/PersonsData/PersonData/City"/>
 +
    <xsl:element name="col">
 +
        <xsl:value-of 
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                      ('getPersonID',concat($name,'$',$city), '$')"/>
 +
    </xsl:element>
 +
 
 +
    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/PersonInsertFull.xsl -->
 +
    <xsl:template match="PersonData">
 +
        <xsl:variable name="PersonId" 
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                ('getPersonID', concat(Name, '#', City), '#')"/>
 +
    .....
 +
    <xsl:template match="CardData">
 +
        <xsl:param name="OwnerId"/>
 +
        <xsl:variable name="CardId"
 +
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
 +
                ('getCardID', concat(Number, '-', $OwnerId), '-')"/>
 +
</syntaxhighlight>
 +
</div>

Latest revision as of 15:59, 27 January 2016

Description

The element DataRetriever allows to define a helper function.

GreenVulcano® ESB configuration

The DataRetriever elements define helper functions used in data transformations for enriching XML products. Might contain placeholders.

It is defined by the following parameters:

Attribute Type Description
cacheable optional If true the calculated function value, for the given parameters set, is cached for future access during the service processing.
The cache is cancelled at service end.
Default false.
method required Helper function name.
signature optional Comma-separated list of parameters name to be substituted in the function.


Examples of GenericRetriever functions

Configuration examples.

<RetrieverConfig>
    <GenericRetriever class="it.greenvulcano.gvesb.datahandling.utils.GenericRetriever"
                        type="retriever">

        <DataRetriever cacheable="true" method="getCityID" signature="NAME">
            select ID from CITY
            where NAME='@{{NAME}}'
        </DataRetriever>

        <DataRetriever cacheable="true" method="getCityName" signature="ID">
            select NAME from CITY
            where ID=@{{ID}}
        </DataRetriever>

        <DataRetriever method="getPersonID" signature="NAME,CITY">
            select ID from PERSON
            where NAME='@{{NAME}}'
            and ID_CITY=(select ID from CITY where NAME='@{{CITY}}')
        </DataRetriever>

        <DataRetriever cacheable="true" method="getCardID" signature="NUMBER,ID_OWNER">
            select ID from CREDIT_CARD
            where CNUMBER='@{{NUMBER}}'
            and ID_OWNER=@{{ID_OWNER}}
        </DataRetriever>

        <DataRetriever method="getSeqVal">
            select SEQ_PERSON_ID.nextval from dual
        </DataRetriever>
    </GenericRetriever>
</RetrieverConfig>

Function description.

Function Parameters Cacheable Description
getCityID NAME true Returns the ID field of the first record of table CITY with field NAME equals to the passed parameter.
The parameter is cacheable so, for the given parameter value, the subsequent call returns the same value.
getCityName ID true Returns the NAME field of the first record of table CITY with field ID equals to the passed parameter.
The parameter is cacheable so, for the given parameter value, the subsequent call returns the same value.
getPersonID NAME,CITY false Returns the ID field of a record of table PERSON with field NAME equals to the first passed parameter and with an external reference to a record of table CITY with field NAME equals to the second passed parameter.
getCardID NUMBER,ID_OWNER true Returns the ID field of the first record of table CREDIT_CARD with field CNUMBER equals to the first passed parameter and the field ID_OWNER equals to the second passed parameter.
The parameter is cacheable so, for the given parameters value, the subsequent call returns the same value.
getSeqVal false Returns the next sequence value.

Usage examples in XSL transformation. The examples use the calling procedure of Java classes of Xalan-J XSLT Engine.

    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/CreditUpdate.xsl -->
    <xsl:variable name="name" select="/PersonsData/PersonData/Name"/>
    <xsl:variable name="city" select="/PersonsData/PersonData/City"/>
    <xsl:element name="col">
        <xsl:value-of   
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                       ('getPersonID',concat($name,',',$city))"/>
    </xsl:element>

    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/PersonInsertFull.xsl -->
    <xsl:template match="PersonData">
        <xsl:variable name="PersonId"  
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                 ('getPersonID', concat(Name, ',', City))"/>
        <xsl:variable name="CityId"
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                 ('getCityID', City)"/>
    .....
        <xsl:variable name="PersonId"  
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                 ('getSeqVal', '')"/>
    .....
    <xsl:template match="CardData">
        <xsl:param name="OwnerId"/>
        <xsl:variable name="CardId" 
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                 ('getCardID', concat(Number, ',', $OwnerId))"/>

From 3.4.0.9 version the getData method can accept 3 parameters, in order to specify the DataRetriever's actual parameters value separator, useful if some parameter value contains a comma.

    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/CreditUpdate.xsl -->
    <xsl:variable name="name" select="/PersonsData/PersonData/Name"/>
    <xsl:variable name="city" select="/PersonsData/PersonData/City"/>
    <xsl:element name="col">
        <xsl:value-of   
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                       ('getPersonID',concat($name,'$',$city), '$')"/>
    </xsl:element>

    <!-- from gvdte/datasource/xsl/DataHandler/CREDIT/PersonInsertFull.xsl -->
    <xsl:template match="PersonData">
        <xsl:variable name="PersonId"  
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                 ('getPersonID', concat(Name, '#', City), '#')"/>
    .....
    <xsl:template match="CardData">
        <xsl:param name="OwnerId"/>
        <xsl:variable name="CardId" 
          select="java:it.greenvulcano.gvesb.datahandling.utils.GenericRetriever.getData
                 ('getCardID', concat(Number, '-', $OwnerId), '-')"/>