Get the most out of your persistence layer<br><br>A high-performance data access layer must resonate with the underlying database system. Knowing the inner workings of a relational database and the data access frameworks in use can make the difference between a high-performance enterprise applicatio
High-Performance Java Persistence
โ Scribed by Vlad Mihalcea
- Year
- 2020
- Tongue
- English
- Leaves
- 461
- Edition
- 2020
- Category
- Library
No coin nor oath required. For personal study only.
โฆ Synopsis
Get the most out of your persistence layer
A high-performance data access layer must resonate with the underlying database system. Knowing the inner workings of a relational database and the data access frameworks in use can make the difference between a high-performance enterprise application and one that barely crawls.
This book is a journey into Java data access performance tuning. From connection management, to batch updates, fetch sizes and concurrency control mechanisms, it unravels the inner workings of the most common Java data access frameworks.
The first part aims to reduce the gap between application developers and database administrators. For this reason, it covers both JDBC and the database fundamentals that are of paramount importance when reducing transaction response times. In this first part, youll learn about connection management, batch updates, statement caching, result set fetching and database transactions.
The second part demonstrates how you can take advantage of JPA and Hibernate without compromising application performance. In this second part, youll learn about the most efficient Hibernate mappings (basic types, associations, inheritance), fetching best practices, caching and concurrency control mechanisms.
The third part is dedicated to jOOQ and its powerful type-safe querying capabilities, like window functions, common table expressions, upsert, stored procedures and database functions.
โฆ Table of Contents
Table of Contents
Preface
The database server and the connectivity layer
The application data access layer
The ORM framework
The native query builder framework
Video Course
Testimonials
I JDBC and Database Essentials
Performance and Scaling
Response time and throughput
Database connections boundaries
Scaling up and scaling out
Master-Slave replication
Multi-Master replication
Sharding
JDBC Connection Management
DriverManager
DataSource
Why is pooling so much faster?
Queuing theory capacity planning
Practical database connection provisioning
A real-life connection pool monitoring example
Concurrent connection request count metric
Concurrent connection count metric
Maximum pool size metric
Connection acquisition time metric
Retry attempts metric
Overall connection acquisition time metric
Connection lease time metric
Batch Updates
Batching Statements
Batching PreparedStatements
Choosing the right batch size
Bulk processing
Retrieving auto-generated keys
Sequences to the rescue
Statement Caching
Statement lifecycle
Parser
Optimizer
Execution plan visualization
Executor
Caching performance gain
Server-side statement caching
Bind-sensitive execution plans
Client-side statement caching
ResultSet Fetching
ResultSet scrollability
ResultSet changeability
ResultSet holdability
Fetching size
ResultSet size
Too many rows
SQL limit clause
JDBC max rows
Less is more
Too many columns
Transactions
Atomicity
Consistency
Isolation
Concurrency control
Two-phase locking
Multi-Version Concurrency Control
Phenomena
Dirty write
Dirty read
Non-repeatable read
Phantom read
Read skew
Write skew
Lost update
Isolation levels
Read Uncommitted
Read Committed
Repeatable Read
Serializable
Durability
Read-only transactions
Read-only transaction routing
Transaction boundaries
Distributed transactions
Two-phase commit
Declarative transactions
Application-level transactions
Pessimistic and optimistic locking
Pessimistic locking
Optimistic locking
II JPA and Hibernate
Why JPA and Hibernate matter
The impedance mismatch
JPA vs. Hibernate
Schema ownership
Entity state transitions
Write-based optimizations
Read-based optimizations
Wrap-up
Connection Management and Monitoring
JPA connection management
Hibernate connection providers
DriverManagerConnectionProvider
C3P0ConnectionProvider
HikariCPConnectionProvider
DatasourceConnectionProvider
Connection release modes
Monitoring connections
Hibernate statistics
Customizing statistics
Statement logging
Statement formatting
Statement-level comments
Logging parameters
DataSource-proxy
P6Spy
Mapping Types and Identifiers
Types
Primitive types
String types
Date and Time types
Numeric types
Binary types
UUID types
Other types
Custom types
Identifiers
UUID identifiers
The assigned generator
The legacy UUID generator
The newer UUID generator
Numerical identifiers
Identity generator
Sequence generator
Table generator
Optimizers
The hi/lo algorithm
The default sequence identifier generator
The default table identifier generator
The pooled optimizer
The pooled-lo optimizer
Optimizer gain
Sequence generator performance gain
Table generator performance gain
Identifier generator performance
Relationships
Relationship types
@ManyToOne
@OneToMany
Bidirectional @OneToMany
Unidirectional @OneToMany
Ordered unidirectional @OneToMany
@OneToMany with @JoinColumn
Unidirectional @OneToMany Set
@ElementCollection
@ElementCollection List
@ElementCollection Set
@OneToOne
Unidirectional @OneToOne
Bidirectional @OneToOne
@ManyToMany
Unidirectional @ManyToMany List
Unidirectional @ManyToMany Set
Bidirectional @ManyToMany
The @OneToMany alternative
Hypersistence Optimizer
Testimonials
Inheritance
Single table
Data integrity constraints
Join table
Table-per-class
Mapped superclass
Flushing
Flush modes
Events and the action queue
Flush operation order
Dirty Checking
The default dirty checking mechanism
Controlling the Persistence Context size
Bytecode enhancement
Batching
Batching insert statements
Batching update statements
Batching delete statements
Fetching
DTO projection
DTO projection pagination
Native query DTO projection
Query fetch size
Fetching entities
Direct fetching
Fetching a Proxy reference
Natural identifier fetching
Query fetching
Fetching associations
FetchType.EAGER
FetchType.LAZY
The N+1 query problem
How to catch N+1 query problems during testing
LazyInitializationException
The Open Session in View Anti-Pattern
Temporary Session Lazy Loading Anti-Pattern
Associations and pagination
Attribute lazy fetching
Fetching subentities
Entity reference deduplication
Query plan cache
Caching
Caching flavors
Cache synchronization strategies
Cache-aside
Read-through
Write-invalidate
Write-through
Write-behind
Database caching
Application-level caching
Entity aggregates
Distributed key-value stores
Cache synchronization patterns
Synchronous updates
Asynchronous updates
Change data capture
Second-level caching
Enabling the second-level cache
Entity cache loading flow
Entity cache entry
Entity reference cache store
Collection cache entry
Query cache entry
Cache concurrency strategies
READ_ONLY
Inserting READ_ONLY cache entries
Updating READ_ONLY cache entries
Deleting READ_ONLY cache entries
NONSTRICT_READ_WRITE
Inserting NONSTRICT_READ_WRITE cache entries
Updating NONSTRICT_READ_WRITE cache entries
Risk of inconsistencies
Deleting NONSTRICT_READ_WRITE cache entries
READ_WRITE
Inserting READ_WRITE cache entries
Updating READ_WRITE cache entries
Deleting READ_WRITE cache entries
Soft locking concurrency control
TRANSACTIONAL
XA_Strict mode
XA mode
Inserting TRANSACTIONAL cache entries
Updating TRANSACTIONAL cache entries
Deleting TRANSACTIONAL cache entries
Query cache strategy
Tablespace query cache invalidation
Native SQL statement query cache invalidation
Concurrency Control
Hibernate optimistic locking
The implicit optimistic locking mechanism
Resolving optimistic locking conflicts
Splitting entities
Versionless optimistic locking
OptimisticLockType.DIRTY update caveat
The explicit locking mechanism
PESSIMISTIC_READ and PESSIMISTIC_WRITE
Lock scope
Lock timeout
LockModeType.OPTIMISTIC
Inconsistency risk
LockModeType.OPTIMISTIC_FORCE_INCREMENT
LockModeType.PESSIMISTIC_FORCE_INCREMENT
III JOOQ
Why jOOQ matters
How jOOQ works
DML statements
Java-based schema
Upsert
Oracle
SQL Server
PostgreSQL
MySQL
Batch updates
Inlining bind parameters
Complex queries
Stored procedures and functions
Streaming
Keyset pagination
๐ SIMILAR VOLUMES
<span><p><b>Optimize the powerful techniques of Java 9 to boost your application's performance</b></p><p><b>About This Book</b></p><ul><li>Tackle all kinds of performance-related issues and streamline your development</li><li>Dive into the new features of Java 9</li><li>Implement highly efficient an
<p><b>Get more control of your applications performances in development and production and know how to meet your Service Level Agreement on critical microservices.</b></p><h4>Key Features</h4><ul><li>Learn how to write a JavaEE application with performance constraints (Service Level Agreement-SLA) l
Take your Java programming skills to the next level and learn to overcome real-world challenges to optimize application performance Key Features Leverage key features of the Java Virtual Machine to maximize runtime performance Unlock optimization strategies to effectively manage objects and mem
This book is a collection of developer code recipes and best practices for persisting data using Spring, particularly Spring Boot. The book is structured around practical recipes, where each recipe discusses a performance case or performance-related case, and almost every recipe has one or more appl