This post is a continuation of the previous post where we connected a database to Java Shindig. Now I will use my own database with shindig. In other words when a social request is executed, the data will be taken from my own social database.
To start with you have to have a working version of shindig-database connection as described in previous post.
1) Imagine I have a social MySQL database with only one table 'people' and three colums:
This will be my own social database that I want to connect to Shindig. (To make life easier you can just remove tables and redundant columns from shindig database (generated in previous post) and rename 'person' table to 'people' table). Add the following data into table: .
2) Now we have to tell shindig not to generate database every time it loads. Normally it should be possible to do through java/samples/src/main/resources/META-INF/persistence.xml but it seems Shindig's samples implementation doesn't take those properties from that file. So I had to change the following file: java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/eclipselink/Bootstrap.java
3) Now we have to change the file java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/PersonDb.java so that it takes needed for us data from the database. Read the explanations in comments.
4) Now recompile project and run jetty server
5) 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)
So, now you are ready to change PersonDb.java, etc. files according to your own social database implementation! Concerning JPQL syntax I found the following useful: JPQL Language Reference
Monday, 19 July 2010
Monday, 12 July 2010
Java Shindig: how to connect to real database (Updated July-2011)
I decided finally to switch to Java Shindig from PHP Shindig due to the better support and development of the first one. I had my working shindig installation for PHP with my own social database. I wanted to have the same with Java Shindig. It turned out to be much harder to set it up in Java (maybe because of my java and maven ignorance). In PHP I only changed the database settings and added my own PersonService, AppDataService implementations. In Java the concept is the same but the way it is done was not that obvious for me. So, here is what I did.
1) I downloaded the shindig trunk from here:
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 I compile the project:
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 this file looks for me.
I also had to change the SocialApiGuiceModule.java to add a sample OAuthDataStore. I also had to change the JPASocialModule.java to add a sample implementation for MediaItemService, MessageService, AlbumService. 4) We will have to recompile shindig with database support now. We have to change 3 files. trunk/pom.xml - add samples module to default "all" and "run" and to dependencyManagement.
trunk/java/server/pom.xml - add dependency on shindig-samples
trunk/java/samples/pom.xml - add dependency on mysql driver (since I use mysql database)
Now to compile the project with maven command as in 2)
5) Generate signing keys for oAuth with the following commands.
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. I use mysql database, so my 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) So, this is a proof-of-concept step on how to connect Shindig to a real database. Next will be how to change shindig classes to connect to my own database!
1) I downloaded the shindig trunk from here:
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 I compile the project:
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 this file looks for me.
I also had to change the SocialApiGuiceModule.java to add a sample OAuthDataStore. I also had to change the JPASocialModule.java to add a sample implementation for MediaItemService, MessageService, AlbumService. 4) We will have to recompile shindig with database support now. We have to change 3 files. trunk/pom.xml - add samples module to default "all" and "run" and to dependencyManagement.
trunk/java/server/pom.xml - add dependency on shindig-samples
trunk/java/samples/pom.xml - add dependency on mysql driver (since I use mysql database)
Now to compile the project with maven command as in 2)
5) Generate signing keys for oAuth with the following commands.
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. I use mysql database, so my 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) So, this is a proof-of-concept step on how to connect Shindig to a real database. Next will be how to change shindig classes to connect to my own database!
Subscribe to:
Posts (Atom)