opensap hanacloud1-1 week 02 persistency basics

Post on 07-Feb-2016

38 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

SAPWeek2

TRANSCRIPT

Week 2 Unit 1: Introduction and

First Steps with EJB

May, 2014

© 2014 SAP AG or an SAP affiliate company. All rights reserved 2 Public

Introduction and First Steps with EJB Persistence as a Service

Manages the database systems in the

cloud and the access to them

Operations on database system level

Monitoring and alerting

Load balancing and scaling

Backup and recovery

Configuration

Metering

Application data isolation

© 2014 SAP AG or an SAP affiliate company. All rights reserved 3 Public

Introduction and First Steps with EJB Easy Consumption

Standards-based access

JDBC

JPA 2.0

Choice of database platform

SAP HANA

SAP MaxDB

Apache Derby (for local development)

Schema management

One schema per application (default)

Many applications sharing one schema

One application using many schemas

Schema management available in cockpit

© 2014 SAP AG or an SAP affiliate company. All rights reserved 4 Public

Introduction and First Steps with EJB Java Persistence API (JPA)

Describes management of relational

data in applications

Replaces persistence solution for

EJB 2.0 CMP

Default support in SAP HANA Cloud

Platform runtimes for JPA 2.0

© 2014 SAP AG or an SAP affiliate company. All rights reserved 5 Public

Introduction and First Steps with EJB EJB Sample

Makes use of Java EE 6 Web Profile

(SAP HANA Cloud Platform SDK 2.x)

Web container

EJB container

Persistence provider - EclipseLink

DB

PersistenceWithEJBServlet

PersonBean

Person EclipseLink as

persistence provider

EJB Container

Web Container

Java EE 6 Web Profile (2.x)

Schemas

JDBC

© 2014 SAP AG or an SAP affiliate company. All rights reserved 6 Public

Introduction and First Steps with EJB EJB Sample

Import to Eclipse as

‘Existing Projects into Workspace’

Location:

<SDK_path>\samples\persistence-with-ejb

© 2014 SAP AG or an SAP affiliate company. All rights reserved 7 Public

Introduction and First Steps with EJB EJB Sample

Building Blocks:

Person.java

persistence entity

PersonBean.java

stateless bean

persistence.xml

JPA configuration file

PersistenceWithEJBServlet.java

provides interaction with end users

web.xml

Web application descriptor

© 2014 SAP AG or an SAP affiliate company. All rights reserved 8 Public

Introduction and First Steps with EJB EJB Sample

Run the sample

– ‘Run on Server’

Configure SAP HANA Cloud Server

– hanatrial.ondemand.com

Request URL

– https://<application_name><account_name>.ha

natrial.ondemand.com/persistence-with-ejb/

© 2014 SAP AG or an SAP affiliate company. All rights reserved 9 Public

Introduction and First Steps with EJB EJB Sample

SAP HANA Cloud Platform cockpit

provides the following information in

the ‘Database Schemas’ view:

Schema name/ID

Database type

Application bindings

© 2014 SAP AG or an SAP affiliate company. All rights reserved 10 Public

Introduction and First Steps with EJB What You’ve Learned in This Unit

The role of Persistence Service

on SAP HANA Cloud Platform

The supported database platform

types

How applications can store data

in a database in the cloud

JPA, and how it is supported on

SAP HANA Cloud Platform

What a persistence-enabled EJB

application looks like

Where to find information about

your schema

Contact information:

open@sap.com

Thank you

© 2014 SAP AG or an SAP affiliate company. All rights reserved 12 Public

© 2014 SAP AG or an SAP affiliate company.

All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG or an

SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG

