Learn how to improve JDBC API code on Quarkus & Jakarta EE!
If you are a Java developer, at some point you will need to understand more deeply how the JDBC API and relational databases like PostgreSQL works from end-to-end in order to improve the quality of the code that is responsible for connecting your application server with the database engine through a DAO or a Repository pattern.
As JDBC (Java Database Connectivity) is a low-level API, you'll have to be careful when managing database resources at the application level, you'll also need relevant important APIs. This is exactly the PoC (Proof-of-concept) that will be covered in this video.
?? *Github:* https://github.com/fercomunello/quarkus-jdbc-api
*Twitter:* https://twitter.com/fercomunello
? *What is covered in this tutorial?*
You'll learn not only how to connect Java to PostgreSQL, but also:
- Start an EE application with Quarkus, framework developed by Red Hat, using OpenJDK 17 LTS as runtime.
- Start a development environment with Docker containers from Postgres and TestContainers without having to configure any configuration for it, you just need to have Docker and the JDK installed on your machine, the DevServices built into Quarkus will do the rest automatically;
- Manage a connection pool correctly with Agroal, a connection pool also created by Red Hat, which is used from JBoss and WildFly application servers, now ported to a Quarkus extension;
- Detect and correct leaks of Connection, Statement, ResultSet and other resources;
- Commit and rollback transactions first via Plain JDBC and then through the JTA (Jakarta Transaction API) specification, using the Narayana JTA implementation;
- Catch SQLException's according to the "SQL State Code". Each database vendor has its own response codes;
- Create Wrapper classes and CDI Beans above the JDBC API;
- Write integration tests with JUnit for each DML (INSERT, INSERT RETURNING, UPDATE, UPDATE RETURNING DELETE) and DQL (SELECT) operation performed;
- Write specific JUnit Test scenario for read operations that act as a fallback in case of writing failure either because of a database constraint that was violated or for another reason;
- In addition to the fallback operation, you will also learn other strategies to reduce the number of roundtrips (round trips) between your application and the RDBMS;
- Finally, I show the differences of the ORM approach compared to JDBC.
The code also used robust Java features such as: Type Inference, Functional Interfaces, Lambdas, Try-With-Resources. And also more recent features like for example: Records, Pattern Matching and Sealed Classes. For now, you don't have to worry about these details, I'll leave some links so you can study whenever you want.
? *For knowledge:*
☕️ *Java SE*
- JDBC API: https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html
- Type Inference: https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html
- Try-with-resources: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
- Functions: https://dev.java/learn/lambdas/first-lambdas
- Records: https://dev.java/learn/records
- Pattern Matching: https://dev.java/learn/pattern-matching
- Sealed Classes: https://docs.oracle.com/en/java/javase/17/language/sealed-classes-and-interfaces.html
- Text Blocks: https://docs.oracle.com/en/java/javase/15/text-blocks/index.html
☕️ *Java Enterprise*
- Jakarta EE: https://jakarta.ee
- Quarkus: https://quarkus.io
? Postgres Driver: https://jdbc.postgresql.org
❓ *FAQ:*
// *Quarkus & Jakarta EE. Together or not?*
https://developers.redhat.com/blog/2020/09/11/quarkus-and-jakarta-ee-together-or-not
// *What's the propagation strategies of JTA transactions?*
https://docs.oracle.com/javaee/6/tutorial/doc/bncij.html
// *What is an Jakarta EE compilant application server?*
Read my article ??: https://medium.com/@fercomunello/primeiros-passos-com-o-servidor-de-aplica%C3%A7%C3%A3o-wildfly-jboss-e-jakarta-ee-c2e166719f15
? *Chapters*
00:00:00 | What you will learn?
00:00:25 | A short history
00:01:01 | Why JDBC?
00:01:21 | Connection Pool
00:02:15 | Trade-offs
00:02:58 | PoC (Proof-of-concept)
00:03:21 | Setup Quarkus
00:04:32 | What is Quarkus Dev Services?
00:05:26 | Plain JDBC? Hold on!
00:09:07 | Try-with-resources feature
00:10:09 | Database Transactions
00:11:05 | Why JTA for Transactions?
00:13:41 | The JDBC Wrapper Solution!
00:14:11 | JDBC Wrapper Explanation
00:19:52 | How to Insert and Return the Key?
00:22:10 | DML & DQL Operations
00:24:37 | Handling Constraint Violations
00:26:52 | JDBC Metadata Overview
00:27:11 | Fallback Query for Constraint Violations
00:30:00 | IntelliJ Highlight Settings
00:30:26 | The Battle: JPA vs JDBC
00:30:52 | Thanks!
#java #jdbc #quarkus #jakartaee #javaee
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Learn how to improve JDBC API code on Quarkus & Jakarta EE!», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.