OData Producer Codegen for JDBC(odata-codegen) can rapidly convert JDBC-backend datasource into OData service in a batch and automatical way. which enable data service consumers to easily access data through standard OData clients like MS Office Excel.
This tool aims to improve the productivity for data service providers. A fter simple configuration and click one button, it will generate OData compliant Restful API, Which gains immediate data interoperability.
This tool is now supporting OData v2.
###Required Tools:###
- [Apache Maven] (http://maven.apache.org/)
- A [GIT] (http://git-scm.com/) client
###Clone and build:### clone the repository to local:
git clone https://github.com/msopentechcn/odata-producer-codegen-for-jdbc.git
Import Maven project - odata-codegen into Java IDE, and build:
Maven will automatically download all the dependencies jars, and build directory structure.
###Config JDBC datasource### After build phase complete, config JDBC datasource, use MySQL as a example:
Copy MySQL JDBC driver to webapp/WEB-INF/lib/
Modify resources/META-INF/persistence.xml,configure JDBC connection information:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="odata2_jpa2" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/database?characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="username"/>
<property name="javax.persistence.jdbc.password" value="password"/>
</properties>
</persistence-unit>
</persistence>
###Deploy to app server### Use Tomcat as a example:
###Publish OData Service### Go to odata-codegen publish UI:http://localhost:8080/odata-codegen/admin
Move tables to be published to the right list:
Click "GENERATE", It will soon return:
Restart Tomcat Server.
###Begin to access your OData Service### After restarting you application server,you can access OData service from:http://localhost:8080/odata-codegen/OdataServlet.svc
###Note### If database schema has been changed, like new tables, delete tables, change column definitions, re-publish Publish OData Service is needed.