Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +11 -0
- 13 - Object-oriented programming/003 Different types of Classes, Abstract keyword and Abstract classes.mp4 +3 -0
- 13 - Object-oriented programming/004 Interfaces.mp4 +3 -0
- 13 - Object-oriented programming/005 Inheritance.mp4 +3 -0
- 13 - Object-oriented programming/006 Polymorphism and 'final' keyword.mp4 +3 -0
- 13 - Object-oriented programming/007 'static' keyword.mp4 +3 -0
- 13 - Object-oriented programming/008 Encapsulation.mp4 +3 -0
- 13 - Object-oriented programming/009 Object, JNI and Object class overview.mp4 +3 -0
- 13 - Object-oriented programming/011 SOLID principles overview & Single Responsibility Principle.mp4 +3 -0
- 13 - Object-oriented programming/012 Open Closed Principle.mp4 +3 -0
- 13 - Object-oriented programming/013 Liskov Substitution Principle.mp4 +3 -0
- 13 - Object-oriented programming/014 Interface Segregation Principle.mp4 +3 -0
- 76 - Cybersecurity Comprehensive Security Practices for Developers/012 Cloud Security Best Practices_en.srt +1060 -0
- 76 - Cybersecurity Comprehensive Security Practices for Developers/013 Mobile Application Security_en.srt +1148 -0
- 77 - ===== EXAM TASK OWASP Top 10, Secure Coding & Logging =====/001 Exam Task Description and Solution (with reference to the source code).html +69 -0
- 78 - ORM, JPA & Hibernate/001 Introduction to JPA & ORM_en.srt +608 -0
- 78 - ORM, JPA & Hibernate/002 First JPA Project Entity, ID GenerationType, Composite Primary Keys, etc)_en.srt +936 -0
- 78 - ORM, JPA & Hibernate/002 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/003 First JPA Project - Part 2 EntityManager, persistence.xml, Transactions in JPA_en.srt +996 -0
- 78 - ORM, JPA & Hibernate/003 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/004 Operations with Entity (Create, Read, Update, Delete) & JPA Entity Lifecycle_en.srt +884 -0
- 78 - ORM, JPA & Hibernate/004 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/005 Locking JPA Optimistic & Pessimistic Locking_en.srt +1320 -0
- 78 - ORM, JPA & Hibernate/005 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/006 Relationships Between Entities_en.srt +1080 -0
- 78 - ORM, JPA & Hibernate/006 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/007 JPA Queries (Query, TypedQuery, NativeQuery, JPQL, Criteria API)_en.srt +1160 -0
- 78 - ORM, JPA & Hibernate/007 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/008 Caching in JPAHibernate_en.srt +1424 -0
- 78 - ORM, JPA & Hibernate/008 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/009 N+1 Problem and Solution_en.srt +808 -0
- 78 - ORM, JPA & Hibernate/009 Source-code-of-examples-from-the-lesson.url +2 -0
- 78 - ORM, JPA & Hibernate/external-links.txt +24 -0
- 79 - ===== ORM & JPA Interview Preparation =====/001 Part 1 ORM & Hibernate Interview - Questions and Answers.html +69 -0
- 79 - ===== ORM & JPA Interview Preparation =====/002 Part 2 ORM & Hibernate Interview - Questions and Answers.html +69 -0
- 79 - ===== ORM & JPA Interview Preparation =====/003 Part 3 JPA Interview - Questions and Answers.html +69 -0
- 79 - ===== ORM & JPA Interview Preparation =====/004 Part 4 JPA Interview - Questions and Answers.html +69 -0
- 80 - ===== EXAM TASK JPA & Hibernate =====/001 ===== EXAM TASK JPA & Hibernate =====_en.srt +964 -0
- 80 - ===== EXAM TASK JPA & Hibernate =====/001 Homework-description-and-reference-to-the-solution.url +2 -0
- 80 - ===== EXAM TASK JPA & Hibernate =====/external-links.txt +3 -0
- 81 - Spring Core/001 List-of-Spring-projects.url +2 -0
- 81 - Spring Core/001 Official-Site-of-Spring.url +2 -0
- 81 - Spring Core/001 Spring Framework General Overview_en.srt +816 -0
- 81 - Spring Core/001 Spring-Initializr.url +2 -0
- 81 - Spring Core/002 Spring Architecture, Inversion of Control, Dependency Injection & Spring Beans_en.srt +736 -0
- 81 - Spring Core/003 IoC, Beans Configuration, XML and Annotations - Practice_en.srt +1584 -0
- 81 - Spring Core/003 Source-code-examples-from-the-lesson.url +2 -0
- 81 - Spring Core/003 applicationContext.xml.url +2 -0
- 81 - Spring Core/004 Source-code-examples-from-the-lesson.url +2 -0
- 81 - Spring Core/004 Spring Dependency Injection Practice_en.srt +1268 -0
.gitattributes
CHANGED
|
@@ -118,3 +118,14 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 118 |
12[[:space:]]-[[:space:]]Debugging[[:space:]]Tools/001[[:space:]]How[[:space:]]to[[:space:]]debug[[:space:]]Java[[:space:]]programs.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 119 |
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/001[[:space:]]Object-oriented[[:space:]]programming[[:space:]]Basics.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 120 |
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/002[[:space:]]Classes[[:space:]]&[[:space:]]Objects.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
12[[:space:]]-[[:space:]]Debugging[[:space:]]Tools/001[[:space:]]How[[:space:]]to[[:space:]]debug[[:space:]]Java[[:space:]]programs.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 119 |
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/001[[:space:]]Object-oriented[[:space:]]programming[[:space:]]Basics.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 120 |
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/002[[:space:]]Classes[[:space:]]&[[:space:]]Objects.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 121 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/003[[:space:]]Different[[:space:]]types[[:space:]]of[[:space:]]Classes,[[:space:]]Abstract[[:space:]]keyword[[:space:]]and[[:space:]]Abstract[[:space:]]classes.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 122 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/004[[:space:]]Interfaces.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 123 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/005[[:space:]]Inheritance.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 124 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/006[[:space:]]Polymorphism[[:space:]]and[[:space:]]'final'[[:space:]]keyword.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 125 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/008[[:space:]]Encapsulation.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 126 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/007[[:space:]]'static'[[:space:]]keyword.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 127 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/012[[:space:]]Open[[:space:]][[:space:]]Closed[[:space:]]Principle.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 128 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/011[[:space:]]SOLID[[:space:]]principles[[:space:]]overview[[:space:]]&[[:space:]]Single[[:space:]]Responsibility[[:space:]]Principle.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 129 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/009[[:space:]]Object,[[:space:]]JNI[[:space:]]and[[:space:]]Object[[:space:]]class[[:space:]]overview.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 130 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/013[[:space:]]Liskov[[:space:]]Substitution[[:space:]]Principle.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 131 |
+
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/014[[:space:]]Interface[[:space:]]Segregation[[:space:]]Principle.mp4 filter=lfs diff=lfs merge=lfs -text
|
13 - Object-oriented programming/003 Different types of Classes, Abstract keyword and Abstract classes.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f65326e2c8257d2888d03406c31e128de20de79ea7d093a24b9064b66cb4b782
|
| 3 |
+
size 214619488
|
13 - Object-oriented programming/004 Interfaces.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:29dd04a13a030b2cc1ff422882325c6fcfb44955075fdf1104fabcc15931a9ad
|
| 3 |
+
size 212297701
|
13 - Object-oriented programming/005 Inheritance.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e9654bb3c034b503f6f0eaf9a8f2e1b012269aee31b7fef825f32ce9b89baf8
|
| 3 |
+
size 204629371
|
13 - Object-oriented programming/006 Polymorphism and 'final' keyword.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:adb5291223aacdc2d3f85b82d4730d58ae7ef04d29597c3577bc9947c792dc12
|
| 3 |
+
size 199334709
|
13 - Object-oriented programming/007 'static' keyword.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cc4be31a6cda08041ca6bbb1e702c3355985098b08c64c0d517a6413e7ef025a
|
| 3 |
+
size 142223829
|
13 - Object-oriented programming/008 Encapsulation.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:930b1ee2a65e135b50873db789e0ef0d73a93224891312f25d321bcc7aa58b12
|
| 3 |
+
size 110141024
|
13 - Object-oriented programming/009 Object, JNI and Object class overview.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ac1bc73de416d712292b3104119a223a1584d99ddc54ed2dc20c267cd8746b21
|
| 3 |
+
size 268547559
|
13 - Object-oriented programming/011 SOLID principles overview & Single Responsibility Principle.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:50d39eda7f47a62f914bfebdd725f64f1783424431605801963826e44baebed9
|
| 3 |
+
size 116235324
|
13 - Object-oriented programming/012 Open Closed Principle.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a9a2729f8510907f595fc97f7f3e2edf488362b8e6cc130819add609f8fe75d
|
| 3 |
+
size 43997110
|
13 - Object-oriented programming/013 Liskov Substitution Principle.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fc648466bd606ca68209d64ef1f140489ec47ca27b86be5bdf70ff535e9932b3
|
| 3 |
+
size 79495387
|
13 - Object-oriented programming/014 Interface Segregation Principle.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d38e5c5de8f2725c906f34580b564b96d8ab801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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:07,000
|
| 3 |
+
Hello dear students.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:07,000 --> 00:00:12,000
|
| 7 |
+
In this lesson we will focus on essential strategies to ensure the security of cloud environments.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:13,000 --> 00:00:19,000
|
| 11 |
+
These practices are designed to protect critical assets, secure data, and maintain control over access
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:19,000 --> 00:00:21,000
|
| 15 |
+
to cloud resources.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:21,000 --> 00:00:27,000
|
| 19 |
+
We'll explore how to manage risks, effectively prevent unauthorized access, and ensure that sensitive
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:27,000 --> 00:00:29,000
|
| 23 |
+
information remains protected.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:29,000 --> 00:00:35,000
|
| 27 |
+
A strong focus will be placed on monitoring cloud environments to detect unusual activities, and apply
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:38,000
|
| 31 |
+
necessary updates to keep systems secure.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:38,000 --> 00:00:44,000
|
| 35 |
+
Additionally, we'll discuss the importance of having comprehensive plans in place to recover from potential
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:44,000 --> 00:00:50,000
|
| 39 |
+
disruptions and how to manage relationships with third party providers to ensure they meet security
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:50,000 --> 00:00:51,000
|
| 43 |
+
requirements.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:51,000 --> 00:00:57,000
|
| 47 |
+
We will also cover proactive measures to identify potential vulnerabilities and safeguard cloud services
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:57,000 --> 00:00:59,000
|
| 51 |
+
from emerging threats.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:59,000 --> 00:01:06,000
|
| 55 |
+
Together, these practices form a solid foundation for maintaining a secure and reliable cloud infrastructure.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:07,000 --> 00:01:08,000
|
| 59 |
+
Let's start our lesson.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:09,000 --> 00:01:16,000
|
| 63 |
+
In this lesson, we will explore a comprehensive set of cloud security best practices organized by their
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:16,000 --> 00:01:18,000
|
| 67 |
+
relevance to cloud environments.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:18,000 --> 00:01:25,000
|
| 71 |
+
The first part of the list focuses on high relevance practices that address critical threat mitigation.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:25,000 --> 00:01:31,000
|
| 75 |
+
These include essential measures such as enforcing strict identity and access management to limit who
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:31,000 --> 00:01:38,000
|
| 79 |
+
can access cloud resources, ensuring that encryption is in place to protect sensitive data both in
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:38,000 --> 00:01:44,000
|
| 83 |
+
transit and at rest, and implementing multi-factor authentication to secure user accounts, particularly
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:44,000 --> 00:01:46,000
|
| 87 |
+
those with elevated privileges.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:46,000 --> 00:01:52,000
|
| 91 |
+
Along with these, regular monitoring and auditing of cloud environments is key to detecting any unusual
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:52,000 --> 00:01:53,000
|
| 95 |
+
activity early on.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:54,000 --> 00:02:00,000
|
| 99 |
+
Lastly, applying security patches and utilizing cloud native security services like firewalls and key
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:00,000 --> 00:02:04,000
|
| 103 |
+
management are critical for keeping cloud infrastructure secure.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:04,000 --> 00:02:11,000
|
| 107 |
+
Moving down the list, we find practices categorized by moderate and low relevance, addressing common
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:11,000 --> 00:02:14,000
|
| 111 |
+
security concerns and lesser known threats.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:14,000 --> 00:02:21,000
|
| 115 |
+
These include setting up robust backup and disaster recovery plans, ensuring network segmentation to
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:21,000 --> 00:02:28,000
|
| 119 |
+
isolate sensitive areas of the cloud, and auditing third party service providers to ensure their security
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:28,000 --> 00:02:33,000
|
| 123 |
+
aligns with your own standards for lower relevance threats.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:33,000 --> 00:02:40,000
|
| 127 |
+
The focus shifts to edge cases such as data loss prevention to prevent unauthorized data sharing, conducting
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:40,000 --> 00:02:46,000
|
| 131 |
+
penetration testing to identify vulnerabilities, and following best practices for securing containerized
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:46,000 --> 00:02:48,000
|
| 135 |
+
and serverless environments.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:48,000 --> 00:02:56,000
|
| 139 |
+
By covering all these areas from high priority risks to less common scenarios, we build a well-rounded
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:56,000 --> 00:02:59,000
|
| 143 |
+
approach to maintaining a secure cloud infrastructure.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:00,000 --> 00:03:07,000
|
| 147 |
+
This second list categorizes cloud security best practices based on complexity, helping to structure
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:07,000 --> 00:03:10,000
|
| 151 |
+
the approach to learning them step by step.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:10,000 --> 00:03:17,000
|
| 155 |
+
In the basic category, we cover foundational practices like implementing multi-factor authentication
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:17,000 --> 00:03:24,000
|
| 159 |
+
to protect user accounts, encrypting sensitive data regularly applying security patches, and establishing
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:24,000 --> 00:03:27,000
|
| 163 |
+
backup and disaster recovery plans.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:27,000 --> 00:03:33,000
|
| 167 |
+
Continuous training programs also fall into this category, ensuring that users and administrators stay
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:33,000 --> 00:03:37,000
|
| 171 |
+
aware of potential threats such as phishing and social engineering.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:37,000 --> 00:03:43,000
|
| 175 |
+
These basic measures create a solid foundation of security that every organization should prioritize.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:43,000 --> 00:03:49,000
|
| 179 |
+
As you move to the intermediate and advanced categories, the focus shifts to more complex strategies.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:49,000 --> 00:03:55,000
|
| 183 |
+
Intermediate practices involve strong identity and access management, regular monitoring and auditing,
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:55,000 --> 00:04:01,000
|
| 187 |
+
and leveraging cloud native security services like firewalls and DDoS protection.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:02,000 --> 00:04:09,000
|
| 191 |
+
Advanced practices involve securing API endpoints, implementing data loss prevention solutions, conducting
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:09,000 --> 00:04:13,000
|
| 195 |
+
regular penetration testing, and securing container and serverless environments.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:14,000 --> 00:04:20,000
|
| 199 |
+
This categorization by complexity allows for a gradual, structured approach to mastering cloud security
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:20,000 --> 00:04:21,000
|
| 203 |
+
principles.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:22,000 --> 00:04:27,000
|
| 207 |
+
However, depending on your comfort level or the organization's needs, you may prefer to group these
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:27,000 --> 00:04:33,000
|
| 211 |
+
practices by threat level or frequency of use to accelerate learning and implementation.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:34,000 --> 00:04:38,000
|
| 215 |
+
As I promised, let's provide a detailed overview of each technique.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:39,000 --> 00:04:42,000
|
| 219 |
+
As you saw, there are different ways to group these practices.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:43,000 --> 00:04:48,000
|
| 223 |
+
However, for the sake of this lesson, let's organize all the techniques by relevance and review them
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:48,000 --> 00:04:49,000
|
| 227 |
+
in that order.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:49,000 --> 00:04:54,000
|
| 231 |
+
And in case you have any questions during the lesson, no need to wait till the end of the lesson.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:54,000 --> 00:04:59,000
|
| 235 |
+
Write them in Q and A section below the video and I will be happy to answer.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:00,000 --> 00:05:04,000
|
| 239 |
+
Let's take a deeper dive into each of these cloud security best practices.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:04,000 --> 00:05:10,000
|
| 243 |
+
Exploring why they are so important and how they contribute to securing cloud environments from critical
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:10,000 --> 00:05:11,000
|
| 247 |
+
threats.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:12,000 --> 00:05:17,000
|
| 251 |
+
Starting with identity and access management, this is the backbone of cloud security.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:18,000 --> 00:05:25,000
|
| 255 |
+
By enforcing least privilege only given users and processes access to what they absolutely need, we
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:25,000 --> 00:05:28,000
|
| 259 |
+
reduce the likelihood of unauthorized access.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:28,000 --> 00:05:33,000
|
| 263 |
+
For instance, if a user's credentials are compromised, limiting their permissions ensures that the
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:33,000 --> 00:05:37,000
|
| 267 |
+
attacker can't move freely across your cloud infrastructure.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:37,000 --> 00:05:43,000
|
| 271 |
+
Role based access control plays a crucial part here, ensuring that each role has predefined permissions
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:43,000 --> 00:05:45,000
|
| 275 |
+
that align with their tasks.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:45,000 --> 00:05:51,000
|
| 279 |
+
This not only mitigates the risk of insider threats, but also restricts external attacks, making it
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:51,000 --> 00:05:55,000
|
| 283 |
+
harder for intruders to access sensitive resources.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:56,000 --> 00:05:59,000
|
| 287 |
+
Next we have data encryption, a cornerstone of cloud security.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:59,000 --> 00:06:07,000
|
| 291 |
+
Encrypting data, both in transit and at rest protects information from being accessed or tampered with
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:07,000 --> 00:06:09,000
|
| 295 |
+
by unauthorized individuals.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:10,000 --> 00:06:16,000
|
| 299 |
+
Whether data is moving between your cloud storage and users, or simply being stored in a database.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:16,000 --> 00:06:23,000
|
| 303 |
+
Encryption ensures that it is unreadable to anyone who doesn't possess the decryption keys.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:23,000 --> 00:06:29,000
|
| 307 |
+
This practice is critical because even if attackers manage to intercept data, they cannot decipher
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:29,000 --> 00:06:34,000
|
| 311 |
+
it without the encryption key, significantly reducing the risk of data breaches.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:35,000 --> 00:06:40,000
|
| 315 |
+
Now let's consider the importance of monitoring and auditing cloud environments.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:40,000 --> 00:06:47,000
|
| 319 |
+
In the dynamic world of cloud computing, environments are constantly changing, making continuous monitoring
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:47,000 --> 00:06:48,000
|
| 323 |
+
essential.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:49,000 --> 00:06:57,000
|
| 327 |
+
By tracking user activity, access patterns and any unusual behavior you can detect and respond to potential
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:57,000 --> 00:07:00,000
|
| 331 |
+
security incidents much faster.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:01,000 --> 00:07:08,000
|
| 335 |
+
Real time monitoring helps catch potential breaches early, while regular auditing ensures that policies
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:08,000 --> 00:07:13,000
|
| 339 |
+
are being followed and that there are no hidden vulnerabilities in your system.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:14,000 --> 00:07:20,000
|
| 343 |
+
This visibility into your cloud infrastructure is key for proactive security management, allowing you
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:20,000 --> 00:07:25,000
|
| 347 |
+
to make informed decisions and take corrective action before issues escalate.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:26,000 --> 00:07:32,000
|
| 351 |
+
The next practice, multi-factor authentication, adds another critical layer of protection.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:33,000 --> 00:07:39,000
|
| 355 |
+
Even if an attacker manages to steal a user's password, multi-factor authentication requires an additional
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:39,000 --> 00:07:46,000
|
| 359 |
+
form of verification, such as a code sent to the mobile device or biometric authentication.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:47,000 --> 00:07:54,000
|
| 363 |
+
This means that a password alone isn't enough to access sensitive cloud resources, drastically reducing
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:54,000 --> 00:07:59,000
|
| 367 |
+
the risk of account compromise, especially for privileged accounts.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:59,000 --> 00:08:05,000
|
| 371 |
+
Multi-factor authentication is particularly vital in cloud environments where access can be made from
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:05,000 --> 00:08:09,000
|
| 375 |
+
anywhere, making it an essential defence against credential based attacks.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:10,000 --> 00:08:14,000
|
| 379 |
+
Another key component is the application of security patches and updates.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:15,000 --> 00:08:20,000
|
| 383 |
+
Cloud infrastructure, like any other software, is vulnerable to security flaws that are regularly
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:20,000 --> 00:08:23,000
|
| 387 |
+
discovered and patched by vendors.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:23,000 --> 00:08:30,000
|
| 391 |
+
Delaying these updates leaves your systems exposed to known vulnerabilities that attackers can easily
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:30,000 --> 00:08:31,000
|
| 395 |
+
exploit.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:31,000 --> 00:08:37,000
|
| 399 |
+
Automating the patching process or setting up regular maintenance windows ensures that your cloud environment
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:37,000 --> 00:08:44,000
|
| 403 |
+
remains protected against the latest threats, which is crucial for staying ahead of potential exploits.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:45,000 --> 00:08:49,000
|
| 407 |
+
Finally, we have the use of cloud native security services.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:49,000 --> 00:08:56,000
|
| 411 |
+
Most cloud providers offer Of powerful built in security features like firewalls, DDoS protection,
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:56,000 --> 00:08:58,000
|
| 415 |
+
and key management services.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:59,000 --> 00:09:06,000
|
| 419 |
+
These services are designed to integrate seamlessly with cloud infrastructures and offer scalable protection
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:09:06,000 --> 00:09:08,000
|
| 423 |
+
that is tailored to cloud environments.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:09,000 --> 00:09:15,000
|
| 427 |
+
For example, using a cloud provider's DDoS protection service helps mitigate large scale attacks that
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:15,000 --> 00:09:17,000
|
| 431 |
+
could overwhelm your systems.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:17,000 --> 00:09:23,000
|
| 435 |
+
While key management services ensure your encryption keys are stored and handled securely.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:24,000 --> 00:09:30,000
|
| 439 |
+
Leveraging these native tools means you are taking advantage of the security capabilities specifically
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:30,000 --> 00:09:36,000
|
| 443 |
+
designed for the cloud, ensuring a stronger, more secure environment.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:37,000 --> 00:09:45,000
|
| 447 |
+
Let's explore this moderate relevance cloud security practices in greater detail, as they play a critical
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:45,000 --> 00:09:51,000
|
| 451 |
+
role in addressing common security concerns and strengthening the overall security of cloud environments.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:52,000 --> 00:09:58,000
|
| 455 |
+
First, establishing strong backup and disaster recovery plans is essential for safeguarding critical,
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:58,000 --> 00:10:02,000
|
| 459 |
+
cloud based data and applications in the cloud.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:10:02,000 --> 00:10:08,000
|
| 463 |
+
System failures, cyber attacks or natural disasters can lead to data loss.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:10:08,000 --> 00:10:14,000
|
| 467 |
+
Making reliable backup strategies crucial for recovery by implementing automated backups and ensuring
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:14,000 --> 00:10:18,000
|
| 471 |
+
they are regularly scheduled, you maintain current copies of important data.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:18,000 --> 00:10:21,000
|
| 475 |
+
But it's not just about having backups.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:21,000 --> 00:10:26,000
|
| 479 |
+
Testing restore processes regularly ensures that you can recover quickly and effectively when needed.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:27,000 --> 00:10:33,000
|
| 483 |
+
A robust disaster recovery plan, thoroughly documented, outlines clear steps for restoring operations,
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:33,000 --> 00:10:36,000
|
| 487 |
+
reducing downtime, and minimizing damage during an incident.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:36,000 --> 00:10:44,000
|
| 491 |
+
Without these precautions, a failure or attack could cause significant data loss and prolonged downtime.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:44,000 --> 00:10:51,000
|
| 495 |
+
Next, we have network segmentation within cloud environments, which is vital for isolating sensitive
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:51,000 --> 00:10:52,000
|
| 499 |
+
resources.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:53,000 --> 00:10:59,000
|
| 503 |
+
Segmentation helps to divide the cloud network into distinct zones with strict access controls between
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:59,000 --> 00:11:00,000
|
| 507 |
+
them.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:11:01,000 --> 00:11:07,000
|
| 511 |
+
This way, even if an attacker gains access to one part of the system, they can't easily move laterally
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:11:07,000 --> 00:11:10,000
|
| 515 |
+
to access more sensitive data or services.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:11:11,000 --> 00:11:17,000
|
| 519 |
+
Think of network segmentation as creating digital barriers between different parts of your infrastructure.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:11:18,000 --> 00:11:24,000
|
| 523 |
+
Tools like virtual private clouds, subnets, and security groups are commonly used for this.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:25,000 --> 00:11:31,000
|
| 527 |
+
By isolating critical resources, you limit the scope of an attack and prevent unnecessary exposure,
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:31,000 --> 00:11:34,000
|
| 531 |
+
enhancing the overall security of your cloud environment.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:36,000 --> 00:11:42,000
|
| 535 |
+
Another important practice is the regular review and audit of third party cloud service providers.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:42,000 --> 00:11:49,000
|
| 539 |
+
Many organizations rely on external cloud providers to manage part of their Infrastructure, which introduces
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:49,000 --> 00:11:51,000
|
| 543 |
+
additional security risks.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:51,000 --> 00:11:58,000
|
| 547 |
+
If your provider has weak security practices, it could expose your data or systems to threats.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:59,000 --> 00:12:04,000
|
| 551 |
+
That's why it's essential to perform due diligence and regularly audit your provider's security posture,
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:12:05,000 --> 00:12:11,000
|
| 555 |
+
checking their certifications such as ISO or SOC, and ensuring they meet industry standards helps you
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:12:11,000 --> 00:12:14,000
|
| 559 |
+
maintain confidence in their security capabilities.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:12:14,000 --> 00:12:20,000
|
| 563 |
+
Without regular reviews, you risk relying on a provider with outdated or insufficient security measures,
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:12:20,000 --> 00:12:23,000
|
| 567 |
+
which can create vulnerabilities in your own infrastructure.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:24,000 --> 00:12:28,000
|
| 571 |
+
Finally, let's talk about monitoring and securing API endpoints.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:29,000 --> 00:12:35,000
|
| 575 |
+
API serves as the communication channel between different parts of your cloud infrastructure or between
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:12:35,000 --> 00:12:40,000
|
| 579 |
+
services, making them prime targets for attackers if not properly secured.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:40,000 --> 00:12:46,000
|
| 583 |
+
APIs can be abused to gain unauthorized access to data or manipulate services.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:46,000 --> 00:12:53,000
|
| 587 |
+
To prevent this, strong authentication measures like API keys or auth and encrypted communication must
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:53,000 --> 00:12:54,000
|
| 591 |
+
be implemented.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:54,000 --> 00:12:59,000
|
| 595 |
+
Additionally, monitoring API traffic for abnormal activity.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:59,000 --> 00:13:07,000
|
| 599 |
+
Applying rate limits and logging all API interactions help detect and respond to potential threats early.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:07,000 --> 00:13:14,000
|
| 603 |
+
By securing these endpoints, you ensure that only authorized entities interact with your systems,
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:14,000 --> 00:13:16,000
|
| 607 |
+
reducing the risk of data leakage or abuse.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:18,000 --> 00:13:24,000
|
| 611 |
+
Let's take a deeper dive into each of these low relevance cloud security practices, which, although
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:24,000 --> 00:13:31,000
|
| 615 |
+
they may seem less urgent, are critical for addressing specific threats and filling gaps in your cloud
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:31,000 --> 00:13:32,000
|
| 619 |
+
security strategy.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:33,000 --> 00:13:39,000
|
| 623 |
+
First, consider data loss prevention, which is essential for safeguarding sensitive information.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:40,000 --> 00:13:46,000
|
| 627 |
+
Cloud environments often host a wide range of data from personal, identifiable Quantifiable information
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:46,000 --> 00:13:52,000
|
| 631 |
+
to financial records, and without the right controls, this data could be accidentally or maliciously
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:52,000 --> 00:13:54,000
|
| 635 |
+
shared with unauthorized parties.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:54,000 --> 00:14:00,000
|
| 639 |
+
By implementing data loss prevention solutions, you can monitor data transfers and block any attempt
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:14:00,000 --> 00:14:04,000
|
| 643 |
+
to share confidential information through unauthorized channels.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:04,000 --> 00:14:10,000
|
| 647 |
+
Data loss prevention policies work by identifying sensitive data and applying rules to prevent it from
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:14:10,000 --> 00:14:13,000
|
| 651 |
+
leaving the organization without proper authorization.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:14:13,000 --> 00:14:19,000
|
| 655 |
+
This is particularly important in industries with strict regulatory requirements, such as healthcare
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:14:19,000 --> 00:14:26,000
|
| 659 |
+
or finance, where the exposure of sensitive data can result in heavy fines and reputational damage.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:27,000 --> 00:14:33,000
|
| 663 |
+
Next is the importance of regular penetration testing, while having strong security configurations
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:33,000 --> 00:14:35,000
|
| 667 |
+
in place is necessary.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:35,000 --> 00:14:39,000
|
| 671 |
+
Testing those configurations through simulated attacks is critical.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:40,000 --> 00:14:46,000
|
| 675 |
+
Penetration testing mimics real world attack scenarios, allowing you to identify vulnerabilities that
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:46,000 --> 00:14:49,000
|
| 679 |
+
might otherwise go unnoticed.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:49,000 --> 00:14:55,000
|
| 683 |
+
These tests provide valuable feedback on potential weak points in your cloud infrastructure, and allow
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:55,000 --> 00:14:59,000
|
| 687 |
+
you to patch vulnerabilities before attackers can exploit them.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:59,000 --> 00:15:05,000
|
| 691 |
+
By performing regular penetration testing, either through automated tools or by hiring third party
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:15:05,000 --> 00:15:12,000
|
| 695 |
+
firms, you ensure that your security defenses are always up to date and capable of withstanding evolving
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:12,000 --> 00:15:13,000
|
| 699 |
+
threats.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:15,000 --> 00:15:20,000
|
| 703 |
+
Then we have container and serverless security best practices, which are becoming increasingly important
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:20,000 --> 00:15:25,000
|
| 707 |
+
as microservices architectures are widely adopted in cloud environments.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:25,000 --> 00:15:32,000
|
| 711 |
+
Containers and serverless computing offer great flexibility, but they also introduce new security risks.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:33,000 --> 00:15:40,000
|
| 715 |
+
Without proper security controls, attackers could compromise insecure container images or exploit vulnerabilities
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:40,000 --> 00:15:45,000
|
| 719 |
+
in serverless functions, which could lead to unauthorized access or data leakage.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:46,000 --> 00:15:50,000
|
| 723 |
+
To mitigate these risks, it's important to use secure, verified images.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:50,000 --> 00:15:56,000
|
| 727 |
+
Apply the principle of least privilege to container permissions and ensure that workloads are isolated
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:56,000 --> 00:15:57,000
|
| 731 |
+
from one another.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:57,000 --> 00:16:02,000
|
| 735 |
+
This approach minimizes the blast radius if one component is compromised, preventing the attack from
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:16:02,000 --> 00:16:04,000
|
| 739 |
+
spreading across the system.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:16:05,000 --> 00:16:09,000
|
| 743 |
+
The next crucial practice is cloud user training and awareness programs.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:09,000 --> 00:16:16,000
|
| 747 |
+
Even with the most sophisticated security controls in place, human error remains one of the top causes
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:16,000 --> 00:16:17,000
|
| 751 |
+
of security breaches.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:17,000 --> 00:16:24,000
|
| 755 |
+
Social engineering attacks, particularly phishing, target cloud users and administrators directly
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:24,000 --> 00:16:31,000
|
| 759 |
+
attempting to trick them into divulging credentials or clicking on malicious links by providing regular
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:31,000 --> 00:16:33,000
|
| 763 |
+
training and awareness programs.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:33,000 --> 00:16:40,000
|
| 767 |
+
Organizations can educate their employees about the latest phishing tactics and social engineering risks,
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:40,000 --> 00:16:44,000
|
| 771 |
+
empowering them to recognize and report suspicious activities.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:44,000 --> 00:16:51,000
|
| 775 |
+
Continuous training also reinforces the importance of following security best practices, ensuring that
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:16:51,000 --> 00:16:55,000
|
| 779 |
+
users stay vigilant and act as an additional layer of defence.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:56,000 --> 00:17:00,000
|
| 783 |
+
Finally, we have regular reviews of cloud service level agreements.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:17:01,000 --> 00:17:06,000
|
| 787 |
+
Service level agreements are formal contracts between an organisation and its cloud service provider,
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:17:06,000 --> 00:17:11,000
|
| 791 |
+
outlining the security, privacy and availability standards that must be maintained.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:12,000 --> 00:17:18,000
|
| 795 |
+
Regularly reviewing these agreements is important to ensure that your provider is meeting their obligations,
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:18,000 --> 00:17:21,000
|
| 799 |
+
especially as security needs evolve over time.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:22,000 --> 00:17:28,000
|
| 803 |
+
For example, if new compliance regulations are introduced or if there are changes in your operational
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:28,000 --> 00:17:35,000
|
| 807 |
+
requirements, you need to verify that your provider is still aligned with your security and privacy
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:35,000 --> 00:17:35,000
|
| 811 |
+
needs.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:36,000 --> 00:17:42,000
|
| 815 |
+
This proactive approach ensures that your provider continues to meet agreed upon standards and helps
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:17:42,000 --> 00:17:45,000
|
| 819 |
+
avoid gaps in your overall security posture.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:17:47,000 --> 00:17:53,000
|
| 823 |
+
Let's summarize and conclude the cloud security best practices structured by their relevance to security
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:17:53,000 --> 00:17:55,000
|
| 827 |
+
and threat mitigation.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:17:56,000 --> 00:17:58,000
|
| 831 |
+
Starting with the high relevance practices.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:58,000 --> 00:18:05,000
|
| 835 |
+
These focus on critical threat mitigation, which are essential for maintaining the core security of
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:05,000 --> 00:18:06,000
|
| 839 |
+
cloud environments.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:06,000 --> 00:18:13,000
|
| 843 |
+
We learned that identity and access management is vital in ensuring that users and processes have the
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:13,000 --> 00:18:16,000
|
| 847 |
+
least privilege necessary, reducing the risk of unauthorized access.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:17,000 --> 00:18:23,000
|
| 851 |
+
Similarly, encryption of data, both in transit and at rest is essential to protect sensitive information
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:23,000 --> 00:18:25,000
|
| 855 |
+
from being exposed or intercepted.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:25,000 --> 00:18:31,000
|
| 859 |
+
Regular monitoring and auditing play a crucial role in detecting unusual activity, allowing you to
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:18:31,000 --> 00:18:33,000
|
| 863 |
+
respond quickly to potential security incidents.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:18:34,000 --> 00:18:40,000
|
| 867 |
+
Moreover, multi-factor authentication strengthens account security, especially for privileged users,
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:18:40,000 --> 00:18:45,000
|
| 871 |
+
making it significantly harder for attackers to gain unauthorized access.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:18:45,000 --> 00:18:51,000
|
| 875 |
+
Keeping cloud infrastructure updated with the latest security patches prevents attackers from exploiting
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:18:51,000 --> 00:18:53,000
|
| 879 |
+
known vulnerabilities.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:18:53,000 --> 00:19:01,000
|
| 883 |
+
Finally, using cloud provider native security services like firewalls, DDoS protection and key management
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:19:01,000 --> 00:19:07,000
|
| 887 |
+
adds an extra layer of security that is specifically tailored for cloud environments, ensuring they
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:19:07,000 --> 00:19:10,000
|
| 891 |
+
remain robust against various threats.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:19:11,000 --> 00:19:13,000
|
| 895 |
+
Moving on to the moderate relevance practices.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:19:13,000 --> 00:19:16,000
|
| 899 |
+
These address common security concerns.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:19:17,000 --> 00:19:24,000
|
| 903 |
+
Having strong backup and disaster recovery plans ensures that even in the event of a failure or attack,
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:24,000 --> 00:19:30,000
|
| 907 |
+
critical data can be restored, minimizing downtime and preventing data loss.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:31,000 --> 00:19:37,000
|
| 911 |
+
Network segmentation is another important practice, helping to isolate sensitive resources and prevent
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:19:37,000 --> 00:19:40,000
|
| 915 |
+
attackers from moving laterally across your cloud environment.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:19:41,000 --> 00:19:48,000
|
| 919 |
+
Regular review and auditing of third party providers ensures that the security of external services
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:19:48,000 --> 00:19:54,000
|
| 923 |
+
is aligned with your internal standards, reducing the risk of vulnerabilities in the supply chain.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:19:54,000 --> 00:20:02,000
|
| 927 |
+
Additionally, securing API endpoints is vital as these can serve as potential entry points for attackers
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:20:02,000 --> 00:20:04,000
|
| 931 |
+
if not properly protected.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:20:04,000 --> 00:20:09,000
|
| 935 |
+
APIs must be continuously monitored to prevent unauthorized access and abuse.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:20:10,000 --> 00:20:17,000
|
| 939 |
+
Lastly, we covered the low relevance practices which focus on edge cases and lesser known threats.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:20:17,000 --> 00:20:23,000
|
| 943 |
+
These practices include the implementation of data loss prevention solutions, which help prevent the
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:20:23,000 --> 00:20:26,000
|
| 947 |
+
unauthorized sharing of sensitive information.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:20:26,000 --> 00:20:28,000
|
| 951 |
+
Adding an extra layer of control.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:20:29,000 --> 00:20:36,000
|
| 955 |
+
Regular penetration testing allows organizations to identify vulnerabilities before attackers can exploit
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:20:36,000 --> 00:20:38,000
|
| 959 |
+
them, ensuring proactive defense Fans.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:20:38,000 --> 00:20:45,000
|
| 963 |
+
Container and serverless security measures are increasingly important as microservices become more common
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:20:45,000 --> 00:20:51,000
|
| 967 |
+
in cloud architectures, with the need for secure management of these technologies, continuous training
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:20:51,000 --> 00:20:57,000
|
| 971 |
+
and awareness programs ensure that cloud users and administrators remain vigilant, particularly against
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:20:57,000 --> 00:21:00,000
|
| 975 |
+
phishing and social engineering attacks.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:21:00,000 --> 00:21:06,000
|
| 979 |
+
Finally, regular review of service level agreements with cloud providers ensures that security and
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:21:06,000 --> 00:21:11,000
|
| 983 |
+
privacy standards are met over time as operational needs evolve.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:21:13,000 --> 00:21:15,000
|
| 987 |
+
That's all what I wanted to discuss with you in the lesson.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:21:15,000 --> 00:21:18,000
|
| 991 |
+
Let's recap what we have learned from the lesson.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:21:19,000 --> 00:21:26,000
|
| 995 |
+
We learned how to implement strong identity and access management controls, and enforce least privilege
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:21:26,000 --> 00:21:28,000
|
| 999 |
+
to limit access to cloud resources.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:21:29,000 --> 00:21:37,000
|
| 1003 |
+
You now understand the importance of encrypting sensitive data both in transit and at rest, using industry
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:21:37,000 --> 00:21:39,000
|
| 1007 |
+
standard encryption protocols.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:21:40,000 --> 00:21:46,000
|
| 1011 |
+
We explored the need for regular monitoring and auditing of cloud environments to detect unusual activity
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:21:46,000 --> 00:21:48,000
|
| 1015 |
+
and prevent security incidents.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:21:48,000 --> 00:21:54,000
|
| 1019 |
+
Together, we implemented multi-factor authentication for user accounts, especially for privileged
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:21:54,000 --> 00:21:57,000
|
| 1023 |
+
users, to strengthen access controls.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:21:57,000 --> 00:22:03,000
|
| 1027 |
+
We reviewed the process of applying security patches and updates to cloud infrastructure, ensuring
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:22:03,000 --> 00:22:06,000
|
| 1031 |
+
systems remain protected against vulnerabilities.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:22:07,000 --> 00:22:14,000
|
| 1035 |
+
I demonstrated how to use cloud provider native security services, such as firewalls and key management
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:22:14,000 --> 00:22:16,000
|
| 1039 |
+
to enhance cloud security.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:22:17,000 --> 00:22:23,000
|
| 1043 |
+
Finally, we covered best practices for reviewing and managing backup and disaster recovery plans,
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:22:23,000 --> 00:22:27,000
|
| 1047 |
+
third party audits, and securing API endpoints.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:22:28,000 --> 00:22:30,000
|
| 1051 |
+
That's all for this lesson.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:22:30,000 --> 00:22:32,000
|
| 1055 |
+
Thanks a lot for your attention.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:22:32,000 --> 00:22:35,000
|
| 1059 |
+
Have a great day and see you in the next lesson.
|
| 1060 |
+
|
76 - Cybersecurity Comprehensive Security Practices for Developers/013 Mobile Application Security_en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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:07,000
|
| 3 |
+
Hello dear team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:07,000 --> 00:00:12,000
|
| 7 |
+
In this lesson we will focus on the key principles of mobile application security, highlighting essential
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:12,000 --> 00:00:17,000
|
| 11 |
+
practices to protect user data and maintain the integrity of your applications.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:18,000 --> 00:00:25,000
|
| 15 |
+
The overall goal is to ensure that sensitive information is safeguarded while preventing unauthorized
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:25,000 --> 00:00:26,000
|
| 19 |
+
access to the app.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:27,000 --> 00:00:34,000
|
| 23 |
+
Strong security measures are required to maintain user trust and to ensure compliance with privacy regulations.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:35,000 --> 00:00:41,000
|
| 27 |
+
Additionally, protecting data during both its transmission and storage is fundamental to keeping it
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:41,000 --> 00:00:43,000
|
| 31 |
+
safe from potential attackers.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:43,000 --> 00:00:48,000
|
| 35 |
+
We will also cover important strategies for securing how your app interacts with external systems,
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:48,000 --> 00:00:52,000
|
| 39 |
+
ensuring that connections are protected and that vulnerabilities are minimized.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:53,000 --> 00:00:59,000
|
| 43 |
+
Another critical aspect of mobile app security is the ability to detect and respond to threats in real
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:59,000 --> 00:01:03,000
|
| 47 |
+
time, as well as keeping the app up to date to address evolving risks.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:04,000 --> 00:01:10,000
|
| 51 |
+
Together, these approaches will help you build a robust security framework that mitigates risks and
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:10,000 --> 00:01:14,000
|
| 55 |
+
helps your mobile app operate securely in a dynamic environment.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:14,000 --> 00:01:16,000
|
| 59 |
+
Let's start our lesson.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:17,000 --> 00:01:23,000
|
| 63 |
+
In this lesson, we'll be exploring mobile application security best practices organized by their relevance
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:23,000 --> 00:01:25,000
|
| 67 |
+
to the most critical threats.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:26,000 --> 00:01:33,000
|
| 71 |
+
The high relevance items focus on the most essential defenses, such as implementing strong authentication
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:33,000 --> 00:01:36,000
|
| 75 |
+
mechanisms and encrypting sensitive data.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:37,000 --> 00:01:44,000
|
| 79 |
+
These practices form the foundation of mobile app security by ensuring that only authorized users can
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:44,000 --> 00:01:51,000
|
| 83 |
+
access sensitive information, and the data remains secure, both while being transmitted and stored.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:51,000 --> 00:01:56,000
|
| 87 |
+
Regular updates and secure storage of credentials are also crucial to prevent vulnerabilities that could
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:56,000 --> 00:01:58,000
|
| 91 |
+
be exploited by attackers.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:59,000 --> 00:02:04,000
|
| 95 |
+
As we delve into the moderate and low relevance practices, we'll look at strategies like secure coding,
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:04,000 --> 00:02:10,000
|
| 99 |
+
ensuring safe communication between the app and backend services, and preventing reverse engineering
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:10,000 --> 00:02:11,000
|
| 103 |
+
through code obfuscation.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:11,000 --> 00:02:18,000
|
| 107 |
+
We will also touch on lesser known threats such as controlling app permissions, detecting tampered
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:18,000 --> 00:02:21,000
|
| 111 |
+
devices, and monitoring for suspicious activity.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:21,000 --> 00:02:27,000
|
| 115 |
+
These practices may not be as critical as the high relevance items, but they still play an important
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:27,000 --> 00:02:32,000
|
| 119 |
+
role in hardening the app against a broader range of potential attacks.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:32,000 --> 00:02:38,000
|
| 123 |
+
We'll be going over each of these in more detail to understand how they contribute to a comprehensive
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:38,000 --> 00:02:39,000
|
| 127 |
+
mobile security strategy.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:40,000 --> 00:02:48,000
|
| 131 |
+
This list categorizes mobile application security best practices by complexity, offering a way to progressively
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:48,000 --> 00:02:52,000
|
| 135 |
+
build your understanding from beginner to advanced techniques.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:52,000 --> 00:02:59,000
|
| 139 |
+
At the basic level, we start with essential practices like applying security updates, Encrypting sensitive
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:59,000 --> 00:03:02,000
|
| 143 |
+
data and securely storing credentials.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:02,000 --> 00:03:09,000
|
| 147 |
+
These are foundational steps that every mobile app should implement to prevent obvious security vulnerabilities.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:09,000 --> 00:03:16,000
|
| 151 |
+
Additionally, implementing strong authentication mechanisms and adhering to privacy regulations ensures
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:16,000 --> 00:03:19,000
|
| 155 |
+
that user data is protected from unauthorized access.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:20,000 --> 00:03:26,000
|
| 159 |
+
As you move to the intermediate and advanced levels, more sophisticated practices come into play.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:26,000 --> 00:03:34,000
|
| 163 |
+
For instance, secure coding and API validation help protect the back end from attacks like SQL injection,
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:34,000 --> 00:03:41,000
|
| 167 |
+
while advanced techniques like tamper detection and real time monitoring defend against threats in dynamic
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:41,000 --> 00:03:42,000
|
| 171 |
+
environments.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:42,000 --> 00:03:47,000
|
| 175 |
+
This layered approach allows for flexibility in how you prioritize your learning, depending on the
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:47,000 --> 00:03:51,000
|
| 179 |
+
specific challenges or risks faced by your mobile application.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:51,000 --> 00:03:57,000
|
| 183 |
+
You can also use different categorization techniques, such as relevance or risk, to help you focus
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:57,000 --> 00:04:02,000
|
| 187 |
+
on the principles that are most applicable to your project or threat landscape.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:03,000 --> 00:04:07,000
|
| 191 |
+
As I promised, let's provide a detailed overview of each technique.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:07,000 --> 00:04:11,000
|
| 195 |
+
As you saw, there are different ways to group these practices.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:11,000 --> 00:04:16,000
|
| 199 |
+
However, for the sake of this lesson, let's organize all the techniques by relevance and review them
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:16,000 --> 00:04:17,000
|
| 203 |
+
in that order.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:18,000 --> 00:04:23,000
|
| 207 |
+
And in case you have any questions during the lesson, no need to wait till the end of the lesson.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:23,000 --> 00:04:27,000
|
| 211 |
+
Write them in the Q&A section below the video and I will be happy to answer.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:29,000 --> 00:04:35,000
|
| 215 |
+
Let's dive deeper into this high relevance mobile application security practices to better understand
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:35,000 --> 00:04:42,000
|
| 219 |
+
their significance and how they contribute to a secure and well-rounded strategy for mobile applications.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:42,000 --> 00:04:47,000
|
| 223 |
+
First, consider authentication and authorization mechanisms.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:47,000 --> 00:04:54,000
|
| 227 |
+
It's not enough to rely on just usernames and passwords anymore, as these can be easily compromised.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:54,000 --> 00:05:01,000
|
| 231 |
+
Instead, by implementing Multi-factor authentication, we add another layer of protection, for example,
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:01,000 --> 00:05:07,000
|
| 235 |
+
requiring users to input a password and then a code sent to their phone ensures that even if a password
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:07,000 --> 00:05:11,000
|
| 239 |
+
is stolen, access can't be gained without the second factor.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:11,000 --> 00:05:14,000
|
| 243 |
+
This significantly reduces the risk of unauthorised access.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:14,000 --> 00:05:20,000
|
| 247 |
+
On the flip side, relying solely on passwords without any additional verification leaves the app vulnerable
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:20,000 --> 00:05:24,000
|
| 251 |
+
to brute force attacks, phishing or credential theft.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:24,000 --> 00:05:31,000
|
| 255 |
+
Making multi-factor authentication essential for modern mobile security, secure token management is
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:31,000 --> 00:05:39,000
|
| 259 |
+
equally important, ensuring that tokens used for session authentication are securely stored and rotated
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:39,000 --> 00:05:43,000
|
| 263 |
+
regularly so they aren't exposed or reused by attackers.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:44,000 --> 00:05:48,000
|
| 267 |
+
Now let's talk about encryption of sensitive data.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:48,000 --> 00:05:56,000
|
| 271 |
+
Encryption ensures that data is scrambled into an unreadable format that can only be decrypted with
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:56,000 --> 00:06:01,000
|
| 275 |
+
a key, making it crucial for both data in transit and data at rest.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:02,000 --> 00:06:07,000
|
| 279 |
+
For example, when a user's banking information is transmitted from their phone to a server.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:07,000 --> 00:06:14,000
|
| 283 |
+
Using encryption protocols ensures that even if the data is intercepted, it remains unreadable.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:14,000 --> 00:06:16,000
|
| 287 |
+
To the attacker.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:16,000 --> 00:06:22,000
|
| 291 |
+
Similarly, storing sensitive information like credit card numbers or personal details on the device
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:22,000 --> 00:06:27,000
|
| 295 |
+
without encryption could lead to devastating consequences if the device is compromised.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:28,000 --> 00:06:34,000
|
| 299 |
+
Encrypting this data prevents unauthorized access and ensures that sensitive information stays secure,
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:34,000 --> 00:06:37,000
|
| 303 |
+
even if it falls into the wrong hands.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:38,000 --> 00:06:41,000
|
| 307 |
+
Another key practice is regular security updates.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:41,000 --> 00:06:47,000
|
| 311 |
+
In today's fast moving threat landscape, security vulnerabilities are discovered frequently, and failing
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:47,000 --> 00:06:51,000
|
| 315 |
+
to apply patches can expose apps to well known exploits.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:51,000 --> 00:06:57,000
|
| 319 |
+
Hackers often target apps that aren't updated because these are easy to exploit.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:57,000 --> 00:07:03,000
|
| 323 |
+
For instance, a developer who pushes regular updates and patches as soon as new vulnerabilities are
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:03,000 --> 00:07:09,000
|
| 327 |
+
identified ensures that the app remains secure and up to date with the latest defenses.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:10,000 --> 00:07:15,000
|
| 331 |
+
On the other hand, neglecting updates leaves the app wide open to exploitation by attackers who know
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:15,000 --> 00:07:17,000
|
| 335 |
+
how to take advantage of outdated systems.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:18,000 --> 00:07:24,000
|
| 339 |
+
Next, consider the protection of sensitive user data with increasing regulations such as GDPR and CcpA.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:24,000 --> 00:07:27,000
|
| 343 |
+
It's no longer just about protecting user data.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:28,000 --> 00:07:33,000
|
| 347 |
+
It's about doing so in a way that complies with privacy laws.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:33,000 --> 00:07:39,000
|
| 351 |
+
This means minimizing the amount of data you collect and storing it securely, and being transparent
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:39,000 --> 00:07:42,000
|
| 355 |
+
with users about how their data is being used.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:43,000 --> 00:07:50,000
|
| 359 |
+
For example, an app that collects only the necessary data for functionality and provides users with
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:50,000 --> 00:07:55,000
|
| 363 |
+
clear privacy notices, builds trust and complies with legal standards.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:56,000 --> 00:08:03,000
|
| 367 |
+
On the other hand, apps that collect excessive amounts of data or fail to inform users of their privacy
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:03,000 --> 00:08:08,000
|
| 371 |
+
practices risk both user distrust and legal consequences.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:09,000 --> 00:08:13,000
|
| 375 |
+
Lastly, we must address secure storage of sensitive information.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:13,000 --> 00:08:20,000
|
| 379 |
+
Mobile apps often deal with credentials, passwords, and session tokens that need to be stored securely
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:21,000 --> 00:08:30,000
|
| 383 |
+
using device native secure storage mechanisms like keychain on iOS or Keystore on Android provides an
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:30,000 --> 00:08:33,000
|
| 387 |
+
encrypted and protected environment for the sensitive data.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:34,000 --> 00:08:41,000
|
| 391 |
+
Storing these elements in easily accessible areas like local storage, would leave them vulnerable to
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:41,000 --> 00:08:43,000
|
| 395 |
+
attackers if the device is compromised.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:44,000 --> 00:08:51,000
|
| 399 |
+
By storing this data in a secure and encrypted format, you greatly reduce the risk of it being exposed
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:51,000 --> 00:08:53,000
|
| 403 |
+
in the event of a device breach.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:55,000 --> 00:09:01,000
|
| 407 |
+
Let's take a deeper look at each of the moderate relevance mobile application security practices.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:09:01,000 --> 00:09:07,000
|
| 411 |
+
Elaborating on how they enhance the security of mobile applications and why they are important in real
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:09:07,000 --> 00:09:08,000
|
| 415 |
+
world scenarios.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:09:09,000 --> 00:09:15,000
|
| 419 |
+
We start with secure coding practices, which are foundational to preventing some of the most common
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:09:15,000 --> 00:09:20,000
|
| 423 |
+
and dangerous vulnerabilities like SQL injection and cross-site scripting.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:21,000 --> 00:09:26,000
|
| 427 |
+
Secure coding ensures that the app's code does not leave gaps that attackers can exploit.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:27,000 --> 00:09:32,000
|
| 431 |
+
For example, SQL injection occurs when malicious input is used to manipulate a database query, potentially
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:32,000 --> 00:09:35,000
|
| 435 |
+
allowing an attacker to access sensitive data.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:35,000 --> 00:09:40,000
|
| 439 |
+
By adopting secure coding practices such as parameterized queries, developers can safeguard against
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:40,000 --> 00:09:42,000
|
| 443 |
+
this kind of attack.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:42,000 --> 00:09:48,000
|
| 447 |
+
Likewise, buffer overflows where excess data overruns a buffer's boundaries, can allow attackers to
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:48,000 --> 00:09:56,000
|
| 451 |
+
inject malicious code into an application properly validating input sizes and bounds in your code ensures
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:56,000 --> 00:09:59,000
|
| 455 |
+
that your application doesn't become vulnerable to this.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:59,000 --> 00:10:06,000
|
| 459 |
+
It's not just about writing functional code, it's about writing hardened code that anticipates potential
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:10:06,000 --> 00:10:08,000
|
| 463 |
+
attack vectors.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:10:08,000 --> 00:10:15,000
|
| 467 |
+
Next, we delve into secure communication between the mobile app and back end services.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:15,000 --> 00:10:21,000
|
| 471 |
+
Whenever data is exchanged between the app and the server, whether it's user credentials, financial
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:21,000 --> 00:10:27,000
|
| 475 |
+
information, or any other sensitive data, it must be securely transmitted to prevent interception.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:28,000 --> 00:10:36,000
|
| 479 |
+
This use of SSL TLS encryption ensures that all data in transit is encrypted, so even if a malicious
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:36,000 --> 00:10:40,000
|
| 483 |
+
actor intercepts the communication, they cannot make sense of the data.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:41,000 --> 00:10:48,000
|
| 487 |
+
For instance, transmitting passwords or session tokens over HTTP would expose that data to attackers,
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:48,000 --> 00:10:51,000
|
| 491 |
+
who could then steal credentials or hijack sessions.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:51,000 --> 00:10:54,000
|
| 495 |
+
Using properly configured SSL.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:54,000 --> 00:11:02,000
|
| 499 |
+
TLS certificates not only encrypts data, but also verifies the identity of the server, further reducing
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:11:02,000 --> 00:11:05,000
|
| 503 |
+
the risk of man in the middle attacks.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:11:06,000 --> 00:11:12,000
|
| 507 |
+
The third practice is secure API use, which is crucial as APIs are often the gateways through which
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:11:12,000 --> 00:11:15,000
|
| 511 |
+
mobile apps communicate with back end systems.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:11:15,000 --> 00:11:22,000
|
| 515 |
+
APIs must be protected to ensure that unauthorized users or malicious actors can't access sensitive
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:11:22,000 --> 00:11:23,000
|
| 519 |
+
endpoints.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:11:23,000 --> 00:11:28,000
|
| 523 |
+
This is where proper validation and authorization come into play.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:28,000 --> 00:11:35,000
|
| 527 |
+
By using methods like Oauth2 for authentication and authorization, you ensure that only users who are
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:35,000 --> 00:11:38,000
|
| 531 |
+
properly authenticated can access certain data or services.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:38,000 --> 00:11:44,000
|
| 535 |
+
Additionally, validating the input passed through these APIs ensures that attackers cannot inject malicious
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:44,000 --> 00:11:46,000
|
| 539 |
+
data to manipulate the system.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:46,000 --> 00:11:52,000
|
| 543 |
+
For example, if an API allows an unauthenticated user to retrieve data without proper access, control,
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:52,000 --> 00:11:55,000
|
| 547 |
+
it opens the door to data breaches and misuse of services.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:56,000 --> 00:12:00,000
|
| 551 |
+
We then look at protection against reverse engineering.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:12:00,000 --> 00:12:07,000
|
| 555 |
+
A key concern for mobile apps, where the source code can be easily decompiled if not properly protected.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:12:08,000 --> 00:12:15,000
|
| 559 |
+
Attackers might reverse engineer an app to learn its functionality, find weaknesses, or extract sensitive
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:12:15,000 --> 00:12:18,000
|
| 563 |
+
information by using code obfuscation tools.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:12:18,000 --> 00:12:25,000
|
| 567 |
+
The app's code is transformed into a version that is hard to read and understand, making it difficult
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:25,000 --> 00:12:27,000
|
| 571 |
+
for an attacker to reverse engineer.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:28,000 --> 00:12:34,000
|
| 575 |
+
Additionally, securing the app's source code involves encrypting sensitive parts of the code and ensuring
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:12:34,000 --> 00:12:38,000
|
| 579 |
+
that debugging features are disabled in production environments.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:38,000 --> 00:12:46,000
|
| 583 |
+
Without these protections, attackers can tamper with the app or even inject malicious code that compromises
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:46,000 --> 00:12:47,000
|
| 587 |
+
user data.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:48,000 --> 00:12:52,000
|
| 591 |
+
Finally, we come to regular security testing and vulnerability assessments.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:52,000 --> 00:12:59,000
|
| 595 |
+
As mobile applications grow and evolve with new features and updates, new vulnerabilities can be introduced
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:59,000 --> 00:13:04,000
|
| 599 |
+
either in the app itself or through dependencies like third party libraries.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:05,000 --> 00:13:11,000
|
| 603 |
+
Regular penetration testing helps developers identify potential weaknesses that can be exploited by
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:11,000 --> 00:13:12,000
|
| 607 |
+
attackers.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:12,000 --> 00:13:18,000
|
| 611 |
+
For example, running periodic static analysis of the code can highlight vulnerabilities like insecure
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:18,000 --> 00:13:22,000
|
| 615 |
+
data storage or insecure API use.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:22,000 --> 00:13:28,000
|
| 619 |
+
These tests should be scheduled frequently, and particularly before major updates, to ensure that
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:28,000 --> 00:13:32,000
|
| 623 |
+
new code doesn't open up new attack vectors.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:33,000 --> 00:13:39,000
|
| 627 |
+
Neglecting regular security testing leaves an app vulnerable to undetected flaws that attackers could
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:39,000 --> 00:13:41,000
|
| 631 |
+
exploit over time.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:43,000 --> 00:13:50,000
|
| 635 |
+
Let's go into more detail on these low relevance mobile application security practices and explore how
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:50,000 --> 00:13:56,000
|
| 639 |
+
each plays a significant role in addressing edge case threats and lesser known vulnerabilities, ensuring
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:56,000 --> 00:13:59,000
|
| 643 |
+
a more comprehensive security approach for mobile apps.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:00,000 --> 00:14:06,000
|
| 647 |
+
First, we have prevention of data leakage by restricting app permissions to only what is necessary
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:14:06,000 --> 00:14:08,000
|
| 651 |
+
for its core functionality.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:14:08,000 --> 00:14:15,000
|
| 655 |
+
When an app requests excessive permissions like access to location data, the user's context, or even
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:14:15,000 --> 00:14:20,000
|
| 659 |
+
camera and microphone without a real need, it opens up unnecessary security risks.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:20,000 --> 00:14:25,000
|
| 663 |
+
Attackers, or even malicious apps could exploit these permissions to harvest sensitive user data.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:26,000 --> 00:14:30,000
|
| 667 |
+
Imagine a simple note taking app asking for access to your phone's contacts.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:30,000 --> 00:14:36,000
|
| 671 |
+
It doesn't need this data, so allowing it increases the risk of data leakage by carefully reviewing
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:36,000 --> 00:14:41,000
|
| 675 |
+
and limiting permissions to only those that are absolutely necessary.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:41,000 --> 00:14:46,000
|
| 679 |
+
We not only reduce the attack surface, but also force the user trust.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:46,000 --> 00:14:51,000
|
| 683 |
+
For example, a weather app should only request location access if it's using that data to provide weather
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:51,000 --> 00:14:52,000
|
| 687 |
+
updates.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:52,000 --> 00:14:53,000
|
| 691 |
+
Nothing more.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:53,000 --> 00:15:00,000
|
| 695 |
+
Broad permission requests not only risk user privacy, but also open up the potential for third party
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:00,000 --> 00:15:02,000
|
| 699 |
+
abuse if the app is compromised.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:02,000 --> 00:15:04,000
|
| 703 |
+
Next is tamper detection.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:04,000 --> 00:15:12,000
|
| 707 |
+
So jailbroken or rooted device checks a jailbroken or rooted device allows the user to bypass the operating
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:12,000 --> 00:15:19,000
|
| 711 |
+
system's built in security controls, which can expose sensitive data, enable app tampering, or allow
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:19,000 --> 00:15:21,000
|
| 715 |
+
malicious code injection.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:22,000 --> 00:15:27,000
|
| 719 |
+
On such compromised devices, even the best designed app can become vulnerable.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:27,000 --> 00:15:34,000
|
| 723 |
+
Tamper detection mechanisms allow the app to detect when it's being run on a compromised device and
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:34,000 --> 00:15:39,000
|
| 727 |
+
respond accordingly, either by disabling sensitive features or refusing to run at all.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:39,000 --> 00:15:46,000
|
| 731 |
+
For instance, a financial app might detect that it's on a rooted device and block access to transactions,
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:46,000 --> 00:15:52,000
|
| 735 |
+
thereby preventing sensitive financial information from being exposed or altered.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:52,000 --> 00:15:59,000
|
| 739 |
+
By doing this, the app ensures that it only functions in secure environments, which reduces the likelihood
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:59,000 --> 00:16:00,000
|
| 743 |
+
of being exploited.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:02,000 --> 00:16:08,000
|
| 747 |
+
Monitoring for suspicious activity is another critical practice, although it may seem like a behind
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:08,000 --> 00:16:09,000
|
| 751 |
+
the scenes measure.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:10,000 --> 00:16:15,000
|
| 755 |
+
Many attackers rely on the fact that abnormal behaviour in apps often goes unnoticed.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:15,000 --> 00:16:22,000
|
| 759 |
+
By setting up real time monitoring for suspicious actions, such as an unusually high number of failed
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:22,000 --> 00:16:30,000
|
| 763 |
+
login attempts, strange access patterns, or unexpected file transfers, the app can proactively identify
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:30,000 --> 00:16:32,000
|
| 767 |
+
potential threats before they escalate.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:33,000 --> 00:16:36,000
|
| 771 |
+
This is akin to installing a security alarm in a house.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:36,000 --> 00:16:41,000
|
| 775 |
+
You may not always expect a break in, but it's crucial to have alerts in place for when something out
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:16:41,000 --> 00:16:43,000
|
| 779 |
+
of the ordinary happens.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:43,000 --> 00:16:49,000
|
| 783 |
+
For example, detecting repeated failed login attempts from a single device could indicate a brute force
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:49,000 --> 00:16:56,000
|
| 787 |
+
attack, enabling the app to temporarily lock the account or request additional authentication steps.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:56,000 --> 00:17:04,000
|
| 791 |
+
Failing to monitor activity means potential breaches could go unnoticed until they have already caused
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:04,000 --> 00:17:05,000
|
| 795 |
+
significant damage.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:06,000 --> 00:17:13,000
|
| 799 |
+
Then there is the use of in-app security tools such as runtime application self-protection.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:13,000 --> 00:17:20,000
|
| 803 |
+
Unlike traditional security tools that work externally, runtime application self-protection is embedded
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:20,000 --> 00:17:22,000
|
| 807 |
+
within the app itself.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:22,000 --> 00:17:26,000
|
| 811 |
+
Monitoring for threats and taking action during runtime.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:26,000 --> 00:17:34,000
|
| 815 |
+
This means the app can detect and block attacks while it is being used, even if the attacker has bypassed
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:17:34,000 --> 00:17:35,000
|
| 819 |
+
other security layers.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:17:36,000 --> 00:17:43,000
|
| 823 |
+
For instance, if someone attempts to reverse engineer the app while it's running, runtime application
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:17:43,000 --> 00:17:48,000
|
| 827 |
+
self-protection can detect this tampering and shut down the app to prevent further damage.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:17:49,000 --> 00:17:56,000
|
| 831 |
+
Similarly, if someone tries to inject malicious code or exploit vulnerabilities during runtime, the
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:56,000 --> 00:18:01,000
|
| 835 |
+
app can protect itself by blocking or neutralizing the attack.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:01,000 --> 00:18:07,000
|
| 839 |
+
This real time defense makes it much harder for attackers to manipulate the app, even if they have
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:07,000 --> 00:18:10,000
|
| 843 |
+
already gained some access to it.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:10,000 --> 00:18:16,000
|
| 847 |
+
Without tools like runtime application self-protection, an attacker who successfully enters the app
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:16,000 --> 00:18:23,000
|
| 851 |
+
environment might be able to run unchecked, leading to significant data breaches or manipulation of
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:23,000 --> 00:18:24,000
|
| 855 |
+
sensitive processes.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:26,000 --> 00:18:33,000
|
| 859 |
+
Finally, session and token management is an often overlooked but essential aspect of mobile security.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:18:33,000 --> 00:18:40,000
|
| 863 |
+
Apps that handle user authentication, such as logging in with passwords or using tokens for session
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:18:40,000 --> 00:18:46,000
|
| 867 |
+
management, must ensure that these sessions are properly managed, and that tokens expire when they're
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:18:46,000 --> 00:18:47,000
|
| 871 |
+
no longer needed.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:18:48,000 --> 00:18:56,000
|
| 875 |
+
For example, if a user logs out of an app, their session token should be immediately invalidated.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:18:56,000 --> 00:19:01,000
|
| 879 |
+
Leaving it active poses a risk because attackers could use it to hijack the session and gain unauthorized
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:19:01,000 --> 00:19:02,000
|
| 883 |
+
access.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:19:03,000 --> 00:19:09,000
|
| 887 |
+
Additionally, tokens should be short lived and automatically expire after a certain period, reducing
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:19:09,000 --> 00:19:11,000
|
| 891 |
+
the window of opportunity for attackers.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:19:11,000 --> 00:19:17,000
|
| 895 |
+
Proper session management helps prevent attacks like session fixation or session hijacking, where attackers
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:19:17,000 --> 00:19:21,000
|
| 899 |
+
could exploit an active session to impersonate a user.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:19:21,000 --> 00:19:26,000
|
| 903 |
+
Without these measures, even an expired or forgotten session could become a doorway for attackers to
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:26,000 --> 00:19:32,000
|
| 907 |
+
access sensitive data long after the user thinks they have logged out.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:34,000 --> 00:19:39,000
|
| 911 |
+
In today's lesson on mobile application security, we've explored a range of practices grouped by their
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:19:39,000 --> 00:19:42,000
|
| 915 |
+
relevance to securing mobile applications.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:19:43,000 --> 00:19:48,000
|
| 919 |
+
The key takeaway is that mobile security is not about a single defense mechanism, but rather a layered
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:19:48,000 --> 00:19:54,000
|
| 923 |
+
approach where each practice addresses a different aspect of the app's attack surface.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:19:54,000 --> 00:19:56,000
|
| 927 |
+
Let's break it down.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:19:56,000 --> 00:20:02,000
|
| 931 |
+
At the high relevance level, we focused on the core foundational practices that mitigate the most critical
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:20:02,000 --> 00:20:03,000
|
| 935 |
+
threats.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:20:03,000 --> 00:20:09,000
|
| 939 |
+
Strong authentication and authorization mechanisms, such as multi-factor authentication, are essential
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:20:09,000 --> 00:20:12,000
|
| 943 |
+
to ensuring that only legitimate users access the app.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:20:13,000 --> 00:20:18,000
|
| 947 |
+
Combined with secure token management, these mechanisms make it much harder for attackers to hijack
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:20:18,000 --> 00:20:20,000
|
| 951 |
+
accounts or misuse credentials.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:20:21,000 --> 00:20:28,000
|
| 955 |
+
Next, the importance of encryption was highlighted both for data in transit and at rest.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:20:28,000 --> 00:20:34,000
|
| 959 |
+
Without encryption, sensitive data like financial information or personal identification could be exposed
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:20:34,000 --> 00:20:39,000
|
| 963 |
+
to attackers during transmission or when stored on the device.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:20:40,000 --> 00:20:47,000
|
| 967 |
+
Another critical point is the need to regularly update the app and its dependencies to patch known vulnerabilities.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:20:47,000 --> 00:20:54,000
|
| 971 |
+
Apps that are not updated are prime targets for attackers looking to exploit outdated systems.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:20:55,000 --> 00:21:01,000
|
| 975 |
+
Finally, protecting sensitive data such as PII by adhering to privacy regulations, and securely store
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:21:01,000 --> 00:21:08,000
|
| 979 |
+
and credentials and tokens in device native secure storage systems, further strengthens the apps defense
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:21:08,000 --> 00:21:11,000
|
| 983 |
+
against unauthorized access and data theft.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:21:12,000 --> 00:21:19,000
|
| 987 |
+
Moving to moderate relevance concerns, we discussed practices that address common security issues,
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:21:19,000 --> 00:21:22,000
|
| 991 |
+
often seen as gateways for attackers.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:21:23,000 --> 00:21:29,000
|
| 995 |
+
This begins with secure coding practices that help prevent vulnerabilities like SQL injection and buffer
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:21:29,000 --> 00:21:34,000
|
| 999 |
+
overflows, which could otherwise be exploited by malicious users.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:21:34,000 --> 00:21:40,000
|
| 1003 |
+
These coding practices, coupled with secure communication between the app and backend services, help
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:21:40,000 --> 00:21:45,000
|
| 1007 |
+
ensure that data transferred over networks remains protected from interception or manipulation.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:21:46,000 --> 00:21:52,000
|
| 1011 |
+
The proper use of APIs with validation and authorization mechanisms adds another critical layer, safeguarding
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:21:52,000 --> 00:21:55,000
|
| 1015 |
+
back end systems from unauthorized access.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:21:55,000 --> 00:22:01,000
|
| 1019 |
+
Furthermore, code obfuscation and securing the source code are essential for protecting against reverse
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:22:01,000 --> 00:22:07,000
|
| 1023 |
+
engineering, which can expose sensitive app logic or security flaws to attackers.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:22:07,000 --> 00:22:14,000
|
| 1027 |
+
Lastly, we discussed the need for regular security testing, including penetration testing, to identify
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:22:14,000 --> 00:22:18,000
|
| 1031 |
+
and fix vulnerabilities before attackers can exploit them.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:22:19,000 --> 00:22:25,000
|
| 1035 |
+
At the low relevance level, we touched on edge cases and lesser known threats, even though they may
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:22:25,000 --> 00:22:26,000
|
| 1039 |
+
seem less critical.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:22:26,000 --> 00:22:31,000
|
| 1043 |
+
Addressing these concerns adds additional layers of protection.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:22:31,000 --> 00:22:38,000
|
| 1047 |
+
Restricting app permissions to only those necessary for functionality helps prevent data leakage by
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:22:38,000 --> 00:22:42,000
|
| 1051 |
+
limiting the app's access to sensitive data.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:22:42,000 --> 00:22:49,000
|
| 1055 |
+
Tamper detection mechanisms, such as detecting jailbroken or rooted devices, prevent attackers from
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:22:49,000 --> 00:22:51,000
|
| 1059 |
+
exploiting compromised environments.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:22:52,000 --> 00:22:59,000
|
| 1063 |
+
Furthermore, monitoring for suspicious activity and using in-app security tools like runtime application
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:22:59,000 --> 00:23:04,000
|
| 1067 |
+
self-protection provide real time defense against emerging threats.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:23:05,000 --> 00:23:12,000
|
| 1071 |
+
Finally, proper session and token management, including revocation of tokens after logout, helps
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:23:12,000 --> 00:23:18,000
|
| 1075 |
+
maintain security by preventing unauthorized access to services once a session has ended.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:23:19,000 --> 00:23:22,000
|
| 1079 |
+
That's all what I wanted to discuss with you in this lesson.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:23:22,000 --> 00:23:25,000
|
| 1083 |
+
Let's recap what we've learned from the lesson.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:23:26,000 --> 00:23:33,000
|
| 1087 |
+
We explored the essential practices for mobile application security, focusing on high relevance threats
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:23:33,000 --> 00:23:37,000
|
| 1091 |
+
including strong authentication mechanisms and secure token management.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:23:38,000 --> 00:23:45,000
|
| 1095 |
+
You now understand how to implement encryption for sensitive data both in transit and at rest, ensuring
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:23:45,000 --> 00:23:48,000
|
| 1099 |
+
its protection throughout the life cycle.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:23:48,000 --> 00:23:54,000
|
| 1103 |
+
We covered the importance of regular app updates and security patches to mitigate known vulnerabilities.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:23:54,000 --> 00:24:00,000
|
| 1107 |
+
Together, we discussed best practices for secure storage of sensitive user data and compliance with
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:24:00,000 --> 00:24:03,000
|
| 1111 |
+
privacy regulations to minimize data collection.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:24:03,000 --> 00:24:09,000
|
| 1115 |
+
You learned about secure coding practices to prevent common vulnerabilities, and how to establish secure
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:24:09,000 --> 00:24:12,000
|
| 1119 |
+
communication between mobile apps and back end services.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:24:12,000 --> 00:24:19,000
|
| 1123 |
+
We examined ways to protect mobile apps against reverse engineering and the importance of regular security
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:24:19,000 --> 00:24:22,000
|
| 1127 |
+
testing and vulnerability assessments.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:24:22,000 --> 00:24:28,000
|
| 1131 |
+
Finally, we addressed lesser known threats like tamper detection, session management, and monitoring
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:24:28,000 --> 00:24:32,000
|
| 1135 |
+
app activity to prevent unauthorized access.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:24:33,000 --> 00:24:35,000
|
| 1139 |
+
That's all for this lesson.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:24:35,000 --> 00:24:37,000
|
| 1143 |
+
Thanks a lot for your attention.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:24:37,000 --> 00:24:40,000
|
| 1147 |
+
Have a great day and see you in the next lesson.
|
| 1148 |
+
|
77 - ===== EXAM TASK OWASP Top 10, Secure Coding & Logging =====/001 Exam Task Description and Solution (with reference to the source code).html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Exam Task Description and Solution (with reference to the source code)</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Exam Task Description and Solution (with reference to the source code)</div>
|
| 65 |
+
<div class="article-asset-container"><h4>EXAM Task:</h4><ol><li><p>Review <strong>the requirements and the solution</strong> of the previous exam task. The solution is located at the bottom of the file with the description of the previous exam task - <a href="https://docs.google.com/document/d/1X9iZaqUFtbz7CcglLAr1yHf6ff_8ae7mWTPp3_e8F5k/edit?usp=sharing" rel="noopener noreferrer" target="_blank">https://docs.google.com/document/d/1X9iZaqUFtbz7CcglLAr1yHf6ff_8ae7mWTPp3_e8F5k/edit?usp=sharing</a> <br><br></p></li><li><p>Use the commit with the solution to create a new branch from it in git <br>Commit with the solution - <a href="https://github.com/AndriiPiatakha/java-learnit-web-online-store/commit/e13e1ace0558d5a8f2dd61fc682c0dea7136544b" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/java-learnit-web-online-store/commit/e13e1ace0558d5a8f2dd61fc682c0dea7136544b</a> <br><br></p></li><li><p>Practice refactoring. Keeping code clean is also hard work. And I want you to learn Refactoring tools in your IDE and to help you gain practice skills in refactoring code. Refactor code: remove all code that is not relevant to the Online Shop application. As we learned in the course - we shouldn’t keep deprecated code that is not working in the application. It is time to clean up our learning project. Namely, remove the following items:</p><ol><li><p>Core module</p><ol><li><p>configs package</p></li><li><p>menu package</p></li><li><p>Main class</p></li><li><p>facades.HelpDeskFacade</p></li><li><p>facades.impl.DefaultHelpDeskFacade</p></li><li><p>AppTest class in the src/test/java source folder</p></li></ol></li><li><p>Persistence module</p><ol><li><p>Remove redundant code from the utils.DBUtils class</p></li><li><p>Remove enteties.impl.ComparableProduct</p></li><li><p>Remove utils.comparators.CustomSupportTicketsComparator class</p></li><li><p>Remove entities.RequestType and entities.SupportTicket</p></li><li><p>Remove entities.impl.DefaultSupportTicket</p></li><li><p>AppTest class in the src/test/java source folder</p></li><li><p>Refactor the package name persistence.enteties to persistence.entities - this is important task for you to practice in refactoring. Just imagine that you did grammatical mistake during the development and now you need to use your IDE to fix this spelling mistake. Use refactoring tools in your IDE.</p></li></ol></li><li><p>Web module</p><ol><li><p>Remove from src/main/webapp source folder</p><ol><li><p>css-demo.html</p></li><li><p>form-demo.html</p></li><li><p>index.html</p></li><li><p>index.jsp</p></li><li><p>jsp-demo.jsp</p></li><li><p>jsp-include-demo.jsp</p></li><li><p>jsp-tags-demo.jsp</p></li><li><p>jstl-demo.jsp</p></li></ol></li><li><p>Move servlets.exceptions package to controllers.exceptions</p></li><li><p>Remove servlets package</p></li><li><p>Remove filters.HelloWorldFilter class</p></li><li><p>Remove productList.jsp from WEB-INF/views</p></li><li><p>Remove WEB-INF/tags/general</p></li><li><p>Remove WEB/INF/tags/shop/plp-subcategories.tag</p></li><li><p>Remove listeners.SessionListener class<br><br></p></li></ol></li></ol></li><li><p>Add a connection pool to the solution. Use DataSource object to get the connection. If you are student of my Java course “Java from Zero to First Job”, then we already did this task during other homework. If you didn’t do this hometask yet, find the solution with the source code at the bottom of the Connection Pooling Homework file here - <a href="https://docs.google.com/document/d/1ZWdFFYlQ9B0KyUzeV_wDReCr8zuW0TJacGKxs8wmvgA/edit?usp=sharing" rel="noopener noreferrer" target="_blank">https://docs.google.com/document/d/1ZWdFFYlQ9B0KyUzeV_wDReCr8zuW0TJacGKxs8wmvgA/edit?usp=sharing</a> <br><br>Add package “connectionpools” and put DBCP connection pooling logic in that package. <br><br>Update DBUtils class to get connection from DBCP pool.<br><br><br></p></li><li><p>Use product GUID when searching and extracting products. For this:</p><ol><li><p>Change ProductDto and add the necessary field</p></li><li><p>Add necessary field in the database table</p></li><li><p>Update MySqlJdbcProductDao</p></li><li><p>Update ProductDao and introduce a new method getProductByGuid(String guid)</p></li><li><p>UpdateProductDto convertor respectively</p></li><li><p>Update Product model</p></li><li><p>Update DefaultProduct class</p></li><li><p>Update ProductServlet to extract product by GUID</p></li><li><p>Send GUID parameter instead of ID to /product controller</p></li><li><p>Update CheckoutController to work with GUID instead of ID</p></li><li><p>Update pdp.jsp to submit GUID instead of ID<br><br></p></li></ol></li><li><p>Implement an edit profile page where I can update my current user info (first name, last name, email, password). I can update information only when I confirm my actions with the current password. <br><br></p></li><li><p>Use password encryption PBKDF2 with sault during the registration and store encrypted passwords. During the login verify that the password entered by the user matches the encrypted password that is associated with this user in the database.<br><br>Do not forget the “Update user” scenario where we need to confirm actions with the current password. <br><br></p></li><li><p>Implement prevention of brute force in case of multiple unsuccessful logins in a row. After three unsuccessful logins show the message to the user “There were 3 unsuccessful attempts to login into the account. Please, try to sign in later”. Show this message instead of the sign-in form. <br><br><br><br><br></p></li><li><p>Validate user password during the registration and password updating against the list of the 10k the most common passwords. In case there is a match between user input and the list - tell the user that weak password is selected and ask user to come up with another password. <br>Use this list for validation - <a href="https://en.wikipedia.org/wiki/Wikipedia:10,000_most_common_passwords" rel="noopener noreferrer" target="_blank">https://en.wikipedia.org/wiki/Wikipedia:10,000_most_common_passwords</a> <br><br><br><br></p></li><li><p>Implement logging of sign up, sign in flows at least. You are welcome also to add logging in other parts of application that you believe is important to cover with logs. Use rolling file appender for logs. No more than 3 files with max size of 10KB.</p></li></ol><p><br></p><p><br></p><h4><strong>SOLUTION</strong></h4><ul><li><p>Find commit with the solution of the whole Exam task - <a href="https://github.com/AndriiPiatakha/java-learnit-web-online-store-2/commit/5be8c4ce9f28cb83e162e770ce6bf3888a7be1af" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/java-learnit-web-online-store-2/commit/5be8c4ce9f28cb83e162e770ce6bf3888a7be1af</a> </p></li><li><p>Find the project with all git history on the github - <a href="https://github.com/AndriiPiatakha/java-learnit-web-online-store-2" rel="noopener noreferrer" target="_blank">https://github.com/AndriiPiatakha/java-learnit-web-online-store-2</a> <br><br>Pay attention, this project is used for online lessons and keeps changing from lesson to lesson, because together with my students we add new features and learning new things. Fill free to explore the state of the commit with the changes that I provided above, if you want to see <strong><em>only solution </em></strong>of this hometask and nothing else.</p></li></ul></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:07,000
|
| 3 |
+
Hello, Kim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:07,000 --> 00:00:09,000
|
| 7 |
+
Today we start a very important topic.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:09,000 --> 00:00:13,000
|
| 11 |
+
We're going to learn this topic with the help of many different lessons.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:13,000 --> 00:00:20,000
|
| 15 |
+
Today we start learning Jakarta Persistence API, formerly known as Java Persistence API.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:20,000 --> 00:00:24,000
|
| 19 |
+
Today we're going to learn some basic and key definitions.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:24,000 --> 00:00:28,000
|
| 23 |
+
One of such definitions that we have to learn is or am.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:28,000 --> 00:00:34,000
|
| 27 |
+
Also in this lesson we are going to learn what GPA is and what hibernate is.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:34,000 --> 00:00:38,000
|
| 31 |
+
Probably these are the key concepts to start with.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:38,000 --> 00:00:42,000
|
| 35 |
+
Also, I'm going to give an overview of all our frameworks.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:43,000 --> 00:00:49,000
|
| 39 |
+
We will hold a comparison of all these different terms in order to understand the difference better.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:49,000 --> 00:00:56,000
|
| 43 |
+
And at the end of the lesson, we're going to talk about GPA advantages and why we have to choose GPA.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:56,000 --> 00:00:58,000
|
| 47 |
+
Let's start our lesson.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:59,000 --> 00:01:03,000
|
| 51 |
+
Let's learn first what Aurum is or stands for.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:03,000 --> 00:01:05,000
|
| 55 |
+
Object Relational Mapping.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:06,000 --> 00:01:08,000
|
| 59 |
+
In very, very simplified words.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:08,000 --> 00:01:14,000
|
| 63 |
+
This is the process of converting Java objects to database tables and vice versa.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:14,000 --> 00:01:22,000
|
| 67 |
+
In other words, this allows us to interact with the relational database without any SQL objects.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:22,000 --> 00:01:31,000
|
| 71 |
+
Relational mapping or or AM is a programming technique to map application domain model objects to the
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:31,000 --> 00:01:39,000
|
| 75 |
+
relational database tables or RAM is used to develop and maintain a relationship between an object and
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:39,000 --> 00:01:40,000
|
| 79 |
+
a relational database.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:40,000 --> 00:01:48,000
|
| 83 |
+
By mapping an object state to database column, it also helps to handle various database operations
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:48,000 --> 00:01:58,000
|
| 87 |
+
easily, such as inserting, updating, deleting, etc. So because of Aurum we can forget about relational
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:58,000 --> 00:02:02,000
|
| 91 |
+
databases and don't be bothered how they work inside.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:03,000 --> 00:02:10,000
|
| 95 |
+
Of course we have to understand how they work, but during the actual coding and programming we are
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:10,000 --> 00:02:13,000
|
| 99 |
+
not bothered about operating database tables.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:13,000 --> 00:02:21,000
|
| 103 |
+
We think only about objects and their structure and or RAM will take care of the rest things that are
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:21,000 --> 00:02:26,000
|
| 107 |
+
needed to be done in order to map properly our objects with tables in the database.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:26,000 --> 00:02:33,000
|
| 111 |
+
Is it clear now when we learn what Aurum is, let's learn what GPI is.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:34,000 --> 00:02:41,000
|
| 115 |
+
GPA stands for Jakarta Persistence API, formerly known as Java Persistence API.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:41,000 --> 00:02:47,000
|
| 119 |
+
If you don't mind, I will use Jakarta and Java interchangeably during the lesson.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:47,000 --> 00:02:54,000
|
| 123 |
+
If you are wondering about the history of terminology, please refer to the lesson about Java EE.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:54,000 --> 00:03:01,000
|
| 127 |
+
In my Java from zero to first job course, I dedicated a part of the lesson explaining the history of
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:03:01,000 --> 00:03:02,000
|
| 131 |
+
such naming.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:03:03,000 --> 00:03:10,000
|
| 135 |
+
The Jakarta Persistence API, first of all, is a specification that defines how to persist data in
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:10,000 --> 00:03:15,000
|
| 139 |
+
Java applications, so it is not ready to use framework.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:15,000 --> 00:03:20,000
|
| 143 |
+
It is not a library, it is just a specification set of interfaces.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:20,000 --> 00:03:28,000
|
| 147 |
+
In other words, contracts that should be followed when you want to use persistence API in Java applications
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:29,000 --> 00:03:32,000
|
| 151 |
+
taking into account Java has huge community.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:32,000 --> 00:03:40,000
|
| 155 |
+
There was a day when people realized it would be better to standardize the way how we persist objects
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:40,000 --> 00:03:45,000
|
| 159 |
+
in Java instead of having custom approach in each different library.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:45,000 --> 00:03:54,000
|
| 163 |
+
The primary focus of Gpe is that there is a specification that facilitates objects relational mapping
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:54,000 --> 00:03:58,000
|
| 167 |
+
to manage relational data in Java applications.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:58,000 --> 00:04:04,000
|
| 171 |
+
It provides a platform to work directly with objects instead of using SQL statements.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:04:05,000 --> 00:04:11,000
|
| 175 |
+
GPA permits the developer to work directly with objects rather than with SQL statements.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:12,000 --> 00:04:21,000
|
| 179 |
+
The GPA implementation is typically called persistence provider GPA X as a bridge between object oriented
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:21,000 --> 00:04:25,000
|
| 183 |
+
domain models and relational database systems.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:26,000 --> 00:04:31,000
|
| 187 |
+
There are different implementations of the GPA persistence providers.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:31,000 --> 00:04:37,000
|
| 191 |
+
Let's hold a brief and very high level overview of different all error frameworks.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:38,000 --> 00:04:39,000
|
| 195 |
+
Hibernate.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:39,000 --> 00:04:45,000
|
| 199 |
+
Hibernate is one of the most popular Java program frameworks in use today.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:45,000 --> 00:04:54,000
|
| 203 |
+
Its first release was almost 20 years ago and still has excellent community support and regular releases.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:54,000 --> 00:05:00,000
|
| 207 |
+
Additionally, Hibernate is a standard implementation of the GPA specification with a few additional
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:05:00,000 --> 00:05:03,000
|
| 211 |
+
features that are specific to hibernate.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:05:04,000 --> 00:05:12,000
|
| 215 |
+
The Eclipse link is the Open Source Eclipse Persistence Service Project from the Eclipse Foundation.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:05:12,000 --> 00:05:20,000
|
| 219 |
+
The software provides an extensible framework that allows Java developers to interact with various data
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:05:20,000 --> 00:05:29,000
|
| 223 |
+
services, including databases, web services, object, XML mapping and enterprise information systems.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:05:29,000 --> 00:05:36,000
|
| 227 |
+
Eclipse Link supports a number of persistence standards, including Jakarta Persistence API.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:05:36,000 --> 00:05:42,000
|
| 231 |
+
Jakarta XML Binding, Jakarta Connectors, Service Data objects.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:43,000 --> 00:05:50,000
|
| 235 |
+
Eclipse Link is based on the top link product from which Oracle contributed the source code to create
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:50,000 --> 00:05:51,000
|
| 239 |
+
the Eclipse Link project.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:52,000 --> 00:05:54,000
|
| 243 |
+
Oracle Toppling.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:54,000 --> 00:06:02,000
|
| 247 |
+
Toppling is produced by Oracle and is part of Oracle's Oracle application server, WebLogic and also
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:06:02,000 --> 00:06:04,000
|
| 251 |
+
for servers.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:06:04,000 --> 00:06:12,000
|
| 255 |
+
It is an object persistence and object transformation framework totaling provides development tools
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:06:12,000 --> 00:06:19,000
|
| 259 |
+
and runtime functionalities that ease the development process and help increase functionality.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:06:20,000 --> 00:06:26,000
|
| 263 |
+
A rich user interface is possible on the topline with the help of topline mapping workbench.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:06:27,000 --> 00:06:35,000
|
| 267 |
+
This Map and workbench supports graphical mapping of an object model to data model generation of data
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:06:35,000 --> 00:06:43,000
|
| 271 |
+
model from its object model and vice versa, or to mapping of any existing data models and object models.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:06:44,000 --> 00:06:46,000
|
| 275 |
+
Apache Open GP.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:46,000 --> 00:06:54,000
|
| 279 |
+
Apache Open GP is a Java persistence project at the Apache Software Foundation that can be used as a
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:54,000 --> 00:07:02,000
|
| 283 |
+
standalone project persistence layer or integrated into any Java E compliant container and many other
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:07:02,000 --> 00:07:06,000
|
| 287 |
+
lightweight frameworks such as Tomcat and Spring.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:07:07,000 --> 00:07:14,000
|
| 291 |
+
Apache AI bodies as a persistence frameworks such as Hibernate allows the creation of an object model
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:07:14,000 --> 00:07:22,000
|
| 295 |
+
by the user and create and maintain the relational database automatically ie bodies takes the reverse
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:07:22,000 --> 00:07:23,000
|
| 299 |
+
approach.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:07:24,000 --> 00:07:31,000
|
| 303 |
+
The developer starts with a SQL database and then bodies automates the creation of Java objects.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:07:31,000 --> 00:07:37,000
|
| 307 |
+
A significant difference between AI bodies and other persistence frameworks such as hibernate is that
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:07:37,000 --> 00:07:45,000
|
| 311 |
+
AI bodies emphasizes the use of SQL, while other frameworks typically use a custom query language such
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:07:45,000 --> 00:07:48,000
|
| 315 |
+
as Hibernate, Query Language or Java persistence.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:07:48,000 --> 00:07:49,000
|
| 319 |
+
Query language.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:07:50,000 --> 00:07:54,000
|
| 323 |
+
Also, I'd like to say a few words about my bodies.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:54,000 --> 00:08:03,000
|
| 327 |
+
My bodies is a fog from I body's and nowadays most of AI bodies developers leave over to my bodies to
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:08:03,000 --> 00:08:07,000
|
| 331 |
+
the I Bodies project is currently marked as inactive.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:08:07,000 --> 00:08:15,000
|
| 335 |
+
Therefore you should go with my buddies for new projects and only use bodies if you are maintaining
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:08:15,000 --> 00:08:18,000
|
| 339 |
+
an existing project which already uses ibus.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:08:19,000 --> 00:08:22,000
|
| 343 |
+
So what should you use?
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:08:22,000 --> 00:08:31,000
|
| 347 |
+
Pure a hybrid or GP API with hibernate or any other or framework one we use hibernate with GP.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:08:31,000 --> 00:08:35,000
|
| 351 |
+
We are actually using the Hibernate GP implementation.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:08:36,000 --> 00:08:44,000
|
| 355 |
+
The benefit of this is that we can swap out Hibernate implementation of GP for another implementation
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:08:44,000 --> 00:08:46,000
|
| 359 |
+
of GP specification.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:08:46,000 --> 00:08:54,000
|
| 363 |
+
When you use straight hibernate, your law can into the implementation because other forums may use
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:08:54,000 --> 00:08:58,000
|
| 367 |
+
different methods or configurations and annotations.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:58,000 --> 00:09:05,000
|
| 371 |
+
Therefore we can switch over to another or ramp easily without making changes in our code.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:09:06,000 --> 00:09:13,000
|
| 375 |
+
If you're already watching this lesson, I assume that you understand abstraction or principle and such
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:09:13,000 --> 00:09:21,000
|
| 379 |
+
solid principle as dependency inversion modules of upper and lower levels should depend on abstractions.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:09:22,000 --> 00:09:29,000
|
| 383 |
+
That's why it is recommended to use GP interfaces, annotations, configurations during the implementation
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:09:29,000 --> 00:09:34,000
|
| 387 |
+
in order to not be bound to only one specific order and framework.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:09:34,000 --> 00:09:35,000
|
| 391 |
+
Is it clear?
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:09:36,000 --> 00:09:42,000
|
| 395 |
+
We have just learned a lot of new words or ram GPA hibernate.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:09:42,000 --> 00:09:46,000
|
| 399 |
+
Probably you might be confused by this moment in lesson.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:09:46,000 --> 00:09:51,000
|
| 403 |
+
Let's understand each definition better by comparing them between each other.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:09:52,000 --> 00:10:00,000
|
| 407 |
+
Or object relational mapping is concept process of converting data from object oriented language to
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:10:00,000 --> 00:10:03,000
|
| 411 |
+
relational database and vice versa.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:10:04,000 --> 00:10:13,000
|
| 415 |
+
Forum is the approach of taking object oriented data and mapping to a relational data store that is
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:10:13,000 --> 00:10:16,000
|
| 419 |
+
tables in a relational database management system.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:10:17,000 --> 00:10:21,000
|
| 423 |
+
Hibernate is an implementation of the Aurum concept.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:10:22,000 --> 00:10:26,000
|
| 427 |
+
GP is a one step above or a RAM.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:10:26,000 --> 00:10:32,000
|
| 431 |
+
GP is a Java EE standard specification for Aurum.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:10:32,000 --> 00:10:41,000
|
| 435 |
+
It is high level API and specification so that different Aurum tools can implement the same interfaces.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:10:42,000 --> 00:10:44,000
|
| 439 |
+
It is like standard for Aurum.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:10:44,000 --> 00:10:53,000
|
| 443 |
+
Following GPU standard gives the flexibility to developer to change the implementation from one to another.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:10:53,000 --> 00:11:01,000
|
| 447 |
+
For example, if application uses the GP API and hibernate as implementation, this can be changed easily
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:11:01,000 --> 00:11:02,000
|
| 451 |
+
in the future.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:11:03,000 --> 00:11:06,000
|
| 455 |
+
In future we can switch to AI bodies if required.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:11:07,000 --> 00:11:10,000
|
| 459 |
+
In case you wouldn't use GP Z is case one.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:11:10,000 --> 00:11:18,000
|
| 463 |
+
The application directly logs the implementation with hibernate without GP platform switching is going
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:11:18,000 --> 00:11:25,000
|
| 467 |
+
to be extremely complicated task to do because a lot of code would need to be written and tested.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:11:25,000 --> 00:11:29,000
|
| 471 |
+
Is it more clear now what is the difference between all these terms?
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:11:30,000 --> 00:11:32,000
|
| 475 |
+
Even in case something is still not clear?
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:11:32,000 --> 00:11:36,000
|
| 479 |
+
Please do not hesitate to ask your questions below.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:11:36,000 --> 00:11:39,000
|
| 483 |
+
Xavier and I will be happy to answer.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:11:39,000 --> 00:11:40,000
|
| 487 |
+
Let's continue.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:11:40,000 --> 00:11:49,000
|
| 491 |
+
Let's summarize GP advantages and let's answer the question why we need to use GP among GP advantages.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:11:49,000 --> 00:11:51,000
|
| 495 |
+
I'd like to highlight the following ones.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:11:52,000 --> 00:12:00,000
|
| 499 |
+
No need to create SQL statements if we use GP while you definitely can if you need some specific optimisation
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:12:00,000 --> 00:12:02,000
|
| 503 |
+
or customization.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:12:02,000 --> 00:12:09,000
|
| 507 |
+
But in general, with the help of GP, we have possibility to operate with objects only without working
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:12:09,000 --> 00:12:11,000
|
| 511 |
+
with the database directly.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:12:12,000 --> 00:12:14,000
|
| 515 |
+
Database Independent.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:12:14,000 --> 00:12:21,000
|
| 519 |
+
If you watched my course about SQL, then you should know that different relational databases may have
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:12:21,000 --> 00:12:23,000
|
| 523 |
+
different SQL dialects.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:12:23,000 --> 00:12:27,000
|
| 527 |
+
Using GPA, you don't have such problems.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:12:27,000 --> 00:12:35,000
|
| 531 |
+
The programming becomes easy by considering the objects, relational mapping and database access process
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:12:36,000 --> 00:12:38,000
|
| 535 |
+
and warding off unnecessary queries.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:12:39,000 --> 00:12:46,000
|
| 539 |
+
The basic idea is to delay all right operations as long as possible so that multiple update statements
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:12:46,000 --> 00:12:48,000
|
| 543 |
+
can be combined into one.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:12:49,000 --> 00:12:57,000
|
| 547 |
+
Your GP implementation therefore stores all entities that will used within one transaction in the first
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:12:57,000 --> 00:13:02,000
|
| 551 |
+
level cache in the course will also go going to run different cache levels.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:13:02,000 --> 00:13:05,000
|
| 555 |
+
And I'm going to explain you how they work.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:13:06,000 --> 00:13:13,000
|
| 559 |
+
Using the GP annotations, you can save your time for defining and architecting tables in the database.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:13:14,000 --> 00:13:20,000
|
| 563 |
+
In the course, I'm going to show you how to create tables based on the entities defined.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:13:21,000 --> 00:13:25,000
|
| 567 |
+
Using GPA, you can easily switch different or RAM implementations.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:13:26,000 --> 00:13:31,000
|
| 571 |
+
These are the main GPU advantages that helps developers a lot.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:13:32,000 --> 00:13:35,000
|
| 575 |
+
That's all what I wanted to share with you in this lesson.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:13:35,000 --> 00:13:38,000
|
| 579 |
+
Let's recap what we have learned today.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:13:39,000 --> 00:13:41,000
|
| 583 |
+
Today we learned what R.E.M. is.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:13:42,000 --> 00:13:44,000
|
| 587 |
+
Now you know what GPA is.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:13:44,000 --> 00:13:50,000
|
| 591 |
+
And also we reviewed different all around frameworks, including Hibernate.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:13:50,000 --> 00:13:54,000
|
| 595 |
+
At the end of the lesson, we learned GPA advantages.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:13:55,000 --> 00:13:56,000
|
| 599 |
+
That's all for this lesson.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:57,000 --> 00:13:58,000
|
| 603 |
+
Thank you all for your attention.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:58,000 --> 00:14:01,000
|
| 607 |
+
Have a great day and see you in the next lesson.
|
| 608 |
+
|
78 - ORM, JPA & Hibernate/002 First JPA Project Entity, ID GenerationType, Composite Primary Keys, etc)_en.srt
ADDED
|
@@ -0,0 +1,936 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:06,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:12,000
|
| 7 |
+
In this lesson, we are going to create our first GPA project and learn more about GPA entities.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:13,000 --> 00:00:17,000
|
| 11 |
+
Today we are going to have a lesson full of practical examples and exercises.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:18,000 --> 00:00:25,000
|
| 15 |
+
As you know, I teach students offline and online, and based on my experience of the examples that
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:25,000 --> 00:00:31,000
|
| 19 |
+
we are going to review today, gradually it becomes easier to understand what GPA is all about.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:32,000 --> 00:00:38,000
|
| 23 |
+
In this lesson, we are going to create our first GPA project and learn how to work with GPA, and that
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:38,000 --> 00:00:45,000
|
| 27 |
+
is how we are going to learn the many different annotations that are used to configure GPA entity.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:45,000 --> 00:00:48,000
|
| 31 |
+
Some of them are entity annotation.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:48,000 --> 00:00:50,000
|
| 35 |
+
Table column.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:50,000 --> 00:00:53,000
|
| 39 |
+
ID generated value annotations.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:53,000 --> 00:00:57,000
|
| 43 |
+
Also, we are going to learn different ID generation strategies.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:57,000 --> 00:01:03,000
|
| 47 |
+
I will explain why that we should follow during the creation of our entity class.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:03,000 --> 00:01:08,000
|
| 51 |
+
We'll learn how to work with composite primary keys in GPA entity.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:08,000 --> 00:01:13,000
|
| 55 |
+
I will explain what temporal annotation is and when we might need to use it.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:14,000 --> 00:01:22,000
|
| 59 |
+
Also, we are going to learn what transit notation is and how to not persist some fields from our entity.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:23,000 --> 00:01:29,000
|
| 63 |
+
In case we'll use enemies, we need to learn enumerate, annotation and learn the specifics of enum
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:29,000 --> 00:01:31,000
|
| 67 |
+
types persistence.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:31,000 --> 00:01:37,000
|
| 71 |
+
After we configure our GPA entity, we are going to learn how to persist our entities.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:38,000 --> 00:01:45,000
|
| 75 |
+
I will explain what entity, manager factory and what entity manager are will create separate file with
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:46,000 --> 00:01:47,000
|
| 79 |
+
configuration.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:47,000 --> 00:01:55,000
|
| 83 |
+
The file is called Persistence XML and I will teach you what configurations can be placed in there.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:56,000 --> 00:02:02,000
|
| 87 |
+
During the lesson, you are going to learn more about transactions in GPA and what transaction types
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:02,000 --> 00:02:09,000
|
| 91 |
+
to use during the configuration will compare and resource local transactions.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:09,000 --> 00:02:16,000
|
| 95 |
+
And after learning all this by the end of the lesson, we're going to have completely work in code example
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:16,000 --> 00:02:18,000
|
| 99 |
+
that will be able to persist.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:18,000 --> 00:02:20,000
|
| 103 |
+
Our entity is in the school.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:20,000 --> 00:02:22,000
|
| 107 |
+
Let's start our lesson.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:22,000 --> 00:02:26,000
|
| 111 |
+
As I promised, this will be less than full of practical examples.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:26,000 --> 00:02:29,000
|
| 115 |
+
So let's start from the demo straight away.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:30,000 --> 00:02:34,000
|
| 119 |
+
First of all, let's create separate project for our GPA examples.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:35,000 --> 00:02:42,000
|
| 123 |
+
Our end goal is to practice our skills by making improvements in the online shop template that we developed
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:42,000 --> 00:02:47,000
|
| 127 |
+
with my students from scratch in my course Java from zero to first job.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:48,000 --> 00:02:56,000
|
| 131 |
+
But we'll learn new topics on the examples in our training GPA project and only after that we'll work
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:56,000 --> 00:03:00,000
|
| 135 |
+
on improvements of our online shop as part of your home tasks.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:01,000 --> 00:03:05,000
|
| 139 |
+
We'll work on implementation of GPA in our online shop to gather.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:06,000 --> 00:03:11,000
|
| 143 |
+
In Eclipse, I create a new Maven project using maven quickstart.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:11,000 --> 00:03:15,000
|
| 147 |
+
Archetype Maven is not a topic for discussion in this lesson.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:16,000 --> 00:03:22,000
|
| 151 |
+
Please refer to the section about build tools in my Java from zero to first job course where we learn
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:23,000 --> 00:03:24,000
|
| 155 |
+
Maven on examples.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:24,000 --> 00:03:32,000
|
| 159 |
+
If you want to learn about Maven more, we'll start learning from understanding of what GPA entities
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:32,000 --> 00:03:32,000
|
| 163 |
+
are.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:33,000 --> 00:03:39,000
|
| 167 |
+
I have a separate package here as it is called entities and there is a class user inside.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:40,000 --> 00:03:45,000
|
| 171 |
+
Don't worry, I will share with you all the source code examples that you see in the lesson.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:46,000 --> 00:03:50,000
|
| 175 |
+
Please find the source code of all examples in attachments to the lesson.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:51,000 --> 00:03:53,000
|
| 179 |
+
Let's learn what an entity is.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:54,000 --> 00:03:58,000
|
| 183 |
+
An entity is a lightweight persistence domain object.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:58,000 --> 00:04:05,000
|
| 187 |
+
Typically, an entity represents a table in a relational database, and each entity instance corresponds
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:05,000 --> 00:04:08,000
|
| 191 |
+
to row in that table.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:08,000 --> 00:04:13,000
|
| 195 |
+
The primary programming artifact of an entity is the entity class.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:14,000 --> 00:04:17,000
|
| 199 |
+
Usually entities are simple Podio classes.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:18,000 --> 00:04:26,000
|
| 203 |
+
Podio stands for plain old java object basically data structure with fields and without behavior.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:27,000 --> 00:04:30,000
|
| 207 |
+
Podger usually have getters and setters.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:30,000 --> 00:04:39,000
|
| 211 |
+
After you create a class market with entity annotation, entity annotation will be used as method information
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:39,000 --> 00:04:40,000
|
| 215 |
+
talents.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:40,000 --> 00:04:45,000
|
| 219 |
+
This class should be mapped with a separate table in the database.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:46,000 --> 00:04:53,000
|
| 223 |
+
The entity annotation is a marker annotation which is used to discover persistent entities.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:53,000 --> 00:04:57,000
|
| 227 |
+
This annotation is from Jakarta Persistence Package.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:58,000 --> 00:05:05,000
|
| 231 |
+
In order to be able to use the sanitation, you have to add Jakarta Persistence Library into your class
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:05,000 --> 00:05:05,000
|
| 235 |
+
pass.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:06,000 --> 00:05:13,000
|
| 239 |
+
I use Maven Build two as a dependency manager, so I edit instructions to the Maven file to add this
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:13,000 --> 00:05:15,000
|
| 243 |
+
library into the class pass.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:15,000 --> 00:05:20,000
|
| 247 |
+
And here you can see the dependency in my pom xml file.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:20,000 --> 00:05:22,000
|
| 251 |
+
Table annotation.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:22,000 --> 00:05:29,000
|
| 255 |
+
By default, this entity will be mapped to the user table as determined by the given class name.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:30,000 --> 00:05:38,000
|
| 259 |
+
If you wanted to map this entity to another table and optionally a specific schema, you could use table
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:38,000 --> 00:05:40,000
|
| 263 |
+
annotation to do that.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:41,000 --> 00:05:48,000
|
| 267 |
+
For example, if you want to map user entity with the table that is called corporate user, then add
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:48,000 --> 00:05:51,000
|
| 271 |
+
table annotation like I did here.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:52,000 --> 00:05:57,000
|
| 275 |
+
But I will keep this command because I want to map user empathy with user table.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:58,000 --> 00:05:59,000
|
| 279 |
+
Column annotation.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:00,000 --> 00:06:01,000
|
| 283 |
+
What we need to do next.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:01,000 --> 00:06:05,000
|
| 287 |
+
Now we need to map properties with table columns.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:06,000 --> 00:06:12,000
|
| 291 |
+
Fields are defined as member variables in the class, with the name of each field being mapped to a
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:12,000 --> 00:06:14,000
|
| 295 |
+
column name in the table.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:14,000 --> 00:06:21,000
|
| 299 |
+
You can override this default mapping by using the column annotation, for example.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:21,000 --> 00:06:29,000
|
| 303 |
+
In this particular case, we're going to persist the state of the last name field into the last name
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:29,000 --> 00:06:32,000
|
| 307 |
+
column with underscore in the name.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:33,000 --> 00:06:35,000
|
| 311 |
+
This is just an example though.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:35,000 --> 00:06:41,000
|
| 315 |
+
Highlight that you can persist state in any custom table column that you need.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:42,000 --> 00:06:45,000
|
| 319 |
+
I also configured column names for other attributes here.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:46,000 --> 00:06:53,000
|
| 323 |
+
Nothing special, just to make sure that I don't use Java style naming to name columns in the SQL table.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:54,000 --> 00:07:00,000
|
| 327 |
+
Column annotation also allows to specify other method information about the mapping.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:00,000 --> 00:07:06,000
|
| 331 |
+
Namely, we can specify the value of some field should be unique and column.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:06,000 --> 00:07:13,000
|
| 335 |
+
Also, we can specify what is a column label insert label updatable lengths.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:13,000 --> 00:07:15,000
|
| 339 |
+
Pay attention to the source code.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:15,000 --> 00:07:20,000
|
| 343 |
+
Here you can see that each of these properties have default value.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:21,000 --> 00:07:27,000
|
| 347 |
+
For most of them we can see true, but for the unique, the default value is false.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:28,000 --> 00:07:37,000
|
| 351 |
+
ID annotation, each entity should have primary key something what will uniquely identifies each row
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:37,000 --> 00:07:43,000
|
| 355 |
+
in the database table and each object in our program in GP.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:43,000 --> 00:07:49,000
|
| 359 |
+
We use ID annotation to designate the field to be the table's primary key.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:50,000 --> 00:07:58,000
|
| 363 |
+
The primary key is required to be a Java primitive type, a primitive wrapper such as integer or long
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:58,000 --> 00:08:02,000
|
| 367 |
+
string that date a big integer or a big decimal.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:03,000 --> 00:08:07,000
|
| 371 |
+
I just add adaptation above ID field.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:08,000 --> 00:08:15,000
|
| 375 |
+
Generate that value annotation, we can generate the identifiers in different ways which are specified
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:15,000 --> 00:08:17,000
|
| 379 |
+
by the generated value annotation.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:17,000 --> 00:08:23,000
|
| 383 |
+
We can choose from five ID generation strategies with the strategy element.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:23,000 --> 00:08:30,000
|
| 387 |
+
The value can be table sequence, identity, UUID or auto.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:30,000 --> 00:08:34,000
|
| 391 |
+
Let's review what is the difference between different generation strategies.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:35,000 --> 00:08:36,000
|
| 395 |
+
Cable generation.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:36,000 --> 00:08:42,000
|
| 399 |
+
The generation type table gets only rarely used nowadays.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:42,000 --> 00:08:49,000
|
| 403 |
+
It's similar a sequence by storing and updating its current value in a database table, which requires
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:49,000 --> 00:08:55,000
|
| 407 |
+
the use of pessimistic logs which put all transactions into a sequential order.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:55,000 --> 00:08:57,000
|
| 411 |
+
What is pessimistic log?
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:57,000 --> 00:09:04,000
|
| 415 |
+
We are going to learn further in the course, but what you have to understand now is that table generation
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:09:04,000 --> 00:09:07,000
|
| 419 |
+
time slows down your application.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:09:08,000 --> 00:09:15,000
|
| 423 |
+
You can use the table generator annotation to specify the database table, which hibernate shell used
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:15,000 --> 00:09:17,000
|
| 427 |
+
to simulate the sequence.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:18,000 --> 00:09:25,000
|
| 431 |
+
The table generator defines the primary key generator that may be referenced by the name when a generator
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:25,000 --> 00:09:29,000
|
| 435 |
+
element is specified for the generated value annotation.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:29,000 --> 00:09:37,000
|
| 439 |
+
A table generator may be specified on the entity clause or on the primary key field of property.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:37,000 --> 00:09:44,000
|
| 443 |
+
The scope of the generator name is global to the persistence unit across all generator types.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:45,000 --> 00:09:51,000
|
| 447 |
+
The table generator annotation uses a standard database table for primary key values.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:51,000 --> 00:09:53,000
|
| 451 |
+
Sequence generation.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:53,000 --> 00:09:59,000
|
| 455 |
+
The generation type sequence uses a database sequence to generate unique values.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:59,000 --> 00:10:06,000
|
| 459 |
+
It requires additional select statements to get the next value from a database sequence.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:10:06,000 --> 00:10:10,000
|
| 463 |
+
But this has no performance impact for most applications.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:10:10,000 --> 00:10:19,000
|
| 467 |
+
And if your application has to persist a huge number of new entities, you can use some specific optimizations
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:19,000 --> 00:10:21,000
|
| 471 |
+
to reduce the number of statements.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:22,000 --> 00:10:29,000
|
| 475 |
+
If you don't provide any additional information, hibernate will request the next value from its default
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:29,000 --> 00:10:30,000
|
| 479 |
+
sequence.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:30,000 --> 00:10:37,000
|
| 483 |
+
You can change that by referencing the name of a sequence generator in the generator attribute of the
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:37,000 --> 00:10:39,000
|
| 487 |
+
generated value annotation.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:39,000 --> 00:10:47,000
|
| 491 |
+
The sequence generated annotation lets you define the name of the generator, the name and scheme of
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:47,000 --> 00:10:52,000
|
| 495 |
+
the database sequence and the allocation size of the sequence.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:53,000 --> 00:10:55,000
|
| 499 |
+
Identity generation.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:55,000 --> 00:11:02,000
|
| 503 |
+
The generation type identity is the easiest to use, but not the best one from a performance point of
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:11:02,000 --> 00:11:03,000
|
| 507 |
+
view.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:11:03,000 --> 00:11:11,000
|
| 511 |
+
It relies on the incremented database column and lets the database generate a new value with each insert
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:11:11,000 --> 00:11:12,000
|
| 515 |
+
operation.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:11:13,000 --> 00:11:14,000
|
| 519 |
+
From a database point of view.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:11:14,000 --> 00:11:22,000
|
| 523 |
+
This is very efficient because all the implement columns are highly optimized and it doesn't require
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:22,000 --> 00:11:23,000
|
| 527 |
+
any additional statements.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:24,000 --> 00:11:27,000
|
| 531 |
+
This approach has a significant drawback.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:27,000 --> 00:11:35,000
|
| 535 |
+
If you use hibernate, hibernate requires a primary key value for each managed entity and therefore
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:35,000 --> 00:11:38,000
|
| 539 |
+
has to perform the insert statement immediately.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:39,000 --> 00:11:44,000
|
| 543 |
+
This prevents it from using different optimization techniques like gdb c bar.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:46,000 --> 00:11:48,000
|
| 547 |
+
You uid generation.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:48,000 --> 00:11:52,000
|
| 551 |
+
Let me briefly cover you uid generation time.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:53,000 --> 00:11:57,000
|
| 555 |
+
UID stands for a universally unique identifier.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:57,000 --> 00:12:03,000
|
| 559 |
+
It is 128 bit label used for information in computer systems.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:12:03,000 --> 00:12:08,000
|
| 563 |
+
The term globally unique identifier is also used.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:12:08,000 --> 00:12:16,000
|
| 567 |
+
Most developers perform numerical primary keys because they are efficient to use and easy to generate.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:16,000 --> 00:12:20,000
|
| 571 |
+
But that doesn't mean that the primary key has to be a number.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:21,000 --> 00:12:26,000
|
| 575 |
+
U IDs, for example, have gained some popularity over recent years.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:12:26,000 --> 00:12:35,000
|
| 579 |
+
The main advantage of a UID is its practical, global uniqueness, which provides a huge advantage for
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:35,000 --> 00:12:37,000
|
| 583 |
+
distributed systems.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:38,000 --> 00:12:45,000
|
| 587 |
+
If you use the typical numerical ID that gets incremented for each new record, you need to generate
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:45,000 --> 00:12:48,000
|
| 591 |
+
all the IDs by the same system component.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:49,000 --> 00:12:55,000
|
| 595 |
+
In most cases, this is sequenced for each table that's managed by your database.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:55,000 --> 00:13:04,000
|
| 599 |
+
And if you want to have identifiers zipping unique globally in your system, you can use uid.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:05,000 --> 00:13:09,000
|
| 603 |
+
On the other hand, the UID also has some disadvantages.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:10,000 --> 00:13:12,000
|
| 607 |
+
The most obvious one is its size.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:13,000 --> 00:13:20,000
|
| 611 |
+
It's four times larger than a numerical YY and can be handled as efficiently as numerically.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:21,000 --> 00:13:30,000
|
| 615 |
+
You should therefore decide carefully if you want to use your UI IDs on America IDs and discuss it with
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:30,000 --> 00:13:32,000
|
| 619 |
+
your database administrator.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:33,000 --> 00:13:40,000
|
| 623 |
+
If we are using the default generation type, the persistence provider will determine values based on
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:40,000 --> 00:13:42,000
|
| 627 |
+
the type of the primary key attribute.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:43,000 --> 00:13:51,000
|
| 631 |
+
For example, if you use Hibernate as your persistence provider, it selects a generation strategy based
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:51,000 --> 00:13:53,000
|
| 635 |
+
on the database specific dialog.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:54,000 --> 00:14:01,000
|
| 639 |
+
For most popular databases, it selects generation type sequence, which I already explained.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:14:02,000 --> 00:14:06,000
|
| 643 |
+
And here's how a simple entity class that we created together.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:06,000 --> 00:14:13,000
|
| 647 |
+
Let's learn a few more requirements for entity class that we need to remember about the things that
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:14:13,000 --> 00:14:15,000
|
| 651 |
+
I'm going to talk about now.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:14:15,000 --> 00:14:19,000
|
| 655 |
+
A pretty simple, logical and intuitive.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:14:19,000 --> 00:14:23,000
|
| 659 |
+
But just in case, let me quickly cover key points.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:24,000 --> 00:14:32,000
|
| 663 |
+
The class must have a public or protected no argument construct that the class may have as a constructors.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:33,000 --> 00:14:36,000
|
| 667 |
+
The class must not be declared final.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:37,000 --> 00:14:41,000
|
| 671 |
+
No masses or persistent instance variables must be declared final.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:42,000 --> 00:14:50,000
|
| 675 |
+
If an entity instance is passed by value as a detached object, such as through a session being a mode
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:50,000 --> 00:14:56,000
|
| 679 |
+
business interface, the class must implement this generalizable interface.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:57,000 --> 00:14:58,000
|
| 683 |
+
And that is my extent.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:58,000 --> 00:15:06,000
|
| 687 |
+
Both entity and non entity classes and non entity classes may extend entity classes.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:15:07,000 --> 00:15:14,000
|
| 691 |
+
Persistent instance, variables must be declared private, protected or packaged private and can be
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:15:14,000 --> 00:15:18,000
|
| 695 |
+
accessed directly only by the entity class masses.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:19,000 --> 00:15:25,000
|
| 699 |
+
Clients must access the entity state through access of business masses.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:26,000 --> 00:15:30,000
|
| 703 |
+
And here we're generated getters and setters for our properties.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:31,000 --> 00:15:33,000
|
| 707 |
+
Composite primary case.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:34,000 --> 00:15:39,000
|
| 711 |
+
The next interesting thing that I'd like to explain is about composite primary keys.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:39,000 --> 00:15:45,000
|
| 715 |
+
Probably composite primary key is not so popular, a simple primary key.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:45,000 --> 00:15:48,000
|
| 719 |
+
But still, this case can happen.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:48,000 --> 00:15:52,000
|
| 723 |
+
And I want you to know how to handle such cases in GPA.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:53,000 --> 00:16:01,000
|
| 727 |
+
Composite primary keys are used when a primary key consists of more than one attribute, which corresponds
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:16:01,000 --> 00:16:04,000
|
| 731 |
+
to a set of single persistent properties of fields.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:16:05,000 --> 00:16:10,000
|
| 735 |
+
Composite primary keys must be defined in a primary key plus.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:16:11,000 --> 00:16:19,000
|
| 739 |
+
Composite primary keys are denoted using the embeddable embedded ID and IEEE class annotations.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:16:20,000 --> 00:16:22,000
|
| 743 |
+
I have a separate class here at the school.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:22,000 --> 00:16:24,000
|
| 747 |
+
User composite key.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:25,000 --> 00:16:30,000
|
| 751 |
+
Here you can see that on top of the class I put embeddable annotation.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:31,000 --> 00:16:36,000
|
| 755 |
+
The class has two properties and this is just for the sake of example.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:36,000 --> 00:16:43,000
|
| 759 |
+
Imagine this is the primary key for our user and that will consist from ID and name properties.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:43,000 --> 00:16:44,000
|
| 763 |
+
That's it.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:44,000 --> 00:16:51,000
|
| 767 |
+
And in case you want to use composite primary key in your entity, you just declare a property of such
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:51,000 --> 00:16:56,000
|
| 771 |
+
type and market with annotation embedded ID.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:56,000 --> 00:17:03,000
|
| 775 |
+
There is also another way to represent the composite primary key and I'll turn it way to represent the
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:17:03,000 --> 00:17:07,000
|
| 779 |
+
composite primary key is to use a class notation.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:17:07,000 --> 00:17:10,000
|
| 783 |
+
Let me show you another example.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:17:10,000 --> 00:17:18,000
|
| 787 |
+
I created another demo class that is called Project and imagine that I have composite key for my project
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:17:18,000 --> 00:17:23,000
|
| 791 |
+
entity that consists from department I.D. and actually Project ID.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:24,000 --> 00:17:32,000
|
| 795 |
+
Just as an example, when an entity has multiple primary key fields, GPA requires defining a special
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:32,000 --> 00:17:38,000
|
| 799 |
+
ID class that is attached to the entity class using the class annotation.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:39,000 --> 00:17:45,000
|
| 803 |
+
Here you can see a class annotation on top and a past project class.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:45,000 --> 00:17:51,000
|
| 807 |
+
Let's look at this class and here I have the port and project ID.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:51,000 --> 00:17:52,000
|
| 811 |
+
That's it.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:52,000 --> 00:17:54,000
|
| 815 |
+
Regarding composite primary keys.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:17:55,000 --> 00:17:57,000
|
| 819 |
+
Temporal annotation.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:17:57,000 --> 00:18:03,000
|
| 823 |
+
There is important annotation for Java to date and for Java calendar data types.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:18:04,000 --> 00:18:06,000
|
| 827 |
+
I am talking about temporal annotation.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:18:07,000 --> 00:18:11,000
|
| 831 |
+
Imagine that we need to store date of birth of our user.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:18:11,000 --> 00:18:16,000
|
| 835 |
+
We can create field of type Java till date or Java calendar.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:17,000 --> 00:18:25,000
|
| 839 |
+
You can use temporal annotation only with data of such types in a temporal annotation source.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:25,000 --> 00:18:32,000
|
| 843 |
+
One of the major issues of converting the date and time values from Java object to compatible database
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:32,000 --> 00:18:36,000
|
| 847 |
+
type and retrieve it back to the application.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:36,000 --> 00:18:43,000
|
| 851 |
+
Pay attention that you shouldn't use temporal annotation with types from java time package like for
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:43,000 --> 00:18:49,000
|
| 855 |
+
example with local date local time offset time offset date time.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:49,000 --> 00:18:55,000
|
| 859 |
+
The map between the Java eight date time classes and the SQL types is implicit.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:18:56,000 --> 00:19:00,000
|
| 863 |
+
There is no need to specify the temporal annotation.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:19:01,000 --> 00:19:06,000
|
| 867 |
+
Let's now imagine that my entity has fields that I don't want to persist.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:19:06,000 --> 00:19:12,000
|
| 871 |
+
For example, in an entity, we can have some field that is calculated on the file.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:19:13,000 --> 00:19:18,000
|
| 875 |
+
What if we calculate age of the user based on his or her date of birth?
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:19:19,000 --> 00:19:27,000
|
| 879 |
+
And I don't want to keep H in the database, but still I want to keep it in the Java object for cases
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:19:27,000 --> 00:19:28,000
|
| 883 |
+
like this.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:19:28,000 --> 00:19:30,000
|
| 887 |
+
There is a transient annotation.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:19:30,000 --> 00:19:37,000
|
| 891 |
+
You have to just put annotation next to field that you don't want to persist, and that's it.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:19:38,000 --> 00:19:40,000
|
| 895 |
+
Persists in some types.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:19:40,000 --> 00:19:44,000
|
| 899 |
+
Sometimes there is a need to persist and type.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:19:45,000 --> 00:19:49,000
|
| 903 |
+
In our particular example, imagine that we have agenda in them.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:50,000 --> 00:19:58,000
|
| 907 |
+
There are only two possible values is a male or female and in them should be part of our user entity.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:59,000 --> 00:20:07,000
|
| 911 |
+
We can use the enumerated annotation to specify whether the enum should be persisted by name or by ordinal.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:20:07,000 --> 00:20:15,000
|
| 915 |
+
You can see that I use enumerated annotation and inside this annotation I specified that I want to persist
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:20:15,000 --> 00:20:16,000
|
| 919 |
+
string.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:20:17,000 --> 00:20:25,000
|
| 923 |
+
So basically male or female value will be persisted, but actually we don't have to specify the enumerated
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:20:25,000 --> 00:20:27,000
|
| 927 |
+
annotation at all.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:20:27,000 --> 00:20:31,000
|
| 931 |
+
If we are going to persist the gender by the enum ordinal.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:20:31,000 --> 00:20:36,000
|
| 935 |
+
But if you want to persist that we have to specify enum type.
|
| 936 |
+
|
78 - ORM, JPA & Hibernate/002 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
|
78 - ORM, JPA & Hibernate/003 First JPA Project - Part 2 EntityManager, persistence.xml, Transactions in JPA_en.srt
ADDED
|
@@ -0,0 +1,996 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:03,000 --> 00:00:09,000
|
| 3 |
+
Now it is time to learn what entity manager is and how we can actually persist our entity.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:10,000 --> 00:00:17,000
|
| 7 |
+
A connection to a database is represented by an entity manager instance, which also provides functionality
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:17,000 --> 00:00:20,000
|
| 11 |
+
for performing operations on a database.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:20,000 --> 00:00:26,000
|
| 15 |
+
Many applications require multiple database connections during their lifetime.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:26,000 --> 00:00:33,000
|
| 19 |
+
For instance, in a web application, it is common to establish a separate database connection using
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:33,000 --> 00:00:35,000
|
| 23 |
+
a separate entity manager instance.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:35,000 --> 00:00:44,000
|
| 27 |
+
For every HTTP request there is a special object of type entity manager factory that is used to manage
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:44,000 --> 00:00:48,000
|
| 31 |
+
instantiation of entity manager instances.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:48,000 --> 00:00:56,000
|
| 35 |
+
An entity manager factory is constructed for a specific database and by managing resources efficiently,
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:56,000 --> 00:01:03,000
|
| 39 |
+
provides an efficient way to construct multiple entity manager instances for that database.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:01:03,000 --> 00:01:10,000
|
| 43 |
+
Operations that modify the content of a database require active transactions.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:10,000 --> 00:01:17,000
|
| 47 |
+
Transactions are managed by an entity transaction instance obtained from the entity manager.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:18,000 --> 00:01:25,000
|
| 51 |
+
And then the manager instance also functions as a factor for query instances which are needed for executing
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:25,000 --> 00:01:27,000
|
| 55 |
+
queries on the database.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:27,000 --> 00:01:29,000
|
| 59 |
+
So the first step is to obtain.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:29,000 --> 00:01:37,000
|
| 63 |
+
And if you manage to do this, we need to obtain and then to manage your factory that represents the
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:37,000 --> 00:01:38,000
|
| 67 |
+
relevant database.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:38,000 --> 00:01:44,000
|
| 71 |
+
And then we can use that factory instance to get an entity manager instance.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:45,000 --> 00:01:52,000
|
| 75 |
+
GP requires the definition of the persistence unit in an XML file in order to be able to generate an
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:52,000 --> 00:02:00,000
|
| 79 |
+
entity manager factor to configure entity manager factor, we need to create persistence is XML file.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:02:01,000 --> 00:02:06,000
|
| 83 |
+
There is also a conventional place where we need to put this file in MAVEN project.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:02:07,000 --> 00:02:16,000
|
| 87 |
+
GPA implementation would look for this file in the C main resources method folder and here you can see
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:16,000 --> 00:02:18,000
|
| 91 |
+
where we put this file.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:18,000 --> 00:02:25,000
|
| 95 |
+
But before we add configurations to this file, let's make sure that we added all required dependencies
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:25,000 --> 00:02:27,000
|
| 99 |
+
into the class space.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:27,000 --> 00:02:37,000
|
| 103 |
+
I open for maximum so we have here edit our Jakarta persistence and hibernate or dependency because
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:37,000 --> 00:02:42,000
|
| 107 |
+
as we learned already, GPA is just a set of interfaces contracts.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:42,000 --> 00:02:50,000
|
| 111 |
+
But to make things actually work we need to add some GPA implementation and in this course we are going
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:50,000 --> 00:02:53,000
|
| 115 |
+
to use hibernate as GPA implementation.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:54,000 --> 00:02:58,000
|
| 119 |
+
Also, let's add my SQL connector to the class pass.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:58,000 --> 00:03:05,000
|
| 123 |
+
It is also required because we are going to use my SQL Server using the course as our persistence storage.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:03:06,000 --> 00:03:09,000
|
| 127 |
+
Let's now open persistence XML file.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:03:09,000 --> 00:03:14,000
|
| 131 |
+
I'm going to give you a basic overview of key elements of the persistence XML file.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:03:15,000 --> 00:03:21,000
|
| 135 |
+
The Persistence Example Configuration file is used to configure a given GPA Persistence Unit.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:22,000 --> 00:03:30,000
|
| 139 |
+
The Persistence Unit defines all the metadata required to bootstrap an entity manager factory like entity
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:30,000 --> 00:03:38,000
|
| 143 |
+
mappings, data source and transaction settings as well as GPA provider the configuration properties.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:38,000 --> 00:03:43,000
|
| 147 |
+
The root tag is the persistence and it defines the GPA version.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:44,000 --> 00:03:48,000
|
| 151 |
+
You can use GPA with a very short basic configuration.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:48,000 --> 00:03:55,000
|
| 155 |
+
You only need a persistence element as the root element and the persistence unit element with the name
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:55,000 --> 00:03:55,000
|
| 159 |
+
attribute.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:56,000 --> 00:04:03,000
|
| 163 |
+
The attribute is used to identify the persistence unit and you can use it during the bootstrap process
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:04:03,000 --> 00:04:07,000
|
| 167 |
+
to instantiate a specific entity manager factor.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:04:07,000 --> 00:04:14,000
|
| 171 |
+
Having the basic default configuration, we also have to accept some default configurations.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:04:14,000 --> 00:04:18,000
|
| 175 |
+
Let me cover some details of basic configuration.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:19,000 --> 00:04:27,000
|
| 179 |
+
Your persistence provider scans the root of your persistence unit and as all annotated managed persistence
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:27,000 --> 00:04:29,000
|
| 183 |
+
clauses to the persistence unit.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:30,000 --> 00:04:36,000
|
| 187 |
+
If your letter is direct, it contains a file called Aurum XML.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:36,000 --> 00:04:41,000
|
| 191 |
+
It gets treated as a mapping file and included mapping information.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:41,000 --> 00:04:42,000
|
| 195 |
+
Get used.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:43,000 --> 00:04:51,000
|
| 199 |
+
I didn't show you example of Aurum XML file yet, but in short you can use XML configuration to configure
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:51,000 --> 00:04:54,000
|
| 203 |
+
entities instead of annotations.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:54,000 --> 00:05:01,000
|
| 207 |
+
Today in this lesson, we used GPA adaptations to configure our GPA entities.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:05:01,000 --> 00:05:09,000
|
| 211 |
+
But theoretically, you can use XML configuration to not mix up Java source code and GPA configuration
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:05:09,000 --> 00:05:11,000
|
| 215 |
+
in one class.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:05:11,000 --> 00:05:14,000
|
| 219 |
+
But this is a matter of the coding style.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:05:14,000 --> 00:05:17,000
|
| 223 |
+
Both ways of configuration are file.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:05:18,000 --> 00:05:22,000
|
| 227 |
+
In case you don't configure any database connection.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:05:22,000 --> 00:05:32,000
|
| 231 |
+
GP therefore expects that you provide a data source at one time or you can specify database properties
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:32,000 --> 00:05:34,000
|
| 235 |
+
to establish database connection.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:35,000 --> 00:05:38,000
|
| 239 |
+
I'm going to show you how to do this in a few minutes.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:39,000 --> 00:05:45,000
|
| 243 |
+
All GP implementations support a set of proprietary configuration parameters.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:46,000 --> 00:05:54,000
|
| 247 |
+
Examples for that as a log in configuration equips GP or hibernates database dialogue as you don't define
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:54,000 --> 00:06:02,000
|
| 251 |
+
any of them in this specific basic configuration, you also rely on all provider specific defaults,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:06:02,000 --> 00:06:08,000
|
| 255 |
+
but during the course we're going to learn key and the most popular configuration parameters.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:06:09,000 --> 00:06:16,000
|
| 259 |
+
Let me also explain one more important concept before you see how to configure transactions, type in
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:06:16,000 --> 00:06:18,000
|
| 263 |
+
the persistence XML.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:06:18,000 --> 00:06:26,000
|
| 267 |
+
Usually in persistence XML file, we have opportunity to configure transaction type, what is it and
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:06:26,000 --> 00:06:28,000
|
| 271 |
+
what transaction types can be used.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:06:29,000 --> 00:06:35,000
|
| 275 |
+
The transaction management is one of the most important Java persistence API aspects.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:35,000 --> 00:06:42,000
|
| 279 |
+
If you are using Hibernate or any other GPU provider, you should know how valuable transaction management
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:42,000 --> 00:06:43,000
|
| 283 |
+
is.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:43,000 --> 00:06:49,000
|
| 287 |
+
The GPA transaction determines when you modify or delete it.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:49,000 --> 00:06:52,000
|
| 291 |
+
Entity is synchronized with the database.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:52,000 --> 00:06:59,000
|
| 295 |
+
There is no way to talk about transaction management without mentioned persistence contacts.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:59,000 --> 00:07:02,000
|
| 299 |
+
What is the persistence contacts?
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:07:02,000 --> 00:07:07,000
|
| 303 |
+
Ensure the persistence context is a named session of entities.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:07:08,000 --> 00:07:15,000
|
| 307 |
+
There are two main types of transactions GTA transactions and the resource local transactions.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:07:16,000 --> 00:07:20,000
|
| 311 |
+
Let's learn what is the difference between these types of transactions.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:07:21,000 --> 00:07:28,000
|
| 315 |
+
GTA Java transaction API is an API for managing transactions in Java.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:07:28,000 --> 00:07:33,000
|
| 319 |
+
It has a few crucial steps according to the transaction lifecycle.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:07:34,000 --> 00:07:40,000
|
| 323 |
+
Transaction synchronization is a process in which transactions becomes registered in the persistence
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:40,000 --> 00:07:41,000
|
| 327 |
+
context.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:41,000 --> 00:07:45,000
|
| 331 |
+
Transaction Association The moment of persistence.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:45,000 --> 00:07:45,000
|
| 335 |
+
Context.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:45,000 --> 00:07:47,000
|
| 339 |
+
Connection with transaction.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:48,000 --> 00:07:51,000
|
| 343 |
+
Transaction propagation is a moment of persistence.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:51,000 --> 00:07:57,000
|
| 347 |
+
Context sharing in application ecosystem may be the only one.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:57,000 --> 00:08:04,000
|
| 351 |
+
Persistence context connect to the GTA and all entity managers within a transaction must have the same
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:08:04,000 --> 00:08:06,000
|
| 355 |
+
persistence context.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:08:07,000 --> 00:08:14,000
|
| 359 |
+
One What type of transaction management exists in GB ecosystem or a source local transaction?
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:08:15,000 --> 00:08:16,000
|
| 363 |
+
What does it mean?
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:08:16,000 --> 00:08:21,000
|
| 367 |
+
It means that transaction management is 100% by your control.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:22,000 --> 00:08:28,000
|
| 371 |
+
Implementation of it happens with the implementation of entity transaction.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:28,000 --> 00:08:31,000
|
| 375 |
+
There are some disadvantages of that.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:31,000 --> 00:08:38,000
|
| 379 |
+
For example, you may get a legal state exception when some transaction is already started and you try
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:38,000 --> 00:08:39,000
|
| 383 |
+
to start the new one.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:40,000 --> 00:08:46,000
|
| 387 |
+
The same exception is caused in the case of commit or rollback without an active transaction.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:47,000 --> 00:08:52,000
|
| 391 |
+
But during the course, I'm going to teach you how to use transactions like a pro.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:53,000 --> 00:08:57,000
|
| 395 |
+
In the following lessons we're going to review the different propagation levels.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:57,000 --> 00:08:58,000
|
| 399 |
+
What is it?
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:58,000 --> 00:09:05,000
|
| 403 |
+
Ensure it is a flow of creative avoiding and passing transaction from massive to massive.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:09:06,000 --> 00:09:08,000
|
| 407 |
+
So what would be the conclusion?
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:09:09,000 --> 00:09:16,000
|
| 411 |
+
In most cases where a source local is fine, this would use basic gdb c level transactions.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:09:16,000 --> 00:09:22,000
|
| 415 |
+
The downside is that the transaction is local to the GPA persistence unit.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:09:23,000 --> 00:09:30,000
|
| 419 |
+
So if you want a transaction that spawns multiple persistence units or other databases, then resource
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:09:30,000 --> 00:09:33,000
|
| 423 |
+
local may not be good enough.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:33,000 --> 00:09:43,000
|
| 427 |
+
GTA is also used for managing transactions across systems like Gems and GCA, but that's fairly exotic
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:43,000 --> 00:09:46,000
|
| 431 |
+
usage for most of us to use.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:46,000 --> 00:09:54,000
|
| 435 |
+
GTA, you need support for it in your application server and also support from the GBK driver.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:54,000 --> 00:09:57,000
|
| 439 |
+
So let's get back to our persistence.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:57,000 --> 00:09:58,000
|
| 443 |
+
Excellent configuration.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:59,000 --> 00:10:06,000
|
| 447 |
+
Now, you know, two main transaction types, the used transaction type depends on the environment in
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:10:06,000 --> 00:10:11,000
|
| 451 |
+
which you deploy your application in the Jakarta E environment.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:10:11,000 --> 00:10:20,000
|
| 455 |
+
GP expects that the container provides a GTA compliant connection provided in a Java SE environment.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:10:20,000 --> 00:10:24,000
|
| 459 |
+
It uses a resource local transaction instead.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:10:25,000 --> 00:10:26,000
|
| 463 |
+
In the file.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:10:26,000 --> 00:10:28,000
|
| 467 |
+
I left the command lines.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:28,000 --> 00:10:30,000
|
| 471 |
+
Please explore them.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:30,000 --> 00:10:35,000
|
| 475 |
+
You can see how I use transaction type property of persistence unit element.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:35,000 --> 00:10:37,000
|
| 479 |
+
It can be resource local or GTA.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:38,000 --> 00:10:46,000
|
| 483 |
+
The GTA data source and non GTA data source elements are mostly used in Jakarta environments.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:46,000 --> 00:10:55,000
|
| 487 |
+
They enable you to reference the GDI name of a data source that is or is not compliant with the Java
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:55,000 --> 00:10:56,000
|
| 491 |
+
transaction API.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:57,000 --> 00:11:03,000
|
| 495 |
+
If you don't use any of these two elements, you need to use a configure default data source for your
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:11:03,000 --> 00:11:09,000
|
| 499 |
+
container or provide the GDI name of a data source at deploy time.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:11:10,000 --> 00:11:17,000
|
| 503 |
+
And if you are using GPI in the Java AC environment, you can either use one of these two elements to
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:11:17,000 --> 00:11:23,000
|
| 507 |
+
reference data source or use a set of properties to configure a database connection.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:11:23,000 --> 00:11:29,000
|
| 511 |
+
In the minute I'm going to show you properties that we use to configure a database connection.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:11:30,000 --> 00:11:33,000
|
| 515 |
+
Let's continue then in other configurations.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:11:33,000 --> 00:11:40,000
|
| 519 |
+
The next thing that we need to do is to specify the managed classes included in the persistence unit.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:11:40,000 --> 00:11:48,000
|
| 523 |
+
By default, your GPA Persistence Unit includes all other paid and managed classes found in its root.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:49,000 --> 00:11:56,000
|
| 527 |
+
If you want to include any classes that are located somewhere else, you can either reference them explicitly
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:56,000 --> 00:12:00,000
|
| 531 |
+
or include all classes from a jar file.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:12:00,000 --> 00:12:06,000
|
| 535 |
+
Each class element needs to contain the full reference name of a class.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:12:06,000 --> 00:12:11,000
|
| 539 |
+
Please be aware that these classes need to be available on your class.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:12:11,000 --> 00:12:11,000
|
| 543 |
+
Pass.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:12:12,000 --> 00:12:17,000
|
| 547 |
+
Here you can see commanded example of adding our user class.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:12:17,000 --> 00:12:25,000
|
| 551 |
+
And also here is a command example of specifying the whole jar instead of specifying all classes from
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:12:25,000 --> 00:12:25,000
|
| 555 |
+
the jar.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:12:26,000 --> 00:12:28,000
|
| 559 |
+
You can also do other way around.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:12:28,000 --> 00:12:34,000
|
| 563 |
+
You can add vividly classes to the persistence yield and exclude all other classes.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:12:34,000 --> 00:12:43,000
|
| 567 |
+
To do that, you first need to use one or more class elements to explicitly specify which managed classes
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:43,000 --> 00:12:44,000
|
| 571 |
+
shall be part of.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:44,000 --> 00:12:48,000
|
| 575 |
+
The persistence unit is the next step.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:12:48,000 --> 00:12:55,000
|
| 579 |
+
You can use the exclude unlisted classes elements to exclude all classes from the persistence unit,
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:55,000 --> 00:12:58,000
|
| 583 |
+
which were not explicitly included.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:59,000 --> 00:13:03,000
|
| 587 |
+
The next step is to specify concrete persistence provider.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:13:04,000 --> 00:13:11,000
|
| 591 |
+
If you use any proprietary features of your persistence provider, you should specify dependency to
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:13:11,000 --> 00:13:11,000
|
| 595 |
+
it.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:13:11,000 --> 00:13:19,000
|
| 599 |
+
You can do that by defining the name of the class that implements the persistence provider interface
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:19,000 --> 00:13:21,000
|
| 603 |
+
in the provider element.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:21,000 --> 00:13:26,000
|
| 607 |
+
In this particular example, I specify hibernate, persistence provided.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:27,000 --> 00:13:30,000
|
| 611 |
+
Now let's add Jeep properties.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:30,000 --> 00:13:34,000
|
| 615 |
+
We are going to configure our database connection here.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:34,000 --> 00:13:39,000
|
| 619 |
+
You can see GBC driver class your URL, username and password.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:40,000 --> 00:13:44,000
|
| 623 |
+
As you can see, your row contains the name of the database.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:44,000 --> 00:13:50,000
|
| 627 |
+
That means that I already created a database before running this example.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:51,000 --> 00:13:57,000
|
| 631 |
+
So not so much new properties here ever since should look familiar to you and ever.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:57,000 --> 00:14:04,000
|
| 635 |
+
What we have learned with my students in the GBK port of my Java from zero to first job course.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:14:05,000 --> 00:14:12,000
|
| 639 |
+
The next step is to configure properties that would tell GP implementation what to do with regards to
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:14:12,000 --> 00:14:12,000
|
| 643 |
+
schema.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:13,000 --> 00:14:21,000
|
| 647 |
+
Since version 2.1, GP can create a new database at startup and initialize it with a predefined data
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:14:21,000 --> 00:14:29,000
|
| 651 |
+
set, you can activate and configure this feature by adding the foreign properties to your configuration.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:14:29,000 --> 00:14:33,000
|
| 655 |
+
Jakarta Persistent Schema Generation Database Action.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:14:34,000 --> 00:14:40,000
|
| 659 |
+
The actions that you want to perform to manage the database schema supported values are none.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:41,000 --> 00:14:44,000
|
| 663 |
+
Create, drop and create and drop.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:44,000 --> 00:14:46,000
|
| 667 |
+
As you probably expect.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:46,000 --> 00:14:54,000
|
| 671 |
+
The create option creates a database schema, start up, drop and create, drops the existing database
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:54,000 --> 00:14:59,000
|
| 675 |
+
and creates a new one and drop just removes the existing database.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:15:00,000 --> 00:15:08,000
|
| 679 |
+
Jakarta Persistent Schema Generation Creates Script source the name of file euro to the script that
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:15:08,000 --> 00:15:10,000
|
| 683 |
+
creates the database.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:15:10,000 --> 00:15:18,000
|
| 687 |
+
Jakarta Persistence Schema Generation Drop Script Source The name of file URL to the script.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:15:18,000 --> 00:15:26,000
|
| 691 |
+
The drops is a database Jakarta Persistent SQL Loss Script Source The name of file.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:15:26,000 --> 00:15:31,000
|
| 695 |
+
You will choose a script that initializes the database with a predefined data set.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:32,000 --> 00:15:36,000
|
| 699 |
+
Now let's specify Hebrew dialect.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:36,000 --> 00:15:37,000
|
| 703 |
+
What is it?
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:37,000 --> 00:15:47,000
|
| 707 |
+
A Hebrew dialect gives information to the framework of how to convert hibernate queries HQ l into native
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:47,000 --> 00:15:48,000
|
| 711 |
+
SQL queries.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:49,000 --> 00:15:54,000
|
| 715 |
+
Since Hibernate is a database agnostic, it can work with different databases.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:55,000 --> 00:16:04,000
|
| 719 |
+
However, databases have proprietary extensions, native SQL variations and set subset of SQL standard
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:16:04,000 --> 00:16:05,000
|
| 723 |
+
implementations.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:16:06,000 --> 00:16:10,000
|
| 727 |
+
And it looks like we're all glued to proceed with our code example.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:16:10,000 --> 00:16:14,000
|
| 731 |
+
Let me open them across that I prepared for this lesson.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:16:15,000 --> 00:16:18,000
|
| 735 |
+
The main method I create entity manager factory.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:16:18,000 --> 00:16:26,000
|
| 739 |
+
First to do this, I use persistence clause first and call create entity manager factory method and
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:16:26,000 --> 00:16:29,000
|
| 743 |
+
pass the name of my persistence unit.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:29,000 --> 00:16:33,000
|
| 747 |
+
Once a great entity manager factory.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:33,000 --> 00:16:35,000
|
| 751 |
+
I can create an entity manager.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:35,000 --> 00:16:37,000
|
| 755 |
+
Just call create entity manager.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:37,000 --> 00:16:40,000
|
| 759 |
+
Method on the entity manager factory.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:40,000 --> 00:16:48,000
|
| 763 |
+
The entity manager instance represents a connection to the database when using GP, every operation
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:48,000 --> 00:16:52,000
|
| 767 |
+
on a database is associated with the entity manager.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:52,000 --> 00:16:59,000
|
| 771 |
+
Further in a multithreaded application, every thread usually has its own entity manager instance,
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:59,000 --> 00:17:05,000
|
| 775 |
+
while at the same time sharing a single application wide entity manager factory.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:17:06,000 --> 00:17:14,000
|
| 779 |
+
Operations that modified database content such as store update and delete, should only be performed
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:17:14,000 --> 00:17:16,000
|
| 783 |
+
within an active transaction.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:17:16,000 --> 00:17:21,000
|
| 787 |
+
That's why we need to start a transaction when a transaction is active.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:17:21,000 --> 00:17:30,000
|
| 791 |
+
You can invoke entity manager methods that modify the database content such as persist and remove.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:30,000 --> 00:17:38,000
|
| 795 |
+
Database updates are collected and managed in memory and apply to the database once the transaction
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:38,000 --> 00:17:39,000
|
| 799 |
+
is completed.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:39,000 --> 00:17:43,000
|
| 803 |
+
So I created an instance of a user type.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:43,000 --> 00:17:47,000
|
| 807 |
+
This is entity type that we created during the lesson.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:47,000 --> 00:17:54,000
|
| 811 |
+
I initialize object with some random state and after that I call persist massive.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:55,000 --> 00:18:00,000
|
| 815 |
+
Now I want to get the reference to the transaction and commit transaction.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:18:00,000 --> 00:18:04,000
|
| 819 |
+
I call that transaction and commit mass.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:18:04,000 --> 00:18:11,000
|
| 823 |
+
Also, we shouldn't forget that after we finished using empathy manager and entity manager factory,
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:18:11,000 --> 00:18:12,000
|
| 827 |
+
we have to close them.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:18:13,000 --> 00:18:18,000
|
| 831 |
+
Just go close mass on the object that we initialize.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:18:19,000 --> 00:18:24,000
|
| 835 |
+
Let's open my SQL workbench now and take a look what we have received.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:24,000 --> 00:18:27,000
|
| 839 |
+
In scope of the lesson, I created two entities.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:27,000 --> 00:18:29,000
|
| 843 |
+
User and project.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:29,000 --> 00:18:36,000
|
| 847 |
+
When I showed example of composite primary key, you can also see a sequence table.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:36,000 --> 00:18:45,000
|
| 851 |
+
That is because we used all the generation type for our user ID, starting with Hibernate version 5.0.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:45,000 --> 00:18:54,000
|
| 855 |
+
When generation type is selected as auto hibernate uses sequence style generator regardless of the database.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:54,000 --> 00:19:04,000
|
| 859 |
+
In this case, my SQL Hibernate emulates a sequence using a table and is why you see the sequence table.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:19:04,000 --> 00:19:08,000
|
| 863 |
+
Anyway, we reviewed today different generation types.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:19:08,000 --> 00:19:11,000
|
| 867 |
+
You can select the one you like the most.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:19:11,000 --> 00:19:17,000
|
| 871 |
+
And if we would take a look at the content of the user table, we are going to see that information
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:19:17,000 --> 00:19:18,000
|
| 875 |
+
about our user.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:19:18,000 --> 00:19:21,000
|
| 879 |
+
John Smith was successfully persisted.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:19:22,000 --> 00:19:24,000
|
| 883 |
+
It is not all about GPA.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:19:24,000 --> 00:19:26,000
|
| 887 |
+
This is just the beginning.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:19:26,000 --> 00:19:31,000
|
| 891 |
+
We still have a lot of things to learn about GPA and hibernate in particular.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:19:31,000 --> 00:19:38,000
|
| 895 |
+
But today we learned already just enough information to perform simple persistence operation.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:19:39,000 --> 00:19:43,000
|
| 899 |
+
Congratulations with your first GPA coding example.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:19:43,000 --> 00:19:48,000
|
| 903 |
+
As always, I'm going to leave the reference to the source code in attachments to the lesson.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:49,000 --> 00:19:54,000
|
| 907 |
+
I encourage you to download the source code and run it on your local computer.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:54,000 --> 00:20:00,000
|
| 911 |
+
Play with the code and ask questions below this video in case something would remain not clear.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:20:00,000 --> 00:20:03,000
|
| 915 |
+
And I will be happy to answer.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:20:03,000 --> 00:20:06,000
|
| 919 |
+
Let's recap what we have learned today.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:20:07,000 --> 00:20:11,000
|
| 923 |
+
In this lesson, we created our first GPA project.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:20:11,000 --> 00:20:15,000
|
| 927 |
+
I explained what entities in GPA are.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:20:15,000 --> 00:20:19,000
|
| 931 |
+
We learned different adaptations to configure entity.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:20:19,000 --> 00:20:27,000
|
| 935 |
+
Some of the key annotations we learned are an entity table column ID generated value.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:20:28,000 --> 00:20:31,000
|
| 939 |
+
We learned different strategies for ID generation.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:20:32,000 --> 00:20:35,000
|
| 943 |
+
Now you know, key requirements for entity class.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:20:35,000 --> 00:20:40,000
|
| 947 |
+
And after this lesson, you can easily create your own entity classes.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:20:41,000 --> 00:20:44,000
|
| 951 |
+
We learned how to work with composite primary keys.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:20:44,000 --> 00:20:49,000
|
| 955 |
+
You saw why we need and how to use temporal annotation.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:20:50,000 --> 00:20:55,000
|
| 959 |
+
I explained how to avoid persistence some fields with transient annotation.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:20:56,000 --> 00:21:03,000
|
| 963 |
+
We reviewed how to configure persistence of enum types and we learned enumerated annotation.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:21:03,000 --> 00:21:09,000
|
| 967 |
+
After this lesson, you learned what entity, manager, factory and what entity manager is.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:21:09,000 --> 00:21:15,000
|
| 971 |
+
Together, we created our persistence XML file and learned the key configurations.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:21:16,000 --> 00:21:22,000
|
| 975 |
+
I explained transactions in GBA and we talked about different transaction types in GBA.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:21:23,000 --> 00:21:24,000
|
| 979 |
+
We compared.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:21:24,000 --> 00:21:29,000
|
| 983 |
+
What is the difference between GTA and resource local transactions?
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:21:30,000 --> 00:21:32,000
|
| 987 |
+
That's all what I wanted to share with you today.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:21:32,000 --> 00:21:34,000
|
| 991 |
+
Thanks a lot for your attention.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:21:34,000 --> 00:21:38,000
|
| 995 |
+
Have a great day and see you in the next lesson.
|
| 996 |
+
|
78 - ORM, JPA & Hibernate/003 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
|
78 - ORM, JPA & Hibernate/004 Operations with Entity (Create, Read, Update, Delete) & JPA Entity Lifecycle_en.srt
ADDED
|
@@ -0,0 +1,884 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:07,000
|
| 3 |
+
Hello, team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:07,000 --> 00:00:11,000
|
| 7 |
+
In this lesson, we're again going to have a lot of practical activity.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:11,000 --> 00:00:18,000
|
| 11 |
+
In this lesson, we're going to know how to perform basic operations with GP and these operations like
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:18,000 --> 00:00:21,000
|
| 15 |
+
create, read, update and delete.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:21,000 --> 00:00:25,000
|
| 19 |
+
And we will talk about GPA and the life cycle.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:25,000 --> 00:00:34,000
|
| 23 |
+
We're going to start from examples that show us how to perform crude operations with GPA entities.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:34,000 --> 00:00:41,000
|
| 27 |
+
We're going to review GPA API to create, read, update and delete our entities.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:42,000 --> 00:00:48,000
|
| 31 |
+
After this lesson, you're going to have ready to use examples to perform all basic operations with
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:48,000 --> 00:00:53,000
|
| 35 |
+
GPA, and this will learn states of GPA entities.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:53,000 --> 00:01:03,000
|
| 39 |
+
We're going to learn four main states of GPA, entity, zero new, persistent, detached and removed.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:01:03,000 --> 00:01:09,000
|
| 43 |
+
And once we learned all this, we are going to run GPA, entity lifecycle.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:09,000 --> 00:01:16,000
|
| 47 |
+
And I'm going to show you how you can handle events related with GPA and the life cycle.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:16,000 --> 00:01:18,000
|
| 51 |
+
Let's start our lesson.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:19,000 --> 00:01:25,000
|
| 55 |
+
As everybody said in this lesson, we're going to learn topics by examples and we are going to start
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:25,000 --> 00:01:27,000
|
| 59 |
+
from the demo straightaway.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:27,000 --> 00:01:34,000
|
| 63 |
+
Before we start, I'd like to say that all examples that I'm going to share with you today are located
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:34,000 --> 00:01:37,000
|
| 67 |
+
in the package that is called Lifecycle.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:38,000 --> 00:01:45,000
|
| 71 |
+
I copied user entities that we created together in previous lesson and I just gave it another name to
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:45,000 --> 00:01:49,000
|
| 75 |
+
avoid conflicts with a user from another lesson.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:49,000 --> 00:01:58,000
|
| 79 |
+
So key which in previous lesson is important for understanding of this lesson, I just wanted to highlight
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:58,000 --> 00:02:02,000
|
| 83 |
+
that I recommend you to not skip lessons.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:02:03,000 --> 00:02:04,000
|
| 87 |
+
Let me run the program.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:05,000 --> 00:02:13,000
|
| 91 |
+
This demo program produces console output that will help us to understand it better and how the application
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:13,000 --> 00:02:13,000
|
| 95 |
+
works.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:14,000 --> 00:02:20,000
|
| 99 |
+
So user class is similar to the one that we created together in the previous lesson.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:21,000 --> 00:02:23,000
|
| 103 |
+
There is nothing new so far here.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:24,000 --> 00:02:30,000
|
| 107 |
+
I open demo class will learn how to configure entity manager factory.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:30,000 --> 00:02:33,000
|
| 111 |
+
We also get the references to entity manager object.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:33,000 --> 00:02:36,000
|
| 115 |
+
We created user objects that we want to persist.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:37,000 --> 00:02:44,000
|
| 119 |
+
In this lesson you saw how we call persist mass and that is great that we'll really learn this method
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:44,000 --> 00:02:46,000
|
| 123 |
+
from the API.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:46,000 --> 00:02:53,000
|
| 127 |
+
Just wanted to recap this quickly with you, but how we can get an idea of the entities that we persisted
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:54,000 --> 00:03:01,000
|
| 131 |
+
because in real life idea of the objects that we have just saved can be required for business logic.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:03:02,000 --> 00:03:07,000
|
| 135 |
+
For example, you need to pass ID for the further operation.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:07,000 --> 00:03:15,000
|
| 139 |
+
So after calling persist method on the entity manager with user object, we can extract ID from the
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:15,000 --> 00:03:15,000
|
| 143 |
+
user.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:16,000 --> 00:03:17,000
|
| 147 |
+
It will be already there.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:17,000 --> 00:03:23,000
|
| 151 |
+
I just print it to console to show that we really received a value here.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:24,000 --> 00:03:32,000
|
| 155 |
+
Now let's find the way how we can read entity from the database to find an entity entity manager interface
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:32,000 --> 00:03:38,000
|
| 159 |
+
provides find method that searches an element on the basis of primary key.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:38,000 --> 00:03:43,000
|
| 163 |
+
And for the sake of the demo, we'll work with the same entity that we have persisted.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:44,000 --> 00:03:47,000
|
| 167 |
+
So we already took the primary key.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:48,000 --> 00:03:55,000
|
| 171 |
+
Probably the simplest version is to call, find, method and pass and the class that we want to find
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:55,000 --> 00:04:03,000
|
| 175 |
+
and the primary key, basically that's it and entity manager will be able to find the requested entity.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:04,000 --> 00:04:10,000
|
| 179 |
+
And here so you can see that we found the users that we have persisted in the previous example.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:11,000 --> 00:04:13,000
|
| 183 |
+
Font mass is overlord.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:13,000 --> 00:04:16,000
|
| 187 |
+
There are also other versions of this message.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:17,000 --> 00:04:18,000
|
| 191 |
+
Let me show it to you.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:19,000 --> 00:04:26,000
|
| 195 |
+
Find mass where we pass entity class, primary key and also map of properties.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:27,000 --> 00:04:35,000
|
| 199 |
+
Basically, no matter which GP implementation you use, you can find properties that you can add to
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:35,000 --> 00:04:36,000
|
| 203 |
+
the query.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:36,000 --> 00:04:43,000
|
| 207 |
+
For example, in Eclipse League documentation, you can find that you can add such properties that are
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:43,000 --> 00:04:46,000
|
| 211 |
+
actually key value pairs.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:46,000 --> 00:04:49,000
|
| 215 |
+
Eclipse link cache usage.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:49,000 --> 00:04:51,000
|
| 219 |
+
Eclipsing query type.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:51,000 --> 00:04:52,000
|
| 223 |
+
Eclipse link.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:52,000 --> 00:04:53,000
|
| 227 |
+
Pessimistic log.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:53,000 --> 00:04:54,000
|
| 231 |
+
Eclipse link.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:54,000 --> 00:04:55,000
|
| 235 |
+
Refresh.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:55,000 --> 00:04:56,000
|
| 239 |
+
Eclipse link.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:56,000 --> 00:05:00,000
|
| 243 |
+
Botch eclipse link with only gdb.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:00,000 --> 00:05:04,000
|
| 247 |
+
Timeout fetch size max rows etc..
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:04,000 --> 00:05:11,000
|
| 251 |
+
So in case you need to exit it, select where with some properties you know how to do this with gpa
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:11,000 --> 00:05:12,000
|
| 255 |
+
api.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:13,000 --> 00:05:20,000
|
| 259 |
+
Another version of Overlord mascot is Wiz and the gloss primary key and lock mode type.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:21,000 --> 00:05:28,000
|
| 263 |
+
Lock mode type is an enum GP lock and is a little bit specific topic to learn.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:28,000 --> 00:05:33,000
|
| 267 |
+
And I'd like to have a separate lesson dedicated to the GP lock.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:33,000 --> 00:05:41,000
|
| 271 |
+
As of now, you can just remember that you have opportunities to specify a lock type for the find operation.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:41,000 --> 00:05:48,000
|
| 275 |
+
In short, this lock in type helps us to solve the issue of concurrent access to the data.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:49,000 --> 00:05:57,000
|
| 279 |
+
For example, if you need to reserve some data for operations and you need no one else with touch ID
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:57,000 --> 00:06:05,000
|
| 283 |
+
you can consider is a configuring of propagation level of your transaction or lock in options, both
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:05,000 --> 00:06:07,000
|
| 287 |
+
propagation levels and locking.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:07,000 --> 00:06:10,000
|
| 291 |
+
We're going to learn separately in the lesson.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:10,000 --> 00:06:16,000
|
| 295 |
+
For now, just remember that you have opportunity to use find massive locking.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:17,000 --> 00:06:23,000
|
| 299 |
+
And the fourth version of Fine Mass is a combination of the previous two that we have discussed.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:23,000 --> 00:06:29,000
|
| 303 |
+
You can use properties and lock more type together with entity, class and ID.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:30,000 --> 00:06:33,000
|
| 307 |
+
Let's move on and learn how we can update entity.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:34,000 --> 00:06:36,000
|
| 311 |
+
Here is the refresh mascot.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:37,000 --> 00:06:44,000
|
| 315 |
+
Refresh mascot refreshes the state of the instance from the database, our write in changes made to
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:44,000 --> 00:06:46,000
|
| 319 |
+
the entity, if any.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:46,000 --> 00:06:50,000
|
| 323 |
+
It also triggers post load event handler.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:51,000 --> 00:06:57,000
|
| 327 |
+
Dubai also has API that allows us to update entity with ease.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:57,000 --> 00:07:03,000
|
| 331 |
+
So here we received the entity from the database after we received it.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:03,000 --> 00:07:08,000
|
| 335 |
+
We can say the entity is managed by our entity manager.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:08,000 --> 00:07:14,000
|
| 339 |
+
We can change its state and entity manager will track these changes.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:14,000 --> 00:07:22,000
|
| 343 |
+
Once transaction will be committed, the state of the entity will be also updated in the database.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:22,000 --> 00:07:24,000
|
| 347 |
+
Basically, that's it.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:24,000 --> 00:07:32,000
|
| 351 |
+
You don't need to call even some special masses like update or anything else because usually we is a
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:32,000 --> 00:07:42,000
|
| 355 |
+
persistent it is a first time or it is already persisted and we extracted and updated to help you understand
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:42,000 --> 00:07:45,000
|
| 359 |
+
the different states of entities.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:45,000 --> 00:07:48,000
|
| 363 |
+
Let's take a look at the following slide.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:48,000 --> 00:07:57,000
|
| 367 |
+
An object that GP or any GP implementation like hibernate can persist in the database and retrieve it
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:57,000 --> 00:08:00,000
|
| 371 |
+
back whenever needed is called an entity.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:00,000 --> 00:08:06,000
|
| 375 |
+
And we already learned this GP manages various states of these entities.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:07,000 --> 00:08:11,000
|
| 379 |
+
Basically there are four states of an object in GP.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:12,000 --> 00:08:22,000
|
| 383 |
+
They are new or transient, persistent, unmanaged, detached or unmanaged and removed or deleted.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:23,000 --> 00:08:28,000
|
| 387 |
+
Understanding of the persistent context is crucial at this moment.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:28,000 --> 00:08:33,000
|
| 391 |
+
In the previous lesson, we talked a little bit about persistence, context.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:33,000 --> 00:08:38,000
|
| 395 |
+
But let me elaborate more about it in simple words.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:38,000 --> 00:08:43,000
|
| 399 |
+
The persistence context sits between the client code and data store.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:44,000 --> 00:08:53,000
|
| 403 |
+
It's a staging area where persistent data is converted to entities ready to be read and altered by client
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:53,000 --> 00:08:53,000
|
| 407 |
+
code.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:54,000 --> 00:09:03,000
|
| 411 |
+
It keeps track of all law that data tracks changes of that data and is responsible to eventually synchronize
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:09:03,000 --> 00:09:08,000
|
| 415 |
+
any changes back to the database at the end of the business transaction.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:09:09,000 --> 00:09:17,000
|
| 419 |
+
GP and the key manager and hibernate session types are in implementation of the persistence context
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:09:17,000 --> 00:09:18,000
|
| 423 |
+
concept.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:18,000 --> 00:09:26,000
|
| 427 |
+
An object that is newly created and has never been associated with a persistence context is that this
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:26,000 --> 00:09:33,000
|
| 431 |
+
entity, manager or Hibernate session is considered to be in the new or transient state.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:33,000 --> 00:09:38,000
|
| 435 |
+
The data of object in this state is not stored in the database.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:39,000 --> 00:09:46,000
|
| 439 |
+
It is the case when we have just created user object, but our entity manager knows nothing about this
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:46,000 --> 00:09:47,000
|
| 443 |
+
object.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:47,000 --> 00:09:51,000
|
| 447 |
+
We can say that object is in use state.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:52,000 --> 00:10:00,000
|
| 451 |
+
When an object is associated with a persistent context and the key manager or hibernate session, we
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:10:00,000 --> 00:10:06,000
|
| 455 |
+
can say that object is in persistent state or in another way managed.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:10:07,000 --> 00:10:16,000
|
| 459 |
+
Any changes made to objects in this state are automatically propagated to databases without manually
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:10:16,000 --> 00:10:18,000
|
| 463 |
+
invoking other methods.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:10:19,000 --> 00:10:23,000
|
| 467 |
+
That is how we updated the user entity in our example.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:23,000 --> 00:10:27,000
|
| 471 |
+
So we extracted the user from the database.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:27,000 --> 00:10:37,000
|
| 475 |
+
It was in persistent state and we just updated it and the key manager tracks these changes because this
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:37,000 --> 00:10:41,000
|
| 479 |
+
user object was already associated with a persistent context.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:41,000 --> 00:10:43,000
|
| 483 |
+
Is it clear?
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:43,000 --> 00:10:50,000
|
| 487 |
+
And no object becomes detached when the currently running persistent context is closed.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:51,000 --> 00:10:58,000
|
| 491 |
+
Any changes made to the touched objects are no longer automatically propagated to the database.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:58,000 --> 00:11:05,000
|
| 495 |
+
Once commit is executed on the entity transaction object, the object becomes detached.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:11:06,000 --> 00:11:14,000
|
| 499 |
+
This is seems to be logical that once you call the commit method you shouldn't update the object and
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:11:14,000 --> 00:11:17,000
|
| 503 |
+
sync that it will be updated in the persistent context.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:11:18,000 --> 00:11:24,000
|
| 507 |
+
Because we already learned with you that in GP all actions happen within the transaction.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:11:25,000 --> 00:11:28,000
|
| 511 |
+
No actions should be done outside of transactions.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:11:29,000 --> 00:11:33,000
|
| 515 |
+
Removed objects are deleted from the database.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:11:33,000 --> 00:11:40,000
|
| 519 |
+
GP provides entity manager remove method to remove an entity from the database.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:11:40,000 --> 00:11:42,000
|
| 523 |
+
I'm going to show this in a minute.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:43,000 --> 00:11:45,000
|
| 527 |
+
Let's proceed with the demo.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:46,000 --> 00:11:50,000
|
| 531 |
+
I left here to the example of one method.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:50,000 --> 00:11:52,000
|
| 535 |
+
Let me elaborate on that.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:53,000 --> 00:12:01,000
|
| 539 |
+
GPUs merge massive copies the state of a detached entity to manage the instance of the same entity.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:12:02,000 --> 00:12:11,000
|
| 543 |
+
Kubernetes therefore executes and SQL Select Statement to retrieve a managed entity from the database.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:12:11,000 --> 00:12:19,000
|
| 547 |
+
If the persistence context already contained a managed instance of the entity, Hibernate uses the existing
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:12:19,000 --> 00:12:21,000
|
| 551 |
+
one instead.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:12:21,000 --> 00:12:28,000
|
| 555 |
+
It then copies all attribute values to the managed entity and returns it to the column.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:12:29,000 --> 00:12:37,000
|
| 559 |
+
But taking into account that our user from the BiH entity is in managed state, there is no need for
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:12:37,000 --> 00:12:39,000
|
| 563 |
+
us to call merge statement.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:12:40,000 --> 00:12:46,000
|
| 567 |
+
Talking about the Dutch state, there is a separate mass that is called the Dutch.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:46,000 --> 00:12:52,000
|
| 571 |
+
Invocation of this mass allows us to detach entity from the persistent context.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:53,000 --> 00:13:01,000
|
| 575 |
+
So any changes applied to this entity after calling the Dutch method will not be automatically propagated
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:13:01,000 --> 00:13:02,000
|
| 579 |
+
to the database.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:13:03,000 --> 00:13:04,000
|
| 583 |
+
Is it clear?
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:13:04,000 --> 00:13:12,000
|
| 587 |
+
And even in case you still have any questions, please do not hesitate to ask your questions below the
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:13:12,000 --> 00:13:15,000
|
| 591 |
+
video and I will be happy to answer.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:13:16,000 --> 00:13:18,000
|
| 595 |
+
And there is another operation left.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:13:19,000 --> 00:13:23,000
|
| 599 |
+
Let me remove operation for the sake of the dam.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:23,000 --> 00:13:28,000
|
| 603 |
+
I created one more user and I persisted with first.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:29,000 --> 00:13:32,000
|
| 607 |
+
You already saw how this method works.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:32,000 --> 00:13:35,000
|
| 611 |
+
And after that I call remove mass.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:36,000 --> 00:13:39,000
|
| 615 |
+
The method works as it is expected.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:40,000 --> 00:13:48,000
|
| 619 |
+
So user two is removed from the persistent context and after commit it will be removed from the database.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:49,000 --> 00:13:52,000
|
| 623 |
+
Everything is simple and predictable here.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:53,000 --> 00:13:58,000
|
| 627 |
+
So we have just learned how to perform basic CRUD operations with our entities.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:59,000 --> 00:14:07,000
|
| 631 |
+
We also learned what kind of state between entity and persistent context can be and how to manage this
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:14:07,000 --> 00:14:08,000
|
| 635 |
+
state.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:14:08,000 --> 00:14:09,000
|
| 639 |
+
Amazing.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:14:09,000 --> 00:14:12,000
|
| 643 |
+
Let's proceed with our agenda.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:13,000 --> 00:14:20,000
|
| 647 |
+
Also in this lesson, I was about to show you life cycle events and how we can handle them.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:14:21,000 --> 00:14:30,000
|
| 651 |
+
When we work with GP and zero different lifecycle events that we can work with, we can programme our
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:14:30,000 --> 00:14:39,000
|
| 655 |
+
logic in order to react on this lifecycle events and put any business logic we need in event handlers.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:14:40,000 --> 00:14:45,000
|
| 659 |
+
So Mark Masters, as events handlers, we have to use annotations.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:46,000 --> 00:14:49,000
|
| 663 |
+
I am going to show you annotations now.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:49,000 --> 00:14:55,000
|
| 667 |
+
So what kind of events I'm talking about before?
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:55,000 --> 00:14:59,000
|
| 671 |
+
Persist is called for new entity purposes.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:59,000 --> 00:15:04,000
|
| 675 |
+
Annotation after persist is called for a new entity.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:15:05,000 --> 00:15:10,000
|
| 679 |
+
Post persist annotation before an entity is removed.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:15:10,000 --> 00:15:15,000
|
| 683 |
+
Prior remove annotation after an entity has been deleted.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:15:15,000 --> 00:15:25,000
|
| 687 |
+
Post Remove annotation before the update operation per update annotation after an entity is updated
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:15:26,000 --> 00:15:31,000
|
| 691 |
+
post update annotation after an entity has been loaded.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:15:31,000 --> 00:15:33,000
|
| 695 |
+
Post Load Annotation.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:34,000 --> 00:15:41,000
|
| 699 |
+
So now we know what events we have, how and where we have to use these annotations.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:41,000 --> 00:15:45,000
|
| 703 |
+
There are two ways how we can use these annotations.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:46,000 --> 00:15:54,000
|
| 707 |
+
The first way is to create special event handler masses in the entity and annotate them with annotations
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:54,000 --> 00:15:56,000
|
| 711 |
+
mentioned above.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:56,000 --> 00:16:02,000
|
| 715 |
+
Another option is to create a separate clause that would act as a listener.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:16:03,000 --> 00:16:06,000
|
| 719 |
+
I'm going to show you both options in this lesson.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:16:07,000 --> 00:16:14,000
|
| 723 |
+
If he has turned off my Java from zero to first job course, then you should be aware about event handling
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:16:14,000 --> 00:16:15,000
|
| 727 |
+
concept.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:16:15,000 --> 00:16:23,000
|
| 731 |
+
We even had a separate lesson about handling of the server context, server request and session events.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:16:23,000 --> 00:16:25,000
|
| 735 |
+
So the concept is simple.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:16:26,000 --> 00:16:28,000
|
| 739 |
+
Some event is happening.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:16:28,000 --> 00:16:37,000
|
| 743 |
+
For example, colon persist, mass will trigger an event and the master annotated with annotation purposes
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:37,000 --> 00:16:43,000
|
| 747 |
+
will be called and after record will be inserted into the database.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:43,000 --> 00:16:44,000
|
| 751 |
+
Post persists.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:44,000 --> 00:16:46,000
|
| 755 |
+
The method will be called.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:46,000 --> 00:16:47,000
|
| 759 |
+
Is it clear?
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:48,000 --> 00:16:50,000
|
| 763 |
+
These attachments to the video lesson.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:51,000 --> 00:16:53,000
|
| 767 |
+
You can find the reference to the source code.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:53,000 --> 00:16:55,000
|
| 771 |
+
Examples from the lesson.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:56,000 --> 00:17:01,000
|
| 775 |
+
I encourage you to download the source code and run it on your computer.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:17:02,000 --> 00:17:05,000
|
| 779 |
+
Let me open our user entity clause here.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:17:05,000 --> 00:17:13,000
|
| 783 |
+
You can see that I added masses here and marked them with annotations that we have just reviewed.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:17:13,000 --> 00:17:22,000
|
| 787 |
+
Each event handler method like prep persist or post persist prints its own personalized message.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:17:22,000 --> 00:17:23,000
|
| 791 |
+
Can you see this?
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:24,000 --> 00:17:33,000
|
| 795 |
+
That's how we will be able to identify which method was invoked after investigation of console output.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:34,000 --> 00:17:41,000
|
| 799 |
+
After running our demo file in console output, we can see log messages from entity and from listener
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:41,000 --> 00:17:42,000
|
| 803 |
+
class.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:42,000 --> 00:17:43,000
|
| 807 |
+
One of the last.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:44,000 --> 00:17:52,000
|
| 811 |
+
And to make this class work and intercept events with user entity, we have to add entity listener's
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:52,000 --> 00:17:59,000
|
| 815 |
+
annotation to the user entity and pass single class or array of classes.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:18:00,000 --> 00:18:05,000
|
| 819 |
+
In this particular case, we added the lifecycle listener class here.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:18:05,000 --> 00:18:08,000
|
| 823 |
+
One more important thing to mention.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:18:08,000 --> 00:18:12,000
|
| 827 |
+
Pay attention that matters in our listener class.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:18:12,000 --> 00:18:15,000
|
| 831 |
+
Takes user object as method argument.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:18:16,000 --> 00:18:19,000
|
| 835 |
+
This is user object that participate in event.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:20,000 --> 00:18:27,000
|
| 839 |
+
We can use this reference to the object to create all necessary business logic we need.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:27,000 --> 00:18:33,000
|
| 843 |
+
Now you know how to create event handlers and what is also important.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:33,000 --> 00:18:42,000
|
| 847 |
+
You understood GBA and the lifecycle and when entity is managed in the persistent context and when it
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:42,000 --> 00:18:46,000
|
| 851 |
+
is detached from the persistent context and other states.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:47,000 --> 00:18:50,000
|
| 855 |
+
Let's recap what we have learned in this lesson.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:51,000 --> 00:19:00,000
|
| 859 |
+
In the lesson, we learn how to insert entity into a database, read from the database, updated and
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:19:00,000 --> 00:19:01,000
|
| 863 |
+
remove it.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:19:01,000 --> 00:19:10,000
|
| 867 |
+
Also, we learned states of Gpe entities include a new power system, detached and removed state and
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:19:10,000 --> 00:19:14,000
|
| 871 |
+
we learn how to handle entity lifecycle events.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:19:15,000 --> 00:19:17,000
|
| 875 |
+
That's all for this lesson.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:19:17,000 --> 00:19:19,000
|
| 879 |
+
Thanks a lot for your attention.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:19:19,000 --> 00:19:22,000
|
| 883 |
+
Have a great day and see you in the next lesson.
|
| 884 |
+
|
78 - ORM, JPA & Hibernate/004 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/lifecycle
|
78 - ORM, JPA & Hibernate/005 Locking JPA Optimistic & Pessimistic Locking_en.srt
ADDED
|
@@ -0,0 +1,1320 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:07,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:07,000 --> 00:00:10,000
|
| 7 |
+
Today we're going to have a very interesting lesson.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:10,000 --> 00:00:14,000
|
| 11 |
+
We'll have both theoretical and practical part.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:14,000 --> 00:00:21,000
|
| 15 |
+
It is very important for understanding of how enterprise applications work in the current environment.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:27,000
|
| 19 |
+
Today, we're going to talk about locking optimistic and pessimistic locks.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:28,000 --> 00:00:36,000
|
| 23 |
+
Lennon These topics is important because sometimes you would need to make a decision which lock to apply
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:36,000 --> 00:00:42,000
|
| 27 |
+
in order to optimize query execution and work with entities in the system.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:43,000 --> 00:00:49,000
|
| 31 |
+
We're going to start this lesson from understanding why we need locking.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:49,000 --> 00:00:52,000
|
| 35 |
+
I will explain to you what a database lock is.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:52,000 --> 00:00:54,000
|
| 39 |
+
We will review physical locks.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:54,000 --> 00:00:56,000
|
| 43 |
+
Logical locks.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:56,000 --> 00:01:00,000
|
| 47 |
+
I will explain the different lock and models in the GP.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:00,000 --> 00:01:04,000
|
| 51 |
+
Namely, we're going to talk about optimistic and pessimistic locking.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:05,000 --> 00:01:10,000
|
| 55 |
+
We'll review a version annotation and I will explain you why we need it.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:10,000 --> 00:01:18,000
|
| 59 |
+
Also, I am going to explain explicit log types and we'll review them on the example of lock mode type
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:18,000 --> 00:01:19,000
|
| 63 |
+
enum.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:19,000 --> 00:01:28,000
|
| 67 |
+
And especially for this lesson I prepared coding demo that will help you to understand the topic better.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:28,000 --> 00:01:33,000
|
| 71 |
+
So let's start our lesson before watching this lesson.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:33,000 --> 00:01:38,000
|
| 75 |
+
It is recommended to watch lesson about transaction basics.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:38,000 --> 00:01:45,000
|
| 79 |
+
The lesson is from my job, from zero to first job course, where we learned basics of transactions
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:45,000 --> 00:01:50,000
|
| 83 |
+
and about a main requirements to transactions.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:51,000 --> 00:02:00,000
|
| 87 |
+
Just to remind you that as it stands for automaticity, consistency, isolation and durability also
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:00,000 --> 00:02:08,000
|
| 91 |
+
in some way and the standard of multithreading in topic in Java will help you to build analogy with
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:08,000 --> 00:02:10,000
|
| 95 |
+
lurking in the database.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:10,000 --> 00:02:19,000
|
| 99 |
+
It is not absolutely the same, but as I said, and the standard new topic was analogy is always easier
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:19,000 --> 00:02:22,000
|
| 103 |
+
rather than learning some new topic from scratch.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:23,000 --> 00:02:29,000
|
| 107 |
+
This information will help you better understand the context of the lesson, but you still can proceed
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:29,000 --> 00:02:31,000
|
| 111 |
+
with watching this lesson.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:31,000 --> 00:02:36,000
|
| 115 |
+
And now let's understand why do we need locking?
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:36,000 --> 00:02:43,000
|
| 119 |
+
When we talk about Java enterprise applications, it is very important to handle concurrent operations
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:43,000 --> 00:02:45,000
|
| 123 |
+
to database properly.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:45,000 --> 00:02:53,000
|
| 127 |
+
So we need to handle bulk transactions in a very effective and in a without error way.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:54,000 --> 00:03:01,000
|
| 131 |
+
Also, we need to ensure data consistency between updates and concurrent reads operations.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:03:01,000 --> 00:03:09,000
|
| 135 |
+
In concurrency theory, locking is used for protecting immutable shared data against data integrity
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:09,000 --> 00:03:10,000
|
| 139 |
+
anomalies.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:11,000 --> 00:03:19,000
|
| 143 |
+
Because lock management is a very complex problem, most applications rely on their data provider in
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:19,000 --> 00:03:21,000
|
| 147 |
+
place locking techniques.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:21,000 --> 00:03:28,000
|
| 151 |
+
Delegating is the whole locking responsibility to the database system can both simplify application
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:28,000 --> 00:03:33,000
|
| 155 |
+
development and prevent concurrency issues such as deadlock.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:34,000 --> 00:03:41,000
|
| 159 |
+
But still we need to learn how to work with lock in programmatically in order to achieve better performance
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:41,000 --> 00:03:44,000
|
| 163 |
+
optimization and secure our GP.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:44,000 --> 00:03:49,000
|
| 167 |
+
And that is from lost updates and other concurrent interaction failures.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:50,000 --> 00:03:56,000
|
| 171 |
+
Let's understand what a database lock is and a database log.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:56,000 --> 00:04:03,000
|
| 175 |
+
Only one database user session can update a particular set of data.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:03,000 --> 00:04:11,000
|
| 179 |
+
A database lock prevents two or more users from updating the same piece of data at the same time.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:12,000 --> 00:04:16,000
|
| 183 |
+
So this is why databases have locks.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:17,000 --> 00:04:21,000
|
| 187 |
+
Because imagine the two threads of execution in our program.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:21,000 --> 00:04:27,000
|
| 191 |
+
Read data simultaneously, and the both of them made updates.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:27,000 --> 00:04:31,000
|
| 195 |
+
Which updates should be persisted in the database?
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:31,000 --> 00:04:36,000
|
| 199 |
+
And what rules should be applied in case conflict will be found?
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:37,000 --> 00:04:41,000
|
| 203 |
+
What should we do in case there is a risk of losing one update?
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:41,000 --> 00:04:50,000
|
| 207 |
+
Because another update will erase the first update made from another thread database lock should help
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:50,000 --> 00:04:58,000
|
| 211 |
+
us in answering all these questions by controlling access to the shared resource from different sessions
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:58,000 --> 00:04:59,000
|
| 215 |
+
or threads.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:05:00,000 --> 00:05:09,000
|
| 219 |
+
And database lock is a mechanism that prevents or in other words, controls how the same data is used
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:05:09,000 --> 00:05:10,000
|
| 223 |
+
simultaneously.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:05:11,000 --> 00:05:18,000
|
| 227 |
+
For example, we need to restrict simultaneous right access to the same row in the database to make
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:05:18,000 --> 00:05:21,000
|
| 231 |
+
sure that data will stay consistent.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:22,000 --> 00:05:32,000
|
| 235 |
+
It is necessary to lock down data when multiple users access and update the same data at the same time.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:32,000 --> 00:05:40,000
|
| 239 |
+
Locks are used as a means of synchronizing the access by concurrent transactions to a database item.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:41,000 --> 00:05:48,000
|
| 243 |
+
Most applications tend to ignore thinking about concurrency issues during development, but at the end
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:48,000 --> 00:05:54,000
|
| 247 |
+
of the day, engineering team adds lock mechanism before going to production.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:55,000 --> 00:06:03,000
|
| 251 |
+
If the application will have concurrent writers to the same objects, then the lock in strategy is critical
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:06:03,000 --> 00:06:06,000
|
| 255 |
+
so that data corruption can be prevented.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:06:07,000 --> 00:06:14,000
|
| 259 |
+
Locking is a mechanism that allows parallel work with the same data in the database when more than one
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:06:14,000 --> 00:06:19,000
|
| 263 |
+
transaction tries to access the same data at the same time.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:06:19,000 --> 00:06:26,000
|
| 267 |
+
Locks come into play which ensures that only one of these transactions will change.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:06:26,000 --> 00:06:31,000
|
| 271 |
+
The data database supports two types of locking mechanisms.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:06:31,000 --> 00:06:34,000
|
| 275 |
+
Optimistic model and pessimistic model.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:35,000 --> 00:06:38,000
|
| 279 |
+
Technically there is a search strategy.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:38,000 --> 00:06:45,000
|
| 283 |
+
Ostrich locking on no locking, which means put your head in the sand and ignore the issue.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:46,000 --> 00:06:47,000
|
| 287 |
+
Just a joke.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:48,000 --> 00:06:55,000
|
| 291 |
+
But before learning optimistic and pessimistic walking models, let's talk about physical blocks first.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:55,000 --> 00:07:00,000
|
| 295 |
+
Most database systems use shared and exclusive logs.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:07:01,000 --> 00:07:09,000
|
| 299 |
+
For example, shared logs are used for reading, and exclusive logs are used for writing operations.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:07:10,000 --> 00:07:15,000
|
| 303 |
+
Do you remember read write log from Java concurrent logs package.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:07:15,000 --> 00:07:24,000
|
| 307 |
+
Just as a comparison and analogy, let's remember multiple threats of execution can obtain multiple
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:07:25,000 --> 00:07:29,000
|
| 311 |
+
logs in case there is no right log obtained.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:07:29,000 --> 00:07:34,000
|
| 315 |
+
Because when we read data we don't change its state.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:07:35,000 --> 00:07:44,000
|
| 319 |
+
But when at least one threat obtained write log, we can obtain read more and we can write simultaneously
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:07:44,000 --> 00:07:45,000
|
| 323 |
+
to the same object.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:46,000 --> 00:07:48,000
|
| 327 |
+
That makes perfect sense.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:48,000 --> 00:07:56,000
|
| 331 |
+
The simplest things happening is a database, but instead of objects, our log in elements might be
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:56,000 --> 00:08:00,000
|
| 335 |
+
either rows in the tables or whole tables.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:08:00,000 --> 00:08:05,000
|
| 339 |
+
While physical log is demanded by the SQL standard.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:08:05,000 --> 00:08:08,000
|
| 343 |
+
The pessimistic approach might hinder scalability.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:08:09,000 --> 00:08:14,000
|
| 347 |
+
Modern databases have implemented lightweight logging techniques.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:08:14,000 --> 00:08:21,000
|
| 351 |
+
The implicit database log is hidden behind the transaction isolation level configuration.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:08:22,000 --> 00:08:29,000
|
| 355 |
+
We are going to have a separate lesson about isolation levels and propagation during the transaction.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:08:29,000 --> 00:08:33,000
|
| 359 |
+
So don't worry, we'll learn these topics too.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:08:33,000 --> 00:08:41,000
|
| 363 |
+
Let's learn now more about logical logs and how they're different from the physical logs.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:08:41,000 --> 00:08:49,000
|
| 367 |
+
If database logging is sufficient for batch processing systems and monitor request, that flow spans
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:49,000 --> 00:08:52,000
|
| 371 |
+
over several database transactions.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:52,000 --> 00:09:00,000
|
| 375 |
+
So the real life, real business context, you would need to perform multiple interactions, including
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:09:00,000 --> 00:09:08,000
|
| 379 |
+
interactions with different database systems to perform a single business valuable operation.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:09:08,000 --> 00:09:15,000
|
| 383 |
+
For long conversations, a logical log and mechanism is much more appropriate.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:09:15,000 --> 00:09:19,000
|
| 387 |
+
Logical logs can be configured programmatically.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:09:20,000 --> 00:09:25,000
|
| 391 |
+
But today we'll focus our attention on the locking in the GP.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:09:25,000 --> 00:09:27,000
|
| 395 |
+
Let's discuss it.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:09:28,000 --> 00:09:35,000
|
| 399 |
+
As a database abstraction layer, Gpe can benefit from the implicit blocking mechanisms offered by the
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:09:35,000 --> 00:09:39,000
|
| 403 |
+
underlying relational database management system.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:09:40,000 --> 00:09:47,000
|
| 407 |
+
Four logical looking GPA offers an optional automated entity version control mechanism as well.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:09:48,000 --> 00:09:58,000
|
| 411 |
+
GPS supports explicit lock in for the following operations finding an entity lock in an existing persistence
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:09:58,000 --> 00:10:07,000
|
| 415 |
+
context entity refresh and an entity query through the GPC URL criteria on native queries.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:10:08,000 --> 00:10:17,000
|
| 419 |
+
As I already said, GPA supports two types of working mechanisms optimistic model and pessimistic model.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:10:18,000 --> 00:10:21,000
|
| 423 |
+
Let's learn the difference between these two models.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:10:22,000 --> 00:10:30,000
|
| 427 |
+
Insured optimistic looking is when a record is locked, only when changes are committed to the database,
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:10:30,000 --> 00:10:36,000
|
| 431 |
+
and pessimistic locking is when a record is locked while it is added.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:10:36,000 --> 00:10:44,000
|
| 435 |
+
In both data locking models, the lock is released after the changes are committed is a database.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:10:45,000 --> 00:10:49,000
|
| 439 |
+
Let's learn deeper each of these locking models.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:10:50,000 --> 00:10:59,000
|
| 443 |
+
Optimistic law assumes that the data will not be modified between when you read the data until you write
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:10:59,000 --> 00:10:59,000
|
| 447 |
+
the data.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:11:00,000 --> 00:11:07,000
|
| 451 |
+
This is the most common style of locking used and recommended in today's persistence solutions.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:11:08,000 --> 00:11:16,000
|
| 455 |
+
The strategy involves checking that one or more values from the original object read as still the same
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:11:16,000 --> 00:11:17,000
|
| 459 |
+
when updating it.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:11:18,000 --> 00:11:26,000
|
| 463 |
+
This verifies that the object has not changed by another user in between the read and the run.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:11:26,000 --> 00:11:33,000
|
| 467 |
+
The optimistic log in model also referred to as Optimistic Concurrency Control.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:11:33,000 --> 00:11:42,000
|
| 471 |
+
It is a concurrency control method used in relational databases that doesn't use record locking.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:11:42,000 --> 00:11:51,000
|
| 475 |
+
Optimistic law can allows multiple users to attempt to update the same record without informing the
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:11:51,000 --> 00:11:55,000
|
| 479 |
+
users that others are also attempting to update the record.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:11:56,000 --> 00:12:01,000
|
| 483 |
+
So the record changes are validated only once the record is committed.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:12:02,000 --> 00:12:08,000
|
| 487 |
+
If one user successfully updates the record, they are the users attempting to commit.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:12:08,000 --> 00:12:13,000
|
| 491 |
+
The concurrent updates are informed that a conflict exists.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:12:14,000 --> 00:12:22,000
|
| 495 |
+
An advantage of that reciprocal model is that it avoids the overhead of locking a record for the duration
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:12:22,000 --> 00:12:23,000
|
| 499 |
+
of the action.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:12:24,000 --> 00:12:30,000
|
| 503 |
+
If there are no simultaneous updates, then this model provides fast updates.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:12:30,000 --> 00:12:38,000
|
| 507 |
+
Also in case there are only three operations optimistic law can works just fine.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:12:39,000 --> 00:12:39,000
|
| 511 |
+
Optimistic.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:12:39,000 --> 00:12:46,000
|
| 515 |
+
Walking is a useful approach when concurrent record updates are expected to be infrequent or the lock
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:12:46,000 --> 00:12:48,000
|
| 519 |
+
in overhead is high.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:12:49,000 --> 00:12:56,000
|
| 523 |
+
GPA supports using an optimistic log conversion field that gets update on each update.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:12:57,000 --> 00:13:06,000
|
| 527 |
+
The field can either be numbered or a timestamp value and numeric value is recommended as a numeric
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:13:06,000 --> 00:13:13,000
|
| 531 |
+
value is more precise, portable performance and easier to deal with than a timestamp.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:13:14,000 --> 00:13:22,000
|
| 535 |
+
The version annotation of version element in XML configuration is used to define the optimistic log
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:13:22,000 --> 00:13:23,000
|
| 539 |
+
version filled.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:13:24,000 --> 00:13:33,000
|
| 543 |
+
The annotation is defined on the version field of property for the object similar to an ID mapping.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:13:34,000 --> 00:13:38,000
|
| 547 |
+
The object must contain an attribute to store the version filled.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:13:39,000 --> 00:13:47,000
|
| 551 |
+
The object's version attribute is automatically updated by the GPA provider and should not normally
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:13:47,000 --> 00:13:49,000
|
| 555 |
+
be modified by the application.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:13:50,000 --> 00:13:57,000
|
| 559 |
+
The one exception is if the application reads, the object in one transaction sends the object to the
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:13:57,000 --> 00:14:03,000
|
| 563 |
+
client and updates merges the object in another transaction.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:14:03,000 --> 00:14:09,000
|
| 567 |
+
In this case, the application must ensure that the original object version is used.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:14:10,000 --> 00:14:16,000
|
| 571 |
+
Otherwise, any changes in between read and write will not be detected.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:14:17,000 --> 00:14:24,000
|
| 575 |
+
When the lock in contention is detected and optimistic, lock exception will be strong.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:14:24,000 --> 00:14:32,000
|
| 579 |
+
This will be wrapped inside the rollback exception or the exceptions if using GTA, but it should be
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:14:32,000 --> 00:14:35,000
|
| 583 |
+
set as a course of the exception.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:14:35,000 --> 00:14:43,000
|
| 587 |
+
The application can handle exception, but should normally report the error to the user and let them
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:14:43,000 --> 00:14:44,000
|
| 591 |
+
determine what to do.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:14:45,000 --> 00:14:54,000
|
| 595 |
+
The pessimistic lock model prevents simultaneous updates to records as soon as one user starts to update
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:14:54,000 --> 00:14:55,000
|
| 599 |
+
the record.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:14:56,000 --> 00:14:58,000
|
| 603 |
+
A log is placed on it.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:14:59,000 --> 00:15:07,000
|
| 607 |
+
Other users who attempt to update this record are informed that another user has an update in progress.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:15:08,000 --> 00:15:17,000
|
| 611 |
+
The other users must wait until the first user has finished committing their changes, thereby releasing
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:15:17,000 --> 00:15:18,000
|
| 615 |
+
the record log.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:15:18,000 --> 00:15:25,000
|
| 619 |
+
Only then another user can make changes based on the previous user's changes.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:15:26,000 --> 00:15:35,000
|
| 623 |
+
The main issues with pessimistic logging is that they use database resources, so require a database
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:15:35,000 --> 00:15:40,000
|
| 627 |
+
transaction and connection to be held open for the duration of the ad.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:15:41,000 --> 00:15:46,000
|
| 631 |
+
This is typically not desirable for interactive web applications.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:15:47,000 --> 00:15:52,000
|
| 635 |
+
A simplistic logging can also have concurrency issues and cause deadlocks.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:15:53,000 --> 00:16:01,000
|
| 639 |
+
The main advantage of pessimistic logging is that once the log is obtained, it is fairly certain that
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:16:01,000 --> 00:16:03,000
|
| 643 |
+
the ad will be successful.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:16:03,000 --> 00:16:11,000
|
| 647 |
+
This can be desirable in highly concurrent applications, where optimistic law can make cause to many
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:16:11,000 --> 00:16:20,000
|
| 651 |
+
optimistic logging errors during the pessimistic logging updates as serialized and each subsequent update
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:16:20,000 --> 00:16:24,000
|
| 655 |
+
starts with a committed record changes from the previous user.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:16:25,000 --> 00:16:32,000
|
| 659 |
+
Pessimistic looking is a useful approach when subsequent updates can be delayed until a previous update
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:16:32,000 --> 00:16:33,000
|
| 663 |
+
is completed.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:16:34,000 --> 00:16:39,000
|
| 667 |
+
This usually implies that updates appear in a short time interval.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:16:40,000 --> 00:16:42,000
|
| 671 |
+
Let's have a small demo now.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:16:42,000 --> 00:16:47,000
|
| 675 |
+
I will explain you explicit log types using the source code.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:16:48,000 --> 00:16:56,000
|
| 679 |
+
As you already saw in the previous lesson, when we talked about basic operations with entities, there
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:16:56,000 --> 00:17:01,000
|
| 683 |
+
is an API that allows us to specify lock mode type.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:17:02,000 --> 00:17:09,000
|
| 687 |
+
For example, if you remember fired last, there is an overloaded version that takes a lock mode type
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:17:09,000 --> 00:17:12,000
|
| 691 |
+
enum as one of the massive arguments.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:17:13,000 --> 00:17:19,000
|
| 695 |
+
There is also a loaded version of a fresh message that also uses this enum.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:17:19,000 --> 00:17:25,000
|
| 699 |
+
There is a separate method in the entity manager tab that is called lock to lock entity.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:17:25,000 --> 00:17:26,000
|
| 703 |
+
Vividly.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:17:26,000 --> 00:17:35,000
|
| 707 |
+
So let's review now lock mode type enum and understand a little bit more when we should use which in
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:17:36,000 --> 00:17:39,000
|
| 711 |
+
the first one in the list is read.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:17:39,000 --> 00:17:42,000
|
| 715 |
+
Read is same as optimistic.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:17:43,000 --> 00:17:47,000
|
| 719 |
+
Just a synonym that you can use to increase readability of your code.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:17:48,000 --> 00:17:51,000
|
| 723 |
+
Optimistic is obviously optimistic.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:17:51,000 --> 00:17:54,000
|
| 727 |
+
Lock always issues aversion.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:17:54,000 --> 00:17:55,000
|
| 731 |
+
Check upon transaction.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:17:55,000 --> 00:18:01,000
|
| 735 |
+
Coming to the end of the lesson, I'm going to show you how to set the version.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:18:01,000 --> 00:18:02,000
|
| 739 |
+
Right.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:18:02,000 --> 00:18:06,000
|
| 743 |
+
Is a signal this optimistic force increment.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:18:07,000 --> 00:18:15,000
|
| 747 |
+
Optimistic force increment always increases the entity version even when the entity doesn't change and
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:18:15,000 --> 00:18:19,000
|
| 751 |
+
issue aversion check upon transaction commit.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:18:19,000 --> 00:18:20,000
|
| 755 |
+
Today.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:18:20,000 --> 00:18:22,000
|
| 759 |
+
We're going to see this on example.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:18:23,000 --> 00:18:24,000
|
| 763 |
+
Pessimistic.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:18:24,000 --> 00:18:31,000
|
| 767 |
+
Read is a shared blog that is acquired to prevent any other transaction from acquiring a pessimistic
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:18:31,000 --> 00:18:33,000
|
| 771 |
+
right lobe.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:18:33,000 --> 00:18:41,000
|
| 775 |
+
So in simple words, manage threats, manage transactions, can acquire pessimistic, read, log.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:18:42,000 --> 00:18:49,000
|
| 779 |
+
And while at least one transaction holds this law, no one else can obtain pessimistic write log.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:18:50,000 --> 00:18:52,000
|
| 783 |
+
Everything is easy and logical.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:18:53,000 --> 00:19:01,000
|
| 787 |
+
Pessimistic write log is an exclusive log as it is acquired to prevent any other transaction from acquiring
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:19:01,000 --> 00:19:05,000
|
| 791 |
+
a pessimistic read or a pessimistic write log.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:19:06,000 --> 00:19:15,000
|
| 795 |
+
Exclusive log means that only one transaction can hold this log, and while this log is held by transaction,
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:19:15,000 --> 00:19:22,000
|
| 799 |
+
no other transactions can obtain pessimistic read a pessimistic write lock.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:19:22,000 --> 00:19:30,000
|
| 803 |
+
Pessimistic force increment is a database log that is acquired to prevent any other transaction from
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:19:30,000 --> 00:19:34,000
|
| 807 |
+
acquiring a pessimistic read or a pessimistic write log.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:19:34,000 --> 00:19:42,000
|
| 811 |
+
And the entity version is incremented upon transaction permit and now means that there is no log.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:19:43,000 --> 00:19:51,000
|
| 815 |
+
And now let's use a small example that I have prepared for this lesson in the package that is called
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:19:51,000 --> 00:19:52,000
|
| 819 |
+
walking.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:19:52,000 --> 00:19:58,000
|
| 823 |
+
You can find again user class and city manager, helper and demo class.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:19:59,000 --> 00:20:02,000
|
| 827 |
+
Let me start from entity manager helper class.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:20:02,000 --> 00:20:09,000
|
| 831 |
+
The thing is, as we discussed in the first lessons when we have just started to learn what entity,
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:20:09,000 --> 00:20:18,000
|
| 835 |
+
manager, factory and entity manager are, I told you that entity manager is not a threat safe and using
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:20:18,000 --> 00:20:23,000
|
| 839 |
+
entity manager from different threats requires some extra attention.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:20:24,000 --> 00:20:32,000
|
| 843 |
+
Taking into account that in this lesson I need to show you a multithreading example imitating multiple
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:20:32,000 --> 00:20:36,000
|
| 847 |
+
requests and multiple usage of entity manager from different threats.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:20:37,000 --> 00:20:45,000
|
| 851 |
+
We also need to prepare entity manager for work in multi threat environment, considering that in this
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:20:45,000 --> 00:20:51,000
|
| 855 |
+
part of the course we're focusing on non and purely GP and hibernate.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:20:51,000 --> 00:21:00,000
|
| 859 |
+
I am not adding Sprint to our examples so far because not necessarily you will use spring on your future
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:21:00,000 --> 00:21:01,000
|
| 863 |
+
project.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:21:01,000 --> 00:21:10,000
|
| 867 |
+
And anyway, you need to understand how GPA and GPA implementations work to have solid understanding
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:21:10,000 --> 00:21:14,000
|
| 871 |
+
and be able to fix issues in case of any.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:21:14,000 --> 00:21:22,000
|
| 875 |
+
So in this entity manager helper class, I create one instance of entity manager factory.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:21:22,000 --> 00:21:29,000
|
| 879 |
+
That is fine because it is recommended to have only one instance of entity manager factory across all
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:21:29,000 --> 00:21:35,000
|
| 883 |
+
the app and it is red safe, so we shouldn't face any problems with that.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:21:35,000 --> 00:21:44,000
|
| 887 |
+
And that great instance of threat lock using spring would make things easier because of the dependency
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:21:44,000 --> 00:21:45,000
|
| 891 |
+
injection management.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:21:46,000 --> 00:21:50,000
|
| 895 |
+
Spring would handle all these things under the hood.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:21:51,000 --> 00:21:57,000
|
| 899 |
+
Please check the section about multithreading in my java from zero to first job course.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:21:57,000 --> 00:22:01,000
|
| 903 |
+
In that section we also learn what the thread local is.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:22:02,000 --> 00:22:11,000
|
| 907 |
+
That's why I wouldn't stop on this much, but ensure thread local object stores thread local variables.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:22:11,000 --> 00:22:17,000
|
| 911 |
+
Basically in each thread there will be a different variable inside this object.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:22:18,000 --> 00:22:24,000
|
| 915 |
+
This object like a container that will store different variables depending on the scrap.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:22:25,000 --> 00:22:33,000
|
| 919 |
+
You can imagine it like a map where the key will be the name of the spread and the value will be actually
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:22:33,000 --> 00:22:35,000
|
| 923 |
+
value associated with this thread.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:22:36,000 --> 00:22:41,000
|
| 927 |
+
Using spread local looking store entity manager specific to each threat.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:22:42,000 --> 00:22:50,000
|
| 931 |
+
And here you can find some helpless masses to get entity manager and close entity manager to close.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:22:50,000 --> 00:22:51,000
|
| 935 |
+
Entity manager.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:22:51,000 --> 00:22:54,000
|
| 939 |
+
Factory and helper masses to begin.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:22:54,000 --> 00:22:56,000
|
| 943 |
+
Roll back and commit transactions.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:22:57,000 --> 00:23:03,000
|
| 947 |
+
Let me open now user class like we already discussed in the lesson.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:23:03,000 --> 00:23:09,000
|
| 951 |
+
I created a field of type that is annotated with the version annotation.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:23:10,000 --> 00:23:18,000
|
| 955 |
+
Depending on the log mode types that I'm going to use, the version of the entity will be updated and
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:23:18,000 --> 00:23:21,000
|
| 959 |
+
now I'm going to show it to you.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:23:22,000 --> 00:23:27,000
|
| 963 |
+
I open a demo clause, we create one user and persisted.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:23:27,000 --> 00:23:32,000
|
| 967 |
+
In the class I use entity manager helper that I already showed you.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:23:33,000 --> 00:23:38,000
|
| 971 |
+
After that, I'm going to execute this same operation two times in different threads.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:23:39,000 --> 00:23:42,000
|
| 975 |
+
Let's understand what I do here.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:23:42,000 --> 00:23:45,000
|
| 979 |
+
I get the reference to the entity manager.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:23:45,000 --> 00:23:47,000
|
| 983 |
+
I start the transaction.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:23:48,000 --> 00:23:56,000
|
| 987 |
+
I find the users that I've just created and pay attention that this code will be executed two times
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:23:56,000 --> 00:23:58,000
|
| 991 |
+
in different threads.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:23:58,000 --> 00:23:59,000
|
| 995 |
+
Is it clear?
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:23:59,000 --> 00:24:08,000
|
| 999 |
+
I use execute the service to submit my tasks and again how to work with the execute the service we learn
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:24:08,000 --> 00:24:12,000
|
| 1003 |
+
in the Multithreading section of my Java from zero to first job course.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:24:12,000 --> 00:24:15,000
|
| 1007 |
+
That's why I don't stop on this.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:24:15,000 --> 00:24:23,000
|
| 1011 |
+
So each of the threads will have the reference to is actually the same record in the database.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:24:23,000 --> 00:24:28,000
|
| 1015 |
+
Is it clear because each thread will find the same user?
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:24:29,000 --> 00:24:34,000
|
| 1019 |
+
After that I take the name of the thread for the login purposes.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:24:34,000 --> 00:24:36,000
|
| 1023 |
+
We change email of the user.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:24:37,000 --> 00:24:46,000
|
| 1027 |
+
New email will contain the name of the thread and we'll explore later what email will have our user
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:24:46,000 --> 00:24:47,000
|
| 1031 |
+
at them.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:24:48,000 --> 00:24:52,000
|
| 1035 |
+
After that, I call Loch Mascot and our entity manager.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:24:52,000 --> 00:24:55,000
|
| 1039 |
+
I paused the entity and Locke mode type.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:24:56,000 --> 00:25:03,000
|
| 1043 |
+
I'm going to show you how our program will behave in case of the optimistic and pessimistic Locke.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:25:04,000 --> 00:25:08,000
|
| 1047 |
+
And then we print which thread obtained is log?
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:25:08,000 --> 00:25:14,000
|
| 1051 |
+
It will be important for understanding the difference between optimistic and pessimistic log.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:25:14,000 --> 00:25:21,000
|
| 1055 |
+
We can meet our transaction and also we print version and email here.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:25:21,000 --> 00:25:24,000
|
| 1059 |
+
Put exception handler and print stack.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:25:24,000 --> 00:25:27,000
|
| 1063 |
+
Trace the console to show you the exception.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:25:27,000 --> 00:25:34,000
|
| 1067 |
+
That will happen when we will try to commit changes to the same entity from different spread.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:25:35,000 --> 00:25:42,000
|
| 1071 |
+
And as am here, I just shut down the execution service that they used to submit tasks to different
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:25:42,000 --> 00:25:45,000
|
| 1075 |
+
threats and the close and the manager factory.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:25:46,000 --> 00:25:47,000
|
| 1079 |
+
That's where I'm now.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:25:47,000 --> 00:25:55,000
|
| 1083 |
+
Our application is the first one will be with pessimistic force increment, lock mode type.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:25:57,000 --> 00:26:00,000
|
| 1087 |
+
And now let's investigate console output here.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:26:01,000 --> 00:26:02,000
|
| 1091 |
+
What do we have here?
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:26:03,000 --> 00:26:11,000
|
| 1095 |
+
We see that the first thread was about to obtain a lock on user entity and the second threat was about
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:26:11,000 --> 00:26:12,000
|
| 1099 |
+
to do the same.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:26:12,000 --> 00:26:17,000
|
| 1103 |
+
And we can see that only one thread managed to obtain the lock.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:26:18,000 --> 00:26:25,000
|
| 1107 |
+
You can see that user version of the commit has been changed and in the email we have the name of the
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:26:25,000 --> 00:26:28,000
|
| 1111 |
+
thread that managed to obtain the log.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:26:29,000 --> 00:26:31,000
|
| 1115 |
+
What happened was another thread.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:26:32,000 --> 00:26:37,000
|
| 1119 |
+
And now the threat has been interrupted by optimistic exception.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:26:37,000 --> 00:26:41,000
|
| 1123 |
+
Roe was updated or deleted by another transaction.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:26:41,000 --> 00:26:45,000
|
| 1127 |
+
This exception in term is caused by stale objects.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:26:45,000 --> 00:26:47,000
|
| 1131 |
+
State exception.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:26:47,000 --> 00:26:51,000
|
| 1135 |
+
Exception happened in zero three of this demo file.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:26:52,000 --> 00:26:55,000
|
| 1139 |
+
What conclusion we can make out of this.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:26:55,000 --> 00:27:04,000
|
| 1143 |
+
So in case once we had obtained a pessimistic log on an entity and another thread can obtain pessimistic
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:27:04,000 --> 00:27:06,000
|
| 1147 |
+
log on the same entity.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:27:07,000 --> 00:27:13,000
|
| 1151 |
+
An exception happened during the attempt of obtaining such log is a clear.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:27:14,000 --> 00:27:17,000
|
| 1155 |
+
Let me comment another type of blog.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:27:17,000 --> 00:27:20,000
|
| 1159 |
+
Let me run the program one more time.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:27:20,000 --> 00:27:28,000
|
| 1163 |
+
But this time we will try to understand how optimistic force, incremental work mode type impacts execution
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:27:28,000 --> 00:27:37,000
|
| 1167 |
+
of our threats, like we discussed in case of optimistic lock to threats, managed to obtain the lock,
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:27:37,000 --> 00:27:41,000
|
| 1171 |
+
but only one threat managed to commit changes.
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:27:42,000 --> 00:27:45,000
|
| 1175 |
+
You can see this from lock messages.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:27:45,000 --> 00:27:48,000
|
| 1179 |
+
Explore them to on your computer.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:27:48,000 --> 00:27:54,000
|
| 1183 |
+
You will be able to find the reference to this source code example in attachments to the video.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:27:55,000 --> 00:27:59,000
|
| 1187 |
+
And what happened was the second threat in this case.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:27:59,000 --> 00:28:01,000
|
| 1191 |
+
Let's find this out.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:28:02,000 --> 00:28:09,000
|
| 1195 |
+
This time we have rolled back exception error while committing the transaction, which is caused by
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:28:09,000 --> 00:28:12,000
|
| 1199 |
+
optimistic lock exception.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:28:12,000 --> 00:28:22,000
|
| 1203 |
+
ROE was updated or deleted by another transaction, which in turn caused by stale object state exception.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:28:22,000 --> 00:28:32,000
|
| 1207 |
+
But let's understand in vitro, as you can see from logs here, this time exception happened in zero
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:28:32,000 --> 00:28:33,000
|
| 1211 |
+
37.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:28:33,000 --> 00:28:41,000
|
| 1215 |
+
So the error happened when I tried to commit transaction with updated entity that was updated already
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:28:41,000 --> 00:28:42,000
|
| 1219 |
+
by another scrap.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:28:42,000 --> 00:28:47,000
|
| 1223 |
+
So can you see that exception happened on the later stage?
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:28:48,000 --> 00:28:56,000
|
| 1227 |
+
That is because when we use optimistic log, we still allow other threats to obtain the lock on the
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:28:56,000 --> 00:28:57,000
|
| 1231 |
+
same entity.
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:28:57,000 --> 00:29:00,000
|
| 1235 |
+
This is helpful for reading operations.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:29:01,000 --> 00:29:02,000
|
| 1239 |
+
For example.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:29:02,000 --> 00:29:03,000
|
| 1243 |
+
One Multiple threats.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:29:03,000 --> 00:29:08,000
|
| 1247 |
+
Read information about my user and news of threats.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:29:08,000 --> 00:29:09,000
|
| 1251 |
+
Update the user.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:29:09,000 --> 00:29:17,000
|
| 1255 |
+
In this case, there is no need to block access to the entity, but still there is a need to prevent
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:29:17,000 --> 00:29:22,000
|
| 1259 |
+
multiple updates from different threats in order to avoid cases.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:29:22,000 --> 00:29:29,000
|
| 1263 |
+
When updates from one threat will erase objects from another threat, is it clear?
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:29:30,000 --> 00:29:33,000
|
| 1267 |
+
I believe that now it is more clear for you.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:29:33,000 --> 00:29:37,000
|
| 1271 |
+
What is the difference between optimistic and pessimistic looking?
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:29:38,000 --> 00:29:45,000
|
| 1275 |
+
Even in case you still have any questions, please do not hesitate to ask your questions below the video
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:29:45,000 --> 00:29:47,000
|
| 1279 |
+
and I will be happy to answer.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:29:47,000 --> 00:29:51,000
|
| 1283 |
+
So that's all what I wanted to discuss with you today.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:29:52,000 --> 00:29:55,000
|
| 1287 |
+
Let's recap what we have learned in this lesson.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:29:56,000 --> 00:30:01,000
|
| 1291 |
+
In this lesson, we learned what a database law is and why do we need it.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:30:02,000 --> 00:30:05,000
|
| 1295 |
+
We learned what physical logs are.
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:30:05,000 --> 00:30:08,000
|
| 1299 |
+
I explained what the logical logs are.
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:30:09,000 --> 00:30:16,000
|
| 1303 |
+
William Larkin in GP, I explained the optimistic and pessimistic working models.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:30:17,000 --> 00:30:24,000
|
| 1307 |
+
We learned explicit work types in lock mode, type in them and saw the coding example.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:30:25,000 --> 00:30:26,000
|
| 1311 |
+
That's it for today.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:30:27,000 --> 00:30:28,000
|
| 1315 |
+
Thanks a lot for your attention.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:30:28,000 --> 00:30:31,000
|
| 1319 |
+
Have a great day and see you in the next lesson.
|
| 1320 |
+
|
78 - ORM, JPA & Hibernate/005 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/locking
|
78 - ORM, JPA & Hibernate/006 Relationships Between Entities_en.srt
ADDED
|
@@ -0,0 +1,1080 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:07,000
|
| 3 |
+
Hello, team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:07,000 --> 00:00:11,000
|
| 7 |
+
In this lesson, we're going to learn relationships between entities.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:11,000 --> 00:00:17,000
|
| 11 |
+
It is very important topic because very often we use relations between different types.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:18,000 --> 00:00:25,000
|
| 15 |
+
Today we are going to learn everything you need to know to be able to use relations in GPA like a pro.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:25,000 --> 00:00:30,000
|
| 19 |
+
And also we'll review code examples to get some practical skills.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:31,000 --> 00:00:39,000
|
| 23 |
+
We'll start our lesson from understanding of the use case, namely when we need to use mapping in GPA
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:39,000 --> 00:00:41,000
|
| 27 |
+
to understand the topic better.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:41,000 --> 00:00:48,000
|
| 31 |
+
I believe it is important for us to recall types of relationships in the relational databases.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:48,000 --> 00:00:53,000
|
| 35 |
+
We'll review mapping the reactions and types of mapping in GPA.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:53,000 --> 00:01:00,000
|
| 39 |
+
Today, I'm going to show you on real examples how you can apply such annotations as 1 to 1.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:01:01,000 --> 00:01:02,000
|
| 43 |
+
One to many.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:02,000 --> 00:01:03,000
|
| 47 |
+
And many to one.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:03,000 --> 00:01:04,000
|
| 51 |
+
And many to many.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:05,000 --> 00:01:12,000
|
| 55 |
+
Also we're going to review Cascade, Type, enum, and I will show you in practice how to use Cascade
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:12,000 --> 00:01:12,000
|
| 59 |
+
type.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:13,000 --> 00:01:17,000
|
| 63 |
+
I will explain what EGA and laser fetch types are.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:17,000 --> 00:01:21,000
|
| 67 |
+
And besides that, we're going to have practical examples today.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:21,000 --> 00:01:28,000
|
| 71 |
+
During the examples, we're going to run such annotations as June column and join table, and you will
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:28,000 --> 00:01:31,000
|
| 75 |
+
understand the difference between them.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:31,000 --> 00:01:33,000
|
| 79 |
+
Let's start our lesson.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:34,000 --> 00:01:35,000
|
| 83 |
+
Let's learn first.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:35,000 --> 00:01:41,000
|
| 87 |
+
Why do we need relations in the GP and what challenge would try to solve?
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:41,000 --> 00:01:46,000
|
| 91 |
+
I want you understand why we need relationships between GP entities.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:47,000 --> 00:01:55,000
|
| 95 |
+
Imagine that we have a user entity and our user has collection of orders that he or she did in our online
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:55,000 --> 00:02:01,000
|
| 99 |
+
shop and we need to show list of orders in the profile of our user.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:01,000 --> 00:02:10,000
|
| 103 |
+
So the show list of orders in the profile, we need to prepare this information inside our Java application.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:10,000 --> 00:02:11,000
|
| 107 |
+
Agreed.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:11,000 --> 00:02:18,000
|
| 111 |
+
And technically speaking, we need to make sure that we have a list of purchases inside our user object.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:19,000 --> 00:02:28,000
|
| 115 |
+
GPA allows us to build such kind of connections and also GP allows us to configure other types of relationships.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:29,000 --> 00:02:32,000
|
| 119 |
+
We're going to review all of them in the lesson.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:32,000 --> 00:02:34,000
|
| 123 |
+
That's what we are going to learn today.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:35,000 --> 00:02:41,000
|
| 127 |
+
But the first thing that we need to remember is the things that we learned in the relational database
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:41,000 --> 00:02:44,000
|
| 131 |
+
section of my Java from zero to first jump course.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:45,000 --> 00:02:50,000
|
| 135 |
+
If you remember, we learned types of relationships in the relational databases.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:50,000 --> 00:02:56,000
|
| 139 |
+
I don't want to repeat myself too much, so please refer to that lesson.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:56,000 --> 00:03:04,000
|
| 143 |
+
I will just quickly remind you, because this is important in relational databases, we have three types
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:04,000 --> 00:03:05,000
|
| 147 |
+
of relationships.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:05,000 --> 00:03:07,000
|
| 151 |
+
They are one too many.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:07,000 --> 00:03:15,000
|
| 155 |
+
It is the case when one record and one table is associated with multiple records in the table.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:15,000 --> 00:03:24,000
|
| 159 |
+
For example, each car has owner, but each owner can have multiple cores, many to many.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:24,000 --> 00:03:31,000
|
| 163 |
+
It is the case when one record from one table may be associated with many records from another table
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:31,000 --> 00:03:38,000
|
| 167 |
+
and one record from another table can be associated with many records from the first table.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:38,000 --> 00:03:41,000
|
| 171 |
+
For example, doctor and patients.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:42,000 --> 00:03:49,000
|
| 175 |
+
Each doctor can have multiple patients and different patients can meet different doctors.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:49,000 --> 00:03:51,000
|
| 179 |
+
So it's many, many.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:52,000 --> 00:03:54,000
|
| 183 |
+
And 1 to 1 relationship.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:54,000 --> 00:04:01,000
|
| 187 |
+
It is one one record and one table is associated with only one record from another table.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:01,000 --> 00:04:04,000
|
| 191 |
+
This is very rare case.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:04,000 --> 00:04:12,000
|
| 195 |
+
For example, each person has only one passport and only one passport can be associated with one person.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:13,000 --> 00:04:20,000
|
| 199 |
+
This is important to learn to understand GP and a patients that will be discussed in this lesson.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:20,000 --> 00:04:24,000
|
| 203 |
+
The next thing that we need to learn is mapping directions.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:25,000 --> 00:04:32,000
|
| 207 |
+
It is relatively simple and logical scene to understand, but still, let me quickly cover this to make
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:32,000 --> 00:04:35,000
|
| 211 |
+
sure that we are on the same page.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:36,000 --> 00:04:39,000
|
| 215 |
+
We can divide mapping directions into two parts.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:40,000 --> 00:04:47,000
|
| 219 |
+
You need directional relationship in this relationship on the one and that you can refer the properties
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:47,000 --> 00:04:48,000
|
| 223 |
+
to analysis.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:49,000 --> 00:04:56,000
|
| 227 |
+
It contains only one own insights that specifies how an update can be made in the database.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:57,000 --> 00:04:59,000
|
| 231 |
+
BI Directional Relationship.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:00,000 --> 00:05:06,000
|
| 235 |
+
The relationship contains an own insight as well as an inverse side.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:06,000 --> 00:05:12,000
|
| 239 |
+
So here every entity has a relationship field or refers a property to other entity.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:13,000 --> 00:05:18,000
|
| 243 |
+
As you can see, the main difference here is who owns the relationship.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:18,000 --> 00:05:24,000
|
| 247 |
+
In case of interaction or relationship, only one side owns the relationship.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:24,000 --> 00:05:29,000
|
| 251 |
+
In case of bidirectional relationship, two sides.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:30,000 --> 00:05:38,000
|
| 255 |
+
Now let's learn types of mappings in GP and also let's learn some key annotations that will help us
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:38,000 --> 00:05:40,000
|
| 259 |
+
to configure this map and.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:41,000 --> 00:05:48,000
|
| 263 |
+
Types of mapping can be obviously connected with possible types of relationships in the database.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:48,000 --> 00:05:55,000
|
| 267 |
+
That's why I decided to remind users at the beginning of the lesson, and I'm sure that now it will
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:55,000 --> 00:05:59,000
|
| 271 |
+
be easier for you to remember GP types.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:59,000 --> 00:06:03,000
|
| 275 |
+
There are four types of mapping 1 to 1.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:04,000 --> 00:06:09,000
|
| 279 |
+
This association is represented by 1 to 1 annotation here.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:10,000 --> 00:06:15,000
|
| 283 |
+
Instance of each entity is related to a single instance of another entity.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:16,000 --> 00:06:17,000
|
| 287 |
+
One too many.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:17,000 --> 00:06:22,000
|
| 291 |
+
This association is represented by one to many annotation.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:22,000 --> 00:06:29,000
|
| 295 |
+
In this relationship, an instance of one entity can be related to more than one instance of another
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:29,000 --> 00:06:32,000
|
| 299 |
+
entity, many to one.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:32,000 --> 00:06:36,000
|
| 303 |
+
This map is defined by many to one annotation.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:36,000 --> 00:06:43,000
|
| 307 |
+
In this relationship, multiple instances of an entity can be related to a single instance of another
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:43,000 --> 00:06:44,000
|
| 311 |
+
entity.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:44,000 --> 00:06:51,000
|
| 315 |
+
So as you can see, there is a difference only in what is the direction of the relationship.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:51,000 --> 00:06:55,000
|
| 319 |
+
In the case there is a bi directional relationship.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:55,000 --> 00:07:02,000
|
| 323 |
+
You can use one to many annotation in one entity and manage one annotation in another entity.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:02,000 --> 00:07:03,000
|
| 327 |
+
Many to many.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:04,000 --> 00:07:06,000
|
| 331 |
+
This association is represented by.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:06,000 --> 00:07:08,000
|
| 335 |
+
Many to many annotation.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:08,000 --> 00:07:16,000
|
| 339 |
+
Here, multiple instances of an entity can be related to multiple instances of another entity.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:16,000 --> 00:07:20,000
|
| 343 |
+
In this mapping, any site can be the own inside.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:21,000 --> 00:07:27,000
|
| 347 |
+
In the source code, we can use different types of containers to ensure mappings.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:27,000 --> 00:07:36,000
|
| 351 |
+
For example, we can use either least set or map types for properties that will be used to establish
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:36,000 --> 00:07:37,000
|
| 355 |
+
relationships.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:38,000 --> 00:07:41,000
|
| 359 |
+
Today, during the demo, I'm going to show you this.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:41,000 --> 00:07:46,000
|
| 363 |
+
Now let's learn relationships by examples.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:46,000 --> 00:07:49,000
|
| 367 |
+
I prepared a series of examples for you.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:49,000 --> 00:07:52,000
|
| 371 |
+
Let's use them to understand the topic better.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:53,000 --> 00:07:58,000
|
| 375 |
+
The first examples we're going to review now is 1 to 1 relationship.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:59,000 --> 00:08:02,000
|
| 379 |
+
Imagine the case that we have a user in the system.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:03,000 --> 00:08:12,000
|
| 383 |
+
Each user has only one user profile associated with it, and each user profile can have on the one user
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:12,000 --> 00:08:14,000
|
| 387 |
+
that is associated with it.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:15,000 --> 00:08:18,000
|
| 391 |
+
So here we have a 1 to 1 relationship.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:19,000 --> 00:08:21,000
|
| 395 |
+
How we can configure this in GB.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:22,000 --> 00:08:23,000
|
| 399 |
+
Let me show it to you.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:23,000 --> 00:08:29,000
|
| 403 |
+
All examples from this lesson will be stored in the package that is called mapping.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:30,000 --> 00:08:38,000
|
| 407 |
+
You can find source for examples in attachment to the lesson just in case you want to download the code
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:38,000 --> 00:08:41,000
|
| 411 |
+
and run it on your computer to learn examples better.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:42,000 --> 00:08:44,000
|
| 415 |
+
So I created user entity.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:45,000 --> 00:08:51,000
|
| 419 |
+
You already know how to use column annotation and annotation and generated value annotations.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:52,000 --> 00:08:53,000
|
| 423 |
+
We learned all this.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:53,000 --> 00:09:00,000
|
| 427 |
+
That's why I didn't put a lot of configurations here in order to not lose focus from the main thing
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:00,000 --> 00:09:01,000
|
| 431 |
+
in the lesson.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:02,000 --> 00:09:05,000
|
| 435 |
+
Here is a user profile filled with annotation.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:05,000 --> 00:09:06,000
|
| 439 |
+
One, two, one.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:06,000 --> 00:09:09,000
|
| 443 |
+
Let's run this annotation better.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:09,000 --> 00:09:13,000
|
| 447 |
+
I encourage you to use the source code of this annotation.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:13,000 --> 00:09:16,000
|
| 451 |
+
There are different attributes that you can use.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:16,000 --> 00:09:18,000
|
| 455 |
+
Most of them are optional.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:19,000 --> 00:09:23,000
|
| 459 |
+
Let me just highlight the most interesting attributes in my opinion.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:24,000 --> 00:09:30,000
|
| 463 |
+
Cascade attribute is important one, and probably the one that is used relatively often.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:31,000 --> 00:09:35,000
|
| 467 |
+
You will find the similar attribute in other mappings annotations.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:36,000 --> 00:09:41,000
|
| 471 |
+
So this cascade attribute takes every of the values of cascade type.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:42,000 --> 00:09:51,000
|
| 475 |
+
The escape dipole means that any change happened on one entity must cascade to another entity as well.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:52,000 --> 00:09:58,000
|
| 479 |
+
The Cascade types supported by the Java persistence architecture are as below.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:59,000 --> 00:10:00,000
|
| 483 |
+
Cascade Type Persist.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:01,000 --> 00:10:02,000
|
| 487 |
+
Cascade Type.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:02,000 --> 00:10:05,000
|
| 491 |
+
Persist means that persist operations.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:05,000 --> 00:10:07,000
|
| 495 |
+
Cascade through related entities.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:08,000 --> 00:10:10,000
|
| 499 |
+
Escape type merge.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:10,000 --> 00:10:17,000
|
| 503 |
+
Escape type merge means the two related entities merged when the own entity is merged.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:18,000 --> 00:10:20,000
|
| 507 |
+
The skate tap refresh.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:20,000 --> 00:10:25,000
|
| 511 |
+
The skate tap refresh does the same thing for the refresh operation.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:26,000 --> 00:10:33,000
|
| 515 |
+
Cascade Tap or move cascade tap remove from moves all related entities association with this said when
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:34,000 --> 00:10:36,000
|
| 519 |
+
the own entity is deleted.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:37,000 --> 00:10:42,000
|
| 523 |
+
Escape tab, detach it, detach all related entities.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:42,000 --> 00:10:51,000
|
| 527 |
+
If a nano detach occurs and the escape type all is shorthand for all of the above cascade operations.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:52,000 --> 00:11:00,000
|
| 531 |
+
So in case we have user profile associated with our user object and we have cascade type persist, that
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:00,000 --> 00:11:07,000
|
| 535 |
+
means that user profile will be also persistent one user and that will be persisted.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:07,000 --> 00:11:08,000
|
| 539 |
+
Is it clear?
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:09,000 --> 00:11:16,000
|
| 543 |
+
And now the attributes that I'd like to review with you is fetch by default, eagle fetch type is used.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:17,000 --> 00:11:23,000
|
| 547 |
+
We have two possible options to specify here is an eager or lazy fetch type.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:23,000 --> 00:11:25,000
|
| 551 |
+
So what is the difference?
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:25,000 --> 00:11:29,000
|
| 555 |
+
Well, actually, is this a simple thing to understand?
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:29,000 --> 00:11:33,000
|
| 559 |
+
Lazy fetch type fetch is the child and just lazy.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:34,000 --> 00:11:42,000
|
| 563 |
+
That means that at the time of fetching parent entity it just fetches proxy of the child or related
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:42,000 --> 00:11:43,000
|
| 567 |
+
entities.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:43,000 --> 00:11:50,000
|
| 571 |
+
Actually, there is no query to the database to fetch related entity until you request access to the
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:50,000 --> 00:11:52,000
|
| 575 |
+
property of the child entity.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:52,000 --> 00:12:00,000
|
| 579 |
+
So when you need to access child property of the related entity, only then new request is done to the
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:00,000 --> 00:12:05,000
|
| 583 |
+
database and only then child entity is fetched.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:05,000 --> 00:12:10,000
|
| 587 |
+
Ignore fetch type fetch is the child and that is along with parent.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:11,000 --> 00:12:17,000
|
| 591 |
+
Let's know now mapped by attribute user relationship is bi directional.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:17,000 --> 00:12:27,000
|
| 595 |
+
The non only site must use the map bi element of the 1 to 1 annotation to specify the relationship field
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:27,000 --> 00:12:29,000
|
| 599 |
+
or property of the own inside.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:30,000 --> 00:12:34,000
|
| 603 |
+
Let me also explain it in other simple words.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:34,000 --> 00:12:38,000
|
| 607 |
+
How is this relation will be implemented in the database?
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:39,000 --> 00:12:46,000
|
| 611 |
+
You already knows that 1 to 1 relationship may be implemented just by adding a foreign key into another
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:46,000 --> 00:12:47,000
|
| 615 |
+
table.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:47,000 --> 00:12:55,000
|
| 619 |
+
Here I say that user attribute is mapped by user property in the user profile entity.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:56,000 --> 00:13:03,000
|
| 623 |
+
User profile owns a relationship and holds the reference to the user.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:03,000 --> 00:13:04,000
|
| 627 |
+
Is it clear?
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:05,000 --> 00:13:11,000
|
| 631 |
+
So map by attribute can be specified only on the non only side.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:11,000 --> 00:13:18,000
|
| 635 |
+
Anyway, in case you still have any questions, feel free to ask them below the video and I will be
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:18,000 --> 00:13:19,000
|
| 639 |
+
happy to answer.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:21,000 --> 00:13:29,000
|
| 643 |
+
In the user profile, we just put annotation 1 to 1 and the rest properties here are just properties.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:29,000 --> 00:13:30,000
|
| 647 |
+
Let me open them.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:30,000 --> 00:13:33,000
|
| 651 |
+
A class now is a demo class.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:33,000 --> 00:13:39,000
|
| 655 |
+
I start the transaction, I create user, I create user profile.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:40,000 --> 00:13:45,000
|
| 659 |
+
I set user profile into the user and I persist the user.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:45,000 --> 00:13:55,000
|
| 663 |
+
As I said, if we use cascade attribute of annotation and Cascade type persist, we don't need to persist
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:55,000 --> 00:14:02,000
|
| 667 |
+
manually another entity because it will be automatically persisted together with the user entity.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:03,000 --> 00:14:08,000
|
| 671 |
+
Let me run this program and let me open now my SQL workbench.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:09,000 --> 00:14:12,000
|
| 675 |
+
We have multiple users in different examples.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:12,000 --> 00:14:18,000
|
| 679 |
+
That's why user from the current example is called user 1 to 1.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:18,000 --> 00:14:27,000
|
| 683 |
+
You can see that one, my user was named John is saved here and one user profile is also persisted.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:28,000 --> 00:14:36,000
|
| 687 |
+
Pay attention that in our case, user profile contains foreign key user ID that is used to establish
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:36,000 --> 00:14:39,000
|
| 691 |
+
connection between two entities.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:39,000 --> 00:14:40,000
|
| 695 |
+
Is it clear?
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:41,000 --> 00:14:44,000
|
| 699 |
+
Now let's review another example.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:14:44,000 --> 00:14:48,000
|
| 703 |
+
Let's review now one to many and many to one examples.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:49,000 --> 00:14:56,000
|
| 707 |
+
The one to many and many to one annotations facilitate both sides of the same relationship.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:56,000 --> 00:15:04,000
|
| 711 |
+
Consider an example where a book can have only one author, but an author may have many books.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:04,000 --> 00:15:07,000
|
| 715 |
+
I prepared an example here for you.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:07,000 --> 00:15:10,000
|
| 719 |
+
Let me open book class first.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:10,000 --> 00:15:12,000
|
| 723 |
+
We have such properties here.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:12,000 --> 00:15:15,000
|
| 727 |
+
ID name and also.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:16,000 --> 00:15:19,000
|
| 731 |
+
So each book has one author.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:19,000 --> 00:15:24,000
|
| 735 |
+
So many books can be associated with one author.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:25,000 --> 00:15:32,000
|
| 739 |
+
That's why we have managed to one annotation here and in the author class.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:32,000 --> 00:15:40,000
|
| 743 |
+
We're going to have one to many annotation because one author can be associated with many books.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:15:40,000 --> 00:15:41,000
|
| 747 |
+
Is it clear?
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:42,000 --> 00:15:47,000
|
| 751 |
+
And now the annotations that you didn't see before is John column.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:48,000 --> 00:15:50,000
|
| 755 |
+
Let me explain to you why we need it.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:51,000 --> 00:15:59,000
|
| 759 |
+
This annotation marks a column as a joint column for an entity association or an element collection.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:00,000 --> 00:16:08,000
|
| 763 |
+
June column is used to specify a column for joining an entity, association or element collection.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:08,000 --> 00:16:17,000
|
| 767 |
+
This annotation indicates that the enclosing entity is the owner of the relationship and that the corresponding
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:17,000 --> 00:16:24,000
|
| 771 |
+
table has a foreign key column which references to the table of the non own inside.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:25,000 --> 00:16:34,000
|
| 775 |
+
So that means that in book entity we are going to have a column with the name author ID that will ensure
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:16:34,000 --> 00:16:37,000
|
| 779 |
+
relation with author entity.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:38,000 --> 00:16:45,000
|
| 783 |
+
That means that author ID column will store the foreign key to the author entity.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:45,000 --> 00:16:47,000
|
| 787 |
+
I hope that this is clear.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:49,000 --> 00:16:50,000
|
| 791 |
+
Let me open author class.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:16:50,000 --> 00:16:59,000
|
| 795 |
+
Now in the author class we have property of list type because each author can have multiple books.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:00,000 --> 00:17:03,000
|
| 799 |
+
We learn already what mapped by means.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:03,000 --> 00:17:13,000
|
| 803 |
+
So we specify here attribute name of the entity that owns the relationship and we also specify cascading
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:13,000 --> 00:17:13,000
|
| 807 |
+
type.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:14,000 --> 00:17:15,000
|
| 811 |
+
Let me open them across.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:15,000 --> 00:17:19,000
|
| 815 |
+
Now I create one author and three books.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:17:20,000 --> 00:17:23,000
|
| 819 |
+
I add books to the author and I persist.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:17:23,000 --> 00:17:26,000
|
| 823 |
+
Also, let me run this program.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:17:27,000 --> 00:17:34,000
|
| 827 |
+
After running this program, let me open my SQL workbench and we have two new entities.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:17:34,000 --> 00:17:37,000
|
| 831 |
+
They are book and author.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:37,000 --> 00:17:43,000
|
| 835 |
+
And when I open author table, you can see that I have one author here.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:17:43,000 --> 00:17:52,000
|
| 839 |
+
And when I open book, which is three books and the book table has author ID column to ensure many to
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:17:52,000 --> 00:17:59,000
|
| 843 |
+
one relation that it regarding one to many and many to one relationships.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:00,000 --> 00:18:03,000
|
| 847 |
+
Let me show you now many, many relationship example.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:04,000 --> 00:18:09,000
|
| 851 |
+
In this example, imagine that our book can have multiple authors.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:09,000 --> 00:18:10,000
|
| 855 |
+
Why not?
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:11,000 --> 00:18:15,000
|
| 859 |
+
This is real life case and such things can happen.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:18:15,000 --> 00:18:20,000
|
| 863 |
+
That book is written by multiple authors and each author.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:18:20,000 --> 00:18:23,000
|
| 867 |
+
Each one can have multiple books.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:18:23,000 --> 00:18:27,000
|
| 871 |
+
So this is example of man to man relationship.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:18:28,000 --> 00:18:32,000
|
| 875 |
+
Let's review how it is implemented with the GPA.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:18:32,000 --> 00:18:36,000
|
| 879 |
+
I have a separate package that is called Man to Man.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:18:37,000 --> 00:18:39,000
|
| 883 |
+
Let me start with the book class.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:18:40,000 --> 00:18:49,000
|
| 887 |
+
Amazon is like in previous example besides Z slides, I have annotation many too many from the relational
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:18:49,000 --> 00:18:51,000
|
| 891 |
+
database theory.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:18:51,000 --> 00:18:57,000
|
| 895 |
+
You already know that many to many connection is implemented with the help of the search table.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:18:58,000 --> 00:19:07,000
|
| 899 |
+
That's why we have annotation join table here with specify name of the joint table and we need to specify
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:19:07,000 --> 00:19:15,000
|
| 903 |
+
June column from one and another side, the columns that will be used in mapping entities between each
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:15,000 --> 00:19:15,000
|
| 907 |
+
OSR.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:16,000 --> 00:19:23,000
|
| 911 |
+
It will be book ID from the book entity side and it will be authorized from the author.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:19:23,000 --> 00:19:25,000
|
| 915 |
+
And the this side is every single year.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:19:26,000 --> 00:19:33,000
|
| 919 |
+
In this case, I use set type in order to receive only unique authors for each book.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:19:34,000 --> 00:19:34,000
|
| 923 |
+
Hobbs.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:19:34,000 --> 00:19:37,000
|
| 927 |
+
It's everything sounds logical to you so far.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:19:38,000 --> 00:19:45,000
|
| 931 |
+
In case you have any questions, please ask your questions below the video and I will be happy to answer
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:19:45,000 --> 00:19:46,000
|
| 935 |
+
those.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:19:47,000 --> 00:19:49,000
|
| 939 |
+
And let me open author class now.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:19:49,000 --> 00:19:57,000
|
| 943 |
+
Here we also put many too many annotation and with specified mapping fields for authors property in
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:19:57,000 --> 00:19:59,000
|
| 947 |
+
book entity.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:19:59,000 --> 00:20:03,000
|
| 951 |
+
Okay, let me now open them a class.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:20:03,000 --> 00:20:10,000
|
| 955 |
+
In addition to the code from previous example, one of the persisted books of Stephen King, I just
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:20:10,000 --> 00:20:14,000
|
| 959 |
+
added some imaginary author to other books.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:20:15,000 --> 00:20:17,000
|
| 963 |
+
This is just for the sake of example.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:20:17,000 --> 00:20:22,000
|
| 967 |
+
If you're a fan of Stephen King like I am, please don't be offended.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:20:23,000 --> 00:20:25,000
|
| 971 |
+
This is just for the sake of example.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:20:26,000 --> 00:20:30,000
|
| 975 |
+
But he runs a program and after program has been executed.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:20:30,000 --> 00:20:32,000
|
| 979 |
+
Let me open my SQL workbench.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:20:33,000 --> 00:20:34,000
|
| 983 |
+
I have new types here.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:20:34,000 --> 00:20:37,000
|
| 987 |
+
They are many, many.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:20:37,000 --> 00:20:38,000
|
| 991 |
+
Awesome.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:20:38,000 --> 00:20:39,000
|
| 995 |
+
Many to many.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:20:39,000 --> 00:20:40,000
|
| 999 |
+
And author.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:20:41,000 --> 00:20:49,000
|
| 1003 |
+
We can see that relationship is managed with the help of the set table and it contains consistent data.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:20:50,000 --> 00:20:51,000
|
| 1007 |
+
Great.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:20:51,000 --> 00:20:56,000
|
| 1011 |
+
We have completed a review of all types of mappings in the GPA with examples.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:20:57,000 --> 00:21:00,000
|
| 1015 |
+
One most things that I did for the sake of this demo.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:21:01,000 --> 00:21:08,000
|
| 1019 |
+
I changed attributes schema generation database action in our persistence XML document.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:21:08,000 --> 00:21:15,000
|
| 1023 |
+
I changed it from drop and create to update to eliminate some errors in console.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:21:15,000 --> 00:21:22,000
|
| 1027 |
+
During the multiple code execution, we reviewed this attribute in the first license when we just learned
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:21:22,000 --> 00:21:25,000
|
| 1031 |
+
how to configure entity manager factory.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:21:25,000 --> 00:21:30,000
|
| 1035 |
+
So please refer to that lesson to recap the knowledge about this attribute.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:21:31,000 --> 00:21:34,000
|
| 1039 |
+
That's all what I wanted to share with you in this lesson.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:21:34,000 --> 00:21:37,000
|
| 1043 |
+
Let's recap what we have learned today.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:21:38,000 --> 00:21:43,000
|
| 1047 |
+
In this lesson we learn when we need to use mapping and GP.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:21:43,000 --> 00:21:48,000
|
| 1051 |
+
We learned different types of relationships in relational databases.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:21:48,000 --> 00:21:56,000
|
| 1055 |
+
I explained the different mapping directions and we reviewed different types of mapping in Java.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:21:57,000 --> 00:22:04,000
|
| 1059 |
+
Also today we learned cascade type in them and you saw how to cascade operations with entities.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:22:05,000 --> 00:22:10,000
|
| 1063 |
+
I explained the difference between EGA and laissez faire types.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:22:10,000 --> 00:22:14,000
|
| 1067 |
+
We reviewed practical examples with different map types.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:22:15,000 --> 00:22:17,000
|
| 1071 |
+
That's it for this lesson.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:22:17,000 --> 00:22:19,000
|
| 1075 |
+
Thanks a lot for your attention.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:22:19,000 --> 00:22:22,000
|
| 1079 |
+
Have a great day and see you in the next lesson.
|
| 1080 |
+
|
78 - ORM, JPA & Hibernate/006 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/mapping
|
78 - ORM, JPA & Hibernate/007 JPA Queries (Query, TypedQuery, NativeQuery, JPQL, Criteria API)_en.srt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:00:11,000 --> 00:00:16,000
|
| 11 |
+
We're going to start the lesson from the overview of different GPA queries types.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:16,000 --> 00:00:26,000
|
| 15 |
+
Namely, we'll review such types as query type, query named query, native query and Creative API.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:26,000 --> 00:00:34,000
|
| 19 |
+
During the lesson, I will explain what the GPC is and what its key features are to help you with debugging
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:34,000 --> 00:00:37,000
|
| 23 |
+
of your programs when using GPA.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:37,000 --> 00:00:45,000
|
| 27 |
+
I'm going to show you one more property that would enable logging of SQL queries executed against database.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:45,000 --> 00:00:51,000
|
| 31 |
+
And also we're going to have a lot of practical exercises to date during the lesson.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:51,000 --> 00:00:53,000
|
| 35 |
+
Let's start our lesson.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:54,000 --> 00:00:56,000
|
| 39 |
+
Today we're going to learn different types of queries.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:56,000 --> 00:01:01,000
|
| 43 |
+
Like I said, some of the queries will be created with the help of the GPCR.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:02,000 --> 00:01:06,000
|
| 47 |
+
We're going to learn today what it is and review examples too.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:06,000 --> 00:01:14,000
|
| 51 |
+
Some queries will be written on pure SQL, but still GPA will be used to execute these queries.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:14,000 --> 00:01:20,000
|
| 55 |
+
And also we're going to learn creative API to learn how to create queries programmatically.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:21,000 --> 00:01:29,000
|
| 59 |
+
So to sum it up in GPA, we have the following types of queries query written in Java Persistence query
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:29,000 --> 00:01:32,000
|
| 63 |
+
language that is GPG syntax.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:33,000 --> 00:01:39,000
|
| 67 |
+
There are two additional query subtypes the type query and named query.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:40,000 --> 00:01:47,000
|
| 71 |
+
The next query types are native query written in plain SQL syntax and criteria.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:47,000 --> 00:01:51,000
|
| 75 |
+
API query constructed programmatically where different masses.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:52,000 --> 00:01:56,000
|
| 79 |
+
To understand and work with all different types of queries.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:56,000 --> 00:01:58,000
|
| 83 |
+
We also need to learn GraphQL.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:59,000 --> 00:02:01,000
|
| 87 |
+
Let's learn first what it is.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:02,000 --> 00:02:08,000
|
| 91 |
+
GPL stands for Jakarta Persistence Query Language or Java Persistence Query Language.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:08,000 --> 00:02:16,000
|
| 95 |
+
It is an object oriented query language which is used to perform database operations on persistent entities
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:16,000 --> 00:02:18,000
|
| 99 |
+
instead of a database table.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:18,000 --> 00:02:24,000
|
| 103 |
+
Gpcr uses entity object model to operate the SQL queries.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:24,000 --> 00:02:29,000
|
| 107 |
+
Here, the role of Gpe is to transform GPL into SQL.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:30,000 --> 00:02:35,000
|
| 111 |
+
Thus, it provides an easy platform for developers to handle SQL tasks.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:36,000 --> 00:02:43,000
|
| 115 |
+
GPL is developed based on SQL syntax, but it won't affect the database directory.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:44,000 --> 00:02:49,000
|
| 119 |
+
The general structure and syntax of GPL are very similar to SQL.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:50,000 --> 00:02:58,000
|
| 123 |
+
Having an SQL like syntax in queries is an important advantage because SQL is very powerful query language
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:58,000 --> 00:03:01,000
|
| 127 |
+
and many developers are already familiar with it.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:03:02,000 --> 00:03:10,000
|
| 131 |
+
So to sum it up, the main difference between SQL and GPL is that SQL works with relational database
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:03:10,000 --> 00:03:17,000
|
| 135 |
+
tables, records and fields, whereas GPG works with Java classes and objects.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:17,000 --> 00:03:25,000
|
| 139 |
+
For example, a typical query can retrieve and return entity objects rather than just field values from
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:25,000 --> 00:03:26,000
|
| 143 |
+
the database tables.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:26,000 --> 00:03:34,000
|
| 147 |
+
As with SQL, that makes typical, more object oriented, friendly, and easier to use in Java.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:35,000 --> 00:03:41,000
|
| 151 |
+
The key features are it is platform independent query language.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:41,000 --> 00:03:43,000
|
| 155 |
+
It is simple and robust.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:44,000 --> 00:03:49,000
|
| 159 |
+
It can be used with any type of database such as my SQL or Oracle.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:49,000 --> 00:03:50,000
|
| 163 |
+
It doesn't matter.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:51,000 --> 00:03:59,000
|
| 167 |
+
SQL queries can be declared statically into metadata or can also be dynamically built in code.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:04:00,000 --> 00:04:02,000
|
| 171 |
+
We learned what a gpcr is.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:04:02,000 --> 00:04:09,000
|
| 175 |
+
And before jumping to examples, let's learn a little bit more theory about criteria API.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:09,000 --> 00:04:12,000
|
| 179 |
+
And after that, I will walk you through all the examples.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:13,000 --> 00:04:21,000
|
| 183 |
+
The criteria API is one of the most common ways of constructing queries for entities and they are persistent
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:21,000 --> 00:04:21,000
|
| 187 |
+
state.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:22,000 --> 00:04:27,000
|
| 191 |
+
That is just an alternative method for defining GPA queries criteria.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:27,000 --> 00:04:34,000
|
| 195 |
+
API defines a platform independent criteria queries written in Java programming language.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:34,000 --> 00:04:38,000
|
| 199 |
+
It was introduced in GPA 2.0.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:38,000 --> 00:04:44,000
|
| 203 |
+
The main purpose behind this is to provide a type safe way to express a query.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:45,000 --> 00:04:51,000
|
| 207 |
+
The criteria API is a predefined API used to define queries for entities.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:51,000 --> 00:05:01,000
|
| 211 |
+
It is an alternative way of defining AGP SQL query this query subtype safe, portable and easy to modify
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:05:01,000 --> 00:05:02,000
|
| 215 |
+
by changing the syntax.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:05:03,000 --> 00:05:12,000
|
| 219 |
+
The major advantage of the criteria API is that errors can be detected early during compile time string
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:05:12,000 --> 00:05:19,000
|
| 223 |
+
based typical queries and GP criteria based queries are same and performance and efficiency.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:05:19,000 --> 00:05:24,000
|
| 227 |
+
So it would be up to you which one you would like to use in your code.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:05:25,000 --> 00:05:25,000
|
| 231 |
+
Okay.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:26,000 --> 00:05:29,000
|
| 235 |
+
We learned enough, Sarah, to proceed with practical examples.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:29,000 --> 00:05:33,000
|
| 239 |
+
Let me start screen sharing and proceed with code examples.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:34,000 --> 00:05:39,000
|
| 243 |
+
All examples from today's lesson will be in the package queries.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:39,000 --> 00:05:42,000
|
| 247 |
+
You will be able to find the reference to the source code.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:42,000 --> 00:05:47,000
|
| 251 |
+
Examples in attachments to the lesson you ran multiple examples.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:47,000 --> 00:05:51,000
|
| 255 |
+
Today I am going to use user entity from this package.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:51,000 --> 00:05:59,000
|
| 259 |
+
Here it is to avoid name conflict with other users that we created during the previous classes.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:59,000 --> 00:06:05,000
|
| 263 |
+
This user entity has specific entity name and this is just for the sake of the example.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:06:05,000 --> 00:06:14,000
|
| 267 |
+
As you can see, its name is user queries demo and separately as specified table name user key the.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:06:15,000 --> 00:06:23,000
|
| 271 |
+
I also did this on purpose so that you would be sure when we use Tae Bo name and when we use entity
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:06:23,000 --> 00:06:25,000
|
| 275 |
+
name in our examples.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:25,000 --> 00:06:33,000
|
| 279 |
+
This is important to know and understand because when we write queries today we will use entity name
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:33,000 --> 00:06:37,000
|
| 283 |
+
in gpcr and we will use table name in native queries.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:38,000 --> 00:06:41,000
|
| 287 |
+
Let's start from review of this simple query.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:42,000 --> 00:06:52,000
|
| 291 |
+
I open them across in the main message I create entity manager factory and create entity manager Amazon
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:52,000 --> 00:06:53,000
|
| 295 |
+
as usual.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:53,000 --> 00:06:59,000
|
| 299 |
+
After that, I create user in the database like we also always did.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:07:00,000 --> 00:07:08,000
|
| 303 |
+
And after that I call massive get user buy and I pass ID and entity manager.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:07:09,000 --> 00:07:11,000
|
| 307 |
+
And here I create query.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:07:11,000 --> 00:07:17,000
|
| 311 |
+
So to create query object, we need entity manager using entity manager.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:07:17,000 --> 00:07:22,000
|
| 315 |
+
I can just call mass create query and pause GPIO query.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:07:22,000 --> 00:07:31,000
|
| 319 |
+
As you can see, it has SQL like syntax, but instead of tables we use entity names.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:07:32,000 --> 00:07:42,000
|
| 323 |
+
As you can see, I reference the user queries demo entity by its name and assigns ID variable you to
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:42,000 --> 00:07:42,000
|
| 327 |
+
it.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:43,000 --> 00:07:49,000
|
| 331 |
+
The ID variable is often called alas and we are ready to learn this with you.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:49,000 --> 00:07:52,000
|
| 335 |
+
In the lessons about relational databases.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:52,000 --> 00:07:57,000
|
| 339 |
+
It is similar to a variable in your Java code that you can use later in the query.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:58,000 --> 00:08:07,000
|
| 343 |
+
For example, here in the vehicles, I use you as a reference to the entity name and its ID property
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:08:07,000 --> 00:08:15,000
|
| 347 |
+
so you can see this else in all other parts of the query to reference this entity.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:08:16,000 --> 00:08:21,000
|
| 351 |
+
As you can see in Gpcr, I can use parameters, placeholders.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:08:21,000 --> 00:08:26,000
|
| 355 |
+
I use column and parameter name like wizard here.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:08:27,000 --> 00:08:36,000
|
| 359 |
+
After that, I can use method set parameter to set parameter to the query and after that I call method
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:08:36,000 --> 00:08:37,000
|
| 363 |
+
get single result.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:08:38,000 --> 00:08:46,000
|
| 367 |
+
I encourage you to use a source code of query type and its methods because for example, in case we
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:46,000 --> 00:08:56,000
|
| 371 |
+
wrote our query and we expect multiple users to be returned, we can call mass get result list that
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:56,000 --> 00:09:00,000
|
| 375 |
+
would be needed in case you want to retrieve all users.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:09:01,000 --> 00:09:03,000
|
| 379 |
+
Let's get back to our example.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:09:04,000 --> 00:09:05,000
|
| 383 |
+
Let me run this program.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:09:06,000 --> 00:09:11,000
|
| 387 |
+
And as a result, we see that users that we created is printed to console.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:09:12,000 --> 00:09:18,000
|
| 391 |
+
So as you can see, the syntax is pretty intuitive if you are familiar with SQL.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:09:18,000 --> 00:09:25,000
|
| 395 |
+
And if not, please refer to my lessons about SQL in my course Java from zero to first job.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:09:25,000 --> 00:09:33,000
|
| 399 |
+
I even thought about to show you other examples during this lesson, but when I created those, I decided
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:09:33,000 --> 00:09:38,000
|
| 403 |
+
not to confuse you because they are absolutely similar to SQL query.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:09:38,000 --> 00:09:47,000
|
| 407 |
+
The only thing that is different is that I use name of my entities instead of the table names, and
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:09:47,000 --> 00:09:55,000
|
| 411 |
+
when I refer to some entity properties, I refer to the entity attribute by their names, but not the
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:09:55,000 --> 00:09:57,000
|
| 415 |
+
columns in the database.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:09:57,000 --> 00:10:04,000
|
| 419 |
+
So instead of using column name from the database, just use properties name from the Java entity.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:10:04,000 --> 00:10:13,000
|
| 423 |
+
Another difference is a possibility to use placeholders for parameters like you already saw in example.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:10:13,000 --> 00:10:14,000
|
| 427 |
+
That's it.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:10:14,000 --> 00:10:18,000
|
| 431 |
+
In case you would have some challenges, open questions.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:10:18,000 --> 00:10:23,000
|
| 435 |
+
Please let me know in the comments below video and I will be happy to answer.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:10:24,000 --> 00:10:28,000
|
| 439 |
+
And now the important thing for you to learn during the development.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:10:28,000 --> 00:10:35,000
|
| 443 |
+
If you use hibernate, you can add property to show SQL queries that are sent to the database.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:10:36,000 --> 00:10:39,000
|
| 447 |
+
This is important sometimes to use during the debugging.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:10:39,000 --> 00:10:45,000
|
| 451 |
+
For example, when you want to make sure what exact where it is sent to the database.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:10:46,000 --> 00:10:50,000
|
| 455 |
+
I open persistence x email to add one more additional configuration.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:10:51,000 --> 00:10:56,000
|
| 459 |
+
The property is called Hibernate dot show underscore SQL.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:10:57,000 --> 00:11:03,000
|
| 463 |
+
We need to set it to true if we want to see generated SQL statements in the logs.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:11:03,000 --> 00:11:10,000
|
| 467 |
+
You can find the command here, so feel free to on common ID in the source code examples that I will
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:11:10,000 --> 00:11:11,000
|
| 471 |
+
share with you.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:11:12,000 --> 00:11:15,000
|
| 475 |
+
And let's run our problem one more time.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:11:16,000 --> 00:11:19,000
|
| 479 |
+
As you can see, there are queries in console.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:11:19,000 --> 00:11:27,000
|
| 483 |
+
So in case you would face some errors and you can't understand why code doesn't work as it is expected,
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:11:27,000 --> 00:11:32,000
|
| 487 |
+
then please enable this property and explore logs.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:11:33,000 --> 00:11:36,000
|
| 491 |
+
For now I will comment this property back.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:11:37,000 --> 00:11:45,000
|
| 495 |
+
That tension also to another seen here query can identify what type will be returned.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:11:45,000 --> 00:11:53,000
|
| 499 |
+
That's why we need to cast result manually to the type that we need because get single result method
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:11:53,000 --> 00:11:57,000
|
| 503 |
+
which hands us just object type and that's it.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:11:57,000 --> 00:12:00,000
|
| 507 |
+
This things are different with typed query.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:12:00,000 --> 00:12:05,000
|
| 511 |
+
I open another example that is called GPT type query demo.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:12:06,000 --> 00:12:12,000
|
| 515 |
+
That query is a separate type that extends query time with typed query type.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:12:12,000 --> 00:12:17,000
|
| 519 |
+
I can specify the Java type that I want to extract from the database.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:12:18,000 --> 00:12:25,000
|
| 523 |
+
Typed query is parameterized by the type that I want to work with and when I call get similar result
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:12:25,000 --> 00:12:32,000
|
| 527 |
+
message, I receive the result of the type that I need and I don't need to cast types manually.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:12:33,000 --> 00:12:39,000
|
| 531 |
+
Let me run this program just to make sure that we received our user object that we expect.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:12:40,000 --> 00:12:42,000
|
| 535 |
+
Let's now talk about Named Query.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:12:43,000 --> 00:12:48,000
|
| 539 |
+
I open another example here that is called Gpcr named Query.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:12:48,000 --> 00:12:57,000
|
| 543 |
+
So imagine the case that in different parts of your application you use different queries and you have
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:12:57,000 --> 00:13:04,000
|
| 547 |
+
a lot of different types and a lot of different queries, and gradually it becomes hard to maintain
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:13:04,000 --> 00:13:05,000
|
| 551 |
+
such amount of queries.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:13:06,000 --> 00:13:13,000
|
| 555 |
+
But what if you could keep all queries that you used to gather with a specific entity in one centralized
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:13:13,000 --> 00:13:15,000
|
| 559 |
+
place and we use them?
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:13:15,000 --> 00:13:20,000
|
| 563 |
+
Would it be easier named query type can help us with this?
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:13:21,000 --> 00:13:24,000
|
| 567 |
+
Let me open our user clause here.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:13:24,000 --> 00:13:27,000
|
| 571 |
+
On top you can see annotation named query.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:13:28,000 --> 00:13:32,000
|
| 575 |
+
Basically what we do, we map specific name with the query.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:13:33,000 --> 00:13:37,000
|
| 579 |
+
Now let me open typical named query demo class.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:13:38,000 --> 00:13:40,000
|
| 583 |
+
In this class we have similar example.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:13:41,000 --> 00:13:45,000
|
| 587 |
+
The only difference is our get user by the masses.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:13:45,000 --> 00:13:54,000
|
| 591 |
+
This time I use entity manager reference to call create named query and the name of our named query.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:13:55,000 --> 00:13:57,000
|
| 595 |
+
The rest things are similar here.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:13:58,000 --> 00:14:03,000
|
| 599 |
+
I will just run this program, but believe me will receive the same result.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:14:04,000 --> 00:14:07,000
|
| 603 |
+
Named careers have some huge advantages.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:14:07,000 --> 00:14:12,000
|
| 607 |
+
They are named squares a compiled and validated one.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:14:12,000 --> 00:14:14,000
|
| 611 |
+
The persistence unit is loaded.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:14:14,000 --> 00:14:19,000
|
| 615 |
+
We can centralize named queries to make them easier to maintain.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:14:19,000 --> 00:14:26,000
|
| 619 |
+
For example, in or read maximal in properties, files or in entity classes.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:14:27,000 --> 00:14:30,000
|
| 623 |
+
Now let's talk about native SQL queries.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:14:30,000 --> 00:14:38,000
|
| 627 |
+
Obviously, syntax has some restrictions and sometimes we want to optimize query execution and to use
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:14:38,000 --> 00:14:41,000
|
| 631 |
+
the whole power of SQL.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:14:41,000 --> 00:14:47,000
|
| 635 |
+
This approach actually has its own pros and cons regarding advantages.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:14:47,000 --> 00:14:48,000
|
| 639 |
+
We kind of talk through them.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:14:49,000 --> 00:14:56,000
|
| 643 |
+
It is a possibility to use the whole power of SQL and create queries specifically for the selected database
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:56,000 --> 00:15:01,000
|
| 647 |
+
considering database dialogue but talking about disadvantages.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:15:01,000 --> 00:15:08,000
|
| 651 |
+
You have to understand that using native SQL queries, you can lose portability of your solution.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:15:09,000 --> 00:15:18,000
|
| 655 |
+
By saying this, I mean that GPA serves us as an abstraction and GP takes care of compatibility with
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:15:18,000 --> 00:15:18,000
|
| 659 |
+
the database.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:15:19,000 --> 00:15:25,000
|
| 663 |
+
Basically, you can just change the driver and dialect and configurations, and your solution can work
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:15:25,000 --> 00:15:29,000
|
| 667 |
+
with any other database using native SQL queries.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:15:29,000 --> 00:15:32,000
|
| 671 |
+
Maybe not so flexible.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:15:32,000 --> 00:15:39,000
|
| 675 |
+
You should remember this using native query doesn't necessarily mean that our code works with only one
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:15:39,000 --> 00:15:41,000
|
| 679 |
+
specific database.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:15:41,000 --> 00:15:43,000
|
| 683 |
+
I just highlight the risks.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:15:43,000 --> 00:15:51,000
|
| 687 |
+
At the end of the day, if our queries don't use database specific SQL commands and we are using only
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:15:51,000 --> 00:15:53,000
|
| 691 |
+
a standard SQL syntax.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:15:53,000 --> 00:15:58,000
|
| 695 |
+
Switching providers of databases should not be an issue.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:58,000 --> 00:16:00,000
|
| 699 |
+
But now you're warned.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:16:01,000 --> 00:16:08,000
|
| 703 |
+
But in most cases, a good SQL query can help us to solve our business tasks and most importantly,
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:16:08,000 --> 00:16:13,000
|
| 707 |
+
maintain a level of abstraction from the actual database implementation.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:16:14,000 --> 00:16:16,000
|
| 711 |
+
Let me open a native query demo clause.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:16:17,000 --> 00:16:23,000
|
| 715 |
+
This is the same examples that we already reviewed, but the get user by ID mass is slightly different.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:16:24,000 --> 00:16:32,000
|
| 719 |
+
Basically less complex and creation of native queries you just call massive, create native query and
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:16:32,000 --> 00:16:34,000
|
| 723 |
+
pass native SQL query.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:16:34,000 --> 00:16:35,000
|
| 727 |
+
That's it.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:16:35,000 --> 00:16:42,000
|
| 731 |
+
Pay attention that this time we pass table name but not entity name.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:16:43,000 --> 00:16:46,000
|
| 735 |
+
Basically that's it regarding native queries.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:16:46,000 --> 00:16:55,000
|
| 739 |
+
My general advice would be try to use typical queries when it is possible or criteria API and only in
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:16:55,000 --> 00:17:00,000
|
| 743 |
+
case you want to optimize query execution and it's really worth it.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:17:00,000 --> 00:17:03,000
|
| 747 |
+
In this case, you can try native queries.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:17:04,000 --> 00:17:06,000
|
| 751 |
+
That's my general recommendation.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:17:06,000 --> 00:17:10,000
|
| 755 |
+
But again, it is only up to you what you decide to use.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:17:11,000 --> 00:17:15,000
|
| 759 |
+
And finally, let's learn what the criteria API is.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:17:16,000 --> 00:17:16,000
|
| 763 |
+
Criteria.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:17:16,000 --> 00:17:21,000
|
| 767 |
+
API queries are programmatically built type save queries.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:17:21,000 --> 00:17:29,000
|
| 771 |
+
It enables us to write queries without doing raw SQL as well as gives us some object oriented control
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:17:29,000 --> 00:17:33,000
|
| 775 |
+
over the queries, which is one of the main features of GPA.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:17:34,000 --> 00:17:42,000
|
| 779 |
+
The criteria API allows us to build up a criteria query object programmatically where we can apply different
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:17:42,000 --> 00:17:46,000
|
| 783 |
+
kinds of filtration rules and logical conditions.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:17:47,000 --> 00:17:49,000
|
| 787 |
+
I open another example.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:17:49,000 --> 00:17:52,000
|
| 791 |
+
This is called criteria API demo.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:52,000 --> 00:17:59,000
|
| 795 |
+
This is similar example that we have reviewed, but I have a few methods here written with criteria
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:59,000 --> 00:18:00,000
|
| 799 |
+
API.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:18:01,000 --> 00:18:02,000
|
| 803 |
+
Let's start from the simple one.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:18:03,000 --> 00:18:09,000
|
| 807 |
+
Let's extract all users from the database, even despite we created only one user.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:18:09,000 --> 00:18:17,000
|
| 811 |
+
Still, it will be useful for you to learn API how to extract all entities of the specific entity type.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:18:18,000 --> 00:18:19,000
|
| 815 |
+
Let's review method.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:18:19,000 --> 00:18:22,000
|
| 819 |
+
It is called get all users.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:18:22,000 --> 00:18:26,000
|
| 823 |
+
So if you see criteria, API is the first time.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:18:26,000 --> 00:18:35,000
|
| 827 |
+
Most likely it wouldn't look very friendly, but once you start use it, everything will become logical
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:18:35,000 --> 00:18:35,000
|
| 831 |
+
for you.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:18:36,000 --> 00:18:38,000
|
| 835 |
+
Let's review this simple example.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:39,000 --> 00:18:43,000
|
| 839 |
+
We use entity manager to get criteria builder.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:43,000 --> 00:18:45,000
|
| 843 |
+
Using Criteria Builder.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:45,000 --> 00:18:50,000
|
| 847 |
+
We create query as you can see to create query.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:50,000 --> 00:18:53,000
|
| 851 |
+
I pass class of my entity here.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:53,000 --> 00:19:02,000
|
| 855 |
+
After that we use method form to create a query route so this massive creates and add a query route
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:19:02,000 --> 00:19:05,000
|
| 859 |
+
corresponding to the given entity.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:19:05,000 --> 00:19:10,000
|
| 863 |
+
And using this route will apply different conditions.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:19:11,000 --> 00:19:18,000
|
| 867 |
+
After that I create a query on the entity manager and parse criteria query there.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:19:18,000 --> 00:19:26,000
|
| 871 |
+
We use select method on our criteria query and I pass the root to respondent as a given entity.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:19:26,000 --> 00:19:27,000
|
| 875 |
+
That's it.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:19:28,000 --> 00:19:33,000
|
| 879 |
+
After that, I work with query object to extract the list of results.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:19:34,000 --> 00:19:37,000
|
| 883 |
+
Let's put our focus now on the massive get user buy.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:19:39,000 --> 00:19:45,000
|
| 887 |
+
Basically, we do almost the same thing, but in addition to select I apply condition.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:19:46,000 --> 00:19:51,000
|
| 891 |
+
I can limit results of the query by applying their condition.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:19:51,000 --> 00:20:00,000
|
| 895 |
+
I call their method where method takes predicate to create predicate, you can use different masses,
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:20:00,000 --> 00:20:03,000
|
| 899 |
+
for example, equals mass.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:20:03,000 --> 00:20:08,000
|
| 903 |
+
It creates a protocol that validates equality with the parameter passed.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:20:09,000 --> 00:20:15,000
|
| 907 |
+
We can open criteria, build and just explore masses that we can predict to us.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:20:15,000 --> 00:20:25,000
|
| 911 |
+
In the source code you can see not the equal mass that also returns predicate is not now is now is false
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:20:25,000 --> 00:20:29,000
|
| 915 |
+
is true and a lot of other and masses here.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:20:29,000 --> 00:20:35,000
|
| 919 |
+
I encourage you to look through the source code to learn this API better.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:20:36,000 --> 00:20:43,000
|
| 923 |
+
I don't see that we need to stop on this too much because names of the masses are self describing.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:20:43,000 --> 00:20:50,000
|
| 927 |
+
I believe that you are smart enough to understand what kind of condition is created based on the massive
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:20:50,000 --> 00:20:55,000
|
| 931 |
+
name and even in case some mass that would remain not clear.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:20:55,000 --> 00:21:01,000
|
| 935 |
+
Please do not hesitate to ask your questions below the video and I will be happy to answer.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:21:02,000 --> 00:21:10,000
|
| 939 |
+
After that we call yet mass on our user route reference and we pass here ID's that we need to compare.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:21:11,000 --> 00:21:16,000
|
| 943 |
+
Route type extends from type and from type.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:21:16,000 --> 00:21:18,000
|
| 947 |
+
Extends past the.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:21:19,000 --> 00:21:22,000
|
| 951 |
+
So they get massive ease from the pass interface.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:21:23,000 --> 00:21:27,000
|
| 955 |
+
This is not the pass from the new package that we already learned.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:21:28,000 --> 00:21:32,000
|
| 959 |
+
This is post from Jakarta Persistence Criteria Package.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:21:32,000 --> 00:21:41,000
|
| 963 |
+
It represents a simple or compound attribute pass from a bound type or collection and is a primitive
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:21:41,000 --> 00:21:41,000
|
| 967 |
+
expression.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:21:42,000 --> 00:21:44,000
|
| 971 |
+
Let's get back to our example.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:21:45,000 --> 00:21:52,000
|
| 975 |
+
After that, we mass get single result and that's it and we receive user object.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:21:53,000 --> 00:22:01,000
|
| 979 |
+
There are different other queries that you can make using criteria API and hidden command lines.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:22:01,000 --> 00:22:03,000
|
| 983 |
+
I left a few more examples.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:22:03,000 --> 00:22:08,000
|
| 987 |
+
Some of them are extract users with a greater than one.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:22:09,000 --> 00:22:12,000
|
| 991 |
+
Extract the users where first name contains all.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:22:13,000 --> 00:22:17,000
|
| 995 |
+
Extract users was aged between one and five.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:22:17,000 --> 00:22:22,000
|
| 999 |
+
Extract users with a first name in the specified range.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:22:23,000 --> 00:22:28,000
|
| 1003 |
+
Example of how you can chain expressions using different credit cards.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:22:28,000 --> 00:22:35,000
|
| 1007 |
+
You just create multiple credit cards, put them into the array, and after that you apply an array
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:22:35,000 --> 00:22:36,000
|
| 1011 |
+
of predicates.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:22:37,000 --> 00:22:39,000
|
| 1015 |
+
Such API also exists.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:22:40,000 --> 00:22:42,000
|
| 1019 |
+
Feel free to use it if you wish.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:22:43,000 --> 00:22:44,000
|
| 1023 |
+
Sort an example.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:22:45,000 --> 00:22:53,000
|
| 1027 |
+
In this example you can see that I saw in ascending order by name and in descending order by last name.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:22:53,000 --> 00:22:56,000
|
| 1031 |
+
You can explore these source code examples.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:22:57,000 --> 00:23:02,000
|
| 1035 |
+
Just take a look how a deal predicts here and which methods I use.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:23:03,000 --> 00:23:10,000
|
| 1039 |
+
You can build similar pretty cuts using my examples or you can explore as a massive criteria builder
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:23:10,000 --> 00:23:11,000
|
| 1043 |
+
type.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:23:12,000 --> 00:23:13,000
|
| 1047 |
+
Let's review now.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:23:13,000 --> 00:23:17,000
|
| 1051 |
+
Date example will update email of our user.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:23:18,000 --> 00:23:23,000
|
| 1055 |
+
After I created criteria builder, I call create criteria update massive.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:23:24,000 --> 00:23:29,000
|
| 1059 |
+
I use set mass to provide new value for email field.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:23:29,000 --> 00:23:37,000
|
| 1063 |
+
After that, I apply a rare condition in order to change email only for user where Ivy is equal to one.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:23:37,000 --> 00:23:44,000
|
| 1067 |
+
I post to the mask and after that I create query and call method execute update.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:23:44,000 --> 00:23:45,000
|
| 1071 |
+
That's it.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:23:46,000 --> 00:23:49,000
|
| 1075 |
+
Let me also show you example of deletion.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:23:49,000 --> 00:23:57,000
|
| 1079 |
+
I called create criteria delete massive and after that Amazon which you already saw in the examples
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:23:58,000 --> 00:24:04,000
|
| 1083 |
+
we add pretty good here to make sure that only the record where it matched will be removed.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:24:05,000 --> 00:24:12,000
|
| 1087 |
+
So at the first glance we did a lot of other things instead of just making a to the database.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:24:13,000 --> 00:24:20,000
|
| 1091 |
+
But remember, the criteria API is a programmatic way to build queries in the object oriented manner.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:24:21,000 --> 00:24:24,000
|
| 1095 |
+
It reduces chances to make a mistake.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:24:25,000 --> 00:24:32,000
|
| 1099 |
+
Of course, there are some disadvantages as well, especially around more complex joints.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:24:32,000 --> 00:24:38,000
|
| 1103 |
+
So it is up to you which tool and what API to choose for building query.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:24:38,000 --> 00:24:40,000
|
| 1107 |
+
It will depend on the multiple things.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:24:41,000 --> 00:24:46,000
|
| 1111 |
+
But now you know how to use criteria API to query a database.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:24:46,000 --> 00:24:49,000
|
| 1115 |
+
That's all what I wanted to share with you today.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:24:49,000 --> 00:24:53,000
|
| 1119 |
+
Let's recap what we have learned in this lesson.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:24:54,000 --> 00:24:57,000
|
| 1123 |
+
They learned different types of queries in GPA.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:24:58,000 --> 00:25:03,000
|
| 1127 |
+
We learned such types as query type, query and name query.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:25:04,000 --> 00:25:12,000
|
| 1131 |
+
Also, I explained how to work with native query type and we saw a lot of examples how to work with
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:25:12,000 --> 00:25:13,000
|
| 1135 |
+
criteria API.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:25:14,000 --> 00:25:21,000
|
| 1139 |
+
After this lesson, you should have a clear understanding of what GPL is and its key features.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:25:22,000 --> 00:25:25,000
|
| 1143 |
+
Also, we had a lot of practical exercises today.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:25:26,000 --> 00:25:30,000
|
| 1147 |
+
You can find the reference to the source code examples in attachments to the lesson.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:25:31,000 --> 00:25:33,000
|
| 1151 |
+
That's all for this lesson.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:25:33,000 --> 00:25:35,000
|
| 1155 |
+
Thanks a lot for your attention.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:25:35,000 --> 00:25:39,000
|
| 1159 |
+
Have a great day and see you in the next lesson.
|
| 1160 |
+
|
78 - ORM, JPA & Hibernate/007 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/queries
|
78 - ORM, JPA & Hibernate/008 Caching in JPAHibernate_en.srt
ADDED
|
@@ -0,0 +1,1424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:06,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:13,000
|
| 7 |
+
Today we're going to have important and interesting lessons that will help you to optimize the performance
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:13,000 --> 00:00:16,000
|
| 11 |
+
of your application while working with the GP.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:16,000 --> 00:00:22,000
|
| 15 |
+
Hibernate will go on caching in GP using hibernate.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:23,000 --> 00:00:30,000
|
| 19 |
+
We're going to start our lesson from learning what actually caching is and discussing cache structure
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:30,000 --> 00:00:39,000
|
| 23 |
+
in GP hibernate will learn what first level cache is, what the second level cache is, and what query
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:39,000 --> 00:00:41,000
|
| 27 |
+
level cache is.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:41,000 --> 00:00:48,000
|
| 31 |
+
In the lesson, we'll discuss different cache providers, but in our practical examples, we're going
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:48,000 --> 00:00:55,000
|
| 35 |
+
to focus our attention on the most popular cache provider that is used with Hibernate in the most cases.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:55,000 --> 00:00:57,000
|
| 39 |
+
I'm talking about E Cache.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:58,000 --> 00:01:02,000
|
| 43 |
+
Also, we're going to have a lot of practical examples and demo today.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:02,000 --> 00:01:09,000
|
| 47 |
+
During the review of examples, we'll talk about different cache concurrency strategies, cache eviction
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:09,000 --> 00:01:17,000
|
| 51 |
+
policies also will explain what the standard query cache and update timestamp cache are.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:18,000 --> 00:01:25,000
|
| 55 |
+
I will show you a custom configuration of cash will learn persistence strategies in cash.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:25,000 --> 00:01:28,000
|
| 59 |
+
We have a lot of things to learn today.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:28,000 --> 00:01:29,000
|
| 63 |
+
Let's start our lesson.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:30,000 --> 00:01:35,000
|
| 67 |
+
Let's start from understanding of what Kashin is and why do we need it.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:36,000 --> 00:01:43,000
|
| 71 |
+
In computing, a cache is a hardware or software component that stores data so that future requests
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:43,000 --> 00:01:46,000
|
| 75 |
+
for that data can be served faster.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:46,000 --> 00:01:54,000
|
| 79 |
+
The data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:55,000 --> 00:02:02,000
|
| 83 |
+
To be cost effective and to enable efficient use of data caches must be relatively small.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:02:03,000 --> 00:02:08,000
|
| 87 |
+
Nevertheless, caches have proven themselves in many areas of computing.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:09,000 --> 00:02:15,000
|
| 91 |
+
In the GPA, caching is a mechanism to enhance the performance of a system.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:15,000 --> 00:02:21,000
|
| 95 |
+
It is a buffer memory that lies between the application and the database cache.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:21,000 --> 00:02:30,000
|
| 99 |
+
Memory stores recently used data items in order to reduce the number of database heads as much as possible.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:31,000 --> 00:02:34,000
|
| 103 |
+
Let's review the structure of cache in the GPA.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:35,000 --> 00:02:38,000
|
| 107 |
+
GPUs supports a multilevel cache and skiing.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:38,000 --> 00:02:45,000
|
| 111 |
+
Mainly, there are two levels of cache, first level cache and the second level cache.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:46,000 --> 00:02:52,000
|
| 115 |
+
But as you already learned from agenda to the lesson we are also going to learn today, query level
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:52,000 --> 00:02:53,000
|
| 119 |
+
cache.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:53,000 --> 00:02:59,000
|
| 123 |
+
First level cache is enabled by default and you can disable it.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:03:00,000 --> 00:03:04,000
|
| 127 |
+
Second level cache should be enabled in configuration.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:03:04,000 --> 00:03:07,000
|
| 131 |
+
And today I'm going to show you how to do that.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:03:08,000 --> 00:03:11,000
|
| 135 |
+
The same thing is for query level cache.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:11,000 --> 00:03:20,000
|
| 139 |
+
Second level shared cache is an auxiliary technique mainly used in GPA to enhance performance.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:20,000 --> 00:03:29,000
|
| 143 |
+
It is used a special urine large inflow outflow of data between the database and the application cache
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:29,000 --> 00:03:34,000
|
| 147 |
+
and also reduces search time when the searched entity is already in the cache.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:34,000 --> 00:03:39,000
|
| 151 |
+
Otherwise it is fetched from the database to serve the purpose.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:39,000 --> 00:03:47,000
|
| 155 |
+
However, when a subsequent search query is for it, it takes little time as a searched entity is already
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:47,000 --> 00:03:57,000
|
| 159 |
+
in the cache entity manager stores and it is for almost every CRUD operation in this shared cache before
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:57,000 --> 00:04:00,000
|
| 163 |
+
flushing the content to the database.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:04:00,000 --> 00:04:06,000
|
| 167 |
+
Second level cache is complementary to its first level counterpart.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:04:06,000 --> 00:04:11,000
|
| 171 |
+
Let's review each level before we'll go with practical exercises.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:04:12,000 --> 00:04:16,000
|
| 175 |
+
We're going to review now what the first level cash is.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:17,000 --> 00:04:24,000
|
| 179 |
+
And that manager always maintains a cash call, the first level in the first level.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:24,000 --> 00:04:32,000
|
| 183 |
+
Cash crop operations are performed per transaction basis to reduce the number of queries for to the
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:32,000 --> 00:04:33,000
|
| 187 |
+
database.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:34,000 --> 00:04:41,000
|
| 191 |
+
So for example, when we retrieve an entity from the database, the first time the data is retrieved
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:41,000 --> 00:04:48,000
|
| 195 |
+
from the database and the stored is the first level cash associated with the entity manager.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:48,000 --> 00:04:56,000
|
| 199 |
+
And in case entity is modified several times within the same transaction, all changes are done in the
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:56,000 --> 00:05:03,000
|
| 203 |
+
cash only modification and the database level is postponed until we commit our transaction.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:05:04,000 --> 00:05:10,000
|
| 207 |
+
GP And that is cashed at the persistence, context level and guarantees.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:05:10,000 --> 00:05:17,000
|
| 211 |
+
There will be one object instance per persistence context for a specific role of a database table.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:05:18,000 --> 00:05:25,000
|
| 215 |
+
Concurrent transactions affecting the same row I managed by applying an appropriate locking mechanism
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:05:25,000 --> 00:05:26,000
|
| 219 |
+
in the GP.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:05:27,000 --> 00:05:31,000
|
| 223 |
+
And I have a separate lesson about locking in GPA.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:05:31,000 --> 00:05:35,000
|
| 227 |
+
Feel free to refer to that lesson to learn more about locking.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:05:36,000 --> 00:05:39,000
|
| 231 |
+
Let's now talk about second level cash.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:40,000 --> 00:05:48,000
|
| 235 |
+
This level of cash emerged more due to performance reasons is an absolute necessity, in fact, and
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:48,000 --> 00:05:54,000
|
| 239 |
+
in more shared cash increases the possibility of the problem of a stale read.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:54,000 --> 00:06:03,000
|
| 243 |
+
Stale read is a read operation that fetches an incorrect value from a source that has not synchronized
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:06:03,000 --> 00:06:06,000
|
| 247 |
+
an update operation to the value.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:06:06,000 --> 00:06:14,000
|
| 251 |
+
As you can see on this slide, the second level cash sits between entity manager and the database.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:06:14,000 --> 00:06:22,000
|
| 255 |
+
Persistence context shares the cash making the second level cash available throughout the application
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:06:23,000 --> 00:06:31,000
|
| 259 |
+
database traffic is reduced considerably because entities are loaded into the shared cache and made
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:06:31,000 --> 00:06:32,000
|
| 263 |
+
available from there.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:06:33,000 --> 00:06:38,000
|
| 267 |
+
We can say that second level cash provides the following benefits.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:06:39,000 --> 00:06:43,000
|
| 271 |
+
Persistence provide the managers local store of entity data.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:06:44,000 --> 00:06:48,000
|
| 275 |
+
Leverage is performance by avoiding expensive data based calls.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:49,000 --> 00:06:53,000
|
| 279 |
+
Data are kept transparent to the application.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:53,000 --> 00:06:59,000
|
| 283 |
+
CRUD operation can be performed through normal entity manager functions.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:59,000 --> 00:07:06,000
|
| 287 |
+
Application can remain oblivious of the underlying cache and do its job inadvertently.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:07:07,000 --> 00:07:15,000
|
| 291 |
+
Persistence providers like Eclipse, Link, Hibernate, etc. have their own set of implementation created
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:07:15,000 --> 00:07:21,000
|
| 295 |
+
either reusing an existing one or developing their own from scratch.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:07:22,000 --> 00:07:25,000
|
| 299 |
+
Let's now talk about corporate level cash.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:07:25,000 --> 00:07:28,000
|
| 303 |
+
The cash can be configured in the hibernate.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:07:29,000 --> 00:07:34,000
|
| 307 |
+
The corporate cash is responsible for cash and the results of queries.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:07:34,000 --> 00:07:42,000
|
| 311 |
+
Now that the query cash doesn't cash the state of the actual entities in the results set it.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:07:42,000 --> 00:07:47,000
|
| 315 |
+
Cash is only identifier values and results of value type.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:07:47,000 --> 00:07:56,000
|
| 319 |
+
So the query cash should always be used in conjunction with second level cash, where cash is responsible
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:07:56,000 --> 00:08:04,000
|
| 323 |
+
for cash in the combination of query and values provided as parameters as key and list of identifiers
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:08:04,000 --> 00:08:09,000
|
| 327 |
+
of objects returned by query execution as values.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:08:09,000 --> 00:08:17,000
|
| 331 |
+
Note that the using query cache requires a second level cache too, because when you query result is
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:08:17,000 --> 00:08:21,000
|
| 335 |
+
get from cash is it is the list of identifiers.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:08:21,000 --> 00:08:27,000
|
| 339 |
+
Hibernate will load objects using cached identifiers from second level.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:08:27,000 --> 00:08:32,000
|
| 343 |
+
Today we're going to run query level cache due on examples.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:08:33,000 --> 00:08:39,000
|
| 347 |
+
As I promised to you in this lesson, we're going to have practical Dhamma and exercises.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:08:39,000 --> 00:08:44,000
|
| 351 |
+
But before we start the Dharma, I want to discuss with you a few important notes.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:08:45,000 --> 00:08:51,000
|
| 355 |
+
As always, all examples for this lesson you will be able to find in attachments to the video.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:08:52,000 --> 00:08:58,000
|
| 359 |
+
Taking into account there is some specifics with implementation of the second level cache.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:08:59,000 --> 00:09:06,000
|
| 363 |
+
I created a separate project for this example because you need to be very attentive with the selection
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:09:06,000 --> 00:09:09,000
|
| 367 |
+
of hybrid version and cash provider.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:09:09,000 --> 00:09:14,000
|
| 371 |
+
Take into account we have a lot of examples in our GPA project.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:09:14,000 --> 00:09:19,000
|
| 375 |
+
I created a separate project for second level and higher level cash.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:09:19,000 --> 00:09:20,000
|
| 379 |
+
Examples.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:09:21,000 --> 00:09:27,000
|
| 383 |
+
You are already familiar with the GPA terminology, but to take advantage of Hebrew features in this
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:09:27,000 --> 00:09:31,000
|
| 387 |
+
lesson we're going to use Hibernate API.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:09:31,000 --> 00:09:39,000
|
| 391 |
+
While it is pretty intuitive if you know GPA already, still, I would like to highlight a few things.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:09:39,000 --> 00:09:45,000
|
| 395 |
+
Entity Manager Factory in GB is the seamless sync session factory.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:09:45,000 --> 00:09:50,000
|
| 399 |
+
So one of the examples you are going to see is that I work with Session Factory.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:09:50,000 --> 00:09:56,000
|
| 403 |
+
Remember that it has the similar goals as entity manager factory.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:09:57,000 --> 00:10:03,000
|
| 407 |
+
The next thing entity manager in GB is the similar same as session.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:10:03,000 --> 00:10:08,000
|
| 411 |
+
Also on hibernate, we use configuration file with different name.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:10:08,000 --> 00:10:19,000
|
| 415 |
+
So instead of persistence x symbol that we use in GP, we use hibernate c fg x file in hibernate.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:10:20,000 --> 00:10:23,000
|
| 419 |
+
These are the main things that I'd like to highlight.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:10:24,000 --> 00:10:32,000
|
| 423 |
+
So don't panic and don't be confused in case during the demo you would see me using new classes.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:10:33,000 --> 00:10:36,000
|
| 427 |
+
I believe that now we are ready for practical examples.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:10:36,000 --> 00:10:42,000
|
| 431 |
+
Let me start screen sharing and walk you through the examples that I have prepared for this lesson.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:10:43,000 --> 00:10:51,000
|
| 435 |
+
So the already understood is that once entity manager or in hibernate terminology, the session is closed,
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:10:51,000 --> 00:10:54,000
|
| 439 |
+
the first level cache is terminated as well.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:10:55,000 --> 00:11:03,000
|
| 443 |
+
This is actually desirable as it allows for concurrent sessions to work with entity instances in isolation
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:11:03,000 --> 00:11:04,000
|
| 447 |
+
from each other.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:11:05,000 --> 00:11:11,000
|
| 451 |
+
But today we will also learn and see how the second level cache works.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:11:11,000 --> 00:11:19,000
|
| 455 |
+
A second level cache is Session Factory's code, meaning it is shared by all sessions created with the
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:11:19,000 --> 00:11:21,000
|
| 459 |
+
same session factory.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:11:22,000 --> 00:11:30,000
|
| 463 |
+
When an entity instance is looked up by its ID user, by application logic or by hibernate internally.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:11:30,000 --> 00:11:38,000
|
| 467 |
+
This may happen when we need to load associations to that entity from other entities and second level
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:11:38,000 --> 00:11:40,000
|
| 471 |
+
cache is enabled for that entity.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:11:41,000 --> 00:11:48,000
|
| 475 |
+
The following happens If an instance is already present in the first level cache, it is returned from
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:11:48,000 --> 00:11:49,000
|
| 479 |
+
there.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:11:50,000 --> 00:11:57,000
|
| 483 |
+
If an instance isn't found in the first level cache and the corresponding instance state is cached in
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:11:57,000 --> 00:12:02,000
|
| 487 |
+
the second level cache, then the data is fetched from there.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:12:02,000 --> 00:12:07,000
|
| 491 |
+
Otherwise the necessary data are loaded from the database.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:12:08,000 --> 00:12:15,000
|
| 495 |
+
Once the instance is stored in the persistence context first level cache, it is returned from there
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:12:15,000 --> 00:12:24,000
|
| 499 |
+
in all subsequent calls within the same session until the session is closed or the instance is manually
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:12:24,000 --> 00:12:27,000
|
| 503 |
+
evicted from the persistence context.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:12:27,000 --> 00:12:34,000
|
| 507 |
+
The loaded instant state is also stored in the second level cache if it wasn't already there.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:12:35,000 --> 00:12:38,000
|
| 511 |
+
Let's start the demo from Model Overview.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:12:39,000 --> 00:12:43,000
|
| 515 |
+
We're going to use user model and here it is.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:12:43,000 --> 00:12:52,000
|
| 519 |
+
It is also good tone of coding to use cash annotation for the entity that you want to cash for hibernate.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:12:52,000 --> 00:12:59,000
|
| 523 |
+
It means nothing, but still it is good information that this entity will be stored in the second level
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:12:59,000 --> 00:13:00,000
|
| 527 |
+
cache.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:13:01,000 --> 00:13:06,000
|
| 531 |
+
This is gpe annotation, not hibernate specific one.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:13:07,000 --> 00:13:15,000
|
| 535 |
+
I use hybrid cash annotation here too and thus specify cash concurrency strategy and cache region.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:13:16,000 --> 00:13:19,000
|
| 539 |
+
Let's learn what the cache concurrency strategy is.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:13:20,000 --> 00:13:28,000
|
| 543 |
+
Depending on what we need and our use case, we can select one of the following cash concurrency strategies
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:13:28,000 --> 00:13:33,000
|
| 547 |
+
we only use only for entities that never change.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:13:33,000 --> 00:13:35,000
|
| 551 |
+
Exceptions roam.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:13:35,000 --> 00:13:41,000
|
| 555 |
+
If an attempt to update such an entity is made, it is relatively simple.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:13:41,000 --> 00:13:44,000
|
| 559 |
+
It's suitable for static reference data.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:13:44,000 --> 00:13:45,000
|
| 563 |
+
That doesn't change.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:13:46,000 --> 00:13:48,000
|
| 567 |
+
North Street with.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:13:48,000 --> 00:13:48,000
|
| 571 |
+
Right.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:13:49,000 --> 00:13:53,000
|
| 575 |
+
Cash is updated after the transaction that changed.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:13:53,000 --> 00:13:55,000
|
| 579 |
+
The affected data has been committed.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:13:55,000 --> 00:14:04,000
|
| 583 |
+
Thus strong consistency isn't guaranteed and there is small time window in which stale data may be obtained
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:14:04,000 --> 00:14:06,000
|
| 587 |
+
from the cash.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:14:06,000 --> 00:14:13,000
|
| 591 |
+
This kind of strategy is suitable for use cases that can tolerate eventual consistency.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:14:14,000 --> 00:14:15,000
|
| 595 |
+
We tried.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:14:15,000 --> 00:14:25,000
|
| 599 |
+
This strategy guarantees strong consistency, which it achieves by using soft locks when a cached entity
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:14:25,000 --> 00:14:32,000
|
| 603 |
+
is updated and soft lock is stored in the cache for that entity as well, which is released after the
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:14:32,000 --> 00:14:34,000
|
| 607 |
+
transaction is committed.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:14:35,000 --> 00:14:41,000
|
| 611 |
+
All concurrent transactions that access soft locked entries will fetch the corresponding data directly
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:14:41,000 --> 00:14:43,000
|
| 615 |
+
from the database.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:14:43,000 --> 00:14:49,000
|
| 619 |
+
Transactional cash changes are done in distributed global transactions.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:14:50,000 --> 00:14:59,000
|
| 623 |
+
A change in the cash empathy is committed or rolled back in both the database and cash in the same global
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:14:59,000 --> 00:15:00,000
|
| 627 |
+
transaction.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:15:01,000 --> 00:15:05,000
|
| 631 |
+
Let's get back to the user clause and that's a property of cash.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:15:05,000 --> 00:15:07,000
|
| 635 |
+
Annotation is region.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:15:07,000 --> 00:15:10,000
|
| 639 |
+
Basically this is the cache region.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:15:11,000 --> 00:15:17,000
|
| 643 |
+
Later today, I'm going to show you a configuration of our cash, but ensure you can configure cash
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:15:17,000 --> 00:15:24,000
|
| 647 |
+
regions for different entities based on your business case and how you plan to work with the entity.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:15:25,000 --> 00:15:33,000
|
| 651 |
+
And now the important thing that you have to remember in case your entity has collections, we need
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:15:33,000 --> 00:15:40,000
|
| 655 |
+
to add cash annotation above the field separately because collections are not cached by default.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:15:41,000 --> 00:15:45,000
|
| 659 |
+
So we need explicitly more than as cash symbol.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:15:45,000 --> 00:15:46,000
|
| 663 |
+
That's it.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:15:46,000 --> 00:15:53,000
|
| 667 |
+
Regarding our model, let me now open maximum file to show you the dependencies that we need to make
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:15:53,000 --> 00:15:54,000
|
| 671 |
+
this project work.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:15:55,000 --> 00:16:03,000
|
| 675 |
+
Obviously we need to hibernate core dependency and also we need dependency of cache provider hibernate.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:16:03,000 --> 00:16:10,000
|
| 679 |
+
Second level caching is designed to be unaware of the actual cache provider use.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:16:10,000 --> 00:16:19,000
|
| 683 |
+
Hibernate only needs to be provided with an implementation of the OR Hibernate Cache API region factory
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:16:19,000 --> 00:16:25,000
|
| 687 |
+
interface, which encapsulates all the details specific to the actual cache providers.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:16:26,000 --> 00:16:31,000
|
| 691 |
+
Basically, it acts as a bridge between hibernate and cache providers.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:16:31,000 --> 00:16:39,000
|
| 695 |
+
In this lesson I'm going to use E cache and mature and widely used cache as our cache provider.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:16:40,000 --> 00:16:47,000
|
| 699 |
+
We could select any other provider and start as long as there is an implementation of a region factory
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:16:47,000 --> 00:16:48,000
|
| 703 |
+
for.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:16:49,000 --> 00:16:57,000
|
| 707 |
+
I added here hibernate a cache implementation and also our solution would require e cache core dependency.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:16:58,000 --> 00:17:02,000
|
| 711 |
+
This is just a demo with only one possible cache provider.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:17:02,000 --> 00:17:09,000
|
| 715 |
+
This is the most popular one for Hibernate, but theoretically you can use all the cache providers you
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:17:09,000 --> 00:17:10,000
|
| 719 |
+
like.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:17:10,000 --> 00:17:20,000
|
| 723 |
+
The steps to make it work would be similar among other cache providers that I can mention or J bos swarm
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:17:20,000 --> 00:17:24,000
|
| 727 |
+
cache or se cache and others.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:17:25,000 --> 00:17:32,000
|
| 731 |
+
In the case with E cache, we need to make sure that the hibernate e cache version is equal to the hibernate
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:17:32,000 --> 00:17:35,000
|
| 735 |
+
version we're using in our project.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:17:35,000 --> 00:17:41,000
|
| 739 |
+
Now let's enable second level cache in our hibernate configuration file.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:17:41,000 --> 00:17:45,000
|
| 743 |
+
I open hibernate cfg xml file.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:17:45,000 --> 00:17:49,000
|
| 747 |
+
Here you can see four important properties.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:17:49,000 --> 00:17:57,000
|
| 751 |
+
They are hibernate cache region factory class in this property with specified cache factory class.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:17:57,000 --> 00:18:04,000
|
| 755 |
+
In the case with E cache we can specify either E cache region factory or singleton and cache region
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:18:04,000 --> 00:18:05,000
|
| 759 |
+
factory.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:18:05,000 --> 00:18:08,000
|
| 763 |
+
So what is the difference and which one to choose?
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:18:09,000 --> 00:18:17,000
|
| 767 |
+
The non singleton e cache region factory allows you to configure E cache separately for each hibernate
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:18:17,000 --> 00:18:26,000
|
| 771 |
+
instance using nat asf e cache configuration resource name property the singleton a cache region factory
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:18:26,000 --> 00:18:33,000
|
| 775 |
+
shares the same e cache configuration and more all hibernate session factors.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:18:34,000 --> 00:18:36,000
|
| 779 |
+
The next property is hibernate cash.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:18:36,000 --> 00:18:38,000
|
| 783 |
+
Use second level cash.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:18:39,000 --> 00:18:44,000
|
| 787 |
+
We need to switch this one to true to enable second level cash.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:18:45,000 --> 00:18:45,000
|
| 791 |
+
Hibernate.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:18:45,000 --> 00:18:48,000
|
| 795 |
+
Cash use query cash.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:18:48,000 --> 00:18:49,000
|
| 799 |
+
I already told you that.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:18:49,000 --> 00:18:52,000
|
| 803 |
+
Today we are also going through your query cash.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:18:52,000 --> 00:18:55,000
|
| 807 |
+
We need to set this one to true.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:18:55,000 --> 00:19:01,000
|
| 811 |
+
To enable query cash, not net asset cash configuration resource name.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:19:02,000 --> 00:19:09,000
|
| 815 |
+
Here we specify the name of the configuration file that is going to be used to configure our cash.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:19:10,000 --> 00:19:14,000
|
| 819 |
+
This property is a cash provider specific.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:19:15,000 --> 00:19:23,000
|
| 823 |
+
Basically these are the key configurations that we need to add in our cfg xml file.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:19:23,000 --> 00:19:27,000
|
| 827 |
+
Let's now take a look at E cache configuration file.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:19:28,000 --> 00:19:34,000
|
| 831 |
+
I will share with you the source code of this solution and I encourage you to look through this file
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:19:34,000 --> 00:19:35,000
|
| 835 |
+
slowly.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:19:35,000 --> 00:19:43,000
|
| 839 |
+
You don't need to run all these configuration options by heart because anyway, this is not something
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:19:43,000 --> 00:19:45,000
|
| 843 |
+
what you will do each day.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:19:45,000 --> 00:19:51,000
|
| 847 |
+
Most likely this would be configured by analogy only a project for new cache regions.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:19:51,000 --> 00:19:59,000
|
| 851 |
+
As you can see here, we have default cache configured max entries amount the specified time to leave
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:19:59,000 --> 00:20:03,000
|
| 855 |
+
seconds and many other different configurations.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:20:04,000 --> 00:20:08,000
|
| 859 |
+
Memory store eviction policy is important attribute in my opinion.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:20:09,000 --> 00:20:17,000
|
| 863 |
+
With this attribute, we can specify eviction policy for elements in cache because as you remember from
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:20:17,000 --> 00:20:24,000
|
| 867 |
+
the definition, cache should be limited in space and contain limited amount of elements.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:20:24,000 --> 00:20:33,000
|
| 871 |
+
Otherwise we won't be able to benefit from the performance optimization and we need to have a policy
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:20:33,000 --> 00:20:39,000
|
| 875 |
+
which will define what elements should be removed from cache and under what conditions.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:20:40,000 --> 00:20:44,000
|
| 879 |
+
E cash specifies three possible eviction policies.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:20:44,000 --> 00:20:47,000
|
| 883 |
+
They are last recently used.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:20:47,000 --> 00:20:52,000
|
| 887 |
+
This is the one we selected in our example LRU.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:20:52,000 --> 00:20:58,000
|
| 891 |
+
According to this policy, cash is the last recently used element.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:20:59,000 --> 00:21:07,000
|
| 895 |
+
The last use timestamp is updated when an element is put into the cache or an element is retrieved from
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:21:07,000 --> 00:21:09,000
|
| 899 |
+
the cash with a get call.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:21:10,000 --> 00:21:14,000
|
| 903 |
+
Least frequently used as a few.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:21:15,000 --> 00:21:23,000
|
| 907 |
+
For each get call on the element is a number of heads is updated when a put call is made for a new element
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:21:23,000 --> 00:21:30,000
|
| 911 |
+
and assuming the marks limit is reached, the element was least number of hits.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:21:30,000 --> 00:21:34,000
|
| 915 |
+
The least frequently used element is a victim.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:21:34,000 --> 00:21:43,000
|
| 919 |
+
First in, first out elements are evicted in the same order as they come in when a put call is made
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:21:43,000 --> 00:21:51,000
|
| 923 |
+
for a new element and assuming that the max limit is reached for the memory store, the element is it
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:21:51,000 --> 00:21:56,000
|
| 927 |
+
was placed first in the store is the candidate for eviction.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:21:57,000 --> 00:21:59,000
|
| 931 |
+
These are main eviction policies.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:21:59,000 --> 00:22:01,000
|
| 935 |
+
Let's get back to the demo.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:22:02,000 --> 00:22:07,000
|
| 939 |
+
Also, I configure it a few more custom cash regions here.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:22:07,000 --> 00:22:13,000
|
| 943 |
+
They are user standard query cache and update timestamp cache.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:22:13,000 --> 00:22:20,000
|
| 947 |
+
Standard query cache, as the name implies, is a standard implementation of the Hibernate Query Cache
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:22:20,000 --> 00:22:21,000
|
| 951 |
+
interface.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:22:22,000 --> 00:22:29,000
|
| 955 |
+
This implementation is very good at recognizing stale query results and running queries when it detects
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:22:29,000 --> 00:22:30,000
|
| 959 |
+
this condition.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:22:31,000 --> 00:22:32,000
|
| 963 |
+
Recursion.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:22:32,000 --> 00:22:33,000
|
| 967 |
+
The results.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:22:34,000 --> 00:22:41,000
|
| 971 |
+
Update Timestamps Cache Tracks is a timestamps of the most recent updates to particular tables.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:22:41,000 --> 00:22:49,000
|
| 975 |
+
It is important that the cache timeout of the underlying cache implementation be set to a higher value
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:22:49,000 --> 00:22:52,000
|
| 979 |
+
than timeouts of any of the query caches.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:22:53,000 --> 00:22:54,000
|
| 983 |
+
And the user region.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:22:54,000 --> 00:23:02,000
|
| 987 |
+
Cash and user cache region is a region for our entity that we are going to use in our example.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:23:02,000 --> 00:23:07,000
|
| 991 |
+
As you can see, these elements contain persistence, strategy.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:23:07,000 --> 00:23:12,000
|
| 995 |
+
Let's learn what it is and what potential options we can set here.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:23:13,000 --> 00:23:20,000
|
| 999 |
+
The cash has a restored store which provides fast restored ability and options for cash persistence.
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:23:21,000 --> 00:23:26,000
|
| 1003 |
+
The restart store implements and on disk mirror of the in-memory cache.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:23:27,000 --> 00:23:35,000
|
| 1007 |
+
After any restart data that was lost in the cash will automatically load from disk into the restart
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:23:35,000 --> 00:23:39,000
|
| 1011 |
+
store and from there the data will be available to the cash.
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:23:40,000 --> 00:23:50,000
|
| 1015 |
+
Local restart the boot and labels restart store and corpus all cash entries on head and or off heap
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:23:50,000 --> 00:23:51,000
|
| 1019 |
+
to this.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:23:52,000 --> 00:23:59,000
|
| 1023 |
+
This option provides fast or stability with fault tolerant cash persistence on disk.
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:24:00,000 --> 00:24:04,000
|
| 1027 |
+
This option is available for big memory go only.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:24:05,000 --> 00:24:11,000
|
| 1031 |
+
Distributed the first to the third quarter configuration for persistent settings.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:24:11,000 --> 00:24:15,000
|
| 1035 |
+
This option is for big memory marks only.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:24:16,000 --> 00:24:21,000
|
| 1039 |
+
Local temp swop enables temporary local disk usage.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:24:21,000 --> 00:24:28,000
|
| 1043 |
+
This option provides an extra time for storage during cache operation, but this disk storage is not
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:24:28,000 --> 00:24:29,000
|
| 1047 |
+
persistent.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:24:30,000 --> 00:24:35,000
|
| 1051 |
+
After restart, the disk type is cleared of any cache data.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:24:36,000 --> 00:24:40,000
|
| 1055 |
+
LAN doesn't offload cache entries to this.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:24:41,000 --> 00:24:42,000
|
| 1059 |
+
Was this option?
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:24:42,000 --> 00:24:45,000
|
| 1063 |
+
All of the cash is kept in memory.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:24:45,000 --> 00:24:47,000
|
| 1067 |
+
This is a default mode.
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:24:48,000 --> 00:24:50,000
|
| 1071 |
+
Now let's get back to our demo again.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:24:52,000 --> 00:24:52,000
|
| 1075 |
+
Basically.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:24:52,000 --> 00:24:57,000
|
| 1079 |
+
That's all what I wanted to show you regarding the cache configuration.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:24:57,000 --> 00:25:03,000
|
| 1083 |
+
So probably now when everything is configured, let's look at the second level cash demo.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:25:04,000 --> 00:25:06,000
|
| 1087 |
+
I prepared example here for you.
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:25:07,000 --> 00:25:11,000
|
| 1091 |
+
Let me open clause that is called second level cash demo.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:25:11,000 --> 00:25:18,000
|
| 1095 |
+
Execute this program and that will walk you through the console output and source code line by line.
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:25:19,000 --> 00:25:25,000
|
| 1099 |
+
So we create session factory first like we discussed before the demo.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:25:25,000 --> 00:25:34,000
|
| 1103 |
+
This is hibernate API and similar sync to entity manager factory from the GPA I created here hibernate
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:25:34,000 --> 00:25:40,000
|
| 1107 |
+
until factory which simplifies creation and retrieval of session factory.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:25:40,000 --> 00:25:48,000
|
| 1111 |
+
There is lessons super complicated in Z class, but it just helps us to save time and do not repeat
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:25:48,000 --> 00:25:49,000
|
| 1115 |
+
ourselves.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:25:49,000 --> 00:25:49,000
|
| 1119 |
+
Right.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:25:49,000 --> 00:25:56,000
|
| 1123 |
+
A lot of line of codes that we need to use multiple time in different examples today.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:25:56,000 --> 00:26:03,000
|
| 1127 |
+
After that I retrieve statistics object from the session factory and enable statistics.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:26:03,000 --> 00:26:06,000
|
| 1131 |
+
This is again hibernate specific API.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:26:07,000 --> 00:26:11,000
|
| 1135 |
+
This class is used to track statistics of the session factory.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:26:12,000 --> 00:26:19,000
|
| 1139 |
+
The next thing that I do here, I create a user entity and persisted in the database.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:26:20,000 --> 00:26:22,000
|
| 1143 |
+
As you can see, I create session.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:26:22,000 --> 00:26:26,000
|
| 1147 |
+
After that, I use session to start the transaction.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:26:26,000 --> 00:26:34,000
|
| 1151 |
+
And again, I want to help you understand what this API is doing, comparing it with the GP.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:26:34,000 --> 00:26:42,000
|
| 1155 |
+
If you saw my lessons about GP, you can see that these lines of code are similar to creation of entity
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:26:42,000 --> 00:26:45,000
|
| 1159 |
+
manager and start transaction.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:26:45,000 --> 00:26:53,000
|
| 1163 |
+
You can also see here that I use safe, massive safe massive is a hidden analysis of persist mass.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:26:53,000 --> 00:26:57,000
|
| 1167 |
+
Basically this method stores entities in database.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:26:58,000 --> 00:27:05,000
|
| 1171 |
+
After we created user in the database, we create separate session object on purpose to demonstrate
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:27:05,000 --> 00:27:11,000
|
| 1175 |
+
that this is not the same session object as we use to persist our user.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:27:11,000 --> 00:27:15,000
|
| 1179 |
+
It is a different session object and different transaction.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:27:16,000 --> 00:27:21,000
|
| 1183 |
+
After that I use session object to get user with a one from the database.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:27:22,000 --> 00:27:23,000
|
| 1187 |
+
Lot massive.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:27:23,000 --> 00:27:28,000
|
| 1191 |
+
Here is analogy of find method from entity manager class.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:27:28,000 --> 00:27:31,000
|
| 1195 |
+
I use custom method prints thirds.
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:27:31,000 --> 00:27:37,000
|
| 1199 |
+
The user statistics object to show us information about second level cache.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:27:37,000 --> 00:27:43,000
|
| 1203 |
+
Pay attention here we bring to console second level cache hit count.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:27:43,000 --> 00:27:52,000
|
| 1207 |
+
This is global number of cache and that is collections successively retrieved from the cache second
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:27:52,000 --> 00:27:54,000
|
| 1211 |
+
level cache misc count.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:27:54,000 --> 00:28:02,000
|
| 1215 |
+
This is global number of cache entities collections not found in the cache and loaded from the database
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:28:02,000 --> 00:28:05,000
|
| 1219 |
+
second level cache count.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:28:05,000 --> 00:28:10,000
|
| 1223 |
+
This is global number of catchable entities collections pooled in the cache.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:28:10,000 --> 00:28:19,000
|
| 1227 |
+
So before we load the user from the database, you can see that we had zero value for all these three
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:28:19,000 --> 00:28:21,000
|
| 1231 |
+
parameters in our statistics.
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:28:21,000 --> 00:28:29,000
|
| 1235 |
+
When we lower that user from the database, we have one MIS because user was a D wasn't in the second
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:28:29,000 --> 00:28:37,000
|
| 1239 |
+
level cache and we have one count because now this user is stored in the second level cache to.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:28:38,000 --> 00:28:45,000
|
| 1243 |
+
Example number two, where again road user was the same way and that was statistics is not changed.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:28:45,000 --> 00:28:46,000
|
| 1247 |
+
Why?
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:28:47,000 --> 00:28:54,000
|
| 1251 |
+
Because our user currently stored in the first level cache in our session scope cache and user object
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:28:54,000 --> 00:28:57,000
|
| 1255 |
+
is extracted from the first level cache.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:28:58,000 --> 00:29:01,000
|
| 1259 |
+
That's why we still have hit count zero.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:29:02,000 --> 00:29:02,000
|
| 1263 |
+
Example.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:29:02,000 --> 00:29:10,000
|
| 1267 |
+
Number three, lets evict the user from the first level cache vividly by calling evict massive.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:29:10,000 --> 00:29:20,000
|
| 1271 |
+
A big massive is also a specific API, the mass that removes this instance from the session cache and
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:29:20,000 --> 00:29:27,000
|
| 1275 |
+
after that reload user one more time, do you think it will be loaded from the database and request
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:29:27,000 --> 00:29:29,000
|
| 1279 |
+
will be sent to the database?
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:29:29,000 --> 00:29:30,000
|
| 1283 |
+
No.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:29:30,000 --> 00:29:36,000
|
| 1287 |
+
That's exactly the moment where second level cache comes into play.
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:29:36,000 --> 00:29:44,000
|
| 1291 |
+
This time user will be extracted from the second level cache and will not execute query to the database.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:29:44,000 --> 00:29:45,000
|
| 1295 |
+
Isn't this cool?
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:29:46,000 --> 00:29:54,000
|
| 1299 |
+
Just imagine how much requests will not be sent to the database in the scope of the whole application
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:29:54,000 --> 00:29:58,000
|
| 1303 |
+
in case we need to retrieve the same user in different threads.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:29:58,000 --> 00:30:06,000
|
| 1307 |
+
Considering the fact that second level cache is a session factory scoped cache and is not connected
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:30:06,000 --> 00:30:12,000
|
| 1311 |
+
with the one specific session, we will be able to achieve significant performance optimization.
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:30:13,000 --> 00:30:21,000
|
| 1315 |
+
That's why in the third example, we have hit count changed to one that is basically second level cache
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:30:21,000 --> 00:30:22,000
|
| 1319 |
+
in action.
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:30:22,000 --> 00:30:23,000
|
| 1323 |
+
How do you like it?
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:30:24,000 --> 00:30:31,000
|
| 1327 |
+
Even in case you still have some questions regarding the second level cache, please leave your question
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:30:31,000 --> 00:30:35,000
|
| 1331 |
+
and comments to the video and I will be happy to answer.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:30:35,000 --> 00:30:39,000
|
| 1335 |
+
Now let's review example with square level cash.
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:30:39,000 --> 00:30:40,000
|
| 1339 |
+
I open files.
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:30:40,000 --> 00:30:43,000
|
| 1343 |
+
It is called Square Level Cash Demo.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:30:44,000 --> 00:30:50,000
|
| 1347 |
+
This is useful if we frequently execute a query on entities that really change.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:30:50,000 --> 00:30:56,000
|
| 1351 |
+
We already added property to our hybrid configuration to enable query level cache.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:30:56,000 --> 00:31:03,000
|
| 1355 |
+
Now for each query, we just need to call set cache mass and set the value to true.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:31:04,000 --> 00:31:11,000
|
| 1359 |
+
As you can see an example I create query object and call set cache bonus with true argument.
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:31:11,000 --> 00:31:17,000
|
| 1363 |
+
In addition to that, we can even specify a cache region like you see in this example.
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:31:18,000 --> 00:31:21,000
|
| 1367 |
+
That's how you can use query level cache.
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:31:22,000 --> 00:31:25,000
|
| 1371 |
+
That's all for this class and what I wanted to share with you.
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:31:25,000 --> 00:31:29,000
|
| 1375 |
+
Let's recap what we have learned in this lesson.
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:31:30,000 --> 00:31:32,000
|
| 1379 |
+
Today, we learned what the cache is.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:31:32,000 --> 00:31:36,000
|
| 1383 |
+
We learn the cache structure in Hibernate.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:31:36,000 --> 00:31:43,000
|
| 1387 |
+
After this lesson, you have a clear understanding of what first level cache is, what a second level
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:31:43,000 --> 00:31:50,000
|
| 1391 |
+
cache is, and what the query level cache, as we discussed different cache providers and we learned
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:31:51,000 --> 00:31:53,000
|
| 1395 |
+
E cash cache provider.
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:31:53,000 --> 00:31:58,000
|
| 1399 |
+
You saw a real example how to create custom configuration for E cache.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:31:59,000 --> 00:32:03,000
|
| 1403 |
+
Also today, we learned cache eviction policies.
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:32:03,000 --> 00:32:11,000
|
| 1407 |
+
We discussed different persistence strategies in a cache and we received a lot of practical exercises
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:32:12,000 --> 00:32:13,000
|
| 1411 |
+
that solve for this lesson.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:32:14,000 --> 00:32:15,000
|
| 1415 |
+
I hope you liked it.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:32:16,000 --> 00:32:17,000
|
| 1419 |
+
Thanks a lot for your attention.
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:32:17,000 --> 00:32:21,000
|
| 1423 |
+
Have a great day and see in the next lesson.
|
| 1424 |
+
|
78 - ORM, JPA & Hibernate/008 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-hibernate/tree/master/src/main/java/com/itbulls/learnit/hibernate/cache
|
78 - ORM, JPA & Hibernate/009 N+1 Problem and Solution_en.srt
ADDED
|
@@ -0,0 +1,808 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:06,000
|
| 3 |
+
Hello, Tim.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:12,000
|
| 7 |
+
In this lesson, we're going to discuss such popular problems that you can face while working with GPA
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:12,000 --> 00:00:19,000
|
| 11 |
+
SE and plus one, we're going to talk about what this problem is all about and why it is important for
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:19,000 --> 00:00:21,000
|
| 15 |
+
us to solve this challenge.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:21,000 --> 00:00:27,000
|
| 19 |
+
I'm going to show you different solutions and workarounds to help you understand how we can avoid this
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:27,000 --> 00:00:28,000
|
| 23 |
+
issue.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:28,000 --> 00:00:32,000
|
| 27 |
+
We'll have a lot of practical exercises today during the lesson.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:32,000 --> 00:00:34,000
|
| 31 |
+
I will show you the issue in the source code.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:34,000 --> 00:00:40,000
|
| 35 |
+
And after that, we are going to talk about all possible solutions by reviewing code examples.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:40,000 --> 00:00:45,000
|
| 39 |
+
And as always, you can find all code examples in attachments to the lesson.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:45,000 --> 00:00:47,000
|
| 43 |
+
Let's start our lesson.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:48,000 --> 00:00:53,000
|
| 47 |
+
Let's understand first what one problem is by this moment.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:53,000 --> 00:01:00,000
|
| 51 |
+
In our course, you're already familiar with the GPA and you already saw how GPA helps us use development.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:00,000 --> 00:01:05,000
|
| 55 |
+
Also, GPA saves us from writing boilerplate code.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:05,000 --> 00:01:13,000
|
| 59 |
+
It helps us with object relational data mapping, but everything comes with a price and sometimes GPA
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:13,000 --> 00:01:15,000
|
| 63 |
+
brings us some challenges.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:15,000 --> 00:01:18,000
|
| 67 |
+
And plus one problem is one of those.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:19,000 --> 00:01:27,000
|
| 71 |
+
And plus one query problem occurs when an oil ramp tool, like, for example, executes one query to
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:27,000 --> 00:01:32,000
|
| 75 |
+
retrieve the parent entity and and queries to retrieve the child entities.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:33,000 --> 00:01:40,000
|
| 79 |
+
And all this decreases database performance because a lot of queries are sent to fetch all the required
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:40,000 --> 00:01:41,000
|
| 83 |
+
associations.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:41,000 --> 00:01:48,000
|
| 87 |
+
And can you imagine the scale of the challenge in case you have hundreds, thousands of entities across
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:48,000 --> 00:01:49,000
|
| 91 |
+
all your application?
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:50,000 --> 00:01:55,000
|
| 95 |
+
And to help you understand the challenge better, let me proceed with code examples, because it will
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:55,000 --> 00:01:58,000
|
| 99 |
+
be easier for you to understand the challenge.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:59,000 --> 00:02:05,000
|
| 103 |
+
Let's have very simplified example in order to understand the issue and how to resolve it.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:05,000 --> 00:02:09,000
|
| 107 |
+
Imagine that we have online shop and we have entity.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:09,000 --> 00:02:11,000
|
| 111 |
+
Is this called category?
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:12,000 --> 00:02:18,000
|
| 115 |
+
Each category has a unique ID category name and is available flag.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:18,000 --> 00:02:25,000
|
| 119 |
+
We use is available flag to select those categories which we want to show in our online shop.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:25,000 --> 00:02:28,000
|
| 123 |
+
In other words, our active categories.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:28,000 --> 00:02:32,000
|
| 127 |
+
Also, each category can have multiple products.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:32,000 --> 00:02:41,000
|
| 131 |
+
The relationships type is one domain, one category can have multiple products and product type and
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:41,000 --> 00:02:49,000
|
| 135 |
+
charm has unique ID, product, name and category with as many to one relationships from product entity.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:49,000 --> 00:02:50,000
|
| 139 |
+
That's it.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:51,000 --> 00:02:52,000
|
| 143 |
+
Is this example clear for you?
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:53,000 --> 00:02:55,000
|
| 147 |
+
Let me open the demo class now.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:55,000 --> 00:02:58,000
|
| 151 |
+
We created three categories.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:58,000 --> 00:03:02,000
|
| 155 |
+
The category number one is for laptops.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:02,000 --> 00:03:08,000
|
| 159 |
+
The category number two is for TVs, and the category number three is for fridges.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:08,000 --> 00:03:10,000
|
| 163 |
+
Each category has two products.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:10,000 --> 00:03:12,000
|
| 167 |
+
I hope that this is clear.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:13,000 --> 00:03:19,000
|
| 171 |
+
And now imagine in case we need to extract all categories, is it available at the moment?
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:19,000 --> 00:03:26,000
|
| 175 |
+
On the side, we need to extract all categories, all rows of categories, and separately we need to
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:26,000 --> 00:03:33,000
|
| 179 |
+
extract all related products within those categories because in order to fetch the category items,
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:33,000 --> 00:03:38,000
|
| 183 |
+
GP will issue separate queries for each individual category.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:38,000 --> 00:03:46,000
|
| 187 |
+
If, for example, a category has five products, then Jeep will issue five additional queries to fetch
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:46,000 --> 00:03:49,000
|
| 191 |
+
the products included in those orders.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:49,000 --> 00:03:58,000
|
| 195 |
+
This is basically known as plus one problem, one query to fetch all and categories and and queries
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:58,000 --> 00:04:00,000
|
| 199 |
+
to fetch all products.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:01,000 --> 00:04:04,000
|
| 203 |
+
This behavior creates a scalability problem for us.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:04,000 --> 00:04:12,000
|
| 207 |
+
When our data grows, even a moderate number of categories in products can create significant performance
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:12,000 --> 00:04:13,000
|
| 211 |
+
issues.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:13,000 --> 00:04:19,000
|
| 215 |
+
The different implementations suggest us different solutions of this challenge.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:20,000 --> 00:04:21,000
|
| 219 |
+
Let me show you the problem.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:21,000 --> 00:04:28,000
|
| 223 |
+
On example, in my persistence XML configuration, I turned on SQL login.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:28,000 --> 00:04:33,000
|
| 227 |
+
Without login it would be complicated to detect and plus one issue.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:33,000 --> 00:04:38,000
|
| 231 |
+
Let me open the demo file from the problem package and run it.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:39,000 --> 00:04:46,000
|
| 235 |
+
You can see that they use two entity managers in order to submit securities, a database avoiding extracting,
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:46,000 --> 00:04:52,000
|
| 239 |
+
and that is from the first level cache to learn what the first level cache is.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:52,000 --> 00:04:53,000
|
| 243 |
+
Place.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:53,000 --> 00:04:56,000
|
| 247 |
+
Watch previous lesson about caching.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:56,000 --> 00:05:05,000
|
| 251 |
+
So I use the first entity manager to persist all entities and I use the second entity manager to load
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:05,000 --> 00:05:08,000
|
| 255 |
+
all categories that are available in our online shop.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:09,000 --> 00:05:12,000
|
| 259 |
+
Basically all categories that have is available.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:12,000 --> 00:05:14,000
|
| 263 |
+
Flag set to true.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:15,000 --> 00:05:19,000
|
| 267 |
+
I create type query and I extract result list.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:20,000 --> 00:05:26,000
|
| 271 |
+
After that, I print this log message the console and I print all categories.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:26,000 --> 00:05:29,000
|
| 275 |
+
Let's explore now the console output.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:29,000 --> 00:05:37,000
|
| 279 |
+
You can see that hibernate did select for categories that have is available flag set for true and after
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:37,000 --> 00:05:40,000
|
| 283 |
+
that hibernate make two more queries.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:41,000 --> 00:05:44,000
|
| 287 |
+
Basically that is because we have two categories.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:44,000 --> 00:05:52,000
|
| 291 |
+
This flag is available, set the true and after that for each of these categories, hibernate submits
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:52,000 --> 00:05:57,000
|
| 295 |
+
separate queries to extract products for those categories.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:57,000 --> 00:06:04,000
|
| 299 |
+
And what would happen in case I have hundreds of categories and thousands of products that understand
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:04,000 --> 00:06:06,000
|
| 303 |
+
the scope of potential issue?
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:06,000 --> 00:06:14,000
|
| 307 |
+
That is because in our problem statement example, I used IGA fetch type for products in my category
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:14,000 --> 00:06:14,000
|
| 311 |
+
entity.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:15,000 --> 00:06:22,000
|
| 315 |
+
In my demo you can see that I extracted all products even before I actually needed those.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:23,000 --> 00:06:28,000
|
| 319 |
+
You can see that select queries to product entity was executed before.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:28,000 --> 00:06:31,000
|
| 323 |
+
I wanted to print categories to console.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:31,000 --> 00:06:34,000
|
| 327 |
+
This can cause performance issues.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:34,000 --> 00:06:37,000
|
| 331 |
+
So what would be the solution?
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:37,000 --> 00:06:44,000
|
| 335 |
+
Actually, there are different approaches to consider, first of all, and the general one is to avoid
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:44,000 --> 00:06:46,000
|
| 339 |
+
IGA fetching.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:46,000 --> 00:06:50,000
|
| 343 |
+
This is the main reason behind the plus one issue.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:50,000 --> 00:06:54,000
|
| 347 |
+
We should get rid of all IGA fetching from our mapping.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:54,000 --> 00:07:00,000
|
| 351 |
+
They have almost no benefits that justifies the use in the production grade application.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:00,000 --> 00:07:06,000
|
| 355 |
+
We should mark all relationships as lazy and state by default.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:06,000 --> 00:07:07,000
|
| 359 |
+
Fetch type is lazy.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:08,000 --> 00:07:14,000
|
| 363 |
+
So in case you didn't specify fetch type iga vividly, you are not supposed to have an issues.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:15,000 --> 00:07:22,000
|
| 367 |
+
One important point to note more than a relationship mapping is lazy, doesn't guarantee that the underlying
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:22,000 --> 00:07:26,000
|
| 371 |
+
persistent provider will also treat it as such.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:27,000 --> 00:07:31,000
|
| 375 |
+
The specification doesn't guarantees a lazy patch.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:31,000 --> 00:07:35,000
|
| 379 |
+
It is a hint to the persistent provider at best.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:36,000 --> 00:07:40,000
|
| 383 |
+
Let me open the demo across from the solution package and run it.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:41,000 --> 00:07:48,000
|
| 387 |
+
This absolutely is the same example, but we use default lazy fetch type for fetch and products for
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:48,000 --> 00:07:55,000
|
| 391 |
+
the category and if we would explore console output, you can see that select queries to the product
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:55,000 --> 00:08:03,000
|
| 395 |
+
entity has been executed already after I load the category and when I needed those.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:03,000 --> 00:08:11,000
|
| 399 |
+
So basically when I started putting category items into console and they had to have products to show
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:11,000 --> 00:08:19,000
|
| 403 |
+
basically when we refer to the products property inside the category, inside the string method only
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:19,000 --> 00:08:22,000
|
| 407 |
+
then we executed additional queries to the database.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:22,000 --> 00:08:29,000
|
| 411 |
+
This can help us to increase performance because imagine that you work with categories, not always.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:29,000 --> 00:08:35,000
|
| 415 |
+
You need to work with products of those categories and when you need to work with the products only
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:35,000 --> 00:08:39,000
|
| 419 |
+
at that moment you extract the products least that you need.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:40,000 --> 00:08:41,000
|
| 423 |
+
Is it clear.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:41,000 --> 00:08:48,000
|
| 427 |
+
The second thing you have to remember, in order to avoid any plus one issue, never fetch the data
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:48,000 --> 00:08:49,000
|
| 431 |
+
that you don't need.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:50,000 --> 00:08:57,000
|
| 435 |
+
For example, in this particular case will fetch categories that are active and we need to work only
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:57,000 --> 00:08:58,000
|
| 439 |
+
with the category name.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:59,000 --> 00:09:02,000
|
| 443 |
+
Imagine that you need to publish category names.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:02,000 --> 00:09:04,000
|
| 447 |
+
This is just an example.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:04,000 --> 00:09:11,000
|
| 451 |
+
The volume of information you need may vary, but the main thing here is that in case you don't need
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:11,000 --> 00:09:16,000
|
| 455 |
+
all the information about the entity, then do not fetch it.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:16,000 --> 00:09:20,000
|
| 459 |
+
Create a query to fetch on the required and necessary information.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:21,000 --> 00:09:29,000
|
| 463 |
+
I had a case in my practice when I worked with customer entity and each customer had from one to thousand
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:29,000 --> 00:09:29,000
|
| 467 |
+
orders.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:29,000 --> 00:09:31,000
|
| 471 |
+
It was B2B solution.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:31,000 --> 00:09:39,000
|
| 475 |
+
So customers had really a lot of orders and in one query application extracted customers and iterated
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:39,000 --> 00:09:40,000
|
| 479 |
+
over them.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:40,000 --> 00:09:47,000
|
| 483 |
+
And performance of this end point was really poor because of the amount of additional requests sent
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:47,000 --> 00:09:50,000
|
| 487 |
+
to fetch all customer orders.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:50,000 --> 00:09:52,000
|
| 491 |
+
So be careful with this.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:53,000 --> 00:09:54,000
|
| 495 |
+
And that's true.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:54,000 --> 00:10:02,000
|
| 499 |
+
Using next solution we can use during fetch in our queries whenever we need to fetch an entity with
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:02,000 --> 00:10:04,000
|
| 503 |
+
all of its children.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:04,000 --> 00:10:08,000
|
| 507 |
+
At the same time, this results in the much less database.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:08,000 --> 00:10:18,000
|
| 511 |
+
Traffic resulted in an improved performance, starting from the GP 2.1 specification introduced entity
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:18,000 --> 00:10:23,000
|
| 515 |
+
graphs which allows us to create static dynamic query load plans.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:23,000 --> 00:10:31,000
|
| 519 |
+
Entity graphs provides a way to formulate better performing queries by defining which entities need
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:31,000 --> 00:10:34,000
|
| 523 |
+
to be retrieved from the database using SQL joins.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:35,000 --> 00:10:42,000
|
| 527 |
+
The main goal of the entity graph is to improve the runtime performance when loadings, the entities,
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:42,000 --> 00:10:45,000
|
| 531 |
+
related associations and basic fields.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:45,000 --> 00:10:48,000
|
| 535 |
+
There are two types of entity graphs.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:48,000 --> 00:10:55,000
|
| 539 |
+
They are fetch and log which defines is the entities not specified by attribute nodes or entity.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:55,000 --> 00:10:59,000
|
| 543 |
+
Graphs should be fetched lazily or eagerly.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:00,000 --> 00:11:06,000
|
| 547 |
+
Attributes specified by attribute nodes of entity graph are always fetched easily.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:06,000 --> 00:11:14,000
|
| 551 |
+
That means together with the load of the parent entity in fetch graph only the specified attributes
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:14,000 --> 00:11:18,000
|
| 555 |
+
are retrieved from the database in the load graph.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:18,000 --> 00:11:25,000
|
| 559 |
+
In addition to the specified attributes, attribute statically configured as eager are also retrieved.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:26,000 --> 00:11:31,000
|
| 563 |
+
You specify fetch as you strategy by inputting gearbox persistence.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:31,000 --> 00:11:34,000
|
| 567 |
+
Fetch graph is a file containing the entity.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:35,000 --> 00:11:43,000
|
| 571 |
+
In this case, all attributes specified in your entity graph will be treated as fetch type IGA and all
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:43,000 --> 00:11:47,000
|
| 575 |
+
attributes not specified will be treated as fetch type lazy.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:48,000 --> 00:11:55,000
|
| 579 |
+
On the other hand, if you specify load as your strategy by inputting gearbox persistence load graph,
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:55,000 --> 00:12:03,000
|
| 583 |
+
then all attributes specified in the entity graph are also fetch type eg, but attributes not specified
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:03,000 --> 00:12:08,000
|
| 587 |
+
use the specified type or default if the entity specified nothing.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:09,000 --> 00:12:11,000
|
| 591 |
+
This may sound confusing, but don't worry.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:11,000 --> 00:12:14,000
|
| 595 |
+
I'm going to show you all this an example.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:14,000 --> 00:12:19,000
|
| 599 |
+
Let's learn on example how we can define and work with entity graphs.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:20,000 --> 00:12:23,000
|
| 603 |
+
There are two ways to define entity graphs.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:23,000 --> 00:12:31,000
|
| 607 |
+
The first one is by using named entity graph annotation and the second one without entity graphs but
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:31,000 --> 00:12:32,000
|
| 611 |
+
create an entity.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:32,000 --> 00:12:36,000
|
| 615 |
+
Graphs from our entity managers using attribute nodes.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:37,000 --> 00:12:39,000
|
| 619 |
+
Let's learn these two ways on example.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:40,000 --> 00:12:48,000
|
| 623 |
+
According to the first way we need to open our entity and add annotations there to use a named entity
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:48,000 --> 00:12:55,000
|
| 627 |
+
graph first and update the entity class category with GPUs named entity graph annotation.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:55,000 --> 00:12:59,000
|
| 631 |
+
In the example, you can see that I gave the name to the entity graph.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:59,000 --> 00:13:06,000
|
| 635 |
+
I'm going to use this name in the example and then as a property it is called attribute nodes.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:06,000 --> 00:13:12,000
|
| 639 |
+
I add name attribute node was the name of my property that I'd like to fetch.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:12,000 --> 00:13:16,000
|
| 643 |
+
The gas was a parent entity with the help of joint statements.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:17,000 --> 00:13:24,000
|
| 647 |
+
In case we want to use named entity graphs without using annotations, we can create those programmatically.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:24,000 --> 00:13:27,000
|
| 651 |
+
I'm going to show you this in the demo class.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:27,000 --> 00:13:30,000
|
| 655 |
+
Now let me open a demo class.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:31,000 --> 00:13:38,000
|
| 659 |
+
This is a similar example that you already saw, but with the entity graph, pay attention to these
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:38,000 --> 00:13:39,000
|
| 663 |
+
lines of code.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:39,000 --> 00:13:42,000
|
| 667 |
+
Here I create entity graph object.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:13:43,000 --> 00:13:51,000
|
| 671 |
+
I call that entity graph method on the entity manager object and I pause the name of our entity graph.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:13:51,000 --> 00:13:57,000
|
| 675 |
+
In case you don't want to use annotations, you can create an entity graph programmatically.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:13:57,000 --> 00:14:05,000
|
| 679 |
+
Just call not yet entity graph method but called create entity graph method and parse the type for which
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:05,000 --> 00:14:07,000
|
| 683 |
+
you want to create entity graph.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:07,000 --> 00:14:12,000
|
| 687 |
+
After creation of entity graph, you have to add attribute nodes.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:12,000 --> 00:14:19,000
|
| 691 |
+
And again, we already did this with annotations, but you can add them programmatically here by calling
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:19,000 --> 00:14:21,000
|
| 695 |
+
add attribute nodes massive.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:21,000 --> 00:14:25,000
|
| 699 |
+
It is up to you which way of creation of entity graph to choose.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:14:26,000 --> 00:14:31,000
|
| 703 |
+
Now on the query object I called Nasser said hand.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:31,000 --> 00:14:36,000
|
| 707 |
+
I call this method to pass my entity graph as a value result.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:36,000 --> 00:14:40,000
|
| 711 |
+
This hand will fetch products only when it will be needed.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:14:41,000 --> 00:14:49,000
|
| 715 |
+
In this example, we'll use products only when will print products to console, but with this hand will
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:14:49,000 --> 00:14:58,000
|
| 719 |
+
force our GPU implementation to create joint statements and to fetch products in one single query.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:58,000 --> 00:15:06,000
|
| 723 |
+
So in case we would execute this example, we're going to see how products were extracted in scope of
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:06,000 --> 00:15:10,000
|
| 727 |
+
the one SQL query with the help of joint statement.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:10,000 --> 00:15:18,000
|
| 731 |
+
So let's make a summary of how you can avoid and plus one issue, because we have discussed different
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:18,000 --> 00:15:19,000
|
| 735 |
+
options.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:19,000 --> 00:15:20,000
|
| 739 |
+
Let's recap those.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:21,000 --> 00:15:28,000
|
| 743 |
+
The first thing that we can do to avoid endless one issue is to avoid each type and to use laissez faire
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:15:28,000 --> 00:15:29,000
|
| 747 |
+
each type.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:30,000 --> 00:15:35,000
|
| 751 |
+
The second thing that we can do is to fetch only the data that we need.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:35,000 --> 00:15:42,000
|
| 755 |
+
If we don't need the whole information about our entity to perform operation, then let's not fetch
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:42,000 --> 00:15:43,000
|
| 759 |
+
all the data.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:15:43,000 --> 00:15:44,000
|
| 763 |
+
Everything is simple.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:45,000 --> 00:15:51,000
|
| 767 |
+
And the last, but not the least thing to remember to use joins was the help of entity graphs.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:15:52,000 --> 00:15:54,000
|
| 771 |
+
That's so what I wanted to say in this lesson.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:55,000 --> 00:15:58,000
|
| 775 |
+
Let's recap what we have learned today.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:59,000 --> 00:16:02,000
|
| 779 |
+
Today we learned what an impasse one problem is.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:02,000 --> 00:16:09,000
|
| 783 |
+
I believe you understood why it is important to avoid and how it can impact performance of our application.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:10,000 --> 00:16:15,000
|
| 787 |
+
We reviewed and plus one problem solutions where you have two different ones.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:15,000 --> 00:16:22,000
|
| 791 |
+
Today we learned new concept of entity graphs and how to work with them, and we reviewed a lot of different
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:16:22,000 --> 00:16:24,000
|
| 795 |
+
practical exercises.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:16:24,000 --> 00:16:26,000
|
| 799 |
+
That's all for this lesson.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:16:26,000 --> 00:16:28,000
|
| 803 |
+
Thanks a lot for your attention.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:16:28,000 --> 00:16:31,000
|
| 807 |
+
Have a great day and see you in the next lesson.
|
| 808 |
+
|
78 - ORM, JPA & Hibernate/009 Source-code-of-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/n1
|
78 - ORM, JPA & Hibernate/external-links.txt
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
002 Source-code-of-examples-from-the-lesson
|
| 3 |
+
https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
|
| 4 |
+
|
| 5 |
+
003 Source-code-of-examples-from-the-lesson
|
| 6 |
+
https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
|
| 7 |
+
|
| 8 |
+
004 Source-code-of-examples-from-the-lesson
|
| 9 |
+
https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/lifecycle
|
| 10 |
+
|
| 11 |
+
005 Source-code-of-examples-from-the-lesson
|
| 12 |
+
https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/locking
|
| 13 |
+
|
| 14 |
+
006 Source-code-of-examples-from-the-lesson
|
| 15 |
+
https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/mapping
|
| 16 |
+
|
| 17 |
+
007 Source-code-of-examples-from-the-lesson
|
| 18 |
+
https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/queries
|
| 19 |
+
|
| 20 |
+
008 Source-code-of-examples-from-the-lesson
|
| 21 |
+
https://github.com/AndriiPiatakha/java-learnit-hibernate/tree/master/src/main/java/com/itbulls/learnit/hibernate/cache
|
| 22 |
+
|
| 23 |
+
009 Source-code-of-examples-from-the-lesson
|
| 24 |
+
https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/n1
|
79 - ===== ORM & JPA Interview Preparation =====/001 Part 1 ORM & Hibernate Interview - Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 1 ORM & Hibernate Interview - Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 1 ORM & Hibernate Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT IS ORM?</strong></p></li></ul><p><br></p><p>ORM (Object-relational mapping) - programming technology, which links databases to the concepts of object-oriented programming languages, creating a "virtual object database".</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS HIBERNATE?</strong></p></li></ul><p><br></p><p>It is a framework for object-relational mapping of entities to a traditional relational database.</p><p><br></p><p>The main features of the framework:</p><ul><li><p>Automatic generation and updating of tables in databases;</p></li><li><p>Since the main database queries (save, update, delete and search) are presented as methods of the framework, the code that is written by the developer is significantly reduced;</p></li><li><p>Provides the use of a SQL-like language (HQL - hibernate query language). HQL queries can be written with a number of data objects (POJO classes prepared to work with the database).</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE THE BENEFITS OF USING HIBERNATE?</strong></p></li></ul><p><br></p><p>Some of them:</p><ul><li><p>Eliminates a lot of repetitive code that constantly haunts a developer when working with JDBC. Hides from the developer a lot of code needed to manage resources and allows you to focus on business logic.</p></li><li><p>Supports XML as well as JPA annotations, which allows you to make the implementation of the code independent.</p></li><li><p>Provides its own powerful query language (HQL) which is similar to SQL. It is worth to highlight that HQL is fully object-oriented and understands principles such as inheritance, polymorphism, and associations (relationships).</p></li><li><p>Hibernate integrates easily with other Java EE frameworks, for example the Spring Framework supports built-in integration with Hibernate.</p></li><li><p>Supports lazy initialization using proxy objects and queries the database only when needed.</p></li><li><p>Supports different levels of cache, and therefore can improve performance.</p></li><li><p>It is important that Hibernate can use pure SQL, which means it supports the ability to optimize queries and work with any third-party database vendor.</p></li><li><p>Hibernate is an open source project. Thanks to this, thousands of open articles, examples, as well as documentation on using the framework are available.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW DOES HIBERNATE HELP WITH PROGRAMMING?</strong></p></li></ul><p><br></p><p>Hibernate implements a number of features that greatly simplify the developer's work.</p><ul><li><p>One such feature is that hibernate allows the developer to avoid writing most SQL queries (they are already implemented, you just need to use the methods provided by the framework).</p></li><li><p>Under the hood, Hibernate has a bunch of useful tools that significantly speed up the application, the most notable of which are two-level caching and fine-tuning lazy and eager fetching.</p></li><li><p>It generates tables in the database</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE BENEFITS OF HIBERNATE OVER JDBC?</strong></p></li></ul><p><br></p><p>Hibernate has a number of advantages over the JDBC API:</p><ul><li><p>Hibernate removes a lot of repetitive code from the JDBC API and is therefore easier to read, write and maintain.</p></li><li><p>Hibernate supports inheritance, associations, and collections, which is not available in the JDBC API.</p></li><li><p>Hibernate implicitly uses transaction management. Most queries cannot be executed outside of a transaction. When using the JDBC API to manage transactions, you must explicitly use commit and rollback.</p></li><li><p>JDBC API throws SQLException, which refers to checked exceptions, which means that you need to constantly write a lot of try-catch blocks. In most cases this is not needed for every JDBC call and is used for transaction management. Hibernate wraps JDBC exceptions through unchecked JDBCException or HibernateException, which means there is no need to check them in your code every time. Hibernate's built-in transaction management support removes try-catch blocks.</p></li><li><p>Hibernate Query Language (HQL) is a more object-oriented and Java-like programming language than SQL in JDBC.</p></li><li><p>Hibernate supports caching, but JDBC queries do not, which can degrade performance.</p></li><li><p>Hibernate provides the ability to manipulate the database (such as creating tables), while JDBC can only work with existing tables in the database.</p></li><li><p>The Hibernate configuration allows you to use JDBC like a JNDI DataSource connection for a connection pool. This is an important feature for enterprise applications that is completely missing from the JDBC API.</p></li><li><p>Hibernate supports JPA annotations, which means that the code is portable to other ORM frameworks that implement the standard, while the JDBC code is tightly coupled to the application.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS A HIBERNATE CONFIGURATION FILE?</strong></p></li></ul><p><br></p><p>The Hibernate configuration file contains data about the database and is required to initialize the SessionFactory. In the .xml file, you must specify the database vendor or JNDI resources, as well as information about the dialect used, which will help hibernate choose the mode of operation with a particular database.</p><p><br></p><p><br></p><ul><li><p><strong>WAYS TO CONFIGURE HIBERNATE.</strong></p></li></ul><p><br></p><p>There are four ways to configure how Hibernate works:</p><ul><li><p>using annotations;</p></li><li><p>hibernate.cfg.xml</p></li><li><p>hibernate.properties;</p></li><li><p>persistence.xml.</p></li></ul><p><br></p><p>The most common configuration method: through annotations and the persistence.xml file, as for the hibernate.properties and hibernate.cfg.xml files, hibernate.cfg.xml is more important (if the application has both files, then the settings from the hibernate.cfg file are accepted. xml). Annotation configuration, although convenient, is not always possible, for example, if you want to have different entity configurations for different databases or for different situations, then you should use xml configuration files.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS HIBERNATE MAPPING FILE?</strong></p></li></ul><p><br></p><p>A mapping file is used to link entity beans and columns in a database table. In cases where JPA annotations are not used, an .xml mapping file can be useful.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE TRANSIENT OBJECTS?</strong></p></li></ul><p><br></p><p>Instances of long-lived classes that are not currently associated with a Session. They may have been initialized in the application and not yet saved, or they may have been initialized with a closed Session.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE PERSISTENT OBJECTS?</strong></p></li></ul><p><br></p><p>Short-lived, single-threaded objects containing persistent state and business functions. These can be plain Java Beans/POJOs (Plain Old Java Object). They are associated with only one Session. After the Session is closed, they will be separated and free to be used in any application layer protocol (for example, as data transfer objects to and from the view).</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS TRANSACTIONFACTORY?</strong></p></li></ul><p><br></p><p>Factory for Transaction instances. The interface is not open to the application, but can be extended or implemented by the developer.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS CONNECTIONPROVIDER?</strong></p></li></ul><p><br></p><p>Factory and pool of JDBC connections. The interface abstracts the application from the underlying data source or driver manager. It is not open to the application, but can be extended or implemented by the developer.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS A TRANSACTION?</strong></p></li></ul><p><br></p><p>A single-threaded, short-lived object used by an application to specify atomic work variables. It abstracts the application from the underlying JDBC, JTA, or CORBA transactions. A Session may span multiple Transactions in some cases. However, transaction demarcation is always mandatory.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE THE STRATEGIES FOR LOADING OBJECTS IN HIBERNATE?</strong></p></li></ul><p><br></p><p>There are following fetch types:</p><ul><li><p>Join fetching: hibernate fetches associated objects and collections in one SELECT using OUTER JOIN</p></li><li><p>Select fetching: Uses a qualifying SELECT to get associated objects and collections. If you don't set lazy fetching by defining lazy="false", the qualifying SELECT will only be executed when you request access to associated objects</p></li><li><p>Subselect fetching: The behavior is the same as the previous type, except that the associations for all other collections whose "parent" is the entity you loaded with the first SELECT will be loaded.</p></li><li><p>Batch fetching: Optimized select fetching view strategy. Gets a group of entities or collections in a single SELECT.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE ID GENERATOR CLASSES IN HIBERNATE?</strong></p></li></ul><p><br></p><ul><li><p>increment - Generates an identifier of type long, short, or int that will only be unique if no other process is adding an entry to the same table at the same time.</p></li><li><p>identity - generates an identifier of type long, short, or int. Supported in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL.</p></li><li><p>sequence - uses sequences in DB2, PostgreSQL, Oracle, SAP DB, McKoi, or the Interbase generator. Returns an identifier of type long, short, or int.</p></li><li><p>hilo - Uses the hi/lo algorithm to generate long, short, or int identifiers. The algorithm guarantees the generation of identifiers that are unique only in the given database.</p></li><li><p>seqhilo - Uses the hi/lo algorithm to generate long, short, or int type identifiers given a database sequence.</p></li><li><p>uuid - uses the 128-bit UUID algorithm to generate an identifier. The identifier will be unique within the network. The UUID is represented as a string of 32 numbers.</p></li><li><p>guid - uses a DB generated GUID string in MS SQL Server and MySQL.</p></li><li><p>native - uses identity, sequence or hilo depending on the type of database the application works with</p></li><li><p>assigned - Allows an application to set an identifier for an object before the save() method is called. Used by default if the <generator> tag is not specified.</p></li><li><p>select - Gets the primary key assigned by the database trigger</p></li><li><p>foreign - uses the identifier of another object associated with the given object. Used in <one-to-one> primary key associations.</p></li><li><p>sequence-identity is a specialized identifier generator.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE THE KEY INTERFACES HIBERNATE USES?</strong></p></li></ul><p><br></p><p>There are five key interfaces that are used in every Hibernate related application:</p><ul><li><p>Session interface;</p></li><li><p>SessionFactory interface;</p></li><li><p>Configuration interface;</p></li><li><p>Transaction interface;</p></li><li><p>Query and Criteria interfaces.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>NAME SOME IMPORTANT ANNOTATIONS USED FOR Rendering IN HIBERNATE.</strong></p></li></ul><p><br></p><p>Hibernate supports both annotations from JPA and its own annotations, which are located in the org.hibernate.annotations package. The most important JPA and Hibernate annotations are:</p><p><br></p><ul><li><p>javax.persistence.Entity: used to specify a class as an entity bean.</p></li><li><p>javax.persistence.Table: used to define the name of the table from the database that will be mapped to the entity bean.</p></li><li><p>javax.persistence.Access: Specifies the access type, field or property. The field is the default value and if you want hibernate to use getter/setter methods, then they must be set for the desired property.</p></li><li><p>javax.persistence.Id: defines the primary key in the entity bean.</p></li><li><p>javax.persistence.EmbeddedId: used to define an embedded key in a bean.</p></li><li><p>javax.persistence.Column: Specifies the name of a column from a table in the database.</p></li><li><p>javax.persistence.GeneratedValue: Specifies the strategy for generating primary keys. Used in conjunction with javax.persistence.GenerationType enum.</p></li><li><p>javax.persistence.OneToOne: Specifies a one-to-one relationship between two entity beans. Accordingly, there are other OneToMany, ManyToOne and ManyToMany annotations.</p></li><li><p>org.hibernate.annotations.Cascade: Defines a cascading relationship between two entity beans. Used in conjunction with org.hibernate.annotations.CascadeType.</p></li><li><p>javax.persistence.PrimaryKeyJoinColumn: Specifies the foreign key for the property. Used in conjunction with org.hibernate.annotations.GenericGenerator and org.hibernate.annotations.Parameter.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE ROLE OF THE SESSION INTERFACE IN HIBERNATE?</strong></p></li></ul><p><br></p><p>Session is the main interface that is responsible for communicating with the database. Also, it helps to create query objects to get persistent objects. (persistent object - an object that is already in the database; query object - an object that is obtained when we receive the result of a query to the database, the application works with it). The Session object can be obtained from the SessionFactory.</p><p><br></p><p>Role of the Session interface:</p><ul><li><p>is a wrapper for JDBC database connection;</p></li><li><p>is a factory for transactions (according to the official documentation transaction - allows the application to define units of work, which, in fact, means that the transaction defines the boundaries of operations associated with the database).</p></li><li><p>is the keeper of the mandatory first-level cache.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE ROLE OF THE SESSIONFACTORY INTERFACE IN HIBERNATE?</strong></p></li></ul><p><br></p><p>We can objects of type session from the object of the SessionFactory type. There is only one SessionFactory for the entire application, and it is initialized along with the start of the application. The SessionFactory caches metadata and SQL queries that are frequently used by the application at runtime. It also caches information that was received in one of the transactions and can be used in other transactions.</p><p><br></p><p><br></p><ul><li><p><strong>IS HIBERNATE SESSIONFACTORY THREADS SAFE?</strong></p></li></ul><p><br></p><p>Because the SessionFactory object is immutable (immutable), then yes, it is thread-safe. Multiple threads can access the same object at the same time.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE BETWEEN OPENSESSION AND GETCURRENTSESSION?</strong></p></li></ul><p><br></p><p>Hibernate SessionFactory <strong>getCurrentSession</strong>() returns the session associated with the context. But in order for this to work, we need to set it up in the hibernate config file. Since this session object is associated with the hibernate context, there is no need to close it. The session object is closed when the SessionFactory is closed.</p><p><br></p><p>The Hibernate SessionFactory <strong>openSession</strong>() method always creates a new session. We must ensure that the session object is closed when all database operations are completed.</p><p><br></p><p>For a multi-threaded environment, a new session object must be created for each request.</p><p>There is another openStatelessSession() method that returns a stateless session. Such an object does not implement the first level of caching and does not interact with the second level. This also includes ignoring collections and some event handlers. Such objects can be useful when loading large amounts of data without keeping a large amount of information in the cache.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT CACHE TYPES DOES HIBERNATE USE?</strong></p></li></ul><p><br></p><p>Hibernate uses 2 types of cache: first level cache and second level cache.</p><p><br></p><p>The first level cache is associated with the session object, while the second level cache is associated with the session factory object. By default, Hibernate uses the first level cache for every operation in a transaction. First of all, the cache is used to reduce the number of SQL queries. For example, if an object has been modified multiple times in the same transaction, then Hibernate will generate only one UPDATE.</p><p><br></p><p>To reduce traffic from the database, Hibernate uses a second-level cache that is shared across the entire application, not just for this particular user. Thus, if the query result is in the cache, we potentially reduce the number of transactions to the database.</p><p><br></p><p>EHCache is a fast and simple cache. It supports read-only and read/write caching, as well as caching to memory and to disk. But does not support clustering.</p><p><br></p><p>OSCache is another opensource cache implementation. In addition to everything that EHCache supports, this implementation also supports clustering via JavaGroups or JMS.</p><p><br></p><p>SwarmCache is just a cluster-based solution based on JavaGroups. Supports read-only and non-strict read/write caching. This type of caching is useful when the number of read operations from the database exceeds the number of write operations.</p><p><br></p><p>JBoss TreeCache - Provides a complete transaction cache.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT TYPES OF CACHE STRATEGIES ARE THERE?</strong></p></li></ul><p><br></p><ul><li><p>Read-only: This strategy is used when data is being read but never updated. The simplest and most productive strategy</p></li><li><p>Read/write: can be used when the data needs to be updated.</p></li><li><p>Non-strict read/write: This strategy does not guarantee that two transactions do not modify the same data synchronously.</p></li><li><p>Transactional: full transaction caching. Only available in JTA environment.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT DO YOU KNOW ABOUT HIBERNATE CACHE? EXPLAIN LEVEL 1 CACHE IN HIBERNATE?</strong></p></li></ul><p><br></p><p>Hibernate uses caching to make our application faster. The Hibernate cache can be very helpful in getting high application performance when used properly. The idea of caching is to reduce the number of queries to the database.</p><p><br></p><p>The Hibernate first level cache is associated with the Session object. Hibernate's first level cache is enabled by default and there is no way to disable it. However, Hibernate provides methods by which we can remove selected objects from the cache or clear the cache entirely.</p><p><br></p><p>Any object cached in a session will not be visible to other session objects. After the session object is closed, all cached objects will be lost.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
79 - ===== ORM & JPA Interview Preparation =====/002 Part 2 ORM & Hibernate Interview - Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 2 ORM & Hibernate Interview - Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 2 ORM & Hibernate Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>HOW TO CONFIGURE THE SECOND LEVEL CACHE IN HIBERNATE?</strong></p></li></ul><p><br></p><p>To specify a second level cache you need to define hibernate.cache.provider_class in hibernate.cfg.xml.</p><p><br></p><p>The default is EHCache.</p><p>To use the query cache, you need to enable it by setting the hibernate.cache.use_query_cache property to true in hibernate.properties.</p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE IN THE WORK OF THE LOAD(); And GET();?</strong></p></li></ul><p><br></p><p>Hibernate session has various methods for loading data from the database. Most often</p><p>the methods used for this are get() and load().</p><ul><li><p>load() method usually used when you are not sure if the requested object is already in the database. If the object is not found, then the method throws an exception. If the object is found, the method returns a proxy object, which is a link to the object located in the database (the request to the database has not yet been made, a kind of lazy wfetching), a direct query to the database will be performed when we we directly access the required object through the proxy object.</p></li><li><p>get() method is used when you are not 100 percent sure if the requested object exists in the database. In the case of accessing a non-existent object, the get(); will return null. If an object is found, the get() method will return the object itself and the query to the database will be made immediately.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE THE DIFFERENT STATES OF THE ENTITY BEAN?</strong></p></li></ul><p><br></p><ul><li><p>Transient: A state in which an object has never been associated with any session and is not persistent. This object is in a temporary state. An object in this state can become persistent when the save(), persist(), or saveOrUpdate() method is called. A persistence object can transition to a transient state after calling the delete() method.</p></li><li><p>Persistent: When an object is associated with a unique session, it is in a persistent state. Any instance returned by the get() or load() methods is in a persistent state.</p></li><li><p>Detached: If an object was persistent but is not currently associated with any session, then it is in the detached state. Such an object can be made persistent using the update() , saveOrUpdate() , lock() , or replicate() methods. The transient or detached states can also transition to the persistent state as a new persistence object after calling the merge() method.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT HAPPENS IF THE ENTITY BEAN DOES NOT HAVE A CONSTRUCTOR WITHOUT ARGUMENTS?</strong></p></li></ul><p><br></p><p>Hibernate uses reflection to instantiate Entity beans when the get() or load() methods are called. This is done using the Class.newInstance() method, which requires a parameterless constructor. Therefore, if it is missing, you will get a HibernateException error.</p><p><br></p><p><br></p><ul><li><p><strong>HOW IS THE HIBERNATE SESSION MERGE() METHOD CALL USED?</strong></p></li></ul><p><br></p><p>Hibernate merge() can be used to update existing values, however this method creates a copy from the passed entity object and returns it. The returned object is part of the persistence context and tracks any changes, while the passed object is not tracked.</p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE BETWEEN HIBERNATE SAVE(), SAVEORUPDATE() AND PERSIST()?</strong></p></li></ul><p><br></p><p>Hibernate save() is used to save an entity to the database. The problem with using the save() method is that it can be called without a transaction. Therefore, if we have a set of several objects, then only the one object potentially can be saved and we will get inconsistent data. Also save() returns the generated ID immediately.</p><p><br></p><p>Hibernate persist() is similar to save() with a transaction. persist() doesn't return the generated ID right away.</p><p><br></p><p>Hibernate saveOrUpdate() uses a query to insert or update based on the provided data. If the data is already present in the database, then an update request will be executed. The saveOrUpdate() method can be used without a transaction, but it can lead to the same problems as the save() method.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS LAZY FETCHING IN HIBERNATE?</strong></p></li></ul><p><br></p><p>The Lazy fetching type, in Hibernate, is associated with leaf (child) entities and defines a shared checkout policy if a request is made to fetch a parent entity.</p><p><br></p><p>Simple example:</p><p>There is the essence of the House. It stores information about its number, street, number of apartments and information about the families that live in apartments, these families form a child entity relative to the House entity. When we request information about the House, it may be completely unnecessary for us to know the information about the families that live in it, here lazy fetching comes to our aid, which allows us to configure the House entity so that information about families is submitted only on demand, this is significant facilitates the request and speeds up the application.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE BETWEEN SORTED COLLECTION AND ORDERED COLLECTION? WHICH ONE IS BETTER?</strong></p></li></ul><p><br></p><p>When using the sorting algorithms from the Collection API to sort a collection, it calls a sorted list. For small collections, this does not result in excessive resource consumption, but for large collections, it can lead to performance degradation and OutOfMemory errors. Also, entity beans must implement the Comparable or Comparator interface to work with sorted collections.</p><p><br></p><p>When using the Hibernate framework to load data from a database, we can use the Criteria API and the order by command to get an ordered list. Ordered list is a better choice to sorted list, because it uses sorting at the database level. It is faster and cannot leak memory.</p><p><br></p><p><br></p><ul><li><p><strong>HOW WE CAN USE JOINS IN HIBERNATE?</strong></p></li></ul><p>There are several ways to implement relationships in Hibernate.</p><ul><li><p>Use associations such as one-to-one, one-to-many, many-to-many.</p></li><li><p>Use JOIN command in HQL query. There is another form of "join fetch" that allows data to be loaded immediately (not lazy).</p></li><li><p>Use pure SQL query with join command.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHY SHOULD WE NOT MAKE ENTITY CLASS FINAL?</strong></p></li></ul><p><br></p><p>Hibernate uses proxy classes to load data lazily (i.e. as needed, not immediately). This is achieved by extending the entity bean and hence if it were final then this would not be possible. Lazy loading data improves performance in many cases and is therefore important.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT DO YOU KNOW ABOUT HQL AND WHAT ARE ITS BENEFITS?</strong></p></li></ul><p><br></p><p>The Hibernate Framework comes with a powerful object-oriented query language, Hibernate Query Language (HQL). It is very similar to SQL, except that it uses objects instead of table names, making the language closer to object-oriented programming.</p><p><br></p><p>HQL is case-insensitive, except for the use of java variable and class names in queries, where it obeys the rules of Java. For example, SelECt is the same as select, but com.test.MyClass is different from com.test.MyCLASS. HQL queries are cached (this is both an advantage and a disadvantage).</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS QUERY CACHE IN HIBERNATE?</strong></p></li></ul><p><br></p><p>Hibernate implements a cache scope for resultset queries that works closely with Hibernate's second-level cache. Connecting this extra feature requires a few extra steps in the code. Query Cache is only useful for frequently executed queries with repetitive parameters. First you need to add special configuration into the Hibernate configuration file.</p><p><br></p><p>And after that, already inside the application code, the setCacheable(true) method is used for the request.</p><p><br></p><p><br></p><ul><li><p><strong>CAN WE EXECUTE A SQL (SQL NATIVE) QUERY IN HIBERNATE?</strong></p></li></ul><p><br></p><p>By using SQLQuery, you can execute a pure SQL query. In general, this is not recommended, because you lose all the benefits of HQL (associations, caching).</p><p><br></p><p><br></p><ul><li><p><strong>NAME THE BENEFITS OF NATIVE SQL SUPPORT IN HIBERNATE.</strong></p></li></ul><p><br></p><p>Using native SQL may be necessary when querying some databases that may not be supported by Hibernate. An example is some specific queries and special occasions when working with a database from Oracle.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS NAMED SQL QUERY?</strong></p></li></ul><p><br></p><p>Hibernate supports a named query that we can define in a central place and then use it anywhere in the code. Named queries support both HQL and Native SQL. You can create a named query using the @NamedQuery, @NamedNativeQuery JPA annotations or in the mapping configuration file.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE THE BENEFITS OF NAMED SQL QUERY?</strong></p></li></ul><p><br></p><ul><li><p>The Hibernate named query allows you to collect many queries in one place and then call them in any class.</p></li><li><p>The syntax of the Named Query is checked when the session factory is created, which allows you to notice an error at an early stage, and not when the application is running and the request is executed.</p></li><li><p>Named Query are global, i.e. given once, can be used anywhere.</p></li><li><p>However, one of the main disadvantages of a named query is that it is very difficult to debug (it can be difficult to find where the query is defined).</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT DO YOU KNOW ABOUT HIBERNATE PROXY AND HOW DOES IT HELP WITH LAZY LOAD?</strong></p></li></ul><p><br></p><p>Hibernate uses a proxy object to support lazy loading. Normally, when loading data from a table, Hibernate does not load all the mapped objects. As soon as you refer to a child object or lookup an object using a getter, if the related entity is not in the session cache, then the proxy code will go to the database to load the related entity. It uses javassist to efficiently and dynamically create subclass implementations of your entity objects.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW TO MANAGE TRANSACTIONS WITH HIBERNATE?</strong></p></li></ul><p><br></p><p>Hibernate generally doesn't allow most operations without using transactions. Therefore, after receiving the session instance from the SessionFactory, beginTransaction() must be executed to start the transaction. The method will return a link that we can use to commit or rollback the transaction.</p><p><br></p><p>In general, transaction management in the framework is much better than in JDBC, because we should not rely on throwing an exception to roll back a transaction. Any exception will automatically call rollback.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS CASCADE LINKS (UPDATES) IN HIBERNATE?</strong></p></li></ul><p><br></p><p>If we have dependencies between entities, then we need to determine how different operations will affect another entity. This is done using cascading links (or updates).</p><p><br></p><p><br></p><ul><li><p><strong>WHAT CASCADE TYPES ARE IN HIBERNATE?</strong></p></li></ul><p><br></p><p>The most commonly used CascadeType enums are described below.</p><ul><li><p>None: No Cascading. Formally, this is not a type, but if we do not specify a cascading relationship, then no operation on the parent will have an effect on the child.</p></li><li><p>ALL: Cascades save, delete, update, evict, lock, replicate, merge, persist. Well, that's all.</p></li><li><p>SAVE_UPDATE: Cascades save and update. Only available for hibernate.</p></li><li><p>DELETE: Passes an action to Hibernate's native DELETE. For hibernate only.</p></li><li><p>DETATCH, MERGE, PERSIST, REFRESH and REMOVE are for simple operations.</p></li><li><p>LOCK: Passes an action to Hibernate's native LOCK.</p></li><li><p>REPLICATE: Passes an action to Hibernate's native REPLICATE.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT IS SESSION AND SESSION FACTORY IN HIBERNATE? HOW TO SET UP A SESSION FACTORY IN A SPRING CONFIGURATION FILE?</strong></p></li></ul><p><br></p><p>Hibernate session is the main interface between Java application and Hibernate. The SessionFactory allows you to create sessions according to the hibernate.cfg.xml configuration.</p><p><br></p><p>When Configuration().configure() is called, the hibernate.cfg.xml file is loaded and the Hibernate environment is configured. After the configuration is loaded, you can make additional modifications to the settings already at the program level. These adjustments are possible before the session factory is instantiated. The SessionFactory instance is typically created once and used throughout the application.</p><p><br></p><p>The main task of the session is to provide mechanisms for creating, reading and deleting instances of classes attached to the database. Instances can be in three states:</p><ul><li><p>transient - never saved, not associated with any session;</p></li><li><p>persistent - associated with a unique session;</p></li><li><p>detached - previously saved, not associated with the session.</p></li></ul><p><br></p><p>The Hibernate Session object represents a single database operation. A session is opened by a session factory. The session must be closed when all database operations are completed.</p><p><br></p><p><br></p><ul><li><p><strong>HOW TO USE JNDI DATASOURCE APP SERVER WITH HIBERNATE FRAMEWORK?</strong></p></li></ul><p><br></p><p>In a web application, it is best to use a servlet container to manage the connection pool. Therefore, it is better to define a JNDI resource for the DataSource and use it in the web application. To do this in Hibernate, you need to remove all database-specific properties and use JNDI DataSource property hints.</p><p><br></p><p><br></p><ul><li><p><strong>HOW TO INTEGRATE HIBERNATE AND SPRING?</strong></p></li></ul><p><br></p><p>It is best to read about the settings on the framework sites for the current version. Both frameworks support integration out of the box and in general, setting up their interaction is not difficult. The general steps are as follows.</p><p><br></p><ul><li><p>Add dependencies for hibernate-entitymanager, hibernate-core and spring-orm.</p></li><li><p>Create model classes and pass DAO implementations of database operations. It is important that the DAO classes use the SessionFactory, which is injected into the Spring bean configuration.</p></li><li><p>Set up the Spring configuration file (look in the offline documentation or from the example on this site).</p></li><li><p>Additionally, it becomes possible to use the @Transactional annotation and stop worrying about Hibernate transaction management.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT PATTERNS ARE USED IN HIBERNATE?</strong></p></li></ul><p><br></p><ul><li><p>Domain Model Pattern - An object model of a domain that includes both behavior and data.</p></li><li><p>Data Mapper is a Mappers layer that transfers data between objects and the database, keeping them independent of each other and themselves.</p></li><li><p>Proxy Pattern - used for lazy loading.</p></li><li><p>Factory pattern - used in SessionFactory</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE BENEFITS OF USING THE HIBERNATE TOOLS ECLIPSE PLUG?</strong></p></li></ul><p><br></p><p>The Hibernate Tools plugin makes it easy to set up a mapping, configuration file. Simplifies work with property files or xml tags. Helps to minimize coding errors.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
79 - ===== ORM & JPA Interview Preparation =====/003 Part 3 JPA Interview - Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 3 JPA Interview - Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 3 JPA Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT IS JPA?</strong></p></li></ul><p><br></p><p>JPA is a technology that provides an object-relational mapping of simple JAVA objects and provides an API for storing, retrieving, and manipulating such objects.</p><p>JPA is a specification (a document approved as a standard that describes all aspects of the technology), part of the EJB3 specification.</p><p>JPA itself does not know how to save or manage objects, JPA only determines the rules of the game: how something will act. JPA also defines interfaces that will need to be implemented by providers. Plus, JPA defines rules about how mapping metadata should be described and how providers should work. Further, each provider, implementing JPA, defines getting, saving and managing objects. Each provider has a different implementation.</p><p><br></p><p>JPA implementations:</p><ul><li><p>Hibernate</p></li><li><p>Oracle TopLink</p></li><li><p>Apache Open JPA</p></li><li><p>Eclipselink</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS JPA COMPOSED OF?</strong></p></li></ul><p><br></p><p>JPA consists of three main points:</p><ul><li><p>APIs are the interfaces in the javax(jakarta).persistance package. A set of interfaces that allow you to organize interaction with an ORM provider.</p></li><li><p>JPQL is an object query language. Very similar to SQL, but queries are performed on objects.</p></li><li><p>Metadata - annotations over objects. A set of annotations with which we describe the displayed metadata. Then JPA already knows which object to which table needs to be saved. Metadata can be described in two ways: by an XML file or through annotations.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS JPA DIFFERENT FROM HIBERNATE?</strong></p></li></ul><p><br></p><p>Hibernate is one of the most popular open-source implementations of the latest specification. That is, JPA only describes the rules and API, and Hibernate implements these descriptions, however, Hibernate (like many other JPA implementations) has additional features not described in JPA (and not portable to other JPA implementations).</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS DIFFERENT BETWEEN JPA AND JDO?</strong></p></li></ul><p><br></p><p>JPA (Java Persistence API) and Java Data Objects (JDO) are two specifications for persisting java objects in databases. If JPA is focused only on relational databases, then JDO is a more general specification that describes the ORM for any possible databases and repositories.</p><p><br></p><p>The "developers" of the specifications also differ - JPA is developed as a JSR. At the beginning, JDO was also developed as a JSR, but now it is developed as an Apache JDO project.</p><p><br></p><p><br></p><ul><li><p><strong>IS IT POSSIBLE TO USE JPA WITH NOSQL BASES?</strong></p></li></ul><p><br></p><p>The JPA specification only talks about mapping java objects to relational database tables, but there are a number of implementations of this standard for NoSql databases: Kundera, DataNucleus, ObjectDB and a number of others. Naturally, in this case, not all the features of the specification specific to relational databases are completely transferred to NoSql databases.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS JPQL (JAVA PERSISTENCE QUERY LANGUAGE) AND HOW IS IT DIFFERENT FROM SQL?</strong></p></li></ul><p><br></p><p>JPQL (Java Persistence Query Language) is a query language, much like SQL, but instead of database table names and columns, it uses Entity class names and their attributes. Entity attribute data types are also used as query parameters, not database fields. Unlike SQL, JPQL has automatic polymorphism. Also, JPQL uses functions that are not in SQL: such as KEY (Map's key), VALUE (Map's value), TREAT (to cast the superclass to its child object, downcasting), ENTRY, etc.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT DOES POLYMORPHISM MEAN IN JPQL (JAVA PERSISTENCE QUERY LANGUAGE) AND HOW TO "TURN IT OFF"?</strong></p></li></ul><p><br></p><p>Unlike SQL, JPQL queries have automatic polymorphism, that is, each query to an Entity returns not only the objects of this Entity, but also the objects of all its descendant classes, regardless of the inheritance strategy (for example, a select * from Animal query will return not only Animal objects, but also objects of classes Cat and Dog, which are inherited from Animal). To exclude this behavior, the TYPE function in the where condition is used (for example, select * from Animal a where TYPE(a) IN (Animal, Cat) will no longer return objects of the Dog class).</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE CRITERIA API AND WHAT IS IT USED FOR?</strong></p></li></ul><p><br></p><p>The Criteria API is also a query language similar to JPQL (Java Persistence query language), but queries are based on methods and objects.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS ENTITY?</strong></p></li></ul><p><br></p><p>Entity is a lightweight persistent domain object. The main programming entity is an entity class, which can also use additional classes, which can be used as auxiliary classes or to save the state of the entity.</p><p><br></p><p><br></p><ul><li><p><strong>CAN AN NOT ENTITY CLASS BE EXTENDED FROM ENTITY CLASS?</strong></p></li></ul><p><br></p><p>Yes, it can.</p><p><br></p><p><br></p><ul><li><p><strong>CAN AN ENTITY CLASS BE EXTENDED FROM OTHER ENTITY CLASSES?</strong></p></li></ul><p><br></p><p>Yes, it can.</p><p><br></p><p><br></p><ul><li><p><strong>CAN ENTITY BE AN ABSTRACT CLASS?</strong></p></li></ul><p><br></p><p>Yes, it can be. Being abstract class it retains all the properties of the Entity, except that it can't be directly initialized.</p><p><br></p><p><br></p><ul><li><p><strong>CAN ENTITY CLASS INHERITE FROM NON-ENTITY CLASSES?</strong></p></li></ul><p><br></p><p>Yes, it can.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT JPA REQUIREMENTS FOR ENTITY CLASSES CAN YOU LIST (AT LEAST SIX REQUIREMENTS)?</strong></p></li></ul><p><br></p><ol><li><p>An Entity class must be annotated with the Entity annotation or described in a JPA configuration XML file.</p></li><li><p>The Entity class must contain a public or protected constructor with no arguments (it can also have constructors with arguments).</p></li><li><p>Entity class must be a top-level class.</p></li><li><p>Entity class cannot be enum or interface.</p></li><li><p>Entity class cannot be final class.</p></li><li><p>Entity class cannot contain final fields or methods if they are involved in mapping (persistent final methods or persistent final instance variables).</p></li><li><p>If the Entity object of the class will be passed by value as a separate object (detached object), for example, through a remote interface, it must also implement the Serializable interface.</p></li><li><p>Fields of an Entity class should be directly accessible only to methods of the Entity class itself and should not be directly accessible to other classes using this Entity. Such classes should only access methods (getter/setter methods or other business logic methods in the Entity class).</p></li><li><p>An Enity class must contain a primary key, that is, an attribute or group of attributes that uniquely identifies an entry for that Enity class in the database.</p></li></ol><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE ENTITY CLASS ATTRIBUTE IN JPA TERMINOLOGY?</strong></p></li></ul><p><br></p><p>JPA indicates that it can work both with class properties (property), or with fields (field), that is, class variables. Both types of elements of an Entity class are called attributes of the Entity class.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT DATA TYPES ARE ALLOWED IN ENTITY CLASS ATTRIBUTES (FIELDS OR PROPERTIES)?</strong></p></li></ul><p><br></p><p>Valid attribute types for Entity classes:</p><ul><li><p>primitive types and their Java wrappers,</p></li><li><p>String,</p></li><li><p>any serializable Java types (implementing the Serializable interface),</p></li><li><p>enums;</p></li><li><p>entity types;</p></li><li><p>embeddable classes</p></li><li><p>and collections of specific types</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT DATA TYPES CAN BE USED IN THE ATTRIBUTES CONTAINED IN THE PRIMARY KEY OF AN ENTITY CLASS (COMPOSITE OR SIMPLE) SO THAT THE PRIMARY KEY CAN BE USED FOR ANY DATABASE? AND IN THE CASE OF AUTOGENERATED PRIMARY KEYS (GENERATED PRIMARY KEYS)?</strong></p></li></ul><p><br></p><p>Valid attribute types included in the primary key:</p><ul><li><p>primitive types and their Java wrappers,</p></li><li><p>String,</p></li><li><p>BigDecimal and BigInteger</p></li><li><p>java.util.Date and java.sql.Date,</p></li></ul><p><br></p><p>In the case of an auto-generated primary key, only numeric types are allowed, In the case of using other data types in the primary key, it may only work for some databases, i.e. becomes not portable.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS AN EMBEDDABLE CLASS?</strong></p></li></ul><p><br></p><p>An embedded (Embeddable) class is a class that is not used by itself, only as part of one or more Entity classes. Entity classes can contain both single embedded classes and collections of such classes. Also, such classes can be used as keys or map values. At run time, each embeddable class belongs to only one Entity class object and cannot be used to pass data between Entity class objects (that is, such a class is not a common data structure for different objects). In general, such a class serves to define common attributes for several Entities, it can be considered that JPA simply embeds the attributes that it contains into the Entity instead of an object of this class.</p><p><br></p><p><br></p><ul><li><p><strong>CAN AN EMBEDDABLE CLASS CONTAIN ANOTHER EMBEDDABLE CLASS?</strong></p></li></ul><p><br></p><p>Yes, it can.</p><p><br></p><p><br></p><ul><li><p><strong>CAN AN EMBEDDABLE CLASS CONTAIN RELATIONSHIP WITH OTHER ENTITY OR COLLECTIONS OF ENTITY? IF THERE IS ANY LIMITATION ON SUCH RELATIONSHIP?</strong></p></li></ul><p><br></p><p>It can, but only if such a class is not used as a primary key or map key.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT REQUIREMENTS JPA SETS FOR EMBEDDABLE CLASSES?</strong></p></li></ul><p><br></p><p>1. Such classes must follow the same rules as Entity classes, except that they are not required to contain a primary key and be marked with the Entity annotation</p><p>2. The Embeddable class must be marked with the Embeddable annotation or described in the JPA configuration XML file.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT TYPES OF RELATIONS (RELATIONSHIP) BETWEEN ENTITY DO YOU KNOW (LIST EIGHT TYPES, OR SPECIFY FOUR TYPES OF RELATIONS, EACH OF WHICH CAN BE DIVIDED INTO TWO MORE TYPES)?</strong></p></li></ul><p><br></p><p>There are four types of links</p><ul><li><p>OneToOne (one-to-one relationship, that is, one Entity object can be associated with no more than one object of another Entity ),</p></li><li><p>OneToMany (one-to-many relationship, one Entity object can be related to a whole collection of other Entities),</p></li><li><p>ManyToOne (many-to-one relationship, it is an opposite to OneToMany),</p></li><li><p>ManyToMany (many-to-many relationship).</p></li></ul><p><br></p><p>Each of which can be further divided into two types:</p><ul><li><p>Bidirectional - each Entity has a link to an opposite Entity, that is, in the case of OneToOne A-B, Entity A has a link to Entity B, Entity B has a link to Entity A, Entity A is considered the owner of this link (this is important for cases of cascading data deletion, then deleting A will also delete B, but not vice versa).</p></li><li><p>Undirectional - the link to the relationship is established only on one side, that is, in the case of OneToOne A-B, only Entity A will have a link to Entity B, Entity B will not have a link to A.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT IS MAPPED SUPERCLASS?</strong></p></li></ul><p><br></p><p>Mapped Superclass is a class from which Entities inherit, it may contain JPA annotations, but such a class itself is not an Entity, it does not have to fulfill all the requirements set for Entity (for example, it may not contain a primary key). Such a class cannot be used in EntityManager or Query operations. Such a class must be annotated with the MappedSuperclass annotation or described accordingly in the xml file.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT TWO TYPES OF FETCH STRATEGIES IN JPA DO YOU KNOW?</strong></p></li></ul><p><br></p><p>JPA describes two types of fetch strategy:</p><ul><li><p>LAZY - field data will be loaded only during the first access to this field,</p></li><li><p>EAGER - field data will be loaded immediately.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHICH THREE TYPES OF INHERITANCE MAPPING STRATEGIES ARE DESCRIBED IN JPA?</strong></p></li></ul><p><br></p><p>JPA describes three Inheritance Mapping Strategies, that is, how JPA will work with Entity derived classes:</p><ul><li><p>one table for the entire inheritance hierarchy (a single table per class hierarchy) - all enities, with all child types, are recorded in one table, a special column "discriminator column" is defined to identify the entity type. For example, if there is an entity Animals with descendant classes of Cats and Dogs, with this strategy all entities are written to the Animals table, but at the same time they have an additional animalType column in which the value "cat" or "dog" is written accordingly. The downside is that in general table, all fields unique for each of the child classes will be empty for all other classes. For example, in the animals table, there will also be a tree climbing speed from cats and whether a dog can bring slippers from dogs, which will always have null for dog and cat, respectively.</p></li><li><p>joining strategy (joined subclass strategy) - in this strategy, each entity class saves data to its table, but only unique columns (not inherited from ancestor classes) and the primary key, and all inherited columns are written to the tables of the ancestor class, an additional relationship is established (relationships) between these tables, for example, in the case of the Animals classes hierarchy (see example above), there will be three tables: animals, cats, dogs, and in cats only the key and climbing speed will be recorded, in dogs - the key and whether the dog can bring a stick, and in animals, all other data of cats and dogs with a link to the corresponding tables. The downside here is the performance loss from joining tables (join) for any operations.</p></li><li><p>one table for each class (table per concrete class strategy) - everything is simple here, each separate child class has its own table, i.e. for cats and dogs, all data will simply be written to the cats and dogs tables as if they had no common superclass at all. The downside is poor support for polymorphism (polymorphic relationships) and the fact that to select all classes of the hierarchy, a large number of separate sql queries or the use of a UNION query will be required.</p></li></ul><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
79 - ===== ORM & JPA Interview Preparation =====/004 Part 4 JPA Interview - Questions and Answers.html
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Part 4 JPA Interview - Questions and Answers</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
}
|
| 14 |
+
body {
|
| 15 |
+
font-family: var(--font-stack-text);
|
| 16 |
+
font-weight: 400;
|
| 17 |
+
line-height: 1.4;
|
| 18 |
+
font-size: 1.6rem;
|
| 19 |
+
color: #2d2f31;
|
| 20 |
+
}
|
| 21 |
+
.container {
|
| 22 |
+
position: relative;
|
| 23 |
+
height: 100%;
|
| 24 |
+
overflow-y: auto;
|
| 25 |
+
}
|
| 26 |
+
.content {
|
| 27 |
+
padding: 3.2rem 4.8rem;
|
| 28 |
+
word-break: break-word;
|
| 29 |
+
max-width: 69.6rem;
|
| 30 |
+
margin: 0 auto;
|
| 31 |
+
}
|
| 32 |
+
.heading {
|
| 33 |
+
margin-bottom: 24px;
|
| 34 |
+
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif,
|
| 35 |
+
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
line-height: 1.2;
|
| 38 |
+
letter-spacing: 0;
|
| 39 |
+
font-size: 32px;
|
| 40 |
+
max-width: 36em;
|
| 41 |
+
}
|
| 42 |
+
.article-asset-container {
|
| 43 |
+
padding: 2.4rem;
|
| 44 |
+
}
|
| 45 |
+
.article-asset-container p {
|
| 46 |
+
font-size: 19px;
|
| 47 |
+
}
|
| 48 |
+
code {
|
| 49 |
+
background-color: #fff;
|
| 50 |
+
border: 1px solid #d1d7dc;
|
| 51 |
+
color: #b4690e;
|
| 52 |
+
font-size: 80%;
|
| 53 |
+
padding: 0.2rem 0.4rem;
|
| 54 |
+
font-family: sfmono-regular, Consolas, liberation mono, Menlo, Courier, monospace;
|
| 55 |
+
}
|
| 56 |
+
p {
|
| 57 |
+
font-weight: 400;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
</head>
|
| 61 |
+
<body>
|
| 62 |
+
<div class="container">
|
| 63 |
+
<div class="content">
|
| 64 |
+
<div class="heading">Part 4 JPA Interview - Questions and Answers</div>
|
| 65 |
+
<div class="article-asset-container"><ul><li><p><strong>WHAT IS ENTITYMANAGER AND WHAT ITS MAIN FUNCTIONS CAN YOU NAME?</strong></p></li></ul><p><br></p><p>EntityManager is an interface that describes the API for all the basic operations on Enitity, getting data and other JPA entities. Essentially, EntityManager is the main API for working with JPA. Basic Operations:</p><ul><li><p>For operations on Entity: persist (adding an Entity under JPA control), merge, remove, refresh, detach, lock,</p></li><li><p>Getting data: find (search and get Entity), createQuery, createNamedQuery, createNativeQuery, contains, createNamedStoredProcedureQuery, createStoredProcedureQuery</p></li><li><p>Getting other JPA entities: getTransaction, getEntityManagerFactory, getCriteriaBuilder, getMetamodel, getDelegate</p></li><li><p>Working with EntityGraph: createEntityGraph, getEntityGraph</p></li><li><p>General operations on EntityManager or all Entities: close, isOpen, getProperties, setProperty, clear.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHICH FOUR ENTITY INSTANCE’S LIFE CYCLE STATES CAN YOU LIST?</strong></p></li></ul><p><br></p><p>An Entity object has four lifecycle statuses: new, managed, detached, or removed. Their description</p><ul><li><p>new - the object has been created, but it does not yet have generated primary keys and has not yet been stored in the database,</p></li><li><p>managed - object created, managed by JPA, has generated primary keys</p></li><li><p>detached - the object has been created but is not managed (or no longer managed) by JPA,</p></li><li><p>removed - the object has been created, managed by JPA, but will be deleted after the transaction is committed.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>HOW DOES THE MERGE OPERATION AFFECT THE ENTITY OBJECTS OF EACH OF THE FOUR STATUS?</strong></p></li></ul><p><br></p><p>1. If the status is detached, then either the data will be copied to an existing managed entity with the same primary key, or a new managed entity will be created into which the data will be copied,</p><p>2. If the status is Entity new, then a new managed entity will be created, into which the data of the past object will be copied,</p><p>3. If the status is managed, the operation is ignored, however, the merge operation will work on cascade dependent Entities if their status is not managed,</p><p>4. If the status is removed, an exception will be thrown immediately or at the commit stage of the transaction.</p><p><br></p><p><br></p><ul><li><p><strong>HOW DOES THE REMOVE OPERATION AFFECT THE ENTITY OBJECTS IN CASE OF EACH OF THE FOUR STATUSES MENTIONED IN THE PREVIOUS QUESTION?</strong></p></li></ul><p>1. If the Entity status is new, the operation is ignored, however, dependent Entities can change the status to removed if they have cascading change annotations and were in the managed status,</p><p>2. If the status is managed, then the status changes to removed and the object record in the database will be deleted when the transaction is committed (there will also be remove operations for all cascade dependent objects),</p><p>3. If the status is removed, then the operation is ignored,</p><p>4. If the status is detached, an exception will be thrown immediately or at the commit stage of the transaction.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW DOES THE PERSIST OPERATION AFFECT ENTITY OBJECTS IN CASE OF EACH OF THE FOUR STATUSES?</strong></p></li></ul><p><br></p><p>1. If the Entity status is new, then it changes to managed and the object will be saved to the database when the transaction is committed or as a result of flush operations,</p><p>2. If the status is already managed, the operation is ignored, however, dependent Entities can change the status to managed if they have cascading change annotations,</p><p>3. If the status is removed, then it changes to managed,</p><p>4. If the status is detached, an exception will be thrown immediately or at the commit stage of the transaction.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW DOES A REFRESH OPERATION AFFECT ENTITY OBJECTS IN CASE OF EACH OF THE FOUR STATUS?</strong></p></li></ul><p><br></p><p>1. If the status of the Entity is managed, then as a result of the operation all changes from the database of this Entity will be restored, as well as a refresh of all cascade dependent objects,</p><p>2. If the status is new, removed or detached, an exception will be thrown.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>HOW DOES THE DETACH OPERATION AFFECT THE ENTITY OBJECTS IN CASE OF EACH OF THE FOUR STATUS?</strong></p></li></ul><p><br></p><p>1. If the status is Entity managed or removed, then as a result of the operation, the status of the Entity (and all cascade-dependent objects) will become detached.</p><p>2. If the status is new or detached, then the operation is ignored.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE ACCESS ANNOTATION FOR?</strong></p></li></ul><p><br></p><p>It defines the access type for an entity class, superclass, embeddable, or individual attributes, i.e. how JPA will access entity attributes, as class fields (FIELD) or as class properties (PROPERTY) that have getters and seters.</p><p><br></p><p><br></p><ul><li><p><strong>WHY DO YOU NEED A BASIC ANNOTATION?</strong></p></li></ul><p><br></p><p>Basic - indicates the simplest type of data mapping to a database table column. Also in the annotation parameters, you can specify the fetch field access strategy and whether this field is required or not.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT ANOTATIONS CAN OVERRIDE ENTITY RELATIONSHIP OR ATTRIBUTES INHERITED FROM A SUPERCLASS OR SET IN AN EMBEDDABLE CLASS WHEN USING THIS EMBEDDABLE CLASS IN ONE OF THE ENTITY CLASSES AND NOT OVERRIDING IN THE OTHERS?</strong></p></li></ul><p><br></p><p>There are four annotations for such an overlay:</p><ul><li><p>AttributeOverride to override fields, properties and primary keys,</p></li><li><p>AttributeOverrides can similarly override fields, properties, and primary keys with multiple values,</p></li><li><p>AssociationOverride to override entity relationships,</p></li><li><p>AssociationOverrides to override multiple relationships.</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT ANOTATIONS SERVE TO SET THE CLASS OF CONVERTING THE BASIC ENTITY ATTRIBUTE TO ANOTHER TYPE WHEN SAVING / RETRIEVE DATA FROM THE BASE (FOR EXAMPLE, WORKING WITH THE ENTITY ATTRIBUTE OF THE BOOLEAN TYPE, BUT SAVE IT AS A NUMBER IN THE DATABASE)?</strong></p></li></ul><p><br></p><p>Convert and Converts - allow you to specify a class for converting the Basic attribute of an Entity to another type (Converts - allow you to specify several conversion classes). Classes to be converted must implement the AttributeConverter interface and may (but not mandatory) be annotated with the Converter annotation.</p><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WITH WHAT ANNOTATION IT IS POSSIBLE TO CONTROL JPA CACHE FOR THIS ENTITY?</strong></p></li></ul><p><br></p><p>Cacheable - allows you to enable or disable the use of the second-level cache for this Entity (if the JPA provider supports caching and the cache settings (second-level cache) are ENABLE_SELECTIVE or DISABLE_SELECTIVE). Pay attention to the property is inherited and if it is not blocked in the child types, then the caching will change for them too.</p><p><br></p><p><br></p><ul><li><p><strong>WITH WHAT ANNOTATION IT IS POSSIBLE TO SPECIFY A CLASS, WHICH METHODS SHOULD BE EXECUTED WHEN WE PERFORM CERTAIN JPA OPERATIONS OVER THE DATA ENITITY OR MAPPED SUPERCLASS (SUCH AS DELETE, MODIFY DATA, ETC.)?</strong></p></li></ul><p><br></p><p>The EntityListeners annotation allows you to define a Listener class that will contain event handling methods (callback methods) defined by an Entity or a Mapped Superclass.</p><p><br></p><p><br></p><ul><li><p><strong>WHY DO WE NEED CALLBACK METHODS IN JPA? WHERE CALLBACK METHOD ANNOTATIONS ARE APPLIED? LIST SEVEN CALLBACK METHODS (OR CALLBACK METHOD ANNOTATIONS).</strong></p></li></ul><p><br></p><p>Callback methods are used to be called on certain Entity events (for example, in case we need to add handling for deleting an Entity by JPA methods), can be added to an entity class, to a mapped superclass, or to a callback listener class defined by the EntityListeners annotation. There are seven callback methods (and annotations with the same names):</p><ul><li><p>PrePersist</p></li><li><p>PostPersist</p></li><li><p>PreRemove</p></li><li><p>PostRemove</p></li><li><p>PreUpdate</p></li><li><p>PostUpdate</p></li><li><p>PostLoad</p></li></ul><p><br></p><p><br></p><p><br></p><ul><li><p><strong>WHAT AN ANNOTATION CAN EXCLUDE FIELDS AND ENTITY PROPERTIES FROM MAPPING?</strong></p></li></ul><p><br></p><p>This is what the Transient annotation is for.</p><p><br></p><p><br></p><ul><li><p><strong>WHICH ANNOTATIONS ARE USED TO SET THE ORDER OF ENTITY COLLECTION ITEMS?</strong></p></li></ul><p><br></p><p>The annotation OrderBy and OrderColumn is used for this.</p><p><br></p><p><br></p><ul><li><p><strong>WHICH SIX LOCK TYPES ARE DESCRIBED IN THE JPA SPECIFICATION?</strong></p></li></ul><p><br></p><p>There is LockModeType enum. JPA has six types of locks. I list them in order of increasing reliability (from the most unreliable and fastest, to the most reliable and slow):</p><ul><li><p>NONE - no blocking</p></li><li><p>OPTIMISTIC (or READ synonym left over from JPA 1) - optimistic locking</p></li><li><p>OPTIMISTIC_FORCE_INCREMENT (or a synonym for WRITE, left over from JPA 1) - optimistic locking with forced versioning field increment</p></li><li><p>PESSIMISTIC_READ - pessimistic read lock</p></li><li><p>PESSIMISTIC_WRITE - pessimistic write (and read) lock</p></li><li><p>PESSIMISTIC_FORCE_INCREMENT - pessimistic write (and read) lock with forced version field increment.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT TWO TYPES OF CACHES DO YOU KNOW IN JPA AND WHAT DO YOU NEED THEM FOR?</strong></p></li></ul><p><br></p><p>JPA talks about two kinds of caches (cache):</p><ul><li><p>first-level cache (first-level cache) - caches the data of one transaction,</p></li><li><p>second-level cache (second-level cache) - caches data for longer than one transaction. The JPA provider may, but is not required to, implement second-level cache handling. This type of cache saves access time and improves performance, but the downside is the possibility of getting stale data.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>WHAT ARE THE OPTIONS FOR SETTING THE SECOND-LEVEL CACHE IN JPA OR WHAT VALUES CAN THE SHARED-CACHE-MODE ELEMENT FROM PERSISTENCE.XML TAKE?</strong></p></li></ul><p><br></p><p>JPA talks about five shared-cache-mode values from persistence.xml which define how the second-level cache will be used:</p><ul><li><p>ALL - all Entities can be cached in the second level cache</p></li><li><p>NONE - caching is disabled for all Entities</p></li><li><p>ENABLE_SELECTIVE - caching works only for those Entities that have the Cacheable(true) annotation or its xml equivalent set, caching is disabled for all others</p></li><li><p>DISABLE_SELECTIVE - caching works for all Entities, except for those with the Cacheable(false) annotation or its xml equivalent set</p></li><li><p>UNSPECIFIED - caching is not defined, each JPA provider uses its own default for caching</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>HOW IS IT POSSIBLE TO CHANGE THE FETCH SETTINGS OF ANY ENTITY STRATEGY FOR INDIVIDUAL QUERY OR FIND METHODS, IF ENITY HAS A FETCHTYPE = LAZY ATTRIBUTE, BUT FOR A SPECIFIC REQUEST IT IS REQUIRED TO MAKE EAGER OR vice versa?</strong></p></li></ul><p><br></p><p>There is an EntityGraph API for this, it is used like this: using the NamedEntityGraph annotation for Entity, named EntityGraph objects are created that contain a list of attributes whose fetchType needs to be changed to EAGER, and then this name is indicated in the hits of queries or the find method. As a result, the fetchType of the Entity attributes changes, but only for this request. There are two standard properties for specifying an EntityGraph on a hit:</p><ul><li><p>javax.persistence.fetchgraph - all attributes listed in EntityGraph change fetchType to EAGER, all others to LAZY</p></li><li><p>javax.persistence.loadgraph - all attributes listed in EntityGraph change fetchType to EAGER, all others retain their fetchType (that is, if an attribute not specified in EntityGraph had fetchType EAGER, then it will remain EAGER) Using NamedSubgraph, you can also change fetchType of nested Entity objects.</p></li></ul><p><br></p><p><br></p><ul><li><p><strong>HOW CAN I GET JPA METADATA (INFORMATION ABOUT ENTITY TYPES, EMBEDDABLE AND MANAGED CLASSES, ETC.)?</strong></p></li></ul><p><br></p><p>JPA uses the Metamodel interface to get this information. An object of this interface can be obtained using the getMetamodel method of the EntityManagerFactory or EntityManager.</p><p><br></p><p><br></p><ul><li><p><strong>HOW IS IT POSSIBLE TO WORK WITH THE SECOND LEVEL CACHE IN THE CODE (DELETE ALL OR CERTAIN ENTITY FROM THE CACHE, FIND OUT WHETHER THIS ENTITY IS CACHED, ETC.)?</strong></p></li></ul><p><br></p><p>To work with the second level cache, JPA describes the Cache interface, which contains a large number of methods for managing the second level cache, if it is supported by the JPA provider, of course. An object of this interface can be obtained using the getCache method of the EntityManagerFactory.</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS THE DIFFERENCE IN THE ENTITY REQUIREMENTS IN HIBERNATE FROM THE ENTITY REQUIREMENTS IN THE JPA SPECIFICATION?</strong></p></li></ul><p><br></p><p>1. A constructor without arguments does not have to be public or protected, it is recommended that it be at least package visible, but this is only a recommendation, if Java security settings allow access to private fields, then it can be private,</p><p>2. JPA categorically requires not to use final classes, Hibernate only recommends not to use such classes so that it can create proxies for lazy loading, however, it allows you to either turn off the Proxy(lazy=false) proxy, or use an interface containing all the mapping methods for of this class (annotation Proxy(proxyClass=Interface.class) )</p><p><br></p><p><br></p><ul><li><p><strong>WHAT IS A UNIQUE INHERITANCE STRATEGY IN HIBERNATE BUT NOT IN THE JPA SPEC?</strong></p></li></ul><p><br></p><p>Unlike JPA, Hibernate has a unique inheritance strategy called implicit polymorphism.</p><p><br></p></div>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</body>
|
| 69 |
+
</html>
|
80 - ===== EXAM TASK JPA & Hibernate =====/001 ===== EXAM TASK JPA & Hibernate =====_en.srt
ADDED
|
@@ -0,0 +1,964 @@
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:06,000
|
| 3 |
+
Hello, team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:14,000
|
| 7 |
+
We have learned a lot about Chip and Kimberly already by this moment, and now it is time to check your
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:14,000 --> 00:00:16,000
|
| 11 |
+
skills in real ecommerce project.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:17,000 --> 00:00:24,000
|
| 15 |
+
I prepared special tasks for you that will help you to check and sharpen your skills.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:24,000 --> 00:00:29,000
|
| 19 |
+
You can find the reference to the tasks description in attachments to the video.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:30,000 --> 00:00:36,000
|
| 23 |
+
So the first thing that I recommend you to do is to download this example from the GitHub.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:37,000 --> 00:00:43,000
|
| 27 |
+
This is the online shop application that we did together with my students from scratch in my course
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:43,000 --> 00:00:45,000
|
| 31 |
+
Java from zero to first job.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:46,000 --> 00:00:54,000
|
| 35 |
+
It is implemented with pure DBC and we are going to improve it in order to use GP and hibernate in step.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:55,000 --> 00:01:01,000
|
| 39 |
+
Just in case I left here as a reference to the database expert, you know that you could configure your
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:01:01,000 --> 00:01:08,000
|
| 43 |
+
database locally to deploy the application and also you can find the reference to the place in the code
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:01:09,000 --> 00:01:12,000
|
| 47 |
+
where we hardcoded configuration for the database.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:12,000 --> 00:01:17,000
|
| 51 |
+
Feel free to update it to in order to make your application work smoothly.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:17,000 --> 00:01:24,000
|
| 55 |
+
And when you deploy the application locally and you make sure that everything works and you can run
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:24,000 --> 00:01:32,000
|
| 59 |
+
the application, you have just one simple task to do make the application works with GP and hibernate
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:32,000 --> 00:01:33,000
|
| 63 |
+
instead of DBC.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:34,000 --> 00:01:41,000
|
| 67 |
+
As you can see, we have modular structure in our project, so to deal with this home task you need
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:41,000 --> 00:01:46,000
|
| 71 |
+
to adjust only persistence module without impacting the modules.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:47,000 --> 00:01:50,000
|
| 75 |
+
Take your time sync about the solution.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:50,000 --> 00:01:51,000
|
| 79 |
+
Create your own solution.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:51,000 --> 00:01:59,000
|
| 83 |
+
First, you can put on pause this video and once you are done with your solution, let's compare your
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:59,000 --> 00:02:01,000
|
| 87 |
+
solution with mine.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:02:01,000 --> 00:02:07,000
|
| 91 |
+
I'm going to walk you through my solution and give comments as we'll go over it.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:02:07,000 --> 00:02:09,000
|
| 95 |
+
Let's start with you.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:02:10,000 --> 00:02:18,000
|
| 99 |
+
First of all, we need to add a GPA configuration file and you can find it here in the SLC main resources
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:18,000 --> 00:02:19,000
|
| 103 |
+
folder.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:19,000 --> 00:02:26,000
|
| 107 |
+
I didn't change a lot of configurations here compared to what we learned during the course.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:26,000 --> 00:02:33,000
|
| 111 |
+
I changed here schema and also I added C three pure connection properties here.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:34,000 --> 00:02:35,000
|
| 115 |
+
Here they are.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:35,000 --> 00:02:40,000
|
| 119 |
+
So we already had connection to implement in our solution.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:40,000 --> 00:02:48,000
|
| 123 |
+
And in case we introduce GP and hibernate, we have to be sure that our solution will not lose in performance.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:48,000 --> 00:02:55,000
|
| 127 |
+
If you don't know what the connection is and why do I recommend you to watch the lesson about an action
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:55,000 --> 00:02:58,000
|
| 131 |
+
pool in my course java from zero to first job?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:59,000 --> 00:03:06,000
|
| 135 |
+
In that lesson we have learned different connection libraries and I explained all the benefits of having
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:03:07,000 --> 00:03:09,000
|
| 139 |
+
connection with examples.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:03:09,000 --> 00:03:13,000
|
| 143 |
+
Let me elaborate on C sweeper properties that I put here.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:14,000 --> 00:03:24,000
|
| 147 |
+
Mean size minimum number of GDC connections in the pool hibernate default is one max source maximum
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:24,000 --> 00:03:27,000
|
| 151 |
+
number of GB C connections in the pool.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:27,000 --> 00:03:37,000
|
| 155 |
+
Hebrew default is 100 timeout when an idle connection is removed from the pool in seconds hibernate
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:37,000 --> 00:03:42,000
|
| 159 |
+
default is zero never x bar max statements.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:42,000 --> 00:03:51,000
|
| 163 |
+
Number of prepared statements will be cached increased performance hibernate default is zero caching
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:51,000 --> 00:03:59,000
|
| 167 |
+
is disabled idle test zero idle time and seconds before connection is automatically validated.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:04:00,000 --> 00:04:02,000
|
| 171 |
+
Hibernate default is zero.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:04:03,000 --> 00:04:07,000
|
| 175 |
+
Obviously we need to add new and required dependencies.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:04:07,000 --> 00:04:14,000
|
| 179 |
+
Our Jakarta persistence API hibernate itself and dependency for the Hibernate Connection pool.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:04:15,000 --> 00:04:23,000
|
| 183 |
+
So I made the required updates in the home XML file to what do we have to do next?
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:04:24,000 --> 00:04:27,000
|
| 187 |
+
Now we need to configure our models.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:27,000 --> 00:04:34,000
|
| 191 |
+
Let's mark them with the entity annotations and make sure that we gave name to the columns.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:34,000 --> 00:04:37,000
|
| 195 |
+
According to the SQL Naming Convention.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:37,000 --> 00:04:45,000
|
| 199 |
+
During the implementation of this exam task and this online shop, we have learned a lot with students,
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:45,000 --> 00:04:49,000
|
| 203 |
+
including the NBC Dolly Parton duo.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:50,000 --> 00:04:57,000
|
| 207 |
+
So in case you missed lessons from my course go from zero to first job, some terminology may sound
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:57,000 --> 00:05:00,000
|
| 211 |
+
strange and a little bit confusing to you.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:05:01,000 --> 00:05:07,000
|
| 215 |
+
Feel free to watch the lessons about web application architecture in my course Java from zero to first
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:05:07,000 --> 00:05:07,000
|
| 219 |
+
job.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:05:08,000 --> 00:05:10,000
|
| 223 |
+
At the meantime, we proceed.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:05:11,000 --> 00:05:16,000
|
| 227 |
+
All data models in our application are stored in the digital package.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:05:16,000 --> 00:05:18,000
|
| 231 |
+
Let's review our entities here.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:19,000 --> 00:05:23,000
|
| 235 |
+
I actually didn't change anything in the code itself.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:24,000 --> 00:05:27,000
|
| 239 |
+
I just put annotations on top of the classes and fields.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:28,000 --> 00:05:31,000
|
| 243 |
+
For example, in category detail.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:31,000 --> 00:05:33,000
|
| 247 |
+
There is nothing special.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:33,000 --> 00:05:41,000
|
| 251 |
+
Just entity annotation, ID generated value and column annotations in the product detail.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:41,000 --> 00:05:45,000
|
| 255 |
+
You can also find similar annotations and configuration.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:45,000 --> 00:05:53,000
|
| 259 |
+
In addition to those you can see many one relationship with category detail because many products may
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:53,000 --> 00:05:54,000
|
| 263 |
+
belong to one category.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:55,000 --> 00:05:58,000
|
| 267 |
+
That's why we have managed to one here.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:59,000 --> 00:06:01,000
|
| 271 |
+
Is a purchase detail.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:06:01,000 --> 00:06:10,000
|
| 275 |
+
You can find many to one relationship with user entity because many purchases can be done by one user.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:06:10,000 --> 00:06:18,000
|
| 279 |
+
Many, many relationships between purchase and products, because each purchase can contain many products
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:06:19,000 --> 00:06:22,000
|
| 283 |
+
and each product can be part of many purchases.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:06:23,000 --> 00:06:29,000
|
| 287 |
+
For many, too many relationships, we need to have this third table and I configured here the search
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:06:29,000 --> 00:06:32,000
|
| 291 |
+
table and mapping columns.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:32,000 --> 00:06:41,000
|
| 295 |
+
Also, we have many to one relationship with purchase status because many purchases can share the same
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:41,000 --> 00:06:41,000
|
| 299 |
+
status.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:42,000 --> 00:06:44,000
|
| 303 |
+
Another important thing here.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:44,000 --> 00:06:47,000
|
| 307 |
+
You can see how I can figure it.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:47,000 --> 00:06:55,000
|
| 311 |
+
Timestamp field to be populated automatically when the record is inserted into the database is searchable.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:55,000 --> 00:07:02,000
|
| 315 |
+
Property tells us what a field is going to be part of auto generated insert statement we set this one
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:07:02,000 --> 00:07:10,000
|
| 319 |
+
to false updatable attribute tells us whether the field is going to be a part of an update statement.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:07:10,000 --> 00:07:18,000
|
| 323 |
+
And again, we don't need this because we would like to create timestamp value only once during the
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:07:18,000 --> 00:07:22,000
|
| 327 |
+
record insertion on the side of the database.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:07:23,000 --> 00:07:26,000
|
| 331 |
+
The next attribute here is column definition.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:27,000 --> 00:07:33,000
|
| 335 |
+
It is the SQL fragment that they used when generating DDL for the column to run more.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:33,000 --> 00:07:42,000
|
| 339 |
+
What the deal is, please refer to my lessons about SQL in the SQL course or in the course java from
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:42,000 --> 00:07:43,000
|
| 343 |
+
zero to first job.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:44,000 --> 00:07:51,000
|
| 347 |
+
Also, as we discussed in the GPS section of the course, we use temporal annotation to map timestamp
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:51,000 --> 00:07:59,000
|
| 351 |
+
in the database with the date data type is program purchase status and it doesn't contain any special
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:59,000 --> 00:08:01,000
|
| 355 |
+
or complicated connections.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:08:02,000 --> 00:08:03,000
|
| 359 |
+
So let's move on.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:08:04,000 --> 00:08:08,000
|
| 363 |
+
Raw data is also relatively simple entity.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:08:08,000 --> 00:08:17,000
|
| 367 |
+
User entity has many to one relationship with role and because many users can share the same role.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:08:17,000 --> 00:08:25,000
|
| 371 |
+
And also there is a relationship with the wrapper user because many users can be referred to the system
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:08:25,000 --> 00:08:27,000
|
| 375 |
+
by the same partner.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:27,000 --> 00:08:33,000
|
| 379 |
+
Together with my students in my course in Java, from zero to first job, we developed this application
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:33,000 --> 00:08:41,000
|
| 383 |
+
together and I understand that it can be challenging for you to grasp the logic very quickly.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:41,000 --> 00:08:45,000
|
| 387 |
+
So take your time exploring the existing business logic.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:46,000 --> 00:08:51,000
|
| 391 |
+
Because it was my students, we implemented support of affiliate marketing.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:51,000 --> 00:09:00,000
|
| 395 |
+
Basically each user has partner code and each user can benefit from promoting our online shop by getting
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:09:00,000 --> 00:09:02,000
|
| 399 |
+
percentage from our sales.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:09:03,000 --> 00:09:06,000
|
| 403 |
+
We are done with a review of our entities.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:09:06,000 --> 00:09:09,000
|
| 407 |
+
That's all updates that we did in our entities.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:09:09,000 --> 00:09:10,000
|
| 411 |
+
Let's move on.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:09:11,000 --> 00:09:18,000
|
| 415 |
+
The next thing that we need to do is to create DAO implementations that would respect the persistence
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:09:18,000 --> 00:09:22,000
|
| 419 |
+
API and would use it during the interaction with the database.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:09:22,000 --> 00:09:29,000
|
| 423 |
+
And here's the benefit of our architecture and design that we have learned with my students in the course
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:29,000 --> 00:09:31,000
|
| 427 |
+
Java from zero to job.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:31,000 --> 00:09:39,000
|
| 431 |
+
The huge advantage of this architecture is that I don't need to change existing interfaces or OSM modules,
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:39,000 --> 00:09:44,000
|
| 435 |
+
I just have to implement the interfaces and that's it.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:44,000 --> 00:09:46,000
|
| 439 |
+
The rest code will work as it worked.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:47,000 --> 00:09:55,000
|
| 443 |
+
I just need to meet the contract of existing interfaces and I'm done with the integration of the hibernate
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:55,000 --> 00:09:56,000
|
| 447 |
+
into our application.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:57,000 --> 00:10:04,000
|
| 451 |
+
In my now input packages you can see that we have a lot of my SQL GDC implementations.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:10:05,000 --> 00:10:13,000
|
| 455 |
+
Basically, we just need to introduce the new implementations of the interface and to inject new implementations
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:10:13,000 --> 00:10:17,000
|
| 459 |
+
in the places where we use the objects.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:10:17,000 --> 00:10:19,000
|
| 463 |
+
Let's go step by step.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:10:20,000 --> 00:10:24,000
|
| 467 |
+
I have implemented different GP implementations here.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:24,000 --> 00:10:26,000
|
| 471 |
+
Let me walk you through them.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:27,000 --> 00:10:30,000
|
| 475 |
+
The first one in our list is GP category down.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:31,000 --> 00:10:34,000
|
| 479 |
+
To be honest, there is nothing super interesting here.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:35,000 --> 00:10:43,000
|
| 483 |
+
Everything we have learned during the lessons simple font operation by the infection of all categories.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:44,000 --> 00:10:52,000
|
| 487 |
+
A similar thing with the GP roll down not so much masses to implement and all of them are pretty standard
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:52,000 --> 00:10:53,000
|
| 491 |
+
ones.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:53,000 --> 00:11:01,000
|
| 495 |
+
The next one is product down and in case you did this home task by yourself, I bet you spent a lot
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:11:01,000 --> 00:11:09,000
|
| 499 |
+
of time on this down and on the purchase down to because usually when we reviews this task with my offline
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:11:09,000 --> 00:11:17,000
|
| 503 |
+
students, these two down implementations are the most complex one, especially the piece where we perform
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:11:17,000 --> 00:11:18,000
|
| 507 |
+
search.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:11:19,000 --> 00:11:27,000
|
| 511 |
+
You're in the course review different ways of how we can create GP queries and it is only up to you
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:11:27,000 --> 00:11:30,000
|
| 515 |
+
to decide which option you would like to choose.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:11:31,000 --> 00:11:37,000
|
| 519 |
+
You can solve this task with the GPC criteria API or native query.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:11:38,000 --> 00:11:45,000
|
| 523 |
+
Actually during the implementation I tried different approaches, but still I decided to leave the example
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:45,000 --> 00:11:46,000
|
| 527 |
+
with native code.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:47,000 --> 00:11:56,000
|
| 531 |
+
My opinion it is more readable, simple and clear because your code has to be clean and clear and be
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:56,000 --> 00:11:57,000
|
| 535 |
+
easy to support.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:58,000 --> 00:12:05,000
|
| 539 |
+
If you notice the specifics of the implementation, we need also to implement the pagination support
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:12:05,000 --> 00:12:16,000
|
| 543 |
+
and again you can use GP API here, namely query type has the following methods set first result sets
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:12:16,000 --> 00:12:26,000
|
| 547 |
+
the offset position in the result set to start pagination set max results sets the maximum number of
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:12:26,000 --> 00:12:33,000
|
| 551 |
+
entities that should be included in the page so you can use this mass instead of limit.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:12:33,000 --> 00:12:41,000
|
| 555 |
+
Operator Whatever you like the most, all options are fine, but still in the case of complex queries.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:12:41,000 --> 00:12:45,000
|
| 559 |
+
Personally, I prefer to use native queries.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:12:45,000 --> 00:12:53,000
|
| 563 |
+
For example, you can see that I use upper function here to make sure this search will work case independently
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:12:53,000 --> 00:12:55,000
|
| 567 |
+
and again like a set.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:55,000 --> 00:12:58,000
|
| 571 |
+
There are different ways of how to solve this.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:59,000 --> 00:13:04,000
|
| 575 |
+
You can purchase down during the implementation of get not completed purchases.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:13:04,000 --> 00:13:11,000
|
| 579 |
+
Probably you faced with the exception that tells you that the products can be fetched because there
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:13:11,000 --> 00:13:12,000
|
| 583 |
+
is no session.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:13:12,000 --> 00:13:18,000
|
| 587 |
+
And indeed, in case you would investigate the stack trace of the potential error.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:13:18,000 --> 00:13:23,000
|
| 591 |
+
You would find that sometimes in the application we get a massive.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:13:24,000 --> 00:13:29,000
|
| 595 |
+
For example, get product details mass outside of the transaction.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:13:29,000 --> 00:13:34,000
|
| 599 |
+
And apparently there is no session to establish the connection to the database.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:34,000 --> 00:13:38,000
|
| 603 |
+
There are different ways of how to resolve this.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:38,000 --> 00:13:44,000
|
| 607 |
+
First of all, you can use eagle fetch, but this will bring us to the end plus one issue.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:45,000 --> 00:13:49,000
|
| 611 |
+
If you don't remember what it is place, what is the lesson?
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:49,000 --> 00:13:54,000
|
| 615 |
+
Both and plus one issue where we use a problem and potential solutions.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:55,000 --> 00:13:57,000
|
| 619 |
+
You may want to use entity graphs.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:58,000 --> 00:14:03,000
|
| 623 |
+
Also, you can add in persistence axonal properties that is called hibernate.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:14:03,000 --> 00:14:05,000
|
| 627 |
+
Enable lazy load.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:14:05,000 --> 00:14:06,000
|
| 631 |
+
No chance.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:14:06,000 --> 00:14:09,000
|
| 635 |
+
But still, I wouldn't recommend to do so.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:14:09,000 --> 00:14:17,000
|
| 639 |
+
Setting this property to true means that each access to an associated lazy loaded entity will be rubbed
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:14:17,000 --> 00:14:21,000
|
| 643 |
+
in use session running in the transaction.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:22,000 --> 00:14:27,000
|
| 647 |
+
This is also not recommended because you would end up with endless one issue.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:14:27,000 --> 00:14:36,000
|
| 651 |
+
Again, one of the recommended solutions is to use creative API or simply do not fetch the data that
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:14:36,000 --> 00:14:37,000
|
| 655 |
+
you don't need.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:14:38,000 --> 00:14:44,000
|
| 659 |
+
Here, I created a query to fetch the data that is required for this specific business case.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:44,000 --> 00:14:47,000
|
| 663 |
+
An example is criteria API.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:47,000 --> 00:14:50,000
|
| 667 |
+
I'm going to show you a little bit later.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:50,000 --> 00:14:56,000
|
| 671 |
+
So here in query, I specified on the fields that I want to fetch.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:56,000 --> 00:15:04,000
|
| 675 |
+
But unfortunately, because I fetched not all fields, or in case you fetch custom set of fields, not
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:15:04,000 --> 00:15:10,000
|
| 679 |
+
always hibernate and convert automatically results into the entity as an option.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:15:10,000 --> 00:15:17,000
|
| 683 |
+
You can create a separate entity that would contain the less amount of fields, but I don't recommend
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:15:17,000 --> 00:15:19,000
|
| 687 |
+
you to do that.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:15:19,000 --> 00:15:27,000
|
| 691 |
+
Just wanted to show that you can always take the topos that you received and initialize the type that
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:15:27,000 --> 00:15:27,000
|
| 695 |
+
you need.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:28,000 --> 00:15:32,000
|
| 699 |
+
Like in this case, we received a list of object arrays.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:33,000 --> 00:15:38,000
|
| 703 |
+
Each object array is a set of values as specified in the query.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:39,000 --> 00:15:42,000
|
| 707 |
+
The first value will be on the zero.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:42,000 --> 00:15:46,000
|
| 711 |
+
The second value will be under the index one and so on.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:47,000 --> 00:15:49,000
|
| 715 |
+
Some get purchased by DH.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:49,000 --> 00:15:52,000
|
| 719 |
+
I prepare the example for you with the criteria API.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:53,000 --> 00:16:01,000
|
| 723 |
+
So using the criteria you can specify vividly that you also want to fetch user detail, property and
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:16:01,000 --> 00:16:10,000
|
| 727 |
+
product details properties that these properties will be fetched easily and we will avoid upgrades.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:16:10,000 --> 00:16:19,000
|
| 731 |
+
Initialization exception in the update purchase you can see that I use merge method instead of persist,
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:16:19,000 --> 00:16:20,000
|
| 735 |
+
but why?
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:16:20,000 --> 00:16:27,000
|
| 739 |
+
In case we will use persist here we will see error that tells us that you want to persist.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:16:27,000 --> 00:16:34,000
|
| 743 |
+
The dodged entity and attached entity is a Java object that is no longer tracked by the persistence
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:34,000 --> 00:16:44,000
|
| 747 |
+
context entities can reach this state if we close only as a session component will throw a persistent
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:44,000 --> 00:16:47,000
|
| 751 |
+
exception with the detached entity passed to persist.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:47,000 --> 00:16:48,000
|
| 755 |
+
Error message.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:49,000 --> 00:16:56,000
|
| 759 |
+
If we use the March method hibernate, we attach the entity to the persistence context based on the
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:56,000 --> 00:16:57,000
|
| 763 |
+
ID field.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:57,000 --> 00:17:04,000
|
| 767 |
+
So in my solution in different places, you are going to see that the use merge instead of persist and
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:17:04,000 --> 00:17:07,000
|
| 771 |
+
you'll know why I do like this.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:17:08,000 --> 00:17:10,000
|
| 775 |
+
Their suits were getting purchased down.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:17:10,000 --> 00:17:11,000
|
| 779 |
+
Let's continue.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:17:12,000 --> 00:17:15,000
|
| 783 |
+
The next on the list is purchase status down.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:17:16,000 --> 00:17:22,000
|
| 787 |
+
Actually, there is only one mass here and they use one method that we have already learned.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:17:23,000 --> 00:17:24,000
|
| 791 |
+
And the user Dao.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:24,000 --> 00:17:31,000
|
| 795 |
+
I apply the same principles that we are already talked through to implement the DAO interface.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:31,000 --> 00:17:38,000
|
| 799 |
+
Another interesting thing here is that the protocol logic is built around the verification.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:38,000 --> 00:17:46,000
|
| 803 |
+
If a user is present in the database during the registration, we check if user with such email exists
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:46,000 --> 00:17:53,000
|
| 807 |
+
and in case there is no user with such email, we proceed with the registration get single result so
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:53,000 --> 00:18:00,000
|
| 811 |
+
we throw no result exception in case result wouldn't be found for such cases.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:18:00,000 --> 00:18:04,000
|
| 815 |
+
You have to handle this exception like I did in this case.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:18:04,000 --> 00:18:11,000
|
| 819 |
+
I catch this exception and return now because there is no handling already in place according to the
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:18:11,000 --> 00:18:13,000
|
| 823 |
+
contract that we have developed.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:18:14,000 --> 00:18:16,000
|
| 827 |
+
Take the time to look through the implementation solo.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:18:17,000 --> 00:18:25,000
|
| 831 |
+
And anyway, in case after you still have some questions, please do not hesitate to ask your questions
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:18:25,000 --> 00:18:28,000
|
| 835 |
+
below the video and I will be happy to answer.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:18:29,000 --> 00:18:35,000
|
| 839 |
+
The only thing that is still left to do is to inject the implementations into the business layer.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:36,000 --> 00:18:42,000
|
| 843 |
+
Let's find our facade layer and instead of gdb see the implementations.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:42,000 --> 00:18:45,000
|
| 847 |
+
Let's inject our implementations.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:46,000 --> 00:18:50,000
|
| 851 |
+
Our facade implementations are located in the core module.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:51,000 --> 00:18:54,000
|
| 855 |
+
So let's open the full category facade, for example.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:54,000 --> 00:19:00,000
|
| 859 |
+
And for category implementation, let's use GPU category class.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:19:01,000 --> 00:19:06,000
|
| 863 |
+
Unless there's a seamless sync with all other facade objects.
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:19:06,000 --> 00:19:07,000
|
| 867 |
+
Definitely.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:19:07,000 --> 00:19:14,000
|
| 871 |
+
When you have a container to manage your beans like we have in spring, it is easier to make injections
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:19:14,000 --> 00:19:16,000
|
| 875 |
+
like this in the configuration file.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:19:17,000 --> 00:19:22,000
|
| 879 |
+
In my course java from zero to first job, we are going to learn how to work with spring conversion
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:19:22,000 --> 00:19:26,000
|
| 883 |
+
of control, container speed data and lots more.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:19:26,000 --> 00:19:32,000
|
| 887 |
+
After we injected, our new patients were good to run our application.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:19:33,000 --> 00:19:34,000
|
| 891 |
+
One more thing.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:19:34,000 --> 00:19:41,000
|
| 895 |
+
When you run the applications the first time, make sure that you have drop and create value in the
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:19:41,000 --> 00:19:44,000
|
| 899 |
+
persistence section for schema generation option.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:19:45,000 --> 00:19:49,000
|
| 903 |
+
Run the program first time all tables will be created.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:50,000 --> 00:19:56,000
|
| 907 |
+
After that, I suggest to use prepared data set to populate database with the fake data.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:57,000 --> 00:20:03,000
|
| 911 |
+
Prepared dataset is located in the persistence module in the folder database expert.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:20:04,000 --> 00:20:09,000
|
| 915 |
+
The reason file was only input statements created specially for this project.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:20:10,000 --> 00:20:13,000
|
| 919 |
+
It is called data input for GP project.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:20:14,000 --> 00:20:21,000
|
| 923 |
+
And after you inserted all this data, change the value of this property to update in order to keep
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:20:21,000 --> 00:20:26,000
|
| 927 |
+
your data stored in the database just to help you with all these steps.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:20:26,000 --> 00:20:29,000
|
| 931 |
+
I created a simple checklist for you.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:20:29,000 --> 00:20:37,000
|
| 935 |
+
You can open a new file in the route of the application, and here describes the deployment algorithm
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:20:37,000 --> 00:20:39,000
|
| 939 |
+
that we have just discussed.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:20:40,000 --> 00:20:41,000
|
| 943 |
+
That's it.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:20:41,000 --> 00:20:45,000
|
| 947 |
+
Basically, that's all solutions that I'd like to share with you.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:20:45,000 --> 00:20:50,000
|
| 951 |
+
Now you can run application and testing to get it.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:20:50,000 --> 00:20:57,000
|
| 955 |
+
And as always, you're welcome to ask any questions you want, and that will be happy to answer.
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:20:58,000 --> 00:21:00,000
|
| 959 |
+
Thanks a lot for your attention.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:21:00,000 --> 00:21:03,000
|
| 963 |
+
Have a great day and see you in the next lesson.
|
| 964 |
+
|
80 - ===== EXAM TASK JPA & Hibernate =====/001 Homework-description-and-reference-to-the-solution.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://docs.google.com/document/d/19OqkSC7kxj5y7TOH3GDxIVa8MjDnatrJ0u3R1hDYha8/edit?usp=sharing
|
80 - ===== EXAM TASK JPA & Hibernate =====/external-links.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Homework-description-and-reference-to-the-solution
|
| 3 |
+
https://docs.google.com/document/d/19OqkSC7kxj5y7TOH3GDxIVa8MjDnatrJ0u3R1hDYha8/edit?usp=sharing
|
81 - Spring Core/001 List-of-Spring-projects.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://spring.io/projects
|
81 - Spring Core/001 Official-Site-of-Spring.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://spring.io
|
81 - Spring Core/001 Spring Framework General Overview_en.srt
ADDED
|
@@ -0,0 +1,816 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 15 |
+
We are starting learning with you spring framework.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:12,000 --> 00:00:18,000
|
| 19 |
+
And this is the first lesson where we'll talk about what a spring framework is, what elements does
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:18,000 --> 00:00:24,000
|
| 23 |
+
it have, what we are going to learn in the course and help you to understand which parts of spring
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:24,000 --> 00:00:31,000
|
| 27 |
+
framework is more necessary for you at this moment, We are going to start the lesson from the learning
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:31,000 --> 00:00:32,000
|
| 31 |
+
of what a spring is.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:32,000 --> 00:00:37,000
|
| 35 |
+
After that, I'm going to explain you the key features of Spring framework.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:37,000 --> 00:00:44,000
|
| 39 |
+
This will help you to understand what benefits we expect to get by using Spring framework.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:44,000 --> 00:00:48,000
|
| 43 |
+
I will make a high level overview of spring projects and modules.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:48,000 --> 00:00:55,000
|
| 47 |
+
You are going to understand the purpose of different spring modules and at the end of the video we are
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:55,000 --> 00:00:59,000
|
| 51 |
+
going to talk about advantages and disadvantages of spring framework.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:59,000 --> 00:01:01,000
|
| 55 |
+
Let's start our lesson.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:01,000 --> 00:01:06,000
|
| 59 |
+
Let's start from answering the question what a spring is and why do we need it?
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:07,000 --> 00:01:14,000
|
| 63 |
+
The spring provides a comprehensive programming and configuration model for modern Java based enterprise
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:14,000 --> 00:01:18,000
|
| 67 |
+
applications on any kind of deployment platform.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:19,000 --> 00:01:26,000
|
| 71 |
+
Spring is a large body of predefined code to which developers can add code to solve a problem in a specific
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:26,000 --> 00:01:27,000
|
| 75 |
+
domain.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:27,000 --> 00:01:33,000
|
| 79 |
+
A key element of spring is infrastructural support at the application level.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:33,000 --> 00:01:42,000
|
| 83 |
+
Spring focuses on the plumbing of enterprise application so that teams can focus on application level
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:42,000 --> 00:01:48,000
|
| 87 |
+
business logic without unnecessary ties to the specific deployment environments.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:48,000 --> 00:01:56,000
|
| 91 |
+
Spring is an open source product written in Java with Apache license, meaning that you can freely use
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:56,000 --> 00:01:58,000
|
| 95 |
+
it in your commercial projects.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:58,000 --> 00:02:07,000
|
| 99 |
+
So summarizing what a spring is, in simple words, Spring Framework contains a set of tools libraries
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:07,000 --> 00:02:10,000
|
| 103 |
+
that can help us to solve typical challenges.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:10,000 --> 00:02:18,000
|
| 107 |
+
Typical tasks implement typical engineering solutions faster without writing tons of code and configurations
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:18,000 --> 00:02:22,000
|
| 111 |
+
because this is already considered by spring.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:22,000 --> 00:02:25,000
|
| 115 |
+
Let's learn what the key features of spring are.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:26,000 --> 00:02:35,000
|
| 119 |
+
As I said, spring contains multiple tools, projects, components, whatever you call it, and each
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:35,000 --> 00:02:37,000
|
| 123 |
+
project has its own features.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:37,000 --> 00:02:45,000
|
| 127 |
+
But let me try to summarize probably the most significant ones and those that would be easier to understand
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:45,000 --> 00:02:46,000
|
| 131 |
+
at the moment.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:46,000 --> 00:02:53,000
|
| 135 |
+
And actually, let's understand what are those typical enterprise scale challenges and questions that
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:53,000 --> 00:02:55,000
|
| 139 |
+
spring helps us to deal with.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:56,000 --> 00:03:01,000
|
| 143 |
+
Spring supports core technologies and most of the popular programming concepts.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:02,000 --> 00:03:08,000
|
| 147 |
+
Among them are events handling in my course Java from zero to first job.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:08,000 --> 00:03:15,000
|
| 151 |
+
We already talked about event handling and events that can appear in our web application.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:15,000 --> 00:03:23,000
|
| 155 |
+
Spring contains tools that help us to work with events, concept, internationalization.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:23,000 --> 00:03:29,000
|
| 159 |
+
And again, if you are a student of my Java from zero to first job course, you know that we created
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:29,000 --> 00:03:37,000
|
| 163 |
+
our own online shop from scratch and you saw how much code should be written and how much attention
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:37,000 --> 00:03:42,000
|
| 167 |
+
it requires to handle internationalization questions properly.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:42,000 --> 00:03:48,000
|
| 171 |
+
Spring will save our nerves and will help us to do the same things faster.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:49,000 --> 00:03:50,000
|
| 175 |
+
Data binding.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:50,000 --> 00:03:55,000
|
| 179 |
+
Spring offers solution for data mapping and data binding.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:56,000 --> 00:03:58,000
|
| 183 |
+
Aspect oriented programming.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:58,000 --> 00:04:02,000
|
| 187 |
+
In this course we are going to learn what it is deeper.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:04:02,000 --> 00:04:10,000
|
| 191 |
+
But in short, AOP is a programming paradigm that aims to increase modularity by allowing the separation
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:04:10,000 --> 00:04:12,000
|
| 195 |
+
of cross-cutting concerns.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:04:13,000 --> 00:04:22,000
|
| 199 |
+
Data validation work with resources, dependency injection, work with axises to ensure security and
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:22,000 --> 00:04:23,000
|
| 203 |
+
lots more.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:24,000 --> 00:04:28,000
|
| 207 |
+
Spring MVC and Spring Web flux Web frameworks.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:28,000 --> 00:04:35,000
|
| 211 |
+
In my course Java from zero to first job, we have learned already what an MVC pattern is.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:35,000 --> 00:04:42,000
|
| 215 |
+
You already aware that this is model view controller pattern for web application?
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:42,000 --> 00:04:47,000
|
| 219 |
+
And Spring MVC allows you to implement MVC pattern easily.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:48,000 --> 00:04:51,000
|
| 223 |
+
Talking about spring flags and short.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:51,000 --> 00:04:57,000
|
| 227 |
+
It is used to make it possible to build reactive applications on the HTTP layer.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:57,000 --> 00:05:00,000
|
| 231 |
+
We are going to learn in the details for the spring web.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:05:00,000 --> 00:05:03,000
|
| 235 |
+
Flux is in other lessons.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:05:04,000 --> 00:05:05,000
|
| 239 |
+
Features for testing.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:05:06,000 --> 00:05:07,000
|
| 243 |
+
Mock Objects.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:07,000 --> 00:05:09,000
|
| 247 |
+
Test Context Framework.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:09,000 --> 00:05:11,000
|
| 251 |
+
Spring MVC Test.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:11,000 --> 00:05:12,000
|
| 255 |
+
Web Test.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:12,000 --> 00:05:13,000
|
| 259 |
+
Client.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:13,000 --> 00:05:16,000
|
| 263 |
+
Data Access Transactions.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:16,000 --> 00:05:21,000
|
| 267 |
+
DAO Support JDBC ORM Marshalling XML.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:22,000 --> 00:05:27,000
|
| 271 |
+
Integration remoting is this Java message service.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:27,000 --> 00:05:28,000
|
| 275 |
+
GCA.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:28,000 --> 00:05:30,000
|
| 279 |
+
Java Connector.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:30,000 --> 00:05:31,000
|
| 283 |
+
Architecture.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:31,000 --> 00:05:32,000
|
| 287 |
+
Jmax.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:32,000 --> 00:05:34,000
|
| 291 |
+
Java Management Extensions.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:34,000 --> 00:05:36,000
|
| 295 |
+
Email Tasks.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:36,000 --> 00:05:38,000
|
| 299 |
+
Scheduling Cache.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:38,000 --> 00:05:43,000
|
| 303 |
+
Embedded Tomcat web server to boost your Web application creation.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:44,000 --> 00:05:48,000
|
| 307 |
+
Powerful repository and custom object mapping abstractions.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:48,000 --> 00:05:55,000
|
| 311 |
+
Comprehensive and extensible support for both authentication and authorization.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:05:55,000 --> 00:05:58,000
|
| 315 |
+
Support of transaction management.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:05:58,000 --> 00:06:01,000
|
| 319 |
+
Distributed version Configuration.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:01,000 --> 00:06:05,000
|
| 323 |
+
Load balancing and other different features.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:06,000 --> 00:06:10,000
|
| 327 |
+
Spring has different projects, libraries and different modules.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:10,000 --> 00:06:12,000
|
| 331 |
+
Or in other words, components.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:12,000 --> 00:06:17,000
|
| 335 |
+
Each component of the spring framework has its own purpose.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:17,000 --> 00:06:23,000
|
| 339 |
+
Let me make a brief overview of spring components and understand why we need each of them.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:24,000 --> 00:06:32,000
|
| 343 |
+
Here is the official website of Spring Community and under the Projects menu Select View All Projects.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:33,000 --> 00:06:34,000
|
| 347 |
+
Spring Core.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:34,000 --> 00:06:42,000
|
| 351 |
+
Spring Framework provides a support for dependency injection, transaction management, data access
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:42,000 --> 00:06:43,000
|
| 355 |
+
and others.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:06:43,000 --> 00:06:49,000
|
| 359 |
+
This is core spring module that we need to start with in order to understand the spring.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:06:50,000 --> 00:06:56,000
|
| 363 |
+
We are going to have separate lessons about spring core and I'm going to explain what a dependency injection
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:06:56,000 --> 00:06:57,000
|
| 367 |
+
is.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:06:57,000 --> 00:07:05,000
|
| 371 |
+
But in short, this component of the spring helps us to manage configurations of our application manage
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:05,000 --> 00:07:11,000
|
| 375 |
+
lifecycle of objects in the application, their construction and lots more.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:11,000 --> 00:07:13,000
|
| 379 |
+
I would say this is the basics.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:14,000 --> 00:07:21,000
|
| 383 |
+
Spring Boot, in simple words, contains all necessary tools in order to help you start creation of
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:21,000 --> 00:07:24,000
|
| 387 |
+
the application as soon as possible.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:25,000 --> 00:07:28,000
|
| 391 |
+
Actually, there are two concepts of learning spring.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:29,000 --> 00:07:37,000
|
| 395 |
+
Some teachers recommend to start from the spring boot that essentially combines many other spring components.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:37,000 --> 00:07:44,000
|
| 399 |
+
Other teachers agree that to understand spring boot, it is better to understand other spring components.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:45,000 --> 00:07:49,000
|
| 403 |
+
I also believe that it is not a good idea to start from the spring boot.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:50,000 --> 00:07:52,000
|
| 407 |
+
I am not saying that we will not learn it.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:07:52,000 --> 00:07:59,000
|
| 411 |
+
I would just call spring boot as an aggregator of other spring elements and I would prefer you to learn
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:07:59,000 --> 00:08:00,000
|
| 415 |
+
spring gradually.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:01,000 --> 00:08:03,000
|
| 419 |
+
And another important moment.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:03,000 --> 00:08:04,000
|
| 423 |
+
Not always.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:04,000 --> 00:08:06,000
|
| 427 |
+
We use spring boot.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:06,000 --> 00:08:10,000
|
| 431 |
+
Sometimes we use few spring modules that we need only.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:11,000 --> 00:08:19,000
|
| 435 |
+
Spring data, very powerful tool to work with data mapping and persistent storage in your application.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:19,000 --> 00:08:28,000
|
| 439 |
+
In my course Java from zero to first job, we have learned GP Hibernate and Gdcc Ziza tools to work
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:28,000 --> 00:08:36,000
|
| 443 |
+
with data and persistent storages and spring data introduces additional layer of abstraction on top
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:36,000 --> 00:08:36,000
|
| 447 |
+
of that.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:08:37,000 --> 00:08:43,000
|
| 451 |
+
Also, I wanted to say that spring data as it is something what would help us to work with data?
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:08:44,000 --> 00:08:49,000
|
| 455 |
+
And sometimes it will help us to save even more time than hibernate.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:08:49,000 --> 00:08:55,000
|
| 459 |
+
You would see in the course you can see here Spring Cloud by its name.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:08:55,000 --> 00:09:01,000
|
| 463 |
+
It is clear that this project provides us with tools for working with cloud based technologies.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:02,000 --> 00:09:09,000
|
| 467 |
+
Spring Security helps us to configure authentication and authorization while working with resources
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:09,000 --> 00:09:10,000
|
| 471 |
+
in our application.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:11,000 --> 00:09:19,000
|
| 475 |
+
And this is important for you to know basics and how web application works inside the web filter concept
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:19,000 --> 00:09:21,000
|
| 479 |
+
and other basics.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:21,000 --> 00:09:25,000
|
| 483 |
+
Because spring security is built on top of those basic tools.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:26,000 --> 00:09:29,000
|
| 487 |
+
You can see many, many other spring projects here.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:30,000 --> 00:09:34,000
|
| 491 |
+
I believe there is no need me going over each one here in the list.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:35,000 --> 00:09:38,000
|
| 495 |
+
I'm going to share with you a link to this page.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:09:38,000 --> 00:09:41,000
|
| 499 |
+
You can find the link in attachments to the video.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:09:42,000 --> 00:09:47,000
|
| 503 |
+
Let's now talk about advantages and disadvantages of the spring.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:09:47,000 --> 00:09:49,000
|
| 507 |
+
Talking about advantages.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:09:49,000 --> 00:09:52,000
|
| 511 |
+
It is worth to mention the next sinks.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:09:52,000 --> 00:09:59,000
|
| 515 |
+
Loose coupling spring applications are loosely coupled because of dependency injection.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:09:59,000 --> 00:10:06,000
|
| 519 |
+
It handles injecting dependent components without a component knowing where they came from.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:07,000 --> 00:10:08,000
|
| 523 |
+
Powerful abstraction.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:09,000 --> 00:10:18,000
|
| 527 |
+
It provides a powerful abstraction to give specifications such as GM's GPC, GPA and GTA.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:19,000 --> 00:10:21,000
|
| 531 |
+
Declarative support.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:22,000 --> 00:10:28,000
|
| 535 |
+
It provides declarative support for caching validation, transaction and formatting.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:29,000 --> 00:10:33,000
|
| 539 |
+
Declarative means opposite to programmatic approach.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:33,000 --> 00:10:40,000
|
| 543 |
+
With the declarative approach, we can manage different things through configuration annotations or
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:40,000 --> 00:10:42,000
|
| 547 |
+
XML based configuration.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:10:43,000 --> 00:10:44,000
|
| 551 |
+
Configuration.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:10:44,000 --> 00:10:52,000
|
| 555 |
+
It provides a consistent way of configuring everything separate configuration from application logic
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:10:52,000 --> 00:10:53,000
|
| 559 |
+
lifecycle.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:10:54,000 --> 00:10:58,000
|
| 563 |
+
Responsible for managing all your application components.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:10:58,000 --> 00:11:04,000
|
| 567 |
+
First, the team of Spring Engineers deeply cares about the performance.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:05,000 --> 00:11:10,000
|
| 571 |
+
It's fast startup fast shut down and optimized execution.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:10,000 --> 00:11:12,000
|
| 575 |
+
Maintain performance.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:12,000 --> 00:11:13,000
|
| 579 |
+
Make it fast.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:14,000 --> 00:11:21,000
|
| 583 |
+
We can start a new spring project in seconds by using spring initializer web application.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:21,000 --> 00:11:23,000
|
| 587 |
+
Basically, here it is.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:24,000 --> 00:11:31,000
|
| 591 |
+
You can just go to the website with this link and configure that project that you need.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:31,000 --> 00:11:33,000
|
| 595 |
+
Select Automation.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:11:33,000 --> 00:11:40,000
|
| 599 |
+
Build Tool language, Specify spring boot version, project metadata, dependencies.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:11:40,000 --> 00:11:47,000
|
| 603 |
+
And after specifying all this, you can quickly download archive with a template project.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:11:47,000 --> 00:11:49,000
|
| 607 |
+
Isn't this cool?
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:11:49,000 --> 00:11:56,000
|
| 611 |
+
Don't worry, during the course we are going to use this tool to just wanted to show it to you.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:11:57,000 --> 00:12:00,000
|
| 615 |
+
The next advantage is that spring is secure.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:00,000 --> 00:12:04,000
|
| 619 |
+
It monitors third party dependencies closely.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:04,000 --> 00:12:07,000
|
| 623 |
+
The regular update is issued.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:07,000 --> 00:12:11,000
|
| 627 |
+
That make our data and application secure.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:12,000 --> 00:12:17,000
|
| 631 |
+
We can make our application secure by using the spring security framework.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:17,000 --> 00:12:25,000
|
| 635 |
+
It provides industry standard security schemas and delivers a trustworthy solution that is secure by
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:25,000 --> 00:12:26,000
|
| 639 |
+
default.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:27,000 --> 00:12:28,000
|
| 643 |
+
Supportive.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:12:28,000 --> 00:12:30,000
|
| 647 |
+
Spring has huge community.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:12:30,000 --> 00:12:33,000
|
| 651 |
+
It is not just big, it is huge.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:12:33,000 --> 00:12:37,000
|
| 655 |
+
Working with spring and facing with some challenges.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:12:37,000 --> 00:12:45,000
|
| 659 |
+
Most likely somebody already solved it some time ago and you can easily find the solution for a challenge
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:12:45,000 --> 00:12:46,000
|
| 663 |
+
in the internet.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:12:47,000 --> 00:12:52,000
|
| 667 |
+
The spring Community provides support and resources to get you to the next level.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:12:52,000 --> 00:12:58,000
|
| 671 |
+
Quick start guides, tutorials, videos and meetups help a lot.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:12:59,000 --> 00:13:00,000
|
| 675 |
+
Productive.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:13:00,000 --> 00:13:07,000
|
| 679 |
+
It is more productive because the spring application can integrate with other spring based applications.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:07,000 --> 00:13:12,000
|
| 683 |
+
For example, we can combine spring boot application with Spring Cloud.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:13,000 --> 00:13:18,000
|
| 687 |
+
Depending on whom you talk to, you can hear different advantages.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:18,000 --> 00:13:25,000
|
| 691 |
+
But the thing is that spring deserved its place and reputation in the world of Java ecosystem.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:25,000 --> 00:13:29,000
|
| 695 |
+
Not all projects in the world use spring.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:29,000 --> 00:13:37,000
|
| 699 |
+
This is also true, but really a lot of projects nowadays relies on the spring during the development.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:38,000 --> 00:13:40,000
|
| 703 |
+
We have learned spring advantages.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:13:40,000 --> 00:13:44,000
|
| 707 |
+
Now let's learn spring disadvantages.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:13:45,000 --> 00:13:51,000
|
| 711 |
+
In case you need to implement something custom, you need to be very familiar with what is happening
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:13:51,000 --> 00:13:53,000
|
| 715 |
+
in spring under the hood.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:13:53,000 --> 00:14:02,000
|
| 719 |
+
You need to understand which classes do what in order to override their behavior whenever it will be
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:02,000 --> 00:14:02,000
|
| 723 |
+
needed.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:03,000 --> 00:14:11,000
|
| 727 |
+
A lot of things happening outside of your control in case you would seek for optimization or any security
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:11,000 --> 00:14:12,000
|
| 731 |
+
questions.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:13,000 --> 00:14:20,000
|
| 735 |
+
Again, you need to be familiar with spring internals to understand how it works inside.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:14:21,000 --> 00:14:22,000
|
| 739 |
+
Complexity.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:14:22,000 --> 00:14:29,000
|
| 743 |
+
While spring saves us time during the development and can make our lives easier, it is still needed
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:14:29,000 --> 00:14:33,000
|
| 747 |
+
to learn how it works and its specifics.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:14:33,000 --> 00:14:38,000
|
| 751 |
+
Working with spring is more complex than with plain Java, for example.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:14:38,000 --> 00:14:42,000
|
| 755 |
+
It requires a lot of expertise.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:14:42,000 --> 00:14:47,000
|
| 759 |
+
If you have not used spring before, first you will have to learn.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:14:47,000 --> 00:14:50,000
|
| 763 |
+
The learning curve is also difficult.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:14:50,000 --> 00:14:56,000
|
| 767 |
+
So if you have not a lot of development experience, it is difficult to learn.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:14:57,000 --> 00:14:59,000
|
| 771 |
+
One, you will learn spring better.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:14:59,000 --> 00:15:04,000
|
| 775 |
+
Probably you will be able to add your own items in the disadvantages list.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:05,000 --> 00:15:10,000
|
| 779 |
+
But for now, I believe these are the main disadvantages.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:15:10,000 --> 00:15:14,000
|
| 783 |
+
Let's recap what we have learned in this lesson.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:15:14,000 --> 00:15:17,000
|
| 787 |
+
In this video, we have learned what a spring is.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:15:17,000 --> 00:15:20,000
|
| 791 |
+
We discussed key spring features.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:15:20,000 --> 00:15:24,000
|
| 795 |
+
Now you can imagine what spring does and why do we need it?
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:15:24,000 --> 00:15:32,000
|
| 799 |
+
I showed you what spring consists of and we did a high level overview of spring projects and modules.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:15:32,000 --> 00:15:38,000
|
| 803 |
+
And at the end of the lesson we have discussed advantages and disadvantages of spring framework.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:15:39,000 --> 00:15:41,000
|
| 807 |
+
That's all for this lesson.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:15:41,000 --> 00:15:43,000
|
| 811 |
+
Thanks a lot for your attention.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:15:43,000 --> 00:15:46,000
|
| 815 |
+
Have a great day and see you in the next lesson.
|
| 816 |
+
|
81 - Spring Core/001 Spring-Initializr.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://start.spring.io/
|
81 - Spring Core/002 Spring Architecture, Inversion of Control, Dependency Injection & Spring Beans_en.srt
ADDED
|
@@ -0,0 +1,736 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:06,000
|
| 3 |
+
Hello, team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:09,000
|
| 7 |
+
Today we start learning spring core.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:09,000 --> 00:00:15,000
|
| 11 |
+
This is very interesting and important topic that will help you to understand all further lessons about
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:15,000 --> 00:00:16,000
|
| 15 |
+
spring.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:16,000 --> 00:00:21,000
|
| 19 |
+
Today we are going to have theoretical lesson, but believe me, this is important.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:21,000 --> 00:00:27,000
|
| 23 |
+
In order you can proceed with learning and understanding of practical examples.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:27,000 --> 00:00:35,000
|
| 27 |
+
I know that series sometimes may sound boring, but I will try to make it as interesting as possible.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:41,000
|
| 31 |
+
I will not tell you redundant things and I will be as short as possible to share with you only necessary
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:41,000 --> 00:00:42,000
|
| 35 |
+
things.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:42,000 --> 00:00:49,000
|
| 39 |
+
In this lesson we are going to hold an overview and learn spring framework architecture and you are
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:49,000 --> 00:00:53,000
|
| 43 |
+
going to understand the place of spring core in the general architecture.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:53,000 --> 00:01:00,000
|
| 47 |
+
We will learn such basic and important concepts as inversion of control and dependency injection.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:01:00,000 --> 00:01:05,000
|
| 51 |
+
After that, we are going to talk about spring inversion of control container.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:05,000 --> 00:01:11,000
|
| 55 |
+
I'm going to review with you key types that we are going to work with while interacting with a spring
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:12,000 --> 00:01:13,000
|
| 59 |
+
container.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:13,000 --> 00:01:16,000
|
| 63 |
+
I will explain what a spring context is.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:16,000 --> 00:01:23,000
|
| 67 |
+
Besides that, today we are going to learn super important concept that is called spring beans.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:23,000 --> 00:01:28,000
|
| 71 |
+
We will learn what is a and we will review the scopes of spring beans.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:28,000 --> 00:01:33,000
|
| 75 |
+
And at the end of the lesson we'll review what a spring expression language is.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:33,000 --> 00:01:35,000
|
| 79 |
+
We have a lot of things to learn today.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:35,000 --> 00:01:37,000
|
| 83 |
+
Let's start our lesson.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:38,000 --> 00:01:45,000
|
| 87 |
+
Let's start from learning of architecture of spring framework and understand what is the role and place
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:45,000 --> 00:01:52,000
|
| 91 |
+
of spring core in the general spring architecture like we have learned already in the introduction Lesson
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:52,000 --> 00:01:53,000
|
| 95 |
+
about the spring.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:53,000 --> 00:01:57,000
|
| 99 |
+
Spring framework consists of many different components.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:57,000 --> 00:02:05,000
|
| 103 |
+
The spring framework comprises several modules and features such as inversion of control aspect oriented
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:05,000 --> 00:02:06,000
|
| 107 |
+
programming.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:06,000 --> 00:02:08,000
|
| 111 |
+
DAO Context.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:08,000 --> 00:02:09,000
|
| 115 |
+
Or Earum.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:09,000 --> 00:02:09,000
|
| 119 |
+
Depb.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:09,000 --> 00:02:10,000
|
| 123 |
+
MVC.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:10,000 --> 00:02:11,000
|
| 127 |
+
ET cetera.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:11,000 --> 00:02:19,000
|
| 131 |
+
We'll learn these modules and features one by one, but there is some basics that lies in the core for
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:19,000 --> 00:02:21,000
|
| 135 |
+
all modules.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:21,000 --> 00:02:28,000
|
| 139 |
+
I'm talking about core spring inversion of control, container dependency, injection, spring context
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:28,000 --> 00:02:30,000
|
| 143 |
+
and such basic concepts as spring bean.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:31,000 --> 00:02:35,000
|
| 147 |
+
You can see on this slide where core container is located.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:35,000 --> 00:02:40,000
|
| 151 |
+
So it is like in basement of the spring framework.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:02:40,000 --> 00:02:46,000
|
| 155 |
+
It contains the fundamental modules that are the cornerstone of spring framework.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:02:46,000 --> 00:02:55,000
|
| 159 |
+
Core Spring core is a core of the framework that power features such as inversion of control and dependency
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:02:55,000 --> 00:02:57,000
|
| 163 |
+
injection beans.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:02:57,000 --> 00:03:05,000
|
| 167 |
+
Spring Beans provides bean factory, which is sophisticated implementation of the factory pattern.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:05,000 --> 00:03:15,000
|
| 171 |
+
Context Spring context builds on core and beans and provides a medium to access defined objects.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:15,000 --> 00:03:21,000
|
| 175 |
+
Application context interface is the core part of the context module and the spring context.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:21,000 --> 00:03:29,000
|
| 179 |
+
Support provides support for third party interactions such as caching, mailing and template engines.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:29,000 --> 00:03:31,000
|
| 183 |
+
Spring Expression Language.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:31,000 --> 00:03:39,000
|
| 187 |
+
Spring expression enables users to use the spring expression language to query and manipulate the object
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:39,000 --> 00:03:41,000
|
| 191 |
+
graph at runtime.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:41,000 --> 00:03:46,000
|
| 195 |
+
Before moving to other slides and learning specifics of spring.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:46,000 --> 00:03:52,000
|
| 199 |
+
Let's understand such core concepts as inversion of control and dependency injection.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:53,000 --> 00:03:59,000
|
| 203 |
+
IOC inverts the flow of control as compared to traditional control flow.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:03:59,000 --> 00:04:06,000
|
| 207 |
+
In traditional programming, the flow of the business logic is determined by objects that are statically
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:06,000 --> 00:04:08,000
|
| 211 |
+
bound to one another.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:08,000 --> 00:04:16,000
|
| 215 |
+
This inversion of control the flow depends on the object graph that is built up during program execution.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:16,000 --> 00:04:24,000
|
| 219 |
+
Such a dynamic flow is made possible by object interactions that are defined through abstractions.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:24,000 --> 00:04:33,000
|
| 223 |
+
This runtime binding is achieved by mechanisms such as dependency, injection or service locator in
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:33,000 --> 00:04:33,000
|
| 227 |
+
IOC.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:33,000 --> 00:04:40,000
|
| 231 |
+
The code could also be linked statically during compilation, but you will find that to execute the
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:40,000 --> 00:04:48,000
|
| 235 |
+
code, the external configuration will be used to build object graph and manage all the dependencies
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:48,000 --> 00:04:56,000
|
| 239 |
+
so you already can understand that dependency injection is just one of the possible ways how we can
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:56,000 --> 00:04:58,000
|
| 243 |
+
implement inversion of control.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:59,000 --> 00:05:07,000
|
| 247 |
+
Dependency injection is a pattern we can use to implement IOC where the control being inverted is set
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:07,000 --> 00:05:09,000
|
| 251 |
+
in an object's dependencies.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:09,000 --> 00:05:17,000
|
| 255 |
+
Connecting objects with other objects or injecting objects into other objects is done by an assembler
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:17,000 --> 00:05:20,000
|
| 259 |
+
rather than by the objects themselves.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:20,000 --> 00:05:25,000
|
| 263 |
+
There are three main ways in which a client can receive injected services.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:25,000 --> 00:05:32,000
|
| 267 |
+
Constructor injection where dependencies are provided through a client class constructor.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:32,000 --> 00:05:40,000
|
| 271 |
+
Setter injection where the client exposes a setter method which accepts the dependency interface.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:40,000 --> 00:05:47,000
|
| 275 |
+
Injection where the dependencies interface provides an injector method that will inject the dependency
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:47,000 --> 00:05:50,000
|
| 279 |
+
into any client passed to it.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:50,000 --> 00:05:51,000
|
| 283 |
+
Okay.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:51,000 --> 00:05:56,000
|
| 287 |
+
Now when we have learned what an inversion of control and dependency injections are.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:56,000 --> 00:06:00,000
|
| 291 |
+
Let's understand now what a spring IOC container is.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:01,000 --> 00:06:07,000
|
| 295 |
+
The IOC container is responsible to instantiate, configure and assemble the objects.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:07,000 --> 00:06:16,000
|
| 299 |
+
The IOC container gets information from the XML file or Java annotations and works accordingly.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:16,000 --> 00:06:24,000
|
| 303 |
+
The main tasks performed by IOC Container are to instantiate the application class to configure the
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:24,000 --> 00:06:28,000
|
| 307 |
+
object to assemble the dependencies between the objects.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:29,000 --> 00:06:38,000
|
| 311 |
+
Spring IOC is a mechanism to achieve loose coupling between objects dependencies to achieve loose coupling.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:38,000 --> 00:06:45,000
|
| 315 |
+
And dynamic binding of the objects at runtime objects, dependencies are injected by other assembler
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:45,000 --> 00:06:46,000
|
| 319 |
+
objects.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:46,000 --> 00:06:54,000
|
| 323 |
+
Spring IOC Container is a program that injects dependencies into an object and make it ready for our
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:54,000 --> 00:06:55,000
|
| 327 |
+
use.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:55,000 --> 00:07:02,000
|
| 331 |
+
In other words, with a spring IOC, we have entity in our program that is in charge of the life cycle
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:07:02,000 --> 00:07:06,000
|
| 335 |
+
of our objects and dependencies between them.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:06,000 --> 00:07:12,000
|
| 339 |
+
We can manage our dependencies between objects directly in the configuration files.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:13,000 --> 00:07:20,000
|
| 343 |
+
Let's review the key interfaces and types that are in charge of spring inversion of Control container.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:20,000 --> 00:07:26,000
|
| 347 |
+
Spring IAC Container provides us different ways to decouple the object dependencies.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:26,000 --> 00:07:31,000
|
| 351 |
+
Bean factory is the root interface of spring IOC container.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:32,000 --> 00:07:37,000
|
| 355 |
+
Application context is a child interface of bean factory interface.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:37,000 --> 00:07:45,000
|
| 359 |
+
Some of the useful child interfaces of application contexts are configurable application context and
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:45,000 --> 00:07:47,000
|
| 363 |
+
web application context.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:47,000 --> 00:07:53,000
|
| 367 |
+
Spring Framework provides a number of useful application context implementation classes that we can
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:53,000 --> 00:07:57,000
|
| 371 |
+
use to get the spring context and then the spring bean.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:57,000 --> 00:08:05,000
|
| 375 |
+
Some of the useful application context implementations is that we use are annotation config application
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:08:05,000 --> 00:08:06,000
|
| 379 |
+
context.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:06,000 --> 00:08:14,000
|
| 383 |
+
If we are using spring in standalone Java applications and using annotations for configuration, then
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:14,000 --> 00:08:19,000
|
| 387 |
+
we can use this to initialize the container and get the bean objects.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:20,000 --> 00:08:23,000
|
| 391 |
+
Classpath XML application context.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:23,000 --> 00:08:30,000
|
| 395 |
+
If we have spring bean configuration XML file in standalone application, then we can use this class
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:30,000 --> 00:08:33,000
|
| 399 |
+
to load the file and get the container object.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:34,000 --> 00:08:35,000
|
| 403 |
+
File system.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:35,000 --> 00:08:37,000
|
| 407 |
+
XML application context.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:37,000 --> 00:08:39,000
|
| 411 |
+
This is similar to classpath.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:39,000 --> 00:08:47,000
|
| 415 |
+
XML application context, except that the XML configuration file can be loaded from anywhere in the
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:47,000 --> 00:08:48,000
|
| 419 |
+
file system.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:49,000 --> 00:08:57,000
|
| 423 |
+
Annotation config web application context, an XML web application context for web applications for
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:57,000 --> 00:09:03,000
|
| 427 |
+
a standalone application, we need to initialize the container somewhere in the application and then
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:03,000 --> 00:09:06,000
|
| 431 |
+
use it to get the spring beans.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:07,000 --> 00:09:10,000
|
| 435 |
+
We mentioned spring context on previous slides.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:10,000 --> 00:09:13,000
|
| 439 |
+
Let me now explain you what it is.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:14,000 --> 00:09:22,000
|
| 443 |
+
The context in the spring framework is shorthand for application context type and its child types.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:22,000 --> 00:09:29,000
|
| 447 |
+
Spring context is a programming construct that framework uses to access components from the inversion
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:29,000 --> 00:09:32,000
|
| 451 |
+
of control container where they are cache.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:33,000 --> 00:09:34,000
|
| 455 |
+
Linguistically.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:34,000 --> 00:09:41,000
|
| 459 |
+
Context is a vague term for the abstract set of circumstances in which an event occurs.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:41,000 --> 00:09:48,000
|
| 463 |
+
However, in the context of the spring framework, the application context is well defined and understood
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:49,000 --> 00:09:56,000
|
| 467 |
+
by framework users as a state of the IOC container from which a component has been produced via dependency
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:56,000 --> 00:09:57,000
|
| 471 |
+
injection.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:58,000 --> 00:10:00,000
|
| 475 |
+
Hope that this is clear now.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:00,000 --> 00:10:05,000
|
| 479 |
+
Also during the course were often we are going to use such term as spring bean.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:05,000 --> 00:10:07,000
|
| 483 |
+
Let's understand.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:07,000 --> 00:10:08,000
|
| 487 |
+
What is it?
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:08,000 --> 00:10:11,000
|
| 491 |
+
Spring bean is nothing special.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:11,000 --> 00:10:16,000
|
| 495 |
+
Any object in the spring framework that we initialize through spring container is called Spring Bean.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:17,000 --> 00:10:21,000
|
| 499 |
+
Any normal Java project class can be a spring bean.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:21,000 --> 00:10:28,000
|
| 503 |
+
It is configured to be initialized with a container by providing configuration metadata information.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:29,000 --> 00:10:33,000
|
| 507 |
+
Each bean in spring container has its own scope.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:33,000 --> 00:10:35,000
|
| 511 |
+
What is bean scope?
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:35,000 --> 00:10:39,000
|
| 515 |
+
Bean scopes refers to the lifecycle of bean.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:39,000 --> 00:10:46,000
|
| 519 |
+
That means when the object of bean will be instantiated, how long does the object leave and how many
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:46,000 --> 00:10:49,000
|
| 523 |
+
objects will be created for that bean sprout?
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:49,000 --> 00:10:56,000
|
| 527 |
+
Basically, it controls the instance creation of the bean and it is managed by the spring container.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:57,000 --> 00:11:02,000
|
| 531 |
+
There are five scopes defined for spring beans Singleton.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:02,000 --> 00:11:06,000
|
| 535 |
+
Only one instance of the bean will be created for each container.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:07,000 --> 00:11:09,000
|
| 539 |
+
This is the default scope for the spring beans.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:09,000 --> 00:11:15,000
|
| 543 |
+
While using this scope, make sure Bean doesn't have shared instance variables.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:15,000 --> 00:11:20,000
|
| 547 |
+
Otherwise it might lead to data inconsistency issues.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:20,000 --> 00:11:21,000
|
| 551 |
+
Prototype.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:21,000 --> 00:11:25,000
|
| 555 |
+
A new instance will be created every time the bean is requested.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:26,000 --> 00:11:27,000
|
| 559 |
+
Request.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:27,000 --> 00:11:30,000
|
| 563 |
+
This is the same as prototype scope.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:30,000 --> 00:11:37,000
|
| 567 |
+
However, it's meant to be used for web applications and new instance of the bin will be created for
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:37,000 --> 00:11:39,000
|
| 571 |
+
each HTTP request.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:39,000 --> 00:11:40,000
|
| 575 |
+
Session.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:41,000 --> 00:11:45,000
|
| 579 |
+
A new bill will be created for each HTTP session by the container.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:46,000 --> 00:11:52,000
|
| 583 |
+
Application scope container creates one instance per web application runtime.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:52,000 --> 00:11:57,000
|
| 587 |
+
It is almost similar to singleton scope with only two differences.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:11:57,000 --> 00:11:58,000
|
| 591 |
+
That is.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:11:58,000 --> 00:12:04,000
|
| 595 |
+
Application scoped bean is singleton per served context, whereas Singleton scoped.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:04,000 --> 00:12:08,000
|
| 599 |
+
Bean is singleton per application context.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:08,000 --> 00:12:14,000
|
| 603 |
+
Please note that there can be multiple application contexts for a single application.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:15,000 --> 00:12:20,000
|
| 607 |
+
Application scoped bean is visible as a servlet context attribute.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:21,000 --> 00:12:22,000
|
| 611 |
+
WebSocket.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:23,000 --> 00:12:28,000
|
| 615 |
+
WebSocket scoped beans are stored in the websocket session attributes.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:28,000 --> 00:12:35,000
|
| 619 |
+
The same instance of the bean is then returned whenever the bean is accessed during the entire WebSocket
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:35,000 --> 00:12:36,000
|
| 623 |
+
session.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:36,000 --> 00:12:41,000
|
| 627 |
+
Spring framework is extendable and we can create our own scopes too.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:12:41,000 --> 00:12:47,000
|
| 631 |
+
However, most of the times we are good with the scopes provided by the framework.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:12:47,000 --> 00:12:53,000
|
| 635 |
+
And the last but not the least, that I would like to talk about today is spring expression language.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:12:53,000 --> 00:12:57,000
|
| 639 |
+
It is an extension to the expression language defined in JSP.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:12:58,000 --> 00:13:02,000
|
| 643 |
+
It provides support to setting and getting property values.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:02,000 --> 00:13:04,000
|
| 647 |
+
Method Invocation.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:04,000 --> 00:13:05,000
|
| 651 |
+
Access and collection.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:05,000 --> 00:13:06,000
|
| 655 |
+
And indexers.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:06,000 --> 00:13:08,000
|
| 659 |
+
Named Variables.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:08,000 --> 00:13:11,000
|
| 663 |
+
Logical and Arithmetic Operators.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:11,000 --> 00:13:15,000
|
| 667 |
+
Retrieval of objects by name, etcetera.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:13:15,000 --> 00:13:21,000
|
| 671 |
+
The spring expression language is a powerful expression language that supports querying and manipulating
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:13:21,000 --> 00:13:23,000
|
| 675 |
+
an object graph at runtime.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:13:24,000 --> 00:13:29,000
|
| 679 |
+
We can use it with XML or annotation based spring configurations.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:13:30,000 --> 00:13:32,000
|
| 683 |
+
That's all what I wanted to share with you today.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:13:32,000 --> 00:13:36,000
|
| 687 |
+
Let's recap what we have learned in the lesson.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:13:37,000 --> 00:13:41,000
|
| 691 |
+
In this lesson, we have learned how spring framework architecture looks like.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:13:41,000 --> 00:13:49,000
|
| 695 |
+
We learned what an inversion of control is and what a dependency injection is and how they are different.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:13:49,000 --> 00:13:56,000
|
| 699 |
+
We talked about inversion of control container in spring and reviewed key types that we are going to
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:13:56,000 --> 00:14:00,000
|
| 703 |
+
work with while interacting with Container in spring.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:01,000 --> 00:14:03,000
|
| 707 |
+
I explained to you what a spring context is.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:04,000 --> 00:14:11,000
|
| 711 |
+
Also, we have learned such important concepts as spring beans and reviewed spring beans scopes.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:14:11,000 --> 00:14:15,000
|
| 715 |
+
And at the end of the lesson we talked about spring expression language.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:14:15,000 --> 00:14:17,000
|
| 719 |
+
That's it for this lesson.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:18,000 --> 00:14:24,000
|
| 723 |
+
It is important you learn concepts from this lesson in order to be able to proceed with practical examples
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:14:24,000 --> 00:14:27,000
|
| 727 |
+
and understand them well.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:14:27,000 --> 00:14:29,000
|
| 731 |
+
Thanks a lot for your attention.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:14:29,000 --> 00:14:32,000
|
| 735 |
+
Have a great day and see you in the next lesson.
|
| 736 |
+
|
81 - Spring Core/003 IoC, Beans Configuration, XML and Annotations - Practice_en.srt
ADDED
|
@@ -0,0 +1,1584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:05,000 --> 00:00:06,000
|
| 3 |
+
Hello, team.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:06,000 --> 00:00:10,000
|
| 7 |
+
Today we're going to have a practical lesson about Sprint core.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:10,000 --> 00:00:16,000
|
| 11 |
+
It is important to you Watch the previous theoretical lesson about Spring Corps, because in this lesson
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:16,000 --> 00:00:21,000
|
| 15 |
+
we are going to use terms and concepts that we have learned in previous video.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:22,000 --> 00:00:28,000
|
| 19 |
+
Namely, we are going to talk about how to initialize and how to work with Spring build factory and
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:28,000 --> 00:00:30,000
|
| 23 |
+
spring application context.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:30,000 --> 00:00:35,000
|
| 27 |
+
I'm going to explain you more about IFC Containers in Spring.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:35,000 --> 00:00:40,000
|
| 31 |
+
Also, in this lesson, we are going to have practical exercises with spring bins.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:41,000 --> 00:00:45,000
|
| 35 |
+
We'll learn how to declare spring bins and how to configure them.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:45,000 --> 00:00:50,000
|
| 39 |
+
I'm going to show you both XML and annotation configuration.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:50,000 --> 00:00:53,000
|
| 43 |
+
We'll learn configuration specifics.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:53,000 --> 00:00:57,000
|
| 47 |
+
I will explain you the difference between D and Bin name.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:57,000 --> 00:01:06,000
|
| 51 |
+
Also, we'll talk about differences between such annotations as component service, controller and repository.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:06,000 --> 00:01:11,000
|
| 55 |
+
I will explain what is the purpose of qualifier annotation on real examples.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:11,000 --> 00:01:18,000
|
| 59 |
+
We are going to see how to configure bin scopes and what is the difference between being scopes and
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:18,000 --> 00:01:24,000
|
| 63 |
+
at the end of the lesson we are going to make a summary and compare advantages and disadvantages of
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:24,000 --> 00:01:27,000
|
| 67 |
+
XML and annotation based configuration.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:28,000 --> 00:01:29,000
|
| 71 |
+
Let's start our lesson.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:30,000 --> 00:01:34,000
|
| 75 |
+
And as I already said today, we're going to have practical lesson.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:34,000 --> 00:01:37,000
|
| 79 |
+
So let's start from the demo straightaway.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:37,000 --> 00:01:42,000
|
| 83 |
+
Before the lesson, I prepared source code examples in order to save your time.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:42,000 --> 00:01:47,000
|
| 87 |
+
You're watching the video and make sure that I didn't miss anything.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:47,000 --> 00:01:51,000
|
| 91 |
+
I'm going to walk you through the all the examples line by line.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:52,000 --> 00:01:58,000
|
| 95 |
+
You will find all source code examples from the lesson in attachments to the video and even in case
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:58,000 --> 00:02:00,000
|
| 99 |
+
some questions will laugh.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:00,000 --> 00:02:07,000
|
| 103 |
+
You are always welcome to ask your questions below the video and I will be happy to answer the first
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:07,000 --> 00:02:09,000
|
| 107 |
+
thing that we are going to do.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:09,000 --> 00:02:14,000
|
| 111 |
+
Let's create simple MAVEN project using Quick Start Archetype.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:14,000 --> 00:02:22,000
|
| 115 |
+
We're going to start from the simple project and after that gradually we'll turn it into a web project
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:22,000 --> 00:02:29,000
|
| 119 |
+
and once we'll learn all necessary things required for running and supporting the project, we are going
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:29,000 --> 00:02:33,000
|
| 123 |
+
to integrate Spring Framework into our online shop application.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:34,000 --> 00:02:40,000
|
| 127 |
+
In my course, Java from zero to first job together with my students, will create online shop from
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:40,000 --> 00:02:40,000
|
| 131 |
+
scratch.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:41,000 --> 00:02:48,000
|
| 135 |
+
And after learning of each new topic, we practice our skills by updating and improving our online shop.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:49,000 --> 00:02:54,000
|
| 139 |
+
This is going to be very interesting, but let's start small and become big.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:55,000 --> 00:03:01,000
|
| 143 |
+
In case you are not familiar with Maven, please refer to this section about automated build tools in
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:03:01,000 --> 00:03:02,000
|
| 147 |
+
my course.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:03:02,000 --> 00:03:04,000
|
| 151 |
+
Go from zero to first job.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:04,000 --> 00:03:08,000
|
| 155 |
+
By the way, if you wish, you can create a grad or project.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:09,000 --> 00:03:10,000
|
| 159 |
+
It is only up to you.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:10,000 --> 00:03:18,000
|
| 163 |
+
We'll put our focus on the learning of spring in this section of the course so you can use whatever
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:18,000 --> 00:03:22,000
|
| 167 |
+
automated build to you wish or even don't use any.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:22,000 --> 00:03:26,000
|
| 171 |
+
But I'm going to show you examples with MAVEN build tool.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:27,000 --> 00:03:31,000
|
| 175 |
+
After project is created, we need to add dependencies.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:31,000 --> 00:03:34,000
|
| 179 |
+
Let's add sprint core dependency.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:34,000 --> 00:03:36,000
|
| 183 |
+
Here it is in dependency section.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:37,000 --> 00:03:43,000
|
| 187 |
+
Also, let's add screwing beans, dependency and dependency for the sprint context.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:43,000 --> 00:03:49,000
|
| 191 |
+
All these dependencies are required for our practical exercises today.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:49,000 --> 00:03:55,000
|
| 195 |
+
And the important thing to mention here is that it is highly recommended that all sprint dependencies
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:55,000 --> 00:04:00,000
|
| 199 |
+
would have this same version to make sure that they're compatible with each other.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:04:00,000 --> 00:04:08,000
|
| 203 |
+
That's why I create a sprint version property in the main properties and use this variable just in case.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:08,000 --> 00:04:10,000
|
| 207 |
+
To not mess things up.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:11,000 --> 00:04:15,000
|
| 211 |
+
Now let's create simple class that is called user.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:15,000 --> 00:04:21,000
|
| 215 |
+
This is a simple project class that has first name, last name and email fields.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:22,000 --> 00:04:24,000
|
| 219 |
+
Getters and setters.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:24,000 --> 00:04:26,000
|
| 223 |
+
Default constructor and the string method.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:27,000 --> 00:04:27,000
|
| 227 |
+
That's it.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:28,000 --> 00:04:35,000
|
| 231 |
+
This class is going to be our spring bin and to consider it as a spring bin, we need to let spring
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:35,000 --> 00:04:38,000
|
| 235 |
+
context to manage its lifecycle.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:38,000 --> 00:04:41,000
|
| 239 |
+
Let's configure this in spring.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:41,000 --> 00:04:45,000
|
| 243 |
+
We have two ways of how we can handle our configurations.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:04:45,000 --> 00:04:49,000
|
| 247 |
+
The first way is to handle configurations in the XML file.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:04:50,000 --> 00:04:54,000
|
| 251 |
+
The second option is to handle configurations with the annotations.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:04:54,000 --> 00:05:01,000
|
| 255 |
+
During the course, I'm going to show you both options and we are going to discuss pros and cons of
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:01,000 --> 00:05:02,000
|
| 259 |
+
each approach.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:02,000 --> 00:05:08,000
|
| 263 |
+
Let me start from showing how we can configure our spring bins with the XML file.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:08,000 --> 00:05:11,000
|
| 267 |
+
Let's create application Context XML file.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:12,000 --> 00:05:18,000
|
| 271 |
+
Technically speaking, you can put it wherever you want in the class pass, but in case this will be
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:18,000 --> 00:05:25,000
|
| 275 |
+
our web application for security reasons, it is recommended to make it not accessible from the web.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:25,000 --> 00:05:30,000
|
| 279 |
+
But anyway, one will come for configuration of the web application.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:30,000 --> 00:05:34,000
|
| 283 |
+
I'm going to remind you this so far.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:34,000 --> 00:05:39,000
|
| 287 |
+
I put application context XML file into resources source folder.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:39,000 --> 00:05:40,000
|
| 291 |
+
Let's check.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:05:40,000 --> 00:05:42,000
|
| 295 |
+
What do we have here inside?
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:05:43,000 --> 00:05:47,000
|
| 299 |
+
We have ex Loco law and XML schema validation here.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:05:48,000 --> 00:05:51,000
|
| 303 |
+
You don't need to learn these values by heart.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:05:51,000 --> 00:05:53,000
|
| 307 |
+
You can easily find them in the internet.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:05:54,000 --> 00:06:00,000
|
| 311 |
+
If you are familiar with the XML format, then you can understand what an XML namespace is.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:00,000 --> 00:06:02,000
|
| 315 |
+
An XML schema definition.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:03,000 --> 00:06:10,000
|
| 319 |
+
The main thing here with regards to screen configuration is that the file has a single root element
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:10,000 --> 00:06:12,000
|
| 323 |
+
is it is called beans.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:12,000 --> 00:06:17,000
|
| 327 |
+
And inside this element we can declare multiple bean elements.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:17,000 --> 00:06:21,000
|
| 331 |
+
For example, like you can see here, I created user bean.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:22,000 --> 00:06:27,000
|
| 335 |
+
Each bean has ID that can be used when we need to refer to some bean.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:06:28,000 --> 00:06:34,000
|
| 339 |
+
I can use bean name for identification purposes to and use it instead of ID.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:06:35,000 --> 00:06:43,000
|
| 343 |
+
The only difference between an ID and the name is that a name can contain multiple aliases separated
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:06:43,000 --> 00:06:50,000
|
| 347 |
+
by a comma, semicolon or whitespace, whereas an ID must be a single value.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:06:51,000 --> 00:06:56,000
|
| 351 |
+
Also, we need to specify full class name, and that's what I did here.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:06:57,000 --> 00:07:00,000
|
| 355 |
+
I specified properties and past string values.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:01,000 --> 00:07:04,000
|
| 359 |
+
I injected string values into my bin.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:04,000 --> 00:07:08,000
|
| 363 |
+
Let me open Demo bin Factory ISC class now.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:09,000 --> 00:07:11,000
|
| 367 |
+
I opened them a bin factory.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:11,000 --> 00:07:13,000
|
| 371 |
+
I see class and run.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:14,000 --> 00:07:19,000
|
| 375 |
+
I'm going to walk you through the console output and explain what is happening here.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:20,000 --> 00:07:25,000
|
| 379 |
+
As we will keep learning in spring, I recommend you to learn spring by reviewing the spring source
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:07:25,000 --> 00:07:26,000
|
| 383 |
+
code.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:07:26,000 --> 00:07:33,000
|
| 387 |
+
Because for example, in many video courses, even today and in many online articles, since the internet
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:07:33,000 --> 00:07:39,000
|
| 391 |
+
tutors just copy content from each other without diving deeper into the details.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:07:39,000 --> 00:07:47,000
|
| 395 |
+
So I just wanted to say that X Factor class is deprecated already and it is recommended to use default
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:07:47,000 --> 00:07:53,000
|
| 399 |
+
list will be in factory and XML definition reader class instead.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:07:53,000 --> 00:07:57,000
|
| 403 |
+
It has a little bit different API, but I am going to show it now.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:07:58,000 --> 00:08:02,000
|
| 407 |
+
We create object of default list being factory at the beginning.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:03,000 --> 00:08:09,000
|
| 411 |
+
This is in general bin factory object that is in charge of generating bins.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:09,000 --> 00:08:14,000
|
| 415 |
+
After that we create object of XML bin definition reader.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:14,000 --> 00:08:18,000
|
| 419 |
+
This object will read our XML build definitions.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:18,000 --> 00:08:21,000
|
| 423 |
+
I paused the reference to the bin factory to.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:08:22,000 --> 00:08:26,000
|
| 427 |
+
Then we create a resource of our XML configuration.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:08:27,000 --> 00:08:32,000
|
| 431 |
+
I use class POS resource and parse the name of our configuration file.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:08:33,000 --> 00:08:40,000
|
| 435 |
+
The next important thing that I do here I call massive load definitions on my excellent build definition
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:08:40,000 --> 00:08:47,000
|
| 439 |
+
reader, and once the definitions are read, I can use bin factory to instantiate our bins.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:08:48,000 --> 00:08:55,000
|
| 443 |
+
I call get bin method on my bin factory object pass ID of my bin and class.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:08:55,000 --> 00:09:04,000
|
| 447 |
+
After that I print user to console and you can see that user has all fields initialized like we configured
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:04,000 --> 00:09:05,000
|
| 451 |
+
in our configuration file.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:06,000 --> 00:09:12,000
|
| 455 |
+
Now let me try to instantiate the bit based on the name that I gave to.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:13,000 --> 00:09:21,000
|
| 459 |
+
And as you can see in the console, I managed to get my beam not by IGI, but by the names that I specified
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:21,000 --> 00:09:22,000
|
| 463 |
+
in the configuration.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:22,000 --> 00:09:25,000
|
| 467 |
+
This is just a useful thing to remember.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:09:26,000 --> 00:09:30,000
|
| 471 |
+
The remember from previous lesson would be scopes are.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:09:30,000 --> 00:09:32,000
|
| 475 |
+
And what is the default scope of beings?
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:09:33,000 --> 00:09:38,000
|
| 479 |
+
Just to remind you, the scopes refers to the lifecycle of being.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:09:38,000 --> 00:09:45,000
|
| 483 |
+
That means when the object of being will be instantiated, how long does that object leave and how many
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:09:45,000 --> 00:09:51,000
|
| 487 |
+
objects will be created for that to be throughout the default scope is singleton.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:09:52,000 --> 00:09:58,000
|
| 491 |
+
That means that only one instance of the user being exists in the container at the moment.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:09:58,000 --> 00:10:05,000
|
| 495 |
+
Thus, these two references are pointing out to the same object in the memory.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:05,000 --> 00:10:08,000
|
| 499 |
+
We can check it by comparing the links.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:09,000 --> 00:10:16,000
|
| 503 |
+
The fact that we receive truth here proves that these two references are pointing out to the same object
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:16,000 --> 00:10:17,000
|
| 507 |
+
in the memory.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:18,000 --> 00:10:19,000
|
| 511 |
+
Is it clear?
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:19,000 --> 00:10:26,000
|
| 515 |
+
In case you have any questions, please do not hesitate to ask your questions in comments to the video.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:26,000 --> 00:10:29,000
|
| 519 |
+
We saw a simple example was Bean Factory.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:10:30,000 --> 00:10:35,000
|
| 523 |
+
Let's now take a look at the example with application context and understand the difference.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:10:36,000 --> 00:10:39,000
|
| 527 |
+
I open the next A file that is called Demo.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:10:39,000 --> 00:10:41,000
|
| 531 |
+
Application Context IOC.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:10:42,000 --> 00:10:50,000
|
| 535 |
+
Technically speaking, we can say the spring framework comes with two sea containers bin factory and
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:10:50,000 --> 00:10:52,000
|
| 539 |
+
application context.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:10:52,000 --> 00:10:59,000
|
| 543 |
+
The Big Factory is the most basic version of ICI containers, and the application context extends the
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:10:59,000 --> 00:11:01,000
|
| 547 |
+
features of a factory.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:02,000 --> 00:11:10,000
|
| 551 |
+
One of the differences between these two ISC containers is that bin factory loads bins on demand while
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:10,000 --> 00:11:14,000
|
| 555 |
+
application context across all beans at startup.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:14,000 --> 00:11:19,000
|
| 559 |
+
Thus being factory is lightweight as compared to application context.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:20,000 --> 00:11:28,000
|
| 563 |
+
Application context enhances bean factory in a more framework oriented style and provides several features
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:28,000 --> 00:11:31,000
|
| 567 |
+
that are suitable for enterprise applications.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:11:31,000 --> 00:11:39,000
|
| 571 |
+
For example, it provides messaging, internationalization, functionality, event publication, functionality,
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:11:39,000 --> 00:11:46,000
|
| 575 |
+
annotation based dependency injection, and easy integration with spring AOP features.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:11:46,000 --> 00:11:55,000
|
| 579 |
+
Apart from this, the application context supports all types of scopes, but the bean factory only supports
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:11:55,000 --> 00:11:57,000
|
| 583 |
+
two scopes single tone and prototype.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:11:58,000 --> 00:12:05,000
|
| 587 |
+
Therefore, it's always preferable to use application context 1 billion complex enterprise applications.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:05,000 --> 00:12:08,000
|
| 591 |
+
So what do we have here now?
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:08,000 --> 00:12:16,000
|
| 595 |
+
Example I create a reference of type application context and initialize it with object of class pos
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:16,000 --> 00:12:18,000
|
| 599 |
+
XML application context.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:12:18,000 --> 00:12:25,000
|
| 603 |
+
I pause the name of my configuration file into the constructor and after having the reference to the
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:12:25,000 --> 00:12:30,000
|
| 607 |
+
context object, I can just call Massive Get bin and that's it.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:12:31,000 --> 00:12:39,000
|
| 611 |
+
In a similar way I can get bin is a by ID or by name and you can see that both references are pointing
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:12:39,000 --> 00:12:42,000
|
| 615 |
+
out to the same object as a heap memory.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:12:43,000 --> 00:12:50,000
|
| 619 |
+
You can see that instantiating offspring application context to us, less lines of codes in comparing
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:12:50,000 --> 00:12:52,000
|
| 623 |
+
to being factory.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:12:52,000 --> 00:13:01,000
|
| 627 |
+
So in summary, being factory is okay for testing and non-production use, but application context is
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:01,000 --> 00:13:08,000
|
| 631 |
+
more feature which contain the implementation and should be favored over being factor and in general
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:08,000 --> 00:13:12,000
|
| 635 |
+
using of application context suits for most cases.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:13,000 --> 00:13:16,000
|
| 639 |
+
We saw how to configure beans with eczema.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:16,000 --> 00:13:21,000
|
| 643 |
+
Now let's take a look at annotation based configuration.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:13:21,000 --> 00:13:26,000
|
| 647 |
+
We have different bean naming strategies and I'm going to show you some.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:13:27,000 --> 00:13:31,000
|
| 651 |
+
We can use annotations for the bean configuration at different levels.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:13:32,000 --> 00:13:35,000
|
| 655 |
+
Let's review first class level annotations.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:13:36,000 --> 00:13:42,000
|
| 659 |
+
We can use component controller service or repository annotation.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:13:42,000 --> 00:13:45,000
|
| 663 |
+
What is the difference between these annotations?
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:13:45,000 --> 00:13:50,000
|
| 667 |
+
By using different annotations, we can achieve two goals simultaneously.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:13:51,000 --> 00:13:59,000
|
| 671 |
+
The first one will mark types as spring beans and will enable them for auto detection during the components
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:13:59,000 --> 00:14:00,000
|
| 675 |
+
can.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:00,000 --> 00:14:09,000
|
| 679 |
+
And the second thing we will be able to add component specific behavior component is a generic stereotype
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:09,000 --> 00:14:12,000
|
| 683 |
+
for any spring managed component or bean.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:12,000 --> 00:14:20,000
|
| 687 |
+
When I open any other annotations from already mentioned, you can see that service is a component too,
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:20,000 --> 00:14:23,000
|
| 691 |
+
and the controller is also a component.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:14:23,000 --> 00:14:27,000
|
| 695 |
+
So component is the most generic annotation.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:14:28,000 --> 00:14:28,000
|
| 699 |
+
Service.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:14:28,000 --> 00:14:32,000
|
| 703 |
+
Sanitation is a stereotype for the service layer.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:14:33,000 --> 00:14:38,000
|
| 707 |
+
In our online shop, we have a business layer that contains different services.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:14:38,000 --> 00:14:47,000
|
| 711 |
+
Unfortunately, I can't show all possible examples at once in one single lesson, but I will show you
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:14:47,000 --> 00:14:49,000
|
| 715 |
+
all examples during the course grade.
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:14:50,000 --> 00:14:55,000
|
| 719 |
+
For now, I want you just to be aware about different annotations.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:14:56,000 --> 00:15:01,000
|
| 723 |
+
Controller is a stereotype for controller structural element according to NBC.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:01,000 --> 00:15:02,000
|
| 727 |
+
Pardon.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:02,000 --> 00:15:10,000
|
| 731 |
+
In spring MVC and my course go from zero to first job we have learned and we see architectural portal
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:11,000 --> 00:15:17,000
|
| 735 |
+
controller annotation is for controller objects is a model view controller architecture.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:15:17,000 --> 00:15:21,000
|
| 739 |
+
Also specific content rules are applied for controllers.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:15:22,000 --> 00:15:30,000
|
| 743 |
+
For example dispatcher server that will look for request on classes which are annotated using controller
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:15:30,000 --> 00:15:33,000
|
| 747 |
+
but not with component annotation.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:15:33,000 --> 00:15:40,000
|
| 751 |
+
What a dispatcher servlet is and what the request mapping is, We'll discuss in a separate lesson for
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:15:40,000 --> 00:15:41,000
|
| 755 |
+
sure.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:15:41,000 --> 00:15:43,000
|
| 759 |
+
One will come to one of spring.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:15:43,000 --> 00:15:44,000
|
| 763 |
+
Can we see?
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:15:44,000 --> 00:15:45,000
|
| 767 |
+
We'll get back to this.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:15:45,000 --> 00:15:51,000
|
| 771 |
+
Annotation repository is a stereotype for persistence layer.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:15:51,000 --> 00:15:58,000
|
| 775 |
+
For example, we can use this annotation to mark our dog classes as spring beans, for example.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:15:58,000 --> 00:16:02,000
|
| 779 |
+
Is it clear all of them are used to order the tags?
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:02,000 --> 00:16:03,000
|
| 783 |
+
Spring beans.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:16:03,000 --> 00:16:10,000
|
| 787 |
+
One context canon is enabled and essentially provides the same functionality with respect to dependency
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:16:10,000 --> 00:16:11,000
|
| 791 |
+
injection.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:16:12,000 --> 00:16:16,000
|
| 795 |
+
The repository also adds component specific behavior.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:16:16,000 --> 00:16:23,000
|
| 799 |
+
For example, repository annotation is not only helping in annotation based configuration, but also
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:16:23,000 --> 00:16:31,000
|
| 803 |
+
catches platform specific exceptions and throws them as one of the springs unified unchecked exception.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:16:31,000 --> 00:16:38,000
|
| 807 |
+
Just to remind you, they're not shy to ask your questions below the video and I will be happy to answer.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:16:38,000 --> 00:16:46,000
|
| 811 |
+
So here I have user two plus because we already have user and I need to show you different similar examples
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:16:46,000 --> 00:16:49,000
|
| 815 |
+
in order it would be easier to compare them.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:16:50,000 --> 00:16:57,000
|
| 819 |
+
In the component annotation, I can specify component name, but even without specifying component name,
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:16:57,000 --> 00:17:04,000
|
| 823 |
+
spring will use class name with the first character lowercase as a spring bean name.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:17:04,000 --> 00:17:12,000
|
| 827 |
+
In this particular case, the default name would be user to start from the lowercase, but I want to
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:17:12,000 --> 00:17:15,000
|
| 831 |
+
use user as a name for this component.
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:16,000 --> 00:17:20,000
|
| 835 |
+
Let me show you now how we can instantiate this bin.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:17:20,000 --> 00:17:25,000
|
| 839 |
+
I open the class to the scope demo application context annotations.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:17:25,000 --> 00:17:30,000
|
| 843 |
+
We will instantiate object of annotation config application context.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:17:31,000 --> 00:17:39,000
|
| 847 |
+
After that we'll call scan method and we'll pass the base package from where to start scanning.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:17:40,000 --> 00:17:47,000
|
| 851 |
+
Spring will look types marked with annotations component, but it would also find all types marked with
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:17:47,000 --> 00:17:55,000
|
| 855 |
+
service controller or repository annotations, because as you already saw, those annotations are marked
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:17:55,000 --> 00:17:58,000
|
| 859 |
+
with component annotations too.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:17:58,000 --> 00:18:06,000
|
| 863 |
+
After holding a scanning, I need to call refresh message on the context object and after that I extract
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:18:06,000 --> 00:18:08,000
|
| 867 |
+
my been its name.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:18:08,000 --> 00:18:10,000
|
| 871 |
+
It is relatively simple.
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:18:10,000 --> 00:18:11,000
|
| 875 |
+
Do you agree?
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:18:12,000 --> 00:18:18,000
|
| 879 |
+
The next thing that I would like to show you is massive level annotations for configuration of spring
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:18:18,000 --> 00:18:19,000
|
| 883 |
+
bins.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:18:20,000 --> 00:18:23,000
|
| 887 |
+
I open Klaus is it is called beans configuration.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:18:24,000 --> 00:18:26,000
|
| 891 |
+
On top of the class name.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:18:26,000 --> 00:18:28,000
|
| 895 |
+
I have annotation configuration.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:18:29,000 --> 00:18:37,000
|
| 899 |
+
In this class I can have multiple masses marked with bin annotation and inside the mascot I can configure
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:18:37,000 --> 00:18:39,000
|
| 903 |
+
the bin object that I need.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:18:39,000 --> 00:18:42,000
|
| 907 |
+
The advantage of such approach is obvious.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:18:42,000 --> 00:18:49,000
|
| 911 |
+
You can configure bin with java code as you need call all necessary and required methods.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:18:50,000 --> 00:18:55,000
|
| 915 |
+
When we use bin annotation, Spring will use massive names as being names.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:18:56,000 --> 00:19:04,000
|
| 919 |
+
So this is the case when you're allowed to violate naming convention for masses and use noun instead
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:19:04,000 --> 00:19:05,000
|
| 923 |
+
of verb.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:19:05,000 --> 00:19:11,000
|
| 927 |
+
For method name, I will use user to name because we already have user being in the context.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:19:12,000 --> 00:19:18,000
|
| 931 |
+
Also, you can set the bin name in the annotation and default bin names.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:19:18,000 --> 00:19:21,000
|
| 935 |
+
It is equal to the method name will be overwritten.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:19:22,000 --> 00:19:26,000
|
| 939 |
+
Just look at this example like I did here with custom user.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:19:27,000 --> 00:19:31,000
|
| 943 |
+
Let me get back to the application context annotations clause.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:19:32,000 --> 00:19:40,000
|
| 947 |
+
And you can see here that I request been from the context I requested user to and custom user in the
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:19:40,000 --> 00:19:41,000
|
| 951 |
+
console.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:19:41,000 --> 00:19:48,000
|
| 955 |
+
You can see that I receive beans that I have configured because I set different first name and last
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:19:48,000 --> 00:19:48,000
|
| 959 |
+
name.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:19:49,000 --> 00:19:55,000
|
| 963 |
+
And here I can see first name and last name that I sat in these beans ever since.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:19:55,000 --> 00:19:56,000
|
| 967 |
+
Clear so far.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:19:57,000 --> 00:19:58,000
|
| 971 |
+
Okay, let's proceed.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:19:59,000 --> 00:20:05,000
|
| 975 |
+
Let me now explain to you how word for annotation works, and it is better to do an example.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:20:06,000 --> 00:20:09,000
|
| 979 |
+
Imagine that we have some interface.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:20:09,000 --> 00:20:18,000
|
| 983 |
+
For example, we have product interface, and product interface has two implementations, master product
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:20:18,000 --> 00:20:20,000
|
| 987 |
+
and variant product.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:20:20,000 --> 00:20:25,000
|
| 991 |
+
Master product is just a regular product and variant product.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:20:25,000 --> 00:20:27,000
|
| 995 |
+
It is like boots.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:20:27,000 --> 00:20:33,000
|
| 999 |
+
We have one model of boots, but actually there are different sizes and different colors of the same
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:20:33,000 --> 00:20:37,000
|
| 1003 |
+
boots and they are variants anyway.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:20:37,000 --> 00:20:40,000
|
| 1007 |
+
The business logic is not critical at the moment.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:20:40,000 --> 00:20:47,000
|
| 1011 |
+
The main thing is that you have one type, for example, some interface and two different implementations,
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:20:48,000 --> 00:20:56,000
|
| 1015 |
+
and I use component annotation to mark these types as spring bins and I use qualifier annotation in
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:20:56,000 --> 00:20:57,000
|
| 1019 |
+
two types.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:20:58,000 --> 00:21:05,000
|
| 1023 |
+
In the demo clause, you can see example that I can get been also uses the name given in the qualifier
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:21:05,000 --> 00:21:06,000
|
| 1027 |
+
annotation.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:21:07,000 --> 00:21:14,000
|
| 1031 |
+
But another goal of using color for annotation is to eliminate the issue of which build needs to be
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:21:14,000 --> 00:21:15,000
|
| 1035 |
+
injected.
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:21:16,000 --> 00:21:18,000
|
| 1039 |
+
Let me show you another example.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:21:18,000 --> 00:21:23,000
|
| 1043 |
+
Imagine that we have another class that is called Special Offer.
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:21:23,000 --> 00:21:26,000
|
| 1047 |
+
And again, guys, this is just examples.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:21:26,000 --> 00:21:33,000
|
| 1051 |
+
Try to put aside all possible details of the business logic at the moment and try to understand the
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:21:33,000 --> 00:21:36,000
|
| 1055 |
+
technical details of implementation.
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:21:36,000 --> 00:21:46,000
|
| 1059 |
+
So you have some class where you need to inject two different beams of the same type or other way around.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:21:46,000 --> 00:21:51,000
|
| 1063 |
+
You have different classes where you need to use different beams of the same type.
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:21:52,000 --> 00:21:59,000
|
| 1067 |
+
In both cases you have different beams of the same type in your content and you need to distinguish
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:21:59,000 --> 00:22:00,000
|
| 1071 |
+
them.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:22:00,000 --> 00:22:08,000
|
| 1075 |
+
That's why to inject the specific strain that you need, you can use names specified by the qualifier
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:22:08,000 --> 00:22:10,000
|
| 1079 |
+
here in the special offer class.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:22:10,000 --> 00:22:16,000
|
| 1083 |
+
You can see that I used constructor injection with the qualifier annotation.
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:22:16,000 --> 00:22:25,000
|
| 1087 |
+
Yes, this is magic of spring and that's actually how injection may be configured with annotations while
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:22:25,000 --> 00:22:27,000
|
| 1091 |
+
configuring unzipping.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:22:27,000 --> 00:22:34,000
|
| 1095 |
+
You can ask sprint container to provide you with a necessary beam to construct the object and spring
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:22:34,000 --> 00:22:41,000
|
| 1099 |
+
container will manage all the dependencies and sequence of initialization in order to construct objects
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:22:41,000 --> 00:22:42,000
|
| 1103 |
+
that you need.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:22:43,000 --> 00:22:47,000
|
| 1107 |
+
Let's get back to the demo application Context annotation class.
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:22:48,000 --> 00:22:56,000
|
| 1111 |
+
I get the feel of the special offer and I verify that the beans of master product and variant product
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:22:56,000 --> 00:23:00,000
|
| 1115 |
+
were successfully injected into the special offer bin.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:23:01,000 --> 00:23:08,000
|
| 1119 |
+
Because I didn't receive no parental exception and I received plus names that I expected to get.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:23:08,000 --> 00:23:15,000
|
| 1123 |
+
That means that container created beans of my products and injected them into the special offer.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:23:15,000 --> 00:23:21,000
|
| 1127 |
+
Being even despite special offer has two properties of the same type.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:23:21,000 --> 00:23:26,000
|
| 1131 |
+
I managed to inject different beads with the same parent type.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:23:27,000 --> 00:23:29,000
|
| 1135 |
+
That's why qualifier annotation is needed.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:23:30,000 --> 00:23:31,000
|
| 1139 |
+
Isn't this cool?
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:23:32,000 --> 00:23:37,000
|
| 1143 |
+
That's how you can manage dependencies between the objects using configurations.
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:23:37,000 --> 00:23:41,000
|
| 1147 |
+
So I can say that we are done with none in all possible ways.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:23:41,000 --> 00:23:43,000
|
| 1151 |
+
How you can declare spring bins.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:23:43,000 --> 00:23:46,000
|
| 1155 |
+
These are just first steps of learning spring.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:23:47,000 --> 00:23:51,000
|
| 1159 |
+
This is the basement that we need to have to move further.
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:23:51,000 --> 00:23:59,000
|
| 1163 |
+
Probably right now you can't imagine why we need this and how we are going to use all this.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:23:59,000 --> 00:24:03,000
|
| 1167 |
+
But just believe me, you will understand the big picture very, very soon.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:24:04,000 --> 00:24:11,000
|
| 1171 |
+
We're just learning alphabet at the moment and a little bit later will start building words and sentences
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:24:11,000 --> 00:24:12,000
|
| 1175 |
+
with the spring.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:24:13,000 --> 00:24:15,000
|
| 1179 |
+
Hope you understood my analogy.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:24:16,000 --> 00:24:17,000
|
| 1183 |
+
Let's move on.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:24:17,000 --> 00:24:23,000
|
| 1187 |
+
Example was a special offer, was an example of sprint dependency injection.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:24:23,000 --> 00:24:28,000
|
| 1191 |
+
We are going to have a separate practical lesson dedicated to sprint injection.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:24:28,000 --> 00:24:34,000
|
| 1195 |
+
I just wanted to show you the purpose of the qualifier annotation because spring dependency injection
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:24:34,000 --> 00:24:36,000
|
| 1199 |
+
is a separate big topic to talk about.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:24:37,000 --> 00:24:40,000
|
| 1203 |
+
Stay tuned and we'll discuss it in another lesson.
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:24:41,000 --> 00:24:45,000
|
| 1207 |
+
The only thing that we still need to talk about is being scopes.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:24:46,000 --> 00:24:50,000
|
| 1211 |
+
What pre-defined scopes we have in the spring and how is different?
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:24:50,000 --> 00:24:56,000
|
| 1215 |
+
We have discussed in the previous lesson, just to remind you what scopes exist.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:24:56,000 --> 00:25:03,000
|
| 1219 |
+
So your prototype, request session, application and web socket.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:25:04,000 --> 00:25:11,000
|
| 1223 |
+
Whereas this can be configured if we use XML configuration, we can use scope attribute of bin element
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:25:11,000 --> 00:25:13,000
|
| 1227 |
+
to specify scope.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:25:13,000 --> 00:25:22,000
|
| 1231 |
+
Let me open application context in XML file here you can see that I created B with ID user prototype
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:25:22,000 --> 00:25:28,000
|
| 1235 |
+
and it has scope attributes that is equal to prototype instead of prototype.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:25:28,000 --> 00:25:31,000
|
| 1239 |
+
You can use any other scope that you would like to use.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:25:32,000 --> 00:25:37,000
|
| 1243 |
+
Let me now open Demo Bean Scopes class and show you how prototype scope works.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:25:38,000 --> 00:25:42,000
|
| 1247 |
+
I will run this program and we'll walk you through the code example here.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:25:43,000 --> 00:25:48,000
|
| 1251 |
+
I create class, pass XML application context and I request user.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:25:49,000 --> 00:25:50,000
|
| 1255 |
+
Two times in a row.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:25:51,000 --> 00:25:55,000
|
| 1259 |
+
Just to remind you, the default bean scope is singleton.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:25:55,000 --> 00:26:04,000
|
| 1263 |
+
After that, I compare user one and user to references, and as you can see in console the equal, that
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:26:04,000 --> 00:26:10,000
|
| 1267 |
+
means that these two references are pointing out to the same object as a heap memory.
|
| 1268 |
+
|
| 1269 |
+
318
|
| 1270 |
+
00:26:11,000 --> 00:26:17,000
|
| 1271 |
+
And when I request two times in a row user prototype being that we can figure it with the prototype
|
| 1272 |
+
|
| 1273 |
+
319
|
| 1274 |
+
00:26:17,000 --> 00:26:23,000
|
| 1275 |
+
scope, I actually receive two different objects because that's how prototype scope works.
|
| 1276 |
+
|
| 1277 |
+
320
|
| 1278 |
+
00:26:24,000 --> 00:26:24,000
|
| 1279 |
+
It returns.
|
| 1280 |
+
|
| 1281 |
+
321
|
| 1282 |
+
00:26:24,000 --> 00:26:27,000
|
| 1283 |
+
You view objects of the same bean.
|
| 1284 |
+
|
| 1285 |
+
322
|
| 1286 |
+
00:26:27,000 --> 00:26:35,000
|
| 1287 |
+
And when I compare user three and user for references, we can see that these two references are pointing
|
| 1288 |
+
|
| 1289 |
+
323
|
| 1290 |
+
00:26:35,000 --> 00:26:37,000
|
| 1291 |
+
out to the different objects.
|
| 1292 |
+
|
| 1293 |
+
324
|
| 1294 |
+
00:26:37,000 --> 00:26:38,000
|
| 1295 |
+
Is it clear?
|
| 1296 |
+
|
| 1297 |
+
325
|
| 1298 |
+
00:26:39,000 --> 00:26:45,000
|
| 1299 |
+
In case you want to recall what other scopes are about, please refer to the previous lesson where I
|
| 1300 |
+
|
| 1301 |
+
326
|
| 1302 |
+
00:26:45,000 --> 00:26:48,000
|
| 1303 |
+
explained in the details how bean scopes are different.
|
| 1304 |
+
|
| 1305 |
+
327
|
| 1306 |
+
00:26:49,000 --> 00:26:54,000
|
| 1307 |
+
In this lesson we are focusing only on the practical part of the implementation.
|
| 1308 |
+
|
| 1309 |
+
328
|
| 1310 |
+
00:26:55,000 --> 00:27:01,000
|
| 1311 |
+
And in case we need to configure scopes with the annotations, we just need to use scope annotation
|
| 1312 |
+
|
| 1313 |
+
329
|
| 1314 |
+
00:27:02,000 --> 00:27:04,000
|
| 1315 |
+
like you see in the user three class.
|
| 1316 |
+
|
| 1317 |
+
330
|
| 1318 |
+
00:27:05,000 --> 00:27:10,000
|
| 1319 |
+
Here you can see that I used scope annotation to configure prototype scope.
|
| 1320 |
+
|
| 1321 |
+
331
|
| 1322 |
+
00:27:11,000 --> 00:27:15,000
|
| 1323 |
+
Let me open now Demo Bin Scopes Annotations Class.
|
| 1324 |
+
|
| 1325 |
+
332
|
| 1326 |
+
00:27:16,000 --> 00:27:22,000
|
| 1327 |
+
Here we have similar example, but just with annotation, config application context and with all the
|
| 1328 |
+
|
| 1329 |
+
333
|
| 1330 |
+
00:27:22,000 --> 00:27:23,000
|
| 1331 |
+
bins.
|
| 1332 |
+
|
| 1333 |
+
334
|
| 1334 |
+
00:27:23,000 --> 00:27:25,000
|
| 1335 |
+
But the example is similar.
|
| 1336 |
+
|
| 1337 |
+
335
|
| 1338 |
+
00:27:25,000 --> 00:27:30,000
|
| 1339 |
+
You can see that the new objects are created for beam with the prototype scope.
|
| 1340 |
+
|
| 1341 |
+
336
|
| 1342 |
+
00:27:30,000 --> 00:27:33,000
|
| 1343 |
+
Each time we call get bin message.
|
| 1344 |
+
|
| 1345 |
+
337
|
| 1346 |
+
00:27:34,000 --> 00:27:39,000
|
| 1347 |
+
I encourage you to download this source code examples and run them on your computer.
|
| 1348 |
+
|
| 1349 |
+
338
|
| 1350 |
+
00:27:40,000 --> 00:27:43,000
|
| 1351 |
+
This will help you to understand the code better.
|
| 1352 |
+
|
| 1353 |
+
339
|
| 1354 |
+
00:27:44,000 --> 00:27:50,000
|
| 1355 |
+
Try to change scopes and play with the code to get better understanding of the topic.
|
| 1356 |
+
|
| 1357 |
+
340
|
| 1358 |
+
00:27:50,000 --> 00:27:57,000
|
| 1359 |
+
And the last but not least, things that I'd like to discuss with you today is a comparison of XML and
|
| 1360 |
+
|
| 1361 |
+
341
|
| 1362 |
+
00:27:57,000 --> 00:27:59,000
|
| 1363 |
+
annotation based configuration.
|
| 1364 |
+
|
| 1365 |
+
342
|
| 1366 |
+
00:28:00,000 --> 00:28:07,000
|
| 1367 |
+
During the video you saw already some basic examples and you have understanding what is the difference
|
| 1368 |
+
|
| 1369 |
+
343
|
| 1370 |
+
00:28:07,000 --> 00:28:09,000
|
| 1371 |
+
between these two types of configuration?
|
| 1372 |
+
|
| 1373 |
+
344
|
| 1374 |
+
00:28:10,000 --> 00:28:15,000
|
| 1375 |
+
Let's just understand the advantages and disadvantages of each approach.
|
| 1376 |
+
|
| 1377 |
+
345
|
| 1378 |
+
00:28:15,000 --> 00:28:20,000
|
| 1379 |
+
Advantage of one approach are disadvantages of another approach and vice versa.
|
| 1380 |
+
|
| 1381 |
+
346
|
| 1382 |
+
00:28:21,000 --> 00:28:23,000
|
| 1383 |
+
Advantages of annotations.
|
| 1384 |
+
|
| 1385 |
+
347
|
| 1386 |
+
00:28:24,000 --> 00:28:30,000
|
| 1387 |
+
The first advantage also information related to the bin is in a single file.
|
| 1388 |
+
|
| 1389 |
+
348
|
| 1390 |
+
00:28:31,000 --> 00:28:35,000
|
| 1391 |
+
You can see both configuration and the source code.
|
| 1392 |
+
|
| 1393 |
+
349
|
| 1394 |
+
00:28:35,000 --> 00:28:41,000
|
| 1395 |
+
There is no need to check XML file for configuration and after that check the source code.
|
| 1396 |
+
|
| 1397 |
+
350
|
| 1398 |
+
00:28:41,000 --> 00:28:46,000
|
| 1399 |
+
This can save some time and may look like simpler approach.
|
| 1400 |
+
|
| 1401 |
+
351
|
| 1402 |
+
00:28:47,000 --> 00:28:53,000
|
| 1403 |
+
The second advantage when you change the class, there is no need to modify the XML file.
|
| 1404 |
+
|
| 1405 |
+
352
|
| 1406 |
+
00:28:53,000 --> 00:28:56,000
|
| 1407 |
+
Thus you have only one file to update.
|
| 1408 |
+
|
| 1409 |
+
353
|
| 1410 |
+
00:28:56,000 --> 00:29:01,000
|
| 1411 |
+
Instead of verifying consistency between the source code and configuration.
|
| 1412 |
+
|
| 1413 |
+
354
|
| 1414 |
+
00:29:02,000 --> 00:29:06,000
|
| 1415 |
+
Disadvantages of annotation base configuration.
|
| 1416 |
+
|
| 1417 |
+
355
|
| 1418 |
+
00:29:07,000 --> 00:29:13,000
|
| 1419 |
+
You mix up source code and configuration, which is not good from the separation of concerns point of
|
| 1420 |
+
|
| 1421 |
+
356
|
| 1422 |
+
00:29:13,000 --> 00:29:13,000
|
| 1423 |
+
view.
|
| 1424 |
+
|
| 1425 |
+
357
|
| 1426 |
+
00:29:14,000 --> 00:29:19,000
|
| 1427 |
+
Nowadays it is a matter of style rather than strict requirement.
|
| 1428 |
+
|
| 1429 |
+
358
|
| 1430 |
+
00:29:19,000 --> 00:29:25,000
|
| 1431 |
+
But some engineers prefer to keep configurations separately from the compiled source code.
|
| 1432 |
+
|
| 1433 |
+
359
|
| 1434 |
+
00:29:26,000 --> 00:29:30,000
|
| 1435 |
+
Advantages of XML file is the first advantage.
|
| 1436 |
+
|
| 1437 |
+
360
|
| 1438 |
+
00:29:31,000 --> 00:29:34,000
|
| 1439 |
+
The separation between the module and its behavior.
|
| 1440 |
+
|
| 1441 |
+
361
|
| 1442 |
+
00:29:35,000 --> 00:29:37,000
|
| 1443 |
+
The second advantage.
|
| 1444 |
+
|
| 1445 |
+
362
|
| 1446 |
+
00:29:37,000 --> 00:29:40,000
|
| 1447 |
+
All the configurations are in one file.
|
| 1448 |
+
|
| 1449 |
+
363
|
| 1450 |
+
00:29:41,000 --> 00:29:48,000
|
| 1451 |
+
You can open application context, XML looks through the file or make some search through the file to
|
| 1452 |
+
|
| 1453 |
+
364
|
| 1454 |
+
00:29:48,000 --> 00:29:53,000
|
| 1455 |
+
find information that you need and to update configurations that you need.
|
| 1456 |
+
|
| 1457 |
+
365
|
| 1458 |
+
00:29:53,000 --> 00:29:58,000
|
| 1459 |
+
Instead of looking through the source code of dozens or hundreds of Java files.
|
| 1460 |
+
|
| 1461 |
+
366
|
| 1462 |
+
00:29:59,000 --> 00:30:01,000
|
| 1463 |
+
Disadvantages of XML file.
|
| 1464 |
+
|
| 1465 |
+
367
|
| 1466 |
+
00:30:02,000 --> 00:30:10,000
|
| 1467 |
+
As your application will grow, your configuration file will grow too, and it is okay to manage relatively
|
| 1468 |
+
|
| 1469 |
+
368
|
| 1470 |
+
00:30:10,000 --> 00:30:18,000
|
| 1471 |
+
not big XML file, but when your XML file will turn into the file with thousands of rows, you may start
|
| 1472 |
+
|
| 1473 |
+
369
|
| 1474 |
+
00:30:18,000 --> 00:30:26,000
|
| 1475 |
+
thinking about separation of configuration into smaller pieces and for example, to put configurations
|
| 1476 |
+
|
| 1477 |
+
370
|
| 1478 |
+
00:30:26,000 --> 00:30:28,000
|
| 1479 |
+
in each class with annotations.
|
| 1480 |
+
|
| 1481 |
+
371
|
| 1482 |
+
00:30:29,000 --> 00:30:37,000
|
| 1483 |
+
All the pros and cons are 100% valid, and at the end of the day it is only you who decide which approach
|
| 1484 |
+
|
| 1485 |
+
372
|
| 1486 |
+
00:30:37,000 --> 00:30:38,000
|
| 1487 |
+
to choose.
|
| 1488 |
+
|
| 1489 |
+
373
|
| 1490 |
+
00:30:38,000 --> 00:30:46,000
|
| 1491 |
+
The main goal is to stay consistent with approach select, making sure everyone on the project follows
|
| 1492 |
+
|
| 1493 |
+
374
|
| 1494 |
+
00:30:46,000 --> 00:30:47,000
|
| 1495 |
+
the same rules.
|
| 1496 |
+
|
| 1497 |
+
375
|
| 1498 |
+
00:30:48,000 --> 00:30:56,000
|
| 1499 |
+
It is also not a question of isare or which one over the other, because you can use any combination
|
| 1500 |
+
|
| 1501 |
+
376
|
| 1502 |
+
00:30:56,000 --> 00:31:02,000
|
| 1503 |
+
of configuration options in your application, one or all combined.
|
| 1504 |
+
|
| 1505 |
+
377
|
| 1506 |
+
00:31:02,000 --> 00:31:06,000
|
| 1507 |
+
You just have to make your rules and stick to them.
|
| 1508 |
+
|
| 1509 |
+
378
|
| 1510 |
+
00:31:06,000 --> 00:31:08,000
|
| 1511 |
+
The main thing is a consistency.
|
| 1512 |
+
|
| 1513 |
+
379
|
| 1514 |
+
00:31:09,000 --> 00:31:13,000
|
| 1515 |
+
Basically, that's all what I wanted to share with you today in the lesson.
|
| 1516 |
+
|
| 1517 |
+
380
|
| 1518 |
+
00:31:13,000 --> 00:31:16,000
|
| 1519 |
+
Let's recap what we have learned today.
|
| 1520 |
+
|
| 1521 |
+
381
|
| 1522 |
+
00:31:17,000 --> 00:31:23,000
|
| 1523 |
+
Today we have learned how to work with the factory and with the application context.
|
| 1524 |
+
|
| 1525 |
+
382
|
| 1526 |
+
00:31:23,000 --> 00:31:28,000
|
| 1527 |
+
Now, you know, what is the difference between being factory and application context on practice?
|
| 1528 |
+
|
| 1529 |
+
383
|
| 1530 |
+
00:31:29,000 --> 00:31:35,000
|
| 1531 |
+
We learn on practice what I see container is and how we can interact and work with it.
|
| 1532 |
+
|
| 1533 |
+
384
|
| 1534 |
+
00:31:36,000 --> 00:31:43,000
|
| 1535 |
+
I showed you how we can work with spring beans, including how to declare them and instantiate in different
|
| 1536 |
+
|
| 1537 |
+
385
|
| 1538 |
+
00:31:43,000 --> 00:31:44,000
|
| 1539 |
+
ways.
|
| 1540 |
+
|
| 1541 |
+
386
|
| 1542 |
+
00:31:45,000 --> 00:31:49,000
|
| 1543 |
+
Now, you know, what is the difference between beloved and bin Laden?
|
| 1544 |
+
|
| 1545 |
+
387
|
| 1546 |
+
00:31:49,000 --> 00:31:55,000
|
| 1547 |
+
In the last movie removed all examples was XML configuration and annotation configuration.
|
| 1548 |
+
|
| 1549 |
+
388
|
| 1550 |
+
00:31:56,000 --> 00:32:03,000
|
| 1551 |
+
After this lesson, you know the difference between these two approaches together with their advantages
|
| 1552 |
+
|
| 1553 |
+
389
|
| 1554 |
+
00:32:03,000 --> 00:32:04,000
|
| 1555 |
+
and disadvantages.
|
| 1556 |
+
|
| 1557 |
+
390
|
| 1558 |
+
00:32:04,000 --> 00:32:12,000
|
| 1559 |
+
We learned such annotations as component sets, controller and repository, and how they're different.
|
| 1560 |
+
|
| 1561 |
+
391
|
| 1562 |
+
00:32:13,000 --> 00:32:18,000
|
| 1563 |
+
Also, we learned being and qualifier annotations on real examples.
|
| 1564 |
+
|
| 1565 |
+
392
|
| 1566 |
+
00:32:18,000 --> 00:32:25,000
|
| 1567 |
+
You understood the difference between the scopes and at the end of the lesson we compare the advantages
|
| 1568 |
+
|
| 1569 |
+
393
|
| 1570 |
+
00:32:25,000 --> 00:32:29,000
|
| 1571 |
+
and disadvantages of XML annotation screen configuration.
|
| 1572 |
+
|
| 1573 |
+
394
|
| 1574 |
+
00:32:30,000 --> 00:32:32,000
|
| 1575 |
+
That's so what I wanted to share with you today.
|
| 1576 |
+
|
| 1577 |
+
395
|
| 1578 |
+
00:32:32,000 --> 00:32:34,000
|
| 1579 |
+
Thanks a lot for your attention.
|
| 1580 |
+
|
| 1581 |
+
396
|
| 1582 |
+
00:32:34,000 --> 00:32:37,000
|
| 1583 |
+
Have a great day and see you in the next lesson.
|
| 1584 |
+
|
81 - Spring Core/003 Source-code-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-spring/tree/master/src/main/java/com/itbulls/learnit/spring/core/ioc
|
81 - Spring Core/003 applicationContext.xml.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-spring/blob/master/src/main/resources/applicationContext.xml
|
81 - Spring Core/004 Source-code-examples-from-the-lesson.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/AndriiPiatakha/java-learnit-spring/tree/master/src/main/java/com/itbulls/learnit/spring/core/ioc/di
|
81 - Spring Core/004 Spring Dependency Injection Practice_en.srt
ADDED
|
@@ -0,0 +1,1268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:06,000 --> 00:00:07,000
|
| 3 |
+
Hello came in this lesson.
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:07,000 --> 00:00:13,000
|
| 7 |
+
We are going to have a practical activities and exercises to help you understand dependency injection
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:13,000 --> 00:00:14,000
|
| 11 |
+
better.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:14,000 --> 00:00:21,000
|
| 15 |
+
And again, I would like to highlight that it is important you watch lessons one by one because we already
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:21,000 --> 00:00:28,000
|
| 19 |
+
have a theoretical lesson where we talked about dependency injection and we also have practical exercise
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:28,000 --> 00:00:31,000
|
| 23 |
+
about basic spring configuration.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:31,000 --> 00:00:36,000
|
| 27 |
+
In the lesson we are going to see what a dependency injection is on practice.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:36,000 --> 00:00:43,000
|
| 31 |
+
We are going to learn different types of injection, namely constructor injection, center injection
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:43,000 --> 00:00:45,000
|
| 35 |
+
and field injection.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:45,000 --> 00:00:49,000
|
| 39 |
+
I will show you how auto work annotation works.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:49,000 --> 00:00:54,000
|
| 43 |
+
All examples will review with annotation and XML configuration.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:55,000 --> 00:00:58,000
|
| 47 |
+
We'll learn what the value annotation is and when to use it.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:59,000 --> 00:01:04,000
|
| 51 |
+
We'll review what no unique being definition exception is and how we can avoid it.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:01:05,000 --> 00:01:08,000
|
| 55 |
+
We'll learn how to apply qualifier annotation.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:01:08,000 --> 00:01:11,000
|
| 59 |
+
Also, we'll talk about primary annotation.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:01:11,000 --> 00:01:15,000
|
| 63 |
+
Another not long topic, but important one.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:01:15,000 --> 00:01:19,000
|
| 67 |
+
We will talk about configuration of lazy initialization of our builds.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:01:20,000 --> 00:01:25,000
|
| 71 |
+
During the lesson, I am going to show you how we can inject the action and map objects.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:01:25,000 --> 00:01:32,000
|
| 75 |
+
I will show you what an order annotation is and at the end of the lesson we will learn what a lookup
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:32,000 --> 00:01:35,000
|
| 79 |
+
annotation is and when we need to use it.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:36,000 --> 00:01:37,000
|
| 83 |
+
Let's start our lesson.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:38,000 --> 00:01:44,000
|
| 87 |
+
Dependency injection is one of the core and fundamental things in this framework.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:44,000 --> 00:01:52,000
|
| 91 |
+
With the help of dependency injection, Spring injects objects into other objects and manage dependencies
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:52,000 --> 00:01:53,000
|
| 95 |
+
between them.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:54,000 --> 00:02:00,000
|
| 99 |
+
This helps us to achieve loose coupling of components and moves the responsibility of managing components
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:02:00,000 --> 00:02:02,000
|
| 103 |
+
onto the container.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:02:02,000 --> 00:02:06,000
|
| 107 |
+
So as we have learned in our theoretical lesson.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:02:06,000 --> 00:02:14,000
|
| 111 |
+
Dependency injection is a partner we can use to implement ISC, where the control being inverted is
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:02:14,000 --> 00:02:15,000
|
| 115 |
+
set in an object.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:02:15,000 --> 00:02:19,000
|
| 119 |
+
Dependencies according to the dependency injection part.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:02:19,000 --> 00:02:27,000
|
| 123 |
+
We connect objects with each other by injecting one object into others, and injecting is done not by
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:02:27,000 --> 00:02:31,000
|
| 127 |
+
the objects but by the assembler itself.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:02:31,000 --> 00:02:40,000
|
| 131 |
+
In the spring framework by spring ISC container dependency injection in spring can be done through constructors
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:02:40,000 --> 00:02:41,000
|
| 135 |
+
setters or fields.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:02:42,000 --> 00:02:46,000
|
| 139 |
+
And today in the lesson we are going to review all these approaches.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:02:46,000 --> 00:02:52,000
|
| 143 |
+
And as I promised you, we're going to have a lot of practical exercises in this lesson.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:02:52,000 --> 00:02:56,000
|
| 147 |
+
So let me start from the examples and screen sharing.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:02:56,000 --> 00:03:01,000
|
| 151 |
+
As always, you can find all source code examples in attachments to the video.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:03:01,000 --> 00:03:06,000
|
| 155 |
+
And I'm going to start with a demo of constructor based injection.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:03:06,000 --> 00:03:09,000
|
| 159 |
+
I opens a class that is called app config.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:03:10,000 --> 00:03:12,000
|
| 163 |
+
I have been admin role.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:03:12,000 --> 00:03:13,000
|
| 167 |
+
Here it is.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:03:14,000 --> 00:03:18,000
|
| 171 |
+
I create an object of role type with admin role role name.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:03:19,000 --> 00:03:21,000
|
| 175 |
+
And I have been of admin user.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:03:22,000 --> 00:03:29,000
|
| 179 |
+
Potentially that admin user is created with admin role when this user being will be instantiated.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:03:29,000 --> 00:03:38,000
|
| 183 |
+
Spring will create be of admin role first and only after that will inject role into the user.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:03:39,000 --> 00:03:43,000
|
| 187 |
+
Let me now open class by annotation demo.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:03:44,000 --> 00:03:48,000
|
| 191 |
+
I create the annotation config application context clause.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:03:48,000 --> 00:03:50,000
|
| 195 |
+
I scan packages.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:03:50,000 --> 00:03:56,000
|
| 199 |
+
I will not stop on z slides of code because we reviewed them in our previous lesson.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:03:56,000 --> 00:04:04,000
|
| 203 |
+
So please just be attentive and I get admin user B and get its row.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:04:04,000 --> 00:04:11,000
|
| 207 |
+
I run the application and we expect to see admin role name and console to prove that object of admin
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:04:11,000 --> 00:04:15,000
|
| 211 |
+
role has been successfully injected into the user object.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:04:16,000 --> 00:04:17,000
|
| 215 |
+
Is it clear?
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:04:18,000 --> 00:04:25,000
|
| 219 |
+
So now admin user bean has the reference to the admin role and injection happened through the constructive
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:04:26,000 --> 00:04:31,000
|
| 223 |
+
and you can see that we have constructor in the user for the row object.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:04:32,000 --> 00:04:36,000
|
| 227 |
+
The simplest thing we can do with the help of XML configuration.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:04:36,000 --> 00:04:40,000
|
| 231 |
+
Let me open our application context XML file.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:04:41,000 --> 00:04:49,000
|
| 235 |
+
Here you can see that I created admin role bean and set admin role value to the role name property and
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:04:49,000 --> 00:04:56,000
|
| 239 |
+
after that I create admin user B and the use constructor argument element to inject another bean.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:04:57,000 --> 00:05:03,000
|
| 243 |
+
You can see that I specify name of the constructor argument and reference to the bean that I would like
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:05:03,000 --> 00:05:04,000
|
| 247 |
+
to inject.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:05:05,000 --> 00:05:11,000
|
| 251 |
+
In this case, the name should match with the name of the local variable in constructor.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:05:11,000 --> 00:05:16,000
|
| 255 |
+
You can also inject beans by the sequence number of the constructor argument.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:05:17,000 --> 00:05:23,000
|
| 259 |
+
The argument constructor would have index zero and in the admin user to be.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:05:23,000 --> 00:05:26,000
|
| 263 |
+
You can see how I inject admin role.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:05:26,000 --> 00:05:33,000
|
| 267 |
+
Another way of constructing injecting You can specify times that you want to inject and spring will
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:05:33,000 --> 00:05:37,000
|
| 271 |
+
identify which b you want to inject by matching types.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:05:38,000 --> 00:05:43,000
|
| 275 |
+
So these are three ways how you can describe constructor injection.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:05:44,000 --> 00:05:47,000
|
| 279 |
+
Let me now open the AI XML demo.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:05:47,000 --> 00:05:51,000
|
| 283 |
+
In this class I read XML definition.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:05:51,000 --> 00:05:58,000
|
| 287 |
+
We have learned how to do this in the previous lesson, so please make sure you don't skip lessons.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:05:58,000 --> 00:06:05,000
|
| 291 |
+
And after that, I want to extract three beans that we described in different ways and to prove that
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:06:05,000 --> 00:06:13,000
|
| 295 |
+
raw object has been injected successfully, I just refer to that property and print role name to console.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:06:14,000 --> 00:06:16,000
|
| 299 |
+
Is everything clear so far?
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:06:16,000 --> 00:06:23,000
|
| 303 |
+
Even in case you have some questions, please don't hesitate to ask your questions in comments below
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:06:23,000 --> 00:06:26,000
|
| 307 |
+
the video and I will be happy to answer.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:06:26,000 --> 00:06:27,000
|
| 311 |
+
Let's continue.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:06:28,000 --> 00:06:34,000
|
| 315 |
+
Now I'm going to show you Saturn injection for Saturn based dependency injection.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:06:34,000 --> 00:06:42,000
|
| 319 |
+
The container will call Saturn masses of our class after invoked and no argument Constructor Let me
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:06:42,000 --> 00:06:45,000
|
| 323 |
+
open app config class again here.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:06:45,000 --> 00:06:51,000
|
| 327 |
+
You can see that to create admin user to begin I inject row we are set and massive.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:06:52,000 --> 00:06:56,000
|
| 331 |
+
The simplest thing we can make with the help of maximal configuration.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:06:56,000 --> 00:06:59,000
|
| 335 |
+
Let me open application Context XML file now.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:07:00,000 --> 00:07:06,000
|
| 339 |
+
You already saw that we can use property element and build description and just set value.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:07:06,000 --> 00:07:13,000
|
| 343 |
+
But probably you never thought about what mechanism is used here in order to inject the value.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:07:13,000 --> 00:07:21,000
|
| 347 |
+
The regular set method for property is used to inject the value and instead of the value attribute,
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:07:21,000 --> 00:07:28,000
|
| 351 |
+
we use ref attribute to parse the reference to our bin to make sure that our injection works.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:07:28,000 --> 00:07:34,000
|
| 355 |
+
Please use the annotations demo and Die XML demo classes.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:07:34,000 --> 00:07:40,000
|
| 359 |
+
The similar check is present here and you can see the result of code execution in console.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:07:41,000 --> 00:07:42,000
|
| 363 |
+
Let's move on.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:07:43,000 --> 00:07:47,000
|
| 367 |
+
Let's now talk about field based dependency injection.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:07:47,000 --> 00:07:50,000
|
| 371 |
+
In case there is no constructor or setter in the class.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:07:50,000 --> 00:07:55,000
|
| 375 |
+
Dependency still can be injected by spring using refraction API.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:07:56,000 --> 00:08:02,000
|
| 379 |
+
If you are not familiar with the refraction API, please refer to my course Java from zero to first
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:08:02,000 --> 00:08:04,000
|
| 383 |
+
job to the section about reflection.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:08:04,000 --> 00:08:10,000
|
| 387 |
+
Where we reviewed the reflection API in Java is and how we can work with it.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:08:10,000 --> 00:08:14,000
|
| 391 |
+
Let me create another class here and call it user two.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:08:15,000 --> 00:08:20,000
|
| 395 |
+
In this class you can see that I have just role field and that's it.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:08:20,000 --> 00:08:25,000
|
| 399 |
+
As you can see, no setters, no constructors, just gather.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:08:25,000 --> 00:08:31,000
|
| 403 |
+
In order to prove that injection happen, the field has private modifier.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:08:31,000 --> 00:08:38,000
|
| 407 |
+
And again, if you're familiar with the Reflection API, you have to be aware that the private modifier
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:08:38,000 --> 00:08:42,000
|
| 411 |
+
is not a problem for reflection API to access the field.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:08:42,000 --> 00:08:50,000
|
| 415 |
+
I just want to highlight that my role is a component and my user two is also a component.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:08:51,000 --> 00:08:55,000
|
| 419 |
+
Spring will create all required beams and will identify dependencies.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:08:55,000 --> 00:09:03,000
|
| 423 |
+
Spring will also identify all the dependencies and will manage the dependencies with the beams available
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:09:03,000 --> 00:09:07,000
|
| 427 |
+
in the container and will inject all the required beams.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:09:08,000 --> 00:09:15,000
|
| 431 |
+
In this particular case, being of user to and role being will be created and will be present in container.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:09:16,000 --> 00:09:23,000
|
| 435 |
+
After that spring will identify or to warrant annotation for the role property and we'll check in the
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:09:23,000 --> 00:09:31,000
|
| 439 |
+
container whether there are any role being is available in case zero is such bin Splunk will inject
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:09:31,000 --> 00:09:33,000
|
| 443 |
+
role being into the user object.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:09:33,000 --> 00:09:34,000
|
| 447 |
+
Is it clear?
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:09:35,000 --> 00:09:36,000
|
| 451 |
+
Let me open the class.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:09:36,000 --> 00:09:45,000
|
| 455 |
+
The annotations demo in a similar way I request BIM user to and I assign it to the admin user variable.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:09:45,000 --> 00:09:49,000
|
| 459 |
+
And as you may guess, everything works as expected.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:09:50,000 --> 00:09:57,000
|
| 463 |
+
This demo is needed just to verify that we don't have any errors and that all objects created successfully.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:09:58,000 --> 00:10:01,000
|
| 467 |
+
And one more thing that I wanted to draw your attention to.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:10:01,000 --> 00:10:09,000
|
| 471 |
+
In case you use annotations for being configuration and you don't use XML and you want to set some default
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:10:09,000 --> 00:10:16,000
|
| 475 |
+
value for this, you can use value annotation like ID is a row component.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:10:16,000 --> 00:10:18,000
|
| 479 |
+
Let me show it to you.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:10:18,000 --> 00:10:22,000
|
| 483 |
+
You can use this annotation to pass an expression here.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:10:23,000 --> 00:10:24,000
|
| 487 |
+
Okay.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:10:24,000 --> 00:10:27,000
|
| 491 |
+
We saw how we used auto wire annotation.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:10:28,000 --> 00:10:32,000
|
| 495 |
+
Let's learn more about auto wiring in the XML configuration.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:10:32,000 --> 00:10:37,000
|
| 499 |
+
I open application context XML file and I declare another bean.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:10:38,000 --> 00:10:41,000
|
| 503 |
+
This bean definition has whatever attribute.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:10:42,000 --> 00:10:45,000
|
| 507 |
+
Let's learn what values we can use in this attribute.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:10:46,000 --> 00:10:50,000
|
| 511 |
+
There are four modes of auto being using an XML configuration.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:10:51,000 --> 00:10:53,000
|
| 515 |
+
No is the default value.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:10:53,000 --> 00:11:01,000
|
| 519 |
+
This means no auto wiring is used for the bean and we have to explicitly names the dependencies by name.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:11:02,000 --> 00:11:05,000
|
| 523 |
+
Auto wiring is done based on the name of the property.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:11:05,000 --> 00:11:14,000
|
| 527 |
+
Therefore, Sprint will look for a beam with the same name as property that needs to be set by type
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:11:14,000 --> 00:11:19,000
|
| 531 |
+
similar to the by name of the wiring only based on the type of the property.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:11:20,000 --> 00:11:25,000
|
| 535 |
+
This means spring will look for a beam with the same type of the property to set.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:11:25,000 --> 00:11:31,000
|
| 539 |
+
If there is more than one beam of that type, the framework throws an exception.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:11:31,000 --> 00:11:32,000
|
| 543 |
+
Constructor.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:11:33,000 --> 00:11:40,000
|
| 547 |
+
Auto wiring is done based on constructor arguments, meaning spring will look for beams with the same
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:11:40,000 --> 00:11:42,000
|
| 551 |
+
type as the constructor arguments.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:11:42,000 --> 00:11:49,000
|
| 555 |
+
But what will happen in case there are more than one being that is compatible by type with dependency.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:11:50,000 --> 00:11:51,000
|
| 559 |
+
Let's imagine the next case.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:11:52,000 --> 00:11:58,000
|
| 563 |
+
Just imagine that we have role interface and two implementations of the interface.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:11:59,000 --> 00:12:05,000
|
| 567 |
+
Please don't ask questions regarding business logic and why we implement role interface.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:12:05,000 --> 00:12:11,000
|
| 571 |
+
Just take this as an abstract example because there can be different cases like this.
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:12:12,000 --> 00:12:19,000
|
| 575 |
+
I open class ample role for employees and customer role for our customers.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:12:19,000 --> 00:12:27,000
|
| 579 |
+
As you can see, both of these classes implements role interface, so they are compatible.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:12:28,000 --> 00:12:37,000
|
| 583 |
+
And now the question is object of which type will be injected into my user three bin into the role property
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:12:37,000 --> 00:12:39,000
|
| 587 |
+
of role interface type.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:12:40,000 --> 00:12:46,000
|
| 591 |
+
By the way, as you can see here, I can use all the word annotation above the constructor.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:12:47,000 --> 00:12:55,000
|
| 595 |
+
Also, I can use auto word annotation with setter that would describe the way of how injection will
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:12:55,000 --> 00:13:02,000
|
| 599 |
+
be done is with the help of reflection API or a constructor or with a set of massive.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:13:03,000 --> 00:13:09,000
|
| 603 |
+
So we have two bees of the compatible type, which one will be selected and inject it.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:13:10,000 --> 00:13:13,000
|
| 607 |
+
Let's run the dialog station's demo program.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:13:13,000 --> 00:13:20,000
|
| 611 |
+
And in the console you can see that when I just get user three being from the container, I have no
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:13:20,000 --> 00:13:26,000
|
| 615 |
+
unique being definition exception because Sprint can't understand which build to inject.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:13:27,000 --> 00:13:30,000
|
| 619 |
+
What if I need to inject ample role here?
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:13:30,000 --> 00:13:39,000
|
| 623 |
+
What I have to do in this case, we need to inject specific being where we use auto word annotation.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:13:40,000 --> 00:13:43,000
|
| 627 |
+
You can use qualified annotation for that.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:13:43,000 --> 00:13:47,000
|
| 631 |
+
We removed for annotation in the previous lesson.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:13:47,000 --> 00:13:50,000
|
| 635 |
+
Let me show it in scope of this example.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:13:51,000 --> 00:13:56,000
|
| 639 |
+
So in the user three class I can use qualifier annotation.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:13:56,000 --> 00:14:02,000
|
| 643 |
+
In the previous lesson you already saw how we use qualifier notation near the constructor parameters.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:14:03,000 --> 00:14:08,000
|
| 647 |
+
In the same way we can use it as a massive parameters like you see here.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:14:09,000 --> 00:14:13,000
|
| 651 |
+
We can also use it as a field with all of our annotation.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:14:13,000 --> 00:14:17,000
|
| 655 |
+
You can select the place for this annotation as you wish.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:14:18,000 --> 00:14:23,000
|
| 659 |
+
Let me commend the private sector and on command you set a massive.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:14:24,000 --> 00:14:32,000
|
| 663 |
+
Let's now get back to the guy on the -- demo and run the program one more time, then cancel.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:14:32,000 --> 00:14:37,000
|
| 667 |
+
You can see that this time ample role object has been injected.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:14:37,000 --> 00:14:42,000
|
| 671 |
+
Can I do anything else to avoid no unique definition exception?
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:14:42,000 --> 00:14:43,000
|
| 675 |
+
Actually, yes.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:14:43,000 --> 00:14:46,000
|
| 679 |
+
I can use primary annotation.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:14:46,000 --> 00:14:53,000
|
| 683 |
+
In spring framework, the primary annotation is used to give higher preference to being when there are
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:14:53,000 --> 00:14:55,000
|
| 687 |
+
multiple means of same type.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:14:55,000 --> 00:15:03,000
|
| 691 |
+
The primary notation may be used on any class, directly or indirectly annotated with component or on
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:15:03,000 --> 00:15:04,000
|
| 695 |
+
masses.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:15:04,000 --> 00:15:05,000
|
| 699 |
+
Annotated was been.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:15:06,000 --> 00:15:10,000
|
| 703 |
+
Let me now try to command the setter with a qualified annotation.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:15:11,000 --> 00:15:15,000
|
| 707 |
+
After that I uncommon setter was just at the connotation.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:15:15,000 --> 00:15:24,000
|
| 711 |
+
I also command primary annotation in the ample role class and execute our example one more time and
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:15:24,000 --> 00:15:31,000
|
| 715 |
+
you can see that code is executed without any exceptions and the ample role being has been injected
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:15:31,000 --> 00:15:38,000
|
| 719 |
+
since it has priority of a customer role based on our configuration that we specify.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:15:39,000 --> 00:15:46,000
|
| 723 |
+
Now you know how to use no unique being definition exception and how to rope with qualifier and primary
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:15:46,000 --> 00:15:47,000
|
| 727 |
+
annotations.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:15:48,000 --> 00:15:54,000
|
| 731 |
+
And with regards to other word annotation, also small but important thing.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:15:55,000 --> 00:16:02,000
|
| 735 |
+
Usually if you put out a word on a patient, that means that some beans that's supposed to be injected
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:16:02,000 --> 00:16:07,000
|
| 739 |
+
should be present in the container in case such being is not found.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:16:07,000 --> 00:16:14,000
|
| 743 |
+
You are going to see the exception in case the injection is not required and should be treated like
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:16:14,000 --> 00:16:15,000
|
| 747 |
+
optional.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:16:15,000 --> 00:16:23,000
|
| 751 |
+
In this case, in Ottawa notation you should specify required force attribute like you can see in the
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:16:23,000 --> 00:16:27,000
|
| 755 |
+
command the connotation here in the user three plus.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:16:27,000 --> 00:16:29,000
|
| 759 |
+
Let's continue.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:16:29,000 --> 00:16:36,000
|
| 763 |
+
Let me also share with you one little thing, because it is really so minor that this doesn't work for
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:16:36,000 --> 00:16:39,000
|
| 767 |
+
a separate lesson but still can be very useful.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:16:39,000 --> 00:16:46,000
|
| 771 |
+
By default, the container creates and configures all singleton bins during initialization.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:16:47,000 --> 00:16:54,000
|
| 775 |
+
So with this we can use the lazy init attribute with value true on the beam configuration in the application
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:16:54,000 --> 00:16:56,000
|
| 779 |
+
context xml file.
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:16:56,000 --> 00:17:03,000
|
| 783 |
+
You can see how I used this attribute in the definition of the admin user file.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:17:03,000 --> 00:17:05,000
|
| 787 |
+
Just to let you know.
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:17:05,000 --> 00:17:08,000
|
| 791 |
+
Let's continue with the next thing.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:17:09,000 --> 00:17:13,000
|
| 795 |
+
Let's understand now how we can inject collections and maps.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:17:14,000 --> 00:17:18,000
|
| 799 |
+
Imagine that for our user beans that we describe in the class.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:17:18,000 --> 00:17:23,000
|
| 803 |
+
User four we need to store collection of order IDs.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:17:24,000 --> 00:17:26,000
|
| 807 |
+
These are orders of the user.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:17:26,000 --> 00:17:29,000
|
| 811 |
+
For example, again, imaginary case.
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:17:29,000 --> 00:17:35,000
|
| 815 |
+
In order to inject collection, we can use the same annotation that we have just removed.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:17:35,000 --> 00:17:43,000
|
| 819 |
+
Let's declare a field of type leased parameterized by string type and let's add auto word annotation
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:17:43,000 --> 00:17:44,000
|
| 823 |
+
on top of it.
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:17:44,000 --> 00:17:48,000
|
| 827 |
+
The good news is that you can use generic types for auto wiring.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:17:49,000 --> 00:17:56,000
|
| 831 |
+
Spring lets us use a generic type as a qualifier without the need for an explicit annotation since version
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:17:56,000 --> 00:17:57,000
|
| 835 |
+
four.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:17:58,000 --> 00:18:00,000
|
| 839 |
+
Let me open app config class now.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:18:01,000 --> 00:18:10,000
|
| 843 |
+
In this class I declare another bill of type list and name like property in our user class order IDs.
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:18:10,000 --> 00:18:16,000
|
| 847 |
+
This method will return list of elements that I would like to inject, but actually even in the case
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:18:16,000 --> 00:18:18,000
|
| 851 |
+
the name would be different.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:18:18,000 --> 00:18:25,000
|
| 855 |
+
Spring still will be able to inject this list into the user for me because spring will detect compatible
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:18:25,000 --> 00:18:26,000
|
| 859 |
+
types.
|
| 860 |
+
|
| 861 |
+
216
|
| 862 |
+
00:18:27,000 --> 00:18:37,000
|
| 863 |
+
Now let me open the demo class and I will try to get user for being from container and print order IDs
|
| 864 |
+
|
| 865 |
+
217
|
| 866 |
+
00:18:38,000 --> 00:18:39,000
|
| 867 |
+
as you can see.
|
| 868 |
+
|
| 869 |
+
218
|
| 870 |
+
00:18:39,000 --> 00:18:47,000
|
| 871 |
+
So everything works as expected and we managed to inject list of strings successfully and obviously
|
| 872 |
+
|
| 873 |
+
219
|
| 874 |
+
00:18:47,000 --> 00:18:53,000
|
| 875 |
+
you can inject collection using the constructor while constructing your beam.
|
| 876 |
+
|
| 877 |
+
220
|
| 878 |
+
00:18:53,000 --> 00:18:56,000
|
| 879 |
+
Let me open app config class.
|
| 880 |
+
|
| 881 |
+
221
|
| 882 |
+
00:18:56,000 --> 00:19:00,000
|
| 883 |
+
You can see how I configured the user with list.
|
| 884 |
+
|
| 885 |
+
222
|
| 886 |
+
00:19:00,000 --> 00:19:03,000
|
| 887 |
+
So basically nothing special.
|
| 888 |
+
|
| 889 |
+
223
|
| 890 |
+
00:19:03,000 --> 00:19:08,000
|
| 891 |
+
Like this, you can inject any least set left or map.
|
| 892 |
+
|
| 893 |
+
224
|
| 894 |
+
00:19:08,000 --> 00:19:09,000
|
| 895 |
+
It is up to you.
|
| 896 |
+
|
| 897 |
+
225
|
| 898 |
+
00:19:10,000 --> 00:19:13,000
|
| 899 |
+
Use constructor injection to inject whatever you need.
|
| 900 |
+
|
| 901 |
+
226
|
| 902 |
+
00:19:14,000 --> 00:19:21,000
|
| 903 |
+
Let's learn how we can configure corrections on that injection with the help of XML configuration.
|
| 904 |
+
|
| 905 |
+
227
|
| 906 |
+
00:19:21,000 --> 00:19:26,000
|
| 907 |
+
I created a class that is called Java Collection Injection demo.
|
| 908 |
+
|
| 909 |
+
228
|
| 910 |
+
00:19:27,000 --> 00:19:28,000
|
| 911 |
+
Let me show it to you.
|
| 912 |
+
|
| 913 |
+
229
|
| 914 |
+
00:19:29,000 --> 00:19:35,000
|
| 915 |
+
As you can see in this class, we have different properties of type, least sad map and properties.
|
| 916 |
+
|
| 917 |
+
230
|
| 918 |
+
00:19:36,000 --> 00:19:39,000
|
| 919 |
+
And also I have getters and setters.
|
| 920 |
+
|
| 921 |
+
231
|
| 922 |
+
00:19:39,000 --> 00:19:43,000
|
| 923 |
+
Let's configure this being with the XML configuration.
|
| 924 |
+
|
| 925 |
+
232
|
| 926 |
+
00:19:43,000 --> 00:19:46,000
|
| 927 |
+
Ends application contacts XML file.
|
| 928 |
+
|
| 929 |
+
233
|
| 930 |
+
00:19:46,000 --> 00:19:49,000
|
| 931 |
+
You can find definitions of Java collection bin.
|
| 932 |
+
|
| 933 |
+
234
|
| 934 |
+
00:19:50,000 --> 00:19:54,000
|
| 935 |
+
You can see that I injected values into each property.
|
| 936 |
+
|
| 937 |
+
235
|
| 938 |
+
00:19:54,000 --> 00:19:59,000
|
| 939 |
+
For example, to inject list elements I have leased.
|
| 940 |
+
|
| 941 |
+
236
|
| 942 |
+
00:19:59,000 --> 00:20:04,000
|
| 943 |
+
Element to inject set elements I have set element.
|
| 944 |
+
|
| 945 |
+
237
|
| 946 |
+
00:20:04,000 --> 00:20:12,000
|
| 947 |
+
Also, I have mapped with the entry elements and props with prop element to describe key value pairs.
|
| 948 |
+
|
| 949 |
+
238
|
| 950 |
+
00:20:12,000 --> 00:20:18,000
|
| 951 |
+
Obviously, in each case you can inject not just three values, but be references.
|
| 952 |
+
|
| 953 |
+
239
|
| 954 |
+
00:20:19,000 --> 00:20:28,000
|
| 955 |
+
Use hotkeys control space to see suggestions here and you will find that you can use ref attribute to
|
| 956 |
+
|
| 957 |
+
240
|
| 958 |
+
00:20:28,000 --> 00:20:31,000
|
| 959 |
+
inject the references in the class.
|
| 960 |
+
|
| 961 |
+
241
|
| 962 |
+
00:20:31,000 --> 00:20:35,000
|
| 963 |
+
GUI xml you can find is a demo of this bin.
|
| 964 |
+
|
| 965 |
+
242
|
| 966 |
+
00:20:36,000 --> 00:20:41,000
|
| 967 |
+
Always remember that in attachments to the lesson you find the reference to the source code.
|
| 968 |
+
|
| 969 |
+
243
|
| 970 |
+
00:20:42,000 --> 00:20:47,000
|
| 971 |
+
Feel free to download the code on your local computer and execute it on your machine.
|
| 972 |
+
|
| 973 |
+
244
|
| 974 |
+
00:20:48,000 --> 00:20:53,000
|
| 975 |
+
Navigate between the files to understand better how this code works.
|
| 976 |
+
|
| 977 |
+
245
|
| 978 |
+
00:20:53,000 --> 00:20:58,000
|
| 979 |
+
Let's know now what an order annotation is and when we need to use it.
|
| 980 |
+
|
| 981 |
+
246
|
| 982 |
+
00:20:59,000 --> 00:21:02,000
|
| 983 |
+
Imagine that you have type that is called priority.
|
| 984 |
+
|
| 985 |
+
247
|
| 986 |
+
00:21:03,000 --> 00:21:09,000
|
| 987 |
+
Priority is an interface and thus we are the types that implements this interface.
|
| 988 |
+
|
| 989 |
+
248
|
| 990 |
+
00:21:10,000 --> 00:21:16,000
|
| 991 |
+
Like in our example, we have high priority, medium priority and low priority.
|
| 992 |
+
|
| 993 |
+
249
|
| 994 |
+
00:21:17,000 --> 00:21:22,000
|
| 995 |
+
Each priority implements mass get priority run according to interface.
|
| 996 |
+
|
| 997 |
+
250
|
| 998 |
+
00:21:23,000 --> 00:21:30,000
|
| 999 |
+
And now imagine that I need to gather all priorities in one list, and moreover, I need to gather them
|
| 1000 |
+
|
| 1001 |
+
251
|
| 1002 |
+
00:21:30,000 --> 00:21:32,000
|
| 1003 |
+
in the specific order.
|
| 1004 |
+
|
| 1005 |
+
252
|
| 1006 |
+
00:21:32,000 --> 00:21:34,000
|
| 1007 |
+
How I can do that.
|
| 1008 |
+
|
| 1009 |
+
253
|
| 1010 |
+
00:21:34,000 --> 00:21:42,000
|
| 1011 |
+
Each of the priority implementation is a component, as you can see, and each of these types has also
|
| 1012 |
+
|
| 1013 |
+
254
|
| 1014 |
+
00:21:42,000 --> 00:21:43,000
|
| 1015 |
+
order annotation.
|
| 1016 |
+
|
| 1017 |
+
255
|
| 1018 |
+
00:21:44,000 --> 00:21:48,000
|
| 1019 |
+
Order is used to specify the order of injection.
|
| 1020 |
+
|
| 1021 |
+
256
|
| 1022 |
+
00:21:49,000 --> 00:21:56,000
|
| 1023 |
+
We can use constants like highest precedence from the ordered interface or lowest precedence, which
|
| 1024 |
+
|
| 1025 |
+
257
|
| 1026 |
+
00:21:56,000 --> 00:21:59,000
|
| 1027 |
+
specifies the sequence number of injection, for example.
|
| 1028 |
+
|
| 1029 |
+
258
|
| 1030 |
+
00:22:00,000 --> 00:22:05,000
|
| 1031 |
+
In our annotations demo I auto word list of priorities.
|
| 1032 |
+
|
| 1033 |
+
259
|
| 1034 |
+
00:22:05,000 --> 00:22:12,000
|
| 1035 |
+
Spring is smart enough to understand that in this property you want to gather all components that are
|
| 1036 |
+
|
| 1037 |
+
260
|
| 1038 |
+
00:22:12,000 --> 00:22:14,000
|
| 1039 |
+
compatible with priority type.
|
| 1040 |
+
|
| 1041 |
+
261
|
| 1042 |
+
00:22:15,000 --> 00:22:22,000
|
| 1043 |
+
By the way, this is just another way of how to inject collection of values and the order annotation
|
| 1044 |
+
|
| 1045 |
+
262
|
| 1046 |
+
00:22:22,000 --> 00:22:27,000
|
| 1047 |
+
helps us to inject our beams into the list in the specific order.
|
| 1048 |
+
|
| 1049 |
+
263
|
| 1050 |
+
00:22:28,000 --> 00:22:34,000
|
| 1051 |
+
In the main method, when I get the reference to the injected collection and iterate over it.
|
| 1052 |
+
|
| 1053 |
+
264
|
| 1054 |
+
00:22:34,000 --> 00:22:42,000
|
| 1055 |
+
I pruned the priority run of each object and in console you can see that all items are injected not
|
| 1056 |
+
|
| 1057 |
+
265
|
| 1058 |
+
00:22:42,000 --> 00:22:45,000
|
| 1059 |
+
in the random but in the specific order.
|
| 1060 |
+
|
| 1061 |
+
266
|
| 1062 |
+
00:22:45,000 --> 00:22:47,000
|
| 1063 |
+
Is it clear?
|
| 1064 |
+
|
| 1065 |
+
267
|
| 1066 |
+
00:22:47,000 --> 00:22:53,000
|
| 1067 |
+
Even in case you have any questions, please do not hesitate to ask your questions in comments to the
|
| 1068 |
+
|
| 1069 |
+
268
|
| 1070 |
+
00:22:53,000 --> 00:22:57,000
|
| 1071 |
+
video and I will be happy to answer those.
|
| 1072 |
+
|
| 1073 |
+
269
|
| 1074 |
+
00:22:58,000 --> 00:23:02,000
|
| 1075 |
+
And the last but not the least, think for today that I'd like to show you this.
|
| 1076 |
+
|
| 1077 |
+
270
|
| 1078 |
+
00:23:02,000 --> 00:23:03,000
|
| 1079 |
+
Look up annotation.
|
| 1080 |
+
|
| 1081 |
+
271
|
| 1082 |
+
00:23:04,000 --> 00:23:05,000
|
| 1083 |
+
When do we need it?
|
| 1084 |
+
|
| 1085 |
+
272
|
| 1086 |
+
00:23:06,000 --> 00:23:13,000
|
| 1087 |
+
Imagine that you declared a bean with Singleton's code and that bill has dependency on another bill's
|
| 1088 |
+
|
| 1089 |
+
273
|
| 1090 |
+
00:23:13,000 --> 00:23:14,000
|
| 1091 |
+
prototype scope.
|
| 1092 |
+
|
| 1093 |
+
274
|
| 1094 |
+
00:23:14,000 --> 00:23:21,000
|
| 1095 |
+
Then the logical question is how will our singletons spring bill access this prototype?
|
| 1096 |
+
|
| 1097 |
+
275
|
| 1098 |
+
00:23:21,000 --> 00:23:22,000
|
| 1099 |
+
Spring beans.
|
| 1100 |
+
|
| 1101 |
+
276
|
| 1102 |
+
00:23:23,000 --> 00:23:26,000
|
| 1103 |
+
Here's where Luke Configuration can help us.
|
| 1104 |
+
|
| 1105 |
+
277
|
| 1106 |
+
00:23:26,000 --> 00:23:33,000
|
| 1107 |
+
Spring will override our annotated method and use our methods return type and parameter as arguments
|
| 1108 |
+
|
| 1109 |
+
278
|
| 1110 |
+
00:23:33,000 --> 00:23:34,000
|
| 1111 |
+
could be in factory.
|
| 1112 |
+
|
| 1113 |
+
279
|
| 1114 |
+
00:23:34,000 --> 00:23:36,000
|
| 1115 |
+
Get bin message.
|
| 1116 |
+
|
| 1117 |
+
280
|
| 1118 |
+
00:23:37,000 --> 00:23:40,000
|
| 1119 |
+
Let me show you an example and you will understand.
|
| 1120 |
+
|
| 1121 |
+
281
|
| 1122 |
+
00:23:41,000 --> 00:23:47,000
|
| 1123 |
+
Imagine that we have class that is called user messenger and it has properties.
|
| 1124 |
+
|
| 1125 |
+
282
|
| 1126 |
+
00:23:47,000 --> 00:23:54,000
|
| 1127 |
+
The scope message user messenger being will be a single thought and message will be a prototype.
|
| 1128 |
+
|
| 1129 |
+
283
|
| 1130 |
+
00:23:55,000 --> 00:24:01,000
|
| 1131 |
+
How to ensure that message be will be new object Each time we refer to this property.
|
| 1132 |
+
|
| 1133 |
+
284
|
| 1134 |
+
00:24:02,000 --> 00:24:03,000
|
| 1135 |
+
Let me show it to.
|
| 1136 |
+
|
| 1137 |
+
285
|
| 1138 |
+
00:24:04,000 --> 00:24:06,000
|
| 1139 |
+
First of all, here is message.
|
| 1140 |
+
|
| 1141 |
+
286
|
| 1142 |
+
00:24:06,000 --> 00:24:14,000
|
| 1143 |
+
Object was the prototype scope and in the user messenger, let's create a lookup mask which tells us
|
| 1144 |
+
|
| 1145 |
+
287
|
| 1146 |
+
00:24:14,000 --> 00:24:15,000
|
| 1147 |
+
a message type.
|
| 1148 |
+
|
| 1149 |
+
288
|
| 1150 |
+
00:24:16,000 --> 00:24:20,000
|
| 1151 |
+
Pay attention that you don't need to implement this method.
|
| 1152 |
+
|
| 1153 |
+
289
|
| 1154 |
+
00:24:20,000 --> 00:24:22,000
|
| 1155 |
+
This is just a setup.
|
| 1156 |
+
|
| 1157 |
+
290
|
| 1158 |
+
00:24:22,000 --> 00:24:30,000
|
| 1159 |
+
Spring framework will override all methods marked with the lookup annotation to extract from the container
|
| 1160 |
+
|
| 1161 |
+
291
|
| 1162 |
+
00:24:30,000 --> 00:24:31,000
|
| 1163 |
+
new builds.
|
| 1164 |
+
|
| 1165 |
+
292
|
| 1166 |
+
00:24:32,000 --> 00:24:34,000
|
| 1167 |
+
Let's now test this.
|
| 1168 |
+
|
| 1169 |
+
293
|
| 1170 |
+
00:24:34,000 --> 00:24:43,000
|
| 1171 |
+
I open class die annotations demo here the bottom I create your messenger bin and after that I call
|
| 1172 |
+
|
| 1173 |
+
294
|
| 1174 |
+
00:24:43,000 --> 00:24:46,000
|
| 1175 |
+
get message twice and to prove use it.
|
| 1176 |
+
|
| 1177 |
+
295
|
| 1178 |
+
00:24:46,000 --> 00:24:51,000
|
| 1179 |
+
I receive references to the new objects but not the same objects.
|
| 1180 |
+
|
| 1181 |
+
296
|
| 1182 |
+
00:24:51,000 --> 00:24:53,000
|
| 1183 |
+
I will just compare the references.
|
| 1184 |
+
|
| 1185 |
+
297
|
| 1186 |
+
00:24:54,000 --> 00:24:55,000
|
| 1187 |
+
Let me run the program.
|
| 1188 |
+
|
| 1189 |
+
298
|
| 1190 |
+
00:24:55,000 --> 00:24:59,000
|
| 1191 |
+
And so we see that we received false here.
|
| 1192 |
+
|
| 1193 |
+
299
|
| 1194 |
+
00:24:59,000 --> 00:25:07,000
|
| 1195 |
+
When we compare the references, that means that each time I call get message method, I receive the
|
| 1196 |
+
|
| 1197 |
+
300
|
| 1198 |
+
00:25:07,000 --> 00:25:09,000
|
| 1199 |
+
reference to the new object.
|
| 1200 |
+
|
| 1201 |
+
301
|
| 1202 |
+
00:25:09,000 --> 00:25:10,000
|
| 1203 |
+
Is it clear?
|
| 1204 |
+
|
| 1205 |
+
302
|
| 1206 |
+
00:25:11,000 --> 00:25:16,000
|
| 1207 |
+
That's how lookup annotation can help us in the configuration of our dependency injection.
|
| 1208 |
+
|
| 1209 |
+
303
|
| 1210 |
+
00:25:17,000 --> 00:25:20,000
|
| 1211 |
+
That's all what I wanted to share with you in this lesson.
|
| 1212 |
+
|
| 1213 |
+
304
|
| 1214 |
+
00:25:21,000 --> 00:25:24,000
|
| 1215 |
+
Let's recap what we have learned today.
|
| 1216 |
+
|
| 1217 |
+
305
|
| 1218 |
+
00:25:25,000 --> 00:25:28,000
|
| 1219 |
+
In the lesson we learned what a dependency injection is.
|
| 1220 |
+
|
| 1221 |
+
306
|
| 1222 |
+
00:25:29,000 --> 00:25:34,000
|
| 1223 |
+
Now you know what the constructive injection, the injection and field injection are.
|
| 1224 |
+
|
| 1225 |
+
307
|
| 1226 |
+
00:25:34,000 --> 00:25:39,000
|
| 1227 |
+
We reviewed all examples with annotation and XML configuration.
|
| 1228 |
+
|
| 1229 |
+
308
|
| 1230 |
+
00:25:40,000 --> 00:25:42,000
|
| 1231 |
+
Now you know what the value annotation is.
|
| 1232 |
+
|
| 1233 |
+
309
|
| 1234 |
+
00:25:43,000 --> 00:25:45,000
|
| 1235 |
+
We learned all the wiring in the lesson.
|
| 1236 |
+
|
| 1237 |
+
310
|
| 1238 |
+
00:25:46,000 --> 00:25:50,000
|
| 1239 |
+
I showed you how to deal with no unique build definition exception.
|
| 1240 |
+
|
| 1241 |
+
311
|
| 1242 |
+
00:25:50,000 --> 00:25:54,000
|
| 1243 |
+
We discussed qualifier and primary annotations.
|
| 1244 |
+
|
| 1245 |
+
312
|
| 1246 |
+
00:25:54,000 --> 00:25:58,000
|
| 1247 |
+
I showed you how to configure the lazy initialization of the bin.
|
| 1248 |
+
|
| 1249 |
+
313
|
| 1250 |
+
00:25:58,000 --> 00:26:03,000
|
| 1251 |
+
Also, we learned how to inject collection and map object into the bin.
|
| 1252 |
+
|
| 1253 |
+
314
|
| 1254 |
+
00:26:04,000 --> 00:26:09,000
|
| 1255 |
+
And at the end of the lesson we learn what an order and lookup annotations are.
|
| 1256 |
+
|
| 1257 |
+
315
|
| 1258 |
+
00:26:10,000 --> 00:26:12,000
|
| 1259 |
+
That's all for this lesson.
|
| 1260 |
+
|
| 1261 |
+
316
|
| 1262 |
+
00:26:12,000 --> 00:26:14,000
|
| 1263 |
+
Thanks a lot for your attention.
|
| 1264 |
+
|
| 1265 |
+
317
|
| 1266 |
+
00:26:14,000 --> 00:26:17,000
|
| 1267 |
+
Have a great day and see you in the next lesson.
|
| 1268 |
+
|