Hibernate Language Binding Guide For The Connection Cloud Using Java Persistence API (JAP)

Similar documents
PHP Language Binding Guide For The Connection Cloud Web Services

OTN Developer Day Enterprise Java. Hands on Lab Manual JPA 2.0 and Object Relational Mapping Basics

Developing an EJB3 Application. on WebSphere 6.1. using RAD 7.5

Develop an Asset Management System (AMS) for Ho Chi Minh University of Industry

SETTING UP YOUR JAVA DEVELOPER ENVIRONMENT

OpenReports: Users Guide

Copyright Pivotal Software Inc, of 10

Overview of Web Services API

SDK Code Examples Version 2.4.2

How To Extend Content Broker Storage On Libs Libs (Libs) With Libs 4.5) And Libs 5.5

CS346: Database Programming.

Upgrade Guide BES12. Version 12.1

Crystal Reports for Eclipse

Install BA Server with Your Own BA Repository

Safewhere*Identify 3.4. Release Notes

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

Force.com Migration Tool Guide

ESET Secure Authentication Java SDK

The end. Carl Nettelblad

Java EE 7: Back-End Server Application Development

EMC Documentum Composer

Using ilove SharePoint Web Services Workflow Action

Third-Party Software Support. Converting from SAS Table Server to a SQL Server Database

Selenium Automation set up with TestNG and Eclipse- A Beginners Guide

Java SE 7 Programming

Java SE 7 Programming

Teiid - Salesforce Connector Guide 6.2.0

Background on Elastic Compute Cloud (EC2) AMI s to choose from including servers hosted on different Linux distros

1. Introduction What is Slice? Background Why Slice? Purpose of this Document Intended Audience...

Interworks. Interworks Cloud Platform Installation Guide

Integration Overview. Web Services and Single Sign On

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

Using Netbeans and the Derby Database for Projects Contents

Configuring Single Sign-On from the VMware Identity Manager Service to Office 365

Onset Computer Corporation

Single Sign-On Implementation Guide

Java Web Services SDK

PingFederate. Salesforce Connector. Quick Connection Guide. Version 4.1

SnapLogic Salesforce Snap Reference

Using EMC Documentum with Adobe LiveCycle ES

Copyright 2013 Consona Corporation. All rights reserved

Tutorial for Spring DAO with JDBC

Actian Vortex Express 3.0

USER GUIDE for Salesforce

IBM Campaign and IBM Silverpop Engage Version 1 Release 2 August 31, Integration Guide IBM

D4.1.2 Cloud-based Data Storage (Prototype II)

SpagoBI exo Tomcat Installation Manual

Salesforce.com Integration Guide

Java SE 7 Programming

Installation and Administration Guide

Using Microsoft Windows Authentication for Microsoft SQL Server Connections in Data Archive

Using SQL Developer. Copyright 2008, Oracle. All rights reserved.

Eclipse Web Tools Platform. Naci Dai (Eteration), WTP JST Lead

EclipseLink. Solutions Guide for EclipseLink Release 2.5

PERFORMANCE EVALUATION OF JAVA OBJECT-RELATIONAL MAPPING TOOLS HASEEB YOUSAF. (Under the Direction of John A. Miller)

New Features for Sybase Mobile SDK and Runtime. Sybase Unwired Platform 2.1 ESD #2

Copyright 2014 Jaspersoft Corporation. All rights reserved. Printed in the U.S.A. Jaspersoft, the Jaspersoft

LAB 6: Code Generation with Visual Paradigm for UML and JDBC Integration

PASS4TEST 専 門 IT 認 証 試 験 問 題 集 提 供 者

for Salesforce CRM INSTALLATION GUIDE February

Salesforce Files Connect Implementation Guide

Installation Guide of the Change Management API Reference Implementation

IBM Maximo Asset Management. V7.5x Designer 371 Report Development Guide

Introduction to HP ArcSight ESM Web Services APIs

Single Sign-On Implementation Guide

Chapter 13. Introduction to SQL Programming Techniques. Database Programming: Techniques and Issues. SQL Programming. Database applications

Single Sign-On Implementation Guide

Oracle Forms Services Secure Web.Show_Document() calls to Oracle Reports Server 6i

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

HR Onboarding Solution

Custom Encryption in Siebel & Siebel Web Service Security Test Guide 1.0

Informatica Cloud Connector for SharePoint 2010/2013 User Guide

Integration Guide. SafeNet Authentication Service. Using SAS as an Identity Provider for Salesforce

