SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
JDBC, what is it good for?
1
Thomas Risberg
@trisberg
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
About Me
2
Thomas Risberg (@trisberg)
• Member of the Spring engineering team at Pivotal
• Contributing to Project riff and Spring Cloud Data
Flow
• Joined the Spring Framework open source project
in 2003 working on JDBC support
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Where it all started … back in 2002
3
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring solved JDBC try-catch nightmare and more
4
From “Spring JDBC” presentation at OSCON 2005
https://github.com/trisberg/s1p2017-jdbc/tree/master/older-presentations
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring JDBC - who does what?
5
Spring You
DataSource/Connection Configuration ✓
Connection Management ✓
Specify the SQL statement and its parameters ✓
Manage statement execution and loop through results ✓
Retrieve and handle data for each row ✓
Manage the transaction ✓
Translate exceptions to RuntimeExceptions ✓
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring JDBC Support
Choosing an approach for JDBC database access
• JdbcTemplate is the classic Spring JDBC approach and the most popular
• NamedParameterJdbcTemplate wraps a JdbcTemplate to provide named
parameters instead of the traditional JDBC "?" placeholders
• SimpleJdbcInsert and SimpleJdbcCall utilize database metadata to limit the
amount of necessary configuration
• RDBMS Objects including MappingSqlQuery, SqlUpdate and
StoredProcedure for creating reusable and thread-safe objects during
initialization
6
Demo
Some JDBC Examples
https://github.com/trisberg/s1p2017-jdbc/tree/master/jdbc-demo
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
What is next for Spring JDBC?
A new Spring Data JDBC project
https://github.com/spring-projects/spring-data-jdbc
• Spring Data Repository implementation with JDBC
• This is NOT an ORM
• CRUD operations
• Id generation
• NamingStrategy
• Events
• BeforeDelete / AfterDelete
• BeforeSave / AfterSave
• AfterCreation
8
Demo
Spring Data JDBC Demo App
https://github.com/gregturn/spring-data-jdbc-demo
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Using JDBC in new application architectures
• Microservices / Cloud Deployments
• Event Sourcing / CQRS
• Reactive, Non-Blocking APIs
• Serverless
10
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
JDBC in the Cloud
11
Connecting to RDBMS databases in cloud
environments
• Cloud Foundry
• Kubernetes
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Cloud Foundry for Spring Boot with JDBC
12
Running Spring Boot JDBC Apps
• Java Buildpack will auto-reconfigure your app injecting its own
DataSource configuration unless:
• You have multiple DataSource beans defined
• You have multiple RDBMS services bound to you app
• Java Buildpack auto-reconfiguration will also inject a symbolic link to it’s
jdbc driver if you don’t provide one in your app jar
• You can turn auto-reconfiguration off with an environment variable:
• JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '[enabled: false]’
• You probably still want to set the active profile:
• SPRING_PROFILES_ACTIVE: cloud
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Deploying JDBC Spring Boot App on Cloud Foundry
13
cf create-service p-mysql 512mb mysql
cf push -f cloudfoundry/jdbc-demo_manifest.yml 
-p target/spring-data-jdbc-demo-0.0.1-SNAPSHOT.jar
cloudfoundry/jdbc-demo_manifest.yml resources/application-cloud.properties
resources/schema-mysql.sql
applications:
- name: jdbc-demo
disk_quota: 512M
instances: 1
memory: 512M
routes:
- route: jdbc-demo.local.pcfdev.io
services:
- mysql
stack: cflinuxfs2
spring.datasource.platform=mysql
spring.datasource.initialization-mode=always
spring.datasource.driverClassName=org.mariadb.jdbc.Driver
CREATE TABLE IF NOT EXISTS Employee ( id BIGINT AUTO_INCREMENT
PRIMARY KEY, firstname VARCHAR(100), lastname VARCHAR(100), role
VARCHAR(20))
CREATE TABLE IF NOT EXISTS Manager ( manager_id BIGINT
AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100))
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Deploying JDBC Spring Boot App on Kubernetes
14
apiVersion: v1
kind: ConfigMap
metadata:
name: jdbc-demo
labels:
app: jdbc-demo
data:
application.yaml: |-
spring:
datasource:
url: jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT}/mysql
username: root
password: ${MYSQL_ROOT_PASSWORD}
driverClassName: org.mariadb.jdbc.Driver
testOnBorrow: true
validationQuery: "SELECT 1"
kubectl apply -f kubernetes/mysql/
kubectl apply -f kubernetes/
kubernetes/jdbc-demo-config.yaml
spring.datasource.platform=mysql
spring.datasource.initialization-mode=always
spring.datasource.driverClassName=org.mariadb.jdbc.Driver
resources/application-kubernetes.properties
CREATE TABLE IF NOT EXISTS Employee ( id BIGINT AUTO_INCREMENT
PRIMARY KEY, firstname VARCHAR(100), lastname VARCHAR(100), role
VARCHAR(20))
CREATE TABLE IF NOT EXISTS Manager ( manager_id BIGINT AUTO_INCREMENT
PRIMARY KEY, NAME VARCHAR(100))
resources/schema-mysql.sql
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Event Sourcing / CQRS
• Separates reads from writes
• Uses different data models for Event Store and Read
Storage
• Might use different type of data stores for Event Store
and Read Storage
• JDBC could be a good for for one or both of them
15
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
JDBC and Async / Reactive
We are not there yet.
Async JDBC proposal from JavaOne 2017
• Developed by the JDBC Expert Group through the Java Community Process
• The API is available for download from OpenJDK at
http://oracle.com/goto/java-async-db
• Send feedback to jdbc-spec-discuss@openjdk.java.net
Fake it using thread pools, an async layer and Futures to hide your blocking calls
16
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Serverless JDBC
17
Running serverless functions accessing RDBMS data
• Spring Cloud Function provides abstraction layer that can be used on:
• Project riff ✓
• AWS Lambda ✓
• Azure Functions
• Open Whisk
• Fn Project
• …
• Prefer using JDBC rather than JPA/Hibernate for faster cold start
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
The JDBC Function
18
public class JdbcWriter implements Function<Map<String, Object>, String> {
@Autowired
private JdbcTemplate jdbcTemplate;
private SimpleJdbcInsert insert;
@PostConstruct
public void init() {
this.insert = new SimpleJdbcInsert(jdbcTemplate)
.withTableName("data")
.usingColumns("name", "description")
.usingGeneratedKeyColumns("id");
}
@Override
public String apply(Map<String, Object> data) {
logger.info("Received: " + data);
Object name = data.get("name");
Object description = data.get("description");
logger.info("Inserting into data table: [" + name + ", " + description +"]");
SqlParameterSource input = new MapSqlParameterSource("name", name).addValue("description", description);
Number newId = insert.executeAndReturnKey(input);
logger.info("NewId is: " + newId);
return "{ "newId": " + newId + " }";
}
}
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring Cloud Function on AWS Lambda
19
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Spring Cloud Function with JDBC Writer
Parameters:
DBPwd:
NoEcho: true
Description: The database account password
Type: String
Resources:
Employee:
Type: AWS::Serverless::Function
Properties:
FunctionName: JdbcWriter
Handler: org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler
Runtime: java8
CodeUri: s3://trisberg-functions/jdbc-writer-0.0.1-SNAPSHOT-uber.jar
Description: Demo JDBC Writer on AWS
Timeout: 30
MemorySize: 1024
Environment:
Variables:
SPRING_DATASOURCE_URL: jdbc:mysql://springone.clsmkylda5na.us-east-1.rds.amazonaws.com:3306/test
SPRING_DATASOURCE_USERNAME: master
SPRING_DATASOURCE_PASSWORD: { "Ref" : "DBPwd" }
SPRING_DATASOURCE_PLATFORM: mysql
Role: arn:aws:iam::641162161031:role/lambda-execution-role
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Spring Cloud Function on Project riff
20
apiVersion: projectriff.io/v1
kind: Topic
metadata:
name: data
---
apiVersion: projectriff.io/v1
kind: Function
metadata:
name: jdbc-writer
spec:
protocol: http
input: data
container:
image: trisberg/jdbc-writer:0.0.1-SNAPSHOT
env:
- name: FUNCTION_URI
value: file:///functions/function.jar?handler=example.JdbcWriter
- name: SPRING_PROFILES_ACTIVE
value: kubernetes
- name: SPRING_DATASOURCE_DRIVER_CLASS_NAME
value: 'org.mariadb.jdbc.Driver'
- name: SPRING_DATASOURCE_URL
value: 'jdbc:mysql://data-mysql:3306/mysql'
- name: SPRING_DATASOURCE_USERNAME
value: root
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: data-mysql
key: mysql-root-password
Demo
Spring Cloud Function JDBC Writer App
https://github.com/trisberg/s1p2017-jdbc/tree/master/jdbc-writer
Learn More. Stay Connected.
https://github.com/spring-projects/spring-framework/tree/master/spring-jdbc
https://github.com/spring-projects/spring-data-jdbc
https://github.com/spring-cloud/spring-cloud-function
https://github.com/projectriff/riff
22
#springone@s1p