(or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional

trademark information and notices.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP AG or an SAP affiliate company for informational purposes only, without representation or warranty of any kind,

and SAP AG or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP AG or

SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and

services, if any. Nothing herein should be construed as constituting an additional warranty.

In particular, SAP AG or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related

presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP AG’s or its affiliated

companies’ strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be

changed by SAP AG or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment,

promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties

that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking

statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

Week 2 Unit 2:

Connecting to Your Database

May, 2014

© 2014 SAP AG or an SAP affiliate company. All rights reserved 2 Public

Connecting to Your Database How to Connect to My Database in the Cloud

Scenario:

App developer wants to connect to

database in the cloud via JDBC tool

Database in the cloud is not publicly

accessible

How to do it:

Use Eclipse IDE plug-ins:

SAP HANA Cloud Platform Tools for

connecting to SAP HANA systems

SAP HANA Tools

Eclipse IDE

+ SAP HANA Tools

DB

SAP HANA Cloud Platform

DB Tunnel over SSL

Schema

© 2014 SAP AG or an SAP affiliate company. All rights reserved 3 Public

Connecting to Your Database Procedure

Open Perspective:

SAP HANA Administration

Console

Add Cloud System

Select Trial Instances option

Choose the instance you want

to work with

© 2014 SAP AG or an SAP affiliate company. All rights reserved 4 Public

Connecting to Your Database Finding Your Application Data

DEV_<GUID> - the schema for the

automatically generated developer

user

NEO_<GUID> - the schema used by

the application

T_PERSONS – the table created by

the application

© 2014 SAP AG or an SAP affiliate company. All rights reserved 5 Public

Connecting to Your Database What You’ve Learned in This Unit

How to connect to your database in

the cloud

What the additional tools are that

should be installed in Eclipse IDE to

support this scenario

Operations on application data that

can be performed from the SAP HANA

Tools plug-in

Contact information:

open@sap.com

Thank you

© 2014 SAP AG or an SAP affiliate company. All rights reserved 7 Public

© 2014 SAP AG or an SAP affiliate company.

All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG or an

SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG

(or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional

trademark information and notices.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP AG or an SAP affiliate company for informational purposes only, without representation or warranty of any kind,

and SAP AG or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP AG or

SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and

services, if any. Nothing herein should be construed as constituting an additional warranty.

In particular, SAP AG or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related

presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP AG’s or its affiliated

companies’ strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be

changed by SAP AG or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment,

promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties

that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking

statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

Week 2 Unit 3:Creating a JDBC ApplicationOctober, 2013

© 2013 SAP AG. All rights reserved. 2Public

Creating a JDBC ApplicationJDBC Overview

Java Database Connectivity (JDBC)Java-based data access technologyDefines how a client can connect,query, and update data in a database

JDBC APIJDBC connections support creation andexecution of statementsResultSet presents the outcome after astatement has been executed

© 2013 SAP AG. All rights reserved. 3Public

Creating a JDBC ApplicationWhy Use JDBC?

Advantages of JDBCClean and easy for small applicationsGood performance with large amountsof dataAllows optimization of SQL requestsReuse of existing JDBC libraries(Liquibase, Hibernate)

Disadvantages of JDBCLarge programming overhead for largeprojectsConcurrency support and transactionand connection management requiredInitial creation of database structuresrequired

© 2013 SAP AG. All rights reserved. 4Public

Creating a JDBC ApplicationJDBC Sample

Uses standard database access(JDBC)

Needs only a Web container, so canrun in both runtimes

Java Web (1.x)Java EE 6 Web Profile (2.x)

PersistenceWithEJBServlet

PersonDAO

Person

Web Container

Java EE 6 Web Profile (2.x) orJava Web (1.x)

SchemasDB

JDBC

© 2013 SAP AG. All rights reserved. 5Public

Creating a JDBC ApplicationJDBC Sample

Import to Eclipse as‘Existing Projects into Workspace’Location:<SDK_path>\samples\persistence-with-jdbc

© 2013 SAP AG. All rights reserved. 6Public

Creating a JDBC ApplicationJDBC Sample

Building Blocks:Person.javaholds the information for a person

PersonDAO.javaperforms all operations with DB

PersistenceWithJDBCServlet.javaprovides interaction with the end users andlooks up the DataSource from JNDI

web.xmlweb application descriptor; definesdatasource resource

© 2013 SAP AG. All rights reserved. 7Public

Creating a JDBC ApplicationJDBC Sample

Run the sample– ‘Run on Server’

Configure SAP HANA Cloud Server– hanatrial.ondemand.com

Request URL– https://<application_name><account_name>.

hanatrial.ondemand.com/persistence-with-jdbc/

© 2013 SAP AG. All rights reserved. 8Public

Creating a JDBC ApplicationJDBC Sample

In the background:A new schema is createdSchema is bound to the applicationWhen app requests data source the appgets connected to this schema– Maximum 8 parallel database connections per

schema

When application is undeployed, theschema is not removedWhen application is redeployed, it usessame schema and bindings

© 2013 SAP AG. All rights reserved. 9Public

Creating a JDBC ApplicationHow Can I See the SQL Statements Sent to the Database?

SQL TraceProvides a log of selected SQLstatementsRelevant for both JPA and JDBCapplicationsIntegrated in the standard trace logfilesDisabled by default

ScenariosInvestigate database access-relatedperformance issuesDetermine inefficient SQL statements

© 2013 SAP AG. All rights reserved. 10Public

Creating a JDBC ApplicationHow to Enable the SQL Trace

Set the log level of “com.sap.core.persistence.sql.trace” to DEBUG

Tools:Eclipse IDESAP HANA Cloud Platform Cockpit

© 2013 SAP AG. All rights reserved. 11Public

Creating a JDBC ApplicationHow to Read SQL Trace Records

The SQL trace is written in the default trace log fileFile name prefix ljs_trace_vsa

Tools:Eclipse IDESAP HANA Cloud Platform Cockpit

© 2013 SAP AG. All rights reserved. 12Public

Creating a JDBC ApplicationWhat You’ve Learned in This Unit

What JDBC isThe advantages and disadvantagesof JDBCWhat a persistence-enabled JDBCapplication looks likeWhat happens in the backgroundwhen an application is deployed andstartedHow to trace the SQL statementsperformed by your applicationHow to enable, disable, and displaythe SQL trace recordings

Contact information:

open@sap.com

Thank you

© 2013 SAP AG. All rights reserved. 14Public

© 2013 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation orwarranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Groupproducts and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothingherein should be construed as constituting an additional warranty.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG inGermany and other countries.Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.

Week 2 Unit 4:Sharing Data Between ApplicationsOctober, 2013

© 2013 SAP AG. All rights reserved. 2Public

Sharing Data Between ApplicationsHow Can I Share Data Between Applications?

Scenario:Multiple applications need to work withthe same data

Auto-generated schemasNew schema is automatically createdfor application on first startApplication is bound to the schemawith default data-source binding

SAP HANA databasesystems

Application2

Application1

Auto-bound

<DEFAULT>

Data source

Auto-bound

<DEFAULT>

Data source

Auto-generatedschema2

Auto-generatedschema1

© 2013 SAP AG. All rights reserved. 3Public

Sharing Data Between ApplicationsSharing Schemas

A schema can be shared betweenapplications by binding it to morethan one application

Steps:Unbind the schema from theapplicationBind the application to the otherschema with <DEFAULT> data-sourcebindingRestart the application

SAP HANA databasesystems

Application2

Application1

Auto-bound

<DEFAULT>

Data source

Auto-bound

<DEFAULT>

Data source

Auto-generatedschema2

Auto-generatedschema1

© 2013 SAP AG. All rights reserved. 4Public

Sharing Data Between ApplicationsTools: SAP HANA Cloud Platform Cockpit

Database Schema ViewsOperations:– list all schemas in account– show bindings per schema– delete existing binding– create new binding– delete schema

Applications -> DashboardOperations:– restart application

© 2013 SAP AG. All rights reserved. 5Public

Sharing Data Between ApplicationsTools: SDK Console Commands

Open a command window in the ‘<SDK>/tools’ folder and set proxy settings ifneeded

list-schemasneo list-schemas -h <host> -u <user> -a <account>

display-schema-infoneo display-schema-info -h <host> -u <user> -a <account> --id <schema id>

unbind-schemaneo unbind-schema -h <host> -u <user> -a <account> -b <application>

bind-schemaneo bind-schema -h <host> -u <user> -a <account> -b <application> --id<schema id>

© 2013 SAP AG. All rights reserved. 6Public

Sharing Data Between ApplicationsDemo

Scenario: Configure the JDBC sampleto use the same data as the EJB sample

No code change is neededUnbind the JDBC sample applicationfrom its schemaBind it to the schema of the EJB sampleRestart the JDBC sample applicationRequest it

SAP HANA databasesystems

JDBC Sample

EJB Sample

Auto-bound

<DEFAULT>

Data source

Auto-bound

<DEFAULT>

Data source

jdbc sampleschema

ejb sample schema

© 2013 SAP AG. All rights reserved. 7Public

Sharing Data Between ApplicationsWhat You’ve Learned in This Unit

What auto-generated schemas areWhat default data-source binding isHow to bind a schema to anapplicationHow to remove the binding betweenan application and a schemaHow to share data betweenapplications

Contact information:

open@sap.com

Thank you

© 2013 SAP AG. All rights reserved. 9Public

© 2013 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation orwarranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Groupproducts and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothingherein should be construed as constituting an additional warranty.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG inGermany and other countries.Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.

Week 2 Unit 5:

Using Multiple Databases

May, 2014

© 2014 SAP AG or an SAP affiliate company. All rights reserved 2 Public

Using Multiple Databases How Can I Use Multiple Schemas in My Application?

Scenario:

You want your application to store data

in multiple schemas

Auto-generated schemas

One schema per application

Database type (default account

setting)

Default data-source binding

Auto-bound

<DEFAULT>

Data source

SAP HANA database systems

Application2

Application1

Auto-bound

<DEFAULT>

Data source

SAP MaxDB database

systems

Auto-generated

schema

Auto-generated

schema

© 2014 SAP AG or an SAP affiliate company. All rights reserved 3 Public

Using Multiple Databases How to Use Multiple Schemas in an Application

Steps:

1. Prepare the application

2. Create schemas

3. Unbind the auto-generated

schema

4. Bind the application to the other

schemas using declared data-

source names

5. For Java EE Web Profile 2.X,

also create bindings to – jdbc/defaultManagedDataSource

– jdbc/defaultUnmanagedDataSource

6. Re-deploy the application

© 2014 SAP AG or an SAP affiliate company. All rights reserved 4 Public

Using Multiple Databases Demo: Scenario

Enhance the JDBC sample to use a

second schema of type MaxDB

Auto-generated

schema

SAP HANA database systems

JDBC Sample

maxdb schema

SAP MaxDB database systems

‘jdbc/MaxDB’

Data source

‘jdbc/DefaultDB’

Data source

© 2014 SAP AG or an SAP affiliate company. All rights reserved 5 Public

Using Multiple Databases Demo: Code Changes

Declare additional resource reference

in web.xml

<resource-ref>

<res-ref-name>jdbc/MaxDB</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

</resource-ref>

© 2014 SAP AG or an SAP affiliate company. All rights reserved 6 Public

Using Multiple Databases Demo: Code Changes

Create a new method in ‘PersistenceWithJDBCServlet‘ that looks up a data

source by name and returns the database product information

private String getDatabaseNameAndVersion(String dataSourceName) throws NamingException, SQLException { InitialContext ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup(dataSourceName); Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); return metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion(); } finally { if (connection != null) connection.close(); } }

