In this tutorial, we will run through the process of exposing and RDBMS as an OData service. When OData is enabled for an datasource, you do not need to manually define CRUD operations. These will be automatically created.
...
Follow the steps given below to set up a MySQL database for this tutorial.
- Install the MySQL server and the MySQL client.
- Download the JDBC driver for MySQL from here and copy it to your
<DSS_HOME>/repository/components/lib
directory. Create a MySQL database with the following table:
Code Block CREATE TABLE ACCOUNT(AccountID int NOT NULL,Branch varchar(255) NOT NULL, AccountNumber varchar(255),AccountType ENUM('CURRENT', 'SAVINGS') NOT NULL, Balance FLOAT,ModifiedDate DATE,PRIMARY KEY (AccountID));
Enter the following data into the table:
Code Block INSERT INTO ACCOUNT VALUES (1,"AOB","A00012","CURRENT",231221,'2014-12-02');
...
Access the data service using CRUD operations
Open a command prompt execute the following CURL commands using CRUD operations:
Note |
---|
Note that the user should have privileges to perform CRUD operations on the database. For Oracle databases, the user should be the schema owner. If not, the OData service will not work properly. |
To get the service document:
Code Block curl -X GET -H 'Accept: application/json' https://10.100.5.65localhost:9443/services/dataservice/odata/{data_service_name}/{data_source_id}
To get the metadata of the service:
Code Block curl -X GET -H 'Accept: application/xml' https://10.100.5.65localhost:9443/services/dataservice/odata/{data_service_name}/{data_source_id}/$metadata
To read details from the ACCOUNT table:
Code Block curl -X GET -H 'Accept: application/xml' https://10.100.5.65localhost:9443/services/dataserviceodata/{data_service_name}/{data_source_id}/ACCOUNT