Apache Tuscany > Home > DAS Overview > DAS Java > DAS Java Documentation Menu > DAS Java Developer Guide > RDB DAS Java > RDB DAS - User Guide > Named parameters support User List | Dev List | Issue Tracker  

Named parameters support

JDB API requires indexed parameter setting. i.e. statement.setXXX(int, value). But in the DAS client
it may be helpful to provide named parameters setting on the command. This is particularly convenient
when the table involves many columns during insert/update.

Below are config schema portion supporting this.

<xsd:complexType name="Parameter">
  <xsd:attribute name="name" type="xsd:string"/>
  <xsd:attribute name="columnType" type="xsd:string"/>
  <xsd:attribute name="direction" type="xsd:string" default="IN"/>
  <xsd:attribute name="index" type="xsd:int"/>
</xsd:complexType>
<xsd:complexType name="Parameters">
  <xsd:sequence>
	<xsd:element maxOccurs="unbounded" minOccurs="0" name="Parameter" type="config:Parameter"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Create">
  <xsd:sequence>
    <xsd:element maxOccurs="1" minOccurs="0" name="Parameters" type="config:Parameters"/>
  </xsd:sequence>
  <xsd:attribute name="sql" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="Update">
  <xsd:sequence>
    <xsd:element maxOccurs="1" minOccurs="0" name="Parameters" type="config:Parameters"/>
  </xsd:sequence>
  <xsd:attribute name="sql" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="Delete">
  <xsd:sequence>
    <xsd:element maxOccurs="1" minOccurs="0" name="Parameters" type="config:Parameters"/>
  </xsd:sequence>
  <xsd:attribute name="sql" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="Command">
  <xsd:sequence>
     <xsd:element maxOccurs="unbounded" minOccurs="0" name="Parameter" type="config:Parameter"/>
     <xsd:element maxOccurs="unbounded" minOccurs="0" name="ResultDescriptor" type="config:ResultDescriptor"/>
  </xsd:sequence>
  <xsd:attribute name="name" type="xsd:string"/>
  <xsd:attribute name="SQL" type="xsd:string"/>
  <xsd:attribute name="kind" type="xsd:string"/>
</xsd:complexType>

User can do Command.setParameter(String name, Object value), getParameter(String name). Indexed set/getParameter() is available as before. Also <create>, <update>, <delete> from Config support named parameters.

example config:

<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd"> 
<Table tableName="CUSTOMER">  		 
  <create sql="insert into customer values (?, ?, ?)" >
    <Parameters>
      <Parameter name="ID" index="1"/>
      <Parameter name="LASTNAME" index="1"/>
      <Parameter name="ADDRESS" index="3"/>
    </Parameters>
  </create>
</Table>
<Command name="createCustomer" SQL="insert into CUSTOMER values ( ?, ?, ?)" kind="Insert">
   <Parameter name="ID" index="1"/>
   <Parameter name="LASTNAME" index="2"/>
   <Parameter name="ADDRESS" index="3"/>
</Command>

if +ve index is specified in Parameter, it is used, else auto-increment is used. As List is an ordered collection, the sequence(index value) appearing in the cofig file will be maintained. Partially specifying indexes is not supported (i.e. give index for 2 out of 3 params and leave one without it, is not supported)
Also, if indexes are specified, the ordering in config is flexible, i.e. below is valid.

<Command name="createCustomer" SQL="insert into CUSTOMER values ( ?, ?, ?)" kind="Insert">   
   <Parameter name="LASTNAME" index="2"/>
   <Parameter name="ID" index="1"/>
   <Parameter name="ADDRESS" index="3"/>
</Command>

Note Convention over config is followed, if Parameters are not defined in config, the sequence
should match the table columns convention,else user should specify params on command in config and specify index attributes in them config

website stats