Extracts from Intro to Db - Jdbc - JPA SpringData

Similar documents
Introduction to SpringBoot. (Spring

Top 50 JDBC Interview Questions and Answers

CO Java EE 6: Develop Database Applications with JPA

What data persistence means? We manipulate data (represented as object state) that need to be stored

Java Persistence API (JPA)

Kyle Brown Knowledge Systems Corporation by Kyle Brown and Knowledge Systems Corporation

foreword to the first edition preface xxi acknowledgments xxiii about this book xxv about the cover illustration

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

CSE 308. Database Issues. Goals. Separate the application code from the database

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Java EE Architecture, Part Three. Java EE architecture, part three 1(57)

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Web Application Development Using Spring, Hibernate and JPA

Complete Java Contents

Acknowledgments About the Authors

Web Application Development Using Spring, Hibernate and JPA

Web Application Development Using Spring, Hibernate and JPA

Persistence Performance Tips

object/relational persistence What is persistence? 5

Developing Applications with Java EE 6 on WebLogic Server 12c

ADVANCED JAVA TRAINING IN BANGALORE

Database Programming Overview. COSC 304 Introduction to Database Systems. Database Programming. JDBC Interfaces. JDBC Overview

Spring Persistence. with Hibernate PAUL TEPPER FISHER BRIAN D. MURPHY

JDBC MOCK TEST JDBC MOCK TEST IV

Efficient Object-Relational Mapping for JAVA and J2EE Applications or the impact of J2EE on RDB. Marc Stampfli Oracle Software (Switzerland) Ltd.

TopLink Grid: Scaling JPA applications with Coherence

Chapter 3 DB-Gateways

com Spring + Spring-MVC + Spring-Boot + Design Pattern + XML + JMS Hibernate + Struts + Web Services = 8000/-

Java EE Architecture, Part Three. Java EE architecture, part three 1(69)

Pieter van den Hombergh. March 25, 2018

Running SQL in Java and PHP

Lightweight J2EE Framework

Databases and MySQL. COMP 342: Programming Methods. 16 September Databases and MySQL

Chapter 13 Introduction to SQL Programming Techniques

Call: JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline

Fast Track to EJB 3.0 and the JPA Using JBoss

Lightweight J2EE Framework

UNIT III - JDBC Two Marks

High-Performance Hibernate VLAD MIHALCEA

Advanced Web Systems 9- Hibernate annotations, Spring integration, Aspect Oriented Programming. A. Venturini

Deployment. See Packaging and deployment processes

Running SQL in Java and PHP

Enterprise JavaBeans, Version 3 (EJB3) Programming

Leverage Rational Application Developer v8 to develop Java EE6 application and test with WebSphere Application Server v8

Using Java - for PL/SQL and Database Developers Student Guide

Discuss setting up JDBC connectivity. Demonstrate a JDBC program Discuss and demonstrate methods associated with JDBC connectivity

Lecture 9&10 JDBC. Mechanism. Some Warnings. Notes. Style. Introductory Databases SSC Introduction to DataBases 1.

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Object Persistence Design Guidelines

DATABASE SYSTEMS. Database programming in a web environment. Database System Course, 2016


Chapter 3 DB-Gateways

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

Spring Professional v5.0 Exam

JAVA MICROSERVICES. Java Language Environment. Java Set Up. Java Fundamentals. Packages. Operations

Struts: Struts 1.x. Introduction. Enterprise Application

Chapter 3 DB-Gateways

Questions and Answers. A. A DataSource is the basic service for managing a set of JDBC drivers.

Architecture overview

Object Persistence and Object-Relational Mapping. James Brucker

Table of Contents. Introduction... xxi

Enterprise JavaBeans 3.1

HIBERNATE MOCK TEST HIBERNATE MOCK TEST IV

find() method, 178 forclass() method, 162 getcurrentsession(), 16 getexecutablecriteria() method, 162 get() method, 17, 177 getreference() method, 178

The Good, the Bad and the Ugly

Wentworth Institute of Technology COMP570 Database Applications Fall 2014 Derbinsky. SQL Programming. Lecture 8. SQL Programming

JDBC - INTERVIEW QUESTIONS

Database Access with JDBC. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Chapter 9 SQL in a server environment

EMBEDDED SQL. SE 3DB3 Fall 2016 MICHAEL LIUT DEPARTMENT OF COMPUTING AND SOFTWARE MCMASTER UNIVERSITY

DATABASE SYSTEMS. Database programming in a web environment. Database System Course,

Java EE Architecture, Part Three. Java EE architecture, part three 1(24)

Skyway Builder 6.3 Reference

Java 8 Programming for OO Experienced Developers

JDBC BASIC 19/05/2012. Objectives. Java Database Connectivity. Definitions of JDBC. Part 1. JDBC basic Working with JDBC Adv anced JDBC programming

The dialog boxes Import Database Schema, Import Hibernate Mappings and Import Entity EJBs are used to create annotated Java classes and persistence.

Why use a database? You can query the data (run searches) You can integrate with other business systems that use the same database You can store huge

GAVIN KING RED HAT CEYLON SWARM

Java Persistence API. Patrick Linskey EJB Team Lead BEA Systems Oracle

Cyrus Shahabi Computer Science Department University of Southern California C. Shahabi

Application Programming for Relational Databases

DB2 for z/os and Websphere Integration Update

Real SQL Programming 1

Review. Fundamentals of Website Development. Web Extensions Server side & Where is your JOB? The Department of Computer Science 11/30/2015

Unit 3 - Java Data Base Connectivity

Pro JPA 2. Mastering the Java Persistence API. Apress* Mike Keith and Merrick Schnicariol

JAVA SYLLABUS FOR 6 MONTHS

Contents. Chapter 1: Introducing Spring Persistence...1 Persistence...2 Spring as a de Facto Standard...4

Configuring JDBC data-sources

Java Database Connectivity (JDBC) 25.1 What is JDBC?

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Schema Name In The Sql Statement Hsql Invalid

Embedded SQL. Introduction

Embedded SQL. Davood Rafiei

SQL, the underestimated Big Data technology

Oracle Exam 1z0-898 Java EE 6 Java Persistence API Developer Certified Expert Exam Version: 8.0 [ Total Questions: 33 ]

Ghislain Fourny. Information Systems for Engineers 7. The ecosystem around SQL

Object-Relational Mapping Tools let s talk to each other!

Setting Schema Name For Native Queries In. Hibernate >>>CLICK HERE<<<

Transcription:

arnaud.nauwynck@gmail.com Extracts from Intro to Db - Jdbc - JPA SpringData This document: http://arnaud-nauwynck.github.io/docs/introcodeextract-db-jdbc-jpa-springdata.pdf

SOURCE Document : http://arnaud-nauwynck.github.io/docs/ Intro-DB-Jdbc-JPA-SpringData.pdf ~ 150 pages : lesson to read THIS Document ~ 80 pages : slides to present

(4) < Spring Data < JPA API - JPQL (3) < Hibernate/EclipseLink Spring JPA QueryDsl Spring JDBC < JDBC API (2) < Driver Impl. SQL Client Driver (1) < DataBase < B-Tree File

Oracle Sample DataBase https://github.com/oracle/db-sample-schemas/ human_resources/hr_cre.sql

UML Employee - Department * employees Employee 0..1 dept Department 0..1 deptmanager 0..1 manager

Example using PGAdmin3

Detailed CRUD CRUD = Create INSERT into <Table..> (col1, col2, ) VALUES (?0,?1, 123,..) Read SELECT * from <Table..> where <expr..> Update UPDATE col1=value1, col2= from <Table..> where <expr..> Delete DELETE from <Table..> where <expr..>

Emp-Dept CRUD Sample

SQL Exercises http://www.w3resource.com/sql-exercises/sql-subqueriesexercises.php

B-Tree = Balanced-Tree (not only Binary Tree)

B-Tree on (Col1,Col2...) = INDEX Insert ROW = (ACID : Atomic) Insert Data + Insert Index1 + Insert Index2 +. PK INDEX : col (ID) INDEX2 : (Col2,Col3,ID) INDEX3 : (Col3,Col2,Col6)

Select.. where ID =? Execution Plan Step 1: Index Lookup (Unique) by ID Log(N) logical reads => get rowid (=address) Step 2: table lookup by RowId (=O(1)) => get other columns

Applicable Index(es)? for.. where Col2=? And Col5=? PK INDEX : col (ID) INDEX (Col2,Col6,Col5) INDEX (Col2,Col5,Col6) INDEX (Col5,Col2,Col7) INDEX (Col1,Col2,Col5) Applicable = Allow Lexicographical Top->Down Search

Query Execution Engine Select.. from.. where.. col1='val1' and col2=123 Execute Query Result : Tabular Data Format = ResultSet

Huge Result.. Server-Side Cursor Begin Execute Query Result = Partial Data + Cursor (= handle of server-side Partial Data+ Iterator) Fetch next page Fetch next page Fetch next page CLOSE CURSOR!!

SoftParse HardParse PrepareQuery + BindVariable Select.. from.. where.. col1=?0 and col2=?1 BindVariable: set(0, val1 ) set(1, 1234) Compute Execution Plan First Seen? HARD Parse Put in Cache Already Seen? SOFT Parse = create Cursor

Explain Execution Plan

Query / Prepared Query Execution Select.. from.. where.. col1=?0 and col2=?1 BindVariable: set(0, val1 ) set(1, 1234) Prepare (SQL) PreparedStatement ExecuteQuery ResultSet (page1) Next row get col1, get col2 next row... Fetch next page

Spring JPA QueryDsl Spring JDBC

import java.sql.*; DataSource Connection PreparedStatement ResultSet

Sample Jdbc (Test with Rollback)

Refactored (1/2)

Refactored (2/2) Template + Callback Code to run with Cx + rollback Common Template Framework.. similar to Spring Template

Data Transfer Object for CRUD

CRUD 1 / 4 : SELECT

Jdbc is As Verbose as Easy... Is it DRY? D don't R repeat Y yourself

CRUD 2 / 4 : INSERT

CRUD 3 / 4 : UPDATE (All columns)

UPDATE with Versioning

CRUD 4 / 4 : DELETE

import java.sql.*; (full) DatabaseMetaData DataSource Connection ParameterMetaData Statement PreparedStatement CallableStatement Driver XAResource XADataSource XAConnection ResultSetMetaData ResultSet

H2 DataSource HelloWorld

Postgresql HelloWorld

Spring JPA QueryDsl Spring JDBC

Spring-Jdbc Database App

Springboot config/application.yml

Springboot JDBC JUST work

Springboot Jdbc main() Start Spring + inject DataSource Pooled DataSource injected

Springboot JUnit Pooled DataSource injected DataSource in injected Start Spring + inject DataSource

(Reminder) try-finally.close() Using explicit Transaction + commit/rollback Using try-close Rule for ALL Resources : If You Open It => You Close It

using Template Spring-Jdbc

PooledConnection + Transaction = Thread-Locked : reuse Thread-12 Conn XA.. XA commit/rollback => connection commit/rollback THEN repool

Springboot built-in supports JTA @Transactional

Spring JPA QueryDsl Spring JDBC

JPA (with springboot data)

EntityManager

What is an Entity? A class with @Entity And an @Id

Sufficient @Annotations to know? @Entity SubClasses @Inheritance @DiscriminatorColumn @Id @GeneratedValue @SequenceGenerator @Table @Version Custom @Column For relationships @ManyToOne FK (*) (1) PK @JoinTable PK (1) (*) FK @OneToMany @JoinColumn Base

Why putting @Column & @Table?

@Id with Sequence Generator SQL: CREATE SEQUENCE employees_seq INCREMENT BY 10; Detailed JPA:

@Version? whenever overwriting modified value without reading => version=1 (5): REDO fetch + update (1) (2): Get data version:1 (3): Mofify + Save (on version 1) OK => increment version=2 Wait... (4): Mofify + Save (on version 1?) => OptimisticLockException.. version=2! (6): Save (on version=2) OK

@Entity Employee-Department Database table EMPLOYEE id (PK), version, first_name, last_name,. department_id (FK department.id) manager_id (FK employee.id) Database table DEPARTMENT id (PK), version, name, department_manager_id (FK employee.id)

For real with @Column...

FindById with JPA

CRUD with JPA

Dynamic Query ( java.persistence.criteriabuilder )

Dynamic Query using Bind-Variables

Dynamic Query String type checking? Which one is correct??? Discover it by Exception on PROD! cb.get( addr ) // column name in Database cb.get( address ) // field name in java cb.get( adress ) // with a Typo cb.get( city_id ).get( name ) // after refactoring db schema

Generated *_ class MetaModel + Compile Type Check Generate

DynamicCriteria using MetaModel

Search Parameters in Criteria class (also called Specification ) Cascading Setters with return this for Fluent API

springboot data Spring JPA QueryDsl Spring JDBC

QueryDsl ++More Fluent than JPA

springboot data Spring JPA QueryDsl Spring JDBC

Repository

Sample Code using springboot-data Repository

Springboot hibernate JUST work CRUD select * from EMPLOYEE where insert into EMPLOYEE (..) values (..)

When/How/Where are my create Table ()??? Tables are created/updated at startup Detected H2 Database SQL langage Also create PK/FK indexes

extends JpaRepository

Small + Custom + Almost Complete (see also next for QueryDsl) By naming convention.. Equivalent to: Select * from EMPLOYEE where email=? Extends JpaRepository built-in CRUD findall, by Page, save, delete... (no update, use Setters)

QueryDsl + Spring-Data

AngularJS + Springboot In Jhipster you have 100% springboot on server-side with Code Generator And also Hipe code on client-side : Html / Css + AngularJS +..

Java is Hipe Make Jar nor WAR NO PHP NO NodeJS on server 20 years of Java Just The Beginning Its HIPE...because of springboot & open-source & java community

Conclusion This document: http://arnaud-nauwynck.github.io/docs/introcodeextract-db-jdbc-jpa-springdata.pdf