Mais conteúdo relacionado

Mais procurados

Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
Jollen Chen
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
Jollen Chen
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
Brightcove
 

Mais procurados (10)

Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
 
Migrating to Angular 5 for Spring Developers
Migrating to Angular 5 for Spring DevelopersMigrating to Angular 5 for Spring Developers
Migrating to Angular 5 for Spring Developers
 
Migrating to Angular 4 for Spring Developers
Migrating to Angular 4 for Spring Developers Migrating to Angular 4 for Spring Developers
Migrating to Angular 4 for Spring Developers
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
 
Accelerating Development with Organizational Opinions
Accelerating Development with Organizational OpinionsAccelerating Development with Organizational Opinions
Accelerating Development with Organizational Opinions
 
Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
 
The Future Of Web Frameworks
The Future Of Web FrameworksThe Future Of Web Frameworks
The Future Of Web Frameworks
 
RDBMS and Apache Geode Data Movement: Low Latency ETL Pipeline By Using Cloud...
RDBMS and Apache Geode Data Movement: Low Latency ETL Pipeline By Using Cloud...RDBMS and Apache Geode Data Movement: Low Latency ETL Pipeline By Using Cloud...
RDBMS and Apache Geode Data Movement: Low Latency ETL Pipeline By Using Cloud...
 
Web application framework
Web application frameworkWeb application framework
Web application framework
 

