Prerequisites

  • caGrid data service generated by Introduce
  • JavaEE IDE (Eclipse was used in the following tutorial) NOTE: Any other Java IDE would be compatible too. but since, Introduce auto-generates an Eclipse project while creating the caGrid Data Service, its convenient to build query clients in Eclipse for the data service

Import Project

To import the project into the Eclipse workspace

  1. File -> Import -> Existing Projects into Workspace

source:exp/sds/exp1/images/sds13/ImportPrj1.png

  1. Browse to the location where you saved the Introduce created data service in step 6 of generating the domain model

source:exp/sds/exp1/images/sds13/ImportPrj2.png

  1. Click Finish

Create Query Classes

We will form a query using the Hibernate Query Language (HQL). We've already created the required classes, HibernateUtil.java and PeopleClient.java when we created a query client for the People object model. We will just copy these same two classes for querying the grid data service.

NOTE: The only difference between the two query clients is that one is local while the other is remote i.e., the query client for the object model is local (need not start tomcat) and the query client for the Introduce created grid data service is remote (need to start tomcat)

  1. Expand project Person in Eclipse and navigate to src -> edu.uab.uabgrid.cacoresdk.domain package
  2. Select the package -> Right Click -> New -> class

source:exp/sds/exp1/images/sds13/CreateClass1.png

  1. Type the class Name as HibernateUtil.java -> Finish
  2. Copy this java code and paste to the above created HibernateUtil.java
  3. Make sure that the first line in the above class is the package name package edu.uabgrid.uab.cacoresdk.domain to preserve the namespace

source:exp/sds/exp1/images/sds13/CreateClass2.png

  1. Save project Ctrl-S

Now, create the class which forms a query and lists the contents of the single table data service People

  1. Repeat steps 1 and 2 above to create a new class
  2. Type the class Name as PeopleClient.java -> Finish
  3. Copy this java code and paste to the above created PeopleClient.java
  4. Make sure that the first line in the above class is the package name package edu.uabgrid.uab.cacoresdk.domain to preserve the namespace
  5. Save project Ctrl-S

source:exp/sds/exp1/images/sds13/CreateClass3.png

Add External Jar

Since, we are building our query with HQL and since, Introduce does not provision the Eclipse project for the caGrid data service with Hibernate mappings file for the grid data service, we need to explicitly add the required jar. This jar file is the same <obj-name>-orm.jar file created during the object model generation using caCORESDK. If we assume that your caCORE SDK has been installed at /home/user/src/caCORE, then for the People object model created in part 1 of this tutorial the related hibernate mappings jar will be located at

/home/user/src/caCORE/output/person/package/local-client/lib/person-orm.jar

To add the above jar file to the Person grid data service in Eclipse,

  1. Select project Person -> Right Click -> Properties
  2. In the Properties window -> select Java Build Path -> Click on the tab Libraries

source:exp/sds/exp1/images/sds13/AddExtJar1.png

  1. Click on the tab Add External Jars
  2. Navigate to the above specified location to add the person-orm.jar

source:exp/sds/exp1/images/sds13/AddExtJar2.png

  1. Click OK -> OK
  2. You will now see the person-orm.jar listed under the Referenced Libraries folder

Start Tomcat

Start tomcat via the Eclipse plugin or from command line

$CATALINA_HOME/bin/startup.sh

Execute the Query

  1. In Eclipse, navigate to Person -> src -> edu.uabgrid.uab.cacoresdk.domain
  2. Select PeopleClient.java -> Right Click -> Run As -> Java Application

source:exp/sds/exp1/images/sds13/RunApp.png

  1. The console will list the objects in the table PERSON of the Person caGrid data service

source:exp/sds/exp1/images/sds13/QueryResult.png

Check the Data Service Registration

Troubleshoot caGrid Index Service Registration. Perform diagnostic checks for the data service published to caGrid-1.3 training index service

References

caGrid Tutorials