Named parameters support (TUSCANY) edited by Amita Vadhavkar
Page:
http://cwiki.apache.org/confluence/display/TUSCANY/Named+parameters+support
Changes:
http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=66139&originalVersion=1&revisedVersion=2
Content:
---------------------------------------------------------------------
h1. 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.
{noformat}
<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>
{noformat}
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:
{noformat}
<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>
{noformat}
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.
{noformat}
<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>
{noformat}
*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*
---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence
Unsubscribe or edit your notifications preferences
http://cwiki.apache.org/confluence/users/viewnotifications.action
If you think it was sent incorrectly contact one of the administrators
http://cwiki.apache.org/confluence/administrators.action
If you want more information on Confluence, or have a bug to report see
http://www.atlassian.com/software/confluence
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]