Semelhante a JDBC, What Is It Good For?

Semelhante a JDBC, What Is It Good For? (20)

deep learning in production cff 2017
deep learning in production cff 2017deep learning in production cff 2017
deep learning in production cff 2017
 
Spark forspringdevs springone_final
Spark forspringdevs springone_finalSpark forspringdevs springone_final
Spark forspringdevs springone_final
 
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
Kafka Summit NYC 2017 - Cloud Native Data Streaming Microservices with Spring...
 
Enable SQL/JDBC Access to Apache Geode/GemFire Using Apache Calcite
Enable SQL/JDBC Access to Apache Geode/GemFire Using Apache CalciteEnable SQL/JDBC Access to Apache Geode/GemFire Using Apache Calcite
Enable SQL/JDBC Access to Apache Geode/GemFire Using Apache Calcite
 
Springone2gx 2015 Cassandra and Grails
Springone2gx 2015 Cassandra and GrailsSpringone2gx 2015 Cassandra and Grails
Springone2gx 2015 Cassandra and Grails
 
Full Steam Ahead, R2DBC!
Full Steam Ahead, R2DBC!Full Steam Ahead, R2DBC!
Full Steam Ahead, R2DBC!
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
 
Enable SQL/JDBC Access to Apache Geode/GemFire Using Apache Calcite
Enable SQL/JDBC Access to Apache Geode/GemFire Using Apache CalciteEnable SQL/JDBC Access to Apache Geode/GemFire Using Apache Calcite
Enable SQL/JDBC Access to Apache Geode/GemFire Using Apache Calcite
 
Java database programming with jdbc
Java database programming with jdbcJava database programming with jdbc
Java database programming with jdbc
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
 
Ajp notes-chapter-05
Ajp notes-chapter-05Ajp notes-chapter-05
Ajp notes-chapter-05
 
Creating a Facebook Clone - Part XVII - Transcript.pdf
Creating a Facebook Clone - Part XVII - Transcript.pdfCreating a Facebook Clone - Part XVII - Transcript.pdf
Creating a Facebook Clone - Part XVII - Transcript.pdf
 
SoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringSoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with Spring
 
Deploying Spring Boot apps on Kubernetes
Deploying Spring Boot apps on KubernetesDeploying Spring Boot apps on Kubernetes
Deploying Spring Boot apps on Kubernetes
 
chapter 5 java.pptx
chapter 5  java.pptxchapter 5  java.pptx
chapter 5 java.pptx
 
Midao JDBC presentation
Midao JDBC presentationMidao JDBC presentation
Midao JDBC presentation
 
Running Java Applications on Cloud Foundry
Running Java Applications on Cloud FoundryRunning Java Applications on Cloud Foundry
Running Java Applications on Cloud Foundry
 
Measuring Web Performance
Measuring Web Performance Measuring Web Performance
Measuring Web Performance
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
Airline report
Airline reportAirline report
Airline report
 