Easy-Cassandra User Guide

EMC Documentum Content Services for SAP iviews for Related Content

Phone Manager Application Support JANUARY 2015 DOCUMENT RELEASE 4.2 APPLICATION SUPPORT

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

Amazon Glacier. Developer Guide API Version

IBM Campaign Version-independent Integration with IBM Engage Version 1 Release 3 April 8, Integration Guide IBM

Java SE 8 Programming

To Java SE 8, and Beyond (Plan B)

Introduction Web Portal Main Page Group Management Create group Modify Group Member List... 5

Creating a Public Knowledge Base with Salesforce Knowledge

Data Integration using Integration Gateway. SAP Mobile Platform 3.0 SP02

HarePoint Workflow Extensions for Office 365. Quick Start Guide

Single Sign-On Implementation Guide

Cloud Elements ecommerce Hub Provisioning Guide API Version 2.0 BETA

TIBCO Runtime Agent Authentication API User s Guide. Software Release November 2012

PLE Server Application Development Kit

IBM InfoSphere MDM Server v9.0. Version: Demo. Page <<1/11>>

Driver for Oracle E-Business Suite (User Management, HR, and TCA) Implementation Guide

Welcome to the Force.com Developer Day

Getting Started with the Ed-Fi ODS and Ed-Fi ODS API

Software Architecture Document

Oracle EBS Interface Connector User Guide V1.4

Amazon Fulfillment Web Service. Getting Started Guide Version 1.1

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Exam Name: IBM InfoSphere MDM Server v9.0

FreeSB Installation Guide 1. Introduction Purpose

Transcription:

Hibernate Language Binding Guide For The Connection Cloud Using Java Persistence API (JAP)

Table Of Contents Overview... 3 Intended Audience... 3 Prerequisites... 3 Term Definitions... 3 Introduction... 4 What s Required... 5 Language Binding... 5 Creating a Connection... 6 Building Entity Classes... 6 Executing Queries... 7 Error Handling... 8 Appendix... 9 B: Full Sample Code... 9 Page 2 of 11

Overview As the number of cloud applications increases, so does the amount of data stored in the cloud. More and more application developers are looking for ways to integrate the vast amounts of cloud data into their applications but, of course, this has been a challenge until now. The Connection Cloud is a platform that allows seamless integration of data from any data source by providing language bindings for application developers. Please note this document focuses on the use of Hibernate, an implementation of Java Persistence API (JAP), in conjunction with the Connection Cloud JDBC driver. Intended Audience This document is for Java developers who need to integrate cloud data, or data mash- ups into their applications. The Connection Cloud makes this possible without requiring custom query syntax, custom authentication code, or specialized drivers. This applies to cloud application developers and website designers using Java- enabled development environments in conjunction with Hibernate. Basic understanding of Hibernate and database query operations is required. You will need access to the items listed in the Prerequisites section before following the instructions in this document. Prerequisites Before attempting to use the Connection Cloud capabilities in an application, please be sure the following software and credentials are available: IDE/Compiler An Integrated Development Environment such as Eclipse or NetBeans to support Java development, or a simple command- line compiler. Connection Cloud Hibernate Resource Package Free WSQL dialect JAR as well as the JDBC driver for the Connection Cloud. You can download the Hibernate Package here: www.connectioncloud.com Java Runtime Environment The Connection Cloud JDBC driver requires any of the following at a minimum: Java 5 JRE, Java 6 JRE, JDK 1.5, or JDK 1.6. Connection Cloud Login Credentials The credentials to access your Connection Cloud account. Register for a free account at www.connectioncloud.com. Target Data Source Credentials The credentials to access the cloud data your application needs to integrate. For example, you may need your Salesforce.com username, password, and security token. Term Definitions This document uses the following terms: Cloud Data Source Data stored in a cloud application s underlying database such as Salesforce or Facebook data. Page 3 of 11

