Monday, July 27, 2015

How to create Data Source in WSO2 DSS

In this blog we will see hot to create a data source in DSS and will use the same in one data service.

Data source is just a database connection to fetch the data from the database, but we keep it in a common place and keep using this from data service so that if in future if any change is required then no need to go again and again in each data service and change it but good option to change in one place and it will reflect in all the data service whichever is using this data source. This gives the flexibility to service to enable data stored in several of data storage, Here we will only talk about RDBMS data source.

RDBMS data sources are used to service enable data from a relational database.


Steps to create Data Source:



Click on configuration on left panel above sheen will come.


Click on Data Sources icon to create new Data Source.


Fill the details as required, here we are creating data source for MySql database.


Once you fill all the necessary information then check the connection by clicking “Test Connection” if everything is configured properly a screen will popup saying “Connection is healthy”.


This is the last step just click on the save button to create this data source. It will be added in above screen.

Example:

 <data name="EmployeeDataService" enableBatchRequests="false" enableBoxcarring="false" serviceStatus="active">    
   <config id="mySqlDataSource">     
   <property name="carbon_datasource_name">mySqlDataSource</property>  
   </config>    
   <query id="DataQueryEmp" useConfig="mySqlDataSource">     
    <sql>select EMP_ID, EMP_NAME, EMP_ADDRESS from emp_table where EMP_ID=?</sql>     
    <result element="employees" rowName="employee" defaultNamespace="http://shriwithjava.blogspot.co.nz/">       
      <element name="id" column="EMP_ID" xsdType="xs:string" />       
      <element name="name" column="EMP_NAME" xsdType="xs:string" />       
      <element name="address" column="EMP_ADDRESS" xsdType="xs:string" />     
    </result>    
       <param name="empId" paramType="SCALAR" sqlType="STRING" type="IN" />    
   </query>    
   <operation name="getEmployees">     
    <description></description>     
    <call-query href="DataQueryEmp" >  
 <with-param name="empId" query-param="EmpId" />   
 </call-query>      
   </operation>  
 </data>  

No comments:

Post a Comment