Mais de VMware Tanzu

Mais de VMware Tanzu (20)

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Último

Último (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

JDBC, What Is It Good For?

  • 1. JDBC, what is it good for? 1 Thomas Risberg @trisberg
  • 2. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About Me 2 Thomas Risberg (@trisberg) • Member of the Spring engineering team at Pivotal • Contributing to Project riff and Spring Cloud Data Flow • Joined the Spring Framework open source project in 2003 working on JDBC support
  • 3. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Where it all started … back in 2002 3
  • 4. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring solved JDBC try-catch nightmare and more 4 From “Spring JDBC” presentation at OSCON 2005 https://github.com/trisberg/s1p2017-jdbc/tree/master/older-presentations
  • 5. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring JDBC - who does what? 5 Spring You DataSource/Connection Configuration ✓ Connection Management ✓ Specify the SQL statement and its parameters ✓ Manage statement execution and loop through results ✓ Retrieve and handle data for each row ✓ Manage the transaction ✓ Translate exceptions to RuntimeExceptions ✓
  • 6. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring JDBC Support Choosing an approach for JDBC database access • JdbcTemplate is the classic Spring JDBC approach and the most popular • NamedParameterJdbcTemplate wraps a JdbcTemplate to provide named parameters instead of the traditional JDBC "?" placeholders • SimpleJdbcInsert and SimpleJdbcCall utilize database metadata to limit the amount of necessary configuration • RDBMS Objects including MappingSqlQuery, SqlUpdate and StoredProcedure for creating reusable and thread-safe objects during initialization 6
  • 8. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What is next for Spring JDBC? A new Spring Data JDBC project https://github.com/spring-projects/spring-data-jdbc • Spring Data Repository implementation with JDBC • This is NOT an ORM • CRUD operations • Id generation • NamingStrategy • Events • BeforeDelete / AfterDelete • BeforeSave / AfterSave • AfterCreation 8
  • 9. Demo Spring Data JDBC Demo App https://github.com/gregturn/spring-data-jdbc-demo
  • 10. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Using JDBC in new application architectures • Microservices / Cloud Deployments • Event Sourcing / CQRS • Reactive, Non-Blocking APIs • Serverless 10
  • 11. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JDBC in the Cloud 11 Connecting to RDBMS databases in cloud environments • Cloud Foundry • Kubernetes
  • 12. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Foundry for Spring Boot with JDBC 12 Running Spring Boot JDBC Apps • Java Buildpack will auto-reconfigure your app injecting its own DataSource configuration unless: • You have multiple DataSource beans defined • You have multiple RDBMS services bound to you app • Java Buildpack auto-reconfiguration will also inject a symbolic link to it’s jdbc driver if you don’t provide one in your app jar • You can turn auto-reconfiguration off with an environment variable: • JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '[enabled: false]’ • You probably still want to set the active profile: • SPRING_PROFILES_ACTIVE: cloud
  • 13. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Deploying JDBC Spring Boot App on Cloud Foundry 13 cf create-service p-mysql 512mb mysql cf push -f cloudfoundry/jdbc-demo_manifest.yml -p target/spring-data-jdbc-demo-0.0.1-SNAPSHOT.jar cloudfoundry/jdbc-demo_manifest.yml resources/application-cloud.properties resources/schema-mysql.sql applications: - name: jdbc-demo disk_quota: 512M instances: 1 memory: 512M routes: - route: jdbc-demo.local.pcfdev.io services: - mysql stack: cflinuxfs2 spring.datasource.platform=mysql spring.datasource.initialization-mode=always spring.datasource.driverClassName=org.mariadb.jdbc.Driver CREATE TABLE IF NOT EXISTS Employee ( id BIGINT AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(100), lastname VARCHAR(100), role VARCHAR(20)) CREATE TABLE IF NOT EXISTS Manager ( manager_id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100))
  • 14. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Deploying JDBC Spring Boot App on Kubernetes 14 apiVersion: v1 kind: ConfigMap metadata: name: jdbc-demo labels: app: jdbc-demo data: application.yaml: |- spring: datasource: url: jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT}/mysql username: root password: ${MYSQL_ROOT_PASSWORD} driverClassName: org.mariadb.jdbc.Driver testOnBorrow: true validationQuery: "SELECT 1" kubectl apply -f kubernetes/mysql/ kubectl apply -f kubernetes/ kubernetes/jdbc-demo-config.yaml spring.datasource.platform=mysql spring.datasource.initialization-mode=always spring.datasource.driverClassName=org.mariadb.jdbc.Driver resources/application-kubernetes.properties CREATE TABLE IF NOT EXISTS Employee ( id BIGINT AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(100), lastname VARCHAR(100), role VARCHAR(20)) CREATE TABLE IF NOT EXISTS Manager ( manager_id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)) resources/schema-mysql.sql
  • 15. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Event Sourcing / CQRS • Separates reads from writes • Uses different data models for Event Store and Read Storage • Might use different type of data stores for Event Store and Read Storage • JDBC could be a good for for one or both of them 15
  • 16. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JDBC and Async / Reactive We are not there yet. Async JDBC proposal from JavaOne 2017 • Developed by the JDBC Expert Group through the Java Community Process • The API is available for download from OpenJDK at http://oracle.com/goto/java-async-db • Send feedback to jdbc-spec-discuss@openjdk.java.net Fake it using thread pools, an async layer and Futures to hide your blocking calls 16
  • 17. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Serverless JDBC 17 Running serverless functions accessing RDBMS data • Spring Cloud Function provides abstraction layer that can be used on: • Project riff ✓ • AWS Lambda ✓ • Azure Functions • Open Whisk • Fn Project • … • Prefer using JDBC rather than JPA/Hibernate for faster cold start
  • 18. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The JDBC Function 18 public class JdbcWriter implements Function<Map<String, Object>, String> { @Autowired private JdbcTemplate jdbcTemplate; private SimpleJdbcInsert insert; @PostConstruct public void init() { this.insert = new SimpleJdbcInsert(jdbcTemplate) .withTableName("data") .usingColumns("name", "description") .usingGeneratedKeyColumns("id"); } @Override public String apply(Map<String, Object> data) { logger.info("Received: " + data); Object name = data.get("name"); Object description = data.get("description"); logger.info("Inserting into data table: [" + name + ", " + description +"]"); SqlParameterSource input = new MapSqlParameterSource("name", name).addValue("description", description); Number newId = insert.executeAndReturnKey(input); logger.info("NewId is: " + newId); return "{ "newId": " + newId + " }"; } }
  • 19. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Cloud Function on AWS Lambda 19 AWSTemplateFormatVersion : '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Spring Cloud Function with JDBC Writer Parameters: DBPwd: NoEcho: true Description: The database account password Type: String Resources: Employee: Type: AWS::Serverless::Function Properties: FunctionName: JdbcWriter Handler: org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler Runtime: java8 CodeUri: s3://trisberg-functions/jdbc-writer-0.0.1-SNAPSHOT-uber.jar Description: Demo JDBC Writer on AWS Timeout: 30 MemorySize: 1024 Environment: Variables: SPRING_DATASOURCE_URL: jdbc:mysql://springone.clsmkylda5na.us-east-1.rds.amazonaws.com:3306/test SPRING_DATASOURCE_USERNAME: master SPRING_DATASOURCE_PASSWORD: { "Ref" : "DBPwd" } SPRING_DATASOURCE_PLATFORM: mysql Role: arn:aws:iam::641162161031:role/lambda-execution-role
  • 20. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Cloud Function on Project riff 20 apiVersion: projectriff.io/v1 kind: Topic metadata: name: data --- apiVersion: projectriff.io/v1 kind: Function metadata: name: jdbc-writer spec: protocol: http input: data container: image: trisberg/jdbc-writer:0.0.1-SNAPSHOT env: - name: FUNCTION_URI value: file:///functions/function.jar?handler=example.JdbcWriter - name: SPRING_PROFILES_ACTIVE value: kubernetes - name: SPRING_DATASOURCE_DRIVER_CLASS_NAME value: 'org.mariadb.jdbc.Driver' - name: SPRING_DATASOURCE_URL value: 'jdbc:mysql://data-mysql:3306/mysql' - name: SPRING_DATASOURCE_USERNAME value: root - name: SPRING_DATASOURCE_PASSWORD valueFrom: secretKeyRef: name: data-mysql key: mysql-root-password
  • 21. Demo Spring Cloud Function JDBC Writer App https://github.com/trisberg/s1p2017-jdbc/tree/master/jdbc-writer
  • 22. Learn More. Stay Connected. https://github.com/spring-projects/spring-framework/tree/master/spring-jdbc https://github.com/spring-projects/spring-data-jdbc https://github.com/spring-cloud/spring-cloud-function https://github.com/projectriff/riff 22 #springone@s1p