JDBC Java Database Connectivity is a Java- based data access technology that allows developers to query relational databases using the provided access methods. Please refer to the following URL for more information: http://en.wikipedia.org/wiki/jdbc Database Query An operation to manipulate data in a database management system. This may include fetching, updating, and/or deleting data. Query Language Syntax used to create database queries. Different databases and cloud applications may have vastly diverse query language syntax. SQL Structured Query Language is the most widely used query language to manipulate and fetch data in database management systems. Also referred to as ANSI SQL due to being a standard recognized by the American National Standards Institute. WSQL Web Services Query Language is the native query language of the Connection Cloud. It is a superset of ANSI SQL and includes the ability to call web service operations. For more information on syntax and features please visit the WSQL help page: https://connectioncloud.atlassian.net/wiki/display/wsql/home Introduction The complexity of data and data integration for application developers increases with the exponential growth of cloud applications. Each cloud data source can expose and require an authentication method, an API style such as SOAP or REST, a native query language with varying levels of functionality (SOQL, FQL, YQL, etc.), and may even release API updates with no backward compatibility. This has led to many silos of data since getting access to the underlying data varies from application to application. Furthermore, not having an ANSI SQL interface to these cloud databases increases the challenges involved with integrating multiple data sources into a single application. Most developers have had to first solve the data integration challenge before focusing on core application development tasks. This has stifled the rapid application development path most software professionals are accustomed to. The Connection Cloud hooks up any development language, application, or JDBC/ODBC compatible tool to cloud data sources just as easily as if the data were in a local, standard SQL database. In essence, the Connection Cloud allows programmatic access to any data source on the Web. Java developers looking to easily integrate cloud data into their applications using the Hibernate dialect implementation of Java Persistence API (JAP) should use this document. Page 4 of 11

What s Required To retrieve data via the Connection Cloud inside a Hibernate application you need a Connection Cloud account. Register for free at www.connectioncloud.com and use the username and password selected here when connecting to the Connection Cloud Web services. The Connection Cloud platform does not grant anonymous access. After you log into the Connection Cloud workbench, navigate to the Channels page and activate the desired cloud data sources. You can choose from sources like Salesforce.com, Facebook, or NetSuite. To set up credentials for each data source please refer to the Connection Cloud help pages/faq. Note: some cloud data sources require a certain subscription level to provide full API access. For instance, Salesforce.com only provides API access to the underlying data when subscribed to the Enterprise or Unlimited editions of the platform. Please be mindful of such restrictions when looking for access to cloud data. Language Binding To use the Connection Cloud inside your Hibernate application, include the following two libraries in your project: Connection Cloud JDBC Driver (CC_JDBC_x.jar, where x denotes the version number) WSQL Dialect Library (WSQLDialect.jar) You need to include these libraries in addition to the required libraries for Hibernate and Hibernate JPA. Please refer to the following link for information and help on creating Hibernate projects: http://docs.oracle.com/javaee/5/tutorial/doc/bnbpy.html Once you have included the required libraries, create a connection to the Connection Cloud per the instructions in the next section. You may then use standard Hibernate constructs such as Entity classes to define the tables the application needs access to. Please note, queries stored in the Connection Cloud Repository look like database tables to Hibernate. Page 5 of 11

Creating a Connection In order to execute queries through the Connection Cloud an application needs to first create a connection using Connection Cloud credentials. Most Connection Cloud account credentials will not include a tenant name ; therefore the only required credentials are the username and password. To configure the Hibernate connection to the Connection Cloud, configure the persistence.xml file by defining the following: Connection URL: jdbc:demandreports://workbench.demandreports.com Connection Username: Connection Cloud account username Connection Password: Connection Cloud account password Connection Driver: com.demandreports.jdbc.driver Connection Dialect: com.demandreports.hibernate.dialect.wsqldialect The following is a sample persistence.xml file: <?xml version="1.0" encoding="utf-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="hibernateexample" transaction-type="resource_local"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <properties> <property name="hibernate.connection.username" value="myusername"/> <property name="hibernate.connection.password" value="mypassword"/> <property name="hibernate.connection.url" value="jdbc:demandreports://workbench.demandreports.com"/> <property name="hibernate.connection.driver_class" value="com.demandreports.jdbc.driver"/> <property name="hibernate.dialect" value="com.demandreports.hibernate.dialect.wsqldialect"/> </properties> </persistence-unit> </persistence> Building Entity Classes To execute queries on the Connection Cloud via Hibernate you need to create an Entity class per query or table. You may specify the name of the table as a reference to the stored query inside the Connection Cloud Repository using the following format: FolderName.QueryName Page 6 of 11