© 2014 SAP AG or an SAP affiliate company. All rights reserved 7 Public

Using Multiple Databases Demo: Code Changes

Invoke the new method ‘PersistenceWithJDBCServlet’ in doGet(…) to

display the database product information in the UI for both the ‘jdbc/MaxDB’

and ‘jdbc/DefaultDB’ data sources

response.getWriter().println("<p>The MaxDB data source is connected to " + getDatabaseNameAndVersion("java:comp/env/jdbc/MaxDB") + "</p>"); response.getWriter().println("<p>The DefaultDB data source is connected to " + getDatabaseNameAndVersion("java:comp/env/jdbc/DefaultDB") + "</p>");

© 2014 SAP AG or an SAP affiliate company. All rights reserved 8 Public

Using Multiple Databases Demo: Configuration Changes

Create a new schema of type MaxDB

visible to all apps in the account

Choose a unique schema name

Choose the database type SAP

MaxDB

Tools

SAP HANA Cloud Platform cockpit

Console client command

neo create-schema -h <host> -u <user> -a

<account> --id<schema id> -d <db type>

© 2014 SAP AG or an SAP affiliate company. All rights reserved 9 Public

Using Multiple Databases Demo: Configuration Changes

Unbind the default data-source

binding

Bind the new MaxDB schema with

