Table of Contents
Prerequisites
The following are needed for creating the query application
- caCORESDK generated data service as described in part1
- JavaEE IDE (Eclipse was used in the following tutorial)
caCORESDK Runtime System
The SDK Runtime system follows an n-tier architecture and is made up of the following tiers (starting from lowest tier):
- Persistence
- Application Service
- Security Interception and
- Client Interface
Chapter 4 of caCORESDK programmer's guide gives a detailed explanation on the Runtime System. In this tutorial, we will be mainly dealing with Application Service and Client Interface tiers.
Application Service Tier
The Application Service tier is responsible for combining all the requests coming from the various client interfaces and forward them to the appropriate persistence tier (which is by default hibernate-based ORM).
- The Application Service tier is realized with the java interface ApplicationService (gov.nih.nci.system.applicationservice package).
- The ApplicationService interface has methods to perform various types of queries and searches on objects (see below).
- The class ApplicationServiceProvider returns a handle to the ApplicationService interface.
Client Interface Tier
caCORE SDK generates four types of client interfaces to reach the Application Service tier.
- XML-HTTP
- Web Services
- Local Java API
- Remote Java API
The local java API test client generated by caCORE SDK will serve as an example to create our custom query client. Notes on Local/Remote Java API Client:
- caCORESDK generated local/remote java API test client makes use of Aspect Oriented Programming (AOP) to create custom transaction interceptors to open a hibernate session and forward transactions to the database.
- The ApplicationService tier of the caCORESDK Runtime System is responsible for generating these custom transaction interceptors and makes use of the AOP Springframework API to do so.
- Chapter 4 from caCORESDK programmer's guide gives a detailed explanation on the Runtime System
- Of particular significance in Chapter 4 of caCORESDK programmer's guide, is the section titled Client Interface Tier. Sub-section of Client Interface Tier, Technical Challenges, explains the workings of ApplicationService tier with sequence diagrams.
- This is also a good link in understanding AOP with Hibernate.
The ApplicationService interface has methods to perform five types of queries and searches on objects, namely,
- Simple
- Nested Criteria
- Detached Criteria
- Hibernate (HQL) and
- caBig Query (CQL)
Chapter 5 of caCORESDK programmer's guide discusses in detail about all these queries in the section titled Java API Interface. We will develop our custom query client using HQL to list the objects in our single table PERSON.
Create a New Project
- In Eclipse, File -> New -> Java Project
- Enter project name as TestSDKRuntime -> Next -> Finish
- Select the project TestSDKRuntime -> Right-Click -> Import -> File system and browse to the directory caCORE/output/people/package/local-client,
- Click on the checkbox beside local-client -> Next -> Finish
The New project with src, build, conf, and lib dirs will be visible in the Package Explorer on the left
Create a New Class
We will first create a class which performs a Hibernate query (with HQLCriteria class of the ApplicationService API)
- Expand project TestSDKRuntime and navigate to src -> (default package)
- Select default package -> Right Click -> New -> Class -> Enter name as TestHQLClient -> Finish
- Copy this java code and paste to the above created TestHQLClient.java
- Save project Ctrl-S
Modify Build Configuration
Since we are making use of the caCORE SDK Runtime system API, we need to add the ApplicationService API configuration files to the Eclipse project classpath.
Add Folder to Eclipse Project Classpath
- Select the project TestSDKRuntime -> Right-Click -> Build Path -> Configure Build Path
- Click on the tab Add Folder -> Select Conf -> OK -> OK
- Select the project TestSDKRuntime -> Right-Click -> Refresh
Add External Jars to Eclipse Project Classpath
- Select the project TestSDKRuntime -> Right-Click -> Build Path -> Configure Build Path
- Click on the tab "Libraries"
- Click on the tab "Add External JARs" and navigate to your local-client/lib folder ie., caCORE/output/person/package/local-client/lib
- Select all the jars from your local-client lib folder
- Click Ok -> Ok. This will add to the Libraries and will show up as Referenced Libraries folder within your project folder in the Package Explorer on the left.
- Select the project TestSDKRuntime -> Right-Click -> Refresh
Run the Application
- In Eclipse, navigate to the query client class TestHQLClient.java. It will be located at src/default package.
- Select TestHQLClient.java -> Right Click -> Run as -> Java Application
- The console should print the result of the run, i.e., print the third row of the table Person, consisting of id, first name, and last name from the People data service
Other Queries
Now that we've seen how to create a HQL query with caCORE SDK ApplicationService API, in the same way we can create other forms of queries with Nested Search Criteria, Detached Criteria and CQL.
- Follow steps outlined to create a new class
- Instead of TestHQLClient, create individual classes, namely
- Follow steps outlined to to run the application for each query client created
If one wishes to, for whatever reason, not make use of the caCAORE SDK Runtime system, i.e., ApplicationService API, here is another way to build a custom query client. This query client makes use of the caCORE SDK generated Java Beans and Hibernate mappings for the "Person" object model instead of the ApplicationService API.
References
- JavaBeans Concepts
- Hibernate - Getting Started
- Hibernate Tutorial - The first application
- Hibernate API
- HQL - The Hibernate Query Language
- AOP Springframework API - Aspect Oriented Programming API from SpringSource