The following sample class describes a Customer Entity class that executes a query stored inside the Connection Cloud Repository as /MyQueries/CustomersQuery. @Entity @Table( name = "MyQueries.CustomersQuery" ) public class Customer { private Long id; private String emailaddress; private List<Order> orders; public Customer() { // Default constructor @Id @Column(name = "customerid") public Long getid() { return id; private void setid(long id) { this.id = id; ` @Column(name = "emailaddress") public String getemailaddress() { return emailaddress; public void setemailaddress(string emailaddress) { this.emailaddress = emailaddress; @OneToMany @JoinColumn(name="customerid", referencedcolumnname="customerid") public List<Order> getorders() { return orders; public void setorders(list<order> orders) { this.orders = orders; This class outlines the various columns the application will require from the Customers table. Executing Queries In order to execute queries use standard Hibernate method calls such as createentitymanagerfactory, gettransaction().begin(), and createquery. Page 7 of 11

The following code snippet demonstrates the necessary steps required in order to execute queries via the Connection Cloud. import java.util.list; import java.util.date; import javax.persistence.entitymanager; import javax.persistence.entitymanagerfactory; import javax.persistence.persistence; public class HibernateExample { /** * @param args the command line arguments */ public static void main(string[] args) { EntityManagerFactory entitymanagerfactory = Persistence.createEntityManagerFactory( "HibernateExample" ); EntityManager entitymanager = entitymanagerfactory.createentitymanager(); entitymanager.gettransaction().begin(); List<Customer> customers = entitymanager.createquery( "from Customer where locate(substring(trim(emailaddress), 1),'@XYZCompany.com')!= 0").getResultList(); System.out.println( "customer count: " + customers.size() ); for ( Customer customer : customers ) { System.out.println( "Customer (" + customer.getid() + ") : " + customer.getemailaddress() ); List<Order> orders = customer.getorders(); for ( Order order : orders ) { System.out.println( "Order (" + order.getid() + ") : " + order.getorderdate() ); entitymanager.gettransaction().commit(); entitymanager.close(); Error Handling You should always use appropriate Exception handling when calling the Connection Cloud via Hibernate. Implement all calls to the Connection Cloud within a try-catch block. Page 8 of 11

Appendix B: Full Sample Code CustomersEntity.java import java.util.date; import java.util.list; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.onetomany; import javax.persistence.table; import javax.persistence.temporal; import javax.persistence.temporaltype; import org.hibernate.annotations.genericgenerator; @Entity @Table( name = "MyQueries.CustomersQuery" ) public class Customer { private Long id; private String emailaddress; private List<Order> orders; public Customer() { // Default constructor @Id @Column(name = "customerid") public Long getid() { return id; private void setid(long id) { this.id = id; @Column(name = "emailaddress") public String getemailaddress() { return emailaddress; public void setemailaddress(string emailaddress) { this.emailaddress = emailaddress; @OneToMany @JoinColumn(name="customerid", referencedcolumnname="customerid") public List<Order> getorders() { return orders; public void setorders(list<order> orders) { this.orders = orders; Page 9 of 11

OrdersEntity.java import java.util.date; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.table; import javax.persistence.temporal; import javax.persistence.temporaltype; import org.hibernate.annotations.genericgenerator; @Entity @Table( name = "MyQueries.OrdersQuery" ) public class Order { private Long id; private Date orderdate; private Customer customer; public Order() { // this form used by Hibernate @Id @Column(name = "orderid") public Long getid() { return id; private void setid(long id) { this.id = id; @Temporal(TemporalType.TIMESTAMP) @Column(name = "orderdate") public Date getorderdate() { return orderdate; public void setorderdate(date orderdate) { this.orderdate = orderdate; Page 10 of 11

Main.java import java.util.list; import java.util.date; import javax.persistence.entitymanager; import javax.persistence.entitymanagerfactory; import javax.persistence.persistence; public class HibernateExample { /** * @param args the command line arguments */ public static void main(string[] args) { EntityManagerFactory entitymanagerfactory = Persistence.createEntityManagerFactory( "HibernateExample" ); EntityManager entitymanager = entitymanagerfactory.createentitymanager(); entitymanager.gettransaction().begin(); List<Customer> customers = entitymanager.createquery( "from Customer where locate(substring(trim(emailaddress), 1),'@XYZCompany.com')!= 0").getResultList(); System.out.println( "customer count: " + customers.size() ); for ( Customer customer : customers ) { System.out.println( "Customer (" + customer.getid() + ") : " + customer.getemailaddress() ); List<Order> orders = customer.getorders(); for ( Order order : orders ) { System.out.println( "Order (" + order.getid() + ") : " + order.getorderdate() ); entitymanager.gettransaction().commit(); entitymanager.close(); Page 11 of 11