data-source name ‘jdbc/MaxDB‘

Bind the old SAP HANA schema with

data-source names

– jdbc/DefaultDB

– jdbc/defaultManagedDataSource

– jdbc/defaultUnmanagedDataSource

my_hana

schema

Auto-bound

<DEFAULT>

Data source

Auto-generated

schema

SAP HANA database systems

JDBC Sample

my_maxdb

schema

SAP MaxDB database systems

© 2014 SAP AG or an SAP affiliate company. All rights reserved 10 Public

Using Multiple Databases Demo: Results

Restart the JDBC sample application

Request it

Check the UI for the new entries showing the database product name and

version

© 2014 SAP AG or an SAP affiliate company. All rights reserved 11 Public

Using Multiple Databases What You’ve Learned in This Unit

How an application can use multiple

schemas

How to create a schema

How to bind multiple schemas to an

application

Which additional data-source

bindings must be created if the

application uses Java EE Web

Profile 2.X

Contact information:

open@sap.com

Thank you

© 2014 SAP AG or an SAP affiliate company. All rights reserved 13 Public

© 2014 SAP AG or an SAP affiliate company.

All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG or an

SAP affiliate company.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG

(or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional

trademark information and notices.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

National product specifications may vary.

These materials are provided by SAP AG or an SAP affiliate company for informational purposes only, without representation or warranty of any kind,

and SAP AG or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP AG or

SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and

services, if any. Nothing herein should be construed as constituting an additional warranty.

In particular, SAP AG or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related

presentation, or to develop or release any functionality mentioned therein. This document, or any related presentation, and SAP AG’s or its affiliated

companies’ strategy and possible future developments, products, and/or platform directions and functionality are all subject to change and may be

changed by SAP AG or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment,

promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties

that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking

statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

top related