This tutorial shows how one can add a database to Java Shindig,
so that social requests to shindig will be taking data from this database.
For this tutorial MySQL database is used.
1) Download shindig trunk as follows:
2) To use database in Shindig one could take advantage of existing in shindig "samples" project that uses JPA and EclipseLink to connect to the database from Java. This how Shindig should be compiled in this tutorial (in future it should be cleaned up to have only one command for compilation)
3) First of all we need to add JPASocialModule.java into Shindig's Guice modules. This module will provide real database implementations for PersonService, AppDataService, etc. One should add this module in java/server/src/main/webapp/WEB-INF/web.xml. Some default Guice modules should be removed from this file in order to avoid compilation problems. This is how the <context-params> section should look.
We also need to change the SocialApiGuiceModule.java to add a sample OAuthDataStore.
4) Here we will adjust Shindig settings to compile with database support. We have to move external dependencies from samples/pom.xml to social-api/pom.xml. We also add dependency on shinig-samples and (since we use mysql database) we add dependency on the database driver too. Now to compile the project we have to compile first "samples" and then the whole project (as explained in 2)
5) Generate signing keys for oAuth with the following commands. (In production use the proper keys)
Add the keys information into java/common/conf/shindig.properties. Don't forget the full path to your oauthkey.pem!!
6) Add your database information to java/samples/src/main/resources/socialjpa.properties. Here we use mysql database, so the settings are mysql specific.
7) Create database "shindig" and give access to it for user "shindig" with password "shindig".
8) Compile now the project and run jetty server according to 2)
The tables will be created in the database based on shindig's default database structure.
9) When database is created, add manually a row to the Person table with
oid = 1, person_id = 1 and display_name = Shindig User
10) Run the jetty server as explained in 2) (Ignore errors that tables already exist). Now execute a social request in your browser.
You should get back a json response (I had to reload page 3 times to get it)
This is a proof-of-concept tutorial on how to connect Shindig to a real MySQL database. Next tutorial will explain how to change shindig classes to connect to your own database structure and not the one provided by shindig samples!
There is a patch as attachment to this document that makes all the discussed changes (please use it with care because shindig trunk might have changed when you read this and do not forget to change the absolute path to your own shindig signing keys)