diff --git a/.gitattributes b/.gitattributes
index b4119adb784c7a028ca7912251a6cd91666b48bc..b5cdfa27b762ffc45b54f99b1c13c8b53159502c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -118,3 +118,14 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
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
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/001[[:space:]]Object-oriented[[:space:]]programming[[:space:]]Basics.mp4 filter=lfs diff=lfs merge=lfs -text
13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/002[[:space:]]Classes[[:space:]]&[[:space:]]Objects.mp4 filter=lfs diff=lfs merge=lfs -text
+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
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/004[[:space:]]Interfaces.mp4 filter=lfs diff=lfs merge=lfs -text
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/005[[:space:]]Inheritance.mp4 filter=lfs diff=lfs merge=lfs -text
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/006[[:space:]]Polymorphism[[:space:]]and[[:space:]]'final'[[:space:]]keyword.mp4 filter=lfs diff=lfs merge=lfs -text
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/008[[:space:]]Encapsulation.mp4 filter=lfs diff=lfs merge=lfs -text
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/007[[:space:]]'static'[[:space:]]keyword.mp4 filter=lfs diff=lfs merge=lfs -text
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/012[[:space:]]Open[[:space:]][[:space:]]Closed[[:space:]]Principle.mp4 filter=lfs diff=lfs merge=lfs -text
+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
+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
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/013[[:space:]]Liskov[[:space:]]Substitution[[:space:]]Principle.mp4 filter=lfs diff=lfs merge=lfs -text
+13[[:space:]]-[[:space:]]Object-oriented[[:space:]]programming/014[[:space:]]Interface[[:space:]]Segregation[[:space:]]Principle.mp4 filter=lfs diff=lfs merge=lfs -text
diff --git a/13 - Object-oriented programming/003 Different types of Classes, Abstract keyword and Abstract classes.mp4 b/13 - Object-oriented programming/003 Different types of Classes, Abstract keyword and Abstract classes.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..1ba27045410a85e254dfbd1c91e1a164727d7946
--- /dev/null
+++ b/13 - Object-oriented programming/003 Different types of Classes, Abstract keyword and Abstract classes.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:f65326e2c8257d2888d03406c31e128de20de79ea7d093a24b9064b66cb4b782
+size 214619488
diff --git a/13 - Object-oriented programming/004 Interfaces.mp4 b/13 - Object-oriented programming/004 Interfaces.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..93511fd9be8d793044f812a07ba52cb8f483b3ab
--- /dev/null
+++ b/13 - Object-oriented programming/004 Interfaces.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:29dd04a13a030b2cc1ff422882325c6fcfb44955075fdf1104fabcc15931a9ad
+size 212297701
diff --git a/13 - Object-oriented programming/005 Inheritance.mp4 b/13 - Object-oriented programming/005 Inheritance.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..e7554ec185d5a39e81af618b1db8af5b720a40d1
--- /dev/null
+++ b/13 - Object-oriented programming/005 Inheritance.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4e9654bb3c034b503f6f0eaf9a8f2e1b012269aee31b7fef825f32ce9b89baf8
+size 204629371
diff --git a/13 - Object-oriented programming/006 Polymorphism and 'final' keyword.mp4 b/13 - Object-oriented programming/006 Polymorphism and 'final' keyword.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..9f42232af49063c7d37817093ffdd73db1dbb1e4
--- /dev/null
+++ b/13 - Object-oriented programming/006 Polymorphism and 'final' keyword.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:adb5291223aacdc2d3f85b82d4730d58ae7ef04d29597c3577bc9947c792dc12
+size 199334709
diff --git a/13 - Object-oriented programming/007 'static' keyword.mp4 b/13 - Object-oriented programming/007 'static' keyword.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..4736c863bb613bcdb00b481ff671a85a9272fcd5
--- /dev/null
+++ b/13 - Object-oriented programming/007 'static' keyword.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:cc4be31a6cda08041ca6bbb1e702c3355985098b08c64c0d517a6413e7ef025a
+size 142223829
diff --git a/13 - Object-oriented programming/008 Encapsulation.mp4 b/13 - Object-oriented programming/008 Encapsulation.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..f92777715375af28352832da42895f24616711d4
--- /dev/null
+++ b/13 - Object-oriented programming/008 Encapsulation.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:930b1ee2a65e135b50873db789e0ef0d73a93224891312f25d321bcc7aa58b12
+size 110141024
diff --git a/13 - Object-oriented programming/009 Object, JNI and Object class overview.mp4 b/13 - Object-oriented programming/009 Object, JNI and Object class overview.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..1ba44142c914462c36db83d2e7f66542306420f4
--- /dev/null
+++ b/13 - Object-oriented programming/009 Object, JNI and Object class overview.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ac1bc73de416d712292b3104119a223a1584d99ddc54ed2dc20c267cd8746b21
+size 268547559
diff --git a/13 - Object-oriented programming/011 SOLID principles overview & Single Responsibility Principle.mp4 b/13 - Object-oriented programming/011 SOLID principles overview & Single Responsibility Principle.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..95db5404909ec315f10d0b674e40c835ed236b29
--- /dev/null
+++ b/13 - Object-oriented programming/011 SOLID principles overview & Single Responsibility Principle.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:50d39eda7f47a62f914bfebdd725f64f1783424431605801963826e44baebed9
+size 116235324
diff --git a/13 - Object-oriented programming/012 Open Closed Principle.mp4 b/13 - Object-oriented programming/012 Open Closed Principle.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..9ff7f4fad51b96d6fd1868b6ff627df5a8a72433
--- /dev/null
+++ b/13 - Object-oriented programming/012 Open Closed Principle.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5a9a2729f8510907f595fc97f7f3e2edf488362b8e6cc130819add609f8fe75d
+size 43997110
diff --git a/13 - Object-oriented programming/013 Liskov Substitution Principle.mp4 b/13 - Object-oriented programming/013 Liskov Substitution Principle.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..41598ca8ab2210e2f067dce22c59c14e678b954e
--- /dev/null
+++ b/13 - Object-oriented programming/013 Liskov Substitution Principle.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:fc648466bd606ca68209d64ef1f140489ec47ca27b86be5bdf70ff535e9932b3
+size 79495387
diff --git a/13 - Object-oriented programming/014 Interface Segregation Principle.mp4 b/13 - Object-oriented programming/014 Interface Segregation Principle.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..a83a9b56db5b9ce122fbaec2527ae37f8f7952c5
--- /dev/null
+++ b/13 - Object-oriented programming/014 Interface Segregation Principle.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1d38e5c5de8f2725c906f34580b564b96d8ab801cb1b324cbec8c74129197fe7
+size 63795251
diff --git a/76 - Cybersecurity Comprehensive Security Practices for Developers/012 Cloud Security Best Practices_en.srt b/76 - Cybersecurity Comprehensive Security Practices for Developers/012 Cloud Security Best Practices_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..058aab91a23ab990b24ab2936d2b79f55e3875bc
--- /dev/null
+++ b/76 - Cybersecurity Comprehensive Security Practices for Developers/012 Cloud Security Best Practices_en.srt
@@ -0,0 +1,1060 @@
+1
+00:00:05,000 --> 00:00:07,000
+Hello dear students.
+
+2
+00:00:07,000 --> 00:00:12,000
+In this lesson we will focus on essential strategies to ensure the security of cloud environments.
+
+3
+00:00:13,000 --> 00:00:19,000
+These practices are designed to protect critical assets, secure data, and maintain control over access
+
+4
+00:00:19,000 --> 00:00:21,000
+to cloud resources.
+
+5
+00:00:21,000 --> 00:00:27,000
+We'll explore how to manage risks, effectively prevent unauthorized access, and ensure that sensitive
+
+6
+00:00:27,000 --> 00:00:29,000
+information remains protected.
+
+7
+00:00:29,000 --> 00:00:35,000
+A strong focus will be placed on monitoring cloud environments to detect unusual activities, and apply
+
+8
+00:00:35,000 --> 00:00:38,000
+necessary updates to keep systems secure.
+
+9
+00:00:38,000 --> 00:00:44,000
+Additionally, we'll discuss the importance of having comprehensive plans in place to recover from potential
+
+10
+00:00:44,000 --> 00:00:50,000
+disruptions and how to manage relationships with third party providers to ensure they meet security
+
+11
+00:00:50,000 --> 00:00:51,000
+requirements.
+
+12
+00:00:51,000 --> 00:00:57,000
+We will also cover proactive measures to identify potential vulnerabilities and safeguard cloud services
+
+13
+00:00:57,000 --> 00:00:59,000
+from emerging threats.
+
+14
+00:00:59,000 --> 00:01:06,000
+Together, these practices form a solid foundation for maintaining a secure and reliable cloud infrastructure.
+
+15
+00:01:07,000 --> 00:01:08,000
+Let's start our lesson.
+
+16
+00:01:09,000 --> 00:01:16,000
+In this lesson, we will explore a comprehensive set of cloud security best practices organized by their
+
+17
+00:01:16,000 --> 00:01:18,000
+relevance to cloud environments.
+
+18
+00:01:18,000 --> 00:01:25,000
+The first part of the list focuses on high relevance practices that address critical threat mitigation.
+
+19
+00:01:25,000 --> 00:01:31,000
+These include essential measures such as enforcing strict identity and access management to limit who
+
+20
+00:01:31,000 --> 00:01:38,000
+can access cloud resources, ensuring that encryption is in place to protect sensitive data both in
+
+21
+00:01:38,000 --> 00:01:44,000
+transit and at rest, and implementing multi-factor authentication to secure user accounts, particularly
+
+22
+00:01:44,000 --> 00:01:46,000
+those with elevated privileges.
+
+23
+00:01:46,000 --> 00:01:52,000
+Along with these, regular monitoring and auditing of cloud environments is key to detecting any unusual
+
+24
+00:01:52,000 --> 00:01:53,000
+activity early on.
+
+25
+00:01:54,000 --> 00:02:00,000
+Lastly, applying security patches and utilizing cloud native security services like firewalls and key
+
+26
+00:02:00,000 --> 00:02:04,000
+management are critical for keeping cloud infrastructure secure.
+
+27
+00:02:04,000 --> 00:02:11,000
+Moving down the list, we find practices categorized by moderate and low relevance, addressing common
+
+28
+00:02:11,000 --> 00:02:14,000
+security concerns and lesser known threats.
+
+29
+00:02:14,000 --> 00:02:21,000
+These include setting up robust backup and disaster recovery plans, ensuring network segmentation to
+
+30
+00:02:21,000 --> 00:02:28,000
+isolate sensitive areas of the cloud, and auditing third party service providers to ensure their security
+
+31
+00:02:28,000 --> 00:02:33,000
+aligns with your own standards for lower relevance threats.
+
+32
+00:02:33,000 --> 00:02:40,000
+The focus shifts to edge cases such as data loss prevention to prevent unauthorized data sharing, conducting
+
+33
+00:02:40,000 --> 00:02:46,000
+penetration testing to identify vulnerabilities, and following best practices for securing containerized
+
+34
+00:02:46,000 --> 00:02:48,000
+and serverless environments.
+
+35
+00:02:48,000 --> 00:02:56,000
+By covering all these areas from high priority risks to less common scenarios, we build a well-rounded
+
+36
+00:02:56,000 --> 00:02:59,000
+approach to maintaining a secure cloud infrastructure.
+
+37
+00:03:00,000 --> 00:03:07,000
+This second list categorizes cloud security best practices based on complexity, helping to structure
+
+38
+00:03:07,000 --> 00:03:10,000
+the approach to learning them step by step.
+
+39
+00:03:10,000 --> 00:03:17,000
+In the basic category, we cover foundational practices like implementing multi-factor authentication
+
+40
+00:03:17,000 --> 00:03:24,000
+to protect user accounts, encrypting sensitive data regularly applying security patches, and establishing
+
+41
+00:03:24,000 --> 00:03:27,000
+backup and disaster recovery plans.
+
+42
+00:03:27,000 --> 00:03:33,000
+Continuous training programs also fall into this category, ensuring that users and administrators stay
+
+43
+00:03:33,000 --> 00:03:37,000
+aware of potential threats such as phishing and social engineering.
+
+44
+00:03:37,000 --> 00:03:43,000
+These basic measures create a solid foundation of security that every organization should prioritize.
+
+45
+00:03:43,000 --> 00:03:49,000
+As you move to the intermediate and advanced categories, the focus shifts to more complex strategies.
+
+46
+00:03:49,000 --> 00:03:55,000
+Intermediate practices involve strong identity and access management, regular monitoring and auditing,
+
+47
+00:03:55,000 --> 00:04:01,000
+and leveraging cloud native security services like firewalls and DDoS protection.
+
+48
+00:04:02,000 --> 00:04:09,000
+Advanced practices involve securing API endpoints, implementing data loss prevention solutions, conducting
+
+49
+00:04:09,000 --> 00:04:13,000
+regular penetration testing, and securing container and serverless environments.
+
+50
+00:04:14,000 --> 00:04:20,000
+This categorization by complexity allows for a gradual, structured approach to mastering cloud security
+
+51
+00:04:20,000 --> 00:04:21,000
+principles.
+
+52
+00:04:22,000 --> 00:04:27,000
+However, depending on your comfort level or the organization's needs, you may prefer to group these
+
+53
+00:04:27,000 --> 00:04:33,000
+practices by threat level or frequency of use to accelerate learning and implementation.
+
+54
+00:04:34,000 --> 00:04:38,000
+As I promised, let's provide a detailed overview of each technique.
+
+55
+00:04:39,000 --> 00:04:42,000
+As you saw, there are different ways to group these practices.
+
+56
+00:04:43,000 --> 00:04:48,000
+However, for the sake of this lesson, let's organize all the techniques by relevance and review them
+
+57
+00:04:48,000 --> 00:04:49,000
+in that order.
+
+58
+00:04:49,000 --> 00:04:54,000
+And in case you have any questions during the lesson, no need to wait till the end of the lesson.
+
+59
+00:04:54,000 --> 00:04:59,000
+Write them in Q and A section below the video and I will be happy to answer.
+
+60
+00:05:00,000 --> 00:05:04,000
+Let's take a deeper dive into each of these cloud security best practices.
+
+61
+00:05:04,000 --> 00:05:10,000
+Exploring why they are so important and how they contribute to securing cloud environments from critical
+
+62
+00:05:10,000 --> 00:05:11,000
+threats.
+
+63
+00:05:12,000 --> 00:05:17,000
+Starting with identity and access management, this is the backbone of cloud security.
+
+64
+00:05:18,000 --> 00:05:25,000
+By enforcing least privilege only given users and processes access to what they absolutely need, we
+
+65
+00:05:25,000 --> 00:05:28,000
+reduce the likelihood of unauthorized access.
+
+66
+00:05:28,000 --> 00:05:33,000
+For instance, if a user's credentials are compromised, limiting their permissions ensures that the
+
+67
+00:05:33,000 --> 00:05:37,000
+attacker can't move freely across your cloud infrastructure.
+
+68
+00:05:37,000 --> 00:05:43,000
+Role based access control plays a crucial part here, ensuring that each role has predefined permissions
+
+69
+00:05:43,000 --> 00:05:45,000
+that align with their tasks.
+
+70
+00:05:45,000 --> 00:05:51,000
+This not only mitigates the risk of insider threats, but also restricts external attacks, making it
+
+71
+00:05:51,000 --> 00:05:55,000
+harder for intruders to access sensitive resources.
+
+72
+00:05:56,000 --> 00:05:59,000
+Next we have data encryption, a cornerstone of cloud security.
+
+73
+00:05:59,000 --> 00:06:07,000
+Encrypting data, both in transit and at rest protects information from being accessed or tampered with
+
+74
+00:06:07,000 --> 00:06:09,000
+by unauthorized individuals.
+
+75
+00:06:10,000 --> 00:06:16,000
+Whether data is moving between your cloud storage and users, or simply being stored in a database.
+
+76
+00:06:16,000 --> 00:06:23,000
+Encryption ensures that it is unreadable to anyone who doesn't possess the decryption keys.
+
+77
+00:06:23,000 --> 00:06:29,000
+This practice is critical because even if attackers manage to intercept data, they cannot decipher
+
+78
+00:06:29,000 --> 00:06:34,000
+it without the encryption key, significantly reducing the risk of data breaches.
+
+79
+00:06:35,000 --> 00:06:40,000
+Now let's consider the importance of monitoring and auditing cloud environments.
+
+80
+00:06:40,000 --> 00:06:47,000
+In the dynamic world of cloud computing, environments are constantly changing, making continuous monitoring
+
+81
+00:06:47,000 --> 00:06:48,000
+essential.
+
+82
+00:06:49,000 --> 00:06:57,000
+By tracking user activity, access patterns and any unusual behavior you can detect and respond to potential
+
+83
+00:06:57,000 --> 00:07:00,000
+security incidents much faster.
+
+84
+00:07:01,000 --> 00:07:08,000
+Real time monitoring helps catch potential breaches early, while regular auditing ensures that policies
+
+85
+00:07:08,000 --> 00:07:13,000
+are being followed and that there are no hidden vulnerabilities in your system.
+
+86
+00:07:14,000 --> 00:07:20,000
+This visibility into your cloud infrastructure is key for proactive security management, allowing you
+
+87
+00:07:20,000 --> 00:07:25,000
+to make informed decisions and take corrective action before issues escalate.
+
+88
+00:07:26,000 --> 00:07:32,000
+The next practice, multi-factor authentication, adds another critical layer of protection.
+
+89
+00:07:33,000 --> 00:07:39,000
+Even if an attacker manages to steal a user's password, multi-factor authentication requires an additional
+
+90
+00:07:39,000 --> 00:07:46,000
+form of verification, such as a code sent to the mobile device or biometric authentication.
+
+91
+00:07:47,000 --> 00:07:54,000
+This means that a password alone isn't enough to access sensitive cloud resources, drastically reducing
+
+92
+00:07:54,000 --> 00:07:59,000
+the risk of account compromise, especially for privileged accounts.
+
+93
+00:07:59,000 --> 00:08:05,000
+Multi-factor authentication is particularly vital in cloud environments where access can be made from
+
+94
+00:08:05,000 --> 00:08:09,000
+anywhere, making it an essential defence against credential based attacks.
+
+95
+00:08:10,000 --> 00:08:14,000
+Another key component is the application of security patches and updates.
+
+96
+00:08:15,000 --> 00:08:20,000
+Cloud infrastructure, like any other software, is vulnerable to security flaws that are regularly
+
+97
+00:08:20,000 --> 00:08:23,000
+discovered and patched by vendors.
+
+98
+00:08:23,000 --> 00:08:30,000
+Delaying these updates leaves your systems exposed to known vulnerabilities that attackers can easily
+
+99
+00:08:30,000 --> 00:08:31,000
+exploit.
+
+100
+00:08:31,000 --> 00:08:37,000
+Automating the patching process or setting up regular maintenance windows ensures that your cloud environment
+
+101
+00:08:37,000 --> 00:08:44,000
+remains protected against the latest threats, which is crucial for staying ahead of potential exploits.
+
+102
+00:08:45,000 --> 00:08:49,000
+Finally, we have the use of cloud native security services.
+
+103
+00:08:49,000 --> 00:08:56,000
+Most cloud providers offer Of powerful built in security features like firewalls, DDoS protection,
+
+104
+00:08:56,000 --> 00:08:58,000
+and key management services.
+
+105
+00:08:59,000 --> 00:09:06,000
+These services are designed to integrate seamlessly with cloud infrastructures and offer scalable protection
+
+106
+00:09:06,000 --> 00:09:08,000
+that is tailored to cloud environments.
+
+107
+00:09:09,000 --> 00:09:15,000
+For example, using a cloud provider's DDoS protection service helps mitigate large scale attacks that
+
+108
+00:09:15,000 --> 00:09:17,000
+could overwhelm your systems.
+
+109
+00:09:17,000 --> 00:09:23,000
+While key management services ensure your encryption keys are stored and handled securely.
+
+110
+00:09:24,000 --> 00:09:30,000
+Leveraging these native tools means you are taking advantage of the security capabilities specifically
+
+111
+00:09:30,000 --> 00:09:36,000
+designed for the cloud, ensuring a stronger, more secure environment.
+
+112
+00:09:37,000 --> 00:09:45,000
+Let's explore this moderate relevance cloud security practices in greater detail, as they play a critical
+
+113
+00:09:45,000 --> 00:09:51,000
+role in addressing common security concerns and strengthening the overall security of cloud environments.
+
+114
+00:09:52,000 --> 00:09:58,000
+First, establishing strong backup and disaster recovery plans is essential for safeguarding critical,
+
+115
+00:09:58,000 --> 00:10:02,000
+cloud based data and applications in the cloud.
+
+116
+00:10:02,000 --> 00:10:08,000
+System failures, cyber attacks or natural disasters can lead to data loss.
+
+117
+00:10:08,000 --> 00:10:14,000
+Making reliable backup strategies crucial for recovery by implementing automated backups and ensuring
+
+118
+00:10:14,000 --> 00:10:18,000
+they are regularly scheduled, you maintain current copies of important data.
+
+119
+00:10:18,000 --> 00:10:21,000
+But it's not just about having backups.
+
+120
+00:10:21,000 --> 00:10:26,000
+Testing restore processes regularly ensures that you can recover quickly and effectively when needed.
+
+121
+00:10:27,000 --> 00:10:33,000
+A robust disaster recovery plan, thoroughly documented, outlines clear steps for restoring operations,
+
+122
+00:10:33,000 --> 00:10:36,000
+reducing downtime, and minimizing damage during an incident.
+
+123
+00:10:36,000 --> 00:10:44,000
+Without these precautions, a failure or attack could cause significant data loss and prolonged downtime.
+
+124
+00:10:44,000 --> 00:10:51,000
+Next, we have network segmentation within cloud environments, which is vital for isolating sensitive
+
+125
+00:10:51,000 --> 00:10:52,000
+resources.
+
+126
+00:10:53,000 --> 00:10:59,000
+Segmentation helps to divide the cloud network into distinct zones with strict access controls between
+
+127
+00:10:59,000 --> 00:11:00,000
+them.
+
+128
+00:11:01,000 --> 00:11:07,000
+This way, even if an attacker gains access to one part of the system, they can't easily move laterally
+
+129
+00:11:07,000 --> 00:11:10,000
+to access more sensitive data or services.
+
+130
+00:11:11,000 --> 00:11:17,000
+Think of network segmentation as creating digital barriers between different parts of your infrastructure.
+
+131
+00:11:18,000 --> 00:11:24,000
+Tools like virtual private clouds, subnets, and security groups are commonly used for this.
+
+132
+00:11:25,000 --> 00:11:31,000
+By isolating critical resources, you limit the scope of an attack and prevent unnecessary exposure,
+
+133
+00:11:31,000 --> 00:11:34,000
+enhancing the overall security of your cloud environment.
+
+134
+00:11:36,000 --> 00:11:42,000
+Another important practice is the regular review and audit of third party cloud service providers.
+
+135
+00:11:42,000 --> 00:11:49,000
+Many organizations rely on external cloud providers to manage part of their Infrastructure, which introduces
+
+136
+00:11:49,000 --> 00:11:51,000
+additional security risks.
+
+137
+00:11:51,000 --> 00:11:58,000
+If your provider has weak security practices, it could expose your data or systems to threats.
+
+138
+00:11:59,000 --> 00:12:04,000
+That's why it's essential to perform due diligence and regularly audit your provider's security posture,
+
+139
+00:12:05,000 --> 00:12:11,000
+checking their certifications such as ISO or SOC, and ensuring they meet industry standards helps you
+
+140
+00:12:11,000 --> 00:12:14,000
+maintain confidence in their security capabilities.
+
+141
+00:12:14,000 --> 00:12:20,000
+Without regular reviews, you risk relying on a provider with outdated or insufficient security measures,
+
+142
+00:12:20,000 --> 00:12:23,000
+which can create vulnerabilities in your own infrastructure.
+
+143
+00:12:24,000 --> 00:12:28,000
+Finally, let's talk about monitoring and securing API endpoints.
+
+144
+00:12:29,000 --> 00:12:35,000
+API serves as the communication channel between different parts of your cloud infrastructure or between
+
+145
+00:12:35,000 --> 00:12:40,000
+services, making them prime targets for attackers if not properly secured.
+
+146
+00:12:40,000 --> 00:12:46,000
+APIs can be abused to gain unauthorized access to data or manipulate services.
+
+147
+00:12:46,000 --> 00:12:53,000
+To prevent this, strong authentication measures like API keys or auth and encrypted communication must
+
+148
+00:12:53,000 --> 00:12:54,000
+be implemented.
+
+149
+00:12:54,000 --> 00:12:59,000
+Additionally, monitoring API traffic for abnormal activity.
+
+150
+00:12:59,000 --> 00:13:07,000
+Applying rate limits and logging all API interactions help detect and respond to potential threats early.
+
+151
+00:13:07,000 --> 00:13:14,000
+By securing these endpoints, you ensure that only authorized entities interact with your systems,
+
+152
+00:13:14,000 --> 00:13:16,000
+reducing the risk of data leakage or abuse.
+
+153
+00:13:18,000 --> 00:13:24,000
+Let's take a deeper dive into each of these low relevance cloud security practices, which, although
+
+154
+00:13:24,000 --> 00:13:31,000
+they may seem less urgent, are critical for addressing specific threats and filling gaps in your cloud
+
+155
+00:13:31,000 --> 00:13:32,000
+security strategy.
+
+156
+00:13:33,000 --> 00:13:39,000
+First, consider data loss prevention, which is essential for safeguarding sensitive information.
+
+157
+00:13:40,000 --> 00:13:46,000
+Cloud environments often host a wide range of data from personal, identifiable Quantifiable information
+
+158
+00:13:46,000 --> 00:13:52,000
+to financial records, and without the right controls, this data could be accidentally or maliciously
+
+159
+00:13:52,000 --> 00:13:54,000
+shared with unauthorized parties.
+
+160
+00:13:54,000 --> 00:14:00,000
+By implementing data loss prevention solutions, you can monitor data transfers and block any attempt
+
+161
+00:14:00,000 --> 00:14:04,000
+to share confidential information through unauthorized channels.
+
+162
+00:14:04,000 --> 00:14:10,000
+Data loss prevention policies work by identifying sensitive data and applying rules to prevent it from
+
+163
+00:14:10,000 --> 00:14:13,000
+leaving the organization without proper authorization.
+
+164
+00:14:13,000 --> 00:14:19,000
+This is particularly important in industries with strict regulatory requirements, such as healthcare
+
+165
+00:14:19,000 --> 00:14:26,000
+or finance, where the exposure of sensitive data can result in heavy fines and reputational damage.
+
+166
+00:14:27,000 --> 00:14:33,000
+Next is the importance of regular penetration testing, while having strong security configurations
+
+167
+00:14:33,000 --> 00:14:35,000
+in place is necessary.
+
+168
+00:14:35,000 --> 00:14:39,000
+Testing those configurations through simulated attacks is critical.
+
+169
+00:14:40,000 --> 00:14:46,000
+Penetration testing mimics real world attack scenarios, allowing you to identify vulnerabilities that
+
+170
+00:14:46,000 --> 00:14:49,000
+might otherwise go unnoticed.
+
+171
+00:14:49,000 --> 00:14:55,000
+These tests provide valuable feedback on potential weak points in your cloud infrastructure, and allow
+
+172
+00:14:55,000 --> 00:14:59,000
+you to patch vulnerabilities before attackers can exploit them.
+
+173
+00:14:59,000 --> 00:15:05,000
+By performing regular penetration testing, either through automated tools or by hiring third party
+
+174
+00:15:05,000 --> 00:15:12,000
+firms, you ensure that your security defenses are always up to date and capable of withstanding evolving
+
+175
+00:15:12,000 --> 00:15:13,000
+threats.
+
+176
+00:15:15,000 --> 00:15:20,000
+Then we have container and serverless security best practices, which are becoming increasingly important
+
+177
+00:15:20,000 --> 00:15:25,000
+as microservices architectures are widely adopted in cloud environments.
+
+178
+00:15:25,000 --> 00:15:32,000
+Containers and serverless computing offer great flexibility, but they also introduce new security risks.
+
+179
+00:15:33,000 --> 00:15:40,000
+Without proper security controls, attackers could compromise insecure container images or exploit vulnerabilities
+
+180
+00:15:40,000 --> 00:15:45,000
+in serverless functions, which could lead to unauthorized access or data leakage.
+
+181
+00:15:46,000 --> 00:15:50,000
+To mitigate these risks, it's important to use secure, verified images.
+
+182
+00:15:50,000 --> 00:15:56,000
+Apply the principle of least privilege to container permissions and ensure that workloads are isolated
+
+183
+00:15:56,000 --> 00:15:57,000
+from one another.
+
+184
+00:15:57,000 --> 00:16:02,000
+This approach minimizes the blast radius if one component is compromised, preventing the attack from
+
+185
+00:16:02,000 --> 00:16:04,000
+spreading across the system.
+
+186
+00:16:05,000 --> 00:16:09,000
+The next crucial practice is cloud user training and awareness programs.
+
+187
+00:16:09,000 --> 00:16:16,000
+Even with the most sophisticated security controls in place, human error remains one of the top causes
+
+188
+00:16:16,000 --> 00:16:17,000
+of security breaches.
+
+189
+00:16:17,000 --> 00:16:24,000
+Social engineering attacks, particularly phishing, target cloud users and administrators directly
+
+190
+00:16:24,000 --> 00:16:31,000
+attempting to trick them into divulging credentials or clicking on malicious links by providing regular
+
+191
+00:16:31,000 --> 00:16:33,000
+training and awareness programs.
+
+192
+00:16:33,000 --> 00:16:40,000
+Organizations can educate their employees about the latest phishing tactics and social engineering risks,
+
+193
+00:16:40,000 --> 00:16:44,000
+empowering them to recognize and report suspicious activities.
+
+194
+00:16:44,000 --> 00:16:51,000
+Continuous training also reinforces the importance of following security best practices, ensuring that
+
+195
+00:16:51,000 --> 00:16:55,000
+users stay vigilant and act as an additional layer of defence.
+
+196
+00:16:56,000 --> 00:17:00,000
+Finally, we have regular reviews of cloud service level agreements.
+
+197
+00:17:01,000 --> 00:17:06,000
+Service level agreements are formal contracts between an organisation and its cloud service provider,
+
+198
+00:17:06,000 --> 00:17:11,000
+outlining the security, privacy and availability standards that must be maintained.
+
+199
+00:17:12,000 --> 00:17:18,000
+Regularly reviewing these agreements is important to ensure that your provider is meeting their obligations,
+
+200
+00:17:18,000 --> 00:17:21,000
+especially as security needs evolve over time.
+
+201
+00:17:22,000 --> 00:17:28,000
+For example, if new compliance regulations are introduced or if there are changes in your operational
+
+202
+00:17:28,000 --> 00:17:35,000
+requirements, you need to verify that your provider is still aligned with your security and privacy
+
+203
+00:17:35,000 --> 00:17:35,000
+needs.
+
+204
+00:17:36,000 --> 00:17:42,000
+This proactive approach ensures that your provider continues to meet agreed upon standards and helps
+
+205
+00:17:42,000 --> 00:17:45,000
+avoid gaps in your overall security posture.
+
+206
+00:17:47,000 --> 00:17:53,000
+Let's summarize and conclude the cloud security best practices structured by their relevance to security
+
+207
+00:17:53,000 --> 00:17:55,000
+and threat mitigation.
+
+208
+00:17:56,000 --> 00:17:58,000
+Starting with the high relevance practices.
+
+209
+00:17:58,000 --> 00:18:05,000
+These focus on critical threat mitigation, which are essential for maintaining the core security of
+
+210
+00:18:05,000 --> 00:18:06,000
+cloud environments.
+
+211
+00:18:06,000 --> 00:18:13,000
+We learned that identity and access management is vital in ensuring that users and processes have the
+
+212
+00:18:13,000 --> 00:18:16,000
+least privilege necessary, reducing the risk of unauthorized access.
+
+213
+00:18:17,000 --> 00:18:23,000
+Similarly, encryption of data, both in transit and at rest is essential to protect sensitive information
+
+214
+00:18:23,000 --> 00:18:25,000
+from being exposed or intercepted.
+
+215
+00:18:25,000 --> 00:18:31,000
+Regular monitoring and auditing play a crucial role in detecting unusual activity, allowing you to
+
+216
+00:18:31,000 --> 00:18:33,000
+respond quickly to potential security incidents.
+
+217
+00:18:34,000 --> 00:18:40,000
+Moreover, multi-factor authentication strengthens account security, especially for privileged users,
+
+218
+00:18:40,000 --> 00:18:45,000
+making it significantly harder for attackers to gain unauthorized access.
+
+219
+00:18:45,000 --> 00:18:51,000
+Keeping cloud infrastructure updated with the latest security patches prevents attackers from exploiting
+
+220
+00:18:51,000 --> 00:18:53,000
+known vulnerabilities.
+
+221
+00:18:53,000 --> 00:19:01,000
+Finally, using cloud provider native security services like firewalls, DDoS protection and key management
+
+222
+00:19:01,000 --> 00:19:07,000
+adds an extra layer of security that is specifically tailored for cloud environments, ensuring they
+
+223
+00:19:07,000 --> 00:19:10,000
+remain robust against various threats.
+
+224
+00:19:11,000 --> 00:19:13,000
+Moving on to the moderate relevance practices.
+
+225
+00:19:13,000 --> 00:19:16,000
+These address common security concerns.
+
+226
+00:19:17,000 --> 00:19:24,000
+Having strong backup and disaster recovery plans ensures that even in the event of a failure or attack,
+
+227
+00:19:24,000 --> 00:19:30,000
+critical data can be restored, minimizing downtime and preventing data loss.
+
+228
+00:19:31,000 --> 00:19:37,000
+Network segmentation is another important practice, helping to isolate sensitive resources and prevent
+
+229
+00:19:37,000 --> 00:19:40,000
+attackers from moving laterally across your cloud environment.
+
+230
+00:19:41,000 --> 00:19:48,000
+Regular review and auditing of third party providers ensures that the security of external services
+
+231
+00:19:48,000 --> 00:19:54,000
+is aligned with your internal standards, reducing the risk of vulnerabilities in the supply chain.
+
+232
+00:19:54,000 --> 00:20:02,000
+Additionally, securing API endpoints is vital as these can serve as potential entry points for attackers
+
+233
+00:20:02,000 --> 00:20:04,000
+if not properly protected.
+
+234
+00:20:04,000 --> 00:20:09,000
+APIs must be continuously monitored to prevent unauthorized access and abuse.
+
+235
+00:20:10,000 --> 00:20:17,000
+Lastly, we covered the low relevance practices which focus on edge cases and lesser known threats.
+
+236
+00:20:17,000 --> 00:20:23,000
+These practices include the implementation of data loss prevention solutions, which help prevent the
+
+237
+00:20:23,000 --> 00:20:26,000
+unauthorized sharing of sensitive information.
+
+238
+00:20:26,000 --> 00:20:28,000
+Adding an extra layer of control.
+
+239
+00:20:29,000 --> 00:20:36,000
+Regular penetration testing allows organizations to identify vulnerabilities before attackers can exploit
+
+240
+00:20:36,000 --> 00:20:38,000
+them, ensuring proactive defense Fans.
+
+241
+00:20:38,000 --> 00:20:45,000
+Container and serverless security measures are increasingly important as microservices become more common
+
+242
+00:20:45,000 --> 00:20:51,000
+in cloud architectures, with the need for secure management of these technologies, continuous training
+
+243
+00:20:51,000 --> 00:20:57,000
+and awareness programs ensure that cloud users and administrators remain vigilant, particularly against
+
+244
+00:20:57,000 --> 00:21:00,000
+phishing and social engineering attacks.
+
+245
+00:21:00,000 --> 00:21:06,000
+Finally, regular review of service level agreements with cloud providers ensures that security and
+
+246
+00:21:06,000 --> 00:21:11,000
+privacy standards are met over time as operational needs evolve.
+
+247
+00:21:13,000 --> 00:21:15,000
+That's all what I wanted to discuss with you in the lesson.
+
+248
+00:21:15,000 --> 00:21:18,000
+Let's recap what we have learned from the lesson.
+
+249
+00:21:19,000 --> 00:21:26,000
+We learned how to implement strong identity and access management controls, and enforce least privilege
+
+250
+00:21:26,000 --> 00:21:28,000
+to limit access to cloud resources.
+
+251
+00:21:29,000 --> 00:21:37,000
+You now understand the importance of encrypting sensitive data both in transit and at rest, using industry
+
+252
+00:21:37,000 --> 00:21:39,000
+standard encryption protocols.
+
+253
+00:21:40,000 --> 00:21:46,000
+We explored the need for regular monitoring and auditing of cloud environments to detect unusual activity
+
+254
+00:21:46,000 --> 00:21:48,000
+and prevent security incidents.
+
+255
+00:21:48,000 --> 00:21:54,000
+Together, we implemented multi-factor authentication for user accounts, especially for privileged
+
+256
+00:21:54,000 --> 00:21:57,000
+users, to strengthen access controls.
+
+257
+00:21:57,000 --> 00:22:03,000
+We reviewed the process of applying security patches and updates to cloud infrastructure, ensuring
+
+258
+00:22:03,000 --> 00:22:06,000
+systems remain protected against vulnerabilities.
+
+259
+00:22:07,000 --> 00:22:14,000
+I demonstrated how to use cloud provider native security services, such as firewalls and key management
+
+260
+00:22:14,000 --> 00:22:16,000
+to enhance cloud security.
+
+261
+00:22:17,000 --> 00:22:23,000
+Finally, we covered best practices for reviewing and managing backup and disaster recovery plans,
+
+262
+00:22:23,000 --> 00:22:27,000
+third party audits, and securing API endpoints.
+
+263
+00:22:28,000 --> 00:22:30,000
+That's all for this lesson.
+
+264
+00:22:30,000 --> 00:22:32,000
+Thanks a lot for your attention.
+
+265
+00:22:32,000 --> 00:22:35,000
+Have a great day and see you in the next lesson.
+
diff --git a/76 - Cybersecurity Comprehensive Security Practices for Developers/013 Mobile Application Security_en.srt b/76 - Cybersecurity Comprehensive Security Practices for Developers/013 Mobile Application Security_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..d7eb650527982b895d5700be918bfc543bc1c132
--- /dev/null
+++ b/76 - Cybersecurity Comprehensive Security Practices for Developers/013 Mobile Application Security_en.srt
@@ -0,0 +1,1148 @@
+1
+00:00:05,000 --> 00:00:07,000
+Hello dear team.
+
+2
+00:00:07,000 --> 00:00:12,000
+In this lesson we will focus on the key principles of mobile application security, highlighting essential
+
+3
+00:00:12,000 --> 00:00:17,000
+practices to protect user data and maintain the integrity of your applications.
+
+4
+00:00:18,000 --> 00:00:25,000
+The overall goal is to ensure that sensitive information is safeguarded while preventing unauthorized
+
+5
+00:00:25,000 --> 00:00:26,000
+access to the app.
+
+6
+00:00:27,000 --> 00:00:34,000
+Strong security measures are required to maintain user trust and to ensure compliance with privacy regulations.
+
+7
+00:00:35,000 --> 00:00:41,000
+Additionally, protecting data during both its transmission and storage is fundamental to keeping it
+
+8
+00:00:41,000 --> 00:00:43,000
+safe from potential attackers.
+
+9
+00:00:43,000 --> 00:00:48,000
+We will also cover important strategies for securing how your app interacts with external systems,
+
+10
+00:00:48,000 --> 00:00:52,000
+ensuring that connections are protected and that vulnerabilities are minimized.
+
+11
+00:00:53,000 --> 00:00:59,000
+Another critical aspect of mobile app security is the ability to detect and respond to threats in real
+
+12
+00:00:59,000 --> 00:01:03,000
+time, as well as keeping the app up to date to address evolving risks.
+
+13
+00:01:04,000 --> 00:01:10,000
+Together, these approaches will help you build a robust security framework that mitigates risks and
+
+14
+00:01:10,000 --> 00:01:14,000
+helps your mobile app operate securely in a dynamic environment.
+
+15
+00:01:14,000 --> 00:01:16,000
+Let's start our lesson.
+
+16
+00:01:17,000 --> 00:01:23,000
+In this lesson, we'll be exploring mobile application security best practices organized by their relevance
+
+17
+00:01:23,000 --> 00:01:25,000
+to the most critical threats.
+
+18
+00:01:26,000 --> 00:01:33,000
+The high relevance items focus on the most essential defenses, such as implementing strong authentication
+
+19
+00:01:33,000 --> 00:01:36,000
+mechanisms and encrypting sensitive data.
+
+20
+00:01:37,000 --> 00:01:44,000
+These practices form the foundation of mobile app security by ensuring that only authorized users can
+
+21
+00:01:44,000 --> 00:01:51,000
+access sensitive information, and the data remains secure, both while being transmitted and stored.
+
+22
+00:01:51,000 --> 00:01:56,000
+Regular updates and secure storage of credentials are also crucial to prevent vulnerabilities that could
+
+23
+00:01:56,000 --> 00:01:58,000
+be exploited by attackers.
+
+24
+00:01:59,000 --> 00:02:04,000
+As we delve into the moderate and low relevance practices, we'll look at strategies like secure coding,
+
+25
+00:02:04,000 --> 00:02:10,000
+ensuring safe communication between the app and backend services, and preventing reverse engineering
+
+26
+00:02:10,000 --> 00:02:11,000
+through code obfuscation.
+
+27
+00:02:11,000 --> 00:02:18,000
+We will also touch on lesser known threats such as controlling app permissions, detecting tampered
+
+28
+00:02:18,000 --> 00:02:21,000
+devices, and monitoring for suspicious activity.
+
+29
+00:02:21,000 --> 00:02:27,000
+These practices may not be as critical as the high relevance items, but they still play an important
+
+30
+00:02:27,000 --> 00:02:32,000
+role in hardening the app against a broader range of potential attacks.
+
+31
+00:02:32,000 --> 00:02:38,000
+We'll be going over each of these in more detail to understand how they contribute to a comprehensive
+
+32
+00:02:38,000 --> 00:02:39,000
+mobile security strategy.
+
+33
+00:02:40,000 --> 00:02:48,000
+This list categorizes mobile application security best practices by complexity, offering a way to progressively
+
+34
+00:02:48,000 --> 00:02:52,000
+build your understanding from beginner to advanced techniques.
+
+35
+00:02:52,000 --> 00:02:59,000
+At the basic level, we start with essential practices like applying security updates, Encrypting sensitive
+
+36
+00:02:59,000 --> 00:03:02,000
+data and securely storing credentials.
+
+37
+00:03:02,000 --> 00:03:09,000
+These are foundational steps that every mobile app should implement to prevent obvious security vulnerabilities.
+
+38
+00:03:09,000 --> 00:03:16,000
+Additionally, implementing strong authentication mechanisms and adhering to privacy regulations ensures
+
+39
+00:03:16,000 --> 00:03:19,000
+that user data is protected from unauthorized access.
+
+40
+00:03:20,000 --> 00:03:26,000
+As you move to the intermediate and advanced levels, more sophisticated practices come into play.
+
+41
+00:03:26,000 --> 00:03:34,000
+For instance, secure coding and API validation help protect the back end from attacks like SQL injection,
+
+42
+00:03:34,000 --> 00:03:41,000
+while advanced techniques like tamper detection and real time monitoring defend against threats in dynamic
+
+43
+00:03:41,000 --> 00:03:42,000
+environments.
+
+44
+00:03:42,000 --> 00:03:47,000
+This layered approach allows for flexibility in how you prioritize your learning, depending on the
+
+45
+00:03:47,000 --> 00:03:51,000
+specific challenges or risks faced by your mobile application.
+
+46
+00:03:51,000 --> 00:03:57,000
+You can also use different categorization techniques, such as relevance or risk, to help you focus
+
+47
+00:03:57,000 --> 00:04:02,000
+on the principles that are most applicable to your project or threat landscape.
+
+48
+00:04:03,000 --> 00:04:07,000
+As I promised, let's provide a detailed overview of each technique.
+
+49
+00:04:07,000 --> 00:04:11,000
+As you saw, there are different ways to group these practices.
+
+50
+00:04:11,000 --> 00:04:16,000
+However, for the sake of this lesson, let's organize all the techniques by relevance and review them
+
+51
+00:04:16,000 --> 00:04:17,000
+in that order.
+
+52
+00:04:18,000 --> 00:04:23,000
+And in case you have any questions during the lesson, no need to wait till the end of the lesson.
+
+53
+00:04:23,000 --> 00:04:27,000
+Write them in the Q&A section below the video and I will be happy to answer.
+
+54
+00:04:29,000 --> 00:04:35,000
+Let's dive deeper into this high relevance mobile application security practices to better understand
+
+55
+00:04:35,000 --> 00:04:42,000
+their significance and how they contribute to a secure and well-rounded strategy for mobile applications.
+
+56
+00:04:42,000 --> 00:04:47,000
+First, consider authentication and authorization mechanisms.
+
+57
+00:04:47,000 --> 00:04:54,000
+It's not enough to rely on just usernames and passwords anymore, as these can be easily compromised.
+
+58
+00:04:54,000 --> 00:05:01,000
+Instead, by implementing Multi-factor authentication, we add another layer of protection, for example,
+
+59
+00:05:01,000 --> 00:05:07,000
+requiring users to input a password and then a code sent to their phone ensures that even if a password
+
+60
+00:05:07,000 --> 00:05:11,000
+is stolen, access can't be gained without the second factor.
+
+61
+00:05:11,000 --> 00:05:14,000
+This significantly reduces the risk of unauthorised access.
+
+62
+00:05:14,000 --> 00:05:20,000
+On the flip side, relying solely on passwords without any additional verification leaves the app vulnerable
+
+63
+00:05:20,000 --> 00:05:24,000
+to brute force attacks, phishing or credential theft.
+
+64
+00:05:24,000 --> 00:05:31,000
+Making multi-factor authentication essential for modern mobile security, secure token management is
+
+65
+00:05:31,000 --> 00:05:39,000
+equally important, ensuring that tokens used for session authentication are securely stored and rotated
+
+66
+00:05:39,000 --> 00:05:43,000
+regularly so they aren't exposed or reused by attackers.
+
+67
+00:05:44,000 --> 00:05:48,000
+Now let's talk about encryption of sensitive data.
+
+68
+00:05:48,000 --> 00:05:56,000
+Encryption ensures that data is scrambled into an unreadable format that can only be decrypted with
+
+69
+00:05:56,000 --> 00:06:01,000
+a key, making it crucial for both data in transit and data at rest.
+
+70
+00:06:02,000 --> 00:06:07,000
+For example, when a user's banking information is transmitted from their phone to a server.
+
+71
+00:06:07,000 --> 00:06:14,000
+Using encryption protocols ensures that even if the data is intercepted, it remains unreadable.
+
+72
+00:06:14,000 --> 00:06:16,000
+To the attacker.
+
+73
+00:06:16,000 --> 00:06:22,000
+Similarly, storing sensitive information like credit card numbers or personal details on the device
+
+74
+00:06:22,000 --> 00:06:27,000
+without encryption could lead to devastating consequences if the device is compromised.
+
+75
+00:06:28,000 --> 00:06:34,000
+Encrypting this data prevents unauthorized access and ensures that sensitive information stays secure,
+
+76
+00:06:34,000 --> 00:06:37,000
+even if it falls into the wrong hands.
+
+77
+00:06:38,000 --> 00:06:41,000
+Another key practice is regular security updates.
+
+78
+00:06:41,000 --> 00:06:47,000
+In today's fast moving threat landscape, security vulnerabilities are discovered frequently, and failing
+
+79
+00:06:47,000 --> 00:06:51,000
+to apply patches can expose apps to well known exploits.
+
+80
+00:06:51,000 --> 00:06:57,000
+Hackers often target apps that aren't updated because these are easy to exploit.
+
+81
+00:06:57,000 --> 00:07:03,000
+For instance, a developer who pushes regular updates and patches as soon as new vulnerabilities are
+
+82
+00:07:03,000 --> 00:07:09,000
+identified ensures that the app remains secure and up to date with the latest defenses.
+
+83
+00:07:10,000 --> 00:07:15,000
+On the other hand, neglecting updates leaves the app wide open to exploitation by attackers who know
+
+84
+00:07:15,000 --> 00:07:17,000
+how to take advantage of outdated systems.
+
+85
+00:07:18,000 --> 00:07:24,000
+Next, consider the protection of sensitive user data with increasing regulations such as GDPR and CcpA.
+
+86
+00:07:24,000 --> 00:07:27,000
+It's no longer just about protecting user data.
+
+87
+00:07:28,000 --> 00:07:33,000
+It's about doing so in a way that complies with privacy laws.
+
+88
+00:07:33,000 --> 00:07:39,000
+This means minimizing the amount of data you collect and storing it securely, and being transparent
+
+89
+00:07:39,000 --> 00:07:42,000
+with users about how their data is being used.
+
+90
+00:07:43,000 --> 00:07:50,000
+For example, an app that collects only the necessary data for functionality and provides users with
+
+91
+00:07:50,000 --> 00:07:55,000
+clear privacy notices, builds trust and complies with legal standards.
+
+92
+00:07:56,000 --> 00:08:03,000
+On the other hand, apps that collect excessive amounts of data or fail to inform users of their privacy
+
+93
+00:08:03,000 --> 00:08:08,000
+practices risk both user distrust and legal consequences.
+
+94
+00:08:09,000 --> 00:08:13,000
+Lastly, we must address secure storage of sensitive information.
+
+95
+00:08:13,000 --> 00:08:20,000
+Mobile apps often deal with credentials, passwords, and session tokens that need to be stored securely
+
+96
+00:08:21,000 --> 00:08:30,000
+using device native secure storage mechanisms like keychain on iOS or Keystore on Android provides an
+
+97
+00:08:30,000 --> 00:08:33,000
+encrypted and protected environment for the sensitive data.
+
+98
+00:08:34,000 --> 00:08:41,000
+Storing these elements in easily accessible areas like local storage, would leave them vulnerable to
+
+99
+00:08:41,000 --> 00:08:43,000
+attackers if the device is compromised.
+
+100
+00:08:44,000 --> 00:08:51,000
+By storing this data in a secure and encrypted format, you greatly reduce the risk of it being exposed
+
+101
+00:08:51,000 --> 00:08:53,000
+in the event of a device breach.
+
+102
+00:08:55,000 --> 00:09:01,000
+Let's take a deeper look at each of the moderate relevance mobile application security practices.
+
+103
+00:09:01,000 --> 00:09:07,000
+Elaborating on how they enhance the security of mobile applications and why they are important in real
+
+104
+00:09:07,000 --> 00:09:08,000
+world scenarios.
+
+105
+00:09:09,000 --> 00:09:15,000
+We start with secure coding practices, which are foundational to preventing some of the most common
+
+106
+00:09:15,000 --> 00:09:20,000
+and dangerous vulnerabilities like SQL injection and cross-site scripting.
+
+107
+00:09:21,000 --> 00:09:26,000
+Secure coding ensures that the app's code does not leave gaps that attackers can exploit.
+
+108
+00:09:27,000 --> 00:09:32,000
+For example, SQL injection occurs when malicious input is used to manipulate a database query, potentially
+
+109
+00:09:32,000 --> 00:09:35,000
+allowing an attacker to access sensitive data.
+
+110
+00:09:35,000 --> 00:09:40,000
+By adopting secure coding practices such as parameterized queries, developers can safeguard against
+
+111
+00:09:40,000 --> 00:09:42,000
+this kind of attack.
+
+112
+00:09:42,000 --> 00:09:48,000
+Likewise, buffer overflows where excess data overruns a buffer's boundaries, can allow attackers to
+
+113
+00:09:48,000 --> 00:09:56,000
+inject malicious code into an application properly validating input sizes and bounds in your code ensures
+
+114
+00:09:56,000 --> 00:09:59,000
+that your application doesn't become vulnerable to this.
+
+115
+00:09:59,000 --> 00:10:06,000
+It's not just about writing functional code, it's about writing hardened code that anticipates potential
+
+116
+00:10:06,000 --> 00:10:08,000
+attack vectors.
+
+117
+00:10:08,000 --> 00:10:15,000
+Next, we delve into secure communication between the mobile app and back end services.
+
+118
+00:10:15,000 --> 00:10:21,000
+Whenever data is exchanged between the app and the server, whether it's user credentials, financial
+
+119
+00:10:21,000 --> 00:10:27,000
+information, or any other sensitive data, it must be securely transmitted to prevent interception.
+
+120
+00:10:28,000 --> 00:10:36,000
+This use of SSL TLS encryption ensures that all data in transit is encrypted, so even if a malicious
+
+121
+00:10:36,000 --> 00:10:40,000
+actor intercepts the communication, they cannot make sense of the data.
+
+122
+00:10:41,000 --> 00:10:48,000
+For instance, transmitting passwords or session tokens over HTTP would expose that data to attackers,
+
+123
+00:10:48,000 --> 00:10:51,000
+who could then steal credentials or hijack sessions.
+
+124
+00:10:51,000 --> 00:10:54,000
+Using properly configured SSL.
+
+125
+00:10:54,000 --> 00:11:02,000
+TLS certificates not only encrypts data, but also verifies the identity of the server, further reducing
+
+126
+00:11:02,000 --> 00:11:05,000
+the risk of man in the middle attacks.
+
+127
+00:11:06,000 --> 00:11:12,000
+The third practice is secure API use, which is crucial as APIs are often the gateways through which
+
+128
+00:11:12,000 --> 00:11:15,000
+mobile apps communicate with back end systems.
+
+129
+00:11:15,000 --> 00:11:22,000
+APIs must be protected to ensure that unauthorized users or malicious actors can't access sensitive
+
+130
+00:11:22,000 --> 00:11:23,000
+endpoints.
+
+131
+00:11:23,000 --> 00:11:28,000
+This is where proper validation and authorization come into play.
+
+132
+00:11:28,000 --> 00:11:35,000
+By using methods like Oauth2 for authentication and authorization, you ensure that only users who are
+
+133
+00:11:35,000 --> 00:11:38,000
+properly authenticated can access certain data or services.
+
+134
+00:11:38,000 --> 00:11:44,000
+Additionally, validating the input passed through these APIs ensures that attackers cannot inject malicious
+
+135
+00:11:44,000 --> 00:11:46,000
+data to manipulate the system.
+
+136
+00:11:46,000 --> 00:11:52,000
+For example, if an API allows an unauthenticated user to retrieve data without proper access, control,
+
+137
+00:11:52,000 --> 00:11:55,000
+it opens the door to data breaches and misuse of services.
+
+138
+00:11:56,000 --> 00:12:00,000
+We then look at protection against reverse engineering.
+
+139
+00:12:00,000 --> 00:12:07,000
+A key concern for mobile apps, where the source code can be easily decompiled if not properly protected.
+
+140
+00:12:08,000 --> 00:12:15,000
+Attackers might reverse engineer an app to learn its functionality, find weaknesses, or extract sensitive
+
+141
+00:12:15,000 --> 00:12:18,000
+information by using code obfuscation tools.
+
+142
+00:12:18,000 --> 00:12:25,000
+The app's code is transformed into a version that is hard to read and understand, making it difficult
+
+143
+00:12:25,000 --> 00:12:27,000
+for an attacker to reverse engineer.
+
+144
+00:12:28,000 --> 00:12:34,000
+Additionally, securing the app's source code involves encrypting sensitive parts of the code and ensuring
+
+145
+00:12:34,000 --> 00:12:38,000
+that debugging features are disabled in production environments.
+
+146
+00:12:38,000 --> 00:12:46,000
+Without these protections, attackers can tamper with the app or even inject malicious code that compromises
+
+147
+00:12:46,000 --> 00:12:47,000
+user data.
+
+148
+00:12:48,000 --> 00:12:52,000
+Finally, we come to regular security testing and vulnerability assessments.
+
+149
+00:12:52,000 --> 00:12:59,000
+As mobile applications grow and evolve with new features and updates, new vulnerabilities can be introduced
+
+150
+00:12:59,000 --> 00:13:04,000
+either in the app itself or through dependencies like third party libraries.
+
+151
+00:13:05,000 --> 00:13:11,000
+Regular penetration testing helps developers identify potential weaknesses that can be exploited by
+
+152
+00:13:11,000 --> 00:13:12,000
+attackers.
+
+153
+00:13:12,000 --> 00:13:18,000
+For example, running periodic static analysis of the code can highlight vulnerabilities like insecure
+
+154
+00:13:18,000 --> 00:13:22,000
+data storage or insecure API use.
+
+155
+00:13:22,000 --> 00:13:28,000
+These tests should be scheduled frequently, and particularly before major updates, to ensure that
+
+156
+00:13:28,000 --> 00:13:32,000
+new code doesn't open up new attack vectors.
+
+157
+00:13:33,000 --> 00:13:39,000
+Neglecting regular security testing leaves an app vulnerable to undetected flaws that attackers could
+
+158
+00:13:39,000 --> 00:13:41,000
+exploit over time.
+
+159
+00:13:43,000 --> 00:13:50,000
+Let's go into more detail on these low relevance mobile application security practices and explore how
+
+160
+00:13:50,000 --> 00:13:56,000
+each plays a significant role in addressing edge case threats and lesser known vulnerabilities, ensuring
+
+161
+00:13:56,000 --> 00:13:59,000
+a more comprehensive security approach for mobile apps.
+
+162
+00:14:00,000 --> 00:14:06,000
+First, we have prevention of data leakage by restricting app permissions to only what is necessary
+
+163
+00:14:06,000 --> 00:14:08,000
+for its core functionality.
+
+164
+00:14:08,000 --> 00:14:15,000
+When an app requests excessive permissions like access to location data, the user's context, or even
+
+165
+00:14:15,000 --> 00:14:20,000
+camera and microphone without a real need, it opens up unnecessary security risks.
+
+166
+00:14:20,000 --> 00:14:25,000
+Attackers, or even malicious apps could exploit these permissions to harvest sensitive user data.
+
+167
+00:14:26,000 --> 00:14:30,000
+Imagine a simple note taking app asking for access to your phone's contacts.
+
+168
+00:14:30,000 --> 00:14:36,000
+It doesn't need this data, so allowing it increases the risk of data leakage by carefully reviewing
+
+169
+00:14:36,000 --> 00:14:41,000
+and limiting permissions to only those that are absolutely necessary.
+
+170
+00:14:41,000 --> 00:14:46,000
+We not only reduce the attack surface, but also force the user trust.
+
+171
+00:14:46,000 --> 00:14:51,000
+For example, a weather app should only request location access if it's using that data to provide weather
+
+172
+00:14:51,000 --> 00:14:52,000
+updates.
+
+173
+00:14:52,000 --> 00:14:53,000
+Nothing more.
+
+174
+00:14:53,000 --> 00:15:00,000
+Broad permission requests not only risk user privacy, but also open up the potential for third party
+
+175
+00:15:00,000 --> 00:15:02,000
+abuse if the app is compromised.
+
+176
+00:15:02,000 --> 00:15:04,000
+Next is tamper detection.
+
+177
+00:15:04,000 --> 00:15:12,000
+So jailbroken or rooted device checks a jailbroken or rooted device allows the user to bypass the operating
+
+178
+00:15:12,000 --> 00:15:19,000
+system's built in security controls, which can expose sensitive data, enable app tampering, or allow
+
+179
+00:15:19,000 --> 00:15:21,000
+malicious code injection.
+
+180
+00:15:22,000 --> 00:15:27,000
+On such compromised devices, even the best designed app can become vulnerable.
+
+181
+00:15:27,000 --> 00:15:34,000
+Tamper detection mechanisms allow the app to detect when it's being run on a compromised device and
+
+182
+00:15:34,000 --> 00:15:39,000
+respond accordingly, either by disabling sensitive features or refusing to run at all.
+
+183
+00:15:39,000 --> 00:15:46,000
+For instance, a financial app might detect that it's on a rooted device and block access to transactions,
+
+184
+00:15:46,000 --> 00:15:52,000
+thereby preventing sensitive financial information from being exposed or altered.
+
+185
+00:15:52,000 --> 00:15:59,000
+By doing this, the app ensures that it only functions in secure environments, which reduces the likelihood
+
+186
+00:15:59,000 --> 00:16:00,000
+of being exploited.
+
+187
+00:16:02,000 --> 00:16:08,000
+Monitoring for suspicious activity is another critical practice, although it may seem like a behind
+
+188
+00:16:08,000 --> 00:16:09,000
+the scenes measure.
+
+189
+00:16:10,000 --> 00:16:15,000
+Many attackers rely on the fact that abnormal behaviour in apps often goes unnoticed.
+
+190
+00:16:15,000 --> 00:16:22,000
+By setting up real time monitoring for suspicious actions, such as an unusually high number of failed
+
+191
+00:16:22,000 --> 00:16:30,000
+login attempts, strange access patterns, or unexpected file transfers, the app can proactively identify
+
+192
+00:16:30,000 --> 00:16:32,000
+potential threats before they escalate.
+
+193
+00:16:33,000 --> 00:16:36,000
+This is akin to installing a security alarm in a house.
+
+194
+00:16:36,000 --> 00:16:41,000
+You may not always expect a break in, but it's crucial to have alerts in place for when something out
+
+195
+00:16:41,000 --> 00:16:43,000
+of the ordinary happens.
+
+196
+00:16:43,000 --> 00:16:49,000
+For example, detecting repeated failed login attempts from a single device could indicate a brute force
+
+197
+00:16:49,000 --> 00:16:56,000
+attack, enabling the app to temporarily lock the account or request additional authentication steps.
+
+198
+00:16:56,000 --> 00:17:04,000
+Failing to monitor activity means potential breaches could go unnoticed until they have already caused
+
+199
+00:17:04,000 --> 00:17:05,000
+significant damage.
+
+200
+00:17:06,000 --> 00:17:13,000
+Then there is the use of in-app security tools such as runtime application self-protection.
+
+201
+00:17:13,000 --> 00:17:20,000
+Unlike traditional security tools that work externally, runtime application self-protection is embedded
+
+202
+00:17:20,000 --> 00:17:22,000
+within the app itself.
+
+203
+00:17:22,000 --> 00:17:26,000
+Monitoring for threats and taking action during runtime.
+
+204
+00:17:26,000 --> 00:17:34,000
+This means the app can detect and block attacks while it is being used, even if the attacker has bypassed
+
+205
+00:17:34,000 --> 00:17:35,000
+other security layers.
+
+206
+00:17:36,000 --> 00:17:43,000
+For instance, if someone attempts to reverse engineer the app while it's running, runtime application
+
+207
+00:17:43,000 --> 00:17:48,000
+self-protection can detect this tampering and shut down the app to prevent further damage.
+
+208
+00:17:49,000 --> 00:17:56,000
+Similarly, if someone tries to inject malicious code or exploit vulnerabilities during runtime, the
+
+209
+00:17:56,000 --> 00:18:01,000
+app can protect itself by blocking or neutralizing the attack.
+
+210
+00:18:01,000 --> 00:18:07,000
+This real time defense makes it much harder for attackers to manipulate the app, even if they have
+
+211
+00:18:07,000 --> 00:18:10,000
+already gained some access to it.
+
+212
+00:18:10,000 --> 00:18:16,000
+Without tools like runtime application self-protection, an attacker who successfully enters the app
+
+213
+00:18:16,000 --> 00:18:23,000
+environment might be able to run unchecked, leading to significant data breaches or manipulation of
+
+214
+00:18:23,000 --> 00:18:24,000
+sensitive processes.
+
+215
+00:18:26,000 --> 00:18:33,000
+Finally, session and token management is an often overlooked but essential aspect of mobile security.
+
+216
+00:18:33,000 --> 00:18:40,000
+Apps that handle user authentication, such as logging in with passwords or using tokens for session
+
+217
+00:18:40,000 --> 00:18:46,000
+management, must ensure that these sessions are properly managed, and that tokens expire when they're
+
+218
+00:18:46,000 --> 00:18:47,000
+no longer needed.
+
+219
+00:18:48,000 --> 00:18:56,000
+For example, if a user logs out of an app, their session token should be immediately invalidated.
+
+220
+00:18:56,000 --> 00:19:01,000
+Leaving it active poses a risk because attackers could use it to hijack the session and gain unauthorized
+
+221
+00:19:01,000 --> 00:19:02,000
+access.
+
+222
+00:19:03,000 --> 00:19:09,000
+Additionally, tokens should be short lived and automatically expire after a certain period, reducing
+
+223
+00:19:09,000 --> 00:19:11,000
+the window of opportunity for attackers.
+
+224
+00:19:11,000 --> 00:19:17,000
+Proper session management helps prevent attacks like session fixation or session hijacking, where attackers
+
+225
+00:19:17,000 --> 00:19:21,000
+could exploit an active session to impersonate a user.
+
+226
+00:19:21,000 --> 00:19:26,000
+Without these measures, even an expired or forgotten session could become a doorway for attackers to
+
+227
+00:19:26,000 --> 00:19:32,000
+access sensitive data long after the user thinks they have logged out.
+
+228
+00:19:34,000 --> 00:19:39,000
+In today's lesson on mobile application security, we've explored a range of practices grouped by their
+
+229
+00:19:39,000 --> 00:19:42,000
+relevance to securing mobile applications.
+
+230
+00:19:43,000 --> 00:19:48,000
+The key takeaway is that mobile security is not about a single defense mechanism, but rather a layered
+
+231
+00:19:48,000 --> 00:19:54,000
+approach where each practice addresses a different aspect of the app's attack surface.
+
+232
+00:19:54,000 --> 00:19:56,000
+Let's break it down.
+
+233
+00:19:56,000 --> 00:20:02,000
+At the high relevance level, we focused on the core foundational practices that mitigate the most critical
+
+234
+00:20:02,000 --> 00:20:03,000
+threats.
+
+235
+00:20:03,000 --> 00:20:09,000
+Strong authentication and authorization mechanisms, such as multi-factor authentication, are essential
+
+236
+00:20:09,000 --> 00:20:12,000
+to ensuring that only legitimate users access the app.
+
+237
+00:20:13,000 --> 00:20:18,000
+Combined with secure token management, these mechanisms make it much harder for attackers to hijack
+
+238
+00:20:18,000 --> 00:20:20,000
+accounts or misuse credentials.
+
+239
+00:20:21,000 --> 00:20:28,000
+Next, the importance of encryption was highlighted both for data in transit and at rest.
+
+240
+00:20:28,000 --> 00:20:34,000
+Without encryption, sensitive data like financial information or personal identification could be exposed
+
+241
+00:20:34,000 --> 00:20:39,000
+to attackers during transmission or when stored on the device.
+
+242
+00:20:40,000 --> 00:20:47,000
+Another critical point is the need to regularly update the app and its dependencies to patch known vulnerabilities.
+
+243
+00:20:47,000 --> 00:20:54,000
+Apps that are not updated are prime targets for attackers looking to exploit outdated systems.
+
+244
+00:20:55,000 --> 00:21:01,000
+Finally, protecting sensitive data such as PII by adhering to privacy regulations, and securely store
+
+245
+00:21:01,000 --> 00:21:08,000
+and credentials and tokens in device native secure storage systems, further strengthens the apps defense
+
+246
+00:21:08,000 --> 00:21:11,000
+against unauthorized access and data theft.
+
+247
+00:21:12,000 --> 00:21:19,000
+Moving to moderate relevance concerns, we discussed practices that address common security issues,
+
+248
+00:21:19,000 --> 00:21:22,000
+often seen as gateways for attackers.
+
+249
+00:21:23,000 --> 00:21:29,000
+This begins with secure coding practices that help prevent vulnerabilities like SQL injection and buffer
+
+250
+00:21:29,000 --> 00:21:34,000
+overflows, which could otherwise be exploited by malicious users.
+
+251
+00:21:34,000 --> 00:21:40,000
+These coding practices, coupled with secure communication between the app and backend services, help
+
+252
+00:21:40,000 --> 00:21:45,000
+ensure that data transferred over networks remains protected from interception or manipulation.
+
+253
+00:21:46,000 --> 00:21:52,000
+The proper use of APIs with validation and authorization mechanisms adds another critical layer, safeguarding
+
+254
+00:21:52,000 --> 00:21:55,000
+back end systems from unauthorized access.
+
+255
+00:21:55,000 --> 00:22:01,000
+Furthermore, code obfuscation and securing the source code are essential for protecting against reverse
+
+256
+00:22:01,000 --> 00:22:07,000
+engineering, which can expose sensitive app logic or security flaws to attackers.
+
+257
+00:22:07,000 --> 00:22:14,000
+Lastly, we discussed the need for regular security testing, including penetration testing, to identify
+
+258
+00:22:14,000 --> 00:22:18,000
+and fix vulnerabilities before attackers can exploit them.
+
+259
+00:22:19,000 --> 00:22:25,000
+At the low relevance level, we touched on edge cases and lesser known threats, even though they may
+
+260
+00:22:25,000 --> 00:22:26,000
+seem less critical.
+
+261
+00:22:26,000 --> 00:22:31,000
+Addressing these concerns adds additional layers of protection.
+
+262
+00:22:31,000 --> 00:22:38,000
+Restricting app permissions to only those necessary for functionality helps prevent data leakage by
+
+263
+00:22:38,000 --> 00:22:42,000
+limiting the app's access to sensitive data.
+
+264
+00:22:42,000 --> 00:22:49,000
+Tamper detection mechanisms, such as detecting jailbroken or rooted devices, prevent attackers from
+
+265
+00:22:49,000 --> 00:22:51,000
+exploiting compromised environments.
+
+266
+00:22:52,000 --> 00:22:59,000
+Furthermore, monitoring for suspicious activity and using in-app security tools like runtime application
+
+267
+00:22:59,000 --> 00:23:04,000
+self-protection provide real time defense against emerging threats.
+
+268
+00:23:05,000 --> 00:23:12,000
+Finally, proper session and token management, including revocation of tokens after logout, helps
+
+269
+00:23:12,000 --> 00:23:18,000
+maintain security by preventing unauthorized access to services once a session has ended.
+
+270
+00:23:19,000 --> 00:23:22,000
+That's all what I wanted to discuss with you in this lesson.
+
+271
+00:23:22,000 --> 00:23:25,000
+Let's recap what we've learned from the lesson.
+
+272
+00:23:26,000 --> 00:23:33,000
+We explored the essential practices for mobile application security, focusing on high relevance threats
+
+273
+00:23:33,000 --> 00:23:37,000
+including strong authentication mechanisms and secure token management.
+
+274
+00:23:38,000 --> 00:23:45,000
+You now understand how to implement encryption for sensitive data both in transit and at rest, ensuring
+
+275
+00:23:45,000 --> 00:23:48,000
+its protection throughout the life cycle.
+
+276
+00:23:48,000 --> 00:23:54,000
+We covered the importance of regular app updates and security patches to mitigate known vulnerabilities.
+
+277
+00:23:54,000 --> 00:24:00,000
+Together, we discussed best practices for secure storage of sensitive user data and compliance with
+
+278
+00:24:00,000 --> 00:24:03,000
+privacy regulations to minimize data collection.
+
+279
+00:24:03,000 --> 00:24:09,000
+You learned about secure coding practices to prevent common vulnerabilities, and how to establish secure
+
+280
+00:24:09,000 --> 00:24:12,000
+communication between mobile apps and back end services.
+
+281
+00:24:12,000 --> 00:24:19,000
+We examined ways to protect mobile apps against reverse engineering and the importance of regular security
+
+282
+00:24:19,000 --> 00:24:22,000
+testing and vulnerability assessments.
+
+283
+00:24:22,000 --> 00:24:28,000
+Finally, we addressed lesser known threats like tamper detection, session management, and monitoring
+
+284
+00:24:28,000 --> 00:24:32,000
+app activity to prevent unauthorized access.
+
+285
+00:24:33,000 --> 00:24:35,000
+That's all for this lesson.
+
+286
+00:24:35,000 --> 00:24:37,000
+Thanks a lot for your attention.
+
+287
+00:24:37,000 --> 00:24:40,000
+Have a great day and see you in the next lesson.
+
diff --git a/77 - ===== EXAM TASK OWASP Top 10, Secure Coding & Logging =====/001 Exam Task Description and Solution (with reference to the source code).html b/77 - ===== EXAM TASK OWASP Top 10, Secure Coding & Logging =====/001 Exam Task Description and Solution (with reference to the source code).html
new file mode 100644
index 0000000000000000000000000000000000000000..4a764ea5c1d3a022a6228f9fe12e7d5b78b95ced
--- /dev/null
+++ b/77 - ===== EXAM TASK OWASP Top 10, Secure Coding & Logging =====/001 Exam Task Description and Solution (with reference to the source code).html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Exam Task Description and Solution (with reference to the source code)
+
+
+
+
+
+
+
Exam Task Description and Solution (with reference to the source code)
+
EXAM Task:
Review the requirements and the solution of the previous exam task. The solution is located at the bottom of the file with the description of the previous exam task - https://docs.google.com/document/d/1X9iZaqUFtbz7CcglLAr1yHf6ff_8ae7mWTPp3_e8F5k/edit?usp=sharing
Use the commit with the solution to create a new branch from it in git
Commit with the solution - https://github.com/AndriiPiatakha/java-learnit-web-online-store/commit/e13e1ace0558d5a8f2dd61fc682c0dea7136544b
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:
Core module
configs package
menu package
Main class
facades.HelpDeskFacade
facades.impl.DefaultHelpDeskFacade
AppTest class in the src/test/java source folder
Persistence module
Remove redundant code from the utils.DBUtils class
Remove enteties.impl.ComparableProduct
Remove utils.comparators.CustomSupportTicketsComparator class
Remove entities.RequestType and entities.SupportTicket
Remove entities.impl.DefaultSupportTicket
AppTest class in the src/test/java source folder
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.
Web module
Remove from src/main/webapp source folder
css-demo.html
form-demo.html
index.html
index.jsp
jsp-demo.jsp
jsp-include-demo.jsp
jsp-tags-demo.jsp
jstl-demo.jsp
Move servlets.exceptions package to controllers.exceptions
Remove servlets package
Remove filters.HelloWorldFilter class
Remove productList.jsp from WEB-INF/views
Remove WEB-INF/tags/general
Remove WEB/INF/tags/shop/plp-subcategories.tag
Remove listeners.SessionListener class
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 - https://docs.google.com/document/d/1ZWdFFYlQ9B0KyUzeV_wDReCr8zuW0TJacGKxs8wmvgA/edit?usp=sharing
Add package “connectionpools” and put DBCP connection pooling logic in that package.
Update DBUtils class to get connection from DBCP pool.
Use product GUID when searching and extracting products. For this:
Change ProductDto and add the necessary field
Add necessary field in the database table
Update MySqlJdbcProductDao
Update ProductDao and introduce a new method getProductByGuid(String guid)
UpdateProductDto convertor respectively
Update Product model
Update DefaultProduct class
Update ProductServlet to extract product by GUID
Send GUID parameter instead of ID to /product controller
Update CheckoutController to work with GUID instead of ID
Update pdp.jsp to submit GUID instead of ID
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.
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.
Do not forget the “Update user” scenario where we need to confirm actions with the current password.
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.
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.
Use this list for validation - https://en.wikipedia.org/wiki/Wikipedia:10,000_most_common_passwords
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.
SOLUTION
+
+
+
+
diff --git a/78 - ORM, JPA & Hibernate/001 Introduction to JPA & ORM_en.srt b/78 - ORM, JPA & Hibernate/001 Introduction to JPA & ORM_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..136db9397ff44d9d8d2703e2791636016dafe6b1
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/001 Introduction to JPA & ORM_en.srt
@@ -0,0 +1,608 @@
+1
+00:00:06,000 --> 00:00:07,000
+Hello, Kim.
+
+2
+00:00:07,000 --> 00:00:09,000
+Today we start a very important topic.
+
+3
+00:00:09,000 --> 00:00:13,000
+We're going to learn this topic with the help of many different lessons.
+
+4
+00:00:13,000 --> 00:00:20,000
+Today we start learning Jakarta Persistence API, formerly known as Java Persistence API.
+
+5
+00:00:20,000 --> 00:00:24,000
+Today we're going to learn some basic and key definitions.
+
+6
+00:00:24,000 --> 00:00:28,000
+One of such definitions that we have to learn is or am.
+
+7
+00:00:28,000 --> 00:00:34,000
+Also in this lesson we are going to learn what GPA is and what hibernate is.
+
+8
+00:00:34,000 --> 00:00:38,000
+Probably these are the key concepts to start with.
+
+9
+00:00:38,000 --> 00:00:42,000
+Also, I'm going to give an overview of all our frameworks.
+
+10
+00:00:43,000 --> 00:00:49,000
+We will hold a comparison of all these different terms in order to understand the difference better.
+
+11
+00:00:49,000 --> 00:00:56,000
+And at the end of the lesson, we're going to talk about GPA advantages and why we have to choose GPA.
+
+12
+00:00:56,000 --> 00:00:58,000
+Let's start our lesson.
+
+13
+00:00:59,000 --> 00:01:03,000
+Let's learn first what Aurum is or stands for.
+
+14
+00:01:03,000 --> 00:01:05,000
+Object Relational Mapping.
+
+15
+00:01:06,000 --> 00:01:08,000
+In very, very simplified words.
+
+16
+00:01:08,000 --> 00:01:14,000
+This is the process of converting Java objects to database tables and vice versa.
+
+17
+00:01:14,000 --> 00:01:22,000
+In other words, this allows us to interact with the relational database without any SQL objects.
+
+18
+00:01:22,000 --> 00:01:31,000
+Relational mapping or or AM is a programming technique to map application domain model objects to the
+
+19
+00:01:31,000 --> 00:01:39,000
+relational database tables or RAM is used to develop and maintain a relationship between an object and
+
+20
+00:01:39,000 --> 00:01:40,000
+a relational database.
+
+21
+00:01:40,000 --> 00:01:48,000
+By mapping an object state to database column, it also helps to handle various database operations
+
+22
+00:01:48,000 --> 00:01:58,000
+easily, such as inserting, updating, deleting, etc. So because of Aurum we can forget about relational
+
+23
+00:01:58,000 --> 00:02:02,000
+databases and don't be bothered how they work inside.
+
+24
+00:02:03,000 --> 00:02:10,000
+Of course we have to understand how they work, but during the actual coding and programming we are
+
+25
+00:02:10,000 --> 00:02:13,000
+not bothered about operating database tables.
+
+26
+00:02:13,000 --> 00:02:21,000
+We think only about objects and their structure and or RAM will take care of the rest things that are
+
+27
+00:02:21,000 --> 00:02:26,000
+needed to be done in order to map properly our objects with tables in the database.
+
+28
+00:02:26,000 --> 00:02:33,000
+Is it clear now when we learn what Aurum is, let's learn what GPI is.
+
+29
+00:02:34,000 --> 00:02:41,000
+GPA stands for Jakarta Persistence API, formerly known as Java Persistence API.
+
+30
+00:02:41,000 --> 00:02:47,000
+If you don't mind, I will use Jakarta and Java interchangeably during the lesson.
+
+31
+00:02:47,000 --> 00:02:54,000
+If you are wondering about the history of terminology, please refer to the lesson about Java EE.
+
+32
+00:02:54,000 --> 00:03:01,000
+In my Java from zero to first job course, I dedicated a part of the lesson explaining the history of
+
+33
+00:03:01,000 --> 00:03:02,000
+such naming.
+
+34
+00:03:03,000 --> 00:03:10,000
+The Jakarta Persistence API, first of all, is a specification that defines how to persist data in
+
+35
+00:03:10,000 --> 00:03:15,000
+Java applications, so it is not ready to use framework.
+
+36
+00:03:15,000 --> 00:03:20,000
+It is not a library, it is just a specification set of interfaces.
+
+37
+00:03:20,000 --> 00:03:28,000
+In other words, contracts that should be followed when you want to use persistence API in Java applications
+
+38
+00:03:29,000 --> 00:03:32,000
+taking into account Java has huge community.
+
+39
+00:03:32,000 --> 00:03:40,000
+There was a day when people realized it would be better to standardize the way how we persist objects
+
+40
+00:03:40,000 --> 00:03:45,000
+in Java instead of having custom approach in each different library.
+
+41
+00:03:45,000 --> 00:03:54,000
+The primary focus of Gpe is that there is a specification that facilitates objects relational mapping
+
+42
+00:03:54,000 --> 00:03:58,000
+to manage relational data in Java applications.
+
+43
+00:03:58,000 --> 00:04:04,000
+It provides a platform to work directly with objects instead of using SQL statements.
+
+44
+00:04:05,000 --> 00:04:11,000
+GPA permits the developer to work directly with objects rather than with SQL statements.
+
+45
+00:04:12,000 --> 00:04:21,000
+The GPA implementation is typically called persistence provider GPA X as a bridge between object oriented
+
+46
+00:04:21,000 --> 00:04:25,000
+domain models and relational database systems.
+
+47
+00:04:26,000 --> 00:04:31,000
+There are different implementations of the GPA persistence providers.
+
+48
+00:04:31,000 --> 00:04:37,000
+Let's hold a brief and very high level overview of different all error frameworks.
+
+49
+00:04:38,000 --> 00:04:39,000
+Hibernate.
+
+50
+00:04:39,000 --> 00:04:45,000
+Hibernate is one of the most popular Java program frameworks in use today.
+
+51
+00:04:45,000 --> 00:04:54,000
+Its first release was almost 20 years ago and still has excellent community support and regular releases.
+
+52
+00:04:54,000 --> 00:05:00,000
+Additionally, Hibernate is a standard implementation of the GPA specification with a few additional
+
+53
+00:05:00,000 --> 00:05:03,000
+features that are specific to hibernate.
+
+54
+00:05:04,000 --> 00:05:12,000
+The Eclipse link is the Open Source Eclipse Persistence Service Project from the Eclipse Foundation.
+
+55
+00:05:12,000 --> 00:05:20,000
+The software provides an extensible framework that allows Java developers to interact with various data
+
+56
+00:05:20,000 --> 00:05:29,000
+services, including databases, web services, object, XML mapping and enterprise information systems.
+
+57
+00:05:29,000 --> 00:05:36,000
+Eclipse Link supports a number of persistence standards, including Jakarta Persistence API.
+
+58
+00:05:36,000 --> 00:05:42,000
+Jakarta XML Binding, Jakarta Connectors, Service Data objects.
+
+59
+00:05:43,000 --> 00:05:50,000
+Eclipse Link is based on the top link product from which Oracle contributed the source code to create
+
+60
+00:05:50,000 --> 00:05:51,000
+the Eclipse Link project.
+
+61
+00:05:52,000 --> 00:05:54,000
+Oracle Toppling.
+
+62
+00:05:54,000 --> 00:06:02,000
+Toppling is produced by Oracle and is part of Oracle's Oracle application server, WebLogic and also
+
+63
+00:06:02,000 --> 00:06:04,000
+for servers.
+
+64
+00:06:04,000 --> 00:06:12,000
+It is an object persistence and object transformation framework totaling provides development tools
+
+65
+00:06:12,000 --> 00:06:19,000
+and runtime functionalities that ease the development process and help increase functionality.
+
+66
+00:06:20,000 --> 00:06:26,000
+A rich user interface is possible on the topline with the help of topline mapping workbench.
+
+67
+00:06:27,000 --> 00:06:35,000
+This Map and workbench supports graphical mapping of an object model to data model generation of data
+
+68
+00:06:35,000 --> 00:06:43,000
+model from its object model and vice versa, or to mapping of any existing data models and object models.
+
+69
+00:06:44,000 --> 00:06:46,000
+Apache Open GP.
+
+70
+00:06:46,000 --> 00:06:54,000
+Apache Open GP is a Java persistence project at the Apache Software Foundation that can be used as a
+
+71
+00:06:54,000 --> 00:07:02,000
+standalone project persistence layer or integrated into any Java E compliant container and many other
+
+72
+00:07:02,000 --> 00:07:06,000
+lightweight frameworks such as Tomcat and Spring.
+
+73
+00:07:07,000 --> 00:07:14,000
+Apache AI bodies as a persistence frameworks such as Hibernate allows the creation of an object model
+
+74
+00:07:14,000 --> 00:07:22,000
+by the user and create and maintain the relational database automatically ie bodies takes the reverse
+
+75
+00:07:22,000 --> 00:07:23,000
+approach.
+
+76
+00:07:24,000 --> 00:07:31,000
+The developer starts with a SQL database and then bodies automates the creation of Java objects.
+
+77
+00:07:31,000 --> 00:07:37,000
+A significant difference between AI bodies and other persistence frameworks such as hibernate is that
+
+78
+00:07:37,000 --> 00:07:45,000
+AI bodies emphasizes the use of SQL, while other frameworks typically use a custom query language such
+
+79
+00:07:45,000 --> 00:07:48,000
+as Hibernate, Query Language or Java persistence.
+
+80
+00:07:48,000 --> 00:07:49,000
+Query language.
+
+81
+00:07:50,000 --> 00:07:54,000
+Also, I'd like to say a few words about my bodies.
+
+82
+00:07:54,000 --> 00:08:03,000
+My bodies is a fog from I body's and nowadays most of AI bodies developers leave over to my bodies to
+
+83
+00:08:03,000 --> 00:08:07,000
+the I Bodies project is currently marked as inactive.
+
+84
+00:08:07,000 --> 00:08:15,000
+Therefore you should go with my buddies for new projects and only use bodies if you are maintaining
+
+85
+00:08:15,000 --> 00:08:18,000
+an existing project which already uses ibus.
+
+86
+00:08:19,000 --> 00:08:22,000
+So what should you use?
+
+87
+00:08:22,000 --> 00:08:31,000
+Pure a hybrid or GP API with hibernate or any other or framework one we use hibernate with GP.
+
+88
+00:08:31,000 --> 00:08:35,000
+We are actually using the Hibernate GP implementation.
+
+89
+00:08:36,000 --> 00:08:44,000
+The benefit of this is that we can swap out Hibernate implementation of GP for another implementation
+
+90
+00:08:44,000 --> 00:08:46,000
+of GP specification.
+
+91
+00:08:46,000 --> 00:08:54,000
+When you use straight hibernate, your law can into the implementation because other forums may use
+
+92
+00:08:54,000 --> 00:08:58,000
+different methods or configurations and annotations.
+
+93
+00:08:58,000 --> 00:09:05,000
+Therefore we can switch over to another or ramp easily without making changes in our code.
+
+94
+00:09:06,000 --> 00:09:13,000
+If you're already watching this lesson, I assume that you understand abstraction or principle and such
+
+95
+00:09:13,000 --> 00:09:21,000
+solid principle as dependency inversion modules of upper and lower levels should depend on abstractions.
+
+96
+00:09:22,000 --> 00:09:29,000
+That's why it is recommended to use GP interfaces, annotations, configurations during the implementation
+
+97
+00:09:29,000 --> 00:09:34,000
+in order to not be bound to only one specific order and framework.
+
+98
+00:09:34,000 --> 00:09:35,000
+Is it clear?
+
+99
+00:09:36,000 --> 00:09:42,000
+We have just learned a lot of new words or ram GPA hibernate.
+
+100
+00:09:42,000 --> 00:09:46,000
+Probably you might be confused by this moment in lesson.
+
+101
+00:09:46,000 --> 00:09:51,000
+Let's understand each definition better by comparing them between each other.
+
+102
+00:09:52,000 --> 00:10:00,000
+Or object relational mapping is concept process of converting data from object oriented language to
+
+103
+00:10:00,000 --> 00:10:03,000
+relational database and vice versa.
+
+104
+00:10:04,000 --> 00:10:13,000
+Forum is the approach of taking object oriented data and mapping to a relational data store that is
+
+105
+00:10:13,000 --> 00:10:16,000
+tables in a relational database management system.
+
+106
+00:10:17,000 --> 00:10:21,000
+Hibernate is an implementation of the Aurum concept.
+
+107
+00:10:22,000 --> 00:10:26,000
+GP is a one step above or a RAM.
+
+108
+00:10:26,000 --> 00:10:32,000
+GP is a Java EE standard specification for Aurum.
+
+109
+00:10:32,000 --> 00:10:41,000
+It is high level API and specification so that different Aurum tools can implement the same interfaces.
+
+110
+00:10:42,000 --> 00:10:44,000
+It is like standard for Aurum.
+
+111
+00:10:44,000 --> 00:10:53,000
+Following GPU standard gives the flexibility to developer to change the implementation from one to another.
+
+112
+00:10:53,000 --> 00:11:01,000
+For example, if application uses the GP API and hibernate as implementation, this can be changed easily
+
+113
+00:11:01,000 --> 00:11:02,000
+in the future.
+
+114
+00:11:03,000 --> 00:11:06,000
+In future we can switch to AI bodies if required.
+
+115
+00:11:07,000 --> 00:11:10,000
+In case you wouldn't use GP Z is case one.
+
+116
+00:11:10,000 --> 00:11:18,000
+The application directly logs the implementation with hibernate without GP platform switching is going
+
+117
+00:11:18,000 --> 00:11:25,000
+to be extremely complicated task to do because a lot of code would need to be written and tested.
+
+118
+00:11:25,000 --> 00:11:29,000
+Is it more clear now what is the difference between all these terms?
+
+119
+00:11:30,000 --> 00:11:32,000
+Even in case something is still not clear?
+
+120
+00:11:32,000 --> 00:11:36,000
+Please do not hesitate to ask your questions below.
+
+121
+00:11:36,000 --> 00:11:39,000
+Xavier and I will be happy to answer.
+
+122
+00:11:39,000 --> 00:11:40,000
+Let's continue.
+
+123
+00:11:40,000 --> 00:11:49,000
+Let's summarize GP advantages and let's answer the question why we need to use GP among GP advantages.
+
+124
+00:11:49,000 --> 00:11:51,000
+I'd like to highlight the following ones.
+
+125
+00:11:52,000 --> 00:12:00,000
+No need to create SQL statements if we use GP while you definitely can if you need some specific optimisation
+
+126
+00:12:00,000 --> 00:12:02,000
+or customization.
+
+127
+00:12:02,000 --> 00:12:09,000
+But in general, with the help of GP, we have possibility to operate with objects only without working
+
+128
+00:12:09,000 --> 00:12:11,000
+with the database directly.
+
+129
+00:12:12,000 --> 00:12:14,000
+Database Independent.
+
+130
+00:12:14,000 --> 00:12:21,000
+If you watched my course about SQL, then you should know that different relational databases may have
+
+131
+00:12:21,000 --> 00:12:23,000
+different SQL dialects.
+
+132
+00:12:23,000 --> 00:12:27,000
+Using GPA, you don't have such problems.
+
+133
+00:12:27,000 --> 00:12:35,000
+The programming becomes easy by considering the objects, relational mapping and database access process
+
+134
+00:12:36,000 --> 00:12:38,000
+and warding off unnecessary queries.
+
+135
+00:12:39,000 --> 00:12:46,000
+The basic idea is to delay all right operations as long as possible so that multiple update statements
+
+136
+00:12:46,000 --> 00:12:48,000
+can be combined into one.
+
+137
+00:12:49,000 --> 00:12:57,000
+Your GP implementation therefore stores all entities that will used within one transaction in the first
+
+138
+00:12:57,000 --> 00:13:02,000
+level cache in the course will also go going to run different cache levels.
+
+139
+00:13:02,000 --> 00:13:05,000
+And I'm going to explain you how they work.
+
+140
+00:13:06,000 --> 00:13:13,000
+Using the GP annotations, you can save your time for defining and architecting tables in the database.
+
+141
+00:13:14,000 --> 00:13:20,000
+In the course, I'm going to show you how to create tables based on the entities defined.
+
+142
+00:13:21,000 --> 00:13:25,000
+Using GPA, you can easily switch different or RAM implementations.
+
+143
+00:13:26,000 --> 00:13:31,000
+These are the main GPU advantages that helps developers a lot.
+
+144
+00:13:32,000 --> 00:13:35,000
+That's all what I wanted to share with you in this lesson.
+
+145
+00:13:35,000 --> 00:13:38,000
+Let's recap what we have learned today.
+
+146
+00:13:39,000 --> 00:13:41,000
+Today we learned what R.E.M. is.
+
+147
+00:13:42,000 --> 00:13:44,000
+Now you know what GPA is.
+
+148
+00:13:44,000 --> 00:13:50,000
+And also we reviewed different all around frameworks, including Hibernate.
+
+149
+00:13:50,000 --> 00:13:54,000
+At the end of the lesson, we learned GPA advantages.
+
+150
+00:13:55,000 --> 00:13:56,000
+That's all for this lesson.
+
+151
+00:13:57,000 --> 00:13:58,000
+Thank you all for your attention.
+
+152
+00:13:58,000 --> 00:14:01,000
+Have a great day and see you in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/002 First JPA Project Entity, ID GenerationType, Composite Primary Keys, etc)_en.srt b/78 - ORM, JPA & Hibernate/002 First JPA Project Entity, ID GenerationType, Composite Primary Keys, etc)_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..3e3f32cf06265e8a1e67949597e3f522eb5499ee
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/002 First JPA Project Entity, ID GenerationType, Composite Primary Keys, etc)_en.srt
@@ -0,0 +1,936 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:12,000
+In this lesson, we are going to create our first GPA project and learn more about GPA entities.
+
+3
+00:00:13,000 --> 00:00:17,000
+Today we are going to have a lesson full of practical examples and exercises.
+
+4
+00:00:18,000 --> 00:00:25,000
+As you know, I teach students offline and online, and based on my experience of the examples that
+
+5
+00:00:25,000 --> 00:00:31,000
+we are going to review today, gradually it becomes easier to understand what GPA is all about.
+
+6
+00:00:32,000 --> 00:00:38,000
+In this lesson, we are going to create our first GPA project and learn how to work with GPA, and that
+
+7
+00:00:38,000 --> 00:00:45,000
+is how we are going to learn the many different annotations that are used to configure GPA entity.
+
+8
+00:00:45,000 --> 00:00:48,000
+Some of them are entity annotation.
+
+9
+00:00:48,000 --> 00:00:50,000
+Table column.
+
+10
+00:00:50,000 --> 00:00:53,000
+ID generated value annotations.
+
+11
+00:00:53,000 --> 00:00:57,000
+Also, we are going to learn different ID generation strategies.
+
+12
+00:00:57,000 --> 00:01:03,000
+I will explain why that we should follow during the creation of our entity class.
+
+13
+00:01:03,000 --> 00:01:08,000
+We'll learn how to work with composite primary keys in GPA entity.
+
+14
+00:01:08,000 --> 00:01:13,000
+I will explain what temporal annotation is and when we might need to use it.
+
+15
+00:01:14,000 --> 00:01:22,000
+Also, we are going to learn what transit notation is and how to not persist some fields from our entity.
+
+16
+00:01:23,000 --> 00:01:29,000
+In case we'll use enemies, we need to learn enumerate, annotation and learn the specifics of enum
+
+17
+00:01:29,000 --> 00:01:31,000
+types persistence.
+
+18
+00:01:31,000 --> 00:01:37,000
+After we configure our GPA entity, we are going to learn how to persist our entities.
+
+19
+00:01:38,000 --> 00:01:45,000
+I will explain what entity, manager factory and what entity manager are will create separate file with
+
+20
+00:01:46,000 --> 00:01:47,000
+configuration.
+
+21
+00:01:47,000 --> 00:01:55,000
+The file is called Persistence XML and I will teach you what configurations can be placed in there.
+
+22
+00:01:56,000 --> 00:02:02,000
+During the lesson, you are going to learn more about transactions in GPA and what transaction types
+
+23
+00:02:02,000 --> 00:02:09,000
+to use during the configuration will compare and resource local transactions.
+
+24
+00:02:09,000 --> 00:02:16,000
+And after learning all this by the end of the lesson, we're going to have completely work in code example
+
+25
+00:02:16,000 --> 00:02:18,000
+that will be able to persist.
+
+26
+00:02:18,000 --> 00:02:20,000
+Our entity is in the school.
+
+27
+00:02:20,000 --> 00:02:22,000
+Let's start our lesson.
+
+28
+00:02:22,000 --> 00:02:26,000
+As I promised, this will be less than full of practical examples.
+
+29
+00:02:26,000 --> 00:02:29,000
+So let's start from the demo straight away.
+
+30
+00:02:30,000 --> 00:02:34,000
+First of all, let's create separate project for our GPA examples.
+
+31
+00:02:35,000 --> 00:02:42,000
+Our end goal is to practice our skills by making improvements in the online shop template that we developed
+
+32
+00:02:42,000 --> 00:02:47,000
+with my students from scratch in my course Java from zero to first job.
+
+33
+00:02:48,000 --> 00:02:56,000
+But we'll learn new topics on the examples in our training GPA project and only after that we'll work
+
+34
+00:02:56,000 --> 00:03:00,000
+on improvements of our online shop as part of your home tasks.
+
+35
+00:03:01,000 --> 00:03:05,000
+We'll work on implementation of GPA in our online shop to gather.
+
+36
+00:03:06,000 --> 00:03:11,000
+In Eclipse, I create a new Maven project using maven quickstart.
+
+37
+00:03:11,000 --> 00:03:15,000
+Archetype Maven is not a topic for discussion in this lesson.
+
+38
+00:03:16,000 --> 00:03:22,000
+Please refer to the section about build tools in my Java from zero to first job course where we learn
+
+39
+00:03:23,000 --> 00:03:24,000
+Maven on examples.
+
+40
+00:03:24,000 --> 00:03:32,000
+If you want to learn about Maven more, we'll start learning from understanding of what GPA entities
+
+41
+00:03:32,000 --> 00:03:32,000
+are.
+
+42
+00:03:33,000 --> 00:03:39,000
+I have a separate package here as it is called entities and there is a class user inside.
+
+43
+00:03:40,000 --> 00:03:45,000
+Don't worry, I will share with you all the source code examples that you see in the lesson.
+
+44
+00:03:46,000 --> 00:03:50,000
+Please find the source code of all examples in attachments to the lesson.
+
+45
+00:03:51,000 --> 00:03:53,000
+Let's learn what an entity is.
+
+46
+00:03:54,000 --> 00:03:58,000
+An entity is a lightweight persistence domain object.
+
+47
+00:03:58,000 --> 00:04:05,000
+Typically, an entity represents a table in a relational database, and each entity instance corresponds
+
+48
+00:04:05,000 --> 00:04:08,000
+to row in that table.
+
+49
+00:04:08,000 --> 00:04:13,000
+The primary programming artifact of an entity is the entity class.
+
+50
+00:04:14,000 --> 00:04:17,000
+Usually entities are simple Podio classes.
+
+51
+00:04:18,000 --> 00:04:26,000
+Podio stands for plain old java object basically data structure with fields and without behavior.
+
+52
+00:04:27,000 --> 00:04:30,000
+Podger usually have getters and setters.
+
+53
+00:04:30,000 --> 00:04:39,000
+After you create a class market with entity annotation, entity annotation will be used as method information
+
+54
+00:04:39,000 --> 00:04:40,000
+talents.
+
+55
+00:04:40,000 --> 00:04:45,000
+This class should be mapped with a separate table in the database.
+
+56
+00:04:46,000 --> 00:04:53,000
+The entity annotation is a marker annotation which is used to discover persistent entities.
+
+57
+00:04:53,000 --> 00:04:57,000
+This annotation is from Jakarta Persistence Package.
+
+58
+00:04:58,000 --> 00:05:05,000
+In order to be able to use the sanitation, you have to add Jakarta Persistence Library into your class
+
+59
+00:05:05,000 --> 00:05:05,000
+pass.
+
+60
+00:05:06,000 --> 00:05:13,000
+I use Maven Build two as a dependency manager, so I edit instructions to the Maven file to add this
+
+61
+00:05:13,000 --> 00:05:15,000
+library into the class pass.
+
+62
+00:05:15,000 --> 00:05:20,000
+And here you can see the dependency in my pom xml file.
+
+63
+00:05:20,000 --> 00:05:22,000
+Table annotation.
+
+64
+00:05:22,000 --> 00:05:29,000
+By default, this entity will be mapped to the user table as determined by the given class name.
+
+65
+00:05:30,000 --> 00:05:38,000
+If you wanted to map this entity to another table and optionally a specific schema, you could use table
+
+66
+00:05:38,000 --> 00:05:40,000
+annotation to do that.
+
+67
+00:05:41,000 --> 00:05:48,000
+For example, if you want to map user entity with the table that is called corporate user, then add
+
+68
+00:05:48,000 --> 00:05:51,000
+table annotation like I did here.
+
+69
+00:05:52,000 --> 00:05:57,000
+But I will keep this command because I want to map user empathy with user table.
+
+70
+00:05:58,000 --> 00:05:59,000
+Column annotation.
+
+71
+00:06:00,000 --> 00:06:01,000
+What we need to do next.
+
+72
+00:06:01,000 --> 00:06:05,000
+Now we need to map properties with table columns.
+
+73
+00:06:06,000 --> 00:06:12,000
+Fields are defined as member variables in the class, with the name of each field being mapped to a
+
+74
+00:06:12,000 --> 00:06:14,000
+column name in the table.
+
+75
+00:06:14,000 --> 00:06:21,000
+You can override this default mapping by using the column annotation, for example.
+
+76
+00:06:21,000 --> 00:06:29,000
+In this particular case, we're going to persist the state of the last name field into the last name
+
+77
+00:06:29,000 --> 00:06:32,000
+column with underscore in the name.
+
+78
+00:06:33,000 --> 00:06:35,000
+This is just an example though.
+
+79
+00:06:35,000 --> 00:06:41,000
+Highlight that you can persist state in any custom table column that you need.
+
+80
+00:06:42,000 --> 00:06:45,000
+I also configured column names for other attributes here.
+
+81
+00:06:46,000 --> 00:06:53,000
+Nothing special, just to make sure that I don't use Java style naming to name columns in the SQL table.
+
+82
+00:06:54,000 --> 00:07:00,000
+Column annotation also allows to specify other method information about the mapping.
+
+83
+00:07:00,000 --> 00:07:06,000
+Namely, we can specify the value of some field should be unique and column.
+
+84
+00:07:06,000 --> 00:07:13,000
+Also, we can specify what is a column label insert label updatable lengths.
+
+85
+00:07:13,000 --> 00:07:15,000
+Pay attention to the source code.
+
+86
+00:07:15,000 --> 00:07:20,000
+Here you can see that each of these properties have default value.
+
+87
+00:07:21,000 --> 00:07:27,000
+For most of them we can see true, but for the unique, the default value is false.
+
+88
+00:07:28,000 --> 00:07:37,000
+ID annotation, each entity should have primary key something what will uniquely identifies each row
+
+89
+00:07:37,000 --> 00:07:43,000
+in the database table and each object in our program in GP.
+
+90
+00:07:43,000 --> 00:07:49,000
+We use ID annotation to designate the field to be the table's primary key.
+
+91
+00:07:50,000 --> 00:07:58,000
+The primary key is required to be a Java primitive type, a primitive wrapper such as integer or long
+
+92
+00:07:58,000 --> 00:08:02,000
+string that date a big integer or a big decimal.
+
+93
+00:08:03,000 --> 00:08:07,000
+I just add adaptation above ID field.
+
+94
+00:08:08,000 --> 00:08:15,000
+Generate that value annotation, we can generate the identifiers in different ways which are specified
+
+95
+00:08:15,000 --> 00:08:17,000
+by the generated value annotation.
+
+96
+00:08:17,000 --> 00:08:23,000
+We can choose from five ID generation strategies with the strategy element.
+
+97
+00:08:23,000 --> 00:08:30,000
+The value can be table sequence, identity, UUID or auto.
+
+98
+00:08:30,000 --> 00:08:34,000
+Let's review what is the difference between different generation strategies.
+
+99
+00:08:35,000 --> 00:08:36,000
+Cable generation.
+
+100
+00:08:36,000 --> 00:08:42,000
+The generation type table gets only rarely used nowadays.
+
+101
+00:08:42,000 --> 00:08:49,000
+It's similar a sequence by storing and updating its current value in a database table, which requires
+
+102
+00:08:49,000 --> 00:08:55,000
+the use of pessimistic logs which put all transactions into a sequential order.
+
+103
+00:08:55,000 --> 00:08:57,000
+What is pessimistic log?
+
+104
+00:08:57,000 --> 00:09:04,000
+We are going to learn further in the course, but what you have to understand now is that table generation
+
+105
+00:09:04,000 --> 00:09:07,000
+time slows down your application.
+
+106
+00:09:08,000 --> 00:09:15,000
+You can use the table generator annotation to specify the database table, which hibernate shell used
+
+107
+00:09:15,000 --> 00:09:17,000
+to simulate the sequence.
+
+108
+00:09:18,000 --> 00:09:25,000
+The table generator defines the primary key generator that may be referenced by the name when a generator
+
+109
+00:09:25,000 --> 00:09:29,000
+element is specified for the generated value annotation.
+
+110
+00:09:29,000 --> 00:09:37,000
+A table generator may be specified on the entity clause or on the primary key field of property.
+
+111
+00:09:37,000 --> 00:09:44,000
+The scope of the generator name is global to the persistence unit across all generator types.
+
+112
+00:09:45,000 --> 00:09:51,000
+The table generator annotation uses a standard database table for primary key values.
+
+113
+00:09:51,000 --> 00:09:53,000
+Sequence generation.
+
+114
+00:09:53,000 --> 00:09:59,000
+The generation type sequence uses a database sequence to generate unique values.
+
+115
+00:09:59,000 --> 00:10:06,000
+It requires additional select statements to get the next value from a database sequence.
+
+116
+00:10:06,000 --> 00:10:10,000
+But this has no performance impact for most applications.
+
+117
+00:10:10,000 --> 00:10:19,000
+And if your application has to persist a huge number of new entities, you can use some specific optimizations
+
+118
+00:10:19,000 --> 00:10:21,000
+to reduce the number of statements.
+
+119
+00:10:22,000 --> 00:10:29,000
+If you don't provide any additional information, hibernate will request the next value from its default
+
+120
+00:10:29,000 --> 00:10:30,000
+sequence.
+
+121
+00:10:30,000 --> 00:10:37,000
+You can change that by referencing the name of a sequence generator in the generator attribute of the
+
+122
+00:10:37,000 --> 00:10:39,000
+generated value annotation.
+
+123
+00:10:39,000 --> 00:10:47,000
+The sequence generated annotation lets you define the name of the generator, the name and scheme of
+
+124
+00:10:47,000 --> 00:10:52,000
+the database sequence and the allocation size of the sequence.
+
+125
+00:10:53,000 --> 00:10:55,000
+Identity generation.
+
+126
+00:10:55,000 --> 00:11:02,000
+The generation type identity is the easiest to use, but not the best one from a performance point of
+
+127
+00:11:02,000 --> 00:11:03,000
+view.
+
+128
+00:11:03,000 --> 00:11:11,000
+It relies on the incremented database column and lets the database generate a new value with each insert
+
+129
+00:11:11,000 --> 00:11:12,000
+operation.
+
+130
+00:11:13,000 --> 00:11:14,000
+From a database point of view.
+
+131
+00:11:14,000 --> 00:11:22,000
+This is very efficient because all the implement columns are highly optimized and it doesn't require
+
+132
+00:11:22,000 --> 00:11:23,000
+any additional statements.
+
+133
+00:11:24,000 --> 00:11:27,000
+This approach has a significant drawback.
+
+134
+00:11:27,000 --> 00:11:35,000
+If you use hibernate, hibernate requires a primary key value for each managed entity and therefore
+
+135
+00:11:35,000 --> 00:11:38,000
+has to perform the insert statement immediately.
+
+136
+00:11:39,000 --> 00:11:44,000
+This prevents it from using different optimization techniques like gdb c bar.
+
+137
+00:11:46,000 --> 00:11:48,000
+You uid generation.
+
+138
+00:11:48,000 --> 00:11:52,000
+Let me briefly cover you uid generation time.
+
+139
+00:11:53,000 --> 00:11:57,000
+UID stands for a universally unique identifier.
+
+140
+00:11:57,000 --> 00:12:03,000
+It is 128 bit label used for information in computer systems.
+
+141
+00:12:03,000 --> 00:12:08,000
+The term globally unique identifier is also used.
+
+142
+00:12:08,000 --> 00:12:16,000
+Most developers perform numerical primary keys because they are efficient to use and easy to generate.
+
+143
+00:12:16,000 --> 00:12:20,000
+But that doesn't mean that the primary key has to be a number.
+
+144
+00:12:21,000 --> 00:12:26,000
+U IDs, for example, have gained some popularity over recent years.
+
+145
+00:12:26,000 --> 00:12:35,000
+The main advantage of a UID is its practical, global uniqueness, which provides a huge advantage for
+
+146
+00:12:35,000 --> 00:12:37,000
+distributed systems.
+
+147
+00:12:38,000 --> 00:12:45,000
+If you use the typical numerical ID that gets incremented for each new record, you need to generate
+
+148
+00:12:45,000 --> 00:12:48,000
+all the IDs by the same system component.
+
+149
+00:12:49,000 --> 00:12:55,000
+In most cases, this is sequenced for each table that's managed by your database.
+
+150
+00:12:55,000 --> 00:13:04,000
+And if you want to have identifiers zipping unique globally in your system, you can use uid.
+
+151
+00:13:05,000 --> 00:13:09,000
+On the other hand, the UID also has some disadvantages.
+
+152
+00:13:10,000 --> 00:13:12,000
+The most obvious one is its size.
+
+153
+00:13:13,000 --> 00:13:20,000
+It's four times larger than a numerical YY and can be handled as efficiently as numerically.
+
+154
+00:13:21,000 --> 00:13:30,000
+You should therefore decide carefully if you want to use your UI IDs on America IDs and discuss it with
+
+155
+00:13:30,000 --> 00:13:32,000
+your database administrator.
+
+156
+00:13:33,000 --> 00:13:40,000
+If we are using the default generation type, the persistence provider will determine values based on
+
+157
+00:13:40,000 --> 00:13:42,000
+the type of the primary key attribute.
+
+158
+00:13:43,000 --> 00:13:51,000
+For example, if you use Hibernate as your persistence provider, it selects a generation strategy based
+
+159
+00:13:51,000 --> 00:13:53,000
+on the database specific dialog.
+
+160
+00:13:54,000 --> 00:14:01,000
+For most popular databases, it selects generation type sequence, which I already explained.
+
+161
+00:14:02,000 --> 00:14:06,000
+And here's how a simple entity class that we created together.
+
+162
+00:14:06,000 --> 00:14:13,000
+Let's learn a few more requirements for entity class that we need to remember about the things that
+
+163
+00:14:13,000 --> 00:14:15,000
+I'm going to talk about now.
+
+164
+00:14:15,000 --> 00:14:19,000
+A pretty simple, logical and intuitive.
+
+165
+00:14:19,000 --> 00:14:23,000
+But just in case, let me quickly cover key points.
+
+166
+00:14:24,000 --> 00:14:32,000
+The class must have a public or protected no argument construct that the class may have as a constructors.
+
+167
+00:14:33,000 --> 00:14:36,000
+The class must not be declared final.
+
+168
+00:14:37,000 --> 00:14:41,000
+No masses or persistent instance variables must be declared final.
+
+169
+00:14:42,000 --> 00:14:50,000
+If an entity instance is passed by value as a detached object, such as through a session being a mode
+
+170
+00:14:50,000 --> 00:14:56,000
+business interface, the class must implement this generalizable interface.
+
+171
+00:14:57,000 --> 00:14:58,000
+And that is my extent.
+
+172
+00:14:58,000 --> 00:15:06,000
+Both entity and non entity classes and non entity classes may extend entity classes.
+
+173
+00:15:07,000 --> 00:15:14,000
+Persistent instance, variables must be declared private, protected or packaged private and can be
+
+174
+00:15:14,000 --> 00:15:18,000
+accessed directly only by the entity class masses.
+
+175
+00:15:19,000 --> 00:15:25,000
+Clients must access the entity state through access of business masses.
+
+176
+00:15:26,000 --> 00:15:30,000
+And here we're generated getters and setters for our properties.
+
+177
+00:15:31,000 --> 00:15:33,000
+Composite primary case.
+
+178
+00:15:34,000 --> 00:15:39,000
+The next interesting thing that I'd like to explain is about composite primary keys.
+
+179
+00:15:39,000 --> 00:15:45,000
+Probably composite primary key is not so popular, a simple primary key.
+
+180
+00:15:45,000 --> 00:15:48,000
+But still, this case can happen.
+
+181
+00:15:48,000 --> 00:15:52,000
+And I want you to know how to handle such cases in GPA.
+
+182
+00:15:53,000 --> 00:16:01,000
+Composite primary keys are used when a primary key consists of more than one attribute, which corresponds
+
+183
+00:16:01,000 --> 00:16:04,000
+to a set of single persistent properties of fields.
+
+184
+00:16:05,000 --> 00:16:10,000
+Composite primary keys must be defined in a primary key plus.
+
+185
+00:16:11,000 --> 00:16:19,000
+Composite primary keys are denoted using the embeddable embedded ID and IEEE class annotations.
+
+186
+00:16:20,000 --> 00:16:22,000
+I have a separate class here at the school.
+
+187
+00:16:22,000 --> 00:16:24,000
+User composite key.
+
+188
+00:16:25,000 --> 00:16:30,000
+Here you can see that on top of the class I put embeddable annotation.
+
+189
+00:16:31,000 --> 00:16:36,000
+The class has two properties and this is just for the sake of example.
+
+190
+00:16:36,000 --> 00:16:43,000
+Imagine this is the primary key for our user and that will consist from ID and name properties.
+
+191
+00:16:43,000 --> 00:16:44,000
+That's it.
+
+192
+00:16:44,000 --> 00:16:51,000
+And in case you want to use composite primary key in your entity, you just declare a property of such
+
+193
+00:16:51,000 --> 00:16:56,000
+type and market with annotation embedded ID.
+
+194
+00:16:56,000 --> 00:17:03,000
+There is also another way to represent the composite primary key and I'll turn it way to represent the
+
+195
+00:17:03,000 --> 00:17:07,000
+composite primary key is to use a class notation.
+
+196
+00:17:07,000 --> 00:17:10,000
+Let me show you another example.
+
+197
+00:17:10,000 --> 00:17:18,000
+I created another demo class that is called Project and imagine that I have composite key for my project
+
+198
+00:17:18,000 --> 00:17:23,000
+entity that consists from department I.D. and actually Project ID.
+
+199
+00:17:24,000 --> 00:17:32,000
+Just as an example, when an entity has multiple primary key fields, GPA requires defining a special
+
+200
+00:17:32,000 --> 00:17:38,000
+ID class that is attached to the entity class using the class annotation.
+
+201
+00:17:39,000 --> 00:17:45,000
+Here you can see a class annotation on top and a past project class.
+
+202
+00:17:45,000 --> 00:17:51,000
+Let's look at this class and here I have the port and project ID.
+
+203
+00:17:51,000 --> 00:17:52,000
+That's it.
+
+204
+00:17:52,000 --> 00:17:54,000
+Regarding composite primary keys.
+
+205
+00:17:55,000 --> 00:17:57,000
+Temporal annotation.
+
+206
+00:17:57,000 --> 00:18:03,000
+There is important annotation for Java to date and for Java calendar data types.
+
+207
+00:18:04,000 --> 00:18:06,000
+I am talking about temporal annotation.
+
+208
+00:18:07,000 --> 00:18:11,000
+Imagine that we need to store date of birth of our user.
+
+209
+00:18:11,000 --> 00:18:16,000
+We can create field of type Java till date or Java calendar.
+
+210
+00:18:17,000 --> 00:18:25,000
+You can use temporal annotation only with data of such types in a temporal annotation source.
+
+211
+00:18:25,000 --> 00:18:32,000
+One of the major issues of converting the date and time values from Java object to compatible database
+
+212
+00:18:32,000 --> 00:18:36,000
+type and retrieve it back to the application.
+
+213
+00:18:36,000 --> 00:18:43,000
+Pay attention that you shouldn't use temporal annotation with types from java time package like for
+
+214
+00:18:43,000 --> 00:18:49,000
+example with local date local time offset time offset date time.
+
+215
+00:18:49,000 --> 00:18:55,000
+The map between the Java eight date time classes and the SQL types is implicit.
+
+216
+00:18:56,000 --> 00:19:00,000
+There is no need to specify the temporal annotation.
+
+217
+00:19:01,000 --> 00:19:06,000
+Let's now imagine that my entity has fields that I don't want to persist.
+
+218
+00:19:06,000 --> 00:19:12,000
+For example, in an entity, we can have some field that is calculated on the file.
+
+219
+00:19:13,000 --> 00:19:18,000
+What if we calculate age of the user based on his or her date of birth?
+
+220
+00:19:19,000 --> 00:19:27,000
+And I don't want to keep H in the database, but still I want to keep it in the Java object for cases
+
+221
+00:19:27,000 --> 00:19:28,000
+like this.
+
+222
+00:19:28,000 --> 00:19:30,000
+There is a transient annotation.
+
+223
+00:19:30,000 --> 00:19:37,000
+You have to just put annotation next to field that you don't want to persist, and that's it.
+
+224
+00:19:38,000 --> 00:19:40,000
+Persists in some types.
+
+225
+00:19:40,000 --> 00:19:44,000
+Sometimes there is a need to persist and type.
+
+226
+00:19:45,000 --> 00:19:49,000
+In our particular example, imagine that we have agenda in them.
+
+227
+00:19:50,000 --> 00:19:58,000
+There are only two possible values is a male or female and in them should be part of our user entity.
+
+228
+00:19:59,000 --> 00:20:07,000
+We can use the enumerated annotation to specify whether the enum should be persisted by name or by ordinal.
+
+229
+00:20:07,000 --> 00:20:15,000
+You can see that I use enumerated annotation and inside this annotation I specified that I want to persist
+
+230
+00:20:15,000 --> 00:20:16,000
+string.
+
+231
+00:20:17,000 --> 00:20:25,000
+So basically male or female value will be persisted, but actually we don't have to specify the enumerated
+
+232
+00:20:25,000 --> 00:20:27,000
+annotation at all.
+
+233
+00:20:27,000 --> 00:20:31,000
+If we are going to persist the gender by the enum ordinal.
+
+234
+00:20:31,000 --> 00:20:36,000
+But if you want to persist that we have to specify enum type.
+
diff --git a/78 - ORM, JPA & Hibernate/002 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/002 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..1eadb49b4e4606157cc6db2f92dc89b26b4bcd76
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/002 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/003 First JPA Project - Part 2 EntityManager, persistence.xml, Transactions in JPA_en.srt b/78 - ORM, JPA & Hibernate/003 First JPA Project - Part 2 EntityManager, persistence.xml, Transactions in JPA_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..60ab1c6a800674616b74f12fd457d29f5cced952
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/003 First JPA Project - Part 2 EntityManager, persistence.xml, Transactions in JPA_en.srt
@@ -0,0 +1,996 @@
+1
+00:00:03,000 --> 00:00:09,000
+Now it is time to learn what entity manager is and how we can actually persist our entity.
+
+2
+00:00:10,000 --> 00:00:17,000
+A connection to a database is represented by an entity manager instance, which also provides functionality
+
+3
+00:00:17,000 --> 00:00:20,000
+for performing operations on a database.
+
+4
+00:00:20,000 --> 00:00:26,000
+Many applications require multiple database connections during their lifetime.
+
+5
+00:00:26,000 --> 00:00:33,000
+For instance, in a web application, it is common to establish a separate database connection using
+
+6
+00:00:33,000 --> 00:00:35,000
+a separate entity manager instance.
+
+7
+00:00:35,000 --> 00:00:44,000
+For every HTTP request there is a special object of type entity manager factory that is used to manage
+
+8
+00:00:44,000 --> 00:00:48,000
+instantiation of entity manager instances.
+
+9
+00:00:48,000 --> 00:00:56,000
+An entity manager factory is constructed for a specific database and by managing resources efficiently,
+
+10
+00:00:56,000 --> 00:01:03,000
+provides an efficient way to construct multiple entity manager instances for that database.
+
+11
+00:01:03,000 --> 00:01:10,000
+Operations that modify the content of a database require active transactions.
+
+12
+00:01:10,000 --> 00:01:17,000
+Transactions are managed by an entity transaction instance obtained from the entity manager.
+
+13
+00:01:18,000 --> 00:01:25,000
+And then the manager instance also functions as a factor for query instances which are needed for executing
+
+14
+00:01:25,000 --> 00:01:27,000
+queries on the database.
+
+15
+00:01:27,000 --> 00:01:29,000
+So the first step is to obtain.
+
+16
+00:01:29,000 --> 00:01:37,000
+And if you manage to do this, we need to obtain and then to manage your factory that represents the
+
+17
+00:01:37,000 --> 00:01:38,000
+relevant database.
+
+18
+00:01:38,000 --> 00:01:44,000
+And then we can use that factory instance to get an entity manager instance.
+
+19
+00:01:45,000 --> 00:01:52,000
+GP requires the definition of the persistence unit in an XML file in order to be able to generate an
+
+20
+00:01:52,000 --> 00:02:00,000
+entity manager factor to configure entity manager factor, we need to create persistence is XML file.
+
+21
+00:02:01,000 --> 00:02:06,000
+There is also a conventional place where we need to put this file in MAVEN project.
+
+22
+00:02:07,000 --> 00:02:16,000
+GPA implementation would look for this file in the C main resources method folder and here you can see
+
+23
+00:02:16,000 --> 00:02:18,000
+where we put this file.
+
+24
+00:02:18,000 --> 00:02:25,000
+But before we add configurations to this file, let's make sure that we added all required dependencies
+
+25
+00:02:25,000 --> 00:02:27,000
+into the class space.
+
+26
+00:02:27,000 --> 00:02:37,000
+I open for maximum so we have here edit our Jakarta persistence and hibernate or dependency because
+
+27
+00:02:37,000 --> 00:02:42,000
+as we learned already, GPA is just a set of interfaces contracts.
+
+28
+00:02:42,000 --> 00:02:50,000
+But to make things actually work we need to add some GPA implementation and in this course we are going
+
+29
+00:02:50,000 --> 00:02:53,000
+to use hibernate as GPA implementation.
+
+30
+00:02:54,000 --> 00:02:58,000
+Also, let's add my SQL connector to the class pass.
+
+31
+00:02:58,000 --> 00:03:05,000
+It is also required because we are going to use my SQL Server using the course as our persistence storage.
+
+32
+00:03:06,000 --> 00:03:09,000
+Let's now open persistence XML file.
+
+33
+00:03:09,000 --> 00:03:14,000
+I'm going to give you a basic overview of key elements of the persistence XML file.
+
+34
+00:03:15,000 --> 00:03:21,000
+The Persistence Example Configuration file is used to configure a given GPA Persistence Unit.
+
+35
+00:03:22,000 --> 00:03:30,000
+The Persistence Unit defines all the metadata required to bootstrap an entity manager factory like entity
+
+36
+00:03:30,000 --> 00:03:38,000
+mappings, data source and transaction settings as well as GPA provider the configuration properties.
+
+37
+00:03:38,000 --> 00:03:43,000
+The root tag is the persistence and it defines the GPA version.
+
+38
+00:03:44,000 --> 00:03:48,000
+You can use GPA with a very short basic configuration.
+
+39
+00:03:48,000 --> 00:03:55,000
+You only need a persistence element as the root element and the persistence unit element with the name
+
+40
+00:03:55,000 --> 00:03:55,000
+attribute.
+
+41
+00:03:56,000 --> 00:04:03,000
+The attribute is used to identify the persistence unit and you can use it during the bootstrap process
+
+42
+00:04:03,000 --> 00:04:07,000
+to instantiate a specific entity manager factor.
+
+43
+00:04:07,000 --> 00:04:14,000
+Having the basic default configuration, we also have to accept some default configurations.
+
+44
+00:04:14,000 --> 00:04:18,000
+Let me cover some details of basic configuration.
+
+45
+00:04:19,000 --> 00:04:27,000
+Your persistence provider scans the root of your persistence unit and as all annotated managed persistence
+
+46
+00:04:27,000 --> 00:04:29,000
+clauses to the persistence unit.
+
+47
+00:04:30,000 --> 00:04:36,000
+If your letter is direct, it contains a file called Aurum XML.
+
+48
+00:04:36,000 --> 00:04:41,000
+It gets treated as a mapping file and included mapping information.
+
+49
+00:04:41,000 --> 00:04:42,000
+Get used.
+
+50
+00:04:43,000 --> 00:04:51,000
+I didn't show you example of Aurum XML file yet, but in short you can use XML configuration to configure
+
+51
+00:04:51,000 --> 00:04:54,000
+entities instead of annotations.
+
+52
+00:04:54,000 --> 00:05:01,000
+Today in this lesson, we used GPA adaptations to configure our GPA entities.
+
+53
+00:05:01,000 --> 00:05:09,000
+But theoretically, you can use XML configuration to not mix up Java source code and GPA configuration
+
+54
+00:05:09,000 --> 00:05:11,000
+in one class.
+
+55
+00:05:11,000 --> 00:05:14,000
+But this is a matter of the coding style.
+
+56
+00:05:14,000 --> 00:05:17,000
+Both ways of configuration are file.
+
+57
+00:05:18,000 --> 00:05:22,000
+In case you don't configure any database connection.
+
+58
+00:05:22,000 --> 00:05:32,000
+GP therefore expects that you provide a data source at one time or you can specify database properties
+
+59
+00:05:32,000 --> 00:05:34,000
+to establish database connection.
+
+60
+00:05:35,000 --> 00:05:38,000
+I'm going to show you how to do this in a few minutes.
+
+61
+00:05:39,000 --> 00:05:45,000
+All GP implementations support a set of proprietary configuration parameters.
+
+62
+00:05:46,000 --> 00:05:54,000
+Examples for that as a log in configuration equips GP or hibernates database dialogue as you don't define
+
+63
+00:05:54,000 --> 00:06:02,000
+any of them in this specific basic configuration, you also rely on all provider specific defaults,
+
+64
+00:06:02,000 --> 00:06:08,000
+but during the course we're going to learn key and the most popular configuration parameters.
+
+65
+00:06:09,000 --> 00:06:16,000
+Let me also explain one more important concept before you see how to configure transactions, type in
+
+66
+00:06:16,000 --> 00:06:18,000
+the persistence XML.
+
+67
+00:06:18,000 --> 00:06:26,000
+Usually in persistence XML file, we have opportunity to configure transaction type, what is it and
+
+68
+00:06:26,000 --> 00:06:28,000
+what transaction types can be used.
+
+69
+00:06:29,000 --> 00:06:35,000
+The transaction management is one of the most important Java persistence API aspects.
+
+70
+00:06:35,000 --> 00:06:42,000
+If you are using Hibernate or any other GPU provider, you should know how valuable transaction management
+
+71
+00:06:42,000 --> 00:06:43,000
+is.
+
+72
+00:06:43,000 --> 00:06:49,000
+The GPA transaction determines when you modify or delete it.
+
+73
+00:06:49,000 --> 00:06:52,000
+Entity is synchronized with the database.
+
+74
+00:06:52,000 --> 00:06:59,000
+There is no way to talk about transaction management without mentioned persistence contacts.
+
+75
+00:06:59,000 --> 00:07:02,000
+What is the persistence contacts?
+
+76
+00:07:02,000 --> 00:07:07,000
+Ensure the persistence context is a named session of entities.
+
+77
+00:07:08,000 --> 00:07:15,000
+There are two main types of transactions GTA transactions and the resource local transactions.
+
+78
+00:07:16,000 --> 00:07:20,000
+Let's learn what is the difference between these types of transactions.
+
+79
+00:07:21,000 --> 00:07:28,000
+GTA Java transaction API is an API for managing transactions in Java.
+
+80
+00:07:28,000 --> 00:07:33,000
+It has a few crucial steps according to the transaction lifecycle.
+
+81
+00:07:34,000 --> 00:07:40,000
+Transaction synchronization is a process in which transactions becomes registered in the persistence
+
+82
+00:07:40,000 --> 00:07:41,000
+context.
+
+83
+00:07:41,000 --> 00:07:45,000
+Transaction Association The moment of persistence.
+
+84
+00:07:45,000 --> 00:07:45,000
+Context.
+
+85
+00:07:45,000 --> 00:07:47,000
+Connection with transaction.
+
+86
+00:07:48,000 --> 00:07:51,000
+Transaction propagation is a moment of persistence.
+
+87
+00:07:51,000 --> 00:07:57,000
+Context sharing in application ecosystem may be the only one.
+
+88
+00:07:57,000 --> 00:08:04,000
+Persistence context connect to the GTA and all entity managers within a transaction must have the same
+
+89
+00:08:04,000 --> 00:08:06,000
+persistence context.
+
+90
+00:08:07,000 --> 00:08:14,000
+One What type of transaction management exists in GB ecosystem or a source local transaction?
+
+91
+00:08:15,000 --> 00:08:16,000
+What does it mean?
+
+92
+00:08:16,000 --> 00:08:21,000
+It means that transaction management is 100% by your control.
+
+93
+00:08:22,000 --> 00:08:28,000
+Implementation of it happens with the implementation of entity transaction.
+
+94
+00:08:28,000 --> 00:08:31,000
+There are some disadvantages of that.
+
+95
+00:08:31,000 --> 00:08:38,000
+For example, you may get a legal state exception when some transaction is already started and you try
+
+96
+00:08:38,000 --> 00:08:39,000
+to start the new one.
+
+97
+00:08:40,000 --> 00:08:46,000
+The same exception is caused in the case of commit or rollback without an active transaction.
+
+98
+00:08:47,000 --> 00:08:52,000
+But during the course, I'm going to teach you how to use transactions like a pro.
+
+99
+00:08:53,000 --> 00:08:57,000
+In the following lessons we're going to review the different propagation levels.
+
+100
+00:08:57,000 --> 00:08:58,000
+What is it?
+
+101
+00:08:58,000 --> 00:09:05,000
+Ensure it is a flow of creative avoiding and passing transaction from massive to massive.
+
+102
+00:09:06,000 --> 00:09:08,000
+So what would be the conclusion?
+
+103
+00:09:09,000 --> 00:09:16,000
+In most cases where a source local is fine, this would use basic gdb c level transactions.
+
+104
+00:09:16,000 --> 00:09:22,000
+The downside is that the transaction is local to the GPA persistence unit.
+
+105
+00:09:23,000 --> 00:09:30,000
+So if you want a transaction that spawns multiple persistence units or other databases, then resource
+
+106
+00:09:30,000 --> 00:09:33,000
+local may not be good enough.
+
+107
+00:09:33,000 --> 00:09:43,000
+GTA is also used for managing transactions across systems like Gems and GCA, but that's fairly exotic
+
+108
+00:09:43,000 --> 00:09:46,000
+usage for most of us to use.
+
+109
+00:09:46,000 --> 00:09:54,000
+GTA, you need support for it in your application server and also support from the GBK driver.
+
+110
+00:09:54,000 --> 00:09:57,000
+So let's get back to our persistence.
+
+111
+00:09:57,000 --> 00:09:58,000
+Excellent configuration.
+
+112
+00:09:59,000 --> 00:10:06,000
+Now, you know, two main transaction types, the used transaction type depends on the environment in
+
+113
+00:10:06,000 --> 00:10:11,000
+which you deploy your application in the Jakarta E environment.
+
+114
+00:10:11,000 --> 00:10:20,000
+GP expects that the container provides a GTA compliant connection provided in a Java SE environment.
+
+115
+00:10:20,000 --> 00:10:24,000
+It uses a resource local transaction instead.
+
+116
+00:10:25,000 --> 00:10:26,000
+In the file.
+
+117
+00:10:26,000 --> 00:10:28,000
+I left the command lines.
+
+118
+00:10:28,000 --> 00:10:30,000
+Please explore them.
+
+119
+00:10:30,000 --> 00:10:35,000
+You can see how I use transaction type property of persistence unit element.
+
+120
+00:10:35,000 --> 00:10:37,000
+It can be resource local or GTA.
+
+121
+00:10:38,000 --> 00:10:46,000
+The GTA data source and non GTA data source elements are mostly used in Jakarta environments.
+
+122
+00:10:46,000 --> 00:10:55,000
+They enable you to reference the GDI name of a data source that is or is not compliant with the Java
+
+123
+00:10:55,000 --> 00:10:56,000
+transaction API.
+
+124
+00:10:57,000 --> 00:11:03,000
+If you don't use any of these two elements, you need to use a configure default data source for your
+
+125
+00:11:03,000 --> 00:11:09,000
+container or provide the GDI name of a data source at deploy time.
+
+126
+00:11:10,000 --> 00:11:17,000
+And if you are using GPI in the Java AC environment, you can either use one of these two elements to
+
+127
+00:11:17,000 --> 00:11:23,000
+reference data source or use a set of properties to configure a database connection.
+
+128
+00:11:23,000 --> 00:11:29,000
+In the minute I'm going to show you properties that we use to configure a database connection.
+
+129
+00:11:30,000 --> 00:11:33,000
+Let's continue then in other configurations.
+
+130
+00:11:33,000 --> 00:11:40,000
+The next thing that we need to do is to specify the managed classes included in the persistence unit.
+
+131
+00:11:40,000 --> 00:11:48,000
+By default, your GPA Persistence Unit includes all other paid and managed classes found in its root.
+
+132
+00:11:49,000 --> 00:11:56,000
+If you want to include any classes that are located somewhere else, you can either reference them explicitly
+
+133
+00:11:56,000 --> 00:12:00,000
+or include all classes from a jar file.
+
+134
+00:12:00,000 --> 00:12:06,000
+Each class element needs to contain the full reference name of a class.
+
+135
+00:12:06,000 --> 00:12:11,000
+Please be aware that these classes need to be available on your class.
+
+136
+00:12:11,000 --> 00:12:11,000
+Pass.
+
+137
+00:12:12,000 --> 00:12:17,000
+Here you can see commanded example of adding our user class.
+
+138
+00:12:17,000 --> 00:12:25,000
+And also here is a command example of specifying the whole jar instead of specifying all classes from
+
+139
+00:12:25,000 --> 00:12:25,000
+the jar.
+
+140
+00:12:26,000 --> 00:12:28,000
+You can also do other way around.
+
+141
+00:12:28,000 --> 00:12:34,000
+You can add vividly classes to the persistence yield and exclude all other classes.
+
+142
+00:12:34,000 --> 00:12:43,000
+To do that, you first need to use one or more class elements to explicitly specify which managed classes
+
+143
+00:12:43,000 --> 00:12:44,000
+shall be part of.
+
+144
+00:12:44,000 --> 00:12:48,000
+The persistence unit is the next step.
+
+145
+00:12:48,000 --> 00:12:55,000
+You can use the exclude unlisted classes elements to exclude all classes from the persistence unit,
+
+146
+00:12:55,000 --> 00:12:58,000
+which were not explicitly included.
+
+147
+00:12:59,000 --> 00:13:03,000
+The next step is to specify concrete persistence provider.
+
+148
+00:13:04,000 --> 00:13:11,000
+If you use any proprietary features of your persistence provider, you should specify dependency to
+
+149
+00:13:11,000 --> 00:13:11,000
+it.
+
+150
+00:13:11,000 --> 00:13:19,000
+You can do that by defining the name of the class that implements the persistence provider interface
+
+151
+00:13:19,000 --> 00:13:21,000
+in the provider element.
+
+152
+00:13:21,000 --> 00:13:26,000
+In this particular example, I specify hibernate, persistence provided.
+
+153
+00:13:27,000 --> 00:13:30,000
+Now let's add Jeep properties.
+
+154
+00:13:30,000 --> 00:13:34,000
+We are going to configure our database connection here.
+
+155
+00:13:34,000 --> 00:13:39,000
+You can see GBC driver class your URL, username and password.
+
+156
+00:13:40,000 --> 00:13:44,000
+As you can see, your row contains the name of the database.
+
+157
+00:13:44,000 --> 00:13:50,000
+That means that I already created a database before running this example.
+
+158
+00:13:51,000 --> 00:13:57,000
+So not so much new properties here ever since should look familiar to you and ever.
+
+159
+00:13:57,000 --> 00:14:04,000
+What we have learned with my students in the GBK port of my Java from zero to first job course.
+
+160
+00:14:05,000 --> 00:14:12,000
+The next step is to configure properties that would tell GP implementation what to do with regards to
+
+161
+00:14:12,000 --> 00:14:12,000
+schema.
+
+162
+00:14:13,000 --> 00:14:21,000
+Since version 2.1, GP can create a new database at startup and initialize it with a predefined data
+
+163
+00:14:21,000 --> 00:14:29,000
+set, you can activate and configure this feature by adding the foreign properties to your configuration.
+
+164
+00:14:29,000 --> 00:14:33,000
+Jakarta Persistent Schema Generation Database Action.
+
+165
+00:14:34,000 --> 00:14:40,000
+The actions that you want to perform to manage the database schema supported values are none.
+
+166
+00:14:41,000 --> 00:14:44,000
+Create, drop and create and drop.
+
+167
+00:14:44,000 --> 00:14:46,000
+As you probably expect.
+
+168
+00:14:46,000 --> 00:14:54,000
+The create option creates a database schema, start up, drop and create, drops the existing database
+
+169
+00:14:54,000 --> 00:14:59,000
+and creates a new one and drop just removes the existing database.
+
+170
+00:15:00,000 --> 00:15:08,000
+Jakarta Persistent Schema Generation Creates Script source the name of file euro to the script that
+
+171
+00:15:08,000 --> 00:15:10,000
+creates the database.
+
+172
+00:15:10,000 --> 00:15:18,000
+Jakarta Persistence Schema Generation Drop Script Source The name of file URL to the script.
+
+173
+00:15:18,000 --> 00:15:26,000
+The drops is a database Jakarta Persistent SQL Loss Script Source The name of file.
+
+174
+00:15:26,000 --> 00:15:31,000
+You will choose a script that initializes the database with a predefined data set.
+
+175
+00:15:32,000 --> 00:15:36,000
+Now let's specify Hebrew dialect.
+
+176
+00:15:36,000 --> 00:15:37,000
+What is it?
+
+177
+00:15:37,000 --> 00:15:47,000
+A Hebrew dialect gives information to the framework of how to convert hibernate queries HQ l into native
+
+178
+00:15:47,000 --> 00:15:48,000
+SQL queries.
+
+179
+00:15:49,000 --> 00:15:54,000
+Since Hibernate is a database agnostic, it can work with different databases.
+
+180
+00:15:55,000 --> 00:16:04,000
+However, databases have proprietary extensions, native SQL variations and set subset of SQL standard
+
+181
+00:16:04,000 --> 00:16:05,000
+implementations.
+
+182
+00:16:06,000 --> 00:16:10,000
+And it looks like we're all glued to proceed with our code example.
+
+183
+00:16:10,000 --> 00:16:14,000
+Let me open them across that I prepared for this lesson.
+
+184
+00:16:15,000 --> 00:16:18,000
+The main method I create entity manager factory.
+
+185
+00:16:18,000 --> 00:16:26,000
+First to do this, I use persistence clause first and call create entity manager factory method and
+
+186
+00:16:26,000 --> 00:16:29,000
+pass the name of my persistence unit.
+
+187
+00:16:29,000 --> 00:16:33,000
+Once a great entity manager factory.
+
+188
+00:16:33,000 --> 00:16:35,000
+I can create an entity manager.
+
+189
+00:16:35,000 --> 00:16:37,000
+Just call create entity manager.
+
+190
+00:16:37,000 --> 00:16:40,000
+Method on the entity manager factory.
+
+191
+00:16:40,000 --> 00:16:48,000
+The entity manager instance represents a connection to the database when using GP, every operation
+
+192
+00:16:48,000 --> 00:16:52,000
+on a database is associated with the entity manager.
+
+193
+00:16:52,000 --> 00:16:59,000
+Further in a multithreaded application, every thread usually has its own entity manager instance,
+
+194
+00:16:59,000 --> 00:17:05,000
+while at the same time sharing a single application wide entity manager factory.
+
+195
+00:17:06,000 --> 00:17:14,000
+Operations that modified database content such as store update and delete, should only be performed
+
+196
+00:17:14,000 --> 00:17:16,000
+within an active transaction.
+
+197
+00:17:16,000 --> 00:17:21,000
+That's why we need to start a transaction when a transaction is active.
+
+198
+00:17:21,000 --> 00:17:30,000
+You can invoke entity manager methods that modify the database content such as persist and remove.
+
+199
+00:17:30,000 --> 00:17:38,000
+Database updates are collected and managed in memory and apply to the database once the transaction
+
+200
+00:17:38,000 --> 00:17:39,000
+is completed.
+
+201
+00:17:39,000 --> 00:17:43,000
+So I created an instance of a user type.
+
+202
+00:17:43,000 --> 00:17:47,000
+This is entity type that we created during the lesson.
+
+203
+00:17:47,000 --> 00:17:54,000
+I initialize object with some random state and after that I call persist massive.
+
+204
+00:17:55,000 --> 00:18:00,000
+Now I want to get the reference to the transaction and commit transaction.
+
+205
+00:18:00,000 --> 00:18:04,000
+I call that transaction and commit mass.
+
+206
+00:18:04,000 --> 00:18:11,000
+Also, we shouldn't forget that after we finished using empathy manager and entity manager factory,
+
+207
+00:18:11,000 --> 00:18:12,000
+we have to close them.
+
+208
+00:18:13,000 --> 00:18:18,000
+Just go close mass on the object that we initialize.
+
+209
+00:18:19,000 --> 00:18:24,000
+Let's open my SQL workbench now and take a look what we have received.
+
+210
+00:18:24,000 --> 00:18:27,000
+In scope of the lesson, I created two entities.
+
+211
+00:18:27,000 --> 00:18:29,000
+User and project.
+
+212
+00:18:29,000 --> 00:18:36,000
+When I showed example of composite primary key, you can also see a sequence table.
+
+213
+00:18:36,000 --> 00:18:45,000
+That is because we used all the generation type for our user ID, starting with Hibernate version 5.0.
+
+214
+00:18:45,000 --> 00:18:54,000
+When generation type is selected as auto hibernate uses sequence style generator regardless of the database.
+
+215
+00:18:54,000 --> 00:19:04,000
+In this case, my SQL Hibernate emulates a sequence using a table and is why you see the sequence table.
+
+216
+00:19:04,000 --> 00:19:08,000
+Anyway, we reviewed today different generation types.
+
+217
+00:19:08,000 --> 00:19:11,000
+You can select the one you like the most.
+
+218
+00:19:11,000 --> 00:19:17,000
+And if we would take a look at the content of the user table, we are going to see that information
+
+219
+00:19:17,000 --> 00:19:18,000
+about our user.
+
+220
+00:19:18,000 --> 00:19:21,000
+John Smith was successfully persisted.
+
+221
+00:19:22,000 --> 00:19:24,000
+It is not all about GPA.
+
+222
+00:19:24,000 --> 00:19:26,000
+This is just the beginning.
+
+223
+00:19:26,000 --> 00:19:31,000
+We still have a lot of things to learn about GPA and hibernate in particular.
+
+224
+00:19:31,000 --> 00:19:38,000
+But today we learned already just enough information to perform simple persistence operation.
+
+225
+00:19:39,000 --> 00:19:43,000
+Congratulations with your first GPA coding example.
+
+226
+00:19:43,000 --> 00:19:48,000
+As always, I'm going to leave the reference to the source code in attachments to the lesson.
+
+227
+00:19:49,000 --> 00:19:54,000
+I encourage you to download the source code and run it on your local computer.
+
+228
+00:19:54,000 --> 00:20:00,000
+Play with the code and ask questions below this video in case something would remain not clear.
+
+229
+00:20:00,000 --> 00:20:03,000
+And I will be happy to answer.
+
+230
+00:20:03,000 --> 00:20:06,000
+Let's recap what we have learned today.
+
+231
+00:20:07,000 --> 00:20:11,000
+In this lesson, we created our first GPA project.
+
+232
+00:20:11,000 --> 00:20:15,000
+I explained what entities in GPA are.
+
+233
+00:20:15,000 --> 00:20:19,000
+We learned different adaptations to configure entity.
+
+234
+00:20:19,000 --> 00:20:27,000
+Some of the key annotations we learned are an entity table column ID generated value.
+
+235
+00:20:28,000 --> 00:20:31,000
+We learned different strategies for ID generation.
+
+236
+00:20:32,000 --> 00:20:35,000
+Now you know, key requirements for entity class.
+
+237
+00:20:35,000 --> 00:20:40,000
+And after this lesson, you can easily create your own entity classes.
+
+238
+00:20:41,000 --> 00:20:44,000
+We learned how to work with composite primary keys.
+
+239
+00:20:44,000 --> 00:20:49,000
+You saw why we need and how to use temporal annotation.
+
+240
+00:20:50,000 --> 00:20:55,000
+I explained how to avoid persistence some fields with transient annotation.
+
+241
+00:20:56,000 --> 00:21:03,000
+We reviewed how to configure persistence of enum types and we learned enumerated annotation.
+
+242
+00:21:03,000 --> 00:21:09,000
+After this lesson, you learned what entity, manager, factory and what entity manager is.
+
+243
+00:21:09,000 --> 00:21:15,000
+Together, we created our persistence XML file and learned the key configurations.
+
+244
+00:21:16,000 --> 00:21:22,000
+I explained transactions in GBA and we talked about different transaction types in GBA.
+
+245
+00:21:23,000 --> 00:21:24,000
+We compared.
+
+246
+00:21:24,000 --> 00:21:29,000
+What is the difference between GTA and resource local transactions?
+
+247
+00:21:30,000 --> 00:21:32,000
+That's all what I wanted to share with you today.
+
+248
+00:21:32,000 --> 00:21:34,000
+Thanks a lot for your attention.
+
+249
+00:21:34,000 --> 00:21:38,000
+Have a great day and see you in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/003 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/003 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..1eadb49b4e4606157cc6db2f92dc89b26b4bcd76
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/003 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/004 Operations with Entity (Create, Read, Update, Delete) & JPA Entity Lifecycle_en.srt b/78 - ORM, JPA & Hibernate/004 Operations with Entity (Create, Read, Update, Delete) & JPA Entity Lifecycle_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..e527e326bf522c68ac96b8c1925d61266e6f559d
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/004 Operations with Entity (Create, Read, Update, Delete) & JPA Entity Lifecycle_en.srt
@@ -0,0 +1,884 @@
+1
+00:00:06,000 --> 00:00:07,000
+Hello, team.
+
+2
+00:00:07,000 --> 00:00:11,000
+In this lesson, we're again going to have a lot of practical activity.
+
+3
+00:00:11,000 --> 00:00:18,000
+In this lesson, we're going to know how to perform basic operations with GP and these operations like
+
+4
+00:00:18,000 --> 00:00:21,000
+create, read, update and delete.
+
+5
+00:00:21,000 --> 00:00:25,000
+And we will talk about GPA and the life cycle.
+
+6
+00:00:25,000 --> 00:00:34,000
+We're going to start from examples that show us how to perform crude operations with GPA entities.
+
+7
+00:00:34,000 --> 00:00:41,000
+We're going to review GPA API to create, read, update and delete our entities.
+
+8
+00:00:42,000 --> 00:00:48,000
+After this lesson, you're going to have ready to use examples to perform all basic operations with
+
+9
+00:00:48,000 --> 00:00:53,000
+GPA, and this will learn states of GPA entities.
+
+10
+00:00:53,000 --> 00:01:03,000
+We're going to learn four main states of GPA, entity, zero new, persistent, detached and removed.
+
+11
+00:01:03,000 --> 00:01:09,000
+And once we learned all this, we are going to run GPA, entity lifecycle.
+
+12
+00:01:09,000 --> 00:01:16,000
+And I'm going to show you how you can handle events related with GPA and the life cycle.
+
+13
+00:01:16,000 --> 00:01:18,000
+Let's start our lesson.
+
+14
+00:01:19,000 --> 00:01:25,000
+As everybody said in this lesson, we're going to learn topics by examples and we are going to start
+
+15
+00:01:25,000 --> 00:01:27,000
+from the demo straightaway.
+
+16
+00:01:27,000 --> 00:01:34,000
+Before we start, I'd like to say that all examples that I'm going to share with you today are located
+
+17
+00:01:34,000 --> 00:01:37,000
+in the package that is called Lifecycle.
+
+18
+00:01:38,000 --> 00:01:45,000
+I copied user entities that we created together in previous lesson and I just gave it another name to
+
+19
+00:01:45,000 --> 00:01:49,000
+avoid conflicts with a user from another lesson.
+
+20
+00:01:49,000 --> 00:01:58,000
+So key which in previous lesson is important for understanding of this lesson, I just wanted to highlight
+
+21
+00:01:58,000 --> 00:02:02,000
+that I recommend you to not skip lessons.
+
+22
+00:02:03,000 --> 00:02:04,000
+Let me run the program.
+
+23
+00:02:05,000 --> 00:02:13,000
+This demo program produces console output that will help us to understand it better and how the application
+
+24
+00:02:13,000 --> 00:02:13,000
+works.
+
+25
+00:02:14,000 --> 00:02:20,000
+So user class is similar to the one that we created together in the previous lesson.
+
+26
+00:02:21,000 --> 00:02:23,000
+There is nothing new so far here.
+
+27
+00:02:24,000 --> 00:02:30,000
+I open demo class will learn how to configure entity manager factory.
+
+28
+00:02:30,000 --> 00:02:33,000
+We also get the references to entity manager object.
+
+29
+00:02:33,000 --> 00:02:36,000
+We created user objects that we want to persist.
+
+30
+00:02:37,000 --> 00:02:44,000
+In this lesson you saw how we call persist mass and that is great that we'll really learn this method
+
+31
+00:02:44,000 --> 00:02:46,000
+from the API.
+
+32
+00:02:46,000 --> 00:02:53,000
+Just wanted to recap this quickly with you, but how we can get an idea of the entities that we persisted
+
+33
+00:02:54,000 --> 00:03:01,000
+because in real life idea of the objects that we have just saved can be required for business logic.
+
+34
+00:03:02,000 --> 00:03:07,000
+For example, you need to pass ID for the further operation.
+
+35
+00:03:07,000 --> 00:03:15,000
+So after calling persist method on the entity manager with user object, we can extract ID from the
+
+36
+00:03:15,000 --> 00:03:15,000
+user.
+
+37
+00:03:16,000 --> 00:03:17,000
+It will be already there.
+
+38
+00:03:17,000 --> 00:03:23,000
+I just print it to console to show that we really received a value here.
+
+39
+00:03:24,000 --> 00:03:32,000
+Now let's find the way how we can read entity from the database to find an entity entity manager interface
+
+40
+00:03:32,000 --> 00:03:38,000
+provides find method that searches an element on the basis of primary key.
+
+41
+00:03:38,000 --> 00:03:43,000
+And for the sake of the demo, we'll work with the same entity that we have persisted.
+
+42
+00:03:44,000 --> 00:03:47,000
+So we already took the primary key.
+
+43
+00:03:48,000 --> 00:03:55,000
+Probably the simplest version is to call, find, method and pass and the class that we want to find
+
+44
+00:03:55,000 --> 00:04:03,000
+and the primary key, basically that's it and entity manager will be able to find the requested entity.
+
+45
+00:04:04,000 --> 00:04:10,000
+And here so you can see that we found the users that we have persisted in the previous example.
+
+46
+00:04:11,000 --> 00:04:13,000
+Font mass is overlord.
+
+47
+00:04:13,000 --> 00:04:16,000
+There are also other versions of this message.
+
+48
+00:04:17,000 --> 00:04:18,000
+Let me show it to you.
+
+49
+00:04:19,000 --> 00:04:26,000
+Find mass where we pass entity class, primary key and also map of properties.
+
+50
+00:04:27,000 --> 00:04:35,000
+Basically, no matter which GP implementation you use, you can find properties that you can add to
+
+51
+00:04:35,000 --> 00:04:36,000
+the query.
+
+52
+00:04:36,000 --> 00:04:43,000
+For example, in Eclipse League documentation, you can find that you can add such properties that are
+
+53
+00:04:43,000 --> 00:04:46,000
+actually key value pairs.
+
+54
+00:04:46,000 --> 00:04:49,000
+Eclipse link cache usage.
+
+55
+00:04:49,000 --> 00:04:51,000
+Eclipsing query type.
+
+56
+00:04:51,000 --> 00:04:52,000
+Eclipse link.
+
+57
+00:04:52,000 --> 00:04:53,000
+Pessimistic log.
+
+58
+00:04:53,000 --> 00:04:54,000
+Eclipse link.
+
+59
+00:04:54,000 --> 00:04:55,000
+Refresh.
+
+60
+00:04:55,000 --> 00:04:56,000
+Eclipse link.
+
+61
+00:04:56,000 --> 00:05:00,000
+Botch eclipse link with only gdb.
+
+62
+00:05:00,000 --> 00:05:04,000
+Timeout fetch size max rows etc..
+
+63
+00:05:04,000 --> 00:05:11,000
+So in case you need to exit it, select where with some properties you know how to do this with gpa
+
+64
+00:05:11,000 --> 00:05:12,000
+api.
+
+65
+00:05:13,000 --> 00:05:20,000
+Another version of Overlord mascot is Wiz and the gloss primary key and lock mode type.
+
+66
+00:05:21,000 --> 00:05:28,000
+Lock mode type is an enum GP lock and is a little bit specific topic to learn.
+
+67
+00:05:28,000 --> 00:05:33,000
+And I'd like to have a separate lesson dedicated to the GP lock.
+
+68
+00:05:33,000 --> 00:05:41,000
+As of now, you can just remember that you have opportunities to specify a lock type for the find operation.
+
+69
+00:05:41,000 --> 00:05:48,000
+In short, this lock in type helps us to solve the issue of concurrent access to the data.
+
+70
+00:05:49,000 --> 00:05:57,000
+For example, if you need to reserve some data for operations and you need no one else with touch ID
+
+71
+00:05:57,000 --> 00:06:05,000
+you can consider is a configuring of propagation level of your transaction or lock in options, both
+
+72
+00:06:05,000 --> 00:06:07,000
+propagation levels and locking.
+
+73
+00:06:07,000 --> 00:06:10,000
+We're going to learn separately in the lesson.
+
+74
+00:06:10,000 --> 00:06:16,000
+For now, just remember that you have opportunity to use find massive locking.
+
+75
+00:06:17,000 --> 00:06:23,000
+And the fourth version of Fine Mass is a combination of the previous two that we have discussed.
+
+76
+00:06:23,000 --> 00:06:29,000
+You can use properties and lock more type together with entity, class and ID.
+
+77
+00:06:30,000 --> 00:06:33,000
+Let's move on and learn how we can update entity.
+
+78
+00:06:34,000 --> 00:06:36,000
+Here is the refresh mascot.
+
+79
+00:06:37,000 --> 00:06:44,000
+Refresh mascot refreshes the state of the instance from the database, our write in changes made to
+
+80
+00:06:44,000 --> 00:06:46,000
+the entity, if any.
+
+81
+00:06:46,000 --> 00:06:50,000
+It also triggers post load event handler.
+
+82
+00:06:51,000 --> 00:06:57,000
+Dubai also has API that allows us to update entity with ease.
+
+83
+00:06:57,000 --> 00:07:03,000
+So here we received the entity from the database after we received it.
+
+84
+00:07:03,000 --> 00:07:08,000
+We can say the entity is managed by our entity manager.
+
+85
+00:07:08,000 --> 00:07:14,000
+We can change its state and entity manager will track these changes.
+
+86
+00:07:14,000 --> 00:07:22,000
+Once transaction will be committed, the state of the entity will be also updated in the database.
+
+87
+00:07:22,000 --> 00:07:24,000
+Basically, that's it.
+
+88
+00:07:24,000 --> 00:07:32,000
+You don't need to call even some special masses like update or anything else because usually we is a
+
+89
+00:07:32,000 --> 00:07:42,000
+persistent it is a first time or it is already persisted and we extracted and updated to help you understand
+
+90
+00:07:42,000 --> 00:07:45,000
+the different states of entities.
+
+91
+00:07:45,000 --> 00:07:48,000
+Let's take a look at the following slide.
+
+92
+00:07:48,000 --> 00:07:57,000
+An object that GP or any GP implementation like hibernate can persist in the database and retrieve it
+
+93
+00:07:57,000 --> 00:08:00,000
+back whenever needed is called an entity.
+
+94
+00:08:00,000 --> 00:08:06,000
+And we already learned this GP manages various states of these entities.
+
+95
+00:08:07,000 --> 00:08:11,000
+Basically there are four states of an object in GP.
+
+96
+00:08:12,000 --> 00:08:22,000
+They are new or transient, persistent, unmanaged, detached or unmanaged and removed or deleted.
+
+97
+00:08:23,000 --> 00:08:28,000
+Understanding of the persistent context is crucial at this moment.
+
+98
+00:08:28,000 --> 00:08:33,000
+In the previous lesson, we talked a little bit about persistence, context.
+
+99
+00:08:33,000 --> 00:08:38,000
+But let me elaborate more about it in simple words.
+
+100
+00:08:38,000 --> 00:08:43,000
+The persistence context sits between the client code and data store.
+
+101
+00:08:44,000 --> 00:08:53,000
+It's a staging area where persistent data is converted to entities ready to be read and altered by client
+
+102
+00:08:53,000 --> 00:08:53,000
+code.
+
+103
+00:08:54,000 --> 00:09:03,000
+It keeps track of all law that data tracks changes of that data and is responsible to eventually synchronize
+
+104
+00:09:03,000 --> 00:09:08,000
+any changes back to the database at the end of the business transaction.
+
+105
+00:09:09,000 --> 00:09:17,000
+GP and the key manager and hibernate session types are in implementation of the persistence context
+
+106
+00:09:17,000 --> 00:09:18,000
+concept.
+
+107
+00:09:18,000 --> 00:09:26,000
+An object that is newly created and has never been associated with a persistence context is that this
+
+108
+00:09:26,000 --> 00:09:33,000
+entity, manager or Hibernate session is considered to be in the new or transient state.
+
+109
+00:09:33,000 --> 00:09:38,000
+The data of object in this state is not stored in the database.
+
+110
+00:09:39,000 --> 00:09:46,000
+It is the case when we have just created user object, but our entity manager knows nothing about this
+
+111
+00:09:46,000 --> 00:09:47,000
+object.
+
+112
+00:09:47,000 --> 00:09:51,000
+We can say that object is in use state.
+
+113
+00:09:52,000 --> 00:10:00,000
+When an object is associated with a persistent context and the key manager or hibernate session, we
+
+114
+00:10:00,000 --> 00:10:06,000
+can say that object is in persistent state or in another way managed.
+
+115
+00:10:07,000 --> 00:10:16,000
+Any changes made to objects in this state are automatically propagated to databases without manually
+
+116
+00:10:16,000 --> 00:10:18,000
+invoking other methods.
+
+117
+00:10:19,000 --> 00:10:23,000
+That is how we updated the user entity in our example.
+
+118
+00:10:23,000 --> 00:10:27,000
+So we extracted the user from the database.
+
+119
+00:10:27,000 --> 00:10:37,000
+It was in persistent state and we just updated it and the key manager tracks these changes because this
+
+120
+00:10:37,000 --> 00:10:41,000
+user object was already associated with a persistent context.
+
+121
+00:10:41,000 --> 00:10:43,000
+Is it clear?
+
+122
+00:10:43,000 --> 00:10:50,000
+And no object becomes detached when the currently running persistent context is closed.
+
+123
+00:10:51,000 --> 00:10:58,000
+Any changes made to the touched objects are no longer automatically propagated to the database.
+
+124
+00:10:58,000 --> 00:11:05,000
+Once commit is executed on the entity transaction object, the object becomes detached.
+
+125
+00:11:06,000 --> 00:11:14,000
+This is seems to be logical that once you call the commit method you shouldn't update the object and
+
+126
+00:11:14,000 --> 00:11:17,000
+sync that it will be updated in the persistent context.
+
+127
+00:11:18,000 --> 00:11:24,000
+Because we already learned with you that in GP all actions happen within the transaction.
+
+128
+00:11:25,000 --> 00:11:28,000
+No actions should be done outside of transactions.
+
+129
+00:11:29,000 --> 00:11:33,000
+Removed objects are deleted from the database.
+
+130
+00:11:33,000 --> 00:11:40,000
+GP provides entity manager remove method to remove an entity from the database.
+
+131
+00:11:40,000 --> 00:11:42,000
+I'm going to show this in a minute.
+
+132
+00:11:43,000 --> 00:11:45,000
+Let's proceed with the demo.
+
+133
+00:11:46,000 --> 00:11:50,000
+I left here to the example of one method.
+
+134
+00:11:50,000 --> 00:11:52,000
+Let me elaborate on that.
+
+135
+00:11:53,000 --> 00:12:01,000
+GPUs merge massive copies the state of a detached entity to manage the instance of the same entity.
+
+136
+00:12:02,000 --> 00:12:11,000
+Kubernetes therefore executes and SQL Select Statement to retrieve a managed entity from the database.
+
+137
+00:12:11,000 --> 00:12:19,000
+If the persistence context already contained a managed instance of the entity, Hibernate uses the existing
+
+138
+00:12:19,000 --> 00:12:21,000
+one instead.
+
+139
+00:12:21,000 --> 00:12:28,000
+It then copies all attribute values to the managed entity and returns it to the column.
+
+140
+00:12:29,000 --> 00:12:37,000
+But taking into account that our user from the BiH entity is in managed state, there is no need for
+
+141
+00:12:37,000 --> 00:12:39,000
+us to call merge statement.
+
+142
+00:12:40,000 --> 00:12:46,000
+Talking about the Dutch state, there is a separate mass that is called the Dutch.
+
+143
+00:12:46,000 --> 00:12:52,000
+Invocation of this mass allows us to detach entity from the persistent context.
+
+144
+00:12:53,000 --> 00:13:01,000
+So any changes applied to this entity after calling the Dutch method will not be automatically propagated
+
+145
+00:13:01,000 --> 00:13:02,000
+to the database.
+
+146
+00:13:03,000 --> 00:13:04,000
+Is it clear?
+
+147
+00:13:04,000 --> 00:13:12,000
+And even in case you still have any questions, please do not hesitate to ask your questions below the
+
+148
+00:13:12,000 --> 00:13:15,000
+video and I will be happy to answer.
+
+149
+00:13:16,000 --> 00:13:18,000
+And there is another operation left.
+
+150
+00:13:19,000 --> 00:13:23,000
+Let me remove operation for the sake of the dam.
+
+151
+00:13:23,000 --> 00:13:28,000
+I created one more user and I persisted with first.
+
+152
+00:13:29,000 --> 00:13:32,000
+You already saw how this method works.
+
+153
+00:13:32,000 --> 00:13:35,000
+And after that I call remove mass.
+
+154
+00:13:36,000 --> 00:13:39,000
+The method works as it is expected.
+
+155
+00:13:40,000 --> 00:13:48,000
+So user two is removed from the persistent context and after commit it will be removed from the database.
+
+156
+00:13:49,000 --> 00:13:52,000
+Everything is simple and predictable here.
+
+157
+00:13:53,000 --> 00:13:58,000
+So we have just learned how to perform basic CRUD operations with our entities.
+
+158
+00:13:59,000 --> 00:14:07,000
+We also learned what kind of state between entity and persistent context can be and how to manage this
+
+159
+00:14:07,000 --> 00:14:08,000
+state.
+
+160
+00:14:08,000 --> 00:14:09,000
+Amazing.
+
+161
+00:14:09,000 --> 00:14:12,000
+Let's proceed with our agenda.
+
+162
+00:14:13,000 --> 00:14:20,000
+Also in this lesson, I was about to show you life cycle events and how we can handle them.
+
+163
+00:14:21,000 --> 00:14:30,000
+When we work with GP and zero different lifecycle events that we can work with, we can programme our
+
+164
+00:14:30,000 --> 00:14:39,000
+logic in order to react on this lifecycle events and put any business logic we need in event handlers.
+
+165
+00:14:40,000 --> 00:14:45,000
+So Mark Masters, as events handlers, we have to use annotations.
+
+166
+00:14:46,000 --> 00:14:49,000
+I am going to show you annotations now.
+
+167
+00:14:49,000 --> 00:14:55,000
+So what kind of events I'm talking about before?
+
+168
+00:14:55,000 --> 00:14:59,000
+Persist is called for new entity purposes.
+
+169
+00:14:59,000 --> 00:15:04,000
+Annotation after persist is called for a new entity.
+
+170
+00:15:05,000 --> 00:15:10,000
+Post persist annotation before an entity is removed.
+
+171
+00:15:10,000 --> 00:15:15,000
+Prior remove annotation after an entity has been deleted.
+
+172
+00:15:15,000 --> 00:15:25,000
+Post Remove annotation before the update operation per update annotation after an entity is updated
+
+173
+00:15:26,000 --> 00:15:31,000
+post update annotation after an entity has been loaded.
+
+174
+00:15:31,000 --> 00:15:33,000
+Post Load Annotation.
+
+175
+00:15:34,000 --> 00:15:41,000
+So now we know what events we have, how and where we have to use these annotations.
+
+176
+00:15:41,000 --> 00:15:45,000
+There are two ways how we can use these annotations.
+
+177
+00:15:46,000 --> 00:15:54,000
+The first way is to create special event handler masses in the entity and annotate them with annotations
+
+178
+00:15:54,000 --> 00:15:56,000
+mentioned above.
+
+179
+00:15:56,000 --> 00:16:02,000
+Another option is to create a separate clause that would act as a listener.
+
+180
+00:16:03,000 --> 00:16:06,000
+I'm going to show you both options in this lesson.
+
+181
+00:16:07,000 --> 00:16:14,000
+If he has turned off my Java from zero to first job course, then you should be aware about event handling
+
+182
+00:16:14,000 --> 00:16:15,000
+concept.
+
+183
+00:16:15,000 --> 00:16:23,000
+We even had a separate lesson about handling of the server context, server request and session events.
+
+184
+00:16:23,000 --> 00:16:25,000
+So the concept is simple.
+
+185
+00:16:26,000 --> 00:16:28,000
+Some event is happening.
+
+186
+00:16:28,000 --> 00:16:37,000
+For example, colon persist, mass will trigger an event and the master annotated with annotation purposes
+
+187
+00:16:37,000 --> 00:16:43,000
+will be called and after record will be inserted into the database.
+
+188
+00:16:43,000 --> 00:16:44,000
+Post persists.
+
+189
+00:16:44,000 --> 00:16:46,000
+The method will be called.
+
+190
+00:16:46,000 --> 00:16:47,000
+Is it clear?
+
+191
+00:16:48,000 --> 00:16:50,000
+These attachments to the video lesson.
+
+192
+00:16:51,000 --> 00:16:53,000
+You can find the reference to the source code.
+
+193
+00:16:53,000 --> 00:16:55,000
+Examples from the lesson.
+
+194
+00:16:56,000 --> 00:17:01,000
+I encourage you to download the source code and run it on your computer.
+
+195
+00:17:02,000 --> 00:17:05,000
+Let me open our user entity clause here.
+
+196
+00:17:05,000 --> 00:17:13,000
+You can see that I added masses here and marked them with annotations that we have just reviewed.
+
+197
+00:17:13,000 --> 00:17:22,000
+Each event handler method like prep persist or post persist prints its own personalized message.
+
+198
+00:17:22,000 --> 00:17:23,000
+Can you see this?
+
+199
+00:17:24,000 --> 00:17:33,000
+That's how we will be able to identify which method was invoked after investigation of console output.
+
+200
+00:17:34,000 --> 00:17:41,000
+After running our demo file in console output, we can see log messages from entity and from listener
+
+201
+00:17:41,000 --> 00:17:42,000
+class.
+
+202
+00:17:42,000 --> 00:17:43,000
+One of the last.
+
+203
+00:17:44,000 --> 00:17:52,000
+And to make this class work and intercept events with user entity, we have to add entity listener's
+
+204
+00:17:52,000 --> 00:17:59,000
+annotation to the user entity and pass single class or array of classes.
+
+205
+00:18:00,000 --> 00:18:05,000
+In this particular case, we added the lifecycle listener class here.
+
+206
+00:18:05,000 --> 00:18:08,000
+One more important thing to mention.
+
+207
+00:18:08,000 --> 00:18:12,000
+Pay attention that matters in our listener class.
+
+208
+00:18:12,000 --> 00:18:15,000
+Takes user object as method argument.
+
+209
+00:18:16,000 --> 00:18:19,000
+This is user object that participate in event.
+
+210
+00:18:20,000 --> 00:18:27,000
+We can use this reference to the object to create all necessary business logic we need.
+
+211
+00:18:27,000 --> 00:18:33,000
+Now you know how to create event handlers and what is also important.
+
+212
+00:18:33,000 --> 00:18:42,000
+You understood GBA and the lifecycle and when entity is managed in the persistent context and when it
+
+213
+00:18:42,000 --> 00:18:46,000
+is detached from the persistent context and other states.
+
+214
+00:18:47,000 --> 00:18:50,000
+Let's recap what we have learned in this lesson.
+
+215
+00:18:51,000 --> 00:19:00,000
+In the lesson, we learn how to insert entity into a database, read from the database, updated and
+
+216
+00:19:00,000 --> 00:19:01,000
+remove it.
+
+217
+00:19:01,000 --> 00:19:10,000
+Also, we learned states of Gpe entities include a new power system, detached and removed state and
+
+218
+00:19:10,000 --> 00:19:14,000
+we learn how to handle entity lifecycle events.
+
+219
+00:19:15,000 --> 00:19:17,000
+That's all for this lesson.
+
+220
+00:19:17,000 --> 00:19:19,000
+Thanks a lot for your attention.
+
+221
+00:19:19,000 --> 00:19:22,000
+Have a great day and see you in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/004 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/004 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..c508d01ff019f24ebef04884237c1ff0be87025e
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/004 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/lifecycle
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/005 Locking JPA Optimistic & Pessimistic Locking_en.srt b/78 - ORM, JPA & Hibernate/005 Locking JPA Optimistic & Pessimistic Locking_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..7f2aae13fa10024678522b26bbf8b9e79cd8f89f
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/005 Locking JPA Optimistic & Pessimistic Locking_en.srt
@@ -0,0 +1,1320 @@
+1
+00:00:06,000 --> 00:00:07,000
+Hello, Tim.
+
+2
+00:00:07,000 --> 00:00:10,000
+Today we're going to have a very interesting lesson.
+
+3
+00:00:10,000 --> 00:00:14,000
+We'll have both theoretical and practical part.
+
+4
+00:00:14,000 --> 00:00:21,000
+It is very important for understanding of how enterprise applications work in the current environment.
+
+5
+00:00:22,000 --> 00:00:27,000
+Today, we're going to talk about locking optimistic and pessimistic locks.
+
+6
+00:00:28,000 --> 00:00:36,000
+Lennon These topics is important because sometimes you would need to make a decision which lock to apply
+
+7
+00:00:36,000 --> 00:00:42,000
+in order to optimize query execution and work with entities in the system.
+
+8
+00:00:43,000 --> 00:00:49,000
+We're going to start this lesson from understanding why we need locking.
+
+9
+00:00:49,000 --> 00:00:52,000
+I will explain to you what a database lock is.
+
+10
+00:00:52,000 --> 00:00:54,000
+We will review physical locks.
+
+11
+00:00:54,000 --> 00:00:56,000
+Logical locks.
+
+12
+00:00:56,000 --> 00:01:00,000
+I will explain the different lock and models in the GP.
+
+13
+00:01:00,000 --> 00:01:04,000
+Namely, we're going to talk about optimistic and pessimistic locking.
+
+14
+00:01:05,000 --> 00:01:10,000
+We'll review a version annotation and I will explain you why we need it.
+
+15
+00:01:10,000 --> 00:01:18,000
+Also, I am going to explain explicit log types and we'll review them on the example of lock mode type
+
+16
+00:01:18,000 --> 00:01:19,000
+enum.
+
+17
+00:01:19,000 --> 00:01:28,000
+And especially for this lesson I prepared coding demo that will help you to understand the topic better.
+
+18
+00:01:28,000 --> 00:01:33,000
+So let's start our lesson before watching this lesson.
+
+19
+00:01:33,000 --> 00:01:38,000
+It is recommended to watch lesson about transaction basics.
+
+20
+00:01:38,000 --> 00:01:45,000
+The lesson is from my job, from zero to first job course, where we learned basics of transactions
+
+21
+00:01:45,000 --> 00:01:50,000
+and about a main requirements to transactions.
+
+22
+00:01:51,000 --> 00:02:00,000
+Just to remind you that as it stands for automaticity, consistency, isolation and durability also
+
+23
+00:02:00,000 --> 00:02:08,000
+in some way and the standard of multithreading in topic in Java will help you to build analogy with
+
+24
+00:02:08,000 --> 00:02:10,000
+lurking in the database.
+
+25
+00:02:10,000 --> 00:02:19,000
+It is not absolutely the same, but as I said, and the standard new topic was analogy is always easier
+
+26
+00:02:19,000 --> 00:02:22,000
+rather than learning some new topic from scratch.
+
+27
+00:02:23,000 --> 00:02:29,000
+This information will help you better understand the context of the lesson, but you still can proceed
+
+28
+00:02:29,000 --> 00:02:31,000
+with watching this lesson.
+
+29
+00:02:31,000 --> 00:02:36,000
+And now let's understand why do we need locking?
+
+30
+00:02:36,000 --> 00:02:43,000
+When we talk about Java enterprise applications, it is very important to handle concurrent operations
+
+31
+00:02:43,000 --> 00:02:45,000
+to database properly.
+
+32
+00:02:45,000 --> 00:02:53,000
+So we need to handle bulk transactions in a very effective and in a without error way.
+
+33
+00:02:54,000 --> 00:03:01,000
+Also, we need to ensure data consistency between updates and concurrent reads operations.
+
+34
+00:03:01,000 --> 00:03:09,000
+In concurrency theory, locking is used for protecting immutable shared data against data integrity
+
+35
+00:03:09,000 --> 00:03:10,000
+anomalies.
+
+36
+00:03:11,000 --> 00:03:19,000
+Because lock management is a very complex problem, most applications rely on their data provider in
+
+37
+00:03:19,000 --> 00:03:21,000
+place locking techniques.
+
+38
+00:03:21,000 --> 00:03:28,000
+Delegating is the whole locking responsibility to the database system can both simplify application
+
+39
+00:03:28,000 --> 00:03:33,000
+development and prevent concurrency issues such as deadlock.
+
+40
+00:03:34,000 --> 00:03:41,000
+But still we need to learn how to work with lock in programmatically in order to achieve better performance
+
+41
+00:03:41,000 --> 00:03:44,000
+optimization and secure our GP.
+
+42
+00:03:44,000 --> 00:03:49,000
+And that is from lost updates and other concurrent interaction failures.
+
+43
+00:03:50,000 --> 00:03:56,000
+Let's understand what a database lock is and a database log.
+
+44
+00:03:56,000 --> 00:04:03,000
+Only one database user session can update a particular set of data.
+
+45
+00:04:03,000 --> 00:04:11,000
+A database lock prevents two or more users from updating the same piece of data at the same time.
+
+46
+00:04:12,000 --> 00:04:16,000
+So this is why databases have locks.
+
+47
+00:04:17,000 --> 00:04:21,000
+Because imagine the two threads of execution in our program.
+
+48
+00:04:21,000 --> 00:04:27,000
+Read data simultaneously, and the both of them made updates.
+
+49
+00:04:27,000 --> 00:04:31,000
+Which updates should be persisted in the database?
+
+50
+00:04:31,000 --> 00:04:36,000
+And what rules should be applied in case conflict will be found?
+
+51
+00:04:37,000 --> 00:04:41,000
+What should we do in case there is a risk of losing one update?
+
+52
+00:04:41,000 --> 00:04:50,000
+Because another update will erase the first update made from another thread database lock should help
+
+53
+00:04:50,000 --> 00:04:58,000
+us in answering all these questions by controlling access to the shared resource from different sessions
+
+54
+00:04:58,000 --> 00:04:59,000
+or threads.
+
+55
+00:05:00,000 --> 00:05:09,000
+And database lock is a mechanism that prevents or in other words, controls how the same data is used
+
+56
+00:05:09,000 --> 00:05:10,000
+simultaneously.
+
+57
+00:05:11,000 --> 00:05:18,000
+For example, we need to restrict simultaneous right access to the same row in the database to make
+
+58
+00:05:18,000 --> 00:05:21,000
+sure that data will stay consistent.
+
+59
+00:05:22,000 --> 00:05:32,000
+It is necessary to lock down data when multiple users access and update the same data at the same time.
+
+60
+00:05:32,000 --> 00:05:40,000
+Locks are used as a means of synchronizing the access by concurrent transactions to a database item.
+
+61
+00:05:41,000 --> 00:05:48,000
+Most applications tend to ignore thinking about concurrency issues during development, but at the end
+
+62
+00:05:48,000 --> 00:05:54,000
+of the day, engineering team adds lock mechanism before going to production.
+
+63
+00:05:55,000 --> 00:06:03,000
+If the application will have concurrent writers to the same objects, then the lock in strategy is critical
+
+64
+00:06:03,000 --> 00:06:06,000
+so that data corruption can be prevented.
+
+65
+00:06:07,000 --> 00:06:14,000
+Locking is a mechanism that allows parallel work with the same data in the database when more than one
+
+66
+00:06:14,000 --> 00:06:19,000
+transaction tries to access the same data at the same time.
+
+67
+00:06:19,000 --> 00:06:26,000
+Locks come into play which ensures that only one of these transactions will change.
+
+68
+00:06:26,000 --> 00:06:31,000
+The data database supports two types of locking mechanisms.
+
+69
+00:06:31,000 --> 00:06:34,000
+Optimistic model and pessimistic model.
+
+70
+00:06:35,000 --> 00:06:38,000
+Technically there is a search strategy.
+
+71
+00:06:38,000 --> 00:06:45,000
+Ostrich locking on no locking, which means put your head in the sand and ignore the issue.
+
+72
+00:06:46,000 --> 00:06:47,000
+Just a joke.
+
+73
+00:06:48,000 --> 00:06:55,000
+But before learning optimistic and pessimistic walking models, let's talk about physical blocks first.
+
+74
+00:06:55,000 --> 00:07:00,000
+Most database systems use shared and exclusive logs.
+
+75
+00:07:01,000 --> 00:07:09,000
+For example, shared logs are used for reading, and exclusive logs are used for writing operations.
+
+76
+00:07:10,000 --> 00:07:15,000
+Do you remember read write log from Java concurrent logs package.
+
+77
+00:07:15,000 --> 00:07:24,000
+Just as a comparison and analogy, let's remember multiple threats of execution can obtain multiple
+
+78
+00:07:25,000 --> 00:07:29,000
+logs in case there is no right log obtained.
+
+79
+00:07:29,000 --> 00:07:34,000
+Because when we read data we don't change its state.
+
+80
+00:07:35,000 --> 00:07:44,000
+But when at least one threat obtained write log, we can obtain read more and we can write simultaneously
+
+81
+00:07:44,000 --> 00:07:45,000
+to the same object.
+
+82
+00:07:46,000 --> 00:07:48,000
+That makes perfect sense.
+
+83
+00:07:48,000 --> 00:07:56,000
+The simplest things happening is a database, but instead of objects, our log in elements might be
+
+84
+00:07:56,000 --> 00:08:00,000
+either rows in the tables or whole tables.
+
+85
+00:08:00,000 --> 00:08:05,000
+While physical log is demanded by the SQL standard.
+
+86
+00:08:05,000 --> 00:08:08,000
+The pessimistic approach might hinder scalability.
+
+87
+00:08:09,000 --> 00:08:14,000
+Modern databases have implemented lightweight logging techniques.
+
+88
+00:08:14,000 --> 00:08:21,000
+The implicit database log is hidden behind the transaction isolation level configuration.
+
+89
+00:08:22,000 --> 00:08:29,000
+We are going to have a separate lesson about isolation levels and propagation during the transaction.
+
+90
+00:08:29,000 --> 00:08:33,000
+So don't worry, we'll learn these topics too.
+
+91
+00:08:33,000 --> 00:08:41,000
+Let's learn now more about logical logs and how they're different from the physical logs.
+
+92
+00:08:41,000 --> 00:08:49,000
+If database logging is sufficient for batch processing systems and monitor request, that flow spans
+
+93
+00:08:49,000 --> 00:08:52,000
+over several database transactions.
+
+94
+00:08:52,000 --> 00:09:00,000
+So the real life, real business context, you would need to perform multiple interactions, including
+
+95
+00:09:00,000 --> 00:09:08,000
+interactions with different database systems to perform a single business valuable operation.
+
+96
+00:09:08,000 --> 00:09:15,000
+For long conversations, a logical log and mechanism is much more appropriate.
+
+97
+00:09:15,000 --> 00:09:19,000
+Logical logs can be configured programmatically.
+
+98
+00:09:20,000 --> 00:09:25,000
+But today we'll focus our attention on the locking in the GP.
+
+99
+00:09:25,000 --> 00:09:27,000
+Let's discuss it.
+
+100
+00:09:28,000 --> 00:09:35,000
+As a database abstraction layer, Gpe can benefit from the implicit blocking mechanisms offered by the
+
+101
+00:09:35,000 --> 00:09:39,000
+underlying relational database management system.
+
+102
+00:09:40,000 --> 00:09:47,000
+Four logical looking GPA offers an optional automated entity version control mechanism as well.
+
+103
+00:09:48,000 --> 00:09:58,000
+GPS supports explicit lock in for the following operations finding an entity lock in an existing persistence
+
+104
+00:09:58,000 --> 00:10:07,000
+context entity refresh and an entity query through the GPC URL criteria on native queries.
+
+105
+00:10:08,000 --> 00:10:17,000
+As I already said, GPA supports two types of working mechanisms optimistic model and pessimistic model.
+
+106
+00:10:18,000 --> 00:10:21,000
+Let's learn the difference between these two models.
+
+107
+00:10:22,000 --> 00:10:30,000
+Insured optimistic looking is when a record is locked, only when changes are committed to the database,
+
+108
+00:10:30,000 --> 00:10:36,000
+and pessimistic locking is when a record is locked while it is added.
+
+109
+00:10:36,000 --> 00:10:44,000
+In both data locking models, the lock is released after the changes are committed is a database.
+
+110
+00:10:45,000 --> 00:10:49,000
+Let's learn deeper each of these locking models.
+
+111
+00:10:50,000 --> 00:10:59,000
+Optimistic law assumes that the data will not be modified between when you read the data until you write
+
+112
+00:10:59,000 --> 00:10:59,000
+the data.
+
+113
+00:11:00,000 --> 00:11:07,000
+This is the most common style of locking used and recommended in today's persistence solutions.
+
+114
+00:11:08,000 --> 00:11:16,000
+The strategy involves checking that one or more values from the original object read as still the same
+
+115
+00:11:16,000 --> 00:11:17,000
+when updating it.
+
+116
+00:11:18,000 --> 00:11:26,000
+This verifies that the object has not changed by another user in between the read and the run.
+
+117
+00:11:26,000 --> 00:11:33,000
+The optimistic log in model also referred to as Optimistic Concurrency Control.
+
+118
+00:11:33,000 --> 00:11:42,000
+It is a concurrency control method used in relational databases that doesn't use record locking.
+
+119
+00:11:42,000 --> 00:11:51,000
+Optimistic law can allows multiple users to attempt to update the same record without informing the
+
+120
+00:11:51,000 --> 00:11:55,000
+users that others are also attempting to update the record.
+
+121
+00:11:56,000 --> 00:12:01,000
+So the record changes are validated only once the record is committed.
+
+122
+00:12:02,000 --> 00:12:08,000
+If one user successfully updates the record, they are the users attempting to commit.
+
+123
+00:12:08,000 --> 00:12:13,000
+The concurrent updates are informed that a conflict exists.
+
+124
+00:12:14,000 --> 00:12:22,000
+An advantage of that reciprocal model is that it avoids the overhead of locking a record for the duration
+
+125
+00:12:22,000 --> 00:12:23,000
+of the action.
+
+126
+00:12:24,000 --> 00:12:30,000
+If there are no simultaneous updates, then this model provides fast updates.
+
+127
+00:12:30,000 --> 00:12:38,000
+Also in case there are only three operations optimistic law can works just fine.
+
+128
+00:12:39,000 --> 00:12:39,000
+Optimistic.
+
+129
+00:12:39,000 --> 00:12:46,000
+Walking is a useful approach when concurrent record updates are expected to be infrequent or the lock
+
+130
+00:12:46,000 --> 00:12:48,000
+in overhead is high.
+
+131
+00:12:49,000 --> 00:12:56,000
+GPA supports using an optimistic log conversion field that gets update on each update.
+
+132
+00:12:57,000 --> 00:13:06,000
+The field can either be numbered or a timestamp value and numeric value is recommended as a numeric
+
+133
+00:13:06,000 --> 00:13:13,000
+value is more precise, portable performance and easier to deal with than a timestamp.
+
+134
+00:13:14,000 --> 00:13:22,000
+The version annotation of version element in XML configuration is used to define the optimistic log
+
+135
+00:13:22,000 --> 00:13:23,000
+version filled.
+
+136
+00:13:24,000 --> 00:13:33,000
+The annotation is defined on the version field of property for the object similar to an ID mapping.
+
+137
+00:13:34,000 --> 00:13:38,000
+The object must contain an attribute to store the version filled.
+
+138
+00:13:39,000 --> 00:13:47,000
+The object's version attribute is automatically updated by the GPA provider and should not normally
+
+139
+00:13:47,000 --> 00:13:49,000
+be modified by the application.
+
+140
+00:13:50,000 --> 00:13:57,000
+The one exception is if the application reads, the object in one transaction sends the object to the
+
+141
+00:13:57,000 --> 00:14:03,000
+client and updates merges the object in another transaction.
+
+142
+00:14:03,000 --> 00:14:09,000
+In this case, the application must ensure that the original object version is used.
+
+143
+00:14:10,000 --> 00:14:16,000
+Otherwise, any changes in between read and write will not be detected.
+
+144
+00:14:17,000 --> 00:14:24,000
+When the lock in contention is detected and optimistic, lock exception will be strong.
+
+145
+00:14:24,000 --> 00:14:32,000
+This will be wrapped inside the rollback exception or the exceptions if using GTA, but it should be
+
+146
+00:14:32,000 --> 00:14:35,000
+set as a course of the exception.
+
+147
+00:14:35,000 --> 00:14:43,000
+The application can handle exception, but should normally report the error to the user and let them
+
+148
+00:14:43,000 --> 00:14:44,000
+determine what to do.
+
+149
+00:14:45,000 --> 00:14:54,000
+The pessimistic lock model prevents simultaneous updates to records as soon as one user starts to update
+
+150
+00:14:54,000 --> 00:14:55,000
+the record.
+
+151
+00:14:56,000 --> 00:14:58,000
+A log is placed on it.
+
+152
+00:14:59,000 --> 00:15:07,000
+Other users who attempt to update this record are informed that another user has an update in progress.
+
+153
+00:15:08,000 --> 00:15:17,000
+The other users must wait until the first user has finished committing their changes, thereby releasing
+
+154
+00:15:17,000 --> 00:15:18,000
+the record log.
+
+155
+00:15:18,000 --> 00:15:25,000
+Only then another user can make changes based on the previous user's changes.
+
+156
+00:15:26,000 --> 00:15:35,000
+The main issues with pessimistic logging is that they use database resources, so require a database
+
+157
+00:15:35,000 --> 00:15:40,000
+transaction and connection to be held open for the duration of the ad.
+
+158
+00:15:41,000 --> 00:15:46,000
+This is typically not desirable for interactive web applications.
+
+159
+00:15:47,000 --> 00:15:52,000
+A simplistic logging can also have concurrency issues and cause deadlocks.
+
+160
+00:15:53,000 --> 00:16:01,000
+The main advantage of pessimistic logging is that once the log is obtained, it is fairly certain that
+
+161
+00:16:01,000 --> 00:16:03,000
+the ad will be successful.
+
+162
+00:16:03,000 --> 00:16:11,000
+This can be desirable in highly concurrent applications, where optimistic law can make cause to many
+
+163
+00:16:11,000 --> 00:16:20,000
+optimistic logging errors during the pessimistic logging updates as serialized and each subsequent update
+
+164
+00:16:20,000 --> 00:16:24,000
+starts with a committed record changes from the previous user.
+
+165
+00:16:25,000 --> 00:16:32,000
+Pessimistic looking is a useful approach when subsequent updates can be delayed until a previous update
+
+166
+00:16:32,000 --> 00:16:33,000
+is completed.
+
+167
+00:16:34,000 --> 00:16:39,000
+This usually implies that updates appear in a short time interval.
+
+168
+00:16:40,000 --> 00:16:42,000
+Let's have a small demo now.
+
+169
+00:16:42,000 --> 00:16:47,000
+I will explain you explicit log types using the source code.
+
+170
+00:16:48,000 --> 00:16:56,000
+As you already saw in the previous lesson, when we talked about basic operations with entities, there
+
+171
+00:16:56,000 --> 00:17:01,000
+is an API that allows us to specify lock mode type.
+
+172
+00:17:02,000 --> 00:17:09,000
+For example, if you remember fired last, there is an overloaded version that takes a lock mode type
+
+173
+00:17:09,000 --> 00:17:12,000
+enum as one of the massive arguments.
+
+174
+00:17:13,000 --> 00:17:19,000
+There is also a loaded version of a fresh message that also uses this enum.
+
+175
+00:17:19,000 --> 00:17:25,000
+There is a separate method in the entity manager tab that is called lock to lock entity.
+
+176
+00:17:25,000 --> 00:17:26,000
+Vividly.
+
+177
+00:17:26,000 --> 00:17:35,000
+So let's review now lock mode type enum and understand a little bit more when we should use which in
+
+178
+00:17:36,000 --> 00:17:39,000
+the first one in the list is read.
+
+179
+00:17:39,000 --> 00:17:42,000
+Read is same as optimistic.
+
+180
+00:17:43,000 --> 00:17:47,000
+Just a synonym that you can use to increase readability of your code.
+
+181
+00:17:48,000 --> 00:17:51,000
+Optimistic is obviously optimistic.
+
+182
+00:17:51,000 --> 00:17:54,000
+Lock always issues aversion.
+
+183
+00:17:54,000 --> 00:17:55,000
+Check upon transaction.
+
+184
+00:17:55,000 --> 00:18:01,000
+Coming to the end of the lesson, I'm going to show you how to set the version.
+
+185
+00:18:01,000 --> 00:18:02,000
+Right.
+
+186
+00:18:02,000 --> 00:18:06,000
+Is a signal this optimistic force increment.
+
+187
+00:18:07,000 --> 00:18:15,000
+Optimistic force increment always increases the entity version even when the entity doesn't change and
+
+188
+00:18:15,000 --> 00:18:19,000
+issue aversion check upon transaction commit.
+
+189
+00:18:19,000 --> 00:18:20,000
+Today.
+
+190
+00:18:20,000 --> 00:18:22,000
+We're going to see this on example.
+
+191
+00:18:23,000 --> 00:18:24,000
+Pessimistic.
+
+192
+00:18:24,000 --> 00:18:31,000
+Read is a shared blog that is acquired to prevent any other transaction from acquiring a pessimistic
+
+193
+00:18:31,000 --> 00:18:33,000
+right lobe.
+
+194
+00:18:33,000 --> 00:18:41,000
+So in simple words, manage threats, manage transactions, can acquire pessimistic, read, log.
+
+195
+00:18:42,000 --> 00:18:49,000
+And while at least one transaction holds this law, no one else can obtain pessimistic write log.
+
+196
+00:18:50,000 --> 00:18:52,000
+Everything is easy and logical.
+
+197
+00:18:53,000 --> 00:19:01,000
+Pessimistic write log is an exclusive log as it is acquired to prevent any other transaction from acquiring
+
+198
+00:19:01,000 --> 00:19:05,000
+a pessimistic read or a pessimistic write log.
+
+199
+00:19:06,000 --> 00:19:15,000
+Exclusive log means that only one transaction can hold this log, and while this log is held by transaction,
+
+200
+00:19:15,000 --> 00:19:22,000
+no other transactions can obtain pessimistic read a pessimistic write lock.
+
+201
+00:19:22,000 --> 00:19:30,000
+Pessimistic force increment is a database log that is acquired to prevent any other transaction from
+
+202
+00:19:30,000 --> 00:19:34,000
+acquiring a pessimistic read or a pessimistic write log.
+
+203
+00:19:34,000 --> 00:19:42,000
+And the entity version is incremented upon transaction permit and now means that there is no log.
+
+204
+00:19:43,000 --> 00:19:51,000
+And now let's use a small example that I have prepared for this lesson in the package that is called
+
+205
+00:19:51,000 --> 00:19:52,000
+walking.
+
+206
+00:19:52,000 --> 00:19:58,000
+You can find again user class and city manager, helper and demo class.
+
+207
+00:19:59,000 --> 00:20:02,000
+Let me start from entity manager helper class.
+
+208
+00:20:02,000 --> 00:20:09,000
+The thing is, as we discussed in the first lessons when we have just started to learn what entity,
+
+209
+00:20:09,000 --> 00:20:18,000
+manager, factory and entity manager are, I told you that entity manager is not a threat safe and using
+
+210
+00:20:18,000 --> 00:20:23,000
+entity manager from different threats requires some extra attention.
+
+211
+00:20:24,000 --> 00:20:32,000
+Taking into account that in this lesson I need to show you a multithreading example imitating multiple
+
+212
+00:20:32,000 --> 00:20:36,000
+requests and multiple usage of entity manager from different threats.
+
+213
+00:20:37,000 --> 00:20:45,000
+We also need to prepare entity manager for work in multi threat environment, considering that in this
+
+214
+00:20:45,000 --> 00:20:51,000
+part of the course we're focusing on non and purely GP and hibernate.
+
+215
+00:20:51,000 --> 00:21:00,000
+I am not adding Sprint to our examples so far because not necessarily you will use spring on your future
+
+216
+00:21:00,000 --> 00:21:01,000
+project.
+
+217
+00:21:01,000 --> 00:21:10,000
+And anyway, you need to understand how GPA and GPA implementations work to have solid understanding
+
+218
+00:21:10,000 --> 00:21:14,000
+and be able to fix issues in case of any.
+
+219
+00:21:14,000 --> 00:21:22,000
+So in this entity manager helper class, I create one instance of entity manager factory.
+
+220
+00:21:22,000 --> 00:21:29,000
+That is fine because it is recommended to have only one instance of entity manager factory across all
+
+221
+00:21:29,000 --> 00:21:35,000
+the app and it is red safe, so we shouldn't face any problems with that.
+
+222
+00:21:35,000 --> 00:21:44,000
+And that great instance of threat lock using spring would make things easier because of the dependency
+
+223
+00:21:44,000 --> 00:21:45,000
+injection management.
+
+224
+00:21:46,000 --> 00:21:50,000
+Spring would handle all these things under the hood.
+
+225
+00:21:51,000 --> 00:21:57,000
+Please check the section about multithreading in my java from zero to first job course.
+
+226
+00:21:57,000 --> 00:22:01,000
+In that section we also learn what the thread local is.
+
+227
+00:22:02,000 --> 00:22:11,000
+That's why I wouldn't stop on this much, but ensure thread local object stores thread local variables.
+
+228
+00:22:11,000 --> 00:22:17,000
+Basically in each thread there will be a different variable inside this object.
+
+229
+00:22:18,000 --> 00:22:24,000
+This object like a container that will store different variables depending on the scrap.
+
+230
+00:22:25,000 --> 00:22:33,000
+You can imagine it like a map where the key will be the name of the spread and the value will be actually
+
+231
+00:22:33,000 --> 00:22:35,000
+value associated with this thread.
+
+232
+00:22:36,000 --> 00:22:41,000
+Using spread local looking store entity manager specific to each threat.
+
+233
+00:22:42,000 --> 00:22:50,000
+And here you can find some helpless masses to get entity manager and close entity manager to close.
+
+234
+00:22:50,000 --> 00:22:51,000
+Entity manager.
+
+235
+00:22:51,000 --> 00:22:54,000
+Factory and helper masses to begin.
+
+236
+00:22:54,000 --> 00:22:56,000
+Roll back and commit transactions.
+
+237
+00:22:57,000 --> 00:23:03,000
+Let me open now user class like we already discussed in the lesson.
+
+238
+00:23:03,000 --> 00:23:09,000
+I created a field of type that is annotated with the version annotation.
+
+239
+00:23:10,000 --> 00:23:18,000
+Depending on the log mode types that I'm going to use, the version of the entity will be updated and
+
+240
+00:23:18,000 --> 00:23:21,000
+now I'm going to show it to you.
+
+241
+00:23:22,000 --> 00:23:27,000
+I open a demo clause, we create one user and persisted.
+
+242
+00:23:27,000 --> 00:23:32,000
+In the class I use entity manager helper that I already showed you.
+
+243
+00:23:33,000 --> 00:23:38,000
+After that, I'm going to execute this same operation two times in different threads.
+
+244
+00:23:39,000 --> 00:23:42,000
+Let's understand what I do here.
+
+245
+00:23:42,000 --> 00:23:45,000
+I get the reference to the entity manager.
+
+246
+00:23:45,000 --> 00:23:47,000
+I start the transaction.
+
+247
+00:23:48,000 --> 00:23:56,000
+I find the users that I've just created and pay attention that this code will be executed two times
+
+248
+00:23:56,000 --> 00:23:58,000
+in different threads.
+
+249
+00:23:58,000 --> 00:23:59,000
+Is it clear?
+
+250
+00:23:59,000 --> 00:24:08,000
+I use execute the service to submit my tasks and again how to work with the execute the service we learn
+
+251
+00:24:08,000 --> 00:24:12,000
+in the Multithreading section of my Java from zero to first job course.
+
+252
+00:24:12,000 --> 00:24:15,000
+That's why I don't stop on this.
+
+253
+00:24:15,000 --> 00:24:23,000
+So each of the threads will have the reference to is actually the same record in the database.
+
+254
+00:24:23,000 --> 00:24:28,000
+Is it clear because each thread will find the same user?
+
+255
+00:24:29,000 --> 00:24:34,000
+After that I take the name of the thread for the login purposes.
+
+256
+00:24:34,000 --> 00:24:36,000
+We change email of the user.
+
+257
+00:24:37,000 --> 00:24:46,000
+New email will contain the name of the thread and we'll explore later what email will have our user
+
+258
+00:24:46,000 --> 00:24:47,000
+at them.
+
+259
+00:24:48,000 --> 00:24:52,000
+After that, I call Loch Mascot and our entity manager.
+
+260
+00:24:52,000 --> 00:24:55,000
+I paused the entity and Locke mode type.
+
+261
+00:24:56,000 --> 00:25:03,000
+I'm going to show you how our program will behave in case of the optimistic and pessimistic Locke.
+
+262
+00:25:04,000 --> 00:25:08,000
+And then we print which thread obtained is log?
+
+263
+00:25:08,000 --> 00:25:14,000
+It will be important for understanding the difference between optimistic and pessimistic log.
+
+264
+00:25:14,000 --> 00:25:21,000
+We can meet our transaction and also we print version and email here.
+
+265
+00:25:21,000 --> 00:25:24,000
+Put exception handler and print stack.
+
+266
+00:25:24,000 --> 00:25:27,000
+Trace the console to show you the exception.
+
+267
+00:25:27,000 --> 00:25:34,000
+That will happen when we will try to commit changes to the same entity from different spread.
+
+268
+00:25:35,000 --> 00:25:42,000
+And as am here, I just shut down the execution service that they used to submit tasks to different
+
+269
+00:25:42,000 --> 00:25:45,000
+threats and the close and the manager factory.
+
+270
+00:25:46,000 --> 00:25:47,000
+That's where I'm now.
+
+271
+00:25:47,000 --> 00:25:55,000
+Our application is the first one will be with pessimistic force increment, lock mode type.
+
+272
+00:25:57,000 --> 00:26:00,000
+And now let's investigate console output here.
+
+273
+00:26:01,000 --> 00:26:02,000
+What do we have here?
+
+274
+00:26:03,000 --> 00:26:11,000
+We see that the first thread was about to obtain a lock on user entity and the second threat was about
+
+275
+00:26:11,000 --> 00:26:12,000
+to do the same.
+
+276
+00:26:12,000 --> 00:26:17,000
+And we can see that only one thread managed to obtain the lock.
+
+277
+00:26:18,000 --> 00:26:25,000
+You can see that user version of the commit has been changed and in the email we have the name of the
+
+278
+00:26:25,000 --> 00:26:28,000
+thread that managed to obtain the log.
+
+279
+00:26:29,000 --> 00:26:31,000
+What happened was another thread.
+
+280
+00:26:32,000 --> 00:26:37,000
+And now the threat has been interrupted by optimistic exception.
+
+281
+00:26:37,000 --> 00:26:41,000
+Roe was updated or deleted by another transaction.
+
+282
+00:26:41,000 --> 00:26:45,000
+This exception in term is caused by stale objects.
+
+283
+00:26:45,000 --> 00:26:47,000
+State exception.
+
+284
+00:26:47,000 --> 00:26:51,000
+Exception happened in zero three of this demo file.
+
+285
+00:26:52,000 --> 00:26:55,000
+What conclusion we can make out of this.
+
+286
+00:26:55,000 --> 00:27:04,000
+So in case once we had obtained a pessimistic log on an entity and another thread can obtain pessimistic
+
+287
+00:27:04,000 --> 00:27:06,000
+log on the same entity.
+
+288
+00:27:07,000 --> 00:27:13,000
+An exception happened during the attempt of obtaining such log is a clear.
+
+289
+00:27:14,000 --> 00:27:17,000
+Let me comment another type of blog.
+
+290
+00:27:17,000 --> 00:27:20,000
+Let me run the program one more time.
+
+291
+00:27:20,000 --> 00:27:28,000
+But this time we will try to understand how optimistic force, incremental work mode type impacts execution
+
+292
+00:27:28,000 --> 00:27:37,000
+of our threats, like we discussed in case of optimistic lock to threats, managed to obtain the lock,
+
+293
+00:27:37,000 --> 00:27:41,000
+but only one threat managed to commit changes.
+
+294
+00:27:42,000 --> 00:27:45,000
+You can see this from lock messages.
+
+295
+00:27:45,000 --> 00:27:48,000
+Explore them to on your computer.
+
+296
+00:27:48,000 --> 00:27:54,000
+You will be able to find the reference to this source code example in attachments to the video.
+
+297
+00:27:55,000 --> 00:27:59,000
+And what happened was the second threat in this case.
+
+298
+00:27:59,000 --> 00:28:01,000
+Let's find this out.
+
+299
+00:28:02,000 --> 00:28:09,000
+This time we have rolled back exception error while committing the transaction, which is caused by
+
+300
+00:28:09,000 --> 00:28:12,000
+optimistic lock exception.
+
+301
+00:28:12,000 --> 00:28:22,000
+ROE was updated or deleted by another transaction, which in turn caused by stale object state exception.
+
+302
+00:28:22,000 --> 00:28:32,000
+But let's understand in vitro, as you can see from logs here, this time exception happened in zero
+
+303
+00:28:32,000 --> 00:28:33,000
+37.
+
+304
+00:28:33,000 --> 00:28:41,000
+So the error happened when I tried to commit transaction with updated entity that was updated already
+
+305
+00:28:41,000 --> 00:28:42,000
+by another scrap.
+
+306
+00:28:42,000 --> 00:28:47,000
+So can you see that exception happened on the later stage?
+
+307
+00:28:48,000 --> 00:28:56,000
+That is because when we use optimistic log, we still allow other threats to obtain the lock on the
+
+308
+00:28:56,000 --> 00:28:57,000
+same entity.
+
+309
+00:28:57,000 --> 00:29:00,000
+This is helpful for reading operations.
+
+310
+00:29:01,000 --> 00:29:02,000
+For example.
+
+311
+00:29:02,000 --> 00:29:03,000
+One Multiple threats.
+
+312
+00:29:03,000 --> 00:29:08,000
+Read information about my user and news of threats.
+
+313
+00:29:08,000 --> 00:29:09,000
+Update the user.
+
+314
+00:29:09,000 --> 00:29:17,000
+In this case, there is no need to block access to the entity, but still there is a need to prevent
+
+315
+00:29:17,000 --> 00:29:22,000
+multiple updates from different threats in order to avoid cases.
+
+316
+00:29:22,000 --> 00:29:29,000
+When updates from one threat will erase objects from another threat, is it clear?
+
+317
+00:29:30,000 --> 00:29:33,000
+I believe that now it is more clear for you.
+
+318
+00:29:33,000 --> 00:29:37,000
+What is the difference between optimistic and pessimistic looking?
+
+319
+00:29:38,000 --> 00:29:45,000
+Even in case you still have any questions, please do not hesitate to ask your questions below the video
+
+320
+00:29:45,000 --> 00:29:47,000
+and I will be happy to answer.
+
+321
+00:29:47,000 --> 00:29:51,000
+So that's all what I wanted to discuss with you today.
+
+322
+00:29:52,000 --> 00:29:55,000
+Let's recap what we have learned in this lesson.
+
+323
+00:29:56,000 --> 00:30:01,000
+In this lesson, we learned what a database law is and why do we need it.
+
+324
+00:30:02,000 --> 00:30:05,000
+We learned what physical logs are.
+
+325
+00:30:05,000 --> 00:30:08,000
+I explained what the logical logs are.
+
+326
+00:30:09,000 --> 00:30:16,000
+William Larkin in GP, I explained the optimistic and pessimistic working models.
+
+327
+00:30:17,000 --> 00:30:24,000
+We learned explicit work types in lock mode, type in them and saw the coding example.
+
+328
+00:30:25,000 --> 00:30:26,000
+That's it for today.
+
+329
+00:30:27,000 --> 00:30:28,000
+Thanks a lot for your attention.
+
+330
+00:30:28,000 --> 00:30:31,000
+Have a great day and see you in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/005 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/005 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..34372aa7a1266004dff47bbb252ae86c71ec03ca
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/005 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/locking
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/006 Relationships Between Entities_en.srt b/78 - ORM, JPA & Hibernate/006 Relationships Between Entities_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..bda73fa646f4f86b5ea122323d26a95df289eec4
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/006 Relationships Between Entities_en.srt
@@ -0,0 +1,1080 @@
+1
+00:00:06,000 --> 00:00:07,000
+Hello, team.
+
+2
+00:00:07,000 --> 00:00:11,000
+In this lesson, we're going to learn relationships between entities.
+
+3
+00:00:11,000 --> 00:00:17,000
+It is very important topic because very often we use relations between different types.
+
+4
+00:00:18,000 --> 00:00:25,000
+Today we are going to learn everything you need to know to be able to use relations in GPA like a pro.
+
+5
+00:00:25,000 --> 00:00:30,000
+And also we'll review code examples to get some practical skills.
+
+6
+00:00:31,000 --> 00:00:39,000
+We'll start our lesson from understanding of the use case, namely when we need to use mapping in GPA
+
+7
+00:00:39,000 --> 00:00:41,000
+to understand the topic better.
+
+8
+00:00:41,000 --> 00:00:48,000
+I believe it is important for us to recall types of relationships in the relational databases.
+
+9
+00:00:48,000 --> 00:00:53,000
+We'll review mapping the reactions and types of mapping in GPA.
+
+10
+00:00:53,000 --> 00:01:00,000
+Today, I'm going to show you on real examples how you can apply such annotations as 1 to 1.
+
+11
+00:01:01,000 --> 00:01:02,000
+One to many.
+
+12
+00:01:02,000 --> 00:01:03,000
+And many to one.
+
+13
+00:01:03,000 --> 00:01:04,000
+And many to many.
+
+14
+00:01:05,000 --> 00:01:12,000
+Also we're going to review Cascade, Type, enum, and I will show you in practice how to use Cascade
+
+15
+00:01:12,000 --> 00:01:12,000
+type.
+
+16
+00:01:13,000 --> 00:01:17,000
+I will explain what EGA and laser fetch types are.
+
+17
+00:01:17,000 --> 00:01:21,000
+And besides that, we're going to have practical examples today.
+
+18
+00:01:21,000 --> 00:01:28,000
+During the examples, we're going to run such annotations as June column and join table, and you will
+
+19
+00:01:28,000 --> 00:01:31,000
+understand the difference between them.
+
+20
+00:01:31,000 --> 00:01:33,000
+Let's start our lesson.
+
+21
+00:01:34,000 --> 00:01:35,000
+Let's learn first.
+
+22
+00:01:35,000 --> 00:01:41,000
+Why do we need relations in the GP and what challenge would try to solve?
+
+23
+00:01:41,000 --> 00:01:46,000
+I want you understand why we need relationships between GP entities.
+
+24
+00:01:47,000 --> 00:01:55,000
+Imagine that we have a user entity and our user has collection of orders that he or she did in our online
+
+25
+00:01:55,000 --> 00:02:01,000
+shop and we need to show list of orders in the profile of our user.
+
+26
+00:02:01,000 --> 00:02:10,000
+So the show list of orders in the profile, we need to prepare this information inside our Java application.
+
+27
+00:02:10,000 --> 00:02:11,000
+Agreed.
+
+28
+00:02:11,000 --> 00:02:18,000
+And technically speaking, we need to make sure that we have a list of purchases inside our user object.
+
+29
+00:02:19,000 --> 00:02:28,000
+GPA allows us to build such kind of connections and also GP allows us to configure other types of relationships.
+
+30
+00:02:29,000 --> 00:02:32,000
+We're going to review all of them in the lesson.
+
+31
+00:02:32,000 --> 00:02:34,000
+That's what we are going to learn today.
+
+32
+00:02:35,000 --> 00:02:41,000
+But the first thing that we need to remember is the things that we learned in the relational database
+
+33
+00:02:41,000 --> 00:02:44,000
+section of my Java from zero to first jump course.
+
+34
+00:02:45,000 --> 00:02:50,000
+If you remember, we learned types of relationships in the relational databases.
+
+35
+00:02:50,000 --> 00:02:56,000
+I don't want to repeat myself too much, so please refer to that lesson.
+
+36
+00:02:56,000 --> 00:03:04,000
+I will just quickly remind you, because this is important in relational databases, we have three types
+
+37
+00:03:04,000 --> 00:03:05,000
+of relationships.
+
+38
+00:03:05,000 --> 00:03:07,000
+They are one too many.
+
+39
+00:03:07,000 --> 00:03:15,000
+It is the case when one record and one table is associated with multiple records in the table.
+
+40
+00:03:15,000 --> 00:03:24,000
+For example, each car has owner, but each owner can have multiple cores, many to many.
+
+41
+00:03:24,000 --> 00:03:31,000
+It is the case when one record from one table may be associated with many records from another table
+
+42
+00:03:31,000 --> 00:03:38,000
+and one record from another table can be associated with many records from the first table.
+
+43
+00:03:38,000 --> 00:03:41,000
+For example, doctor and patients.
+
+44
+00:03:42,000 --> 00:03:49,000
+Each doctor can have multiple patients and different patients can meet different doctors.
+
+45
+00:03:49,000 --> 00:03:51,000
+So it's many, many.
+
+46
+00:03:52,000 --> 00:03:54,000
+And 1 to 1 relationship.
+
+47
+00:03:54,000 --> 00:04:01,000
+It is one one record and one table is associated with only one record from another table.
+
+48
+00:04:01,000 --> 00:04:04,000
+This is very rare case.
+
+49
+00:04:04,000 --> 00:04:12,000
+For example, each person has only one passport and only one passport can be associated with one person.
+
+50
+00:04:13,000 --> 00:04:20,000
+This is important to learn to understand GP and a patients that will be discussed in this lesson.
+
+51
+00:04:20,000 --> 00:04:24,000
+The next thing that we need to learn is mapping directions.
+
+52
+00:04:25,000 --> 00:04:32,000
+It is relatively simple and logical scene to understand, but still, let me quickly cover this to make
+
+53
+00:04:32,000 --> 00:04:35,000
+sure that we are on the same page.
+
+54
+00:04:36,000 --> 00:04:39,000
+We can divide mapping directions into two parts.
+
+55
+00:04:40,000 --> 00:04:47,000
+You need directional relationship in this relationship on the one and that you can refer the properties
+
+56
+00:04:47,000 --> 00:04:48,000
+to analysis.
+
+57
+00:04:49,000 --> 00:04:56,000
+It contains only one own insights that specifies how an update can be made in the database.
+
+58
+00:04:57,000 --> 00:04:59,000
+BI Directional Relationship.
+
+59
+00:05:00,000 --> 00:05:06,000
+The relationship contains an own insight as well as an inverse side.
+
+60
+00:05:06,000 --> 00:05:12,000
+So here every entity has a relationship field or refers a property to other entity.
+
+61
+00:05:13,000 --> 00:05:18,000
+As you can see, the main difference here is who owns the relationship.
+
+62
+00:05:18,000 --> 00:05:24,000
+In case of interaction or relationship, only one side owns the relationship.
+
+63
+00:05:24,000 --> 00:05:29,000
+In case of bidirectional relationship, two sides.
+
+64
+00:05:30,000 --> 00:05:38,000
+Now let's learn types of mappings in GP and also let's learn some key annotations that will help us
+
+65
+00:05:38,000 --> 00:05:40,000
+to configure this map and.
+
+66
+00:05:41,000 --> 00:05:48,000
+Types of mapping can be obviously connected with possible types of relationships in the database.
+
+67
+00:05:48,000 --> 00:05:55,000
+That's why I decided to remind users at the beginning of the lesson, and I'm sure that now it will
+
+68
+00:05:55,000 --> 00:05:59,000
+be easier for you to remember GP types.
+
+69
+00:05:59,000 --> 00:06:03,000
+There are four types of mapping 1 to 1.
+
+70
+00:06:04,000 --> 00:06:09,000
+This association is represented by 1 to 1 annotation here.
+
+71
+00:06:10,000 --> 00:06:15,000
+Instance of each entity is related to a single instance of another entity.
+
+72
+00:06:16,000 --> 00:06:17,000
+One too many.
+
+73
+00:06:17,000 --> 00:06:22,000
+This association is represented by one to many annotation.
+
+74
+00:06:22,000 --> 00:06:29,000
+In this relationship, an instance of one entity can be related to more than one instance of another
+
+75
+00:06:29,000 --> 00:06:32,000
+entity, many to one.
+
+76
+00:06:32,000 --> 00:06:36,000
+This map is defined by many to one annotation.
+
+77
+00:06:36,000 --> 00:06:43,000
+In this relationship, multiple instances of an entity can be related to a single instance of another
+
+78
+00:06:43,000 --> 00:06:44,000
+entity.
+
+79
+00:06:44,000 --> 00:06:51,000
+So as you can see, there is a difference only in what is the direction of the relationship.
+
+80
+00:06:51,000 --> 00:06:55,000
+In the case there is a bi directional relationship.
+
+81
+00:06:55,000 --> 00:07:02,000
+You can use one to many annotation in one entity and manage one annotation in another entity.
+
+82
+00:07:02,000 --> 00:07:03,000
+Many to many.
+
+83
+00:07:04,000 --> 00:07:06,000
+This association is represented by.
+
+84
+00:07:06,000 --> 00:07:08,000
+Many to many annotation.
+
+85
+00:07:08,000 --> 00:07:16,000
+Here, multiple instances of an entity can be related to multiple instances of another entity.
+
+86
+00:07:16,000 --> 00:07:20,000
+In this mapping, any site can be the own inside.
+
+87
+00:07:21,000 --> 00:07:27,000
+In the source code, we can use different types of containers to ensure mappings.
+
+88
+00:07:27,000 --> 00:07:36,000
+For example, we can use either least set or map types for properties that will be used to establish
+
+89
+00:07:36,000 --> 00:07:37,000
+relationships.
+
+90
+00:07:38,000 --> 00:07:41,000
+Today, during the demo, I'm going to show you this.
+
+91
+00:07:41,000 --> 00:07:46,000
+Now let's learn relationships by examples.
+
+92
+00:07:46,000 --> 00:07:49,000
+I prepared a series of examples for you.
+
+93
+00:07:49,000 --> 00:07:52,000
+Let's use them to understand the topic better.
+
+94
+00:07:53,000 --> 00:07:58,000
+The first examples we're going to review now is 1 to 1 relationship.
+
+95
+00:07:59,000 --> 00:08:02,000
+Imagine the case that we have a user in the system.
+
+96
+00:08:03,000 --> 00:08:12,000
+Each user has only one user profile associated with it, and each user profile can have on the one user
+
+97
+00:08:12,000 --> 00:08:14,000
+that is associated with it.
+
+98
+00:08:15,000 --> 00:08:18,000
+So here we have a 1 to 1 relationship.
+
+99
+00:08:19,000 --> 00:08:21,000
+How we can configure this in GB.
+
+100
+00:08:22,000 --> 00:08:23,000
+Let me show it to you.
+
+101
+00:08:23,000 --> 00:08:29,000
+All examples from this lesson will be stored in the package that is called mapping.
+
+102
+00:08:30,000 --> 00:08:38,000
+You can find source for examples in attachment to the lesson just in case you want to download the code
+
+103
+00:08:38,000 --> 00:08:41,000
+and run it on your computer to learn examples better.
+
+104
+00:08:42,000 --> 00:08:44,000
+So I created user entity.
+
+105
+00:08:45,000 --> 00:08:51,000
+You already know how to use column annotation and annotation and generated value annotations.
+
+106
+00:08:52,000 --> 00:08:53,000
+We learned all this.
+
+107
+00:08:53,000 --> 00:09:00,000
+That's why I didn't put a lot of configurations here in order to not lose focus from the main thing
+
+108
+00:09:00,000 --> 00:09:01,000
+in the lesson.
+
+109
+00:09:02,000 --> 00:09:05,000
+Here is a user profile filled with annotation.
+
+110
+00:09:05,000 --> 00:09:06,000
+One, two, one.
+
+111
+00:09:06,000 --> 00:09:09,000
+Let's run this annotation better.
+
+112
+00:09:09,000 --> 00:09:13,000
+I encourage you to use the source code of this annotation.
+
+113
+00:09:13,000 --> 00:09:16,000
+There are different attributes that you can use.
+
+114
+00:09:16,000 --> 00:09:18,000
+Most of them are optional.
+
+115
+00:09:19,000 --> 00:09:23,000
+Let me just highlight the most interesting attributes in my opinion.
+
+116
+00:09:24,000 --> 00:09:30,000
+Cascade attribute is important one, and probably the one that is used relatively often.
+
+117
+00:09:31,000 --> 00:09:35,000
+You will find the similar attribute in other mappings annotations.
+
+118
+00:09:36,000 --> 00:09:41,000
+So this cascade attribute takes every of the values of cascade type.
+
+119
+00:09:42,000 --> 00:09:51,000
+The escape dipole means that any change happened on one entity must cascade to another entity as well.
+
+120
+00:09:52,000 --> 00:09:58,000
+The Cascade types supported by the Java persistence architecture are as below.
+
+121
+00:09:59,000 --> 00:10:00,000
+Cascade Type Persist.
+
+122
+00:10:01,000 --> 00:10:02,000
+Cascade Type.
+
+123
+00:10:02,000 --> 00:10:05,000
+Persist means that persist operations.
+
+124
+00:10:05,000 --> 00:10:07,000
+Cascade through related entities.
+
+125
+00:10:08,000 --> 00:10:10,000
+Escape type merge.
+
+126
+00:10:10,000 --> 00:10:17,000
+Escape type merge means the two related entities merged when the own entity is merged.
+
+127
+00:10:18,000 --> 00:10:20,000
+The skate tap refresh.
+
+128
+00:10:20,000 --> 00:10:25,000
+The skate tap refresh does the same thing for the refresh operation.
+
+129
+00:10:26,000 --> 00:10:33,000
+Cascade Tap or move cascade tap remove from moves all related entities association with this said when
+
+130
+00:10:34,000 --> 00:10:36,000
+the own entity is deleted.
+
+131
+00:10:37,000 --> 00:10:42,000
+Escape tab, detach it, detach all related entities.
+
+132
+00:10:42,000 --> 00:10:51,000
+If a nano detach occurs and the escape type all is shorthand for all of the above cascade operations.
+
+133
+00:10:52,000 --> 00:11:00,000
+So in case we have user profile associated with our user object and we have cascade type persist, that
+
+134
+00:11:00,000 --> 00:11:07,000
+means that user profile will be also persistent one user and that will be persisted.
+
+135
+00:11:07,000 --> 00:11:08,000
+Is it clear?
+
+136
+00:11:09,000 --> 00:11:16,000
+And now the attributes that I'd like to review with you is fetch by default, eagle fetch type is used.
+
+137
+00:11:17,000 --> 00:11:23,000
+We have two possible options to specify here is an eager or lazy fetch type.
+
+138
+00:11:23,000 --> 00:11:25,000
+So what is the difference?
+
+139
+00:11:25,000 --> 00:11:29,000
+Well, actually, is this a simple thing to understand?
+
+140
+00:11:29,000 --> 00:11:33,000
+Lazy fetch type fetch is the child and just lazy.
+
+141
+00:11:34,000 --> 00:11:42,000
+That means that at the time of fetching parent entity it just fetches proxy of the child or related
+
+142
+00:11:42,000 --> 00:11:43,000
+entities.
+
+143
+00:11:43,000 --> 00:11:50,000
+Actually, there is no query to the database to fetch related entity until you request access to the
+
+144
+00:11:50,000 --> 00:11:52,000
+property of the child entity.
+
+145
+00:11:52,000 --> 00:12:00,000
+So when you need to access child property of the related entity, only then new request is done to the
+
+146
+00:12:00,000 --> 00:12:05,000
+database and only then child entity is fetched.
+
+147
+00:12:05,000 --> 00:12:10,000
+Ignore fetch type fetch is the child and that is along with parent.
+
+148
+00:12:11,000 --> 00:12:17,000
+Let's know now mapped by attribute user relationship is bi directional.
+
+149
+00:12:17,000 --> 00:12:27,000
+The non only site must use the map bi element of the 1 to 1 annotation to specify the relationship field
+
+150
+00:12:27,000 --> 00:12:29,000
+or property of the own inside.
+
+151
+00:12:30,000 --> 00:12:34,000
+Let me also explain it in other simple words.
+
+152
+00:12:34,000 --> 00:12:38,000
+How is this relation will be implemented in the database?
+
+153
+00:12:39,000 --> 00:12:46,000
+You already knows that 1 to 1 relationship may be implemented just by adding a foreign key into another
+
+154
+00:12:46,000 --> 00:12:47,000
+table.
+
+155
+00:12:47,000 --> 00:12:55,000
+Here I say that user attribute is mapped by user property in the user profile entity.
+
+156
+00:12:56,000 --> 00:13:03,000
+User profile owns a relationship and holds the reference to the user.
+
+157
+00:13:03,000 --> 00:13:04,000
+Is it clear?
+
+158
+00:13:05,000 --> 00:13:11,000
+So map by attribute can be specified only on the non only side.
+
+159
+00:13:11,000 --> 00:13:18,000
+Anyway, in case you still have any questions, feel free to ask them below the video and I will be
+
+160
+00:13:18,000 --> 00:13:19,000
+happy to answer.
+
+161
+00:13:21,000 --> 00:13:29,000
+In the user profile, we just put annotation 1 to 1 and the rest properties here are just properties.
+
+162
+00:13:29,000 --> 00:13:30,000
+Let me open them.
+
+163
+00:13:30,000 --> 00:13:33,000
+A class now is a demo class.
+
+164
+00:13:33,000 --> 00:13:39,000
+I start the transaction, I create user, I create user profile.
+
+165
+00:13:40,000 --> 00:13:45,000
+I set user profile into the user and I persist the user.
+
+166
+00:13:45,000 --> 00:13:55,000
+As I said, if we use cascade attribute of annotation and Cascade type persist, we don't need to persist
+
+167
+00:13:55,000 --> 00:14:02,000
+manually another entity because it will be automatically persisted together with the user entity.
+
+168
+00:14:03,000 --> 00:14:08,000
+Let me run this program and let me open now my SQL workbench.
+
+169
+00:14:09,000 --> 00:14:12,000
+We have multiple users in different examples.
+
+170
+00:14:12,000 --> 00:14:18,000
+That's why user from the current example is called user 1 to 1.
+
+171
+00:14:18,000 --> 00:14:27,000
+You can see that one, my user was named John is saved here and one user profile is also persisted.
+
+172
+00:14:28,000 --> 00:14:36,000
+Pay attention that in our case, user profile contains foreign key user ID that is used to establish
+
+173
+00:14:36,000 --> 00:14:39,000
+connection between two entities.
+
+174
+00:14:39,000 --> 00:14:40,000
+Is it clear?
+
+175
+00:14:41,000 --> 00:14:44,000
+Now let's review another example.
+
+176
+00:14:44,000 --> 00:14:48,000
+Let's review now one to many and many to one examples.
+
+177
+00:14:49,000 --> 00:14:56,000
+The one to many and many to one annotations facilitate both sides of the same relationship.
+
+178
+00:14:56,000 --> 00:15:04,000
+Consider an example where a book can have only one author, but an author may have many books.
+
+179
+00:15:04,000 --> 00:15:07,000
+I prepared an example here for you.
+
+180
+00:15:07,000 --> 00:15:10,000
+Let me open book class first.
+
+181
+00:15:10,000 --> 00:15:12,000
+We have such properties here.
+
+182
+00:15:12,000 --> 00:15:15,000
+ID name and also.
+
+183
+00:15:16,000 --> 00:15:19,000
+So each book has one author.
+
+184
+00:15:19,000 --> 00:15:24,000
+So many books can be associated with one author.
+
+185
+00:15:25,000 --> 00:15:32,000
+That's why we have managed to one annotation here and in the author class.
+
+186
+00:15:32,000 --> 00:15:40,000
+We're going to have one to many annotation because one author can be associated with many books.
+
+187
+00:15:40,000 --> 00:15:41,000
+Is it clear?
+
+188
+00:15:42,000 --> 00:15:47,000
+And now the annotations that you didn't see before is John column.
+
+189
+00:15:48,000 --> 00:15:50,000
+Let me explain to you why we need it.
+
+190
+00:15:51,000 --> 00:15:59,000
+This annotation marks a column as a joint column for an entity association or an element collection.
+
+191
+00:16:00,000 --> 00:16:08,000
+June column is used to specify a column for joining an entity, association or element collection.
+
+192
+00:16:08,000 --> 00:16:17,000
+This annotation indicates that the enclosing entity is the owner of the relationship and that the corresponding
+
+193
+00:16:17,000 --> 00:16:24,000
+table has a foreign key column which references to the table of the non own inside.
+
+194
+00:16:25,000 --> 00:16:34,000
+So that means that in book entity we are going to have a column with the name author ID that will ensure
+
+195
+00:16:34,000 --> 00:16:37,000
+relation with author entity.
+
+196
+00:16:38,000 --> 00:16:45,000
+That means that author ID column will store the foreign key to the author entity.
+
+197
+00:16:45,000 --> 00:16:47,000
+I hope that this is clear.
+
+198
+00:16:49,000 --> 00:16:50,000
+Let me open author class.
+
+199
+00:16:50,000 --> 00:16:59,000
+Now in the author class we have property of list type because each author can have multiple books.
+
+200
+00:17:00,000 --> 00:17:03,000
+We learn already what mapped by means.
+
+201
+00:17:03,000 --> 00:17:13,000
+So we specify here attribute name of the entity that owns the relationship and we also specify cascading
+
+202
+00:17:13,000 --> 00:17:13,000
+type.
+
+203
+00:17:14,000 --> 00:17:15,000
+Let me open them across.
+
+204
+00:17:15,000 --> 00:17:19,000
+Now I create one author and three books.
+
+205
+00:17:20,000 --> 00:17:23,000
+I add books to the author and I persist.
+
+206
+00:17:23,000 --> 00:17:26,000
+Also, let me run this program.
+
+207
+00:17:27,000 --> 00:17:34,000
+After running this program, let me open my SQL workbench and we have two new entities.
+
+208
+00:17:34,000 --> 00:17:37,000
+They are book and author.
+
+209
+00:17:37,000 --> 00:17:43,000
+And when I open author table, you can see that I have one author here.
+
+210
+00:17:43,000 --> 00:17:52,000
+And when I open book, which is three books and the book table has author ID column to ensure many to
+
+211
+00:17:52,000 --> 00:17:59,000
+one relation that it regarding one to many and many to one relationships.
+
+212
+00:18:00,000 --> 00:18:03,000
+Let me show you now many, many relationship example.
+
+213
+00:18:04,000 --> 00:18:09,000
+In this example, imagine that our book can have multiple authors.
+
+214
+00:18:09,000 --> 00:18:10,000
+Why not?
+
+215
+00:18:11,000 --> 00:18:15,000
+This is real life case and such things can happen.
+
+216
+00:18:15,000 --> 00:18:20,000
+That book is written by multiple authors and each author.
+
+217
+00:18:20,000 --> 00:18:23,000
+Each one can have multiple books.
+
+218
+00:18:23,000 --> 00:18:27,000
+So this is example of man to man relationship.
+
+219
+00:18:28,000 --> 00:18:32,000
+Let's review how it is implemented with the GPA.
+
+220
+00:18:32,000 --> 00:18:36,000
+I have a separate package that is called Man to Man.
+
+221
+00:18:37,000 --> 00:18:39,000
+Let me start with the book class.
+
+222
+00:18:40,000 --> 00:18:49,000
+Amazon is like in previous example besides Z slides, I have annotation many too many from the relational
+
+223
+00:18:49,000 --> 00:18:51,000
+database theory.
+
+224
+00:18:51,000 --> 00:18:57,000
+You already know that many to many connection is implemented with the help of the search table.
+
+225
+00:18:58,000 --> 00:19:07,000
+That's why we have annotation join table here with specify name of the joint table and we need to specify
+
+226
+00:19:07,000 --> 00:19:15,000
+June column from one and another side, the columns that will be used in mapping entities between each
+
+227
+00:19:15,000 --> 00:19:15,000
+OSR.
+
+228
+00:19:16,000 --> 00:19:23,000
+It will be book ID from the book entity side and it will be authorized from the author.
+
+229
+00:19:23,000 --> 00:19:25,000
+And the this side is every single year.
+
+230
+00:19:26,000 --> 00:19:33,000
+In this case, I use set type in order to receive only unique authors for each book.
+
+231
+00:19:34,000 --> 00:19:34,000
+Hobbs.
+
+232
+00:19:34,000 --> 00:19:37,000
+It's everything sounds logical to you so far.
+
+233
+00:19:38,000 --> 00:19:45,000
+In case you have any questions, please ask your questions below the video and I will be happy to answer
+
+234
+00:19:45,000 --> 00:19:46,000
+those.
+
+235
+00:19:47,000 --> 00:19:49,000
+And let me open author class now.
+
+236
+00:19:49,000 --> 00:19:57,000
+Here we also put many too many annotation and with specified mapping fields for authors property in
+
+237
+00:19:57,000 --> 00:19:59,000
+book entity.
+
+238
+00:19:59,000 --> 00:20:03,000
+Okay, let me now open them a class.
+
+239
+00:20:03,000 --> 00:20:10,000
+In addition to the code from previous example, one of the persisted books of Stephen King, I just
+
+240
+00:20:10,000 --> 00:20:14,000
+added some imaginary author to other books.
+
+241
+00:20:15,000 --> 00:20:17,000
+This is just for the sake of example.
+
+242
+00:20:17,000 --> 00:20:22,000
+If you're a fan of Stephen King like I am, please don't be offended.
+
+243
+00:20:23,000 --> 00:20:25,000
+This is just for the sake of example.
+
+244
+00:20:26,000 --> 00:20:30,000
+But he runs a program and after program has been executed.
+
+245
+00:20:30,000 --> 00:20:32,000
+Let me open my SQL workbench.
+
+246
+00:20:33,000 --> 00:20:34,000
+I have new types here.
+
+247
+00:20:34,000 --> 00:20:37,000
+They are many, many.
+
+248
+00:20:37,000 --> 00:20:38,000
+Awesome.
+
+249
+00:20:38,000 --> 00:20:39,000
+Many to many.
+
+250
+00:20:39,000 --> 00:20:40,000
+And author.
+
+251
+00:20:41,000 --> 00:20:49,000
+We can see that relationship is managed with the help of the set table and it contains consistent data.
+
+252
+00:20:50,000 --> 00:20:51,000
+Great.
+
+253
+00:20:51,000 --> 00:20:56,000
+We have completed a review of all types of mappings in the GPA with examples.
+
+254
+00:20:57,000 --> 00:21:00,000
+One most things that I did for the sake of this demo.
+
+255
+00:21:01,000 --> 00:21:08,000
+I changed attributes schema generation database action in our persistence XML document.
+
+256
+00:21:08,000 --> 00:21:15,000
+I changed it from drop and create to update to eliminate some errors in console.
+
+257
+00:21:15,000 --> 00:21:22,000
+During the multiple code execution, we reviewed this attribute in the first license when we just learned
+
+258
+00:21:22,000 --> 00:21:25,000
+how to configure entity manager factory.
+
+259
+00:21:25,000 --> 00:21:30,000
+So please refer to that lesson to recap the knowledge about this attribute.
+
+260
+00:21:31,000 --> 00:21:34,000
+That's all what I wanted to share with you in this lesson.
+
+261
+00:21:34,000 --> 00:21:37,000
+Let's recap what we have learned today.
+
+262
+00:21:38,000 --> 00:21:43,000
+In this lesson we learn when we need to use mapping and GP.
+
+263
+00:21:43,000 --> 00:21:48,000
+We learned different types of relationships in relational databases.
+
+264
+00:21:48,000 --> 00:21:56,000
+I explained the different mapping directions and we reviewed different types of mapping in Java.
+
+265
+00:21:57,000 --> 00:22:04,000
+Also today we learned cascade type in them and you saw how to cascade operations with entities.
+
+266
+00:22:05,000 --> 00:22:10,000
+I explained the difference between EGA and laissez faire types.
+
+267
+00:22:10,000 --> 00:22:14,000
+We reviewed practical examples with different map types.
+
+268
+00:22:15,000 --> 00:22:17,000
+That's it for this lesson.
+
+269
+00:22:17,000 --> 00:22:19,000
+Thanks a lot for your attention.
+
+270
+00:22:19,000 --> 00:22:22,000
+Have a great day and see you in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/006 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/006 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..9722e82b2ef5c2a5f18306fbb881ef747035b3e5
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/006 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/mapping
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/007 JPA Queries (Query, TypedQuery, NativeQuery, JPQL, Criteria API)_en.srt b/78 - ORM, JPA & Hibernate/007 JPA Queries (Query, TypedQuery, NativeQuery, JPQL, Criteria API)_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..c25715bed4456bd4645ae08234c87c1e24351e38
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/007 JPA Queries (Query, TypedQuery, NativeQuery, JPQL, Criteria API)_en.srt
@@ -0,0 +1,1160 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:11,000
+In this lesson, we're going to learn different types of queries in GPA.
+
+3
+00:00:11,000 --> 00:00:16,000
+We're going to start the lesson from the overview of different GPA queries types.
+
+4
+00:00:16,000 --> 00:00:26,000
+Namely, we'll review such types as query type, query named query, native query and Creative API.
+
+5
+00:00:26,000 --> 00:00:34,000
+During the lesson, I will explain what the GPC is and what its key features are to help you with debugging
+
+6
+00:00:34,000 --> 00:00:37,000
+of your programs when using GPA.
+
+7
+00:00:37,000 --> 00:00:45,000
+I'm going to show you one more property that would enable logging of SQL queries executed against database.
+
+8
+00:00:45,000 --> 00:00:51,000
+And also we're going to have a lot of practical exercises to date during the lesson.
+
+9
+00:00:51,000 --> 00:00:53,000
+Let's start our lesson.
+
+10
+00:00:54,000 --> 00:00:56,000
+Today we're going to learn different types of queries.
+
+11
+00:00:56,000 --> 00:01:01,000
+Like I said, some of the queries will be created with the help of the GPCR.
+
+12
+00:01:02,000 --> 00:01:06,000
+We're going to learn today what it is and review examples too.
+
+13
+00:01:06,000 --> 00:01:14,000
+Some queries will be written on pure SQL, but still GPA will be used to execute these queries.
+
+14
+00:01:14,000 --> 00:01:20,000
+And also we're going to learn creative API to learn how to create queries programmatically.
+
+15
+00:01:21,000 --> 00:01:29,000
+So to sum it up in GPA, we have the following types of queries query written in Java Persistence query
+
+16
+00:01:29,000 --> 00:01:32,000
+language that is GPG syntax.
+
+17
+00:01:33,000 --> 00:01:39,000
+There are two additional query subtypes the type query and named query.
+
+18
+00:01:40,000 --> 00:01:47,000
+The next query types are native query written in plain SQL syntax and criteria.
+
+19
+00:01:47,000 --> 00:01:51,000
+API query constructed programmatically where different masses.
+
+20
+00:01:52,000 --> 00:01:56,000
+To understand and work with all different types of queries.
+
+21
+00:01:56,000 --> 00:01:58,000
+We also need to learn GraphQL.
+
+22
+00:01:59,000 --> 00:02:01,000
+Let's learn first what it is.
+
+23
+00:02:02,000 --> 00:02:08,000
+GPL stands for Jakarta Persistence Query Language or Java Persistence Query Language.
+
+24
+00:02:08,000 --> 00:02:16,000
+It is an object oriented query language which is used to perform database operations on persistent entities
+
+25
+00:02:16,000 --> 00:02:18,000
+instead of a database table.
+
+26
+00:02:18,000 --> 00:02:24,000
+Gpcr uses entity object model to operate the SQL queries.
+
+27
+00:02:24,000 --> 00:02:29,000
+Here, the role of Gpe is to transform GPL into SQL.
+
+28
+00:02:30,000 --> 00:02:35,000
+Thus, it provides an easy platform for developers to handle SQL tasks.
+
+29
+00:02:36,000 --> 00:02:43,000
+GPL is developed based on SQL syntax, but it won't affect the database directory.
+
+30
+00:02:44,000 --> 00:02:49,000
+The general structure and syntax of GPL are very similar to SQL.
+
+31
+00:02:50,000 --> 00:02:58,000
+Having an SQL like syntax in queries is an important advantage because SQL is very powerful query language
+
+32
+00:02:58,000 --> 00:03:01,000
+and many developers are already familiar with it.
+
+33
+00:03:02,000 --> 00:03:10,000
+So to sum it up, the main difference between SQL and GPL is that SQL works with relational database
+
+34
+00:03:10,000 --> 00:03:17,000
+tables, records and fields, whereas GPG works with Java classes and objects.
+
+35
+00:03:17,000 --> 00:03:25,000
+For example, a typical query can retrieve and return entity objects rather than just field values from
+
+36
+00:03:25,000 --> 00:03:26,000
+the database tables.
+
+37
+00:03:26,000 --> 00:03:34,000
+As with SQL, that makes typical, more object oriented, friendly, and easier to use in Java.
+
+38
+00:03:35,000 --> 00:03:41,000
+The key features are it is platform independent query language.
+
+39
+00:03:41,000 --> 00:03:43,000
+It is simple and robust.
+
+40
+00:03:44,000 --> 00:03:49,000
+It can be used with any type of database such as my SQL or Oracle.
+
+41
+00:03:49,000 --> 00:03:50,000
+It doesn't matter.
+
+42
+00:03:51,000 --> 00:03:59,000
+SQL queries can be declared statically into metadata or can also be dynamically built in code.
+
+43
+00:04:00,000 --> 00:04:02,000
+We learned what a gpcr is.
+
+44
+00:04:02,000 --> 00:04:09,000
+And before jumping to examples, let's learn a little bit more theory about criteria API.
+
+45
+00:04:09,000 --> 00:04:12,000
+And after that, I will walk you through all the examples.
+
+46
+00:04:13,000 --> 00:04:21,000
+The criteria API is one of the most common ways of constructing queries for entities and they are persistent
+
+47
+00:04:21,000 --> 00:04:21,000
+state.
+
+48
+00:04:22,000 --> 00:04:27,000
+That is just an alternative method for defining GPA queries criteria.
+
+49
+00:04:27,000 --> 00:04:34,000
+API defines a platform independent criteria queries written in Java programming language.
+
+50
+00:04:34,000 --> 00:04:38,000
+It was introduced in GPA 2.0.
+
+51
+00:04:38,000 --> 00:04:44,000
+The main purpose behind this is to provide a type safe way to express a query.
+
+52
+00:04:45,000 --> 00:04:51,000
+The criteria API is a predefined API used to define queries for entities.
+
+53
+00:04:51,000 --> 00:05:01,000
+It is an alternative way of defining AGP SQL query this query subtype safe, portable and easy to modify
+
+54
+00:05:01,000 --> 00:05:02,000
+by changing the syntax.
+
+55
+00:05:03,000 --> 00:05:12,000
+The major advantage of the criteria API is that errors can be detected early during compile time string
+
+56
+00:05:12,000 --> 00:05:19,000
+based typical queries and GP criteria based queries are same and performance and efficiency.
+
+57
+00:05:19,000 --> 00:05:24,000
+So it would be up to you which one you would like to use in your code.
+
+58
+00:05:25,000 --> 00:05:25,000
+Okay.
+
+59
+00:05:26,000 --> 00:05:29,000
+We learned enough, Sarah, to proceed with practical examples.
+
+60
+00:05:29,000 --> 00:05:33,000
+Let me start screen sharing and proceed with code examples.
+
+61
+00:05:34,000 --> 00:05:39,000
+All examples from today's lesson will be in the package queries.
+
+62
+00:05:39,000 --> 00:05:42,000
+You will be able to find the reference to the source code.
+
+63
+00:05:42,000 --> 00:05:47,000
+Examples in attachments to the lesson you ran multiple examples.
+
+64
+00:05:47,000 --> 00:05:51,000
+Today I am going to use user entity from this package.
+
+65
+00:05:51,000 --> 00:05:59,000
+Here it is to avoid name conflict with other users that we created during the previous classes.
+
+66
+00:05:59,000 --> 00:06:05,000
+This user entity has specific entity name and this is just for the sake of the example.
+
+67
+00:06:05,000 --> 00:06:14,000
+As you can see, its name is user queries demo and separately as specified table name user key the.
+
+68
+00:06:15,000 --> 00:06:23,000
+I also did this on purpose so that you would be sure when we use Tae Bo name and when we use entity
+
+69
+00:06:23,000 --> 00:06:25,000
+name in our examples.
+
+70
+00:06:25,000 --> 00:06:33,000
+This is important to know and understand because when we write queries today we will use entity name
+
+71
+00:06:33,000 --> 00:06:37,000
+in gpcr and we will use table name in native queries.
+
+72
+00:06:38,000 --> 00:06:41,000
+Let's start from review of this simple query.
+
+73
+00:06:42,000 --> 00:06:52,000
+I open them across in the main message I create entity manager factory and create entity manager Amazon
+
+74
+00:06:52,000 --> 00:06:53,000
+as usual.
+
+75
+00:06:53,000 --> 00:06:59,000
+After that, I create user in the database like we also always did.
+
+76
+00:07:00,000 --> 00:07:08,000
+And after that I call massive get user buy and I pass ID and entity manager.
+
+77
+00:07:09,000 --> 00:07:11,000
+And here I create query.
+
+78
+00:07:11,000 --> 00:07:17,000
+So to create query object, we need entity manager using entity manager.
+
+79
+00:07:17,000 --> 00:07:22,000
+I can just call mass create query and pause GPIO query.
+
+80
+00:07:22,000 --> 00:07:31,000
+As you can see, it has SQL like syntax, but instead of tables we use entity names.
+
+81
+00:07:32,000 --> 00:07:42,000
+As you can see, I reference the user queries demo entity by its name and assigns ID variable you to
+
+82
+00:07:42,000 --> 00:07:42,000
+it.
+
+83
+00:07:43,000 --> 00:07:49,000
+The ID variable is often called alas and we are ready to learn this with you.
+
+84
+00:07:49,000 --> 00:07:52,000
+In the lessons about relational databases.
+
+85
+00:07:52,000 --> 00:07:57,000
+It is similar to a variable in your Java code that you can use later in the query.
+
+86
+00:07:58,000 --> 00:08:07,000
+For example, here in the vehicles, I use you as a reference to the entity name and its ID property
+
+87
+00:08:07,000 --> 00:08:15,000
+so you can see this else in all other parts of the query to reference this entity.
+
+88
+00:08:16,000 --> 00:08:21,000
+As you can see in Gpcr, I can use parameters, placeholders.
+
+89
+00:08:21,000 --> 00:08:26,000
+I use column and parameter name like wizard here.
+
+90
+00:08:27,000 --> 00:08:36,000
+After that, I can use method set parameter to set parameter to the query and after that I call method
+
+91
+00:08:36,000 --> 00:08:37,000
+get single result.
+
+92
+00:08:38,000 --> 00:08:46,000
+I encourage you to use a source code of query type and its methods because for example, in case we
+
+93
+00:08:46,000 --> 00:08:56,000
+wrote our query and we expect multiple users to be returned, we can call mass get result list that
+
+94
+00:08:56,000 --> 00:09:00,000
+would be needed in case you want to retrieve all users.
+
+95
+00:09:01,000 --> 00:09:03,000
+Let's get back to our example.
+
+96
+00:09:04,000 --> 00:09:05,000
+Let me run this program.
+
+97
+00:09:06,000 --> 00:09:11,000
+And as a result, we see that users that we created is printed to console.
+
+98
+00:09:12,000 --> 00:09:18,000
+So as you can see, the syntax is pretty intuitive if you are familiar with SQL.
+
+99
+00:09:18,000 --> 00:09:25,000
+And if not, please refer to my lessons about SQL in my course Java from zero to first job.
+
+100
+00:09:25,000 --> 00:09:33,000
+I even thought about to show you other examples during this lesson, but when I created those, I decided
+
+101
+00:09:33,000 --> 00:09:38,000
+not to confuse you because they are absolutely similar to SQL query.
+
+102
+00:09:38,000 --> 00:09:47,000
+The only thing that is different is that I use name of my entities instead of the table names, and
+
+103
+00:09:47,000 --> 00:09:55,000
+when I refer to some entity properties, I refer to the entity attribute by their names, but not the
+
+104
+00:09:55,000 --> 00:09:57,000
+columns in the database.
+
+105
+00:09:57,000 --> 00:10:04,000
+So instead of using column name from the database, just use properties name from the Java entity.
+
+106
+00:10:04,000 --> 00:10:13,000
+Another difference is a possibility to use placeholders for parameters like you already saw in example.
+
+107
+00:10:13,000 --> 00:10:14,000
+That's it.
+
+108
+00:10:14,000 --> 00:10:18,000
+In case you would have some challenges, open questions.
+
+109
+00:10:18,000 --> 00:10:23,000
+Please let me know in the comments below video and I will be happy to answer.
+
+110
+00:10:24,000 --> 00:10:28,000
+And now the important thing for you to learn during the development.
+
+111
+00:10:28,000 --> 00:10:35,000
+If you use hibernate, you can add property to show SQL queries that are sent to the database.
+
+112
+00:10:36,000 --> 00:10:39,000
+This is important sometimes to use during the debugging.
+
+113
+00:10:39,000 --> 00:10:45,000
+For example, when you want to make sure what exact where it is sent to the database.
+
+114
+00:10:46,000 --> 00:10:50,000
+I open persistence x email to add one more additional configuration.
+
+115
+00:10:51,000 --> 00:10:56,000
+The property is called Hibernate dot show underscore SQL.
+
+116
+00:10:57,000 --> 00:11:03,000
+We need to set it to true if we want to see generated SQL statements in the logs.
+
+117
+00:11:03,000 --> 00:11:10,000
+You can find the command here, so feel free to on common ID in the source code examples that I will
+
+118
+00:11:10,000 --> 00:11:11,000
+share with you.
+
+119
+00:11:12,000 --> 00:11:15,000
+And let's run our problem one more time.
+
+120
+00:11:16,000 --> 00:11:19,000
+As you can see, there are queries in console.
+
+121
+00:11:19,000 --> 00:11:27,000
+So in case you would face some errors and you can't understand why code doesn't work as it is expected,
+
+122
+00:11:27,000 --> 00:11:32,000
+then please enable this property and explore logs.
+
+123
+00:11:33,000 --> 00:11:36,000
+For now I will comment this property back.
+
+124
+00:11:37,000 --> 00:11:45,000
+That tension also to another seen here query can identify what type will be returned.
+
+125
+00:11:45,000 --> 00:11:53,000
+That's why we need to cast result manually to the type that we need because get single result method
+
+126
+00:11:53,000 --> 00:11:57,000
+which hands us just object type and that's it.
+
+127
+00:11:57,000 --> 00:12:00,000
+This things are different with typed query.
+
+128
+00:12:00,000 --> 00:12:05,000
+I open another example that is called GPT type query demo.
+
+129
+00:12:06,000 --> 00:12:12,000
+That query is a separate type that extends query time with typed query type.
+
+130
+00:12:12,000 --> 00:12:17,000
+I can specify the Java type that I want to extract from the database.
+
+131
+00:12:18,000 --> 00:12:25,000
+Typed query is parameterized by the type that I want to work with and when I call get similar result
+
+132
+00:12:25,000 --> 00:12:32,000
+message, I receive the result of the type that I need and I don't need to cast types manually.
+
+133
+00:12:33,000 --> 00:12:39,000
+Let me run this program just to make sure that we received our user object that we expect.
+
+134
+00:12:40,000 --> 00:12:42,000
+Let's now talk about Named Query.
+
+135
+00:12:43,000 --> 00:12:48,000
+I open another example here that is called Gpcr named Query.
+
+136
+00:12:48,000 --> 00:12:57,000
+So imagine the case that in different parts of your application you use different queries and you have
+
+137
+00:12:57,000 --> 00:13:04,000
+a lot of different types and a lot of different queries, and gradually it becomes hard to maintain
+
+138
+00:13:04,000 --> 00:13:05,000
+such amount of queries.
+
+139
+00:13:06,000 --> 00:13:13,000
+But what if you could keep all queries that you used to gather with a specific entity in one centralized
+
+140
+00:13:13,000 --> 00:13:15,000
+place and we use them?
+
+141
+00:13:15,000 --> 00:13:20,000
+Would it be easier named query type can help us with this?
+
+142
+00:13:21,000 --> 00:13:24,000
+Let me open our user clause here.
+
+143
+00:13:24,000 --> 00:13:27,000
+On top you can see annotation named query.
+
+144
+00:13:28,000 --> 00:13:32,000
+Basically what we do, we map specific name with the query.
+
+145
+00:13:33,000 --> 00:13:37,000
+Now let me open typical named query demo class.
+
+146
+00:13:38,000 --> 00:13:40,000
+In this class we have similar example.
+
+147
+00:13:41,000 --> 00:13:45,000
+The only difference is our get user by the masses.
+
+148
+00:13:45,000 --> 00:13:54,000
+This time I use entity manager reference to call create named query and the name of our named query.
+
+149
+00:13:55,000 --> 00:13:57,000
+The rest things are similar here.
+
+150
+00:13:58,000 --> 00:14:03,000
+I will just run this program, but believe me will receive the same result.
+
+151
+00:14:04,000 --> 00:14:07,000
+Named careers have some huge advantages.
+
+152
+00:14:07,000 --> 00:14:12,000
+They are named squares a compiled and validated one.
+
+153
+00:14:12,000 --> 00:14:14,000
+The persistence unit is loaded.
+
+154
+00:14:14,000 --> 00:14:19,000
+We can centralize named queries to make them easier to maintain.
+
+155
+00:14:19,000 --> 00:14:26,000
+For example, in or read maximal in properties, files or in entity classes.
+
+156
+00:14:27,000 --> 00:14:30,000
+Now let's talk about native SQL queries.
+
+157
+00:14:30,000 --> 00:14:38,000
+Obviously, syntax has some restrictions and sometimes we want to optimize query execution and to use
+
+158
+00:14:38,000 --> 00:14:41,000
+the whole power of SQL.
+
+159
+00:14:41,000 --> 00:14:47,000
+This approach actually has its own pros and cons regarding advantages.
+
+160
+00:14:47,000 --> 00:14:48,000
+We kind of talk through them.
+
+161
+00:14:49,000 --> 00:14:56,000
+It is a possibility to use the whole power of SQL and create queries specifically for the selected database
+
+162
+00:14:56,000 --> 00:15:01,000
+considering database dialogue but talking about disadvantages.
+
+163
+00:15:01,000 --> 00:15:08,000
+You have to understand that using native SQL queries, you can lose portability of your solution.
+
+164
+00:15:09,000 --> 00:15:18,000
+By saying this, I mean that GPA serves us as an abstraction and GP takes care of compatibility with
+
+165
+00:15:18,000 --> 00:15:18,000
+the database.
+
+166
+00:15:19,000 --> 00:15:25,000
+Basically, you can just change the driver and dialect and configurations, and your solution can work
+
+167
+00:15:25,000 --> 00:15:29,000
+with any other database using native SQL queries.
+
+168
+00:15:29,000 --> 00:15:32,000
+Maybe not so flexible.
+
+169
+00:15:32,000 --> 00:15:39,000
+You should remember this using native query doesn't necessarily mean that our code works with only one
+
+170
+00:15:39,000 --> 00:15:41,000
+specific database.
+
+171
+00:15:41,000 --> 00:15:43,000
+I just highlight the risks.
+
+172
+00:15:43,000 --> 00:15:51,000
+At the end of the day, if our queries don't use database specific SQL commands and we are using only
+
+173
+00:15:51,000 --> 00:15:53,000
+a standard SQL syntax.
+
+174
+00:15:53,000 --> 00:15:58,000
+Switching providers of databases should not be an issue.
+
+175
+00:15:58,000 --> 00:16:00,000
+But now you're warned.
+
+176
+00:16:01,000 --> 00:16:08,000
+But in most cases, a good SQL query can help us to solve our business tasks and most importantly,
+
+177
+00:16:08,000 --> 00:16:13,000
+maintain a level of abstraction from the actual database implementation.
+
+178
+00:16:14,000 --> 00:16:16,000
+Let me open a native query demo clause.
+
+179
+00:16:17,000 --> 00:16:23,000
+This is the same examples that we already reviewed, but the get user by ID mass is slightly different.
+
+180
+00:16:24,000 --> 00:16:32,000
+Basically less complex and creation of native queries you just call massive, create native query and
+
+181
+00:16:32,000 --> 00:16:34,000
+pass native SQL query.
+
+182
+00:16:34,000 --> 00:16:35,000
+That's it.
+
+183
+00:16:35,000 --> 00:16:42,000
+Pay attention that this time we pass table name but not entity name.
+
+184
+00:16:43,000 --> 00:16:46,000
+Basically that's it regarding native queries.
+
+185
+00:16:46,000 --> 00:16:55,000
+My general advice would be try to use typical queries when it is possible or criteria API and only in
+
+186
+00:16:55,000 --> 00:17:00,000
+case you want to optimize query execution and it's really worth it.
+
+187
+00:17:00,000 --> 00:17:03,000
+In this case, you can try native queries.
+
+188
+00:17:04,000 --> 00:17:06,000
+That's my general recommendation.
+
+189
+00:17:06,000 --> 00:17:10,000
+But again, it is only up to you what you decide to use.
+
+190
+00:17:11,000 --> 00:17:15,000
+And finally, let's learn what the criteria API is.
+
+191
+00:17:16,000 --> 00:17:16,000
+Criteria.
+
+192
+00:17:16,000 --> 00:17:21,000
+API queries are programmatically built type save queries.
+
+193
+00:17:21,000 --> 00:17:29,000
+It enables us to write queries without doing raw SQL as well as gives us some object oriented control
+
+194
+00:17:29,000 --> 00:17:33,000
+over the queries, which is one of the main features of GPA.
+
+195
+00:17:34,000 --> 00:17:42,000
+The criteria API allows us to build up a criteria query object programmatically where we can apply different
+
+196
+00:17:42,000 --> 00:17:46,000
+kinds of filtration rules and logical conditions.
+
+197
+00:17:47,000 --> 00:17:49,000
+I open another example.
+
+198
+00:17:49,000 --> 00:17:52,000
+This is called criteria API demo.
+
+199
+00:17:52,000 --> 00:17:59,000
+This is similar example that we have reviewed, but I have a few methods here written with criteria
+
+200
+00:17:59,000 --> 00:18:00,000
+API.
+
+201
+00:18:01,000 --> 00:18:02,000
+Let's start from the simple one.
+
+202
+00:18:03,000 --> 00:18:09,000
+Let's extract all users from the database, even despite we created only one user.
+
+203
+00:18:09,000 --> 00:18:17,000
+Still, it will be useful for you to learn API how to extract all entities of the specific entity type.
+
+204
+00:18:18,000 --> 00:18:19,000
+Let's review method.
+
+205
+00:18:19,000 --> 00:18:22,000
+It is called get all users.
+
+206
+00:18:22,000 --> 00:18:26,000
+So if you see criteria, API is the first time.
+
+207
+00:18:26,000 --> 00:18:35,000
+Most likely it wouldn't look very friendly, but once you start use it, everything will become logical
+
+208
+00:18:35,000 --> 00:18:35,000
+for you.
+
+209
+00:18:36,000 --> 00:18:38,000
+Let's review this simple example.
+
+210
+00:18:39,000 --> 00:18:43,000
+We use entity manager to get criteria builder.
+
+211
+00:18:43,000 --> 00:18:45,000
+Using Criteria Builder.
+
+212
+00:18:45,000 --> 00:18:50,000
+We create query as you can see to create query.
+
+213
+00:18:50,000 --> 00:18:53,000
+I pass class of my entity here.
+
+214
+00:18:53,000 --> 00:19:02,000
+After that we use method form to create a query route so this massive creates and add a query route
+
+215
+00:19:02,000 --> 00:19:05,000
+corresponding to the given entity.
+
+216
+00:19:05,000 --> 00:19:10,000
+And using this route will apply different conditions.
+
+217
+00:19:11,000 --> 00:19:18,000
+After that I create a query on the entity manager and parse criteria query there.
+
+218
+00:19:18,000 --> 00:19:26,000
+We use select method on our criteria query and I pass the root to respondent as a given entity.
+
+219
+00:19:26,000 --> 00:19:27,000
+That's it.
+
+220
+00:19:28,000 --> 00:19:33,000
+After that, I work with query object to extract the list of results.
+
+221
+00:19:34,000 --> 00:19:37,000
+Let's put our focus now on the massive get user buy.
+
+222
+00:19:39,000 --> 00:19:45,000
+Basically, we do almost the same thing, but in addition to select I apply condition.
+
+223
+00:19:46,000 --> 00:19:51,000
+I can limit results of the query by applying their condition.
+
+224
+00:19:51,000 --> 00:20:00,000
+I call their method where method takes predicate to create predicate, you can use different masses,
+
+225
+00:20:00,000 --> 00:20:03,000
+for example, equals mass.
+
+226
+00:20:03,000 --> 00:20:08,000
+It creates a protocol that validates equality with the parameter passed.
+
+227
+00:20:09,000 --> 00:20:15,000
+We can open criteria, build and just explore masses that we can predict to us.
+
+228
+00:20:15,000 --> 00:20:25,000
+In the source code you can see not the equal mass that also returns predicate is not now is now is false
+
+229
+00:20:25,000 --> 00:20:29,000
+is true and a lot of other and masses here.
+
+230
+00:20:29,000 --> 00:20:35,000
+I encourage you to look through the source code to learn this API better.
+
+231
+00:20:36,000 --> 00:20:43,000
+I don't see that we need to stop on this too much because names of the masses are self describing.
+
+232
+00:20:43,000 --> 00:20:50,000
+I believe that you are smart enough to understand what kind of condition is created based on the massive
+
+233
+00:20:50,000 --> 00:20:55,000
+name and even in case some mass that would remain not clear.
+
+234
+00:20:55,000 --> 00:21:01,000
+Please do not hesitate to ask your questions below the video and I will be happy to answer.
+
+235
+00:21:02,000 --> 00:21:10,000
+After that we call yet mass on our user route reference and we pass here ID's that we need to compare.
+
+236
+00:21:11,000 --> 00:21:16,000
+Route type extends from type and from type.
+
+237
+00:21:16,000 --> 00:21:18,000
+Extends past the.
+
+238
+00:21:19,000 --> 00:21:22,000
+So they get massive ease from the pass interface.
+
+239
+00:21:23,000 --> 00:21:27,000
+This is not the pass from the new package that we already learned.
+
+240
+00:21:28,000 --> 00:21:32,000
+This is post from Jakarta Persistence Criteria Package.
+
+241
+00:21:32,000 --> 00:21:41,000
+It represents a simple or compound attribute pass from a bound type or collection and is a primitive
+
+242
+00:21:41,000 --> 00:21:41,000
+expression.
+
+243
+00:21:42,000 --> 00:21:44,000
+Let's get back to our example.
+
+244
+00:21:45,000 --> 00:21:52,000
+After that, we mass get single result and that's it and we receive user object.
+
+245
+00:21:53,000 --> 00:22:01,000
+There are different other queries that you can make using criteria API and hidden command lines.
+
+246
+00:22:01,000 --> 00:22:03,000
+I left a few more examples.
+
+247
+00:22:03,000 --> 00:22:08,000
+Some of them are extract users with a greater than one.
+
+248
+00:22:09,000 --> 00:22:12,000
+Extract the users where first name contains all.
+
+249
+00:22:13,000 --> 00:22:17,000
+Extract users was aged between one and five.
+
+250
+00:22:17,000 --> 00:22:22,000
+Extract users with a first name in the specified range.
+
+251
+00:22:23,000 --> 00:22:28,000
+Example of how you can chain expressions using different credit cards.
+
+252
+00:22:28,000 --> 00:22:35,000
+You just create multiple credit cards, put them into the array, and after that you apply an array
+
+253
+00:22:35,000 --> 00:22:36,000
+of predicates.
+
+254
+00:22:37,000 --> 00:22:39,000
+Such API also exists.
+
+255
+00:22:40,000 --> 00:22:42,000
+Feel free to use it if you wish.
+
+256
+00:22:43,000 --> 00:22:44,000
+Sort an example.
+
+257
+00:22:45,000 --> 00:22:53,000
+In this example you can see that I saw in ascending order by name and in descending order by last name.
+
+258
+00:22:53,000 --> 00:22:56,000
+You can explore these source code examples.
+
+259
+00:22:57,000 --> 00:23:02,000
+Just take a look how a deal predicts here and which methods I use.
+
+260
+00:23:03,000 --> 00:23:10,000
+You can build similar pretty cuts using my examples or you can explore as a massive criteria builder
+
+261
+00:23:10,000 --> 00:23:11,000
+type.
+
+262
+00:23:12,000 --> 00:23:13,000
+Let's review now.
+
+263
+00:23:13,000 --> 00:23:17,000
+Date example will update email of our user.
+
+264
+00:23:18,000 --> 00:23:23,000
+After I created criteria builder, I call create criteria update massive.
+
+265
+00:23:24,000 --> 00:23:29,000
+I use set mass to provide new value for email field.
+
+266
+00:23:29,000 --> 00:23:37,000
+After that, I apply a rare condition in order to change email only for user where Ivy is equal to one.
+
+267
+00:23:37,000 --> 00:23:44,000
+I post to the mask and after that I create query and call method execute update.
+
+268
+00:23:44,000 --> 00:23:45,000
+That's it.
+
+269
+00:23:46,000 --> 00:23:49,000
+Let me also show you example of deletion.
+
+270
+00:23:49,000 --> 00:23:57,000
+I called create criteria delete massive and after that Amazon which you already saw in the examples
+
+271
+00:23:58,000 --> 00:24:04,000
+we add pretty good here to make sure that only the record where it matched will be removed.
+
+272
+00:24:05,000 --> 00:24:12,000
+So at the first glance we did a lot of other things instead of just making a to the database.
+
+273
+00:24:13,000 --> 00:24:20,000
+But remember, the criteria API is a programmatic way to build queries in the object oriented manner.
+
+274
+00:24:21,000 --> 00:24:24,000
+It reduces chances to make a mistake.
+
+275
+00:24:25,000 --> 00:24:32,000
+Of course, there are some disadvantages as well, especially around more complex joints.
+
+276
+00:24:32,000 --> 00:24:38,000
+So it is up to you which tool and what API to choose for building query.
+
+277
+00:24:38,000 --> 00:24:40,000
+It will depend on the multiple things.
+
+278
+00:24:41,000 --> 00:24:46,000
+But now you know how to use criteria API to query a database.
+
+279
+00:24:46,000 --> 00:24:49,000
+That's all what I wanted to share with you today.
+
+280
+00:24:49,000 --> 00:24:53,000
+Let's recap what we have learned in this lesson.
+
+281
+00:24:54,000 --> 00:24:57,000
+They learned different types of queries in GPA.
+
+282
+00:24:58,000 --> 00:25:03,000
+We learned such types as query type, query and name query.
+
+283
+00:25:04,000 --> 00:25:12,000
+Also, I explained how to work with native query type and we saw a lot of examples how to work with
+
+284
+00:25:12,000 --> 00:25:13,000
+criteria API.
+
+285
+00:25:14,000 --> 00:25:21,000
+After this lesson, you should have a clear understanding of what GPL is and its key features.
+
+286
+00:25:22,000 --> 00:25:25,000
+Also, we had a lot of practical exercises today.
+
+287
+00:25:26,000 --> 00:25:30,000
+You can find the reference to the source code examples in attachments to the lesson.
+
+288
+00:25:31,000 --> 00:25:33,000
+That's all for this lesson.
+
+289
+00:25:33,000 --> 00:25:35,000
+Thanks a lot for your attention.
+
+290
+00:25:35,000 --> 00:25:39,000
+Have a great day and see you in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/007 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/007 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..27e6ba7beafe6e10637d84d9578d9eb33c9a02d7
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/007 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/queries
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/008 Caching in JPAHibernate_en.srt b/78 - ORM, JPA & Hibernate/008 Caching in JPAHibernate_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..bf297dd996c35448c317952100fc2ba1291cbe59
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/008 Caching in JPAHibernate_en.srt
@@ -0,0 +1,1424 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:13,000
+Today we're going to have important and interesting lessons that will help you to optimize the performance
+
+3
+00:00:13,000 --> 00:00:16,000
+of your application while working with the GP.
+
+4
+00:00:16,000 --> 00:00:22,000
+Hibernate will go on caching in GP using hibernate.
+
+5
+00:00:23,000 --> 00:00:30,000
+We're going to start our lesson from learning what actually caching is and discussing cache structure
+
+6
+00:00:30,000 --> 00:00:39,000
+in GP hibernate will learn what first level cache is, what the second level cache is, and what query
+
+7
+00:00:39,000 --> 00:00:41,000
+level cache is.
+
+8
+00:00:41,000 --> 00:00:48,000
+In the lesson, we'll discuss different cache providers, but in our practical examples, we're going
+
+9
+00:00:48,000 --> 00:00:55,000
+to focus our attention on the most popular cache provider that is used with Hibernate in the most cases.
+
+10
+00:00:55,000 --> 00:00:57,000
+I'm talking about E Cache.
+
+11
+00:00:58,000 --> 00:01:02,000
+Also, we're going to have a lot of practical examples and demo today.
+
+12
+00:01:02,000 --> 00:01:09,000
+During the review of examples, we'll talk about different cache concurrency strategies, cache eviction
+
+13
+00:01:09,000 --> 00:01:17,000
+policies also will explain what the standard query cache and update timestamp cache are.
+
+14
+00:01:18,000 --> 00:01:25,000
+I will show you a custom configuration of cash will learn persistence strategies in cash.
+
+15
+00:01:25,000 --> 00:01:28,000
+We have a lot of things to learn today.
+
+16
+00:01:28,000 --> 00:01:29,000
+Let's start our lesson.
+
+17
+00:01:30,000 --> 00:01:35,000
+Let's start from understanding of what Kashin is and why do we need it.
+
+18
+00:01:36,000 --> 00:01:43,000
+In computing, a cache is a hardware or software component that stores data so that future requests
+
+19
+00:01:43,000 --> 00:01:46,000
+for that data can be served faster.
+
+20
+00:01:46,000 --> 00:01:54,000
+The data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere.
+
+21
+00:01:55,000 --> 00:02:02,000
+To be cost effective and to enable efficient use of data caches must be relatively small.
+
+22
+00:02:03,000 --> 00:02:08,000
+Nevertheless, caches have proven themselves in many areas of computing.
+
+23
+00:02:09,000 --> 00:02:15,000
+In the GPA, caching is a mechanism to enhance the performance of a system.
+
+24
+00:02:15,000 --> 00:02:21,000
+It is a buffer memory that lies between the application and the database cache.
+
+25
+00:02:21,000 --> 00:02:30,000
+Memory stores recently used data items in order to reduce the number of database heads as much as possible.
+
+26
+00:02:31,000 --> 00:02:34,000
+Let's review the structure of cache in the GPA.
+
+27
+00:02:35,000 --> 00:02:38,000
+GPUs supports a multilevel cache and skiing.
+
+28
+00:02:38,000 --> 00:02:45,000
+Mainly, there are two levels of cache, first level cache and the second level cache.
+
+29
+00:02:46,000 --> 00:02:52,000
+But as you already learned from agenda to the lesson we are also going to learn today, query level
+
+30
+00:02:52,000 --> 00:02:53,000
+cache.
+
+31
+00:02:53,000 --> 00:02:59,000
+First level cache is enabled by default and you can disable it.
+
+32
+00:03:00,000 --> 00:03:04,000
+Second level cache should be enabled in configuration.
+
+33
+00:03:04,000 --> 00:03:07,000
+And today I'm going to show you how to do that.
+
+34
+00:03:08,000 --> 00:03:11,000
+The same thing is for query level cache.
+
+35
+00:03:11,000 --> 00:03:20,000
+Second level shared cache is an auxiliary technique mainly used in GPA to enhance performance.
+
+36
+00:03:20,000 --> 00:03:29,000
+It is used a special urine large inflow outflow of data between the database and the application cache
+
+37
+00:03:29,000 --> 00:03:34,000
+and also reduces search time when the searched entity is already in the cache.
+
+38
+00:03:34,000 --> 00:03:39,000
+Otherwise it is fetched from the database to serve the purpose.
+
+39
+00:03:39,000 --> 00:03:47,000
+However, when a subsequent search query is for it, it takes little time as a searched entity is already
+
+40
+00:03:47,000 --> 00:03:57,000
+in the cache entity manager stores and it is for almost every CRUD operation in this shared cache before
+
+41
+00:03:57,000 --> 00:04:00,000
+flushing the content to the database.
+
+42
+00:04:00,000 --> 00:04:06,000
+Second level cache is complementary to its first level counterpart.
+
+43
+00:04:06,000 --> 00:04:11,000
+Let's review each level before we'll go with practical exercises.
+
+44
+00:04:12,000 --> 00:04:16,000
+We're going to review now what the first level cash is.
+
+45
+00:04:17,000 --> 00:04:24,000
+And that manager always maintains a cash call, the first level in the first level.
+
+46
+00:04:24,000 --> 00:04:32,000
+Cash crop operations are performed per transaction basis to reduce the number of queries for to the
+
+47
+00:04:32,000 --> 00:04:33,000
+database.
+
+48
+00:04:34,000 --> 00:04:41,000
+So for example, when we retrieve an entity from the database, the first time the data is retrieved
+
+49
+00:04:41,000 --> 00:04:48,000
+from the database and the stored is the first level cash associated with the entity manager.
+
+50
+00:04:48,000 --> 00:04:56,000
+And in case entity is modified several times within the same transaction, all changes are done in the
+
+51
+00:04:56,000 --> 00:05:03,000
+cash only modification and the database level is postponed until we commit our transaction.
+
+52
+00:05:04,000 --> 00:05:10,000
+GP And that is cashed at the persistence, context level and guarantees.
+
+53
+00:05:10,000 --> 00:05:17,000
+There will be one object instance per persistence context for a specific role of a database table.
+
+54
+00:05:18,000 --> 00:05:25,000
+Concurrent transactions affecting the same row I managed by applying an appropriate locking mechanism
+
+55
+00:05:25,000 --> 00:05:26,000
+in the GP.
+
+56
+00:05:27,000 --> 00:05:31,000
+And I have a separate lesson about locking in GPA.
+
+57
+00:05:31,000 --> 00:05:35,000
+Feel free to refer to that lesson to learn more about locking.
+
+58
+00:05:36,000 --> 00:05:39,000
+Let's now talk about second level cash.
+
+59
+00:05:40,000 --> 00:05:48,000
+This level of cash emerged more due to performance reasons is an absolute necessity, in fact, and
+
+60
+00:05:48,000 --> 00:05:54,000
+in more shared cash increases the possibility of the problem of a stale read.
+
+61
+00:05:54,000 --> 00:06:03,000
+Stale read is a read operation that fetches an incorrect value from a source that has not synchronized
+
+62
+00:06:03,000 --> 00:06:06,000
+an update operation to the value.
+
+63
+00:06:06,000 --> 00:06:14,000
+As you can see on this slide, the second level cash sits between entity manager and the database.
+
+64
+00:06:14,000 --> 00:06:22,000
+Persistence context shares the cash making the second level cash available throughout the application
+
+65
+00:06:23,000 --> 00:06:31,000
+database traffic is reduced considerably because entities are loaded into the shared cache and made
+
+66
+00:06:31,000 --> 00:06:32,000
+available from there.
+
+67
+00:06:33,000 --> 00:06:38,000
+We can say that second level cash provides the following benefits.
+
+68
+00:06:39,000 --> 00:06:43,000
+Persistence provide the managers local store of entity data.
+
+69
+00:06:44,000 --> 00:06:48,000
+Leverage is performance by avoiding expensive data based calls.
+
+70
+00:06:49,000 --> 00:06:53,000
+Data are kept transparent to the application.
+
+71
+00:06:53,000 --> 00:06:59,000
+CRUD operation can be performed through normal entity manager functions.
+
+72
+00:06:59,000 --> 00:07:06,000
+Application can remain oblivious of the underlying cache and do its job inadvertently.
+
+73
+00:07:07,000 --> 00:07:15,000
+Persistence providers like Eclipse, Link, Hibernate, etc. have their own set of implementation created
+
+74
+00:07:15,000 --> 00:07:21,000
+either reusing an existing one or developing their own from scratch.
+
+75
+00:07:22,000 --> 00:07:25,000
+Let's now talk about corporate level cash.
+
+76
+00:07:25,000 --> 00:07:28,000
+The cash can be configured in the hibernate.
+
+77
+00:07:29,000 --> 00:07:34,000
+The corporate cash is responsible for cash and the results of queries.
+
+78
+00:07:34,000 --> 00:07:42,000
+Now that the query cash doesn't cash the state of the actual entities in the results set it.
+
+79
+00:07:42,000 --> 00:07:47,000
+Cash is only identifier values and results of value type.
+
+80
+00:07:47,000 --> 00:07:56,000
+So the query cash should always be used in conjunction with second level cash, where cash is responsible
+
+81
+00:07:56,000 --> 00:08:04,000
+for cash in the combination of query and values provided as parameters as key and list of identifiers
+
+82
+00:08:04,000 --> 00:08:09,000
+of objects returned by query execution as values.
+
+83
+00:08:09,000 --> 00:08:17,000
+Note that the using query cache requires a second level cache too, because when you query result is
+
+84
+00:08:17,000 --> 00:08:21,000
+get from cash is it is the list of identifiers.
+
+85
+00:08:21,000 --> 00:08:27,000
+Hibernate will load objects using cached identifiers from second level.
+
+86
+00:08:27,000 --> 00:08:32,000
+Today we're going to run query level cache due on examples.
+
+87
+00:08:33,000 --> 00:08:39,000
+As I promised to you in this lesson, we're going to have practical Dhamma and exercises.
+
+88
+00:08:39,000 --> 00:08:44,000
+But before we start the Dharma, I want to discuss with you a few important notes.
+
+89
+00:08:45,000 --> 00:08:51,000
+As always, all examples for this lesson you will be able to find in attachments to the video.
+
+90
+00:08:52,000 --> 00:08:58,000
+Taking into account there is some specifics with implementation of the second level cache.
+
+91
+00:08:59,000 --> 00:09:06,000
+I created a separate project for this example because you need to be very attentive with the selection
+
+92
+00:09:06,000 --> 00:09:09,000
+of hybrid version and cash provider.
+
+93
+00:09:09,000 --> 00:09:14,000
+Take into account we have a lot of examples in our GPA project.
+
+94
+00:09:14,000 --> 00:09:19,000
+I created a separate project for second level and higher level cash.
+
+95
+00:09:19,000 --> 00:09:20,000
+Examples.
+
+96
+00:09:21,000 --> 00:09:27,000
+You are already familiar with the GPA terminology, but to take advantage of Hebrew features in this
+
+97
+00:09:27,000 --> 00:09:31,000
+lesson we're going to use Hibernate API.
+
+98
+00:09:31,000 --> 00:09:39,000
+While it is pretty intuitive if you know GPA already, still, I would like to highlight a few things.
+
+99
+00:09:39,000 --> 00:09:45,000
+Entity Manager Factory in GB is the seamless sync session factory.
+
+100
+00:09:45,000 --> 00:09:50,000
+So one of the examples you are going to see is that I work with Session Factory.
+
+101
+00:09:50,000 --> 00:09:56,000
+Remember that it has the similar goals as entity manager factory.
+
+102
+00:09:57,000 --> 00:10:03,000
+The next thing entity manager in GB is the similar same as session.
+
+103
+00:10:03,000 --> 00:10:08,000
+Also on hibernate, we use configuration file with different name.
+
+104
+00:10:08,000 --> 00:10:19,000
+So instead of persistence x symbol that we use in GP, we use hibernate c fg x file in hibernate.
+
+105
+00:10:20,000 --> 00:10:23,000
+These are the main things that I'd like to highlight.
+
+106
+00:10:24,000 --> 00:10:32,000
+So don't panic and don't be confused in case during the demo you would see me using new classes.
+
+107
+00:10:33,000 --> 00:10:36,000
+I believe that now we are ready for practical examples.
+
+108
+00:10:36,000 --> 00:10:42,000
+Let me start screen sharing and walk you through the examples that I have prepared for this lesson.
+
+109
+00:10:43,000 --> 00:10:51,000
+So the already understood is that once entity manager or in hibernate terminology, the session is closed,
+
+110
+00:10:51,000 --> 00:10:54,000
+the first level cache is terminated as well.
+
+111
+00:10:55,000 --> 00:11:03,000
+This is actually desirable as it allows for concurrent sessions to work with entity instances in isolation
+
+112
+00:11:03,000 --> 00:11:04,000
+from each other.
+
+113
+00:11:05,000 --> 00:11:11,000
+But today we will also learn and see how the second level cache works.
+
+114
+00:11:11,000 --> 00:11:19,000
+A second level cache is Session Factory's code, meaning it is shared by all sessions created with the
+
+115
+00:11:19,000 --> 00:11:21,000
+same session factory.
+
+116
+00:11:22,000 --> 00:11:30,000
+When an entity instance is looked up by its ID user, by application logic or by hibernate internally.
+
+117
+00:11:30,000 --> 00:11:38,000
+This may happen when we need to load associations to that entity from other entities and second level
+
+118
+00:11:38,000 --> 00:11:40,000
+cache is enabled for that entity.
+
+119
+00:11:41,000 --> 00:11:48,000
+The following happens If an instance is already present in the first level cache, it is returned from
+
+120
+00:11:48,000 --> 00:11:49,000
+there.
+
+121
+00:11:50,000 --> 00:11:57,000
+If an instance isn't found in the first level cache and the corresponding instance state is cached in
+
+122
+00:11:57,000 --> 00:12:02,000
+the second level cache, then the data is fetched from there.
+
+123
+00:12:02,000 --> 00:12:07,000
+Otherwise the necessary data are loaded from the database.
+
+124
+00:12:08,000 --> 00:12:15,000
+Once the instance is stored in the persistence context first level cache, it is returned from there
+
+125
+00:12:15,000 --> 00:12:24,000
+in all subsequent calls within the same session until the session is closed or the instance is manually
+
+126
+00:12:24,000 --> 00:12:27,000
+evicted from the persistence context.
+
+127
+00:12:27,000 --> 00:12:34,000
+The loaded instant state is also stored in the second level cache if it wasn't already there.
+
+128
+00:12:35,000 --> 00:12:38,000
+Let's start the demo from Model Overview.
+
+129
+00:12:39,000 --> 00:12:43,000
+We're going to use user model and here it is.
+
+130
+00:12:43,000 --> 00:12:52,000
+It is also good tone of coding to use cash annotation for the entity that you want to cash for hibernate.
+
+131
+00:12:52,000 --> 00:12:59,000
+It means nothing, but still it is good information that this entity will be stored in the second level
+
+132
+00:12:59,000 --> 00:13:00,000
+cache.
+
+133
+00:13:01,000 --> 00:13:06,000
+This is gpe annotation, not hibernate specific one.
+
+134
+00:13:07,000 --> 00:13:15,000
+I use hybrid cash annotation here too and thus specify cash concurrency strategy and cache region.
+
+135
+00:13:16,000 --> 00:13:19,000
+Let's learn what the cache concurrency strategy is.
+
+136
+00:13:20,000 --> 00:13:28,000
+Depending on what we need and our use case, we can select one of the following cash concurrency strategies
+
+137
+00:13:28,000 --> 00:13:33,000
+we only use only for entities that never change.
+
+138
+00:13:33,000 --> 00:13:35,000
+Exceptions roam.
+
+139
+00:13:35,000 --> 00:13:41,000
+If an attempt to update such an entity is made, it is relatively simple.
+
+140
+00:13:41,000 --> 00:13:44,000
+It's suitable for static reference data.
+
+141
+00:13:44,000 --> 00:13:45,000
+That doesn't change.
+
+142
+00:13:46,000 --> 00:13:48,000
+North Street with.
+
+143
+00:13:48,000 --> 00:13:48,000
+Right.
+
+144
+00:13:49,000 --> 00:13:53,000
+Cash is updated after the transaction that changed.
+
+145
+00:13:53,000 --> 00:13:55,000
+The affected data has been committed.
+
+146
+00:13:55,000 --> 00:14:04,000
+Thus strong consistency isn't guaranteed and there is small time window in which stale data may be obtained
+
+147
+00:14:04,000 --> 00:14:06,000
+from the cash.
+
+148
+00:14:06,000 --> 00:14:13,000
+This kind of strategy is suitable for use cases that can tolerate eventual consistency.
+
+149
+00:14:14,000 --> 00:14:15,000
+We tried.
+
+150
+00:14:15,000 --> 00:14:25,000
+This strategy guarantees strong consistency, which it achieves by using soft locks when a cached entity
+
+151
+00:14:25,000 --> 00:14:32,000
+is updated and soft lock is stored in the cache for that entity as well, which is released after the
+
+152
+00:14:32,000 --> 00:14:34,000
+transaction is committed.
+
+153
+00:14:35,000 --> 00:14:41,000
+All concurrent transactions that access soft locked entries will fetch the corresponding data directly
+
+154
+00:14:41,000 --> 00:14:43,000
+from the database.
+
+155
+00:14:43,000 --> 00:14:49,000
+Transactional cash changes are done in distributed global transactions.
+
+156
+00:14:50,000 --> 00:14:59,000
+A change in the cash empathy is committed or rolled back in both the database and cash in the same global
+
+157
+00:14:59,000 --> 00:15:00,000
+transaction.
+
+158
+00:15:01,000 --> 00:15:05,000
+Let's get back to the user clause and that's a property of cash.
+
+159
+00:15:05,000 --> 00:15:07,000
+Annotation is region.
+
+160
+00:15:07,000 --> 00:15:10,000
+Basically this is the cache region.
+
+161
+00:15:11,000 --> 00:15:17,000
+Later today, I'm going to show you a configuration of our cash, but ensure you can configure cash
+
+162
+00:15:17,000 --> 00:15:24,000
+regions for different entities based on your business case and how you plan to work with the entity.
+
+163
+00:15:25,000 --> 00:15:33,000
+And now the important thing that you have to remember in case your entity has collections, we need
+
+164
+00:15:33,000 --> 00:15:40,000
+to add cash annotation above the field separately because collections are not cached by default.
+
+165
+00:15:41,000 --> 00:15:45,000
+So we need explicitly more than as cash symbol.
+
+166
+00:15:45,000 --> 00:15:46,000
+That's it.
+
+167
+00:15:46,000 --> 00:15:53,000
+Regarding our model, let me now open maximum file to show you the dependencies that we need to make
+
+168
+00:15:53,000 --> 00:15:54,000
+this project work.
+
+169
+00:15:55,000 --> 00:16:03,000
+Obviously we need to hibernate core dependency and also we need dependency of cache provider hibernate.
+
+170
+00:16:03,000 --> 00:16:10,000
+Second level caching is designed to be unaware of the actual cache provider use.
+
+171
+00:16:10,000 --> 00:16:19,000
+Hibernate only needs to be provided with an implementation of the OR Hibernate Cache API region factory
+
+172
+00:16:19,000 --> 00:16:25,000
+interface, which encapsulates all the details specific to the actual cache providers.
+
+173
+00:16:26,000 --> 00:16:31,000
+Basically, it acts as a bridge between hibernate and cache providers.
+
+174
+00:16:31,000 --> 00:16:39,000
+In this lesson I'm going to use E cache and mature and widely used cache as our cache provider.
+
+175
+00:16:40,000 --> 00:16:47,000
+We could select any other provider and start as long as there is an implementation of a region factory
+
+176
+00:16:47,000 --> 00:16:48,000
+for.
+
+177
+00:16:49,000 --> 00:16:57,000
+I added here hibernate a cache implementation and also our solution would require e cache core dependency.
+
+178
+00:16:58,000 --> 00:17:02,000
+This is just a demo with only one possible cache provider.
+
+179
+00:17:02,000 --> 00:17:09,000
+This is the most popular one for Hibernate, but theoretically you can use all the cache providers you
+
+180
+00:17:09,000 --> 00:17:10,000
+like.
+
+181
+00:17:10,000 --> 00:17:20,000
+The steps to make it work would be similar among other cache providers that I can mention or J bos swarm
+
+182
+00:17:20,000 --> 00:17:24,000
+cache or se cache and others.
+
+183
+00:17:25,000 --> 00:17:32,000
+In the case with E cache, we need to make sure that the hibernate e cache version is equal to the hibernate
+
+184
+00:17:32,000 --> 00:17:35,000
+version we're using in our project.
+
+185
+00:17:35,000 --> 00:17:41,000
+Now let's enable second level cache in our hibernate configuration file.
+
+186
+00:17:41,000 --> 00:17:45,000
+I open hibernate cfg xml file.
+
+187
+00:17:45,000 --> 00:17:49,000
+Here you can see four important properties.
+
+188
+00:17:49,000 --> 00:17:57,000
+They are hibernate cache region factory class in this property with specified cache factory class.
+
+189
+00:17:57,000 --> 00:18:04,000
+In the case with E cache we can specify either E cache region factory or singleton and cache region
+
+190
+00:18:04,000 --> 00:18:05,000
+factory.
+
+191
+00:18:05,000 --> 00:18:08,000
+So what is the difference and which one to choose?
+
+192
+00:18:09,000 --> 00:18:17,000
+The non singleton e cache region factory allows you to configure E cache separately for each hibernate
+
+193
+00:18:17,000 --> 00:18:26,000
+instance using nat asf e cache configuration resource name property the singleton a cache region factory
+
+194
+00:18:26,000 --> 00:18:33,000
+shares the same e cache configuration and more all hibernate session factors.
+
+195
+00:18:34,000 --> 00:18:36,000
+The next property is hibernate cash.
+
+196
+00:18:36,000 --> 00:18:38,000
+Use second level cash.
+
+197
+00:18:39,000 --> 00:18:44,000
+We need to switch this one to true to enable second level cash.
+
+198
+00:18:45,000 --> 00:18:45,000
+Hibernate.
+
+199
+00:18:45,000 --> 00:18:48,000
+Cash use query cash.
+
+200
+00:18:48,000 --> 00:18:49,000
+I already told you that.
+
+201
+00:18:49,000 --> 00:18:52,000
+Today we are also going through your query cash.
+
+202
+00:18:52,000 --> 00:18:55,000
+We need to set this one to true.
+
+203
+00:18:55,000 --> 00:19:01,000
+To enable query cash, not net asset cash configuration resource name.
+
+204
+00:19:02,000 --> 00:19:09,000
+Here we specify the name of the configuration file that is going to be used to configure our cash.
+
+205
+00:19:10,000 --> 00:19:14,000
+This property is a cash provider specific.
+
+206
+00:19:15,000 --> 00:19:23,000
+Basically these are the key configurations that we need to add in our cfg xml file.
+
+207
+00:19:23,000 --> 00:19:27,000
+Let's now take a look at E cache configuration file.
+
+208
+00:19:28,000 --> 00:19:34,000
+I will share with you the source code of this solution and I encourage you to look through this file
+
+209
+00:19:34,000 --> 00:19:35,000
+slowly.
+
+210
+00:19:35,000 --> 00:19:43,000
+You don't need to run all these configuration options by heart because anyway, this is not something
+
+211
+00:19:43,000 --> 00:19:45,000
+what you will do each day.
+
+212
+00:19:45,000 --> 00:19:51,000
+Most likely this would be configured by analogy only a project for new cache regions.
+
+213
+00:19:51,000 --> 00:19:59,000
+As you can see here, we have default cache configured max entries amount the specified time to leave
+
+214
+00:19:59,000 --> 00:20:03,000
+seconds and many other different configurations.
+
+215
+00:20:04,000 --> 00:20:08,000
+Memory store eviction policy is important attribute in my opinion.
+
+216
+00:20:09,000 --> 00:20:17,000
+With this attribute, we can specify eviction policy for elements in cache because as you remember from
+
+217
+00:20:17,000 --> 00:20:24,000
+the definition, cache should be limited in space and contain limited amount of elements.
+
+218
+00:20:24,000 --> 00:20:33,000
+Otherwise we won't be able to benefit from the performance optimization and we need to have a policy
+
+219
+00:20:33,000 --> 00:20:39,000
+which will define what elements should be removed from cache and under what conditions.
+
+220
+00:20:40,000 --> 00:20:44,000
+E cash specifies three possible eviction policies.
+
+221
+00:20:44,000 --> 00:20:47,000
+They are last recently used.
+
+222
+00:20:47,000 --> 00:20:52,000
+This is the one we selected in our example LRU.
+
+223
+00:20:52,000 --> 00:20:58,000
+According to this policy, cash is the last recently used element.
+
+224
+00:20:59,000 --> 00:21:07,000
+The last use timestamp is updated when an element is put into the cache or an element is retrieved from
+
+225
+00:21:07,000 --> 00:21:09,000
+the cash with a get call.
+
+226
+00:21:10,000 --> 00:21:14,000
+Least frequently used as a few.
+
+227
+00:21:15,000 --> 00:21:23,000
+For each get call on the element is a number of heads is updated when a put call is made for a new element
+
+228
+00:21:23,000 --> 00:21:30,000
+and assuming the marks limit is reached, the element was least number of hits.
+
+229
+00:21:30,000 --> 00:21:34,000
+The least frequently used element is a victim.
+
+230
+00:21:34,000 --> 00:21:43,000
+First in, first out elements are evicted in the same order as they come in when a put call is made
+
+231
+00:21:43,000 --> 00:21:51,000
+for a new element and assuming that the max limit is reached for the memory store, the element is it
+
+232
+00:21:51,000 --> 00:21:56,000
+was placed first in the store is the candidate for eviction.
+
+233
+00:21:57,000 --> 00:21:59,000
+These are main eviction policies.
+
+234
+00:21:59,000 --> 00:22:01,000
+Let's get back to the demo.
+
+235
+00:22:02,000 --> 00:22:07,000
+Also, I configure it a few more custom cash regions here.
+
+236
+00:22:07,000 --> 00:22:13,000
+They are user standard query cache and update timestamp cache.
+
+237
+00:22:13,000 --> 00:22:20,000
+Standard query cache, as the name implies, is a standard implementation of the Hibernate Query Cache
+
+238
+00:22:20,000 --> 00:22:21,000
+interface.
+
+239
+00:22:22,000 --> 00:22:29,000
+This implementation is very good at recognizing stale query results and running queries when it detects
+
+240
+00:22:29,000 --> 00:22:30,000
+this condition.
+
+241
+00:22:31,000 --> 00:22:32,000
+Recursion.
+
+242
+00:22:32,000 --> 00:22:33,000
+The results.
+
+243
+00:22:34,000 --> 00:22:41,000
+Update Timestamps Cache Tracks is a timestamps of the most recent updates to particular tables.
+
+244
+00:22:41,000 --> 00:22:49,000
+It is important that the cache timeout of the underlying cache implementation be set to a higher value
+
+245
+00:22:49,000 --> 00:22:52,000
+than timeouts of any of the query caches.
+
+246
+00:22:53,000 --> 00:22:54,000
+And the user region.
+
+247
+00:22:54,000 --> 00:23:02,000
+Cash and user cache region is a region for our entity that we are going to use in our example.
+
+248
+00:23:02,000 --> 00:23:07,000
+As you can see, these elements contain persistence, strategy.
+
+249
+00:23:07,000 --> 00:23:12,000
+Let's learn what it is and what potential options we can set here.
+
+250
+00:23:13,000 --> 00:23:20,000
+The cash has a restored store which provides fast restored ability and options for cash persistence.
+
+251
+00:23:21,000 --> 00:23:26,000
+The restart store implements and on disk mirror of the in-memory cache.
+
+252
+00:23:27,000 --> 00:23:35,000
+After any restart data that was lost in the cash will automatically load from disk into the restart
+
+253
+00:23:35,000 --> 00:23:39,000
+store and from there the data will be available to the cash.
+
+254
+00:23:40,000 --> 00:23:50,000
+Local restart the boot and labels restart store and corpus all cash entries on head and or off heap
+
+255
+00:23:50,000 --> 00:23:51,000
+to this.
+
+256
+00:23:52,000 --> 00:23:59,000
+This option provides fast or stability with fault tolerant cash persistence on disk.
+
+257
+00:24:00,000 --> 00:24:04,000
+This option is available for big memory go only.
+
+258
+00:24:05,000 --> 00:24:11,000
+Distributed the first to the third quarter configuration for persistent settings.
+
+259
+00:24:11,000 --> 00:24:15,000
+This option is for big memory marks only.
+
+260
+00:24:16,000 --> 00:24:21,000
+Local temp swop enables temporary local disk usage.
+
+261
+00:24:21,000 --> 00:24:28,000
+This option provides an extra time for storage during cache operation, but this disk storage is not
+
+262
+00:24:28,000 --> 00:24:29,000
+persistent.
+
+263
+00:24:30,000 --> 00:24:35,000
+After restart, the disk type is cleared of any cache data.
+
+264
+00:24:36,000 --> 00:24:40,000
+LAN doesn't offload cache entries to this.
+
+265
+00:24:41,000 --> 00:24:42,000
+Was this option?
+
+266
+00:24:42,000 --> 00:24:45,000
+All of the cash is kept in memory.
+
+267
+00:24:45,000 --> 00:24:47,000
+This is a default mode.
+
+268
+00:24:48,000 --> 00:24:50,000
+Now let's get back to our demo again.
+
+269
+00:24:52,000 --> 00:24:52,000
+Basically.
+
+270
+00:24:52,000 --> 00:24:57,000
+That's all what I wanted to show you regarding the cache configuration.
+
+271
+00:24:57,000 --> 00:25:03,000
+So probably now when everything is configured, let's look at the second level cash demo.
+
+272
+00:25:04,000 --> 00:25:06,000
+I prepared example here for you.
+
+273
+00:25:07,000 --> 00:25:11,000
+Let me open clause that is called second level cash demo.
+
+274
+00:25:11,000 --> 00:25:18,000
+Execute this program and that will walk you through the console output and source code line by line.
+
+275
+00:25:19,000 --> 00:25:25,000
+So we create session factory first like we discussed before the demo.
+
+276
+00:25:25,000 --> 00:25:34,000
+This is hibernate API and similar sync to entity manager factory from the GPA I created here hibernate
+
+277
+00:25:34,000 --> 00:25:40,000
+until factory which simplifies creation and retrieval of session factory.
+
+278
+00:25:40,000 --> 00:25:48,000
+There is lessons super complicated in Z class, but it just helps us to save time and do not repeat
+
+279
+00:25:48,000 --> 00:25:49,000
+ourselves.
+
+280
+00:25:49,000 --> 00:25:49,000
+Right.
+
+281
+00:25:49,000 --> 00:25:56,000
+A lot of line of codes that we need to use multiple time in different examples today.
+
+282
+00:25:56,000 --> 00:26:03,000
+After that I retrieve statistics object from the session factory and enable statistics.
+
+283
+00:26:03,000 --> 00:26:06,000
+This is again hibernate specific API.
+
+284
+00:26:07,000 --> 00:26:11,000
+This class is used to track statistics of the session factory.
+
+285
+00:26:12,000 --> 00:26:19,000
+The next thing that I do here, I create a user entity and persisted in the database.
+
+286
+00:26:20,000 --> 00:26:22,000
+As you can see, I create session.
+
+287
+00:26:22,000 --> 00:26:26,000
+After that, I use session to start the transaction.
+
+288
+00:26:26,000 --> 00:26:34,000
+And again, I want to help you understand what this API is doing, comparing it with the GP.
+
+289
+00:26:34,000 --> 00:26:42,000
+If you saw my lessons about GP, you can see that these lines of code are similar to creation of entity
+
+290
+00:26:42,000 --> 00:26:45,000
+manager and start transaction.
+
+291
+00:26:45,000 --> 00:26:53,000
+You can also see here that I use safe, massive safe massive is a hidden analysis of persist mass.
+
+292
+00:26:53,000 --> 00:26:57,000
+Basically this method stores entities in database.
+
+293
+00:26:58,000 --> 00:27:05,000
+After we created user in the database, we create separate session object on purpose to demonstrate
+
+294
+00:27:05,000 --> 00:27:11,000
+that this is not the same session object as we use to persist our user.
+
+295
+00:27:11,000 --> 00:27:15,000
+It is a different session object and different transaction.
+
+296
+00:27:16,000 --> 00:27:21,000
+After that I use session object to get user with a one from the database.
+
+297
+00:27:22,000 --> 00:27:23,000
+Lot massive.
+
+298
+00:27:23,000 --> 00:27:28,000
+Here is analogy of find method from entity manager class.
+
+299
+00:27:28,000 --> 00:27:31,000
+I use custom method prints thirds.
+
+300
+00:27:31,000 --> 00:27:37,000
+The user statistics object to show us information about second level cache.
+
+301
+00:27:37,000 --> 00:27:43,000
+Pay attention here we bring to console second level cache hit count.
+
+302
+00:27:43,000 --> 00:27:52,000
+This is global number of cache and that is collections successively retrieved from the cache second
+
+303
+00:27:52,000 --> 00:27:54,000
+level cache misc count.
+
+304
+00:27:54,000 --> 00:28:02,000
+This is global number of cache entities collections not found in the cache and loaded from the database
+
+305
+00:28:02,000 --> 00:28:05,000
+second level cache count.
+
+306
+00:28:05,000 --> 00:28:10,000
+This is global number of catchable entities collections pooled in the cache.
+
+307
+00:28:10,000 --> 00:28:19,000
+So before we load the user from the database, you can see that we had zero value for all these three
+
+308
+00:28:19,000 --> 00:28:21,000
+parameters in our statistics.
+
+309
+00:28:21,000 --> 00:28:29,000
+When we lower that user from the database, we have one MIS because user was a D wasn't in the second
+
+310
+00:28:29,000 --> 00:28:37,000
+level cache and we have one count because now this user is stored in the second level cache to.
+
+311
+00:28:38,000 --> 00:28:45,000
+Example number two, where again road user was the same way and that was statistics is not changed.
+
+312
+00:28:45,000 --> 00:28:46,000
+Why?
+
+313
+00:28:47,000 --> 00:28:54,000
+Because our user currently stored in the first level cache in our session scope cache and user object
+
+314
+00:28:54,000 --> 00:28:57,000
+is extracted from the first level cache.
+
+315
+00:28:58,000 --> 00:29:01,000
+That's why we still have hit count zero.
+
+316
+00:29:02,000 --> 00:29:02,000
+Example.
+
+317
+00:29:02,000 --> 00:29:10,000
+Number three, lets evict the user from the first level cache vividly by calling evict massive.
+
+318
+00:29:10,000 --> 00:29:20,000
+A big massive is also a specific API, the mass that removes this instance from the session cache and
+
+319
+00:29:20,000 --> 00:29:27,000
+after that reload user one more time, do you think it will be loaded from the database and request
+
+320
+00:29:27,000 --> 00:29:29,000
+will be sent to the database?
+
+321
+00:29:29,000 --> 00:29:30,000
+No.
+
+322
+00:29:30,000 --> 00:29:36,000
+That's exactly the moment where second level cache comes into play.
+
+323
+00:29:36,000 --> 00:29:44,000
+This time user will be extracted from the second level cache and will not execute query to the database.
+
+324
+00:29:44,000 --> 00:29:45,000
+Isn't this cool?
+
+325
+00:29:46,000 --> 00:29:54,000
+Just imagine how much requests will not be sent to the database in the scope of the whole application
+
+326
+00:29:54,000 --> 00:29:58,000
+in case we need to retrieve the same user in different threads.
+
+327
+00:29:58,000 --> 00:30:06,000
+Considering the fact that second level cache is a session factory scoped cache and is not connected
+
+328
+00:30:06,000 --> 00:30:12,000
+with the one specific session, we will be able to achieve significant performance optimization.
+
+329
+00:30:13,000 --> 00:30:21,000
+That's why in the third example, we have hit count changed to one that is basically second level cache
+
+330
+00:30:21,000 --> 00:30:22,000
+in action.
+
+331
+00:30:22,000 --> 00:30:23,000
+How do you like it?
+
+332
+00:30:24,000 --> 00:30:31,000
+Even in case you still have some questions regarding the second level cache, please leave your question
+
+333
+00:30:31,000 --> 00:30:35,000
+and comments to the video and I will be happy to answer.
+
+334
+00:30:35,000 --> 00:30:39,000
+Now let's review example with square level cash.
+
+335
+00:30:39,000 --> 00:30:40,000
+I open files.
+
+336
+00:30:40,000 --> 00:30:43,000
+It is called Square Level Cash Demo.
+
+337
+00:30:44,000 --> 00:30:50,000
+This is useful if we frequently execute a query on entities that really change.
+
+338
+00:30:50,000 --> 00:30:56,000
+We already added property to our hybrid configuration to enable query level cache.
+
+339
+00:30:56,000 --> 00:31:03,000
+Now for each query, we just need to call set cache mass and set the value to true.
+
+340
+00:31:04,000 --> 00:31:11,000
+As you can see an example I create query object and call set cache bonus with true argument.
+
+341
+00:31:11,000 --> 00:31:17,000
+In addition to that, we can even specify a cache region like you see in this example.
+
+342
+00:31:18,000 --> 00:31:21,000
+That's how you can use query level cache.
+
+343
+00:31:22,000 --> 00:31:25,000
+That's all for this class and what I wanted to share with you.
+
+344
+00:31:25,000 --> 00:31:29,000
+Let's recap what we have learned in this lesson.
+
+345
+00:31:30,000 --> 00:31:32,000
+Today, we learned what the cache is.
+
+346
+00:31:32,000 --> 00:31:36,000
+We learn the cache structure in Hibernate.
+
+347
+00:31:36,000 --> 00:31:43,000
+After this lesson, you have a clear understanding of what first level cache is, what a second level
+
+348
+00:31:43,000 --> 00:31:50,000
+cache is, and what the query level cache, as we discussed different cache providers and we learned
+
+349
+00:31:51,000 --> 00:31:53,000
+E cash cache provider.
+
+350
+00:31:53,000 --> 00:31:58,000
+You saw a real example how to create custom configuration for E cache.
+
+351
+00:31:59,000 --> 00:32:03,000
+Also today, we learned cache eviction policies.
+
+352
+00:32:03,000 --> 00:32:11,000
+We discussed different persistence strategies in a cache and we received a lot of practical exercises
+
+353
+00:32:12,000 --> 00:32:13,000
+that solve for this lesson.
+
+354
+00:32:14,000 --> 00:32:15,000
+I hope you liked it.
+
+355
+00:32:16,000 --> 00:32:17,000
+Thanks a lot for your attention.
+
+356
+00:32:17,000 --> 00:32:21,000
+Have a great day and see in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/008 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/008 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..58d5108abe5e3c427e2be706ee22b2fe1013b4e3
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/008 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-hibernate/tree/master/src/main/java/com/itbulls/learnit/hibernate/cache
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/009 N+1 Problem and Solution_en.srt b/78 - ORM, JPA & Hibernate/009 N+1 Problem and Solution_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..b2610c805e63a119f0134c090b7ef22e3b807fa2
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/009 N+1 Problem and Solution_en.srt
@@ -0,0 +1,808 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:12,000
+In this lesson, we're going to discuss such popular problems that you can face while working with GPA
+
+3
+00:00:12,000 --> 00:00:19,000
+SE and plus one, we're going to talk about what this problem is all about and why it is important for
+
+4
+00:00:19,000 --> 00:00:21,000
+us to solve this challenge.
+
+5
+00:00:21,000 --> 00:00:27,000
+I'm going to show you different solutions and workarounds to help you understand how we can avoid this
+
+6
+00:00:27,000 --> 00:00:28,000
+issue.
+
+7
+00:00:28,000 --> 00:00:32,000
+We'll have a lot of practical exercises today during the lesson.
+
+8
+00:00:32,000 --> 00:00:34,000
+I will show you the issue in the source code.
+
+9
+00:00:34,000 --> 00:00:40,000
+And after that, we are going to talk about all possible solutions by reviewing code examples.
+
+10
+00:00:40,000 --> 00:00:45,000
+And as always, you can find all code examples in attachments to the lesson.
+
+11
+00:00:45,000 --> 00:00:47,000
+Let's start our lesson.
+
+12
+00:00:48,000 --> 00:00:53,000
+Let's understand first what one problem is by this moment.
+
+13
+00:00:53,000 --> 00:01:00,000
+In our course, you're already familiar with the GPA and you already saw how GPA helps us use development.
+
+14
+00:01:00,000 --> 00:01:05,000
+Also, GPA saves us from writing boilerplate code.
+
+15
+00:01:05,000 --> 00:01:13,000
+It helps us with object relational data mapping, but everything comes with a price and sometimes GPA
+
+16
+00:01:13,000 --> 00:01:15,000
+brings us some challenges.
+
+17
+00:01:15,000 --> 00:01:18,000
+And plus one problem is one of those.
+
+18
+00:01:19,000 --> 00:01:27,000
+And plus one query problem occurs when an oil ramp tool, like, for example, executes one query to
+
+19
+00:01:27,000 --> 00:01:32,000
+retrieve the parent entity and and queries to retrieve the child entities.
+
+20
+00:01:33,000 --> 00:01:40,000
+And all this decreases database performance because a lot of queries are sent to fetch all the required
+
+21
+00:01:40,000 --> 00:01:41,000
+associations.
+
+22
+00:01:41,000 --> 00:01:48,000
+And can you imagine the scale of the challenge in case you have hundreds, thousands of entities across
+
+23
+00:01:48,000 --> 00:01:49,000
+all your application?
+
+24
+00:01:50,000 --> 00:01:55,000
+And to help you understand the challenge better, let me proceed with code examples, because it will
+
+25
+00:01:55,000 --> 00:01:58,000
+be easier for you to understand the challenge.
+
+26
+00:01:59,000 --> 00:02:05,000
+Let's have very simplified example in order to understand the issue and how to resolve it.
+
+27
+00:02:05,000 --> 00:02:09,000
+Imagine that we have online shop and we have entity.
+
+28
+00:02:09,000 --> 00:02:11,000
+Is this called category?
+
+29
+00:02:12,000 --> 00:02:18,000
+Each category has a unique ID category name and is available flag.
+
+30
+00:02:18,000 --> 00:02:25,000
+We use is available flag to select those categories which we want to show in our online shop.
+
+31
+00:02:25,000 --> 00:02:28,000
+In other words, our active categories.
+
+32
+00:02:28,000 --> 00:02:32,000
+Also, each category can have multiple products.
+
+33
+00:02:32,000 --> 00:02:41,000
+The relationships type is one domain, one category can have multiple products and product type and
+
+34
+00:02:41,000 --> 00:02:49,000
+charm has unique ID, product, name and category with as many to one relationships from product entity.
+
+35
+00:02:49,000 --> 00:02:50,000
+That's it.
+
+36
+00:02:51,000 --> 00:02:52,000
+Is this example clear for you?
+
+37
+00:02:53,000 --> 00:02:55,000
+Let me open the demo class now.
+
+38
+00:02:55,000 --> 00:02:58,000
+We created three categories.
+
+39
+00:02:58,000 --> 00:03:02,000
+The category number one is for laptops.
+
+40
+00:03:02,000 --> 00:03:08,000
+The category number two is for TVs, and the category number three is for fridges.
+
+41
+00:03:08,000 --> 00:03:10,000
+Each category has two products.
+
+42
+00:03:10,000 --> 00:03:12,000
+I hope that this is clear.
+
+43
+00:03:13,000 --> 00:03:19,000
+And now imagine in case we need to extract all categories, is it available at the moment?
+
+44
+00:03:19,000 --> 00:03:26,000
+On the side, we need to extract all categories, all rows of categories, and separately we need to
+
+45
+00:03:26,000 --> 00:03:33,000
+extract all related products within those categories because in order to fetch the category items,
+
+46
+00:03:33,000 --> 00:03:38,000
+GP will issue separate queries for each individual category.
+
+47
+00:03:38,000 --> 00:03:46,000
+If, for example, a category has five products, then Jeep will issue five additional queries to fetch
+
+48
+00:03:46,000 --> 00:03:49,000
+the products included in those orders.
+
+49
+00:03:49,000 --> 00:03:58,000
+This is basically known as plus one problem, one query to fetch all and categories and and queries
+
+50
+00:03:58,000 --> 00:04:00,000
+to fetch all products.
+
+51
+00:04:01,000 --> 00:04:04,000
+This behavior creates a scalability problem for us.
+
+52
+00:04:04,000 --> 00:04:12,000
+When our data grows, even a moderate number of categories in products can create significant performance
+
+53
+00:04:12,000 --> 00:04:13,000
+issues.
+
+54
+00:04:13,000 --> 00:04:19,000
+The different implementations suggest us different solutions of this challenge.
+
+55
+00:04:20,000 --> 00:04:21,000
+Let me show you the problem.
+
+56
+00:04:21,000 --> 00:04:28,000
+On example, in my persistence XML configuration, I turned on SQL login.
+
+57
+00:04:28,000 --> 00:04:33,000
+Without login it would be complicated to detect and plus one issue.
+
+58
+00:04:33,000 --> 00:04:38,000
+Let me open the demo file from the problem package and run it.
+
+59
+00:04:39,000 --> 00:04:46,000
+You can see that they use two entity managers in order to submit securities, a database avoiding extracting,
+
+60
+00:04:46,000 --> 00:04:52,000
+and that is from the first level cache to learn what the first level cache is.
+
+61
+00:04:52,000 --> 00:04:53,000
+Place.
+
+62
+00:04:53,000 --> 00:04:56,000
+Watch previous lesson about caching.
+
+63
+00:04:56,000 --> 00:05:05,000
+So I use the first entity manager to persist all entities and I use the second entity manager to load
+
+64
+00:05:05,000 --> 00:05:08,000
+all categories that are available in our online shop.
+
+65
+00:05:09,000 --> 00:05:12,000
+Basically all categories that have is available.
+
+66
+00:05:12,000 --> 00:05:14,000
+Flag set to true.
+
+67
+00:05:15,000 --> 00:05:19,000
+I create type query and I extract result list.
+
+68
+00:05:20,000 --> 00:05:26,000
+After that, I print this log message the console and I print all categories.
+
+69
+00:05:26,000 --> 00:05:29,000
+Let's explore now the console output.
+
+70
+00:05:29,000 --> 00:05:37,000
+You can see that hibernate did select for categories that have is available flag set for true and after
+
+71
+00:05:37,000 --> 00:05:40,000
+that hibernate make two more queries.
+
+72
+00:05:41,000 --> 00:05:44,000
+Basically that is because we have two categories.
+
+73
+00:05:44,000 --> 00:05:52,000
+This flag is available, set the true and after that for each of these categories, hibernate submits
+
+74
+00:05:52,000 --> 00:05:57,000
+separate queries to extract products for those categories.
+
+75
+00:05:57,000 --> 00:06:04,000
+And what would happen in case I have hundreds of categories and thousands of products that understand
+
+76
+00:06:04,000 --> 00:06:06,000
+the scope of potential issue?
+
+77
+00:06:06,000 --> 00:06:14,000
+That is because in our problem statement example, I used IGA fetch type for products in my category
+
+78
+00:06:14,000 --> 00:06:14,000
+entity.
+
+79
+00:06:15,000 --> 00:06:22,000
+In my demo you can see that I extracted all products even before I actually needed those.
+
+80
+00:06:23,000 --> 00:06:28,000
+You can see that select queries to product entity was executed before.
+
+81
+00:06:28,000 --> 00:06:31,000
+I wanted to print categories to console.
+
+82
+00:06:31,000 --> 00:06:34,000
+This can cause performance issues.
+
+83
+00:06:34,000 --> 00:06:37,000
+So what would be the solution?
+
+84
+00:06:37,000 --> 00:06:44,000
+Actually, there are different approaches to consider, first of all, and the general one is to avoid
+
+85
+00:06:44,000 --> 00:06:46,000
+IGA fetching.
+
+86
+00:06:46,000 --> 00:06:50,000
+This is the main reason behind the plus one issue.
+
+87
+00:06:50,000 --> 00:06:54,000
+We should get rid of all IGA fetching from our mapping.
+
+88
+00:06:54,000 --> 00:07:00,000
+They have almost no benefits that justifies the use in the production grade application.
+
+89
+00:07:00,000 --> 00:07:06,000
+We should mark all relationships as lazy and state by default.
+
+90
+00:07:06,000 --> 00:07:07,000
+Fetch type is lazy.
+
+91
+00:07:08,000 --> 00:07:14,000
+So in case you didn't specify fetch type iga vividly, you are not supposed to have an issues.
+
+92
+00:07:15,000 --> 00:07:22,000
+One important point to note more than a relationship mapping is lazy, doesn't guarantee that the underlying
+
+93
+00:07:22,000 --> 00:07:26,000
+persistent provider will also treat it as such.
+
+94
+00:07:27,000 --> 00:07:31,000
+The specification doesn't guarantees a lazy patch.
+
+95
+00:07:31,000 --> 00:07:35,000
+It is a hint to the persistent provider at best.
+
+96
+00:07:36,000 --> 00:07:40,000
+Let me open the demo across from the solution package and run it.
+
+97
+00:07:41,000 --> 00:07:48,000
+This absolutely is the same example, but we use default lazy fetch type for fetch and products for
+
+98
+00:07:48,000 --> 00:07:55,000
+the category and if we would explore console output, you can see that select queries to the product
+
+99
+00:07:55,000 --> 00:08:03,000
+entity has been executed already after I load the category and when I needed those.
+
+100
+00:08:03,000 --> 00:08:11,000
+So basically when I started putting category items into console and they had to have products to show
+
+101
+00:08:11,000 --> 00:08:19,000
+basically when we refer to the products property inside the category, inside the string method only
+
+102
+00:08:19,000 --> 00:08:22,000
+then we executed additional queries to the database.
+
+103
+00:08:22,000 --> 00:08:29,000
+This can help us to increase performance because imagine that you work with categories, not always.
+
+104
+00:08:29,000 --> 00:08:35,000
+You need to work with products of those categories and when you need to work with the products only
+
+105
+00:08:35,000 --> 00:08:39,000
+at that moment you extract the products least that you need.
+
+106
+00:08:40,000 --> 00:08:41,000
+Is it clear.
+
+107
+00:08:41,000 --> 00:08:48,000
+The second thing you have to remember, in order to avoid any plus one issue, never fetch the data
+
+108
+00:08:48,000 --> 00:08:49,000
+that you don't need.
+
+109
+00:08:50,000 --> 00:08:57,000
+For example, in this particular case will fetch categories that are active and we need to work only
+
+110
+00:08:57,000 --> 00:08:58,000
+with the category name.
+
+111
+00:08:59,000 --> 00:09:02,000
+Imagine that you need to publish category names.
+
+112
+00:09:02,000 --> 00:09:04,000
+This is just an example.
+
+113
+00:09:04,000 --> 00:09:11,000
+The volume of information you need may vary, but the main thing here is that in case you don't need
+
+114
+00:09:11,000 --> 00:09:16,000
+all the information about the entity, then do not fetch it.
+
+115
+00:09:16,000 --> 00:09:20,000
+Create a query to fetch on the required and necessary information.
+
+116
+00:09:21,000 --> 00:09:29,000
+I had a case in my practice when I worked with customer entity and each customer had from one to thousand
+
+117
+00:09:29,000 --> 00:09:29,000
+orders.
+
+118
+00:09:29,000 --> 00:09:31,000
+It was B2B solution.
+
+119
+00:09:31,000 --> 00:09:39,000
+So customers had really a lot of orders and in one query application extracted customers and iterated
+
+120
+00:09:39,000 --> 00:09:40,000
+over them.
+
+121
+00:09:40,000 --> 00:09:47,000
+And performance of this end point was really poor because of the amount of additional requests sent
+
+122
+00:09:47,000 --> 00:09:50,000
+to fetch all customer orders.
+
+123
+00:09:50,000 --> 00:09:52,000
+So be careful with this.
+
+124
+00:09:53,000 --> 00:09:54,000
+And that's true.
+
+125
+00:09:54,000 --> 00:10:02,000
+Using next solution we can use during fetch in our queries whenever we need to fetch an entity with
+
+126
+00:10:02,000 --> 00:10:04,000
+all of its children.
+
+127
+00:10:04,000 --> 00:10:08,000
+At the same time, this results in the much less database.
+
+128
+00:10:08,000 --> 00:10:18,000
+Traffic resulted in an improved performance, starting from the GP 2.1 specification introduced entity
+
+129
+00:10:18,000 --> 00:10:23,000
+graphs which allows us to create static dynamic query load plans.
+
+130
+00:10:23,000 --> 00:10:31,000
+Entity graphs provides a way to formulate better performing queries by defining which entities need
+
+131
+00:10:31,000 --> 00:10:34,000
+to be retrieved from the database using SQL joins.
+
+132
+00:10:35,000 --> 00:10:42,000
+The main goal of the entity graph is to improve the runtime performance when loadings, the entities,
+
+133
+00:10:42,000 --> 00:10:45,000
+related associations and basic fields.
+
+134
+00:10:45,000 --> 00:10:48,000
+There are two types of entity graphs.
+
+135
+00:10:48,000 --> 00:10:55,000
+They are fetch and log which defines is the entities not specified by attribute nodes or entity.
+
+136
+00:10:55,000 --> 00:10:59,000
+Graphs should be fetched lazily or eagerly.
+
+137
+00:11:00,000 --> 00:11:06,000
+Attributes specified by attribute nodes of entity graph are always fetched easily.
+
+138
+00:11:06,000 --> 00:11:14,000
+That means together with the load of the parent entity in fetch graph only the specified attributes
+
+139
+00:11:14,000 --> 00:11:18,000
+are retrieved from the database in the load graph.
+
+140
+00:11:18,000 --> 00:11:25,000
+In addition to the specified attributes, attribute statically configured as eager are also retrieved.
+
+141
+00:11:26,000 --> 00:11:31,000
+You specify fetch as you strategy by inputting gearbox persistence.
+
+142
+00:11:31,000 --> 00:11:34,000
+Fetch graph is a file containing the entity.
+
+143
+00:11:35,000 --> 00:11:43,000
+In this case, all attributes specified in your entity graph will be treated as fetch type IGA and all
+
+144
+00:11:43,000 --> 00:11:47,000
+attributes not specified will be treated as fetch type lazy.
+
+145
+00:11:48,000 --> 00:11:55,000
+On the other hand, if you specify load as your strategy by inputting gearbox persistence load graph,
+
+146
+00:11:55,000 --> 00:12:03,000
+then all attributes specified in the entity graph are also fetch type eg, but attributes not specified
+
+147
+00:12:03,000 --> 00:12:08,000
+use the specified type or default if the entity specified nothing.
+
+148
+00:12:09,000 --> 00:12:11,000
+This may sound confusing, but don't worry.
+
+149
+00:12:11,000 --> 00:12:14,000
+I'm going to show you all this an example.
+
+150
+00:12:14,000 --> 00:12:19,000
+Let's learn on example how we can define and work with entity graphs.
+
+151
+00:12:20,000 --> 00:12:23,000
+There are two ways to define entity graphs.
+
+152
+00:12:23,000 --> 00:12:31,000
+The first one is by using named entity graph annotation and the second one without entity graphs but
+
+153
+00:12:31,000 --> 00:12:32,000
+create an entity.
+
+154
+00:12:32,000 --> 00:12:36,000
+Graphs from our entity managers using attribute nodes.
+
+155
+00:12:37,000 --> 00:12:39,000
+Let's learn these two ways on example.
+
+156
+00:12:40,000 --> 00:12:48,000
+According to the first way we need to open our entity and add annotations there to use a named entity
+
+157
+00:12:48,000 --> 00:12:55,000
+graph first and update the entity class category with GPUs named entity graph annotation.
+
+158
+00:12:55,000 --> 00:12:59,000
+In the example, you can see that I gave the name to the entity graph.
+
+159
+00:12:59,000 --> 00:13:06,000
+I'm going to use this name in the example and then as a property it is called attribute nodes.
+
+160
+00:13:06,000 --> 00:13:12,000
+I add name attribute node was the name of my property that I'd like to fetch.
+
+161
+00:13:12,000 --> 00:13:16,000
+The gas was a parent entity with the help of joint statements.
+
+162
+00:13:17,000 --> 00:13:24,000
+In case we want to use named entity graphs without using annotations, we can create those programmatically.
+
+163
+00:13:24,000 --> 00:13:27,000
+I'm going to show you this in the demo class.
+
+164
+00:13:27,000 --> 00:13:30,000
+Now let me open a demo class.
+
+165
+00:13:31,000 --> 00:13:38,000
+This is a similar example that you already saw, but with the entity graph, pay attention to these
+
+166
+00:13:38,000 --> 00:13:39,000
+lines of code.
+
+167
+00:13:39,000 --> 00:13:42,000
+Here I create entity graph object.
+
+168
+00:13:43,000 --> 00:13:51,000
+I call that entity graph method on the entity manager object and I pause the name of our entity graph.
+
+169
+00:13:51,000 --> 00:13:57,000
+In case you don't want to use annotations, you can create an entity graph programmatically.
+
+170
+00:13:57,000 --> 00:14:05,000
+Just call not yet entity graph method but called create entity graph method and parse the type for which
+
+171
+00:14:05,000 --> 00:14:07,000
+you want to create entity graph.
+
+172
+00:14:07,000 --> 00:14:12,000
+After creation of entity graph, you have to add attribute nodes.
+
+173
+00:14:12,000 --> 00:14:19,000
+And again, we already did this with annotations, but you can add them programmatically here by calling
+
+174
+00:14:19,000 --> 00:14:21,000
+add attribute nodes massive.
+
+175
+00:14:21,000 --> 00:14:25,000
+It is up to you which way of creation of entity graph to choose.
+
+176
+00:14:26,000 --> 00:14:31,000
+Now on the query object I called Nasser said hand.
+
+177
+00:14:31,000 --> 00:14:36,000
+I call this method to pass my entity graph as a value result.
+
+178
+00:14:36,000 --> 00:14:40,000
+This hand will fetch products only when it will be needed.
+
+179
+00:14:41,000 --> 00:14:49,000
+In this example, we'll use products only when will print products to console, but with this hand will
+
+180
+00:14:49,000 --> 00:14:58,000
+force our GPU implementation to create joint statements and to fetch products in one single query.
+
+181
+00:14:58,000 --> 00:15:06,000
+So in case we would execute this example, we're going to see how products were extracted in scope of
+
+182
+00:15:06,000 --> 00:15:10,000
+the one SQL query with the help of joint statement.
+
+183
+00:15:10,000 --> 00:15:18,000
+So let's make a summary of how you can avoid and plus one issue, because we have discussed different
+
+184
+00:15:18,000 --> 00:15:19,000
+options.
+
+185
+00:15:19,000 --> 00:15:20,000
+Let's recap those.
+
+186
+00:15:21,000 --> 00:15:28,000
+The first thing that we can do to avoid endless one issue is to avoid each type and to use laissez faire
+
+187
+00:15:28,000 --> 00:15:29,000
+each type.
+
+188
+00:15:30,000 --> 00:15:35,000
+The second thing that we can do is to fetch only the data that we need.
+
+189
+00:15:35,000 --> 00:15:42,000
+If we don't need the whole information about our entity to perform operation, then let's not fetch
+
+190
+00:15:42,000 --> 00:15:43,000
+all the data.
+
+191
+00:15:43,000 --> 00:15:44,000
+Everything is simple.
+
+192
+00:15:45,000 --> 00:15:51,000
+And the last, but not the least thing to remember to use joins was the help of entity graphs.
+
+193
+00:15:52,000 --> 00:15:54,000
+That's so what I wanted to say in this lesson.
+
+194
+00:15:55,000 --> 00:15:58,000
+Let's recap what we have learned today.
+
+195
+00:15:59,000 --> 00:16:02,000
+Today we learned what an impasse one problem is.
+
+196
+00:16:02,000 --> 00:16:09,000
+I believe you understood why it is important to avoid and how it can impact performance of our application.
+
+197
+00:16:10,000 --> 00:16:15,000
+We reviewed and plus one problem solutions where you have two different ones.
+
+198
+00:16:15,000 --> 00:16:22,000
+Today we learned new concept of entity graphs and how to work with them, and we reviewed a lot of different
+
+199
+00:16:22,000 --> 00:16:24,000
+practical exercises.
+
+200
+00:16:24,000 --> 00:16:26,000
+That's all for this lesson.
+
+201
+00:16:26,000 --> 00:16:28,000
+Thanks a lot for your attention.
+
+202
+00:16:28,000 --> 00:16:31,000
+Have a great day and see you in the next lesson.
+
diff --git a/78 - ORM, JPA & Hibernate/009 Source-code-of-examples-from-the-lesson.url b/78 - ORM, JPA & Hibernate/009 Source-code-of-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..c0b4f00b1008a6afa195467a4e420f47a5514e2f
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/009 Source-code-of-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/n1
\ No newline at end of file
diff --git a/78 - ORM, JPA & Hibernate/external-links.txt b/78 - ORM, JPA & Hibernate/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..77a8606331ddd842eabd941fb3be72099f82d5b8
--- /dev/null
+++ b/78 - ORM, JPA & Hibernate/external-links.txt
@@ -0,0 +1,24 @@
+
+002 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
+
+003 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities
+
+004 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/lifecycle
+
+005 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/locking
+
+006 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/entities/mapping
+
+007 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/queries
+
+008 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-hibernate/tree/master/src/main/java/com/itbulls/learnit/hibernate/cache
+
+009 Source-code-of-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-jpa/tree/master/src/main/java/com/itbulls/learnit/jpa/n1
diff --git a/79 - ===== ORM & JPA Interview Preparation =====/001 Part 1 ORM & Hibernate Interview - Questions and Answers.html b/79 - ===== ORM & JPA Interview Preparation =====/001 Part 1 ORM & Hibernate Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..4cee23643ca92de86ca89a74a5db915b3a420a09
--- /dev/null
+++ b/79 - ===== ORM & JPA Interview Preparation =====/001 Part 1 ORM & Hibernate Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 1 ORM & Hibernate Interview - Questions and Answers
+
+
+
+
+
+
+
Part 1 ORM & Hibernate Interview - Questions and Answers
+
ORM (Object-relational mapping) - programming technology, which links databases to the concepts of object-oriented programming languages, creating a "virtual object database".
It is a framework for object-relational mapping of entities to a traditional relational database.
The main features of the framework:
Automatic generation and updating of tables in databases;
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;
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).
Some of them:
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.
Supports XML as well as JPA annotations, which allows you to make the implementation of the code independent.
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).
Hibernate integrates easily with other Java EE frameworks, for example the Spring Framework supports built-in integration with Hibernate.
Supports lazy initialization using proxy objects and queries the database only when needed.
Supports different levels of cache, and therefore can improve performance.
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.
Hibernate is an open source project. Thanks to this, thousands of open articles, examples, as well as documentation on using the framework are available.
Hibernate implements a number of features that greatly simplify the developer's work.
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).
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.
It generates tables in the database
Hibernate has a number of advantages over the JDBC API:
Hibernate removes a lot of repetitive code from the JDBC API and is therefore easier to read, write and maintain.
Hibernate supports inheritance, associations, and collections, which is not available in the JDBC API.
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.
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.
Hibernate Query Language (HQL) is a more object-oriented and Java-like programming language than SQL in JDBC.
Hibernate supports caching, but JDBC queries do not, which can degrade performance.
Hibernate provides the ability to manipulate the database (such as creating tables), while JDBC can only work with existing tables in the database.
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.
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.
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.
There are four ways to configure how Hibernate works:
using annotations;
hibernate.cfg.xml
hibernate.properties;
persistence.xml.
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.
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.
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.
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).
Factory for Transaction instances. The interface is not open to the application, but can be extended or implemented by the developer.
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.
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.
There are following fetch types:
Join fetching: hibernate fetches associated objects and collections in one SELECT using OUTER JOIN
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
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.
Batch fetching: Optimized select fetching view strategy. Gets a group of entities or collections in a single SELECT.
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.
identity - generates an identifier of type long, short, or int. Supported in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL.
sequence - uses sequences in DB2, PostgreSQL, Oracle, SAP DB, McKoi, or the Interbase generator. Returns an identifier of type long, short, or int.
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.
seqhilo - Uses the hi/lo algorithm to generate long, short, or int type identifiers given a database sequence.
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.
guid - uses a DB generated GUID string in MS SQL Server and MySQL.
native - uses identity, sequence or hilo depending on the type of database the application works with
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.
select - Gets the primary key assigned by the database trigger
foreign - uses the identifier of another object associated with the given object. Used in <one-to-one> primary key associations.
sequence-identity is a specialized identifier generator.
There are five key interfaces that are used in every Hibernate related application:
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:
javax.persistence.Entity: used to specify a class as an entity bean.
javax.persistence.Table: used to define the name of the table from the database that will be mapped to the entity bean.
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.
javax.persistence.Id: defines the primary key in the entity bean.
javax.persistence.EmbeddedId: used to define an embedded key in a bean.
javax.persistence.Column: Specifies the name of a column from a table in the database.
javax.persistence.GeneratedValue: Specifies the strategy for generating primary keys. Used in conjunction with javax.persistence.GenerationType enum.
javax.persistence.OneToOne: Specifies a one-to-one relationship between two entity beans. Accordingly, there are other OneToMany, ManyToOne and ManyToMany annotations.
org.hibernate.annotations.Cascade: Defines a cascading relationship between two entity beans. Used in conjunction with org.hibernate.annotations.CascadeType.
javax.persistence.PrimaryKeyJoinColumn: Specifies the foreign key for the property. Used in conjunction with org.hibernate.annotations.GenericGenerator and org.hibernate.annotations.Parameter.
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.
Role of the Session interface:
is a wrapper for JDBC database connection;
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).
is the keeper of the mandatory first-level cache.
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.
Because the SessionFactory object is immutable (immutable), then yes, it is thread-safe. Multiple threads can access the same object at the same time.
Hibernate SessionFactory getCurrentSession() 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.
The Hibernate SessionFactory openSession() method always creates a new session. We must ensure that the session object is closed when all database operations are completed.
For a multi-threaded environment, a new session object must be created for each request.
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.
Hibernate uses 2 types of cache: first level cache and second level cache.
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.
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.
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.
OSCache is another opensource cache implementation. In addition to everything that EHCache supports, this implementation also supports clustering via JavaGroups or JMS.
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.
JBoss TreeCache - Provides a complete transaction cache.
Read-only: This strategy is used when data is being read but never updated. The simplest and most productive strategy
Read/write: can be used when the data needs to be updated.
Non-strict read/write: This strategy does not guarantee that two transactions do not modify the same data synchronously.
Transactional: full transaction caching. Only available in JTA environment.
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.
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.
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.
+
+
+
+
diff --git a/79 - ===== ORM & JPA Interview Preparation =====/002 Part 2 ORM & Hibernate Interview - Questions and Answers.html b/79 - ===== ORM & JPA Interview Preparation =====/002 Part 2 ORM & Hibernate Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..3223e54313fedf1660122e200cc9719ca1c88197
--- /dev/null
+++ b/79 - ===== ORM & JPA Interview Preparation =====/002 Part 2 ORM & Hibernate Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 2 ORM & Hibernate Interview - Questions and Answers
+
+
+
+
+
+
+
Part 2 ORM & Hibernate Interview - Questions and Answers
+
To specify a second level cache you need to define hibernate.cache.provider_class in hibernate.cfg.xml.
The default is EHCache.
To use the query cache, you need to enable it by setting the hibernate.cache.use_query_cache property to true in hibernate.properties.
Hibernate session has various methods for loading data from the database. Most often
the methods used for this are get() and load().
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.
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.
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.
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.
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.
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.
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.
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.
Hibernate persist() is similar to save() with a transaction. persist() doesn't return the generated ID right away.
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.
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.
Simple example:
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.
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.
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.
There are several ways to implement relationships in Hibernate.
Use associations such as one-to-one, one-to-many, many-to-many.
Use JOIN command in HQL query. There is another form of "join fetch" that allows data to be loaded immediately (not lazy).
Use pure SQL query with join command.
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.
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.
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).
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.
And after that, already inside the application code, the setCacheable(true) method is used for the request.
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).
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.
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.
The Hibernate named query allows you to collect many queries in one place and then call them in any class.
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.
Named Query are global, i.e. given once, can be used anywhere.
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).
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.
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.
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.
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).
The most commonly used CascadeType enums are described below.
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.
ALL: Cascades save, delete, update, evict, lock, replicate, merge, persist. Well, that's all.
SAVE_UPDATE: Cascades save and update. Only available for hibernate.
DELETE: Passes an action to Hibernate's native DELETE. For hibernate only.
DETATCH, MERGE, PERSIST, REFRESH and REMOVE are for simple operations.
LOCK: Passes an action to Hibernate's native LOCK.
REPLICATE: Passes an action to Hibernate's native REPLICATE.
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.
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.
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:
transient - never saved, not associated with any session;
persistent - associated with a unique session;
detached - previously saved, not associated with the session.
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.
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.
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.
Add dependencies for hibernate-entitymanager, hibernate-core and spring-orm.
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.
Set up the Spring configuration file (look in the offline documentation or from the example on this site).
Additionally, it becomes possible to use the @Transactional annotation and stop worrying about Hibernate transaction management.
Domain Model Pattern - An object model of a domain that includes both behavior and data.
Data Mapper is a Mappers layer that transfers data between objects and the database, keeping them independent of each other and themselves.
Proxy Pattern - used for lazy loading.
Factory pattern - used in SessionFactory
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.
+
+
+
+
diff --git a/79 - ===== ORM & JPA Interview Preparation =====/003 Part 3 JPA Interview - Questions and Answers.html b/79 - ===== ORM & JPA Interview Preparation =====/003 Part 3 JPA Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..7d6b4bd2e66445ea6b6a3bbf886d83ab5fa2af57
--- /dev/null
+++ b/79 - ===== ORM & JPA Interview Preparation =====/003 Part 3 JPA Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 3 JPA Interview - Questions and Answers
+
+
+
+
+
+
+
Part 3 JPA Interview - Questions and Answers
+
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.
JPA is a specification (a document approved as a standard that describes all aspects of the technology), part of the EJB3 specification.
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.
JPA implementations:
Hibernate
Oracle TopLink
Apache Open JPA
Eclipselink
JPA consists of three main points:
APIs are the interfaces in the javax(jakarta).persistance package. A set of interfaces that allow you to organize interaction with an ORM provider.
JPQL is an object query language. Very similar to SQL, but queries are performed on objects.
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.
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).
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.
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.
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.
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.
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).
The Criteria API is also a query language similar to JPQL (Java Persistence query language), but queries are based on methods and objects.
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.
Yes, it can.
Yes, it can.
Yes, it can be. Being abstract class it retains all the properties of the Entity, except that it can't be directly initialized.
Yes, it can.
An Entity class must be annotated with the Entity annotation or described in a JPA configuration XML file.
The Entity class must contain a public or protected constructor with no arguments (it can also have constructors with arguments).
Entity class must be a top-level class.
Entity class cannot be enum or interface.
Entity class cannot be final class.
Entity class cannot contain final fields or methods if they are involved in mapping (persistent final methods or persistent final instance variables).
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.
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).
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.
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.
Valid attribute types for Entity classes:
primitive types and their Java wrappers,
String,
any serializable Java types (implementing the Serializable interface),
enums;
entity types;
embeddable classes
and collections of specific types
Valid attribute types included in the primary key:
primitive types and their Java wrappers,
String,
BigDecimal and BigInteger
java.util.Date and java.sql.Date,
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.
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.
Yes, it can.
It can, but only if such a class is not used as a primary key or map key.
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
2. The Embeddable class must be marked with the Embeddable annotation or described in the JPA configuration XML file.
There are four types of links
OneToOne (one-to-one relationship, that is, one Entity object can be associated with no more than one object of another Entity ),
OneToMany (one-to-many relationship, one Entity object can be related to a whole collection of other Entities),
ManyToOne (many-to-one relationship, it is an opposite to OneToMany),
ManyToMany (many-to-many relationship).
Each of which can be further divided into two types:
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).
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.
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.
JPA describes two types of fetch strategy:
LAZY - field data will be loaded only during the first access to this field,
EAGER - field data will be loaded immediately.
JPA describes three Inheritance Mapping Strategies, that is, how JPA will work with Entity derived classes:
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.
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.
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.
+
+
+
+
diff --git a/79 - ===== ORM & JPA Interview Preparation =====/004 Part 4 JPA Interview - Questions and Answers.html b/79 - ===== ORM & JPA Interview Preparation =====/004 Part 4 JPA Interview - Questions and Answers.html
new file mode 100644
index 0000000000000000000000000000000000000000..6f5150a2246154101d9c0b0c98ec1d548f423ce2
--- /dev/null
+++ b/79 - ===== ORM & JPA Interview Preparation =====/004 Part 4 JPA Interview - Questions and Answers.html
@@ -0,0 +1,69 @@
+
+
+
+
+
+ Part 4 JPA Interview - Questions and Answers
+
+
+
+
+
+
+
Part 4 JPA Interview - Questions and Answers
+
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:
For operations on Entity: persist (adding an Entity under JPA control), merge, remove, refresh, detach, lock,
Getting data: find (search and get Entity), createQuery, createNamedQuery, createNativeQuery, contains, createNamedStoredProcedureQuery, createStoredProcedureQuery
Getting other JPA entities: getTransaction, getEntityManagerFactory, getCriteriaBuilder, getMetamodel, getDelegate
Working with EntityGraph: createEntityGraph, getEntityGraph
General operations on EntityManager or all Entities: close, isOpen, getProperties, setProperty, clear.
An Entity object has four lifecycle statuses: new, managed, detached, or removed. Their description
new - the object has been created, but it does not yet have generated primary keys and has not yet been stored in the database,
managed - object created, managed by JPA, has generated primary keys
detached - the object has been created but is not managed (or no longer managed) by JPA,
removed - the object has been created, managed by JPA, but will be deleted after the transaction is committed.
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,
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,
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,
4. If the status is removed, an exception will be thrown immediately or at the commit stage of the transaction.
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,
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),
3. If the status is removed, then the operation is ignored,
4. If the status is detached, an exception will be thrown immediately or at the commit stage of the transaction.
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,
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,
3. If the status is removed, then it changes to managed,
4. If the status is detached, an exception will be thrown immediately or at the commit stage of the transaction.
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,
2. If the status is new, removed or detached, an exception will be thrown.
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.
2. If the status is new or detached, then the operation is ignored.
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.
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.
There are four annotations for such an overlay:
AttributeOverride to override fields, properties and primary keys,
AttributeOverrides can similarly override fields, properties, and primary keys with multiple values,
AssociationOverride to override entity relationships,
AssociationOverrides to override multiple relationships.
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)?
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.
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.
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.)?
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.
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):
PrePersist
PostPersist
PreRemove
PostRemove
PreUpdate
PostUpdate
PostLoad
This is what the Transient annotation is for.
The annotation OrderBy and OrderColumn is used for this.
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):
NONE - no blocking
OPTIMISTIC (or READ synonym left over from JPA 1) - optimistic locking
OPTIMISTIC_FORCE_INCREMENT (or a synonym for WRITE, left over from JPA 1) - optimistic locking with forced versioning field increment
PESSIMISTIC_READ - pessimistic read lock
PESSIMISTIC_WRITE - pessimistic write (and read) lock
PESSIMISTIC_FORCE_INCREMENT - pessimistic write (and read) lock with forced version field increment.
JPA talks about two kinds of caches (cache):
first-level cache (first-level cache) - caches the data of one transaction,
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.
JPA talks about five shared-cache-mode values from persistence.xml which define how the second-level cache will be used:
ALL - all Entities can be cached in the second level cache
NONE - caching is disabled for all Entities
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
DISABLE_SELECTIVE - caching works for all Entities, except for those with the Cacheable(false) annotation or its xml equivalent set
UNSPECIFIED - caching is not defined, each JPA provider uses its own default for caching
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?
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:
javax.persistence.fetchgraph - all attributes listed in EntityGraph change fetchType to EAGER, all others to LAZY
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.
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.
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.
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,
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) )
Unlike JPA, Hibernate has a unique inheritance strategy called implicit polymorphism.
+
+
+
+
diff --git a/80 - ===== EXAM TASK JPA & Hibernate =====/001 ===== EXAM TASK JPA & Hibernate =====_en.srt b/80 - ===== EXAM TASK JPA & Hibernate =====/001 ===== EXAM TASK JPA & Hibernate =====_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..9f0a979b89d329991a7297e724b54cb9da796b2d
--- /dev/null
+++ b/80 - ===== EXAM TASK JPA & Hibernate =====/001 ===== EXAM TASK JPA & Hibernate =====_en.srt
@@ -0,0 +1,964 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:14,000
+We have learned a lot about Chip and Kimberly already by this moment, and now it is time to check your
+
+3
+00:00:14,000 --> 00:00:16,000
+skills in real ecommerce project.
+
+4
+00:00:17,000 --> 00:00:24,000
+I prepared special tasks for you that will help you to check and sharpen your skills.
+
+5
+00:00:24,000 --> 00:00:29,000
+You can find the reference to the tasks description in attachments to the video.
+
+6
+00:00:30,000 --> 00:00:36,000
+So the first thing that I recommend you to do is to download this example from the GitHub.
+
+7
+00:00:37,000 --> 00:00:43,000
+This is the online shop application that we did together with my students from scratch in my course
+
+8
+00:00:43,000 --> 00:00:45,000
+Java from zero to first job.
+
+9
+00:00:46,000 --> 00:00:54,000
+It is implemented with pure DBC and we are going to improve it in order to use GP and hibernate in step.
+
+10
+00:00:55,000 --> 00:01:01,000
+Just in case I left here as a reference to the database expert, you know that you could configure your
+
+11
+00:01:01,000 --> 00:01:08,000
+database locally to deploy the application and also you can find the reference to the place in the code
+
+12
+00:01:09,000 --> 00:01:12,000
+where we hardcoded configuration for the database.
+
+13
+00:01:12,000 --> 00:01:17,000
+Feel free to update it to in order to make your application work smoothly.
+
+14
+00:01:17,000 --> 00:01:24,000
+And when you deploy the application locally and you make sure that everything works and you can run
+
+15
+00:01:24,000 --> 00:01:32,000
+the application, you have just one simple task to do make the application works with GP and hibernate
+
+16
+00:01:32,000 --> 00:01:33,000
+instead of DBC.
+
+17
+00:01:34,000 --> 00:01:41,000
+As you can see, we have modular structure in our project, so to deal with this home task you need
+
+18
+00:01:41,000 --> 00:01:46,000
+to adjust only persistence module without impacting the modules.
+
+19
+00:01:47,000 --> 00:01:50,000
+Take your time sync about the solution.
+
+20
+00:01:50,000 --> 00:01:51,000
+Create your own solution.
+
+21
+00:01:51,000 --> 00:01:59,000
+First, you can put on pause this video and once you are done with your solution, let's compare your
+
+22
+00:01:59,000 --> 00:02:01,000
+solution with mine.
+
+23
+00:02:01,000 --> 00:02:07,000
+I'm going to walk you through my solution and give comments as we'll go over it.
+
+24
+00:02:07,000 --> 00:02:09,000
+Let's start with you.
+
+25
+00:02:10,000 --> 00:02:18,000
+First of all, we need to add a GPA configuration file and you can find it here in the SLC main resources
+
+26
+00:02:18,000 --> 00:02:19,000
+folder.
+
+27
+00:02:19,000 --> 00:02:26,000
+I didn't change a lot of configurations here compared to what we learned during the course.
+
+28
+00:02:26,000 --> 00:02:33,000
+I changed here schema and also I added C three pure connection properties here.
+
+29
+00:02:34,000 --> 00:02:35,000
+Here they are.
+
+30
+00:02:35,000 --> 00:02:40,000
+So we already had connection to implement in our solution.
+
+31
+00:02:40,000 --> 00:02:48,000
+And in case we introduce GP and hibernate, we have to be sure that our solution will not lose in performance.
+
+32
+00:02:48,000 --> 00:02:55,000
+If you don't know what the connection is and why do I recommend you to watch the lesson about an action
+
+33
+00:02:55,000 --> 00:02:58,000
+pool in my course java from zero to first job?
+
+34
+00:02:59,000 --> 00:03:06,000
+In that lesson we have learned different connection libraries and I explained all the benefits of having
+
+35
+00:03:07,000 --> 00:03:09,000
+connection with examples.
+
+36
+00:03:09,000 --> 00:03:13,000
+Let me elaborate on C sweeper properties that I put here.
+
+37
+00:03:14,000 --> 00:03:24,000
+Mean size minimum number of GDC connections in the pool hibernate default is one max source maximum
+
+38
+00:03:24,000 --> 00:03:27,000
+number of GB C connections in the pool.
+
+39
+00:03:27,000 --> 00:03:37,000
+Hebrew default is 100 timeout when an idle connection is removed from the pool in seconds hibernate
+
+40
+00:03:37,000 --> 00:03:42,000
+default is zero never x bar max statements.
+
+41
+00:03:42,000 --> 00:03:51,000
+Number of prepared statements will be cached increased performance hibernate default is zero caching
+
+42
+00:03:51,000 --> 00:03:59,000
+is disabled idle test zero idle time and seconds before connection is automatically validated.
+
+43
+00:04:00,000 --> 00:04:02,000
+Hibernate default is zero.
+
+44
+00:04:03,000 --> 00:04:07,000
+Obviously we need to add new and required dependencies.
+
+45
+00:04:07,000 --> 00:04:14,000
+Our Jakarta persistence API hibernate itself and dependency for the Hibernate Connection pool.
+
+46
+00:04:15,000 --> 00:04:23,000
+So I made the required updates in the home XML file to what do we have to do next?
+
+47
+00:04:24,000 --> 00:04:27,000
+Now we need to configure our models.
+
+48
+00:04:27,000 --> 00:04:34,000
+Let's mark them with the entity annotations and make sure that we gave name to the columns.
+
+49
+00:04:34,000 --> 00:04:37,000
+According to the SQL Naming Convention.
+
+50
+00:04:37,000 --> 00:04:45,000
+During the implementation of this exam task and this online shop, we have learned a lot with students,
+
+51
+00:04:45,000 --> 00:04:49,000
+including the NBC Dolly Parton duo.
+
+52
+00:04:50,000 --> 00:04:57,000
+So in case you missed lessons from my course go from zero to first job, some terminology may sound
+
+53
+00:04:57,000 --> 00:05:00,000
+strange and a little bit confusing to you.
+
+54
+00:05:01,000 --> 00:05:07,000
+Feel free to watch the lessons about web application architecture in my course Java from zero to first
+
+55
+00:05:07,000 --> 00:05:07,000
+job.
+
+56
+00:05:08,000 --> 00:05:10,000
+At the meantime, we proceed.
+
+57
+00:05:11,000 --> 00:05:16,000
+All data models in our application are stored in the digital package.
+
+58
+00:05:16,000 --> 00:05:18,000
+Let's review our entities here.
+
+59
+00:05:19,000 --> 00:05:23,000
+I actually didn't change anything in the code itself.
+
+60
+00:05:24,000 --> 00:05:27,000
+I just put annotations on top of the classes and fields.
+
+61
+00:05:28,000 --> 00:05:31,000
+For example, in category detail.
+
+62
+00:05:31,000 --> 00:05:33,000
+There is nothing special.
+
+63
+00:05:33,000 --> 00:05:41,000
+Just entity annotation, ID generated value and column annotations in the product detail.
+
+64
+00:05:41,000 --> 00:05:45,000
+You can also find similar annotations and configuration.
+
+65
+00:05:45,000 --> 00:05:53,000
+In addition to those you can see many one relationship with category detail because many products may
+
+66
+00:05:53,000 --> 00:05:54,000
+belong to one category.
+
+67
+00:05:55,000 --> 00:05:58,000
+That's why we have managed to one here.
+
+68
+00:05:59,000 --> 00:06:01,000
+Is a purchase detail.
+
+69
+00:06:01,000 --> 00:06:10,000
+You can find many to one relationship with user entity because many purchases can be done by one user.
+
+70
+00:06:10,000 --> 00:06:18,000
+Many, many relationships between purchase and products, because each purchase can contain many products
+
+71
+00:06:19,000 --> 00:06:22,000
+and each product can be part of many purchases.
+
+72
+00:06:23,000 --> 00:06:29,000
+For many, too many relationships, we need to have this third table and I configured here the search
+
+73
+00:06:29,000 --> 00:06:32,000
+table and mapping columns.
+
+74
+00:06:32,000 --> 00:06:41,000
+Also, we have many to one relationship with purchase status because many purchases can share the same
+
+75
+00:06:41,000 --> 00:06:41,000
+status.
+
+76
+00:06:42,000 --> 00:06:44,000
+Another important thing here.
+
+77
+00:06:44,000 --> 00:06:47,000
+You can see how I can figure it.
+
+78
+00:06:47,000 --> 00:06:55,000
+Timestamp field to be populated automatically when the record is inserted into the database is searchable.
+
+79
+00:06:55,000 --> 00:07:02,000
+Property tells us what a field is going to be part of auto generated insert statement we set this one
+
+80
+00:07:02,000 --> 00:07:10,000
+to false updatable attribute tells us whether the field is going to be a part of an update statement.
+
+81
+00:07:10,000 --> 00:07:18,000
+And again, we don't need this because we would like to create timestamp value only once during the
+
+82
+00:07:18,000 --> 00:07:22,000
+record insertion on the side of the database.
+
+83
+00:07:23,000 --> 00:07:26,000
+The next attribute here is column definition.
+
+84
+00:07:27,000 --> 00:07:33,000
+It is the SQL fragment that they used when generating DDL for the column to run more.
+
+85
+00:07:33,000 --> 00:07:42,000
+What the deal is, please refer to my lessons about SQL in the SQL course or in the course java from
+
+86
+00:07:42,000 --> 00:07:43,000
+zero to first job.
+
+87
+00:07:44,000 --> 00:07:51,000
+Also, as we discussed in the GPS section of the course, we use temporal annotation to map timestamp
+
+88
+00:07:51,000 --> 00:07:59,000
+in the database with the date data type is program purchase status and it doesn't contain any special
+
+89
+00:07:59,000 --> 00:08:01,000
+or complicated connections.
+
+90
+00:08:02,000 --> 00:08:03,000
+So let's move on.
+
+91
+00:08:04,000 --> 00:08:08,000
+Raw data is also relatively simple entity.
+
+92
+00:08:08,000 --> 00:08:17,000
+User entity has many to one relationship with role and because many users can share the same role.
+
+93
+00:08:17,000 --> 00:08:25,000
+And also there is a relationship with the wrapper user because many users can be referred to the system
+
+94
+00:08:25,000 --> 00:08:27,000
+by the same partner.
+
+95
+00:08:27,000 --> 00:08:33,000
+Together with my students in my course in Java, from zero to first job, we developed this application
+
+96
+00:08:33,000 --> 00:08:41,000
+together and I understand that it can be challenging for you to grasp the logic very quickly.
+
+97
+00:08:41,000 --> 00:08:45,000
+So take your time exploring the existing business logic.
+
+98
+00:08:46,000 --> 00:08:51,000
+Because it was my students, we implemented support of affiliate marketing.
+
+99
+00:08:51,000 --> 00:09:00,000
+Basically each user has partner code and each user can benefit from promoting our online shop by getting
+
+100
+00:09:00,000 --> 00:09:02,000
+percentage from our sales.
+
+101
+00:09:03,000 --> 00:09:06,000
+We are done with a review of our entities.
+
+102
+00:09:06,000 --> 00:09:09,000
+That's all updates that we did in our entities.
+
+103
+00:09:09,000 --> 00:09:10,000
+Let's move on.
+
+104
+00:09:11,000 --> 00:09:18,000
+The next thing that we need to do is to create DAO implementations that would respect the persistence
+
+105
+00:09:18,000 --> 00:09:22,000
+API and would use it during the interaction with the database.
+
+106
+00:09:22,000 --> 00:09:29,000
+And here's the benefit of our architecture and design that we have learned with my students in the course
+
+107
+00:09:29,000 --> 00:09:31,000
+Java from zero to job.
+
+108
+00:09:31,000 --> 00:09:39,000
+The huge advantage of this architecture is that I don't need to change existing interfaces or OSM modules,
+
+109
+00:09:39,000 --> 00:09:44,000
+I just have to implement the interfaces and that's it.
+
+110
+00:09:44,000 --> 00:09:46,000
+The rest code will work as it worked.
+
+111
+00:09:47,000 --> 00:09:55,000
+I just need to meet the contract of existing interfaces and I'm done with the integration of the hibernate
+
+112
+00:09:55,000 --> 00:09:56,000
+into our application.
+
+113
+00:09:57,000 --> 00:10:04,000
+In my now input packages you can see that we have a lot of my SQL GDC implementations.
+
+114
+00:10:05,000 --> 00:10:13,000
+Basically, we just need to introduce the new implementations of the interface and to inject new implementations
+
+115
+00:10:13,000 --> 00:10:17,000
+in the places where we use the objects.
+
+116
+00:10:17,000 --> 00:10:19,000
+Let's go step by step.
+
+117
+00:10:20,000 --> 00:10:24,000
+I have implemented different GP implementations here.
+
+118
+00:10:24,000 --> 00:10:26,000
+Let me walk you through them.
+
+119
+00:10:27,000 --> 00:10:30,000
+The first one in our list is GP category down.
+
+120
+00:10:31,000 --> 00:10:34,000
+To be honest, there is nothing super interesting here.
+
+121
+00:10:35,000 --> 00:10:43,000
+Everything we have learned during the lessons simple font operation by the infection of all categories.
+
+122
+00:10:44,000 --> 00:10:52,000
+A similar thing with the GP roll down not so much masses to implement and all of them are pretty standard
+
+123
+00:10:52,000 --> 00:10:53,000
+ones.
+
+124
+00:10:53,000 --> 00:11:01,000
+The next one is product down and in case you did this home task by yourself, I bet you spent a lot
+
+125
+00:11:01,000 --> 00:11:09,000
+of time on this down and on the purchase down to because usually when we reviews this task with my offline
+
+126
+00:11:09,000 --> 00:11:17,000
+students, these two down implementations are the most complex one, especially the piece where we perform
+
+127
+00:11:17,000 --> 00:11:18,000
+search.
+
+128
+00:11:19,000 --> 00:11:27,000
+You're in the course review different ways of how we can create GP queries and it is only up to you
+
+129
+00:11:27,000 --> 00:11:30,000
+to decide which option you would like to choose.
+
+130
+00:11:31,000 --> 00:11:37,000
+You can solve this task with the GPC criteria API or native query.
+
+131
+00:11:38,000 --> 00:11:45,000
+Actually during the implementation I tried different approaches, but still I decided to leave the example
+
+132
+00:11:45,000 --> 00:11:46,000
+with native code.
+
+133
+00:11:47,000 --> 00:11:56,000
+My opinion it is more readable, simple and clear because your code has to be clean and clear and be
+
+134
+00:11:56,000 --> 00:11:57,000
+easy to support.
+
+135
+00:11:58,000 --> 00:12:05,000
+If you notice the specifics of the implementation, we need also to implement the pagination support
+
+136
+00:12:05,000 --> 00:12:16,000
+and again you can use GP API here, namely query type has the following methods set first result sets
+
+137
+00:12:16,000 --> 00:12:26,000
+the offset position in the result set to start pagination set max results sets the maximum number of
+
+138
+00:12:26,000 --> 00:12:33,000
+entities that should be included in the page so you can use this mass instead of limit.
+
+139
+00:12:33,000 --> 00:12:41,000
+Operator Whatever you like the most, all options are fine, but still in the case of complex queries.
+
+140
+00:12:41,000 --> 00:12:45,000
+Personally, I prefer to use native queries.
+
+141
+00:12:45,000 --> 00:12:53,000
+For example, you can see that I use upper function here to make sure this search will work case independently
+
+142
+00:12:53,000 --> 00:12:55,000
+and again like a set.
+
+143
+00:12:55,000 --> 00:12:58,000
+There are different ways of how to solve this.
+
+144
+00:12:59,000 --> 00:13:04,000
+You can purchase down during the implementation of get not completed purchases.
+
+145
+00:13:04,000 --> 00:13:11,000
+Probably you faced with the exception that tells you that the products can be fetched because there
+
+146
+00:13:11,000 --> 00:13:12,000
+is no session.
+
+147
+00:13:12,000 --> 00:13:18,000
+And indeed, in case you would investigate the stack trace of the potential error.
+
+148
+00:13:18,000 --> 00:13:23,000
+You would find that sometimes in the application we get a massive.
+
+149
+00:13:24,000 --> 00:13:29,000
+For example, get product details mass outside of the transaction.
+
+150
+00:13:29,000 --> 00:13:34,000
+And apparently there is no session to establish the connection to the database.
+
+151
+00:13:34,000 --> 00:13:38,000
+There are different ways of how to resolve this.
+
+152
+00:13:38,000 --> 00:13:44,000
+First of all, you can use eagle fetch, but this will bring us to the end plus one issue.
+
+153
+00:13:45,000 --> 00:13:49,000
+If you don't remember what it is place, what is the lesson?
+
+154
+00:13:49,000 --> 00:13:54,000
+Both and plus one issue where we use a problem and potential solutions.
+
+155
+00:13:55,000 --> 00:13:57,000
+You may want to use entity graphs.
+
+156
+00:13:58,000 --> 00:14:03,000
+Also, you can add in persistence axonal properties that is called hibernate.
+
+157
+00:14:03,000 --> 00:14:05,000
+Enable lazy load.
+
+158
+00:14:05,000 --> 00:14:06,000
+No chance.
+
+159
+00:14:06,000 --> 00:14:09,000
+But still, I wouldn't recommend to do so.
+
+160
+00:14:09,000 --> 00:14:17,000
+Setting this property to true means that each access to an associated lazy loaded entity will be rubbed
+
+161
+00:14:17,000 --> 00:14:21,000
+in use session running in the transaction.
+
+162
+00:14:22,000 --> 00:14:27,000
+This is also not recommended because you would end up with endless one issue.
+
+163
+00:14:27,000 --> 00:14:36,000
+Again, one of the recommended solutions is to use creative API or simply do not fetch the data that
+
+164
+00:14:36,000 --> 00:14:37,000
+you don't need.
+
+165
+00:14:38,000 --> 00:14:44,000
+Here, I created a query to fetch the data that is required for this specific business case.
+
+166
+00:14:44,000 --> 00:14:47,000
+An example is criteria API.
+
+167
+00:14:47,000 --> 00:14:50,000
+I'm going to show you a little bit later.
+
+168
+00:14:50,000 --> 00:14:56,000
+So here in query, I specified on the fields that I want to fetch.
+
+169
+00:14:56,000 --> 00:15:04,000
+But unfortunately, because I fetched not all fields, or in case you fetch custom set of fields, not
+
+170
+00:15:04,000 --> 00:15:10,000
+always hibernate and convert automatically results into the entity as an option.
+
+171
+00:15:10,000 --> 00:15:17,000
+You can create a separate entity that would contain the less amount of fields, but I don't recommend
+
+172
+00:15:17,000 --> 00:15:19,000
+you to do that.
+
+173
+00:15:19,000 --> 00:15:27,000
+Just wanted to show that you can always take the topos that you received and initialize the type that
+
+174
+00:15:27,000 --> 00:15:27,000
+you need.
+
+175
+00:15:28,000 --> 00:15:32,000
+Like in this case, we received a list of object arrays.
+
+176
+00:15:33,000 --> 00:15:38,000
+Each object array is a set of values as specified in the query.
+
+177
+00:15:39,000 --> 00:15:42,000
+The first value will be on the zero.
+
+178
+00:15:42,000 --> 00:15:46,000
+The second value will be under the index one and so on.
+
+179
+00:15:47,000 --> 00:15:49,000
+Some get purchased by DH.
+
+180
+00:15:49,000 --> 00:15:52,000
+I prepare the example for you with the criteria API.
+
+181
+00:15:53,000 --> 00:16:01,000
+So using the criteria you can specify vividly that you also want to fetch user detail, property and
+
+182
+00:16:01,000 --> 00:16:10,000
+product details properties that these properties will be fetched easily and we will avoid upgrades.
+
+183
+00:16:10,000 --> 00:16:19,000
+Initialization exception in the update purchase you can see that I use merge method instead of persist,
+
+184
+00:16:19,000 --> 00:16:20,000
+but why?
+
+185
+00:16:20,000 --> 00:16:27,000
+In case we will use persist here we will see error that tells us that you want to persist.
+
+186
+00:16:27,000 --> 00:16:34,000
+The dodged entity and attached entity is a Java object that is no longer tracked by the persistence
+
+187
+00:16:34,000 --> 00:16:44,000
+context entities can reach this state if we close only as a session component will throw a persistent
+
+188
+00:16:44,000 --> 00:16:47,000
+exception with the detached entity passed to persist.
+
+189
+00:16:47,000 --> 00:16:48,000
+Error message.
+
+190
+00:16:49,000 --> 00:16:56,000
+If we use the March method hibernate, we attach the entity to the persistence context based on the
+
+191
+00:16:56,000 --> 00:16:57,000
+ID field.
+
+192
+00:16:57,000 --> 00:17:04,000
+So in my solution in different places, you are going to see that the use merge instead of persist and
+
+193
+00:17:04,000 --> 00:17:07,000
+you'll know why I do like this.
+
+194
+00:17:08,000 --> 00:17:10,000
+Their suits were getting purchased down.
+
+195
+00:17:10,000 --> 00:17:11,000
+Let's continue.
+
+196
+00:17:12,000 --> 00:17:15,000
+The next on the list is purchase status down.
+
+197
+00:17:16,000 --> 00:17:22,000
+Actually, there is only one mass here and they use one method that we have already learned.
+
+198
+00:17:23,000 --> 00:17:24,000
+And the user Dao.
+
+199
+00:17:24,000 --> 00:17:31,000
+I apply the same principles that we are already talked through to implement the DAO interface.
+
+200
+00:17:31,000 --> 00:17:38,000
+Another interesting thing here is that the protocol logic is built around the verification.
+
+201
+00:17:38,000 --> 00:17:46,000
+If a user is present in the database during the registration, we check if user with such email exists
+
+202
+00:17:46,000 --> 00:17:53,000
+and in case there is no user with such email, we proceed with the registration get single result so
+
+203
+00:17:53,000 --> 00:18:00,000
+we throw no result exception in case result wouldn't be found for such cases.
+
+204
+00:18:00,000 --> 00:18:04,000
+You have to handle this exception like I did in this case.
+
+205
+00:18:04,000 --> 00:18:11,000
+I catch this exception and return now because there is no handling already in place according to the
+
+206
+00:18:11,000 --> 00:18:13,000
+contract that we have developed.
+
+207
+00:18:14,000 --> 00:18:16,000
+Take the time to look through the implementation solo.
+
+208
+00:18:17,000 --> 00:18:25,000
+And anyway, in case after you still have some questions, please do not hesitate to ask your questions
+
+209
+00:18:25,000 --> 00:18:28,000
+below the video and I will be happy to answer.
+
+210
+00:18:29,000 --> 00:18:35,000
+The only thing that is still left to do is to inject the implementations into the business layer.
+
+211
+00:18:36,000 --> 00:18:42,000
+Let's find our facade layer and instead of gdb see the implementations.
+
+212
+00:18:42,000 --> 00:18:45,000
+Let's inject our implementations.
+
+213
+00:18:46,000 --> 00:18:50,000
+Our facade implementations are located in the core module.
+
+214
+00:18:51,000 --> 00:18:54,000
+So let's open the full category facade, for example.
+
+215
+00:18:54,000 --> 00:19:00,000
+And for category implementation, let's use GPU category class.
+
+216
+00:19:01,000 --> 00:19:06,000
+Unless there's a seamless sync with all other facade objects.
+
+217
+00:19:06,000 --> 00:19:07,000
+Definitely.
+
+218
+00:19:07,000 --> 00:19:14,000
+When you have a container to manage your beans like we have in spring, it is easier to make injections
+
+219
+00:19:14,000 --> 00:19:16,000
+like this in the configuration file.
+
+220
+00:19:17,000 --> 00:19:22,000
+In my course java from zero to first job, we are going to learn how to work with spring conversion
+
+221
+00:19:22,000 --> 00:19:26,000
+of control, container speed data and lots more.
+
+222
+00:19:26,000 --> 00:19:32,000
+After we injected, our new patients were good to run our application.
+
+223
+00:19:33,000 --> 00:19:34,000
+One more thing.
+
+224
+00:19:34,000 --> 00:19:41,000
+When you run the applications the first time, make sure that you have drop and create value in the
+
+225
+00:19:41,000 --> 00:19:44,000
+persistence section for schema generation option.
+
+226
+00:19:45,000 --> 00:19:49,000
+Run the program first time all tables will be created.
+
+227
+00:19:50,000 --> 00:19:56,000
+After that, I suggest to use prepared data set to populate database with the fake data.
+
+228
+00:19:57,000 --> 00:20:03,000
+Prepared dataset is located in the persistence module in the folder database expert.
+
+229
+00:20:04,000 --> 00:20:09,000
+The reason file was only input statements created specially for this project.
+
+230
+00:20:10,000 --> 00:20:13,000
+It is called data input for GP project.
+
+231
+00:20:14,000 --> 00:20:21,000
+And after you inserted all this data, change the value of this property to update in order to keep
+
+232
+00:20:21,000 --> 00:20:26,000
+your data stored in the database just to help you with all these steps.
+
+233
+00:20:26,000 --> 00:20:29,000
+I created a simple checklist for you.
+
+234
+00:20:29,000 --> 00:20:37,000
+You can open a new file in the route of the application, and here describes the deployment algorithm
+
+235
+00:20:37,000 --> 00:20:39,000
+that we have just discussed.
+
+236
+00:20:40,000 --> 00:20:41,000
+That's it.
+
+237
+00:20:41,000 --> 00:20:45,000
+Basically, that's all solutions that I'd like to share with you.
+
+238
+00:20:45,000 --> 00:20:50,000
+Now you can run application and testing to get it.
+
+239
+00:20:50,000 --> 00:20:57,000
+And as always, you're welcome to ask any questions you want, and that will be happy to answer.
+
+240
+00:20:58,000 --> 00:21:00,000
+Thanks a lot for your attention.
+
+241
+00:21:00,000 --> 00:21:03,000
+Have a great day and see you in the next lesson.
+
diff --git a/80 - ===== EXAM TASK JPA & Hibernate =====/001 Homework-description-and-reference-to-the-solution.url b/80 - ===== EXAM TASK JPA & Hibernate =====/001 Homework-description-and-reference-to-the-solution.url
new file mode 100644
index 0000000000000000000000000000000000000000..7cad42fd1263a243b69e88f3875cff9a4ccf38fe
--- /dev/null
+++ b/80 - ===== EXAM TASK JPA & Hibernate =====/001 Homework-description-and-reference-to-the-solution.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://docs.google.com/document/d/19OqkSC7kxj5y7TOH3GDxIVa8MjDnatrJ0u3R1hDYha8/edit?usp=sharing
\ No newline at end of file
diff --git a/80 - ===== EXAM TASK JPA & Hibernate =====/external-links.txt b/80 - ===== EXAM TASK JPA & Hibernate =====/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b4fcc04499689c6a6c107604879d8ff8659a8228
--- /dev/null
+++ b/80 - ===== EXAM TASK JPA & Hibernate =====/external-links.txt
@@ -0,0 +1,3 @@
+
+001 Homework-description-and-reference-to-the-solution
+https://docs.google.com/document/d/19OqkSC7kxj5y7TOH3GDxIVa8MjDnatrJ0u3R1hDYha8/edit?usp=sharing
diff --git a/81 - Spring Core/001 List-of-Spring-projects.url b/81 - Spring Core/001 List-of-Spring-projects.url
new file mode 100644
index 0000000000000000000000000000000000000000..a3af8f94b221d3f735834d1d5d9a4d3e1c573bac
--- /dev/null
+++ b/81 - Spring Core/001 List-of-Spring-projects.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://spring.io/projects
\ No newline at end of file
diff --git a/81 - Spring Core/001 Official-Site-of-Spring.url b/81 - Spring Core/001 Official-Site-of-Spring.url
new file mode 100644
index 0000000000000000000000000000000000000000..113bf4a7aa5ceeb167ebf896bd9045082bcc9ea4
--- /dev/null
+++ b/81 - Spring Core/001 Official-Site-of-Spring.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://spring.io
\ No newline at end of file
diff --git a/81 - Spring Core/001 Spring Framework General Overview_en.srt b/81 - Spring Core/001 Spring Framework General Overview_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..5e78d3281fd156775ef960d23f27c528a55a60a9
--- /dev/null
+++ b/81 - Spring Core/001 Spring Framework General Overview_en.srt
@@ -0,0 +1,816 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:08,000
+We're about to start.
+
+3
+00:00:08,000 --> 00:00:09,000
+Huge topic.
+
+4
+00:00:09,000 --> 00:00:12,000
+We are starting learning with you spring framework.
+
+5
+00:00:12,000 --> 00:00:18,000
+And this is the first lesson where we'll talk about what a spring framework is, what elements does
+
+6
+00:00:18,000 --> 00:00:24,000
+it have, what we are going to learn in the course and help you to understand which parts of spring
+
+7
+00:00:24,000 --> 00:00:31,000
+framework is more necessary for you at this moment, We are going to start the lesson from the learning
+
+8
+00:00:31,000 --> 00:00:32,000
+of what a spring is.
+
+9
+00:00:32,000 --> 00:00:37,000
+After that, I'm going to explain you the key features of Spring framework.
+
+10
+00:00:37,000 --> 00:00:44,000
+This will help you to understand what benefits we expect to get by using Spring framework.
+
+11
+00:00:44,000 --> 00:00:48,000
+I will make a high level overview of spring projects and modules.
+
+12
+00:00:48,000 --> 00:00:55,000
+You are going to understand the purpose of different spring modules and at the end of the video we are
+
+13
+00:00:55,000 --> 00:00:59,000
+going to talk about advantages and disadvantages of spring framework.
+
+14
+00:00:59,000 --> 00:01:01,000
+Let's start our lesson.
+
+15
+00:01:01,000 --> 00:01:06,000
+Let's start from answering the question what a spring is and why do we need it?
+
+16
+00:01:07,000 --> 00:01:14,000
+The spring provides a comprehensive programming and configuration model for modern Java based enterprise
+
+17
+00:01:14,000 --> 00:01:18,000
+applications on any kind of deployment platform.
+
+18
+00:01:19,000 --> 00:01:26,000
+Spring is a large body of predefined code to which developers can add code to solve a problem in a specific
+
+19
+00:01:26,000 --> 00:01:27,000
+domain.
+
+20
+00:01:27,000 --> 00:01:33,000
+A key element of spring is infrastructural support at the application level.
+
+21
+00:01:33,000 --> 00:01:42,000
+Spring focuses on the plumbing of enterprise application so that teams can focus on application level
+
+22
+00:01:42,000 --> 00:01:48,000
+business logic without unnecessary ties to the specific deployment environments.
+
+23
+00:01:48,000 --> 00:01:56,000
+Spring is an open source product written in Java with Apache license, meaning that you can freely use
+
+24
+00:01:56,000 --> 00:01:58,000
+it in your commercial projects.
+
+25
+00:01:58,000 --> 00:02:07,000
+So summarizing what a spring is, in simple words, Spring Framework contains a set of tools libraries
+
+26
+00:02:07,000 --> 00:02:10,000
+that can help us to solve typical challenges.
+
+27
+00:02:10,000 --> 00:02:18,000
+Typical tasks implement typical engineering solutions faster without writing tons of code and configurations
+
+28
+00:02:18,000 --> 00:02:22,000
+because this is already considered by spring.
+
+29
+00:02:22,000 --> 00:02:25,000
+Let's learn what the key features of spring are.
+
+30
+00:02:26,000 --> 00:02:35,000
+As I said, spring contains multiple tools, projects, components, whatever you call it, and each
+
+31
+00:02:35,000 --> 00:02:37,000
+project has its own features.
+
+32
+00:02:37,000 --> 00:02:45,000
+But let me try to summarize probably the most significant ones and those that would be easier to understand
+
+33
+00:02:45,000 --> 00:02:46,000
+at the moment.
+
+34
+00:02:46,000 --> 00:02:53,000
+And actually, let's understand what are those typical enterprise scale challenges and questions that
+
+35
+00:02:53,000 --> 00:02:55,000
+spring helps us to deal with.
+
+36
+00:02:56,000 --> 00:03:01,000
+Spring supports core technologies and most of the popular programming concepts.
+
+37
+00:03:02,000 --> 00:03:08,000
+Among them are events handling in my course Java from zero to first job.
+
+38
+00:03:08,000 --> 00:03:15,000
+We already talked about event handling and events that can appear in our web application.
+
+39
+00:03:15,000 --> 00:03:23,000
+Spring contains tools that help us to work with events, concept, internationalization.
+
+40
+00:03:23,000 --> 00:03:29,000
+And again, if you are a student of my Java from zero to first job course, you know that we created
+
+41
+00:03:29,000 --> 00:03:37,000
+our own online shop from scratch and you saw how much code should be written and how much attention
+
+42
+00:03:37,000 --> 00:03:42,000
+it requires to handle internationalization questions properly.
+
+43
+00:03:42,000 --> 00:03:48,000
+Spring will save our nerves and will help us to do the same things faster.
+
+44
+00:03:49,000 --> 00:03:50,000
+Data binding.
+
+45
+00:03:50,000 --> 00:03:55,000
+Spring offers solution for data mapping and data binding.
+
+46
+00:03:56,000 --> 00:03:58,000
+Aspect oriented programming.
+
+47
+00:03:58,000 --> 00:04:02,000
+In this course we are going to learn what it is deeper.
+
+48
+00:04:02,000 --> 00:04:10,000
+But in short, AOP is a programming paradigm that aims to increase modularity by allowing the separation
+
+49
+00:04:10,000 --> 00:04:12,000
+of cross-cutting concerns.
+
+50
+00:04:13,000 --> 00:04:22,000
+Data validation work with resources, dependency injection, work with axises to ensure security and
+
+51
+00:04:22,000 --> 00:04:23,000
+lots more.
+
+52
+00:04:24,000 --> 00:04:28,000
+Spring MVC and Spring Web flux Web frameworks.
+
+53
+00:04:28,000 --> 00:04:35,000
+In my course Java from zero to first job, we have learned already what an MVC pattern is.
+
+54
+00:04:35,000 --> 00:04:42,000
+You already aware that this is model view controller pattern for web application?
+
+55
+00:04:42,000 --> 00:04:47,000
+And Spring MVC allows you to implement MVC pattern easily.
+
+56
+00:04:48,000 --> 00:04:51,000
+Talking about spring flags and short.
+
+57
+00:04:51,000 --> 00:04:57,000
+It is used to make it possible to build reactive applications on the HTTP layer.
+
+58
+00:04:57,000 --> 00:05:00,000
+We are going to learn in the details for the spring web.
+
+59
+00:05:00,000 --> 00:05:03,000
+Flux is in other lessons.
+
+60
+00:05:04,000 --> 00:05:05,000
+Features for testing.
+
+61
+00:05:06,000 --> 00:05:07,000
+Mock Objects.
+
+62
+00:05:07,000 --> 00:05:09,000
+Test Context Framework.
+
+63
+00:05:09,000 --> 00:05:11,000
+Spring MVC Test.
+
+64
+00:05:11,000 --> 00:05:12,000
+Web Test.
+
+65
+00:05:12,000 --> 00:05:13,000
+Client.
+
+66
+00:05:13,000 --> 00:05:16,000
+Data Access Transactions.
+
+67
+00:05:16,000 --> 00:05:21,000
+DAO Support JDBC ORM Marshalling XML.
+
+68
+00:05:22,000 --> 00:05:27,000
+Integration remoting is this Java message service.
+
+69
+00:05:27,000 --> 00:05:28,000
+GCA.
+
+70
+00:05:28,000 --> 00:05:30,000
+Java Connector.
+
+71
+00:05:30,000 --> 00:05:31,000
+Architecture.
+
+72
+00:05:31,000 --> 00:05:32,000
+Jmax.
+
+73
+00:05:32,000 --> 00:05:34,000
+Java Management Extensions.
+
+74
+00:05:34,000 --> 00:05:36,000
+Email Tasks.
+
+75
+00:05:36,000 --> 00:05:38,000
+Scheduling Cache.
+
+76
+00:05:38,000 --> 00:05:43,000
+Embedded Tomcat web server to boost your Web application creation.
+
+77
+00:05:44,000 --> 00:05:48,000
+Powerful repository and custom object mapping abstractions.
+
+78
+00:05:48,000 --> 00:05:55,000
+Comprehensive and extensible support for both authentication and authorization.
+
+79
+00:05:55,000 --> 00:05:58,000
+Support of transaction management.
+
+80
+00:05:58,000 --> 00:06:01,000
+Distributed version Configuration.
+
+81
+00:06:01,000 --> 00:06:05,000
+Load balancing and other different features.
+
+82
+00:06:06,000 --> 00:06:10,000
+Spring has different projects, libraries and different modules.
+
+83
+00:06:10,000 --> 00:06:12,000
+Or in other words, components.
+
+84
+00:06:12,000 --> 00:06:17,000
+Each component of the spring framework has its own purpose.
+
+85
+00:06:17,000 --> 00:06:23,000
+Let me make a brief overview of spring components and understand why we need each of them.
+
+86
+00:06:24,000 --> 00:06:32,000
+Here is the official website of Spring Community and under the Projects menu Select View All Projects.
+
+87
+00:06:33,000 --> 00:06:34,000
+Spring Core.
+
+88
+00:06:34,000 --> 00:06:42,000
+Spring Framework provides a support for dependency injection, transaction management, data access
+
+89
+00:06:42,000 --> 00:06:43,000
+and others.
+
+90
+00:06:43,000 --> 00:06:49,000
+This is core spring module that we need to start with in order to understand the spring.
+
+91
+00:06:50,000 --> 00:06:56,000
+We are going to have separate lessons about spring core and I'm going to explain what a dependency injection
+
+92
+00:06:56,000 --> 00:06:57,000
+is.
+
+93
+00:06:57,000 --> 00:07:05,000
+But in short, this component of the spring helps us to manage configurations of our application manage
+
+94
+00:07:05,000 --> 00:07:11,000
+lifecycle of objects in the application, their construction and lots more.
+
+95
+00:07:11,000 --> 00:07:13,000
+I would say this is the basics.
+
+96
+00:07:14,000 --> 00:07:21,000
+Spring Boot, in simple words, contains all necessary tools in order to help you start creation of
+
+97
+00:07:21,000 --> 00:07:24,000
+the application as soon as possible.
+
+98
+00:07:25,000 --> 00:07:28,000
+Actually, there are two concepts of learning spring.
+
+99
+00:07:29,000 --> 00:07:37,000
+Some teachers recommend to start from the spring boot that essentially combines many other spring components.
+
+100
+00:07:37,000 --> 00:07:44,000
+Other teachers agree that to understand spring boot, it is better to understand other spring components.
+
+101
+00:07:45,000 --> 00:07:49,000
+I also believe that it is not a good idea to start from the spring boot.
+
+102
+00:07:50,000 --> 00:07:52,000
+I am not saying that we will not learn it.
+
+103
+00:07:52,000 --> 00:07:59,000
+I would just call spring boot as an aggregator of other spring elements and I would prefer you to learn
+
+104
+00:07:59,000 --> 00:08:00,000
+spring gradually.
+
+105
+00:08:01,000 --> 00:08:03,000
+And another important moment.
+
+106
+00:08:03,000 --> 00:08:04,000
+Not always.
+
+107
+00:08:04,000 --> 00:08:06,000
+We use spring boot.
+
+108
+00:08:06,000 --> 00:08:10,000
+Sometimes we use few spring modules that we need only.
+
+109
+00:08:11,000 --> 00:08:19,000
+Spring data, very powerful tool to work with data mapping and persistent storage in your application.
+
+110
+00:08:19,000 --> 00:08:28,000
+In my course Java from zero to first job, we have learned GP Hibernate and Gdcc Ziza tools to work
+
+111
+00:08:28,000 --> 00:08:36,000
+with data and persistent storages and spring data introduces additional layer of abstraction on top
+
+112
+00:08:36,000 --> 00:08:36,000
+of that.
+
+113
+00:08:37,000 --> 00:08:43,000
+Also, I wanted to say that spring data as it is something what would help us to work with data?
+
+114
+00:08:44,000 --> 00:08:49,000
+And sometimes it will help us to save even more time than hibernate.
+
+115
+00:08:49,000 --> 00:08:55,000
+You would see in the course you can see here Spring Cloud by its name.
+
+116
+00:08:55,000 --> 00:09:01,000
+It is clear that this project provides us with tools for working with cloud based technologies.
+
+117
+00:09:02,000 --> 00:09:09,000
+Spring Security helps us to configure authentication and authorization while working with resources
+
+118
+00:09:09,000 --> 00:09:10,000
+in our application.
+
+119
+00:09:11,000 --> 00:09:19,000
+And this is important for you to know basics and how web application works inside the web filter concept
+
+120
+00:09:19,000 --> 00:09:21,000
+and other basics.
+
+121
+00:09:21,000 --> 00:09:25,000
+Because spring security is built on top of those basic tools.
+
+122
+00:09:26,000 --> 00:09:29,000
+You can see many, many other spring projects here.
+
+123
+00:09:30,000 --> 00:09:34,000
+I believe there is no need me going over each one here in the list.
+
+124
+00:09:35,000 --> 00:09:38,000
+I'm going to share with you a link to this page.
+
+125
+00:09:38,000 --> 00:09:41,000
+You can find the link in attachments to the video.
+
+126
+00:09:42,000 --> 00:09:47,000
+Let's now talk about advantages and disadvantages of the spring.
+
+127
+00:09:47,000 --> 00:09:49,000
+Talking about advantages.
+
+128
+00:09:49,000 --> 00:09:52,000
+It is worth to mention the next sinks.
+
+129
+00:09:52,000 --> 00:09:59,000
+Loose coupling spring applications are loosely coupled because of dependency injection.
+
+130
+00:09:59,000 --> 00:10:06,000
+It handles injecting dependent components without a component knowing where they came from.
+
+131
+00:10:07,000 --> 00:10:08,000
+Powerful abstraction.
+
+132
+00:10:09,000 --> 00:10:18,000
+It provides a powerful abstraction to give specifications such as GM's GPC, GPA and GTA.
+
+133
+00:10:19,000 --> 00:10:21,000
+Declarative support.
+
+134
+00:10:22,000 --> 00:10:28,000
+It provides declarative support for caching validation, transaction and formatting.
+
+135
+00:10:29,000 --> 00:10:33,000
+Declarative means opposite to programmatic approach.
+
+136
+00:10:33,000 --> 00:10:40,000
+With the declarative approach, we can manage different things through configuration annotations or
+
+137
+00:10:40,000 --> 00:10:42,000
+XML based configuration.
+
+138
+00:10:43,000 --> 00:10:44,000
+Configuration.
+
+139
+00:10:44,000 --> 00:10:52,000
+It provides a consistent way of configuring everything separate configuration from application logic
+
+140
+00:10:52,000 --> 00:10:53,000
+lifecycle.
+
+141
+00:10:54,000 --> 00:10:58,000
+Responsible for managing all your application components.
+
+142
+00:10:58,000 --> 00:11:04,000
+First, the team of Spring Engineers deeply cares about the performance.
+
+143
+00:11:05,000 --> 00:11:10,000
+It's fast startup fast shut down and optimized execution.
+
+144
+00:11:10,000 --> 00:11:12,000
+Maintain performance.
+
+145
+00:11:12,000 --> 00:11:13,000
+Make it fast.
+
+146
+00:11:14,000 --> 00:11:21,000
+We can start a new spring project in seconds by using spring initializer web application.
+
+147
+00:11:21,000 --> 00:11:23,000
+Basically, here it is.
+
+148
+00:11:24,000 --> 00:11:31,000
+You can just go to the website with this link and configure that project that you need.
+
+149
+00:11:31,000 --> 00:11:33,000
+Select Automation.
+
+150
+00:11:33,000 --> 00:11:40,000
+Build Tool language, Specify spring boot version, project metadata, dependencies.
+
+151
+00:11:40,000 --> 00:11:47,000
+And after specifying all this, you can quickly download archive with a template project.
+
+152
+00:11:47,000 --> 00:11:49,000
+Isn't this cool?
+
+153
+00:11:49,000 --> 00:11:56,000
+Don't worry, during the course we are going to use this tool to just wanted to show it to you.
+
+154
+00:11:57,000 --> 00:12:00,000
+The next advantage is that spring is secure.
+
+155
+00:12:00,000 --> 00:12:04,000
+It monitors third party dependencies closely.
+
+156
+00:12:04,000 --> 00:12:07,000
+The regular update is issued.
+
+157
+00:12:07,000 --> 00:12:11,000
+That make our data and application secure.
+
+158
+00:12:12,000 --> 00:12:17,000
+We can make our application secure by using the spring security framework.
+
+159
+00:12:17,000 --> 00:12:25,000
+It provides industry standard security schemas and delivers a trustworthy solution that is secure by
+
+160
+00:12:25,000 --> 00:12:26,000
+default.
+
+161
+00:12:27,000 --> 00:12:28,000
+Supportive.
+
+162
+00:12:28,000 --> 00:12:30,000
+Spring has huge community.
+
+163
+00:12:30,000 --> 00:12:33,000
+It is not just big, it is huge.
+
+164
+00:12:33,000 --> 00:12:37,000
+Working with spring and facing with some challenges.
+
+165
+00:12:37,000 --> 00:12:45,000
+Most likely somebody already solved it some time ago and you can easily find the solution for a challenge
+
+166
+00:12:45,000 --> 00:12:46,000
+in the internet.
+
+167
+00:12:47,000 --> 00:12:52,000
+The spring Community provides support and resources to get you to the next level.
+
+168
+00:12:52,000 --> 00:12:58,000
+Quick start guides, tutorials, videos and meetups help a lot.
+
+169
+00:12:59,000 --> 00:13:00,000
+Productive.
+
+170
+00:13:00,000 --> 00:13:07,000
+It is more productive because the spring application can integrate with other spring based applications.
+
+171
+00:13:07,000 --> 00:13:12,000
+For example, we can combine spring boot application with Spring Cloud.
+
+172
+00:13:13,000 --> 00:13:18,000
+Depending on whom you talk to, you can hear different advantages.
+
+173
+00:13:18,000 --> 00:13:25,000
+But the thing is that spring deserved its place and reputation in the world of Java ecosystem.
+
+174
+00:13:25,000 --> 00:13:29,000
+Not all projects in the world use spring.
+
+175
+00:13:29,000 --> 00:13:37,000
+This is also true, but really a lot of projects nowadays relies on the spring during the development.
+
+176
+00:13:38,000 --> 00:13:40,000
+We have learned spring advantages.
+
+177
+00:13:40,000 --> 00:13:44,000
+Now let's learn spring disadvantages.
+
+178
+00:13:45,000 --> 00:13:51,000
+In case you need to implement something custom, you need to be very familiar with what is happening
+
+179
+00:13:51,000 --> 00:13:53,000
+in spring under the hood.
+
+180
+00:13:53,000 --> 00:14:02,000
+You need to understand which classes do what in order to override their behavior whenever it will be
+
+181
+00:14:02,000 --> 00:14:02,000
+needed.
+
+182
+00:14:03,000 --> 00:14:11,000
+A lot of things happening outside of your control in case you would seek for optimization or any security
+
+183
+00:14:11,000 --> 00:14:12,000
+questions.
+
+184
+00:14:13,000 --> 00:14:20,000
+Again, you need to be familiar with spring internals to understand how it works inside.
+
+185
+00:14:21,000 --> 00:14:22,000
+Complexity.
+
+186
+00:14:22,000 --> 00:14:29,000
+While spring saves us time during the development and can make our lives easier, it is still needed
+
+187
+00:14:29,000 --> 00:14:33,000
+to learn how it works and its specifics.
+
+188
+00:14:33,000 --> 00:14:38,000
+Working with spring is more complex than with plain Java, for example.
+
+189
+00:14:38,000 --> 00:14:42,000
+It requires a lot of expertise.
+
+190
+00:14:42,000 --> 00:14:47,000
+If you have not used spring before, first you will have to learn.
+
+191
+00:14:47,000 --> 00:14:50,000
+The learning curve is also difficult.
+
+192
+00:14:50,000 --> 00:14:56,000
+So if you have not a lot of development experience, it is difficult to learn.
+
+193
+00:14:57,000 --> 00:14:59,000
+One, you will learn spring better.
+
+194
+00:14:59,000 --> 00:15:04,000
+Probably you will be able to add your own items in the disadvantages list.
+
+195
+00:15:05,000 --> 00:15:10,000
+But for now, I believe these are the main disadvantages.
+
+196
+00:15:10,000 --> 00:15:14,000
+Let's recap what we have learned in this lesson.
+
+197
+00:15:14,000 --> 00:15:17,000
+In this video, we have learned what a spring is.
+
+198
+00:15:17,000 --> 00:15:20,000
+We discussed key spring features.
+
+199
+00:15:20,000 --> 00:15:24,000
+Now you can imagine what spring does and why do we need it?
+
+200
+00:15:24,000 --> 00:15:32,000
+I showed you what spring consists of and we did a high level overview of spring projects and modules.
+
+201
+00:15:32,000 --> 00:15:38,000
+And at the end of the lesson we have discussed advantages and disadvantages of spring framework.
+
+202
+00:15:39,000 --> 00:15:41,000
+That's all for this lesson.
+
+203
+00:15:41,000 --> 00:15:43,000
+Thanks a lot for your attention.
+
+204
+00:15:43,000 --> 00:15:46,000
+Have a great day and see you in the next lesson.
+
diff --git a/81 - Spring Core/001 Spring-Initializr.url b/81 - Spring Core/001 Spring-Initializr.url
new file mode 100644
index 0000000000000000000000000000000000000000..904242062126c25bbd990d2c19c413b284db8361
--- /dev/null
+++ b/81 - Spring Core/001 Spring-Initializr.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://start.spring.io/
\ No newline at end of file
diff --git a/81 - Spring Core/002 Spring Architecture, Inversion of Control, Dependency Injection & Spring Beans_en.srt b/81 - Spring Core/002 Spring Architecture, Inversion of Control, Dependency Injection & Spring Beans_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..74d755e56fa55be0387017930cb2ed42cbd6cbfb
--- /dev/null
+++ b/81 - Spring Core/002 Spring Architecture, Inversion of Control, Dependency Injection & Spring Beans_en.srt
@@ -0,0 +1,736 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:09,000
+Today we start learning spring core.
+
+3
+00:00:09,000 --> 00:00:15,000
+This is very interesting and important topic that will help you to understand all further lessons about
+
+4
+00:00:15,000 --> 00:00:16,000
+spring.
+
+5
+00:00:16,000 --> 00:00:21,000
+Today we are going to have theoretical lesson, but believe me, this is important.
+
+6
+00:00:21,000 --> 00:00:27,000
+In order you can proceed with learning and understanding of practical examples.
+
+7
+00:00:27,000 --> 00:00:35,000
+I know that series sometimes may sound boring, but I will try to make it as interesting as possible.
+
+8
+00:00:35,000 --> 00:00:41,000
+I will not tell you redundant things and I will be as short as possible to share with you only necessary
+
+9
+00:00:41,000 --> 00:00:42,000
+things.
+
+10
+00:00:42,000 --> 00:00:49,000
+In this lesson we are going to hold an overview and learn spring framework architecture and you are
+
+11
+00:00:49,000 --> 00:00:53,000
+going to understand the place of spring core in the general architecture.
+
+12
+00:00:53,000 --> 00:01:00,000
+We will learn such basic and important concepts as inversion of control and dependency injection.
+
+13
+00:01:00,000 --> 00:01:05,000
+After that, we are going to talk about spring inversion of control container.
+
+14
+00:01:05,000 --> 00:01:11,000
+I'm going to review with you key types that we are going to work with while interacting with a spring
+
+15
+00:01:12,000 --> 00:01:13,000
+container.
+
+16
+00:01:13,000 --> 00:01:16,000
+I will explain what a spring context is.
+
+17
+00:01:16,000 --> 00:01:23,000
+Besides that, today we are going to learn super important concept that is called spring beans.
+
+18
+00:01:23,000 --> 00:01:28,000
+We will learn what is a and we will review the scopes of spring beans.
+
+19
+00:01:28,000 --> 00:01:33,000
+And at the end of the lesson we'll review what a spring expression language is.
+
+20
+00:01:33,000 --> 00:01:35,000
+We have a lot of things to learn today.
+
+21
+00:01:35,000 --> 00:01:37,000
+Let's start our lesson.
+
+22
+00:01:38,000 --> 00:01:45,000
+Let's start from learning of architecture of spring framework and understand what is the role and place
+
+23
+00:01:45,000 --> 00:01:52,000
+of spring core in the general spring architecture like we have learned already in the introduction Lesson
+
+24
+00:01:52,000 --> 00:01:53,000
+about the spring.
+
+25
+00:01:53,000 --> 00:01:57,000
+Spring framework consists of many different components.
+
+26
+00:01:57,000 --> 00:02:05,000
+The spring framework comprises several modules and features such as inversion of control aspect oriented
+
+27
+00:02:05,000 --> 00:02:06,000
+programming.
+
+28
+00:02:06,000 --> 00:02:08,000
+DAO Context.
+
+29
+00:02:08,000 --> 00:02:09,000
+Or Earum.
+
+30
+00:02:09,000 --> 00:02:09,000
+Depb.
+
+31
+00:02:09,000 --> 00:02:10,000
+MVC.
+
+32
+00:02:10,000 --> 00:02:11,000
+ET cetera.
+
+33
+00:02:11,000 --> 00:02:19,000
+We'll learn these modules and features one by one, but there is some basics that lies in the core for
+
+34
+00:02:19,000 --> 00:02:21,000
+all modules.
+
+35
+00:02:21,000 --> 00:02:28,000
+I'm talking about core spring inversion of control, container dependency, injection, spring context
+
+36
+00:02:28,000 --> 00:02:30,000
+and such basic concepts as spring bean.
+
+37
+00:02:31,000 --> 00:02:35,000
+You can see on this slide where core container is located.
+
+38
+00:02:35,000 --> 00:02:40,000
+So it is like in basement of the spring framework.
+
+39
+00:02:40,000 --> 00:02:46,000
+It contains the fundamental modules that are the cornerstone of spring framework.
+
+40
+00:02:46,000 --> 00:02:55,000
+Core Spring core is a core of the framework that power features such as inversion of control and dependency
+
+41
+00:02:55,000 --> 00:02:57,000
+injection beans.
+
+42
+00:02:57,000 --> 00:03:05,000
+Spring Beans provides bean factory, which is sophisticated implementation of the factory pattern.
+
+43
+00:03:05,000 --> 00:03:15,000
+Context Spring context builds on core and beans and provides a medium to access defined objects.
+
+44
+00:03:15,000 --> 00:03:21,000
+Application context interface is the core part of the context module and the spring context.
+
+45
+00:03:21,000 --> 00:03:29,000
+Support provides support for third party interactions such as caching, mailing and template engines.
+
+46
+00:03:29,000 --> 00:03:31,000
+Spring Expression Language.
+
+47
+00:03:31,000 --> 00:03:39,000
+Spring expression enables users to use the spring expression language to query and manipulate the object
+
+48
+00:03:39,000 --> 00:03:41,000
+graph at runtime.
+
+49
+00:03:41,000 --> 00:03:46,000
+Before moving to other slides and learning specifics of spring.
+
+50
+00:03:46,000 --> 00:03:52,000
+Let's understand such core concepts as inversion of control and dependency injection.
+
+51
+00:03:53,000 --> 00:03:59,000
+IOC inverts the flow of control as compared to traditional control flow.
+
+52
+00:03:59,000 --> 00:04:06,000
+In traditional programming, the flow of the business logic is determined by objects that are statically
+
+53
+00:04:06,000 --> 00:04:08,000
+bound to one another.
+
+54
+00:04:08,000 --> 00:04:16,000
+This inversion of control the flow depends on the object graph that is built up during program execution.
+
+55
+00:04:16,000 --> 00:04:24,000
+Such a dynamic flow is made possible by object interactions that are defined through abstractions.
+
+56
+00:04:24,000 --> 00:04:33,000
+This runtime binding is achieved by mechanisms such as dependency, injection or service locator in
+
+57
+00:04:33,000 --> 00:04:33,000
+IOC.
+
+58
+00:04:33,000 --> 00:04:40,000
+The code could also be linked statically during compilation, but you will find that to execute the
+
+59
+00:04:40,000 --> 00:04:48,000
+code, the external configuration will be used to build object graph and manage all the dependencies
+
+60
+00:04:48,000 --> 00:04:56,000
+so you already can understand that dependency injection is just one of the possible ways how we can
+
+61
+00:04:56,000 --> 00:04:58,000
+implement inversion of control.
+
+62
+00:04:59,000 --> 00:05:07,000
+Dependency injection is a pattern we can use to implement IOC where the control being inverted is set
+
+63
+00:05:07,000 --> 00:05:09,000
+in an object's dependencies.
+
+64
+00:05:09,000 --> 00:05:17,000
+Connecting objects with other objects or injecting objects into other objects is done by an assembler
+
+65
+00:05:17,000 --> 00:05:20,000
+rather than by the objects themselves.
+
+66
+00:05:20,000 --> 00:05:25,000
+There are three main ways in which a client can receive injected services.
+
+67
+00:05:25,000 --> 00:05:32,000
+Constructor injection where dependencies are provided through a client class constructor.
+
+68
+00:05:32,000 --> 00:05:40,000
+Setter injection where the client exposes a setter method which accepts the dependency interface.
+
+69
+00:05:40,000 --> 00:05:47,000
+Injection where the dependencies interface provides an injector method that will inject the dependency
+
+70
+00:05:47,000 --> 00:05:50,000
+into any client passed to it.
+
+71
+00:05:50,000 --> 00:05:51,000
+Okay.
+
+72
+00:05:51,000 --> 00:05:56,000
+Now when we have learned what an inversion of control and dependency injections are.
+
+73
+00:05:56,000 --> 00:06:00,000
+Let's understand now what a spring IOC container is.
+
+74
+00:06:01,000 --> 00:06:07,000
+The IOC container is responsible to instantiate, configure and assemble the objects.
+
+75
+00:06:07,000 --> 00:06:16,000
+The IOC container gets information from the XML file or Java annotations and works accordingly.
+
+76
+00:06:16,000 --> 00:06:24,000
+The main tasks performed by IOC Container are to instantiate the application class to configure the
+
+77
+00:06:24,000 --> 00:06:28,000
+object to assemble the dependencies between the objects.
+
+78
+00:06:29,000 --> 00:06:38,000
+Spring IOC is a mechanism to achieve loose coupling between objects dependencies to achieve loose coupling.
+
+79
+00:06:38,000 --> 00:06:45,000
+And dynamic binding of the objects at runtime objects, dependencies are injected by other assembler
+
+80
+00:06:45,000 --> 00:06:46,000
+objects.
+
+81
+00:06:46,000 --> 00:06:54,000
+Spring IOC Container is a program that injects dependencies into an object and make it ready for our
+
+82
+00:06:54,000 --> 00:06:55,000
+use.
+
+83
+00:06:55,000 --> 00:07:02,000
+In other words, with a spring IOC, we have entity in our program that is in charge of the life cycle
+
+84
+00:07:02,000 --> 00:07:06,000
+of our objects and dependencies between them.
+
+85
+00:07:06,000 --> 00:07:12,000
+We can manage our dependencies between objects directly in the configuration files.
+
+86
+00:07:13,000 --> 00:07:20,000
+Let's review the key interfaces and types that are in charge of spring inversion of Control container.
+
+87
+00:07:20,000 --> 00:07:26,000
+Spring IAC Container provides us different ways to decouple the object dependencies.
+
+88
+00:07:26,000 --> 00:07:31,000
+Bean factory is the root interface of spring IOC container.
+
+89
+00:07:32,000 --> 00:07:37,000
+Application context is a child interface of bean factory interface.
+
+90
+00:07:37,000 --> 00:07:45,000
+Some of the useful child interfaces of application contexts are configurable application context and
+
+91
+00:07:45,000 --> 00:07:47,000
+web application context.
+
+92
+00:07:47,000 --> 00:07:53,000
+Spring Framework provides a number of useful application context implementation classes that we can
+
+93
+00:07:53,000 --> 00:07:57,000
+use to get the spring context and then the spring bean.
+
+94
+00:07:57,000 --> 00:08:05,000
+Some of the useful application context implementations is that we use are annotation config application
+
+95
+00:08:05,000 --> 00:08:06,000
+context.
+
+96
+00:08:06,000 --> 00:08:14,000
+If we are using spring in standalone Java applications and using annotations for configuration, then
+
+97
+00:08:14,000 --> 00:08:19,000
+we can use this to initialize the container and get the bean objects.
+
+98
+00:08:20,000 --> 00:08:23,000
+Classpath XML application context.
+
+99
+00:08:23,000 --> 00:08:30,000
+If we have spring bean configuration XML file in standalone application, then we can use this class
+
+100
+00:08:30,000 --> 00:08:33,000
+to load the file and get the container object.
+
+101
+00:08:34,000 --> 00:08:35,000
+File system.
+
+102
+00:08:35,000 --> 00:08:37,000
+XML application context.
+
+103
+00:08:37,000 --> 00:08:39,000
+This is similar to classpath.
+
+104
+00:08:39,000 --> 00:08:47,000
+XML application context, except that the XML configuration file can be loaded from anywhere in the
+
+105
+00:08:47,000 --> 00:08:48,000
+file system.
+
+106
+00:08:49,000 --> 00:08:57,000
+Annotation config web application context, an XML web application context for web applications for
+
+107
+00:08:57,000 --> 00:09:03,000
+a standalone application, we need to initialize the container somewhere in the application and then
+
+108
+00:09:03,000 --> 00:09:06,000
+use it to get the spring beans.
+
+109
+00:09:07,000 --> 00:09:10,000
+We mentioned spring context on previous slides.
+
+110
+00:09:10,000 --> 00:09:13,000
+Let me now explain you what it is.
+
+111
+00:09:14,000 --> 00:09:22,000
+The context in the spring framework is shorthand for application context type and its child types.
+
+112
+00:09:22,000 --> 00:09:29,000
+Spring context is a programming construct that framework uses to access components from the inversion
+
+113
+00:09:29,000 --> 00:09:32,000
+of control container where they are cache.
+
+114
+00:09:33,000 --> 00:09:34,000
+Linguistically.
+
+115
+00:09:34,000 --> 00:09:41,000
+Context is a vague term for the abstract set of circumstances in which an event occurs.
+
+116
+00:09:41,000 --> 00:09:48,000
+However, in the context of the spring framework, the application context is well defined and understood
+
+117
+00:09:49,000 --> 00:09:56,000
+by framework users as a state of the IOC container from which a component has been produced via dependency
+
+118
+00:09:56,000 --> 00:09:57,000
+injection.
+
+119
+00:09:58,000 --> 00:10:00,000
+Hope that this is clear now.
+
+120
+00:10:00,000 --> 00:10:05,000
+Also during the course were often we are going to use such term as spring bean.
+
+121
+00:10:05,000 --> 00:10:07,000
+Let's understand.
+
+122
+00:10:07,000 --> 00:10:08,000
+What is it?
+
+123
+00:10:08,000 --> 00:10:11,000
+Spring bean is nothing special.
+
+124
+00:10:11,000 --> 00:10:16,000
+Any object in the spring framework that we initialize through spring container is called Spring Bean.
+
+125
+00:10:17,000 --> 00:10:21,000
+Any normal Java project class can be a spring bean.
+
+126
+00:10:21,000 --> 00:10:28,000
+It is configured to be initialized with a container by providing configuration metadata information.
+
+127
+00:10:29,000 --> 00:10:33,000
+Each bean in spring container has its own scope.
+
+128
+00:10:33,000 --> 00:10:35,000
+What is bean scope?
+
+129
+00:10:35,000 --> 00:10:39,000
+Bean scopes refers to the lifecycle of bean.
+
+130
+00:10:39,000 --> 00:10:46,000
+That means when the object of bean will be instantiated, how long does the object leave and how many
+
+131
+00:10:46,000 --> 00:10:49,000
+objects will be created for that bean sprout?
+
+132
+00:10:49,000 --> 00:10:56,000
+Basically, it controls the instance creation of the bean and it is managed by the spring container.
+
+133
+00:10:57,000 --> 00:11:02,000
+There are five scopes defined for spring beans Singleton.
+
+134
+00:11:02,000 --> 00:11:06,000
+Only one instance of the bean will be created for each container.
+
+135
+00:11:07,000 --> 00:11:09,000
+This is the default scope for the spring beans.
+
+136
+00:11:09,000 --> 00:11:15,000
+While using this scope, make sure Bean doesn't have shared instance variables.
+
+137
+00:11:15,000 --> 00:11:20,000
+Otherwise it might lead to data inconsistency issues.
+
+138
+00:11:20,000 --> 00:11:21,000
+Prototype.
+
+139
+00:11:21,000 --> 00:11:25,000
+A new instance will be created every time the bean is requested.
+
+140
+00:11:26,000 --> 00:11:27,000
+Request.
+
+141
+00:11:27,000 --> 00:11:30,000
+This is the same as prototype scope.
+
+142
+00:11:30,000 --> 00:11:37,000
+However, it's meant to be used for web applications and new instance of the bin will be created for
+
+143
+00:11:37,000 --> 00:11:39,000
+each HTTP request.
+
+144
+00:11:39,000 --> 00:11:40,000
+Session.
+
+145
+00:11:41,000 --> 00:11:45,000
+A new bill will be created for each HTTP session by the container.
+
+146
+00:11:46,000 --> 00:11:52,000
+Application scope container creates one instance per web application runtime.
+
+147
+00:11:52,000 --> 00:11:57,000
+It is almost similar to singleton scope with only two differences.
+
+148
+00:11:57,000 --> 00:11:58,000
+That is.
+
+149
+00:11:58,000 --> 00:12:04,000
+Application scoped bean is singleton per served context, whereas Singleton scoped.
+
+150
+00:12:04,000 --> 00:12:08,000
+Bean is singleton per application context.
+
+151
+00:12:08,000 --> 00:12:14,000
+Please note that there can be multiple application contexts for a single application.
+
+152
+00:12:15,000 --> 00:12:20,000
+Application scoped bean is visible as a servlet context attribute.
+
+153
+00:12:21,000 --> 00:12:22,000
+WebSocket.
+
+154
+00:12:23,000 --> 00:12:28,000
+WebSocket scoped beans are stored in the websocket session attributes.
+
+155
+00:12:28,000 --> 00:12:35,000
+The same instance of the bean is then returned whenever the bean is accessed during the entire WebSocket
+
+156
+00:12:35,000 --> 00:12:36,000
+session.
+
+157
+00:12:36,000 --> 00:12:41,000
+Spring framework is extendable and we can create our own scopes too.
+
+158
+00:12:41,000 --> 00:12:47,000
+However, most of the times we are good with the scopes provided by the framework.
+
+159
+00:12:47,000 --> 00:12:53,000
+And the last but not the least, that I would like to talk about today is spring expression language.
+
+160
+00:12:53,000 --> 00:12:57,000
+It is an extension to the expression language defined in JSP.
+
+161
+00:12:58,000 --> 00:13:02,000
+It provides support to setting and getting property values.
+
+162
+00:13:02,000 --> 00:13:04,000
+Method Invocation.
+
+163
+00:13:04,000 --> 00:13:05,000
+Access and collection.
+
+164
+00:13:05,000 --> 00:13:06,000
+And indexers.
+
+165
+00:13:06,000 --> 00:13:08,000
+Named Variables.
+
+166
+00:13:08,000 --> 00:13:11,000
+Logical and Arithmetic Operators.
+
+167
+00:13:11,000 --> 00:13:15,000
+Retrieval of objects by name, etcetera.
+
+168
+00:13:15,000 --> 00:13:21,000
+The spring expression language is a powerful expression language that supports querying and manipulating
+
+169
+00:13:21,000 --> 00:13:23,000
+an object graph at runtime.
+
+170
+00:13:24,000 --> 00:13:29,000
+We can use it with XML or annotation based spring configurations.
+
+171
+00:13:30,000 --> 00:13:32,000
+That's all what I wanted to share with you today.
+
+172
+00:13:32,000 --> 00:13:36,000
+Let's recap what we have learned in the lesson.
+
+173
+00:13:37,000 --> 00:13:41,000
+In this lesson, we have learned how spring framework architecture looks like.
+
+174
+00:13:41,000 --> 00:13:49,000
+We learned what an inversion of control is and what a dependency injection is and how they are different.
+
+175
+00:13:49,000 --> 00:13:56,000
+We talked about inversion of control container in spring and reviewed key types that we are going to
+
+176
+00:13:56,000 --> 00:14:00,000
+work with while interacting with Container in spring.
+
+177
+00:14:01,000 --> 00:14:03,000
+I explained to you what a spring context is.
+
+178
+00:14:04,000 --> 00:14:11,000
+Also, we have learned such important concepts as spring beans and reviewed spring beans scopes.
+
+179
+00:14:11,000 --> 00:14:15,000
+And at the end of the lesson we talked about spring expression language.
+
+180
+00:14:15,000 --> 00:14:17,000
+That's it for this lesson.
+
+181
+00:14:18,000 --> 00:14:24,000
+It is important you learn concepts from this lesson in order to be able to proceed with practical examples
+
+182
+00:14:24,000 --> 00:14:27,000
+and understand them well.
+
+183
+00:14:27,000 --> 00:14:29,000
+Thanks a lot for your attention.
+
+184
+00:14:29,000 --> 00:14:32,000
+Have a great day and see you in the next lesson.
+
diff --git a/81 - Spring Core/003 IoC, Beans Configuration, XML and Annotations - Practice_en.srt b/81 - Spring Core/003 IoC, Beans Configuration, XML and Annotations - Practice_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..2f9c401cdbf72b4a667603bbeceb34b3ca7a8860
--- /dev/null
+++ b/81 - Spring Core/003 IoC, Beans Configuration, XML and Annotations - Practice_en.srt
@@ -0,0 +1,1584 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:10,000
+Today we're going to have a practical lesson about Sprint core.
+
+3
+00:00:10,000 --> 00:00:16,000
+It is important to you Watch the previous theoretical lesson about Spring Corps, because in this lesson
+
+4
+00:00:16,000 --> 00:00:21,000
+we are going to use terms and concepts that we have learned in previous video.
+
+5
+00:00:22,000 --> 00:00:28,000
+Namely, we are going to talk about how to initialize and how to work with Spring build factory and
+
+6
+00:00:28,000 --> 00:00:30,000
+spring application context.
+
+7
+00:00:30,000 --> 00:00:35,000
+I'm going to explain you more about IFC Containers in Spring.
+
+8
+00:00:35,000 --> 00:00:40,000
+Also, in this lesson, we are going to have practical exercises with spring bins.
+
+9
+00:00:41,000 --> 00:00:45,000
+We'll learn how to declare spring bins and how to configure them.
+
+10
+00:00:45,000 --> 00:00:50,000
+I'm going to show you both XML and annotation configuration.
+
+11
+00:00:50,000 --> 00:00:53,000
+We'll learn configuration specifics.
+
+12
+00:00:53,000 --> 00:00:57,000
+I will explain you the difference between D and Bin name.
+
+13
+00:00:57,000 --> 00:01:06,000
+Also, we'll talk about differences between such annotations as component service, controller and repository.
+
+14
+00:01:06,000 --> 00:01:11,000
+I will explain what is the purpose of qualifier annotation on real examples.
+
+15
+00:01:11,000 --> 00:01:18,000
+We are going to see how to configure bin scopes and what is the difference between being scopes and
+
+16
+00:01:18,000 --> 00:01:24,000
+at the end of the lesson we are going to make a summary and compare advantages and disadvantages of
+
+17
+00:01:24,000 --> 00:01:27,000
+XML and annotation based configuration.
+
+18
+00:01:28,000 --> 00:01:29,000
+Let's start our lesson.
+
+19
+00:01:30,000 --> 00:01:34,000
+And as I already said today, we're going to have practical lesson.
+
+20
+00:01:34,000 --> 00:01:37,000
+So let's start from the demo straightaway.
+
+21
+00:01:37,000 --> 00:01:42,000
+Before the lesson, I prepared source code examples in order to save your time.
+
+22
+00:01:42,000 --> 00:01:47,000
+You're watching the video and make sure that I didn't miss anything.
+
+23
+00:01:47,000 --> 00:01:51,000
+I'm going to walk you through the all the examples line by line.
+
+24
+00:01:52,000 --> 00:01:58,000
+You will find all source code examples from the lesson in attachments to the video and even in case
+
+25
+00:01:58,000 --> 00:02:00,000
+some questions will laugh.
+
+26
+00:02:00,000 --> 00:02:07,000
+You are always welcome to ask your questions below the video and I will be happy to answer the first
+
+27
+00:02:07,000 --> 00:02:09,000
+thing that we are going to do.
+
+28
+00:02:09,000 --> 00:02:14,000
+Let's create simple MAVEN project using Quick Start Archetype.
+
+29
+00:02:14,000 --> 00:02:22,000
+We're going to start from the simple project and after that gradually we'll turn it into a web project
+
+30
+00:02:22,000 --> 00:02:29,000
+and once we'll learn all necessary things required for running and supporting the project, we are going
+
+31
+00:02:29,000 --> 00:02:33,000
+to integrate Spring Framework into our online shop application.
+
+32
+00:02:34,000 --> 00:02:40,000
+In my course, Java from zero to first job together with my students, will create online shop from
+
+33
+00:02:40,000 --> 00:02:40,000
+scratch.
+
+34
+00:02:41,000 --> 00:02:48,000
+And after learning of each new topic, we practice our skills by updating and improving our online shop.
+
+35
+00:02:49,000 --> 00:02:54,000
+This is going to be very interesting, but let's start small and become big.
+
+36
+00:02:55,000 --> 00:03:01,000
+In case you are not familiar with Maven, please refer to this section about automated build tools in
+
+37
+00:03:01,000 --> 00:03:02,000
+my course.
+
+38
+00:03:02,000 --> 00:03:04,000
+Go from zero to first job.
+
+39
+00:03:04,000 --> 00:03:08,000
+By the way, if you wish, you can create a grad or project.
+
+40
+00:03:09,000 --> 00:03:10,000
+It is only up to you.
+
+41
+00:03:10,000 --> 00:03:18,000
+We'll put our focus on the learning of spring in this section of the course so you can use whatever
+
+42
+00:03:18,000 --> 00:03:22,000
+automated build to you wish or even don't use any.
+
+43
+00:03:22,000 --> 00:03:26,000
+But I'm going to show you examples with MAVEN build tool.
+
+44
+00:03:27,000 --> 00:03:31,000
+After project is created, we need to add dependencies.
+
+45
+00:03:31,000 --> 00:03:34,000
+Let's add sprint core dependency.
+
+46
+00:03:34,000 --> 00:03:36,000
+Here it is in dependency section.
+
+47
+00:03:37,000 --> 00:03:43,000
+Also, let's add screwing beans, dependency and dependency for the sprint context.
+
+48
+00:03:43,000 --> 00:03:49,000
+All these dependencies are required for our practical exercises today.
+
+49
+00:03:49,000 --> 00:03:55,000
+And the important thing to mention here is that it is highly recommended that all sprint dependencies
+
+50
+00:03:55,000 --> 00:04:00,000
+would have this same version to make sure that they're compatible with each other.
+
+51
+00:04:00,000 --> 00:04:08,000
+That's why I create a sprint version property in the main properties and use this variable just in case.
+
+52
+00:04:08,000 --> 00:04:10,000
+To not mess things up.
+
+53
+00:04:11,000 --> 00:04:15,000
+Now let's create simple class that is called user.
+
+54
+00:04:15,000 --> 00:04:21,000
+This is a simple project class that has first name, last name and email fields.
+
+55
+00:04:22,000 --> 00:04:24,000
+Getters and setters.
+
+56
+00:04:24,000 --> 00:04:26,000
+Default constructor and the string method.
+
+57
+00:04:27,000 --> 00:04:27,000
+That's it.
+
+58
+00:04:28,000 --> 00:04:35,000
+This class is going to be our spring bin and to consider it as a spring bin, we need to let spring
+
+59
+00:04:35,000 --> 00:04:38,000
+context to manage its lifecycle.
+
+60
+00:04:38,000 --> 00:04:41,000
+Let's configure this in spring.
+
+61
+00:04:41,000 --> 00:04:45,000
+We have two ways of how we can handle our configurations.
+
+62
+00:04:45,000 --> 00:04:49,000
+The first way is to handle configurations in the XML file.
+
+63
+00:04:50,000 --> 00:04:54,000
+The second option is to handle configurations with the annotations.
+
+64
+00:04:54,000 --> 00:05:01,000
+During the course, I'm going to show you both options and we are going to discuss pros and cons of
+
+65
+00:05:01,000 --> 00:05:02,000
+each approach.
+
+66
+00:05:02,000 --> 00:05:08,000
+Let me start from showing how we can configure our spring bins with the XML file.
+
+67
+00:05:08,000 --> 00:05:11,000
+Let's create application Context XML file.
+
+68
+00:05:12,000 --> 00:05:18,000
+Technically speaking, you can put it wherever you want in the class pass, but in case this will be
+
+69
+00:05:18,000 --> 00:05:25,000
+our web application for security reasons, it is recommended to make it not accessible from the web.
+
+70
+00:05:25,000 --> 00:05:30,000
+But anyway, one will come for configuration of the web application.
+
+71
+00:05:30,000 --> 00:05:34,000
+I'm going to remind you this so far.
+
+72
+00:05:34,000 --> 00:05:39,000
+I put application context XML file into resources source folder.
+
+73
+00:05:39,000 --> 00:05:40,000
+Let's check.
+
+74
+00:05:40,000 --> 00:05:42,000
+What do we have here inside?
+
+75
+00:05:43,000 --> 00:05:47,000
+We have ex Loco law and XML schema validation here.
+
+76
+00:05:48,000 --> 00:05:51,000
+You don't need to learn these values by heart.
+
+77
+00:05:51,000 --> 00:05:53,000
+You can easily find them in the internet.
+
+78
+00:05:54,000 --> 00:06:00,000
+If you are familiar with the XML format, then you can understand what an XML namespace is.
+
+79
+00:06:00,000 --> 00:06:02,000
+An XML schema definition.
+
+80
+00:06:03,000 --> 00:06:10,000
+The main thing here with regards to screen configuration is that the file has a single root element
+
+81
+00:06:10,000 --> 00:06:12,000
+is it is called beans.
+
+82
+00:06:12,000 --> 00:06:17,000
+And inside this element we can declare multiple bean elements.
+
+83
+00:06:17,000 --> 00:06:21,000
+For example, like you can see here, I created user bean.
+
+84
+00:06:22,000 --> 00:06:27,000
+Each bean has ID that can be used when we need to refer to some bean.
+
+85
+00:06:28,000 --> 00:06:34,000
+I can use bean name for identification purposes to and use it instead of ID.
+
+86
+00:06:35,000 --> 00:06:43,000
+The only difference between an ID and the name is that a name can contain multiple aliases separated
+
+87
+00:06:43,000 --> 00:06:50,000
+by a comma, semicolon or whitespace, whereas an ID must be a single value.
+
+88
+00:06:51,000 --> 00:06:56,000
+Also, we need to specify full class name, and that's what I did here.
+
+89
+00:06:57,000 --> 00:07:00,000
+I specified properties and past string values.
+
+90
+00:07:01,000 --> 00:07:04,000
+I injected string values into my bin.
+
+91
+00:07:04,000 --> 00:07:08,000
+Let me open Demo bin Factory ISC class now.
+
+92
+00:07:09,000 --> 00:07:11,000
+I opened them a bin factory.
+
+93
+00:07:11,000 --> 00:07:13,000
+I see class and run.
+
+94
+00:07:14,000 --> 00:07:19,000
+I'm going to walk you through the console output and explain what is happening here.
+
+95
+00:07:20,000 --> 00:07:25,000
+As we will keep learning in spring, I recommend you to learn spring by reviewing the spring source
+
+96
+00:07:25,000 --> 00:07:26,000
+code.
+
+97
+00:07:26,000 --> 00:07:33,000
+Because for example, in many video courses, even today and in many online articles, since the internet
+
+98
+00:07:33,000 --> 00:07:39,000
+tutors just copy content from each other without diving deeper into the details.
+
+99
+00:07:39,000 --> 00:07:47,000
+So I just wanted to say that X Factor class is deprecated already and it is recommended to use default
+
+100
+00:07:47,000 --> 00:07:53,000
+list will be in factory and XML definition reader class instead.
+
+101
+00:07:53,000 --> 00:07:57,000
+It has a little bit different API, but I am going to show it now.
+
+102
+00:07:58,000 --> 00:08:02,000
+We create object of default list being factory at the beginning.
+
+103
+00:08:03,000 --> 00:08:09,000
+This is in general bin factory object that is in charge of generating bins.
+
+104
+00:08:09,000 --> 00:08:14,000
+After that we create object of XML bin definition reader.
+
+105
+00:08:14,000 --> 00:08:18,000
+This object will read our XML build definitions.
+
+106
+00:08:18,000 --> 00:08:21,000
+I paused the reference to the bin factory to.
+
+107
+00:08:22,000 --> 00:08:26,000
+Then we create a resource of our XML configuration.
+
+108
+00:08:27,000 --> 00:08:32,000
+I use class POS resource and parse the name of our configuration file.
+
+109
+00:08:33,000 --> 00:08:40,000
+The next important thing that I do here I call massive load definitions on my excellent build definition
+
+110
+00:08:40,000 --> 00:08:47,000
+reader, and once the definitions are read, I can use bin factory to instantiate our bins.
+
+111
+00:08:48,000 --> 00:08:55,000
+I call get bin method on my bin factory object pass ID of my bin and class.
+
+112
+00:08:55,000 --> 00:09:04,000
+After that I print user to console and you can see that user has all fields initialized like we configured
+
+113
+00:09:04,000 --> 00:09:05,000
+in our configuration file.
+
+114
+00:09:06,000 --> 00:09:12,000
+Now let me try to instantiate the bit based on the name that I gave to.
+
+115
+00:09:13,000 --> 00:09:21,000
+And as you can see in the console, I managed to get my beam not by IGI, but by the names that I specified
+
+116
+00:09:21,000 --> 00:09:22,000
+in the configuration.
+
+117
+00:09:22,000 --> 00:09:25,000
+This is just a useful thing to remember.
+
+118
+00:09:26,000 --> 00:09:30,000
+The remember from previous lesson would be scopes are.
+
+119
+00:09:30,000 --> 00:09:32,000
+And what is the default scope of beings?
+
+120
+00:09:33,000 --> 00:09:38,000
+Just to remind you, the scopes refers to the lifecycle of being.
+
+121
+00:09:38,000 --> 00:09:45,000
+That means when the object of being will be instantiated, how long does that object leave and how many
+
+122
+00:09:45,000 --> 00:09:51,000
+objects will be created for that to be throughout the default scope is singleton.
+
+123
+00:09:52,000 --> 00:09:58,000
+That means that only one instance of the user being exists in the container at the moment.
+
+124
+00:09:58,000 --> 00:10:05,000
+Thus, these two references are pointing out to the same object in the memory.
+
+125
+00:10:05,000 --> 00:10:08,000
+We can check it by comparing the links.
+
+126
+00:10:09,000 --> 00:10:16,000
+The fact that we receive truth here proves that these two references are pointing out to the same object
+
+127
+00:10:16,000 --> 00:10:17,000
+in the memory.
+
+128
+00:10:18,000 --> 00:10:19,000
+Is it clear?
+
+129
+00:10:19,000 --> 00:10:26,000
+In case you have any questions, please do not hesitate to ask your questions in comments to the video.
+
+130
+00:10:26,000 --> 00:10:29,000
+We saw a simple example was Bean Factory.
+
+131
+00:10:30,000 --> 00:10:35,000
+Let's now take a look at the example with application context and understand the difference.
+
+132
+00:10:36,000 --> 00:10:39,000
+I open the next A file that is called Demo.
+
+133
+00:10:39,000 --> 00:10:41,000
+Application Context IOC.
+
+134
+00:10:42,000 --> 00:10:50,000
+Technically speaking, we can say the spring framework comes with two sea containers bin factory and
+
+135
+00:10:50,000 --> 00:10:52,000
+application context.
+
+136
+00:10:52,000 --> 00:10:59,000
+The Big Factory is the most basic version of ICI containers, and the application context extends the
+
+137
+00:10:59,000 --> 00:11:01,000
+features of a factory.
+
+138
+00:11:02,000 --> 00:11:10,000
+One of the differences between these two ISC containers is that bin factory loads bins on demand while
+
+139
+00:11:10,000 --> 00:11:14,000
+application context across all beans at startup.
+
+140
+00:11:14,000 --> 00:11:19,000
+Thus being factory is lightweight as compared to application context.
+
+141
+00:11:20,000 --> 00:11:28,000
+Application context enhances bean factory in a more framework oriented style and provides several features
+
+142
+00:11:28,000 --> 00:11:31,000
+that are suitable for enterprise applications.
+
+143
+00:11:31,000 --> 00:11:39,000
+For example, it provides messaging, internationalization, functionality, event publication, functionality,
+
+144
+00:11:39,000 --> 00:11:46,000
+annotation based dependency injection, and easy integration with spring AOP features.
+
+145
+00:11:46,000 --> 00:11:55,000
+Apart from this, the application context supports all types of scopes, but the bean factory only supports
+
+146
+00:11:55,000 --> 00:11:57,000
+two scopes single tone and prototype.
+
+147
+00:11:58,000 --> 00:12:05,000
+Therefore, it's always preferable to use application context 1 billion complex enterprise applications.
+
+148
+00:12:05,000 --> 00:12:08,000
+So what do we have here now?
+
+149
+00:12:08,000 --> 00:12:16,000
+Example I create a reference of type application context and initialize it with object of class pos
+
+150
+00:12:16,000 --> 00:12:18,000
+XML application context.
+
+151
+00:12:18,000 --> 00:12:25,000
+I pause the name of my configuration file into the constructor and after having the reference to the
+
+152
+00:12:25,000 --> 00:12:30,000
+context object, I can just call Massive Get bin and that's it.
+
+153
+00:12:31,000 --> 00:12:39,000
+In a similar way I can get bin is a by ID or by name and you can see that both references are pointing
+
+154
+00:12:39,000 --> 00:12:42,000
+out to the same object as a heap memory.
+
+155
+00:12:43,000 --> 00:12:50,000
+You can see that instantiating offspring application context to us, less lines of codes in comparing
+
+156
+00:12:50,000 --> 00:12:52,000
+to being factory.
+
+157
+00:12:52,000 --> 00:13:01,000
+So in summary, being factory is okay for testing and non-production use, but application context is
+
+158
+00:13:01,000 --> 00:13:08,000
+more feature which contain the implementation and should be favored over being factor and in general
+
+159
+00:13:08,000 --> 00:13:12,000
+using of application context suits for most cases.
+
+160
+00:13:13,000 --> 00:13:16,000
+We saw how to configure beans with eczema.
+
+161
+00:13:16,000 --> 00:13:21,000
+Now let's take a look at annotation based configuration.
+
+162
+00:13:21,000 --> 00:13:26,000
+We have different bean naming strategies and I'm going to show you some.
+
+163
+00:13:27,000 --> 00:13:31,000
+We can use annotations for the bean configuration at different levels.
+
+164
+00:13:32,000 --> 00:13:35,000
+Let's review first class level annotations.
+
+165
+00:13:36,000 --> 00:13:42,000
+We can use component controller service or repository annotation.
+
+166
+00:13:42,000 --> 00:13:45,000
+What is the difference between these annotations?
+
+167
+00:13:45,000 --> 00:13:50,000
+By using different annotations, we can achieve two goals simultaneously.
+
+168
+00:13:51,000 --> 00:13:59,000
+The first one will mark types as spring beans and will enable them for auto detection during the components
+
+169
+00:13:59,000 --> 00:14:00,000
+can.
+
+170
+00:14:00,000 --> 00:14:09,000
+And the second thing we will be able to add component specific behavior component is a generic stereotype
+
+171
+00:14:09,000 --> 00:14:12,000
+for any spring managed component or bean.
+
+172
+00:14:12,000 --> 00:14:20,000
+When I open any other annotations from already mentioned, you can see that service is a component too,
+
+173
+00:14:20,000 --> 00:14:23,000
+and the controller is also a component.
+
+174
+00:14:23,000 --> 00:14:27,000
+So component is the most generic annotation.
+
+175
+00:14:28,000 --> 00:14:28,000
+Service.
+
+176
+00:14:28,000 --> 00:14:32,000
+Sanitation is a stereotype for the service layer.
+
+177
+00:14:33,000 --> 00:14:38,000
+In our online shop, we have a business layer that contains different services.
+
+178
+00:14:38,000 --> 00:14:47,000
+Unfortunately, I can't show all possible examples at once in one single lesson, but I will show you
+
+179
+00:14:47,000 --> 00:14:49,000
+all examples during the course grade.
+
+180
+00:14:50,000 --> 00:14:55,000
+For now, I want you just to be aware about different annotations.
+
+181
+00:14:56,000 --> 00:15:01,000
+Controller is a stereotype for controller structural element according to NBC.
+
+182
+00:15:01,000 --> 00:15:02,000
+Pardon.
+
+183
+00:15:02,000 --> 00:15:10,000
+In spring MVC and my course go from zero to first job we have learned and we see architectural portal
+
+184
+00:15:11,000 --> 00:15:17,000
+controller annotation is for controller objects is a model view controller architecture.
+
+185
+00:15:17,000 --> 00:15:21,000
+Also specific content rules are applied for controllers.
+
+186
+00:15:22,000 --> 00:15:30,000
+For example dispatcher server that will look for request on classes which are annotated using controller
+
+187
+00:15:30,000 --> 00:15:33,000
+but not with component annotation.
+
+188
+00:15:33,000 --> 00:15:40,000
+What a dispatcher servlet is and what the request mapping is, We'll discuss in a separate lesson for
+
+189
+00:15:40,000 --> 00:15:41,000
+sure.
+
+190
+00:15:41,000 --> 00:15:43,000
+One will come to one of spring.
+
+191
+00:15:43,000 --> 00:15:44,000
+Can we see?
+
+192
+00:15:44,000 --> 00:15:45,000
+We'll get back to this.
+
+193
+00:15:45,000 --> 00:15:51,000
+Annotation repository is a stereotype for persistence layer.
+
+194
+00:15:51,000 --> 00:15:58,000
+For example, we can use this annotation to mark our dog classes as spring beans, for example.
+
+195
+00:15:58,000 --> 00:16:02,000
+Is it clear all of them are used to order the tags?
+
+196
+00:16:02,000 --> 00:16:03,000
+Spring beans.
+
+197
+00:16:03,000 --> 00:16:10,000
+One context canon is enabled and essentially provides the same functionality with respect to dependency
+
+198
+00:16:10,000 --> 00:16:11,000
+injection.
+
+199
+00:16:12,000 --> 00:16:16,000
+The repository also adds component specific behavior.
+
+200
+00:16:16,000 --> 00:16:23,000
+For example, repository annotation is not only helping in annotation based configuration, but also
+
+201
+00:16:23,000 --> 00:16:31,000
+catches platform specific exceptions and throws them as one of the springs unified unchecked exception.
+
+202
+00:16:31,000 --> 00:16:38,000
+Just to remind you, they're not shy to ask your questions below the video and I will be happy to answer.
+
+203
+00:16:38,000 --> 00:16:46,000
+So here I have user two plus because we already have user and I need to show you different similar examples
+
+204
+00:16:46,000 --> 00:16:49,000
+in order it would be easier to compare them.
+
+205
+00:16:50,000 --> 00:16:57,000
+In the component annotation, I can specify component name, but even without specifying component name,
+
+206
+00:16:57,000 --> 00:17:04,000
+spring will use class name with the first character lowercase as a spring bean name.
+
+207
+00:17:04,000 --> 00:17:12,000
+In this particular case, the default name would be user to start from the lowercase, but I want to
+
+208
+00:17:12,000 --> 00:17:15,000
+use user as a name for this component.
+
+209
+00:17:16,000 --> 00:17:20,000
+Let me show you now how we can instantiate this bin.
+
+210
+00:17:20,000 --> 00:17:25,000
+I open the class to the scope demo application context annotations.
+
+211
+00:17:25,000 --> 00:17:30,000
+We will instantiate object of annotation config application context.
+
+212
+00:17:31,000 --> 00:17:39,000
+After that we'll call scan method and we'll pass the base package from where to start scanning.
+
+213
+00:17:40,000 --> 00:17:47,000
+Spring will look types marked with annotations component, but it would also find all types marked with
+
+214
+00:17:47,000 --> 00:17:55,000
+service controller or repository annotations, because as you already saw, those annotations are marked
+
+215
+00:17:55,000 --> 00:17:58,000
+with component annotations too.
+
+216
+00:17:58,000 --> 00:18:06,000
+After holding a scanning, I need to call refresh message on the context object and after that I extract
+
+217
+00:18:06,000 --> 00:18:08,000
+my been its name.
+
+218
+00:18:08,000 --> 00:18:10,000
+It is relatively simple.
+
+219
+00:18:10,000 --> 00:18:11,000
+Do you agree?
+
+220
+00:18:12,000 --> 00:18:18,000
+The next thing that I would like to show you is massive level annotations for configuration of spring
+
+221
+00:18:18,000 --> 00:18:19,000
+bins.
+
+222
+00:18:20,000 --> 00:18:23,000
+I open Klaus is it is called beans configuration.
+
+223
+00:18:24,000 --> 00:18:26,000
+On top of the class name.
+
+224
+00:18:26,000 --> 00:18:28,000
+I have annotation configuration.
+
+225
+00:18:29,000 --> 00:18:37,000
+In this class I can have multiple masses marked with bin annotation and inside the mascot I can configure
+
+226
+00:18:37,000 --> 00:18:39,000
+the bin object that I need.
+
+227
+00:18:39,000 --> 00:18:42,000
+The advantage of such approach is obvious.
+
+228
+00:18:42,000 --> 00:18:49,000
+You can configure bin with java code as you need call all necessary and required methods.
+
+229
+00:18:50,000 --> 00:18:55,000
+When we use bin annotation, Spring will use massive names as being names.
+
+230
+00:18:56,000 --> 00:19:04,000
+So this is the case when you're allowed to violate naming convention for masses and use noun instead
+
+231
+00:19:04,000 --> 00:19:05,000
+of verb.
+
+232
+00:19:05,000 --> 00:19:11,000
+For method name, I will use user to name because we already have user being in the context.
+
+233
+00:19:12,000 --> 00:19:18,000
+Also, you can set the bin name in the annotation and default bin names.
+
+234
+00:19:18,000 --> 00:19:21,000
+It is equal to the method name will be overwritten.
+
+235
+00:19:22,000 --> 00:19:26,000
+Just look at this example like I did here with custom user.
+
+236
+00:19:27,000 --> 00:19:31,000
+Let me get back to the application context annotations clause.
+
+237
+00:19:32,000 --> 00:19:40,000
+And you can see here that I request been from the context I requested user to and custom user in the
+
+238
+00:19:40,000 --> 00:19:41,000
+console.
+
+239
+00:19:41,000 --> 00:19:48,000
+You can see that I receive beans that I have configured because I set different first name and last
+
+240
+00:19:48,000 --> 00:19:48,000
+name.
+
+241
+00:19:49,000 --> 00:19:55,000
+And here I can see first name and last name that I sat in these beans ever since.
+
+242
+00:19:55,000 --> 00:19:56,000
+Clear so far.
+
+243
+00:19:57,000 --> 00:19:58,000
+Okay, let's proceed.
+
+244
+00:19:59,000 --> 00:20:05,000
+Let me now explain to you how word for annotation works, and it is better to do an example.
+
+245
+00:20:06,000 --> 00:20:09,000
+Imagine that we have some interface.
+
+246
+00:20:09,000 --> 00:20:18,000
+For example, we have product interface, and product interface has two implementations, master product
+
+247
+00:20:18,000 --> 00:20:20,000
+and variant product.
+
+248
+00:20:20,000 --> 00:20:25,000
+Master product is just a regular product and variant product.
+
+249
+00:20:25,000 --> 00:20:27,000
+It is like boots.
+
+250
+00:20:27,000 --> 00:20:33,000
+We have one model of boots, but actually there are different sizes and different colors of the same
+
+251
+00:20:33,000 --> 00:20:37,000
+boots and they are variants anyway.
+
+252
+00:20:37,000 --> 00:20:40,000
+The business logic is not critical at the moment.
+
+253
+00:20:40,000 --> 00:20:47,000
+The main thing is that you have one type, for example, some interface and two different implementations,
+
+254
+00:20:48,000 --> 00:20:56,000
+and I use component annotation to mark these types as spring bins and I use qualifier annotation in
+
+255
+00:20:56,000 --> 00:20:57,000
+two types.
+
+256
+00:20:58,000 --> 00:21:05,000
+In the demo clause, you can see example that I can get been also uses the name given in the qualifier
+
+257
+00:21:05,000 --> 00:21:06,000
+annotation.
+
+258
+00:21:07,000 --> 00:21:14,000
+But another goal of using color for annotation is to eliminate the issue of which build needs to be
+
+259
+00:21:14,000 --> 00:21:15,000
+injected.
+
+260
+00:21:16,000 --> 00:21:18,000
+Let me show you another example.
+
+261
+00:21:18,000 --> 00:21:23,000
+Imagine that we have another class that is called Special Offer.
+
+262
+00:21:23,000 --> 00:21:26,000
+And again, guys, this is just examples.
+
+263
+00:21:26,000 --> 00:21:33,000
+Try to put aside all possible details of the business logic at the moment and try to understand the
+
+264
+00:21:33,000 --> 00:21:36,000
+technical details of implementation.
+
+265
+00:21:36,000 --> 00:21:46,000
+So you have some class where you need to inject two different beams of the same type or other way around.
+
+266
+00:21:46,000 --> 00:21:51,000
+You have different classes where you need to use different beams of the same type.
+
+267
+00:21:52,000 --> 00:21:59,000
+In both cases you have different beams of the same type in your content and you need to distinguish
+
+268
+00:21:59,000 --> 00:22:00,000
+them.
+
+269
+00:22:00,000 --> 00:22:08,000
+That's why to inject the specific strain that you need, you can use names specified by the qualifier
+
+270
+00:22:08,000 --> 00:22:10,000
+here in the special offer class.
+
+271
+00:22:10,000 --> 00:22:16,000
+You can see that I used constructor injection with the qualifier annotation.
+
+272
+00:22:16,000 --> 00:22:25,000
+Yes, this is magic of spring and that's actually how injection may be configured with annotations while
+
+273
+00:22:25,000 --> 00:22:27,000
+configuring unzipping.
+
+274
+00:22:27,000 --> 00:22:34,000
+You can ask sprint container to provide you with a necessary beam to construct the object and spring
+
+275
+00:22:34,000 --> 00:22:41,000
+container will manage all the dependencies and sequence of initialization in order to construct objects
+
+276
+00:22:41,000 --> 00:22:42,000
+that you need.
+
+277
+00:22:43,000 --> 00:22:47,000
+Let's get back to the demo application Context annotation class.
+
+278
+00:22:48,000 --> 00:22:56,000
+I get the feel of the special offer and I verify that the beans of master product and variant product
+
+279
+00:22:56,000 --> 00:23:00,000
+were successfully injected into the special offer bin.
+
+280
+00:23:01,000 --> 00:23:08,000
+Because I didn't receive no parental exception and I received plus names that I expected to get.
+
+281
+00:23:08,000 --> 00:23:15,000
+That means that container created beans of my products and injected them into the special offer.
+
+282
+00:23:15,000 --> 00:23:21,000
+Being even despite special offer has two properties of the same type.
+
+283
+00:23:21,000 --> 00:23:26,000
+I managed to inject different beads with the same parent type.
+
+284
+00:23:27,000 --> 00:23:29,000
+That's why qualifier annotation is needed.
+
+285
+00:23:30,000 --> 00:23:31,000
+Isn't this cool?
+
+286
+00:23:32,000 --> 00:23:37,000
+That's how you can manage dependencies between the objects using configurations.
+
+287
+00:23:37,000 --> 00:23:41,000
+So I can say that we are done with none in all possible ways.
+
+288
+00:23:41,000 --> 00:23:43,000
+How you can declare spring bins.
+
+289
+00:23:43,000 --> 00:23:46,000
+These are just first steps of learning spring.
+
+290
+00:23:47,000 --> 00:23:51,000
+This is the basement that we need to have to move further.
+
+291
+00:23:51,000 --> 00:23:59,000
+Probably right now you can't imagine why we need this and how we are going to use all this.
+
+292
+00:23:59,000 --> 00:24:03,000
+But just believe me, you will understand the big picture very, very soon.
+
+293
+00:24:04,000 --> 00:24:11,000
+We're just learning alphabet at the moment and a little bit later will start building words and sentences
+
+294
+00:24:11,000 --> 00:24:12,000
+with the spring.
+
+295
+00:24:13,000 --> 00:24:15,000
+Hope you understood my analogy.
+
+296
+00:24:16,000 --> 00:24:17,000
+Let's move on.
+
+297
+00:24:17,000 --> 00:24:23,000
+Example was a special offer, was an example of sprint dependency injection.
+
+298
+00:24:23,000 --> 00:24:28,000
+We are going to have a separate practical lesson dedicated to sprint injection.
+
+299
+00:24:28,000 --> 00:24:34,000
+I just wanted to show you the purpose of the qualifier annotation because spring dependency injection
+
+300
+00:24:34,000 --> 00:24:36,000
+is a separate big topic to talk about.
+
+301
+00:24:37,000 --> 00:24:40,000
+Stay tuned and we'll discuss it in another lesson.
+
+302
+00:24:41,000 --> 00:24:45,000
+The only thing that we still need to talk about is being scopes.
+
+303
+00:24:46,000 --> 00:24:50,000
+What pre-defined scopes we have in the spring and how is different?
+
+304
+00:24:50,000 --> 00:24:56,000
+We have discussed in the previous lesson, just to remind you what scopes exist.
+
+305
+00:24:56,000 --> 00:25:03,000
+So your prototype, request session, application and web socket.
+
+306
+00:25:04,000 --> 00:25:11,000
+Whereas this can be configured if we use XML configuration, we can use scope attribute of bin element
+
+307
+00:25:11,000 --> 00:25:13,000
+to specify scope.
+
+308
+00:25:13,000 --> 00:25:22,000
+Let me open application context in XML file here you can see that I created B with ID user prototype
+
+309
+00:25:22,000 --> 00:25:28,000
+and it has scope attributes that is equal to prototype instead of prototype.
+
+310
+00:25:28,000 --> 00:25:31,000
+You can use any other scope that you would like to use.
+
+311
+00:25:32,000 --> 00:25:37,000
+Let me now open Demo Bean Scopes class and show you how prototype scope works.
+
+312
+00:25:38,000 --> 00:25:42,000
+I will run this program and we'll walk you through the code example here.
+
+313
+00:25:43,000 --> 00:25:48,000
+I create class, pass XML application context and I request user.
+
+314
+00:25:49,000 --> 00:25:50,000
+Two times in a row.
+
+315
+00:25:51,000 --> 00:25:55,000
+Just to remind you, the default bean scope is singleton.
+
+316
+00:25:55,000 --> 00:26:04,000
+After that, I compare user one and user to references, and as you can see in console the equal, that
+
+317
+00:26:04,000 --> 00:26:10,000
+means that these two references are pointing out to the same object as a heap memory.
+
+318
+00:26:11,000 --> 00:26:17,000
+And when I request two times in a row user prototype being that we can figure it with the prototype
+
+319
+00:26:17,000 --> 00:26:23,000
+scope, I actually receive two different objects because that's how prototype scope works.
+
+320
+00:26:24,000 --> 00:26:24,000
+It returns.
+
+321
+00:26:24,000 --> 00:26:27,000
+You view objects of the same bean.
+
+322
+00:26:27,000 --> 00:26:35,000
+And when I compare user three and user for references, we can see that these two references are pointing
+
+323
+00:26:35,000 --> 00:26:37,000
+out to the different objects.
+
+324
+00:26:37,000 --> 00:26:38,000
+Is it clear?
+
+325
+00:26:39,000 --> 00:26:45,000
+In case you want to recall what other scopes are about, please refer to the previous lesson where I
+
+326
+00:26:45,000 --> 00:26:48,000
+explained in the details how bean scopes are different.
+
+327
+00:26:49,000 --> 00:26:54,000
+In this lesson we are focusing only on the practical part of the implementation.
+
+328
+00:26:55,000 --> 00:27:01,000
+And in case we need to configure scopes with the annotations, we just need to use scope annotation
+
+329
+00:27:02,000 --> 00:27:04,000
+like you see in the user three class.
+
+330
+00:27:05,000 --> 00:27:10,000
+Here you can see that I used scope annotation to configure prototype scope.
+
+331
+00:27:11,000 --> 00:27:15,000
+Let me open now Demo Bin Scopes Annotations Class.
+
+332
+00:27:16,000 --> 00:27:22,000
+Here we have similar example, but just with annotation, config application context and with all the
+
+333
+00:27:22,000 --> 00:27:23,000
+bins.
+
+334
+00:27:23,000 --> 00:27:25,000
+But the example is similar.
+
+335
+00:27:25,000 --> 00:27:30,000
+You can see that the new objects are created for beam with the prototype scope.
+
+336
+00:27:30,000 --> 00:27:33,000
+Each time we call get bin message.
+
+337
+00:27:34,000 --> 00:27:39,000
+I encourage you to download this source code examples and run them on your computer.
+
+338
+00:27:40,000 --> 00:27:43,000
+This will help you to understand the code better.
+
+339
+00:27:44,000 --> 00:27:50,000
+Try to change scopes and play with the code to get better understanding of the topic.
+
+340
+00:27:50,000 --> 00:27:57,000
+And the last but not least, things that I'd like to discuss with you today is a comparison of XML and
+
+341
+00:27:57,000 --> 00:27:59,000
+annotation based configuration.
+
+342
+00:28:00,000 --> 00:28:07,000
+During the video you saw already some basic examples and you have understanding what is the difference
+
+343
+00:28:07,000 --> 00:28:09,000
+between these two types of configuration?
+
+344
+00:28:10,000 --> 00:28:15,000
+Let's just understand the advantages and disadvantages of each approach.
+
+345
+00:28:15,000 --> 00:28:20,000
+Advantage of one approach are disadvantages of another approach and vice versa.
+
+346
+00:28:21,000 --> 00:28:23,000
+Advantages of annotations.
+
+347
+00:28:24,000 --> 00:28:30,000
+The first advantage also information related to the bin is in a single file.
+
+348
+00:28:31,000 --> 00:28:35,000
+You can see both configuration and the source code.
+
+349
+00:28:35,000 --> 00:28:41,000
+There is no need to check XML file for configuration and after that check the source code.
+
+350
+00:28:41,000 --> 00:28:46,000
+This can save some time and may look like simpler approach.
+
+351
+00:28:47,000 --> 00:28:53,000
+The second advantage when you change the class, there is no need to modify the XML file.
+
+352
+00:28:53,000 --> 00:28:56,000
+Thus you have only one file to update.
+
+353
+00:28:56,000 --> 00:29:01,000
+Instead of verifying consistency between the source code and configuration.
+
+354
+00:29:02,000 --> 00:29:06,000
+Disadvantages of annotation base configuration.
+
+355
+00:29:07,000 --> 00:29:13,000
+You mix up source code and configuration, which is not good from the separation of concerns point of
+
+356
+00:29:13,000 --> 00:29:13,000
+view.
+
+357
+00:29:14,000 --> 00:29:19,000
+Nowadays it is a matter of style rather than strict requirement.
+
+358
+00:29:19,000 --> 00:29:25,000
+But some engineers prefer to keep configurations separately from the compiled source code.
+
+359
+00:29:26,000 --> 00:29:30,000
+Advantages of XML file is the first advantage.
+
+360
+00:29:31,000 --> 00:29:34,000
+The separation between the module and its behavior.
+
+361
+00:29:35,000 --> 00:29:37,000
+The second advantage.
+
+362
+00:29:37,000 --> 00:29:40,000
+All the configurations are in one file.
+
+363
+00:29:41,000 --> 00:29:48,000
+You can open application context, XML looks through the file or make some search through the file to
+
+364
+00:29:48,000 --> 00:29:53,000
+find information that you need and to update configurations that you need.
+
+365
+00:29:53,000 --> 00:29:58,000
+Instead of looking through the source code of dozens or hundreds of Java files.
+
+366
+00:29:59,000 --> 00:30:01,000
+Disadvantages of XML file.
+
+367
+00:30:02,000 --> 00:30:10,000
+As your application will grow, your configuration file will grow too, and it is okay to manage relatively
+
+368
+00:30:10,000 --> 00:30:18,000
+not big XML file, but when your XML file will turn into the file with thousands of rows, you may start
+
+369
+00:30:18,000 --> 00:30:26,000
+thinking about separation of configuration into smaller pieces and for example, to put configurations
+
+370
+00:30:26,000 --> 00:30:28,000
+in each class with annotations.
+
+371
+00:30:29,000 --> 00:30:37,000
+All the pros and cons are 100% valid, and at the end of the day it is only you who decide which approach
+
+372
+00:30:37,000 --> 00:30:38,000
+to choose.
+
+373
+00:30:38,000 --> 00:30:46,000
+The main goal is to stay consistent with approach select, making sure everyone on the project follows
+
+374
+00:30:46,000 --> 00:30:47,000
+the same rules.
+
+375
+00:30:48,000 --> 00:30:56,000
+It is also not a question of isare or which one over the other, because you can use any combination
+
+376
+00:30:56,000 --> 00:31:02,000
+of configuration options in your application, one or all combined.
+
+377
+00:31:02,000 --> 00:31:06,000
+You just have to make your rules and stick to them.
+
+378
+00:31:06,000 --> 00:31:08,000
+The main thing is a consistency.
+
+379
+00:31:09,000 --> 00:31:13,000
+Basically, that's all what I wanted to share with you today in the lesson.
+
+380
+00:31:13,000 --> 00:31:16,000
+Let's recap what we have learned today.
+
+381
+00:31:17,000 --> 00:31:23,000
+Today we have learned how to work with the factory and with the application context.
+
+382
+00:31:23,000 --> 00:31:28,000
+Now, you know, what is the difference between being factory and application context on practice?
+
+383
+00:31:29,000 --> 00:31:35,000
+We learn on practice what I see container is and how we can interact and work with it.
+
+384
+00:31:36,000 --> 00:31:43,000
+I showed you how we can work with spring beans, including how to declare them and instantiate in different
+
+385
+00:31:43,000 --> 00:31:44,000
+ways.
+
+386
+00:31:45,000 --> 00:31:49,000
+Now, you know, what is the difference between beloved and bin Laden?
+
+387
+00:31:49,000 --> 00:31:55,000
+In the last movie removed all examples was XML configuration and annotation configuration.
+
+388
+00:31:56,000 --> 00:32:03,000
+After this lesson, you know the difference between these two approaches together with their advantages
+
+389
+00:32:03,000 --> 00:32:04,000
+and disadvantages.
+
+390
+00:32:04,000 --> 00:32:12,000
+We learned such annotations as component sets, controller and repository, and how they're different.
+
+391
+00:32:13,000 --> 00:32:18,000
+Also, we learned being and qualifier annotations on real examples.
+
+392
+00:32:18,000 --> 00:32:25,000
+You understood the difference between the scopes and at the end of the lesson we compare the advantages
+
+393
+00:32:25,000 --> 00:32:29,000
+and disadvantages of XML annotation screen configuration.
+
+394
+00:32:30,000 --> 00:32:32,000
+That's so what I wanted to share with you today.
+
+395
+00:32:32,000 --> 00:32:34,000
+Thanks a lot for your attention.
+
+396
+00:32:34,000 --> 00:32:37,000
+Have a great day and see you in the next lesson.
+
diff --git a/81 - Spring Core/003 Source-code-examples-from-the-lesson.url b/81 - Spring Core/003 Source-code-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..839aadc81b1c22cbf77474f20a46ddd61d5063a8
--- /dev/null
+++ b/81 - Spring Core/003 Source-code-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring/tree/master/src/main/java/com/itbulls/learnit/spring/core/ioc
\ No newline at end of file
diff --git a/81 - Spring Core/003 applicationContext.xml.url b/81 - Spring Core/003 applicationContext.xml.url
new file mode 100644
index 0000000000000000000000000000000000000000..5a9f45d3b85f8f8a4178e1c74c545330d4bcba04
--- /dev/null
+++ b/81 - Spring Core/003 applicationContext.xml.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring/blob/master/src/main/resources/applicationContext.xml
\ No newline at end of file
diff --git a/81 - Spring Core/004 Source-code-examples-from-the-lesson.url b/81 - Spring Core/004 Source-code-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..85452cce7a155ff3c68865d118d3a34b63ff42a4
--- /dev/null
+++ b/81 - Spring Core/004 Source-code-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring/tree/master/src/main/java/com/itbulls/learnit/spring/core/ioc/di
\ No newline at end of file
diff --git a/81 - Spring Core/004 Spring Dependency Injection Practice_en.srt b/81 - Spring Core/004 Spring Dependency Injection Practice_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..613c2d7390f5f6331ee2775ccd3c1134c16f133a
--- /dev/null
+++ b/81 - Spring Core/004 Spring Dependency Injection Practice_en.srt
@@ -0,0 +1,1268 @@
+1
+00:00:06,000 --> 00:00:07,000
+Hello came in this lesson.
+
+2
+00:00:07,000 --> 00:00:13,000
+We are going to have a practical activities and exercises to help you understand dependency injection
+
+3
+00:00:13,000 --> 00:00:14,000
+better.
+
+4
+00:00:14,000 --> 00:00:21,000
+And again, I would like to highlight that it is important you watch lessons one by one because we already
+
+5
+00:00:21,000 --> 00:00:28,000
+have a theoretical lesson where we talked about dependency injection and we also have practical exercise
+
+6
+00:00:28,000 --> 00:00:31,000
+about basic spring configuration.
+
+7
+00:00:31,000 --> 00:00:36,000
+In the lesson we are going to see what a dependency injection is on practice.
+
+8
+00:00:36,000 --> 00:00:43,000
+We are going to learn different types of injection, namely constructor injection, center injection
+
+9
+00:00:43,000 --> 00:00:45,000
+and field injection.
+
+10
+00:00:45,000 --> 00:00:49,000
+I will show you how auto work annotation works.
+
+11
+00:00:49,000 --> 00:00:54,000
+All examples will review with annotation and XML configuration.
+
+12
+00:00:55,000 --> 00:00:58,000
+We'll learn what the value annotation is and when to use it.
+
+13
+00:00:59,000 --> 00:01:04,000
+We'll review what no unique being definition exception is and how we can avoid it.
+
+14
+00:01:05,000 --> 00:01:08,000
+We'll learn how to apply qualifier annotation.
+
+15
+00:01:08,000 --> 00:01:11,000
+Also, we'll talk about primary annotation.
+
+16
+00:01:11,000 --> 00:01:15,000
+Another not long topic, but important one.
+
+17
+00:01:15,000 --> 00:01:19,000
+We will talk about configuration of lazy initialization of our builds.
+
+18
+00:01:20,000 --> 00:01:25,000
+During the lesson, I am going to show you how we can inject the action and map objects.
+
+19
+00:01:25,000 --> 00:01:32,000
+I will show you what an order annotation is and at the end of the lesson we will learn what a lookup
+
+20
+00:01:32,000 --> 00:01:35,000
+annotation is and when we need to use it.
+
+21
+00:01:36,000 --> 00:01:37,000
+Let's start our lesson.
+
+22
+00:01:38,000 --> 00:01:44,000
+Dependency injection is one of the core and fundamental things in this framework.
+
+23
+00:01:44,000 --> 00:01:52,000
+With the help of dependency injection, Spring injects objects into other objects and manage dependencies
+
+24
+00:01:52,000 --> 00:01:53,000
+between them.
+
+25
+00:01:54,000 --> 00:02:00,000
+This helps us to achieve loose coupling of components and moves the responsibility of managing components
+
+26
+00:02:00,000 --> 00:02:02,000
+onto the container.
+
+27
+00:02:02,000 --> 00:02:06,000
+So as we have learned in our theoretical lesson.
+
+28
+00:02:06,000 --> 00:02:14,000
+Dependency injection is a partner we can use to implement ISC, where the control being inverted is
+
+29
+00:02:14,000 --> 00:02:15,000
+set in an object.
+
+30
+00:02:15,000 --> 00:02:19,000
+Dependencies according to the dependency injection part.
+
+31
+00:02:19,000 --> 00:02:27,000
+We connect objects with each other by injecting one object into others, and injecting is done not by
+
+32
+00:02:27,000 --> 00:02:31,000
+the objects but by the assembler itself.
+
+33
+00:02:31,000 --> 00:02:40,000
+In the spring framework by spring ISC container dependency injection in spring can be done through constructors
+
+34
+00:02:40,000 --> 00:02:41,000
+setters or fields.
+
+35
+00:02:42,000 --> 00:02:46,000
+And today in the lesson we are going to review all these approaches.
+
+36
+00:02:46,000 --> 00:02:52,000
+And as I promised you, we're going to have a lot of practical exercises in this lesson.
+
+37
+00:02:52,000 --> 00:02:56,000
+So let me start from the examples and screen sharing.
+
+38
+00:02:56,000 --> 00:03:01,000
+As always, you can find all source code examples in attachments to the video.
+
+39
+00:03:01,000 --> 00:03:06,000
+And I'm going to start with a demo of constructor based injection.
+
+40
+00:03:06,000 --> 00:03:09,000
+I opens a class that is called app config.
+
+41
+00:03:10,000 --> 00:03:12,000
+I have been admin role.
+
+42
+00:03:12,000 --> 00:03:13,000
+Here it is.
+
+43
+00:03:14,000 --> 00:03:18,000
+I create an object of role type with admin role role name.
+
+44
+00:03:19,000 --> 00:03:21,000
+And I have been of admin user.
+
+45
+00:03:22,000 --> 00:03:29,000
+Potentially that admin user is created with admin role when this user being will be instantiated.
+
+46
+00:03:29,000 --> 00:03:38,000
+Spring will create be of admin role first and only after that will inject role into the user.
+
+47
+00:03:39,000 --> 00:03:43,000
+Let me now open class by annotation demo.
+
+48
+00:03:44,000 --> 00:03:48,000
+I create the annotation config application context clause.
+
+49
+00:03:48,000 --> 00:03:50,000
+I scan packages.
+
+50
+00:03:50,000 --> 00:03:56,000
+I will not stop on z slides of code because we reviewed them in our previous lesson.
+
+51
+00:03:56,000 --> 00:04:04,000
+So please just be attentive and I get admin user B and get its row.
+
+52
+00:04:04,000 --> 00:04:11,000
+I run the application and we expect to see admin role name and console to prove that object of admin
+
+53
+00:04:11,000 --> 00:04:15,000
+role has been successfully injected into the user object.
+
+54
+00:04:16,000 --> 00:04:17,000
+Is it clear?
+
+55
+00:04:18,000 --> 00:04:25,000
+So now admin user bean has the reference to the admin role and injection happened through the constructive
+
+56
+00:04:26,000 --> 00:04:31,000
+and you can see that we have constructor in the user for the row object.
+
+57
+00:04:32,000 --> 00:04:36,000
+The simplest thing we can do with the help of XML configuration.
+
+58
+00:04:36,000 --> 00:04:40,000
+Let me open our application context XML file.
+
+59
+00:04:41,000 --> 00:04:49,000
+Here you can see that I created admin role bean and set admin role value to the role name property and
+
+60
+00:04:49,000 --> 00:04:56,000
+after that I create admin user B and the use constructor argument element to inject another bean.
+
+61
+00:04:57,000 --> 00:05:03,000
+You can see that I specify name of the constructor argument and reference to the bean that I would like
+
+62
+00:05:03,000 --> 00:05:04,000
+to inject.
+
+63
+00:05:05,000 --> 00:05:11,000
+In this case, the name should match with the name of the local variable in constructor.
+
+64
+00:05:11,000 --> 00:05:16,000
+You can also inject beans by the sequence number of the constructor argument.
+
+65
+00:05:17,000 --> 00:05:23,000
+The argument constructor would have index zero and in the admin user to be.
+
+66
+00:05:23,000 --> 00:05:26,000
+You can see how I inject admin role.
+
+67
+00:05:26,000 --> 00:05:33,000
+Another way of constructing injecting You can specify times that you want to inject and spring will
+
+68
+00:05:33,000 --> 00:05:37,000
+identify which b you want to inject by matching types.
+
+69
+00:05:38,000 --> 00:05:43,000
+So these are three ways how you can describe constructor injection.
+
+70
+00:05:44,000 --> 00:05:47,000
+Let me now open the AI XML demo.
+
+71
+00:05:47,000 --> 00:05:51,000
+In this class I read XML definition.
+
+72
+00:05:51,000 --> 00:05:58,000
+We have learned how to do this in the previous lesson, so please make sure you don't skip lessons.
+
+73
+00:05:58,000 --> 00:06:05,000
+And after that, I want to extract three beans that we described in different ways and to prove that
+
+74
+00:06:05,000 --> 00:06:13,000
+raw object has been injected successfully, I just refer to that property and print role name to console.
+
+75
+00:06:14,000 --> 00:06:16,000
+Is everything clear so far?
+
+76
+00:06:16,000 --> 00:06:23,000
+Even in case you have some questions, please don't hesitate to ask your questions in comments below
+
+77
+00:06:23,000 --> 00:06:26,000
+the video and I will be happy to answer.
+
+78
+00:06:26,000 --> 00:06:27,000
+Let's continue.
+
+79
+00:06:28,000 --> 00:06:34,000
+Now I'm going to show you Saturn injection for Saturn based dependency injection.
+
+80
+00:06:34,000 --> 00:06:42,000
+The container will call Saturn masses of our class after invoked and no argument Constructor Let me
+
+81
+00:06:42,000 --> 00:06:45,000
+open app config class again here.
+
+82
+00:06:45,000 --> 00:06:51,000
+You can see that to create admin user to begin I inject row we are set and massive.
+
+83
+00:06:52,000 --> 00:06:56,000
+The simplest thing we can make with the help of maximal configuration.
+
+84
+00:06:56,000 --> 00:06:59,000
+Let me open application Context XML file now.
+
+85
+00:07:00,000 --> 00:07:06,000
+You already saw that we can use property element and build description and just set value.
+
+86
+00:07:06,000 --> 00:07:13,000
+But probably you never thought about what mechanism is used here in order to inject the value.
+
+87
+00:07:13,000 --> 00:07:21,000
+The regular set method for property is used to inject the value and instead of the value attribute,
+
+88
+00:07:21,000 --> 00:07:28,000
+we use ref attribute to parse the reference to our bin to make sure that our injection works.
+
+89
+00:07:28,000 --> 00:07:34,000
+Please use the annotations demo and Die XML demo classes.
+
+90
+00:07:34,000 --> 00:07:40,000
+The similar check is present here and you can see the result of code execution in console.
+
+91
+00:07:41,000 --> 00:07:42,000
+Let's move on.
+
+92
+00:07:43,000 --> 00:07:47,000
+Let's now talk about field based dependency injection.
+
+93
+00:07:47,000 --> 00:07:50,000
+In case there is no constructor or setter in the class.
+
+94
+00:07:50,000 --> 00:07:55,000
+Dependency still can be injected by spring using refraction API.
+
+95
+00:07:56,000 --> 00:08:02,000
+If you are not familiar with the refraction API, please refer to my course Java from zero to first
+
+96
+00:08:02,000 --> 00:08:04,000
+job to the section about reflection.
+
+97
+00:08:04,000 --> 00:08:10,000
+Where we reviewed the reflection API in Java is and how we can work with it.
+
+98
+00:08:10,000 --> 00:08:14,000
+Let me create another class here and call it user two.
+
+99
+00:08:15,000 --> 00:08:20,000
+In this class you can see that I have just role field and that's it.
+
+100
+00:08:20,000 --> 00:08:25,000
+As you can see, no setters, no constructors, just gather.
+
+101
+00:08:25,000 --> 00:08:31,000
+In order to prove that injection happen, the field has private modifier.
+
+102
+00:08:31,000 --> 00:08:38,000
+And again, if you're familiar with the Reflection API, you have to be aware that the private modifier
+
+103
+00:08:38,000 --> 00:08:42,000
+is not a problem for reflection API to access the field.
+
+104
+00:08:42,000 --> 00:08:50,000
+I just want to highlight that my role is a component and my user two is also a component.
+
+105
+00:08:51,000 --> 00:08:55,000
+Spring will create all required beams and will identify dependencies.
+
+106
+00:08:55,000 --> 00:09:03,000
+Spring will also identify all the dependencies and will manage the dependencies with the beams available
+
+107
+00:09:03,000 --> 00:09:07,000
+in the container and will inject all the required beams.
+
+108
+00:09:08,000 --> 00:09:15,000
+In this particular case, being of user to and role being will be created and will be present in container.
+
+109
+00:09:16,000 --> 00:09:23,000
+After that spring will identify or to warrant annotation for the role property and we'll check in the
+
+110
+00:09:23,000 --> 00:09:31,000
+container whether there are any role being is available in case zero is such bin Splunk will inject
+
+111
+00:09:31,000 --> 00:09:33,000
+role being into the user object.
+
+112
+00:09:33,000 --> 00:09:34,000
+Is it clear?
+
+113
+00:09:35,000 --> 00:09:36,000
+Let me open the class.
+
+114
+00:09:36,000 --> 00:09:45,000
+The annotations demo in a similar way I request BIM user to and I assign it to the admin user variable.
+
+115
+00:09:45,000 --> 00:09:49,000
+And as you may guess, everything works as expected.
+
+116
+00:09:50,000 --> 00:09:57,000
+This demo is needed just to verify that we don't have any errors and that all objects created successfully.
+
+117
+00:09:58,000 --> 00:10:01,000
+And one more thing that I wanted to draw your attention to.
+
+118
+00:10:01,000 --> 00:10:09,000
+In case you use annotations for being configuration and you don't use XML and you want to set some default
+
+119
+00:10:09,000 --> 00:10:16,000
+value for this, you can use value annotation like ID is a row component.
+
+120
+00:10:16,000 --> 00:10:18,000
+Let me show it to you.
+
+121
+00:10:18,000 --> 00:10:22,000
+You can use this annotation to pass an expression here.
+
+122
+00:10:23,000 --> 00:10:24,000
+Okay.
+
+123
+00:10:24,000 --> 00:10:27,000
+We saw how we used auto wire annotation.
+
+124
+00:10:28,000 --> 00:10:32,000
+Let's learn more about auto wiring in the XML configuration.
+
+125
+00:10:32,000 --> 00:10:37,000
+I open application context XML file and I declare another bean.
+
+126
+00:10:38,000 --> 00:10:41,000
+This bean definition has whatever attribute.
+
+127
+00:10:42,000 --> 00:10:45,000
+Let's learn what values we can use in this attribute.
+
+128
+00:10:46,000 --> 00:10:50,000
+There are four modes of auto being using an XML configuration.
+
+129
+00:10:51,000 --> 00:10:53,000
+No is the default value.
+
+130
+00:10:53,000 --> 00:11:01,000
+This means no auto wiring is used for the bean and we have to explicitly names the dependencies by name.
+
+131
+00:11:02,000 --> 00:11:05,000
+Auto wiring is done based on the name of the property.
+
+132
+00:11:05,000 --> 00:11:14,000
+Therefore, Sprint will look for a beam with the same name as property that needs to be set by type
+
+133
+00:11:14,000 --> 00:11:19,000
+similar to the by name of the wiring only based on the type of the property.
+
+134
+00:11:20,000 --> 00:11:25,000
+This means spring will look for a beam with the same type of the property to set.
+
+135
+00:11:25,000 --> 00:11:31,000
+If there is more than one beam of that type, the framework throws an exception.
+
+136
+00:11:31,000 --> 00:11:32,000
+Constructor.
+
+137
+00:11:33,000 --> 00:11:40,000
+Auto wiring is done based on constructor arguments, meaning spring will look for beams with the same
+
+138
+00:11:40,000 --> 00:11:42,000
+type as the constructor arguments.
+
+139
+00:11:42,000 --> 00:11:49,000
+But what will happen in case there are more than one being that is compatible by type with dependency.
+
+140
+00:11:50,000 --> 00:11:51,000
+Let's imagine the next case.
+
+141
+00:11:52,000 --> 00:11:58,000
+Just imagine that we have role interface and two implementations of the interface.
+
+142
+00:11:59,000 --> 00:12:05,000
+Please don't ask questions regarding business logic and why we implement role interface.
+
+143
+00:12:05,000 --> 00:12:11,000
+Just take this as an abstract example because there can be different cases like this.
+
+144
+00:12:12,000 --> 00:12:19,000
+I open class ample role for employees and customer role for our customers.
+
+145
+00:12:19,000 --> 00:12:27,000
+As you can see, both of these classes implements role interface, so they are compatible.
+
+146
+00:12:28,000 --> 00:12:37,000
+And now the question is object of which type will be injected into my user three bin into the role property
+
+147
+00:12:37,000 --> 00:12:39,000
+of role interface type.
+
+148
+00:12:40,000 --> 00:12:46,000
+By the way, as you can see here, I can use all the word annotation above the constructor.
+
+149
+00:12:47,000 --> 00:12:55,000
+Also, I can use auto word annotation with setter that would describe the way of how injection will
+
+150
+00:12:55,000 --> 00:13:02,000
+be done is with the help of reflection API or a constructor or with a set of massive.
+
+151
+00:13:03,000 --> 00:13:09,000
+So we have two bees of the compatible type, which one will be selected and inject it.
+
+152
+00:13:10,000 --> 00:13:13,000
+Let's run the dialog station's demo program.
+
+153
+00:13:13,000 --> 00:13:20,000
+And in the console you can see that when I just get user three being from the container, I have no
+
+154
+00:13:20,000 --> 00:13:26,000
+unique being definition exception because Sprint can't understand which build to inject.
+
+155
+00:13:27,000 --> 00:13:30,000
+What if I need to inject ample role here?
+
+156
+00:13:30,000 --> 00:13:39,000
+What I have to do in this case, we need to inject specific being where we use auto word annotation.
+
+157
+00:13:40,000 --> 00:13:43,000
+You can use qualified annotation for that.
+
+158
+00:13:43,000 --> 00:13:47,000
+We removed for annotation in the previous lesson.
+
+159
+00:13:47,000 --> 00:13:50,000
+Let me show it in scope of this example.
+
+160
+00:13:51,000 --> 00:13:56,000
+So in the user three class I can use qualifier annotation.
+
+161
+00:13:56,000 --> 00:14:02,000
+In the previous lesson you already saw how we use qualifier notation near the constructor parameters.
+
+162
+00:14:03,000 --> 00:14:08,000
+In the same way we can use it as a massive parameters like you see here.
+
+163
+00:14:09,000 --> 00:14:13,000
+We can also use it as a field with all of our annotation.
+
+164
+00:14:13,000 --> 00:14:17,000
+You can select the place for this annotation as you wish.
+
+165
+00:14:18,000 --> 00:14:23,000
+Let me commend the private sector and on command you set a massive.
+
+166
+00:14:24,000 --> 00:14:32,000
+Let's now get back to the guy on the -- demo and run the program one more time, then cancel.
+
+167
+00:14:32,000 --> 00:14:37,000
+You can see that this time ample role object has been injected.
+
+168
+00:14:37,000 --> 00:14:42,000
+Can I do anything else to avoid no unique definition exception?
+
+169
+00:14:42,000 --> 00:14:43,000
+Actually, yes.
+
+170
+00:14:43,000 --> 00:14:46,000
+I can use primary annotation.
+
+171
+00:14:46,000 --> 00:14:53,000
+In spring framework, the primary annotation is used to give higher preference to being when there are
+
+172
+00:14:53,000 --> 00:14:55,000
+multiple means of same type.
+
+173
+00:14:55,000 --> 00:15:03,000
+The primary notation may be used on any class, directly or indirectly annotated with component or on
+
+174
+00:15:03,000 --> 00:15:04,000
+masses.
+
+175
+00:15:04,000 --> 00:15:05,000
+Annotated was been.
+
+176
+00:15:06,000 --> 00:15:10,000
+Let me now try to command the setter with a qualified annotation.
+
+177
+00:15:11,000 --> 00:15:15,000
+After that I uncommon setter was just at the connotation.
+
+178
+00:15:15,000 --> 00:15:24,000
+I also command primary annotation in the ample role class and execute our example one more time and
+
+179
+00:15:24,000 --> 00:15:31,000
+you can see that code is executed without any exceptions and the ample role being has been injected
+
+180
+00:15:31,000 --> 00:15:38,000
+since it has priority of a customer role based on our configuration that we specify.
+
+181
+00:15:39,000 --> 00:15:46,000
+Now you know how to use no unique being definition exception and how to rope with qualifier and primary
+
+182
+00:15:46,000 --> 00:15:47,000
+annotations.
+
+183
+00:15:48,000 --> 00:15:54,000
+And with regards to other word annotation, also small but important thing.
+
+184
+00:15:55,000 --> 00:16:02,000
+Usually if you put out a word on a patient, that means that some beans that's supposed to be injected
+
+185
+00:16:02,000 --> 00:16:07,000
+should be present in the container in case such being is not found.
+
+186
+00:16:07,000 --> 00:16:14,000
+You are going to see the exception in case the injection is not required and should be treated like
+
+187
+00:16:14,000 --> 00:16:15,000
+optional.
+
+188
+00:16:15,000 --> 00:16:23,000
+In this case, in Ottawa notation you should specify required force attribute like you can see in the
+
+189
+00:16:23,000 --> 00:16:27,000
+command the connotation here in the user three plus.
+
+190
+00:16:27,000 --> 00:16:29,000
+Let's continue.
+
+191
+00:16:29,000 --> 00:16:36,000
+Let me also share with you one little thing, because it is really so minor that this doesn't work for
+
+192
+00:16:36,000 --> 00:16:39,000
+a separate lesson but still can be very useful.
+
+193
+00:16:39,000 --> 00:16:46,000
+By default, the container creates and configures all singleton bins during initialization.
+
+194
+00:16:47,000 --> 00:16:54,000
+So with this we can use the lazy init attribute with value true on the beam configuration in the application
+
+195
+00:16:54,000 --> 00:16:56,000
+context xml file.
+
+196
+00:16:56,000 --> 00:17:03,000
+You can see how I used this attribute in the definition of the admin user file.
+
+197
+00:17:03,000 --> 00:17:05,000
+Just to let you know.
+
+198
+00:17:05,000 --> 00:17:08,000
+Let's continue with the next thing.
+
+199
+00:17:09,000 --> 00:17:13,000
+Let's understand now how we can inject collections and maps.
+
+200
+00:17:14,000 --> 00:17:18,000
+Imagine that for our user beans that we describe in the class.
+
+201
+00:17:18,000 --> 00:17:23,000
+User four we need to store collection of order IDs.
+
+202
+00:17:24,000 --> 00:17:26,000
+These are orders of the user.
+
+203
+00:17:26,000 --> 00:17:29,000
+For example, again, imaginary case.
+
+204
+00:17:29,000 --> 00:17:35,000
+In order to inject collection, we can use the same annotation that we have just removed.
+
+205
+00:17:35,000 --> 00:17:43,000
+Let's declare a field of type leased parameterized by string type and let's add auto word annotation
+
+206
+00:17:43,000 --> 00:17:44,000
+on top of it.
+
+207
+00:17:44,000 --> 00:17:48,000
+The good news is that you can use generic types for auto wiring.
+
+208
+00:17:49,000 --> 00:17:56,000
+Spring lets us use a generic type as a qualifier without the need for an explicit annotation since version
+
+209
+00:17:56,000 --> 00:17:57,000
+four.
+
+210
+00:17:58,000 --> 00:18:00,000
+Let me open app config class now.
+
+211
+00:18:01,000 --> 00:18:10,000
+In this class I declare another bill of type list and name like property in our user class order IDs.
+
+212
+00:18:10,000 --> 00:18:16,000
+This method will return list of elements that I would like to inject, but actually even in the case
+
+213
+00:18:16,000 --> 00:18:18,000
+the name would be different.
+
+214
+00:18:18,000 --> 00:18:25,000
+Spring still will be able to inject this list into the user for me because spring will detect compatible
+
+215
+00:18:25,000 --> 00:18:26,000
+types.
+
+216
+00:18:27,000 --> 00:18:37,000
+Now let me open the demo class and I will try to get user for being from container and print order IDs
+
+217
+00:18:38,000 --> 00:18:39,000
+as you can see.
+
+218
+00:18:39,000 --> 00:18:47,000
+So everything works as expected and we managed to inject list of strings successfully and obviously
+
+219
+00:18:47,000 --> 00:18:53,000
+you can inject collection using the constructor while constructing your beam.
+
+220
+00:18:53,000 --> 00:18:56,000
+Let me open app config class.
+
+221
+00:18:56,000 --> 00:19:00,000
+You can see how I configured the user with list.
+
+222
+00:19:00,000 --> 00:19:03,000
+So basically nothing special.
+
+223
+00:19:03,000 --> 00:19:08,000
+Like this, you can inject any least set left or map.
+
+224
+00:19:08,000 --> 00:19:09,000
+It is up to you.
+
+225
+00:19:10,000 --> 00:19:13,000
+Use constructor injection to inject whatever you need.
+
+226
+00:19:14,000 --> 00:19:21,000
+Let's learn how we can configure corrections on that injection with the help of XML configuration.
+
+227
+00:19:21,000 --> 00:19:26,000
+I created a class that is called Java Collection Injection demo.
+
+228
+00:19:27,000 --> 00:19:28,000
+Let me show it to you.
+
+229
+00:19:29,000 --> 00:19:35,000
+As you can see in this class, we have different properties of type, least sad map and properties.
+
+230
+00:19:36,000 --> 00:19:39,000
+And also I have getters and setters.
+
+231
+00:19:39,000 --> 00:19:43,000
+Let's configure this being with the XML configuration.
+
+232
+00:19:43,000 --> 00:19:46,000
+Ends application contacts XML file.
+
+233
+00:19:46,000 --> 00:19:49,000
+You can find definitions of Java collection bin.
+
+234
+00:19:50,000 --> 00:19:54,000
+You can see that I injected values into each property.
+
+235
+00:19:54,000 --> 00:19:59,000
+For example, to inject list elements I have leased.
+
+236
+00:19:59,000 --> 00:20:04,000
+Element to inject set elements I have set element.
+
+237
+00:20:04,000 --> 00:20:12,000
+Also, I have mapped with the entry elements and props with prop element to describe key value pairs.
+
+238
+00:20:12,000 --> 00:20:18,000
+Obviously, in each case you can inject not just three values, but be references.
+
+239
+00:20:19,000 --> 00:20:28,000
+Use hotkeys control space to see suggestions here and you will find that you can use ref attribute to
+
+240
+00:20:28,000 --> 00:20:31,000
+inject the references in the class.
+
+241
+00:20:31,000 --> 00:20:35,000
+GUI xml you can find is a demo of this bin.
+
+242
+00:20:36,000 --> 00:20:41,000
+Always remember that in attachments to the lesson you find the reference to the source code.
+
+243
+00:20:42,000 --> 00:20:47,000
+Feel free to download the code on your local computer and execute it on your machine.
+
+244
+00:20:48,000 --> 00:20:53,000
+Navigate between the files to understand better how this code works.
+
+245
+00:20:53,000 --> 00:20:58,000
+Let's know now what an order annotation is and when we need to use it.
+
+246
+00:20:59,000 --> 00:21:02,000
+Imagine that you have type that is called priority.
+
+247
+00:21:03,000 --> 00:21:09,000
+Priority is an interface and thus we are the types that implements this interface.
+
+248
+00:21:10,000 --> 00:21:16,000
+Like in our example, we have high priority, medium priority and low priority.
+
+249
+00:21:17,000 --> 00:21:22,000
+Each priority implements mass get priority run according to interface.
+
+250
+00:21:23,000 --> 00:21:30,000
+And now imagine that I need to gather all priorities in one list, and moreover, I need to gather them
+
+251
+00:21:30,000 --> 00:21:32,000
+in the specific order.
+
+252
+00:21:32,000 --> 00:21:34,000
+How I can do that.
+
+253
+00:21:34,000 --> 00:21:42,000
+Each of the priority implementation is a component, as you can see, and each of these types has also
+
+254
+00:21:42,000 --> 00:21:43,000
+order annotation.
+
+255
+00:21:44,000 --> 00:21:48,000
+Order is used to specify the order of injection.
+
+256
+00:21:49,000 --> 00:21:56,000
+We can use constants like highest precedence from the ordered interface or lowest precedence, which
+
+257
+00:21:56,000 --> 00:21:59,000
+specifies the sequence number of injection, for example.
+
+258
+00:22:00,000 --> 00:22:05,000
+In our annotations demo I auto word list of priorities.
+
+259
+00:22:05,000 --> 00:22:12,000
+Spring is smart enough to understand that in this property you want to gather all components that are
+
+260
+00:22:12,000 --> 00:22:14,000
+compatible with priority type.
+
+261
+00:22:15,000 --> 00:22:22,000
+By the way, this is just another way of how to inject collection of values and the order annotation
+
+262
+00:22:22,000 --> 00:22:27,000
+helps us to inject our beams into the list in the specific order.
+
+263
+00:22:28,000 --> 00:22:34,000
+In the main method, when I get the reference to the injected collection and iterate over it.
+
+264
+00:22:34,000 --> 00:22:42,000
+I pruned the priority run of each object and in console you can see that all items are injected not
+
+265
+00:22:42,000 --> 00:22:45,000
+in the random but in the specific order.
+
+266
+00:22:45,000 --> 00:22:47,000
+Is it clear?
+
+267
+00:22:47,000 --> 00:22:53,000
+Even in case you have any questions, please do not hesitate to ask your questions in comments to the
+
+268
+00:22:53,000 --> 00:22:57,000
+video and I will be happy to answer those.
+
+269
+00:22:58,000 --> 00:23:02,000
+And the last but not the least, think for today that I'd like to show you this.
+
+270
+00:23:02,000 --> 00:23:03,000
+Look up annotation.
+
+271
+00:23:04,000 --> 00:23:05,000
+When do we need it?
+
+272
+00:23:06,000 --> 00:23:13,000
+Imagine that you declared a bean with Singleton's code and that bill has dependency on another bill's
+
+273
+00:23:13,000 --> 00:23:14,000
+prototype scope.
+
+274
+00:23:14,000 --> 00:23:21,000
+Then the logical question is how will our singletons spring bill access this prototype?
+
+275
+00:23:21,000 --> 00:23:22,000
+Spring beans.
+
+276
+00:23:23,000 --> 00:23:26,000
+Here's where Luke Configuration can help us.
+
+277
+00:23:26,000 --> 00:23:33,000
+Spring will override our annotated method and use our methods return type and parameter as arguments
+
+278
+00:23:33,000 --> 00:23:34,000
+could be in factory.
+
+279
+00:23:34,000 --> 00:23:36,000
+Get bin message.
+
+280
+00:23:37,000 --> 00:23:40,000
+Let me show you an example and you will understand.
+
+281
+00:23:41,000 --> 00:23:47,000
+Imagine that we have class that is called user messenger and it has properties.
+
+282
+00:23:47,000 --> 00:23:54,000
+The scope message user messenger being will be a single thought and message will be a prototype.
+
+283
+00:23:55,000 --> 00:24:01,000
+How to ensure that message be will be new object Each time we refer to this property.
+
+284
+00:24:02,000 --> 00:24:03,000
+Let me show it to.
+
+285
+00:24:04,000 --> 00:24:06,000
+First of all, here is message.
+
+286
+00:24:06,000 --> 00:24:14,000
+Object was the prototype scope and in the user messenger, let's create a lookup mask which tells us
+
+287
+00:24:14,000 --> 00:24:15,000
+a message type.
+
+288
+00:24:16,000 --> 00:24:20,000
+Pay attention that you don't need to implement this method.
+
+289
+00:24:20,000 --> 00:24:22,000
+This is just a setup.
+
+290
+00:24:22,000 --> 00:24:30,000
+Spring framework will override all methods marked with the lookup annotation to extract from the container
+
+291
+00:24:30,000 --> 00:24:31,000
+new builds.
+
+292
+00:24:32,000 --> 00:24:34,000
+Let's now test this.
+
+293
+00:24:34,000 --> 00:24:43,000
+I open class die annotations demo here the bottom I create your messenger bin and after that I call
+
+294
+00:24:43,000 --> 00:24:46,000
+get message twice and to prove use it.
+
+295
+00:24:46,000 --> 00:24:51,000
+I receive references to the new objects but not the same objects.
+
+296
+00:24:51,000 --> 00:24:53,000
+I will just compare the references.
+
+297
+00:24:54,000 --> 00:24:55,000
+Let me run the program.
+
+298
+00:24:55,000 --> 00:24:59,000
+And so we see that we received false here.
+
+299
+00:24:59,000 --> 00:25:07,000
+When we compare the references, that means that each time I call get message method, I receive the
+
+300
+00:25:07,000 --> 00:25:09,000
+reference to the new object.
+
+301
+00:25:09,000 --> 00:25:10,000
+Is it clear?
+
+302
+00:25:11,000 --> 00:25:16,000
+That's how lookup annotation can help us in the configuration of our dependency injection.
+
+303
+00:25:17,000 --> 00:25:20,000
+That's all what I wanted to share with you in this lesson.
+
+304
+00:25:21,000 --> 00:25:24,000
+Let's recap what we have learned today.
+
+305
+00:25:25,000 --> 00:25:28,000
+In the lesson we learned what a dependency injection is.
+
+306
+00:25:29,000 --> 00:25:34,000
+Now you know what the constructive injection, the injection and field injection are.
+
+307
+00:25:34,000 --> 00:25:39,000
+We reviewed all examples with annotation and XML configuration.
+
+308
+00:25:40,000 --> 00:25:42,000
+Now you know what the value annotation is.
+
+309
+00:25:43,000 --> 00:25:45,000
+We learned all the wiring in the lesson.
+
+310
+00:25:46,000 --> 00:25:50,000
+I showed you how to deal with no unique build definition exception.
+
+311
+00:25:50,000 --> 00:25:54,000
+We discussed qualifier and primary annotations.
+
+312
+00:25:54,000 --> 00:25:58,000
+I showed you how to configure the lazy initialization of the bin.
+
+313
+00:25:58,000 --> 00:26:03,000
+Also, we learned how to inject collection and map object into the bin.
+
+314
+00:26:04,000 --> 00:26:09,000
+And at the end of the lesson we learn what an order and lookup annotations are.
+
+315
+00:26:10,000 --> 00:26:12,000
+That's all for this lesson.
+
+316
+00:26:12,000 --> 00:26:14,000
+Thanks a lot for your attention.
+
+317
+00:26:14,000 --> 00:26:17,000
+Have a great day and see you in the next lesson.
+
diff --git a/81 - Spring Core/external-links.txt b/81 - Spring Core/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..48b952923ef636e090a46e458cbd8f2981203b5b
--- /dev/null
+++ b/81 - Spring Core/external-links.txt
@@ -0,0 +1,18 @@
+
+001 Official-Site-of-Spring
+https://spring.io
+
+001 List-of-Spring-projects
+https://spring.io/projects
+
+001 Spring-Initializr
+https://start.spring.io/
+
+003 Source-code-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-spring/tree/master/src/main/java/com/itbulls/learnit/spring/core/ioc
+
+003 applicationContext.xml
+https://github.com/AndriiPiatakha/java-learnit-spring/blob/master/src/main/resources/applicationContext.xml
+
+004 Source-code-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-spring/tree/master/src/main/java/com/itbulls/learnit/spring/core/ioc/di
diff --git a/82 - Spring MVC & Spring for WEB/001 Commit-with-the-changes-for-this-lesson.url b/82 - Spring MVC & Spring for WEB/001 Commit-with-the-changes-for-this-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..857001f79daa5c68b08673b16865a0f045a498e0
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/001 Commit-with-the-changes-for-this-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/9473121ad8a02e27bbb26c423100a7ddf4dea060
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/001 Java-Spring-MVC-source-code-examples-from-the-lesson-Repository.url b/82 - Spring MVC & Spring for WEB/001 Java-Spring-MVC-source-code-examples-from-the-lesson-Repository.url
new file mode 100644
index 0000000000000000000000000000000000000000..4a56635ac9a9a618840e4838115e15d15a4c4809
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/001 Java-Spring-MVC-source-code-examples-from-the-lesson-Repository.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/001 Spring MVC Overview & First Project_en.srt b/82 - Spring MVC & Spring for WEB/001 Spring MVC Overview & First Project_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..341a7e4d97aa951a281e8ec0ced5fc5fc14dd866
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/001 Spring MVC Overview & First Project_en.srt
@@ -0,0 +1,1544 @@
+1
+00:00:06,000 --> 00:00:07,000
+Hello, team.
+
+2
+00:00:07,000 --> 00:00:11,000
+With this lesson, we start learning spring framework for web applications.
+
+3
+00:00:11,000 --> 00:00:15,000
+There is a wide range of approaches in web applications development.
+
+4
+00:00:16,000 --> 00:00:22,000
+To proceed with this lesson, you need to be familiar with the World Wide Web concept and have basic
+
+5
+00:00:22,000 --> 00:00:25,000
+understanding of Java servlet.
+
+6
+00:00:25,000 --> 00:00:33,000
+We are going to start the lesson from the overview of what spring MVC is and why we need will quickly
+
+7
+00:00:33,000 --> 00:00:35,000
+remember what MVC pattern is.
+
+8
+00:00:36,000 --> 00:00:42,000
+Also in this lesson, we're going to talk about front controller design pattern and you will understand
+
+9
+00:00:42,000 --> 00:00:46,000
+what this point is about and what this Posture servlet is.
+
+10
+00:00:47,000 --> 00:00:55,000
+After that, I'm going to explain the flow of problem execution in Spring MVC, and once we learn theory,
+
+11
+00:00:55,000 --> 00:00:57,000
+we'll jump to practical example.
+
+12
+00:00:58,000 --> 00:01:03,000
+In this lesson, we are going to create our Hello World Spring Web project.
+
+13
+00:01:03,000 --> 00:01:07,000
+You're going to learn new spring configuration for Web applications.
+
+14
+00:01:07,000 --> 00:01:13,000
+In this lesson, we'll learn such annotations as request mapping and enable web.
+
+15
+00:01:13,000 --> 00:01:20,000
+And we see we're going to configure view resolver BIM, and we'll learn interfaces and classes that
+
+16
+00:01:20,000 --> 00:01:24,000
+are needed for spring web application configuration.
+
+17
+00:01:24,000 --> 00:01:29,000
+And at the end of the lesson, we're going to make a summary of all advantages of spring.
+
+18
+00:01:29,000 --> 00:01:32,000
+And we see let's start our lesson.
+
+19
+00:01:33,000 --> 00:01:39,000
+So before diving deeper into the rest services and the complex web application, we are going to learn
+
+20
+00:01:39,000 --> 00:01:46,000
+some basics and fundamentals about spring web application configuration and Spring MVC.
+
+21
+00:01:46,000 --> 00:01:53,000
+It is important you are familiar with MVC Design Portal in order to understand the general terminology
+
+22
+00:01:53,000 --> 00:01:59,000
+that we are going to use in the lesson, just in case you can find the lesson about spring and the key
+
+23
+00:01:59,000 --> 00:02:04,000
+point in my course, Java from zero to first job from this course.
+
+24
+00:02:04,000 --> 00:02:12,000
+You already learned that spring AVC is a separate project and why we start learning spring for web development
+
+25
+00:02:12,000 --> 00:02:13,000
+with the spring MVC.
+
+26
+00:02:14,000 --> 00:02:20,000
+The Spring MVC framework is the foundation of the building web application.
+
+27
+00:02:20,000 --> 00:02:28,000
+With Spring, it covers a wide range of web applications from traditional MVC style applications all
+
+28
+00:02:28,000 --> 00:02:31,000
+the way to stateless rest APIs.
+
+29
+00:02:32,000 --> 00:02:34,000
+Let's load spring and we see better.
+
+30
+00:02:35,000 --> 00:02:38,000
+It follows the model view controller design pattern.
+
+31
+00:02:38,000 --> 00:02:44,000
+It implements all the basic features of a core spring framework like inversion of control dependency
+
+32
+00:02:44,000 --> 00:02:51,000
+injection, and we already learned what an inversion of control and dependency injection are and we
+
+33
+00:02:51,000 --> 00:02:53,000
+learn them on practice.
+
+34
+00:02:53,000 --> 00:03:00,000
+Feel free to watch previous lessons from this course if you want to refresh the knowledge and the systems
+
+35
+00:03:00,000 --> 00:03:06,000
+for model view controller, let's just quickly remember why we need this separation of concerns and
+
+36
+00:03:06,000 --> 00:03:09,000
+what element is responsible for what.
+
+37
+00:03:10,000 --> 00:03:14,000
+Model and model contains the data of the application.
+
+38
+00:03:14,000 --> 00:03:20,000
+The model component corresponds to all the data related logic that the user works with.
+
+39
+00:03:21,000 --> 00:03:28,000
+This can represent easy the data that is being transferred between the view and controller components
+
+40
+00:03:28,000 --> 00:03:36,000
+or any other business logic related data and data can be a single object or a collection of objects.
+
+41
+00:03:37,000 --> 00:03:37,000
+Controller.
+
+42
+00:03:38,000 --> 00:03:42,000
+A controller contains the business logic of an application.
+
+43
+00:03:42,000 --> 00:03:49,000
+Controllers act as an interface between model and view components to process all the business logic
+
+44
+00:03:49,000 --> 00:03:51,000
+and in common requests.
+
+45
+00:03:51,000 --> 00:04:00,000
+Manipulate data using model, component and interact with the views to render the final output view.
+
+46
+00:04:00,000 --> 00:04:05,000
+A view represents the provided information in a particular format.
+
+47
+00:04:06,000 --> 00:04:11,000
+The view component is issued for all UI logic of the application.
+
+48
+00:04:12,000 --> 00:04:21,000
+Usually we use HTML, CSS, JavaScript, GSP plus G, Steel and other technologies to create a view
+
+49
+00:04:21,000 --> 00:04:22,000
+page.
+
+50
+00:04:22,000 --> 00:04:32,000
+Spring also supports other view technologies such as Apache Velocity, Simile and Freemark, but I can
+
+51
+00:04:32,000 --> 00:04:37,000
+state that they are popular enough in order to spend a lot of time on learning them.
+
+52
+00:04:38,000 --> 00:04:40,000
+Please don't take me wrong.
+
+53
+00:04:40,000 --> 00:04:42,000
+I'm not saying that same leaf is bad.
+
+54
+00:04:42,000 --> 00:04:46,000
+It is also a great technology which is worthy of your attention.
+
+55
+00:04:46,000 --> 00:04:51,000
+Just based on my experience and experience of my students on the market.
+
+56
+00:04:51,000 --> 00:05:00,000
+Currently, there is more preference to React vs Angular and sometimes GSP with GST l for the view from
+
+57
+00:05:00,000 --> 00:05:01,000
+10th poor.
+
+58
+00:05:02,000 --> 00:05:06,000
+But things are changing quickly in the world anyway.
+
+59
+00:05:06,000 --> 00:05:12,000
+Understanding the concept, you will understand different frameworks and technologies.
+
+60
+00:05:12,000 --> 00:05:16,000
+The main thing is to understand core principles.
+
+61
+00:05:16,000 --> 00:05:22,000
+One of the key principles in spring and we see is a concept of the front controller.
+
+62
+00:05:23,000 --> 00:05:30,000
+The front controller software design pattern is listed in several quadrant catalogs and related to the
+
+63
+00:05:30,000 --> 00:05:32,000
+design of web applications.
+
+64
+00:05:32,000 --> 00:05:40,000
+It is a controller that handles all requests for a website which is useful structure for web application
+
+65
+00:05:40,000 --> 00:05:50,000
+developers to achieve flexibility and re-use without code redundancy in spring Web MVC, the dispatcher
+
+66
+00:05:50,000 --> 00:05:50,000
+said.
+
+67
+00:05:50,000 --> 00:05:53,000
+Klaus works as a phone controller.
+
+68
+00:05:53,000 --> 00:06:00,000
+It is responsible to manage the flow of the spring MVC application, in other and simple words.
+
+69
+00:06:01,000 --> 00:06:05,000
+Imagine regular server that do remember what a server is.
+
+70
+00:06:06,000 --> 00:06:13,000
+In case you don't remember what a servlet is, you definitely need to remember this by watching my course
+
+71
+00:06:13,000 --> 00:06:14,000
+for Java web developers.
+
+72
+00:06:15,000 --> 00:06:23,000
+So this purchasing that is a class that receives in common request and maps it to the right resource
+
+73
+00:06:23,000 --> 00:06:27,000
+such as controllers, models and views.
+
+74
+00:06:27,000 --> 00:06:33,000
+On this simple illustration, you can see the flow of execution in spring MVC.
+
+75
+00:06:33,000 --> 00:06:40,000
+And then once you understand the theory first, before we jump to practical exercises, as you can see
+
+76
+00:06:40,000 --> 00:06:48,000
+on this slide, all in common requests intercept by our phone controller, by the dispatcher server.
+
+77
+00:06:49,000 --> 00:06:50,000
+What happens next?
+
+78
+00:06:51,000 --> 00:06:55,000
+Spring stores is a configuration with the list of all controllers.
+
+79
+00:06:55,000 --> 00:07:02,000
+If you remember our lesson about basic beans configuration, you should remember controller annotation.
+
+80
+00:07:02,000 --> 00:07:12,000
+So the controller is also a component and its lifecycle is managed by spring container and spring knows
+
+81
+00:07:12,000 --> 00:07:15,000
+the mapping of each controller.
+
+82
+00:07:15,000 --> 00:07:25,000
+So DISPATCHER Servlet for request to the controller that is supposed to process the request Spring stores
+
+83
+00:07:25,000 --> 00:07:31,000
+URL mapping with classes and masses that should be involved.
+
+84
+00:07:32,000 --> 00:07:40,000
+The controller component prepares model actually data that can be passed further to the view.
+
+85
+00:07:40,000 --> 00:07:46,000
+There are different ways of how you can write methods in controller and what they can return.
+
+86
+00:07:47,000 --> 00:07:55,000
+For example, they can return model and view object, or they can return just the name of the view,
+
+87
+00:07:56,000 --> 00:07:59,000
+or they can return a raw response body.
+
+88
+00:07:59,000 --> 00:08:04,000
+It depends on the configuration and what we would like to achieve.
+
+89
+00:08:05,000 --> 00:08:09,000
+All these edge cases and examples we are going to learn in practice.
+
+90
+00:08:10,000 --> 00:08:17,000
+Based on the answer from controller, the dispatcher servlet uses view resolver to resolve the view.
+
+91
+00:08:17,000 --> 00:08:25,000
+Because on this stage we need to understand how response will look like and what we need to send back
+
+92
+00:08:25,000 --> 00:08:25,000
+to the client.
+
+93
+00:08:26,000 --> 00:08:32,000
+I believe that by this moment you already have high level understanding of spring and we see now it
+
+94
+00:08:32,000 --> 00:08:36,000
+is time to understand better with the code examples.
+
+95
+00:08:36,000 --> 00:08:40,000
+So let me start screen sharing.
+
+96
+00:08:40,000 --> 00:08:48,000
+Before the lesson, I prepared demo project for you, and now we're going to review line by line.
+
+97
+00:08:48,000 --> 00:08:54,000
+As always, you can find the reference to the source code examples in attachments to the video.
+
+98
+00:08:55,000 --> 00:09:01,000
+So the first thing that we have to do, let's create that project.
+
+99
+00:09:02,000 --> 00:09:08,000
+You can create that project is a with maven built to or with grab or build tool.
+
+100
+00:09:09,000 --> 00:09:15,000
+This is not about Maven Gradle or how to create web projects.
+
+101
+00:09:15,000 --> 00:09:18,000
+This is less about spring development for web.
+
+102
+00:09:19,000 --> 00:09:26,000
+That's why I assume that you know how to create web projects in case you have any difficulties.
+
+103
+00:09:26,000 --> 00:09:33,000
+Please refer to my general course Java for Web development or Java from zero to first Job, where we
+
+104
+00:09:33,000 --> 00:09:37,000
+will learn such basics as creation of projects for web development.
+
+105
+00:09:37,000 --> 00:09:45,000
+In this particular example, as you can see, I use Maven build to disregards which automation build
+
+106
+00:09:45,000 --> 00:09:46,000
+tool you use.
+
+107
+00:09:46,000 --> 00:09:56,000
+We have to add dependency for spring and we see you can see here I recommend you to use the latest available
+
+108
+00:09:56,000 --> 00:09:56,000
+version.
+
+109
+00:09:57,000 --> 00:10:01,000
+The version of the spring MVC is stored here in the properties.
+
+110
+00:10:02,000 --> 00:10:06,000
+I also added Java servlet API dependency here.
+
+111
+00:10:06,000 --> 00:10:13,000
+If you saw my lessons about Java for Enterprise Edition, you should be aware about the difference between
+
+112
+00:10:13,000 --> 00:10:16,000
+Gearbox and Jakarta API.
+
+113
+00:10:16,000 --> 00:10:24,000
+I had a separate lesson where I explained the difference in sure, Jakarta API is something what is
+
+114
+00:10:24,000 --> 00:10:28,000
+supported nowadays by Eclipse Foundation and Java Sea.
+
+115
+00:10:28,000 --> 00:10:32,000
+That is something what is not development anymore.
+
+116
+00:10:33,000 --> 00:10:42,000
+In general, for the sake of this course, Jakarta and Java Sea API contains classes with the same class
+
+117
+00:10:42,000 --> 00:10:45,000
+names that serves the same purpose.
+
+118
+00:10:46,000 --> 00:10:49,000
+That's why we wouldn't be impacted too much.
+
+119
+00:10:49,000 --> 00:10:56,000
+Just the base package name for all classes will be started from Java instead of Jakarta.
+
+120
+00:10:57,000 --> 00:11:04,000
+And it is not because I don't want to work with the latest version of Java Spring and Spring Boot.
+
+121
+00:11:04,000 --> 00:11:09,000
+Currently only support Java EE and not Jakarta.
+
+122
+00:11:11,000 --> 00:11:19,000
+By the way, this also means that it will only run with Java EE compatible service.
+
+123
+00:11:19,000 --> 00:11:27,000
+In all our previous lessons we used Tomcat version ten, but Tomcat ten web server is an implementation
+
+124
+00:11:27,000 --> 00:11:33,000
+of the Jakarta E specification which currently isn't supported.
+
+125
+00:11:34,000 --> 00:11:39,000
+So the only solution for us is also to download Tomcat server version nine.
+
+126
+00:11:40,000 --> 00:11:44,000
+You can see that I added Tomcat nine into the server section to.
+
+127
+00:11:45,000 --> 00:11:49,000
+Also, you can see that I've added steel dependency here.
+
+128
+00:11:50,000 --> 00:11:51,000
+Okay.
+
+129
+00:11:51,000 --> 00:11:57,000
+Now that is enough dependencies for our hello world example and we can proceed.
+
+130
+00:11:57,000 --> 00:12:02,000
+One more Jurassic leaps related configuration mouse.
+
+131
+00:12:02,000 --> 00:12:11,000
+Right click on the project then select Properties search for project facets here in the list in order
+
+132
+00:12:11,000 --> 00:12:18,000
+to run your web project from Eclipse and the Tomcat Version nine, you should have dynamic web module
+
+133
+00:12:18,000 --> 00:12:20,000
+version less than five.
+
+134
+00:12:21,000 --> 00:12:25,000
+In my case, I have version four and that is fine.
+
+135
+00:12:25,000 --> 00:12:27,000
+To run the project successfully.
+
+136
+00:12:28,000 --> 00:12:34,000
+I hope this would save your time in case you would have issues with deploying your project from the
+
+137
+00:12:34,000 --> 00:12:37,000
+eclipse directly to the Tomcat server.
+
+138
+00:12:38,000 --> 00:12:39,000
+Let's move on.
+
+139
+00:12:39,000 --> 00:12:42,000
+Let's create our first controller now.
+
+140
+00:12:43,000 --> 00:12:47,000
+I created a class that is called Hello World Controller.
+
+141
+00:12:48,000 --> 00:12:53,000
+Two main annotations that we are going to use our controller annotation.
+
+142
+00:12:54,000 --> 00:13:00,000
+This annotation should be familiar to you from our lesson about beans configuration and the request
+
+143
+00:13:00,000 --> 00:13:01,000
+map.
+
+144
+00:13:02,000 --> 00:13:06,000
+Let me tell you a little bit more about request map and connotation.
+
+145
+00:13:06,000 --> 00:13:13,000
+Request mapping is one of the most widely used string and we see annotation request map and annotation
+
+146
+00:13:13,000 --> 00:13:23,000
+is used to map web request all to specific handler classes and or handler methods.
+
+147
+00:13:23,000 --> 00:13:30,000
+Request mapping can be applied to the controller class as well as methods.
+
+148
+00:13:30,000 --> 00:13:38,000
+When we use this annotation with class, we configures a base drive for the whole controller and we
+
+149
+00:13:38,000 --> 00:13:42,000
+can specify the URI on the level of each method.
+
+150
+00:13:42,000 --> 00:13:52,000
+In addition, like you can see on this example, hello controller will have base UI test and method.
+
+151
+00:13:52,000 --> 00:13:55,000
+Hello world will be mapped to Hello.
+
+152
+00:13:55,000 --> 00:13:57,000
+World are right.
+
+153
+00:13:57,000 --> 00:14:03,000
+So it is a full year right would be test plus Hello world.
+
+154
+00:14:04,000 --> 00:14:05,000
+Is it clear?
+
+155
+00:14:06,000 --> 00:14:07,000
+Don't worry.
+
+156
+00:14:07,000 --> 00:14:11,000
+I'm going to show you this in the browser in a minute.
+
+157
+00:14:11,000 --> 00:14:12,000
+Request.
+
+158
+00:14:12,000 --> 00:14:19,000
+Management is very powerful on rotation because we can configure request mapping as we need.
+
+159
+00:14:19,000 --> 00:14:27,000
+Not everything you need to remember right now in this lesson, but we are going to learn how to work
+
+160
+00:14:27,000 --> 00:14:29,000
+with this adaptation gradually.
+
+161
+00:14:29,000 --> 00:14:34,000
+But something I would like already to share with you in this lesson.
+
+162
+00:14:35,000 --> 00:14:38,000
+First of all, in case it would be needed.
+
+163
+00:14:38,000 --> 00:14:42,000
+You can pass multiple values for POS.
+
+164
+00:14:42,000 --> 00:14:46,000
+You can see here that value takes an array of strings.
+
+165
+00:14:47,000 --> 00:14:55,000
+The next thing here is that you can use headers attribute to specify headers that should be present
+
+166
+00:14:55,000 --> 00:14:56,000
+in the request in order.
+
+167
+00:14:56,000 --> 00:14:59,000
+Spring would involve a specific message.
+
+168
+00:15:00,000 --> 00:15:05,000
+In other words, you are able to add condition for request mapping.
+
+169
+00:15:05,000 --> 00:15:13,000
+Also, you can specify our array of masses because sometimes we would like to have different behavior
+
+170
+00:15:13,000 --> 00:15:18,000
+for different HTTP requests that are sent with the help of different masses.
+
+171
+00:15:19,000 --> 00:15:26,000
+But at the same time we would like to keep the same euro using massive attribute.
+
+172
+00:15:26,000 --> 00:15:35,000
+You can configure this in our particular example we have to the screen in case request will be sent
+
+173
+00:15:35,000 --> 00:15:36,000
+to this resource.
+
+174
+00:15:36,000 --> 00:15:38,000
+We are get method.
+
+175
+00:15:38,000 --> 00:15:46,000
+Then call this message and in case request will be sent to this request mapping.
+
+176
+00:15:46,000 --> 00:15:48,000
+We are the CDP method.
+
+177
+00:15:48,000 --> 00:15:52,000
+This code will not be invoked.
+
+178
+00:15:52,000 --> 00:15:53,000
+Is that clear?
+
+179
+00:15:54,000 --> 00:15:57,000
+Even in case something is still not clear.
+
+180
+00:15:57,000 --> 00:16:04,000
+Please do not hesitate to ask your questions below the video and I will be happy to answer.
+
+181
+00:16:05,000 --> 00:16:10,000
+Also, we can create request mapping with produces and consumes.
+
+182
+00:16:11,000 --> 00:16:18,000
+Request Mapping provides, consumes and produces variables where we can specify the request content
+
+183
+00:16:18,000 --> 00:16:26,000
+type for which method will be invoked and the response content type respectively.
+
+184
+00:16:26,000 --> 00:16:31,000
+There are much more things to tell, but let's go one by one.
+
+185
+00:16:31,000 --> 00:16:34,000
+I promise you will learn all C's gradually.
+
+186
+00:16:35,000 --> 00:16:37,000
+For now, we just create simple.
+
+187
+00:16:37,000 --> 00:16:39,000
+Hello World Controller.
+
+188
+00:16:40,000 --> 00:16:41,000
+And our message returns.
+
+189
+00:16:42,000 --> 00:16:43,000
+Hello, Wall Street.
+
+190
+00:16:44,000 --> 00:16:45,000
+What is this?
+
+191
+00:16:45,000 --> 00:16:49,000
+This actually is the name of our JSP file.
+
+192
+00:16:49,000 --> 00:16:54,000
+But in order to resolve this, you name and forward request to that view.
+
+193
+00:16:54,000 --> 00:16:58,000
+We still need to configure your resolver bin.
+
+194
+00:16:59,000 --> 00:17:01,000
+I'm going to show you how to do that.
+
+195
+00:17:02,000 --> 00:17:05,000
+Let me open a class that is called web config.
+
+196
+00:17:06,000 --> 00:17:11,000
+To enable Sprint can receive support through a Java configuration class.
+
+197
+00:17:11,000 --> 00:17:15,000
+We just add the enable web MVC annotation.
+
+198
+00:17:15,000 --> 00:17:17,000
+Adding this annotation to the class.
+
+199
+00:17:18,000 --> 00:17:25,000
+It is marked with a configuration annotation inputs the spring and we see configuration from web and
+
+200
+00:17:25,000 --> 00:17:27,000
+see configuration support class.
+
+201
+00:17:28,000 --> 00:17:36,000
+This will set up the basic support we need for an MVC project such as registering controllers and mappings,
+
+202
+00:17:36,000 --> 00:17:42,000
+tap converters, validation support, message converters and exception handling.
+
+203
+00:17:43,000 --> 00:17:50,000
+If we want to customize this configuration, we need to implement the web MVC configure interface.
+
+204
+00:17:51,000 --> 00:17:57,000
+Important thing here you can see that I configure being a few resolver.
+
+205
+00:17:57,000 --> 00:17:59,000
+Why do I need it?
+
+206
+00:17:59,000 --> 00:18:01,000
+This is needed in order.
+
+207
+00:18:01,000 --> 00:18:08,000
+I wouldn't specify the path to the views and extension of the files each time.
+
+208
+00:18:08,000 --> 00:18:15,000
+If you are a student of my java from zero to first job course and you remember how we did our online
+
+209
+00:18:15,000 --> 00:18:24,000
+shop from scratch using just servlet, you remember how we created pass our view resources view resolver
+
+210
+00:18:24,000 --> 00:18:27,000
+being helps us to simplify things.
+
+211
+00:18:28,000 --> 00:18:37,000
+You can see that I set graphics where all my views will be stored in the webpage view folder and here
+
+212
+00:18:37,000 --> 00:18:45,000
+is this folder in my directory tree and I also set suffix in order to forward requests to the files
+
+213
+00:18:45,000 --> 00:18:47,000
+with the GCP extension.
+
+214
+00:18:48,000 --> 00:18:52,000
+Can you understand now how POS does a hello world?
+
+215
+00:18:52,000 --> 00:18:54,000
+The GCP will be built.
+
+216
+00:18:55,000 --> 00:18:56,000
+I hope so.
+
+217
+00:18:57,000 --> 00:19:01,000
+Please ask questions in case the example is not clear.
+
+218
+00:19:01,000 --> 00:19:10,000
+And also do not forget to add components can annotation in order to scan all the required packages,
+
+219
+00:19:10,000 --> 00:19:16,000
+in order to initialize all the required beans and inject dependencies.
+
+220
+00:19:17,000 --> 00:19:19,000
+We're almost done.
+
+221
+00:19:19,000 --> 00:19:19,000
+Why?
+
+222
+00:19:19,000 --> 00:19:20,000
+Almost.
+
+223
+00:19:20,000 --> 00:19:21,000
+What is that?
+
+224
+00:19:22,000 --> 00:19:27,000
+The only thing that is left is configuration of our dispatcher server.
+
+225
+00:19:28,000 --> 00:19:31,000
+Now, we actually need to configure something.
+
+226
+00:19:31,000 --> 00:19:39,000
+What will be responsible for mapping requests with our controllers and with masses within our controllers?
+
+227
+00:19:40,000 --> 00:19:47,000
+As always, there are two ways for configuration with XML and with annotations.
+
+228
+00:19:47,000 --> 00:19:50,000
+Let's review both options.
+
+229
+00:19:51,000 --> 00:19:58,000
+And finally, to force our application to load this configuration, we need to create a configuration
+
+230
+00:19:58,000 --> 00:19:59,000
+class.
+
+231
+00:19:59,000 --> 00:20:01,000
+Let me show it to you.
+
+232
+00:20:01,000 --> 00:20:07,000
+It is also located here and it is called Main web app Initialize.
+
+233
+00:20:08,000 --> 00:20:16,000
+This class implements web application initialize or interface the interface to be implemented in servlet
+
+234
+00:20:16,000 --> 00:20:24,000
+3.0 plus versions environments in order to configure the server context programmatically.
+
+235
+00:20:25,000 --> 00:20:33,000
+Implementations of this interface will be detected automatically by spring servlet container initialize,
+
+236
+00:20:34,000 --> 00:20:41,000
+which itself is bootstrapped automatically by any servlet 3.0 container and higher.
+
+237
+00:20:42,000 --> 00:20:49,000
+To learn more about the bootstrap mechanism, you can investigate source code and Java docs for spring
+
+238
+00:20:49,000 --> 00:20:52,000
+servlet container initialize class.
+
+239
+00:20:53,000 --> 00:21:00,000
+Let's explore the details of on startup master that we override in our main web app.
+
+240
+00:21:00,000 --> 00:21:01,000
+Initialize our class.
+
+241
+00:21:02,000 --> 00:21:07,000
+First of all, we create object of annotation config web application context.
+
+242
+00:21:08,000 --> 00:21:15,000
+This is essentially the equivalent of annotation config application context that we used in our previous
+
+243
+00:21:15,000 --> 00:21:20,000
+lesson, but this class is for web environment.
+
+244
+00:21:21,000 --> 00:21:29,000
+You register our web config plus in our context, because our web config stores required configurations
+
+245
+00:21:29,000 --> 00:21:32,000
+is that we want to use for our application.
+
+246
+00:21:33,000 --> 00:21:40,000
+The next thing that we are doing here is attaching of the context loader listener to the servlet context.
+
+247
+00:21:41,000 --> 00:21:42,000
+Why do we need this?
+
+248
+00:21:43,000 --> 00:21:49,000
+The context loader listener is one of the essential components of the spring MVC framework.
+
+249
+00:21:49,000 --> 00:21:54,000
+Probably the most important after the dispatcher servlet itself.
+
+250
+00:21:54,000 --> 00:22:01,000
+It is used to create the root context and responsible for loading beans which are shared by multiple
+
+251
+00:22:01,000 --> 00:22:07,000
+dispatcher servlet like beans related to the service layer and data access layer.
+
+252
+00:22:08,000 --> 00:22:17,000
+In general when you develop sprinkled with sea based web applications and also using spring in the services
+
+253
+00:22:17,000 --> 00:22:21,000
+layer, you need to provide to application contacts.
+
+254
+00:22:21,000 --> 00:22:31,000
+The first one is configured using context loader listener and the one is set using dispatch servlet.
+
+255
+00:22:32,000 --> 00:22:36,000
+The special server is responsible for loading web component.
+
+256
+00:22:36,000 --> 00:22:43,000
+Specific beings like controllers view resolvers and handler mapping.
+
+257
+00:22:43,000 --> 00:22:51,000
+While, as I said before, context low order list is accountable for loading middle power and data turbines,
+
+258
+00:22:51,000 --> 00:22:55,000
+which forms the back end of spring applications.
+
+259
+00:22:56,000 --> 00:23:04,000
+The context loader listener is like any other servlet listener and it has to be declared in the deployment
+
+260
+00:23:04,000 --> 00:23:05,000
+descriptor.
+
+261
+00:23:05,000 --> 00:23:14,000
+To listen to events, it listens for startup and shutdown of the server by implementing servlet context
+
+262
+00:23:14,000 --> 00:23:20,000
+listener and accordingly creates and destroys spring managed bins.
+
+263
+00:23:21,000 --> 00:23:30,000
+In the next row, we can see the variable of nested interface dynamic from the interface servlet registration.
+
+264
+00:23:30,000 --> 00:23:38,000
+We use dynamic interface here because this is an interface through which a servlet registered where
+
+265
+00:23:38,000 --> 00:23:43,000
+one of the servlet methods or server context may be further configured.
+
+266
+00:23:44,000 --> 00:23:52,000
+And you can see here that we add to the servlet context is the instance of our dispatcher server to
+
+267
+00:23:52,000 --> 00:23:54,000
+create dispatcher servlet.
+
+268
+00:23:54,000 --> 00:23:58,000
+I create object of generic web application context.
+
+269
+00:23:59,000 --> 00:24:07,000
+It is a subclass of generic application context suitable for web environments implements configurable
+
+270
+00:24:07,000 --> 00:24:09,000
+web application context.
+
+271
+00:24:10,000 --> 00:24:16,000
+The next thing that I do here is invocation of set load or startup method.
+
+272
+00:24:16,000 --> 00:24:24,000
+What this method is about, the method sets the load of startup priority on the server represented by
+
+273
+00:24:24,000 --> 00:24:27,000
+this dynamic servlet registration.
+
+274
+00:24:28,000 --> 00:24:37,000
+A lot of setup value of greater than or equal to zero indicates to contain the initialization property
+
+275
+00:24:37,000 --> 00:24:37,000
+of the server.
+
+276
+00:24:38,000 --> 00:24:46,000
+In this case, the container must instantiate and initialize the servlet during the initialization phase
+
+277
+00:24:46,000 --> 00:24:47,000
+of the server context.
+
+278
+00:24:48,000 --> 00:24:55,000
+That is after it has invoked all of the server context list objects configured for the server context
+
+279
+00:24:55,000 --> 00:24:57,000
+at their server.
+
+280
+00:24:57,000 --> 00:25:00,000
+Context Listener context initialize method.
+
+281
+00:25:01,000 --> 00:25:10,000
+If load on startup is a negative integer, they contain is free to instantiate and initialize the server
+
+282
+00:25:10,000 --> 00:25:11,000
+lazily.
+
+283
+00:25:11,000 --> 00:25:16,000
+The default value for load on startup is minus one.
+
+284
+00:25:16,000 --> 00:25:24,000
+As you know well, celeb is loaded at the first request, usually because of default value minus one.
+
+285
+00:25:25,000 --> 00:25:29,000
+That means it consumes more time at first request.
+
+286
+00:25:30,000 --> 00:25:38,000
+If you specify a lot of startup in WebEx, more server will be loaded at project deployment time or
+
+287
+00:25:38,000 --> 00:25:39,000
+server start.
+
+288
+00:25:40,000 --> 00:25:45,000
+So it will take less time for respondent to first request.
+
+289
+00:25:45,000 --> 00:25:53,000
+If you pass the positive value, the lower integer values of that will be loaded before the higher integer
+
+290
+00:25:53,000 --> 00:25:53,000
+value servlet.
+
+291
+00:25:54,000 --> 00:26:00,000
+In other words, container loads the servlet in ascending integer value.
+
+292
+00:26:00,000 --> 00:26:06,000
+Zero value will be loaded first, then one, two, three, and so on.
+
+293
+00:26:07,000 --> 00:26:13,000
+So was this line of code will load our dispatcher servlet on certain.
+
+294
+00:26:14,000 --> 00:26:18,000
+And we add mapping to the root of the application.
+
+295
+00:26:19,000 --> 00:26:25,000
+That means the dispatcher server will handle all requests to the application.
+
+296
+00:26:25,000 --> 00:26:27,000
+That is exactly what we need.
+
+297
+00:26:28,000 --> 00:26:31,000
+This is an example of annotations based configuration.
+
+298
+00:26:32,000 --> 00:26:35,000
+Let me also show you an XML based configuration.
+
+299
+00:26:36,000 --> 00:26:43,000
+It is similar and will bring us to the same result like we have already discussed in our previous lesson.
+
+300
+00:26:43,000 --> 00:26:47,000
+It is only up to you what type of configuration to choose.
+
+301
+00:26:47,000 --> 00:26:52,000
+It is a matter of style, whether you use annotations or XML.
+
+302
+00:26:53,000 --> 00:26:56,000
+The main thing is to stay consistent.
+
+303
+00:26:56,000 --> 00:27:03,000
+If you want to remember advantages and disadvantages of annotation and XML configuration, please refer
+
+304
+00:27:03,000 --> 00:27:06,000
+to the previous classes in this course.
+
+305
+00:27:06,000 --> 00:27:14,000
+So in order to configure spring web application with XML, we need three XML files.
+
+306
+00:27:15,000 --> 00:27:18,000
+Two of them are located in the resource source folder.
+
+307
+00:27:19,000 --> 00:27:20,000
+Let's look at them.
+
+308
+00:27:21,000 --> 00:27:25,000
+App config XML is a file for spring configuration.
+
+309
+00:27:25,000 --> 00:27:27,000
+You can declare beans here.
+
+310
+00:27:28,000 --> 00:27:36,000
+We enable auto detection by registering the context components element and provides a package to scan.
+
+311
+00:27:36,000 --> 00:27:42,000
+The next file web config XML file will configure spring MVC.
+
+312
+00:27:42,000 --> 00:27:47,000
+The MVC annotation driven element will enable spring MVC support.
+
+313
+00:27:48,000 --> 00:27:56,000
+Finally, we register the internal resource view resolver, which will resolve the returned view name
+
+314
+00:27:56,000 --> 00:27:58,000
+to the real location of The View.
+
+315
+00:27:59,000 --> 00:28:05,000
+All this configuration is familiar to you already because we have just removed example with similar
+
+316
+00:28:05,000 --> 00:28:14,000
+configuration with annotations, and now we need to configure our dispatcher so that we can do this
+
+317
+00:28:14,000 --> 00:28:15,000
+in the XML file.
+
+318
+00:28:16,000 --> 00:28:17,000
+Let me open it.
+
+319
+00:28:18,000 --> 00:28:25,000
+We register the servlet and provide the location of the web config XML configuration file using the
+
+320
+00:28:25,000 --> 00:28:26,000
+need param.
+
+321
+00:28:26,000 --> 00:28:35,000
+You can see here that I also configured a lot on setup element, servlet map and element to map dispatcher
+
+322
+00:28:35,000 --> 00:28:42,000
+server with the root and I also passed the reference to the context config location.
+
+323
+00:28:42,000 --> 00:28:45,000
+As you can see here, that's it.
+
+324
+00:28:45,000 --> 00:28:52,000
+Basically, this configuration will bring us to the same result as Java based annotation.
+
+325
+00:28:52,000 --> 00:28:55,000
+It is up to you which approach you would like to select.
+
+326
+00:28:56,000 --> 00:29:01,000
+Take into account that we can't use two approaches simultaneously.
+
+327
+00:29:01,000 --> 00:29:09,000
+I will keep web XML file commanded and we will use java based configuration for the sake of this example.
+
+328
+00:29:10,000 --> 00:29:15,000
+And finally, we are done with all configurations.
+
+329
+00:29:15,000 --> 00:29:18,000
+Now we are ready to run our first example.
+
+330
+00:29:19,000 --> 00:29:22,000
+Let me run this application on the web server.
+
+331
+00:29:31,000 --> 00:29:33,000
+When the server is up and running.
+
+332
+00:29:33,000 --> 00:29:35,000
+Let's adjust the orders.
+
+333
+00:29:35,000 --> 00:29:45,000
+Here we have the base of our controller test and the address that is mapped with our method is Hello
+
+334
+00:29:45,000 --> 00:29:45,000
+world.
+
+335
+00:29:46,000 --> 00:29:55,000
+When I send the request to this resource dispatcher, Servlet handles the request and verifies it against
+
+336
+00:29:55,000 --> 00:30:04,000
+all available mappings, finds the proper mapping, invokes the method from our controller that returns
+
+337
+00:30:04,000 --> 00:30:05,000
+string.
+
+338
+00:30:05,000 --> 00:30:14,000
+Spring understands that we return view name and use this view resolver bin to resolve this view name.
+
+339
+00:30:14,000 --> 00:30:23,000
+That's how view file in the web view folder is found with the extension JSP because it is set.
+
+340
+00:30:23,000 --> 00:30:30,000
+So in the crossover bin, is it clear that's how this example works?
+
+341
+00:30:30,000 --> 00:30:37,000
+In case you have any questions, please ask them below the video and I will be happy to answer.
+
+342
+00:30:37,000 --> 00:30:43,000
+I encourage you to download the source code from the lesson link that you will find the attachments
+
+343
+00:30:43,000 --> 00:30:47,000
+to the video and run this code on your computer.
+
+344
+00:30:48,000 --> 00:30:49,000
+I am done with the demo.
+
+345
+00:30:50,000 --> 00:30:58,000
+Let just sum it up and quickly review the main advantages of the spring MVC Now, when you saw example
+
+346
+00:30:58,000 --> 00:31:02,000
+of spring MVC and you can understand what it is, let's review.
+
+347
+00:31:02,000 --> 00:31:07,000
+Advantages of Spring can be see framework separate roles.
+
+348
+00:31:07,000 --> 00:31:16,000
+The spring MVC separates each role, whereas a model object, controller, command object, view resolver,
+
+349
+00:31:16,000 --> 00:31:22,000
+dispatcher, servlet data, etc. can be fulfilled by a specialized object.
+
+350
+00:31:23,000 --> 00:31:29,000
+We are still going to learn all the different objects today in the lesson we just had simple Hello world
+
+351
+00:31:29,000 --> 00:31:32,000
+example and we have lots more to learn.
+
+352
+00:31:33,000 --> 00:31:35,000
+Spring can be flexible.
+
+353
+00:31:35,000 --> 00:31:43,000
+That means there are no super strict requirements regarding code structure, like for example, inheritance
+
+354
+00:31:43,000 --> 00:31:46,000
+between components or specific locations.
+
+355
+00:31:47,000 --> 00:31:55,000
+Vicki Barton is agnostic and I believe this is really great advantage because the pace of updates and
+
+356
+00:31:55,000 --> 00:32:03,000
+the frontend technologies and the amount of frameworks is huge and you're free to select any framework
+
+357
+00:32:03,000 --> 00:32:10,000
+you wish to integrate with the Sprint MVC advantages of Sprint core and version of control and dependency
+
+358
+00:32:10,000 --> 00:32:11,000
+injection.
+
+359
+00:32:12,000 --> 00:32:13,000
+On top of all spring.
+
+360
+00:32:13,000 --> 00:32:15,000
+And we see advantages.
+
+361
+00:32:15,000 --> 00:32:21,000
+We shouldn't forget that we keep taking advantage of Spring Corps and inversion of control.
+
+362
+00:32:22,000 --> 00:32:29,000
+We have container that helps us to manage the lifecycle of our bees and dependencies between the objects.
+
+363
+00:32:30,000 --> 00:32:31,000
+Rapid development.
+
+364
+00:32:32,000 --> 00:32:33,000
+We can make a statement.
+
+365
+00:32:33,000 --> 00:32:34,000
+This is a sprint.
+
+366
+00:32:34,000 --> 00:32:42,000
+NBC facilitates fast and parallel development because of the many ready to use out of the box elements.
+
+367
+00:32:43,000 --> 00:32:50,000
+In my opinion, these are key advantages of the spin can be see framework that is the internet.
+
+368
+00:32:50,000 --> 00:32:52,000
+You can find more of them.
+
+369
+00:32:52,000 --> 00:33:00,000
+But I would say that these are the most important ones in comparison with other frameworks for web development
+
+370
+00:33:00,000 --> 00:33:01,000
+with Java.
+
+371
+00:33:01,000 --> 00:33:04,000
+Let's recap what we have learned in the lesson.
+
+372
+00:33:05,000 --> 00:33:09,000
+In the lesson we learned Basics of spring MVC.
+
+373
+00:33:09,000 --> 00:33:12,000
+Now you know what it is and why we need it.
+
+374
+00:33:13,000 --> 00:33:16,000
+We reviewed MVC design pattern.
+
+375
+00:33:16,000 --> 00:33:19,000
+Also, we learn the front controller design pattern.
+
+376
+00:33:20,000 --> 00:33:23,000
+I explained to you what a dispatcher servlet is.
+
+377
+00:33:23,000 --> 00:33:27,000
+We learned the flow of execution in Spring MVC.
+
+378
+00:33:27,000 --> 00:33:30,000
+We created our first spring web application.
+
+379
+00:33:31,000 --> 00:33:36,000
+Now you know what to request Mapping and enable weapon annotations are.
+
+380
+00:33:36,000 --> 00:33:40,000
+We can figure out being of view resolver.
+
+381
+00:33:40,000 --> 00:33:46,000
+We learned interfaces and classes required to configure a spring MVC project.
+
+382
+00:33:46,000 --> 00:33:50,000
+And at the end of the lesson, we the advantages of spring.
+
+383
+00:33:50,000 --> 00:33:50,000
+Can we see?
+
+384
+00:33:51,000 --> 00:33:53,000
+That's all for this lesson.
+
+385
+00:33:53,000 --> 00:33:55,000
+Thanks a lot for your attention.
+
+386
+00:33:56,000 --> 00:33:59,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/002 Model, RequestParam & PathVariable_en.srt b/82 - Spring MVC & Spring for WEB/002 Model, RequestParam & PathVariable_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..2ba87dba0db05db808fa54e91fc3796b897042bd
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/002 Model, RequestParam & PathVariable_en.srt
@@ -0,0 +1,976 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:10,000
+In this video, we're going to continue learning springtime, the Sea.
+
+3
+00:00:11,000 --> 00:00:15,000
+We're going to start this lesson from learning of model interface.
+
+4
+00:00:15,000 --> 00:00:23,000
+On real examples, I will show you how we can use model object as a container deposit data to the view.
+
+5
+00:00:23,000 --> 00:00:30,000
+After that, I'm going to show you how to work with the HTTP servlet request and HTTP session in the
+
+6
+00:00:30,000 --> 00:00:35,000
+spring MVC and how to inject them into our controllers.
+
+7
+00:00:36,000 --> 00:00:41,000
+And that's the important things that we're going to learn today is request for annotation.
+
+8
+00:00:41,000 --> 00:00:47,000
+We'll learn how to map request parameters with the variables inside our code.
+
+9
+00:00:47,000 --> 00:00:50,000
+Also, we'll pass variable annotation.
+
+10
+00:00:50,000 --> 00:00:53,000
+You're going to understand what it is and how to use it.
+
+11
+00:00:54,000 --> 00:00:58,000
+And at the end of the lesson I will explain you such annotations as Yep.
+
+12
+00:00:58,000 --> 00:01:07,000
+Mapping course Mapping route Mapping, delete mapping and porch mapping on real examples, I will show
+
+13
+00:01:07,000 --> 00:01:09,000
+you how to use these annotations.
+
+14
+00:01:10,000 --> 00:01:14,000
+As you can see today, we have a lot of new things to learn.
+
+15
+00:01:14,000 --> 00:01:16,000
+Let's start our lesson.
+
+16
+00:01:16,000 --> 00:01:23,000
+Today we're going to have practical oriented lesson because to understand things better, you need to
+
+17
+00:01:23,000 --> 00:01:27,000
+see a lot examples and specially for you.
+
+18
+00:01:27,000 --> 00:01:30,000
+I prepared a lot of examples for today.
+
+19
+00:01:31,000 --> 00:01:37,000
+As always, feel free to find reference to the source code examples in attachments to the lesson.
+
+20
+00:01:37,000 --> 00:01:44,000
+We're going to start our lesson from the model example, and once you understand what it is in simple
+
+21
+00:01:44,000 --> 00:01:53,000
+words, model is an interface that defines a holder for model attributes in spring, and we see the
+
+22
+00:01:53,000 --> 00:01:58,000
+model works as a container that contains the data of the application.
+
+23
+00:01:59,000 --> 00:02:07,000
+Here, a data can be in any form, such as objects, strings, information from the database, etc..
+
+24
+00:02:08,000 --> 00:02:09,000
+Let me open the glass.
+
+25
+00:02:09,000 --> 00:02:12,000
+That is cold model demo controller.
+
+26
+00:02:13,000 --> 00:02:21,000
+In this class I put all examples relate with model and on the controller level you can see that I have
+
+27
+00:02:21,000 --> 00:02:24,000
+request mapping that is mapped to test.
+
+28
+00:02:25,000 --> 00:02:28,000
+And our first example is simple model demo.
+
+29
+00:02:29,000 --> 00:02:31,000
+Pay attention to the massive parameters.
+
+30
+00:02:32,000 --> 00:02:39,000
+You can see that they just declared a local variable of model type, but who will pass object of model
+
+31
+00:02:39,000 --> 00:02:40,000
+type to this method?
+
+32
+00:02:41,000 --> 00:02:49,000
+The very short answer is that spring will take care of inject and model object into this mass and inside
+
+33
+00:02:49,000 --> 00:02:51,000
+the mass of body.
+
+34
+00:02:51,000 --> 00:02:55,000
+You can work with model object as we have already discussed.
+
+35
+00:02:55,000 --> 00:02:58,000
+Model can be treated like container.
+
+36
+00:02:58,000 --> 00:02:59,000
+Pay attention.
+
+37
+00:02:59,000 --> 00:03:02,000
+That model has a request scope.
+
+38
+00:03:02,000 --> 00:03:10,000
+In each request you are going to have new object of the model type and in case we can treat model like
+
+39
+00:03:10,000 --> 00:03:11,000
+a container.
+
+40
+00:03:11,000 --> 00:03:14,000
+Then let me just add attribute here.
+
+41
+00:03:14,000 --> 00:03:19,000
+For the sake of example, I'm going to add simple text message.
+
+42
+00:03:20,000 --> 00:03:26,000
+To add attribute, I use add attribute method and I pass key value pair.
+
+43
+00:03:27,000 --> 00:03:32,000
+Feel free to explore the model interface and other masses is a thing to use there.
+
+44
+00:03:33,000 --> 00:03:37,000
+For example, add attribute method is overloaded.
+
+45
+00:03:37,000 --> 00:03:44,000
+You can add any object as an attribute to the model without specifying an attribute name using and get
+
+46
+00:03:44,000 --> 00:03:48,000
+variable name method of conventions clause from the spring core.
+
+47
+00:03:49,000 --> 00:03:54,000
+So take your time to look through the methods here and explore the documentation.
+
+48
+00:03:54,000 --> 00:03:59,000
+And after I edit attribute I will return you name.
+
+49
+00:03:59,000 --> 00:04:06,000
+In the previous lesson, I already explained how the value name is resolved with the view resolver bin.
+
+50
+00:04:07,000 --> 00:04:13,000
+That's why, in case you would like to refresh your knowledge, do not hesitate to review the previous
+
+51
+00:04:13,000 --> 00:04:13,000
+lesson.
+
+52
+00:04:14,000 --> 00:04:23,000
+So when our view is resolved, our request is redirected to the simple model demo JSP file.
+
+53
+00:04:23,000 --> 00:04:24,000
+Let me open it.
+
+54
+00:04:25,000 --> 00:04:32,000
+Here you can see that I used expression language to make a reference to the variable that is stored
+
+55
+00:04:32,000 --> 00:04:33,000
+in my model.
+
+56
+00:04:33,000 --> 00:04:40,000
+Let me run this program on the web server and prove you that this works as expected.
+
+57
+00:04:40,000 --> 00:04:43,000
+My server is starting.
+
+58
+00:04:45,000 --> 00:04:50,000
+And when my server is started, let's just adjust the URL.
+
+59
+00:04:51,000 --> 00:04:57,000
+I set this and the topic of my message simple model demo.
+
+60
+00:04:58,000 --> 00:05:01,000
+And here you can see the message that we put into our model.
+
+61
+00:05:02,000 --> 00:05:04,000
+Basically, that's it.
+
+62
+00:05:05,000 --> 00:05:12,000
+Like this, you can add any object similar to the way how we did with request object when we have just
+
+63
+00:05:12,000 --> 00:05:14,000
+learned the server topic.
+
+64
+00:05:15,000 --> 00:05:16,000
+Okay.
+
+65
+00:05:16,000 --> 00:05:24,000
+What to do in case you miss salads and you want to have an HTTP server request or HD session object.
+
+66
+00:05:25,000 --> 00:05:32,000
+Spring framework is smart enough to understand that you want to inject HTTP server to request or session
+
+67
+00:05:32,000 --> 00:05:35,000
+object and it can be easily done.
+
+68
+00:05:36,000 --> 00:05:39,000
+Let's take a look at the second example here.
+
+69
+00:05:40,000 --> 00:05:48,000
+In the request session injection demo, you can see that a specified HTTP server to request an HTTP
+
+70
+00:05:48,000 --> 00:05:50,000
+session as method parameters.
+
+71
+00:05:50,000 --> 00:05:56,000
+Spring will be responsible for injecting here objects of compatible types in the runtime.
+
+72
+00:05:57,000 --> 00:06:03,000
+Inside the method, I get request parameter and assigns a value to the string object.
+
+73
+00:06:04,000 --> 00:06:11,000
+After that, I use my request object as a container and they put the request parameter into the request
+
+74
+00:06:11,000 --> 00:06:14,000
+object with the key request message.
+
+75
+00:06:14,000 --> 00:06:20,000
+Also, I put session message for the sake of example and return you name.
+
+76
+00:06:20,000 --> 00:06:25,000
+In my view, I use expression language to present the values to decline.
+
+77
+00:06:26,000 --> 00:06:27,000
+Is it clear?
+
+78
+00:06:28,000 --> 00:06:33,000
+Let me get the request more from our example and put it in the address slide.
+
+79
+00:06:34,000 --> 00:06:42,000
+Also I will add question mark and I will write test parameter key and some random value.
+
+80
+00:06:42,000 --> 00:06:49,000
+As you can see, both request attribute and session attributes that we configured successfully created
+
+81
+00:06:49,000 --> 00:06:50,000
+here.
+
+82
+00:06:51,000 --> 00:06:58,000
+By this moment you might be wondering what is the difference between the HTTP servlet request and model
+
+83
+00:06:58,000 --> 00:07:00,000
+parameters?
+
+84
+00:07:00,000 --> 00:07:07,000
+Can model completely substitute HTTP server request unknown and which one to choose?
+
+85
+00:07:08,000 --> 00:07:10,000
+We'll get back to this question.
+
+86
+00:07:10,000 --> 00:07:17,000
+Don't worry, it's a complete answer to this question will learn in other lesson, one will learn spring
+
+87
+00:07:17,000 --> 00:07:18,000
+forms.
+
+88
+00:07:18,000 --> 00:07:25,000
+And now let me share a few more important things related to the process of request in the spring.
+
+89
+00:07:25,000 --> 00:07:33,000
+Can MVC you already know how to get request parameter from the request object because we did this multiple
+
+90
+00:07:33,000 --> 00:07:38,000
+times when we worked with a server that's now in spring.
+
+91
+00:07:38,000 --> 00:07:43,000
+Can we see web annotation that is called request arm?
+
+92
+00:07:43,000 --> 00:07:47,000
+Let me show you how it works here.
+
+93
+00:07:47,000 --> 00:07:55,000
+In simple message I use request from annotation before the method parameter attention is a string can
+
+94
+00:07:55,000 --> 00:07:59,000
+easily convert string parameters to integers, for example.
+
+95
+00:08:00,000 --> 00:08:07,000
+That's why I can put here integer and sprinkled convert parameter value to this type.
+
+96
+00:08:08,000 --> 00:08:16,000
+In case there will be parsing error and string can be passed to integer, but request response will
+
+97
+00:08:16,000 --> 00:08:19,000
+be returned to the client by default.
+
+98
+00:08:19,000 --> 00:08:23,000
+Request parameter is mandatory and required.
+
+99
+00:08:23,000 --> 00:08:31,000
+That means that in case you send the request without ID parameter, you are going to receive an error.
+
+100
+00:08:31,000 --> 00:08:37,000
+Bad request telling is that a parameter is required for this request.
+
+101
+00:08:38,000 --> 00:08:45,000
+In case you want to keep this request parameter optional, you can change required attribute of the
+
+102
+00:08:45,000 --> 00:08:55,000
+annotation to false vividly because by default it is true or you can specify default value and as the
+
+103
+00:08:55,000 --> 00:09:03,000
+important thing, your request parameter should have the same name as local variable name here in case
+
+104
+00:09:03,000 --> 00:09:07,000
+you will use different variable name for the request parameter.
+
+105
+00:09:07,000 --> 00:09:16,000
+Spring won't be able to map those together in case you want to use different request parameter name
+
+106
+00:09:16,000 --> 00:09:18,000
+and local method variable name.
+
+107
+00:09:18,000 --> 00:09:26,000
+We have to specify name attribute in request parameter like you can see in this example.
+
+108
+00:09:26,000 --> 00:09:34,000
+I will keep this example command because otherwise there will be error raised by spring because of the
+
+109
+00:09:34,000 --> 00:09:36,000
+same URL mappings.
+
+110
+00:09:36,000 --> 00:09:45,000
+In this case I can use the user ID as a request parameter name and the ID for the local variable name.
+
+111
+00:09:45,000 --> 00:09:49,000
+I don't see reasons to do different names often.
+
+112
+00:09:49,000 --> 00:09:53,000
+That's why I will show you them with this example.
+
+113
+00:09:53,000 --> 00:09:57,000
+Let me copy and paste the resource mapping.
+
+114
+00:09:58,000 --> 00:10:05,000
+I put a question mark and after that I specify ID and send requests.
+
+115
+00:10:06,000 --> 00:10:13,000
+And as you can see, our view returns as the result that we expect to see is a clear.
+
+116
+00:10:14,000 --> 00:10:21,000
+In case you have any questions, please ask me below the reader and I will be happy to answer.
+
+117
+00:10:22,000 --> 00:10:24,000
+Let's imagine the following scenario.
+
+118
+00:10:24,000 --> 00:10:29,000
+Now we have multiple parameters and we don't know their names.
+
+119
+00:10:29,000 --> 00:10:31,000
+What can we do?
+
+120
+00:10:31,000 --> 00:10:35,000
+We can map all parameters with the map object.
+
+121
+00:10:35,000 --> 00:10:44,000
+Like in this example, I use request for annotation and specify map type of parameter parameterized
+
+122
+00:10:44,000 --> 00:10:45,000
+by string.
+
+123
+00:10:45,000 --> 00:10:49,000
+This will be our parameters, keys and values.
+
+124
+00:10:49,000 --> 00:10:54,000
+Inside the method itself, I create stream on entry set.
+
+125
+00:10:54,000 --> 00:11:01,000
+I transform it to the stream of just values and after that I collect all of them in one stream using
+
+126
+00:11:01,000 --> 00:11:03,000
+comma as a separator.
+
+127
+00:11:04,000 --> 00:11:07,000
+I will not stop here on the stream API.
+
+128
+00:11:07,000 --> 00:11:11,000
+If you want to refresh your knowledge about collections and stream API.
+
+129
+00:11:11,000 --> 00:11:15,000
+Feel free to watch my course Java from zero to first job.
+
+130
+00:11:15,000 --> 00:11:20,000
+I have sections there dedicated to the collections and functional programming.
+
+131
+00:11:20,000 --> 00:11:25,000
+I put the results stream into the model and forward that request to The View.
+
+132
+00:11:26,000 --> 00:11:27,000
+Let's try this method.
+
+133
+00:11:28,000 --> 00:11:30,000
+I copy the mapping.
+
+134
+00:11:30,000 --> 00:11:32,000
+I paste it in the web browser.
+
+135
+00:11:32,000 --> 00:11:37,000
+Now I need to pass any set of key value pairs.
+
+136
+00:11:37,000 --> 00:11:39,000
+Give me just a few seconds.
+
+137
+00:11:41,000 --> 00:11:47,000
+And after sentence requests, you can see that they printed all the values from the request parameters
+
+138
+00:11:47,000 --> 00:11:48,000
+separated by comma.
+
+139
+00:11:49,000 --> 00:11:51,000
+So just remember this API.
+
+140
+00:11:51,000 --> 00:11:54,000
+It can come in handy during the development.
+
+141
+00:11:55,000 --> 00:12:02,000
+Other interesting things that you can do with the help of request for annotation is the mapping of multi
+
+142
+00:12:02,000 --> 00:12:04,000
+value parameter.
+
+143
+00:12:04,000 --> 00:12:11,000
+This is not very popular case, but still, as a tutor, I have to provide you with the whole tool set
+
+144
+00:12:12,000 --> 00:12:19,000
+and after that, having all those said will calculate the most efficient way of achieving our goals.
+
+145
+00:12:20,000 --> 00:12:22,000
+Take a look at this example.
+
+146
+00:12:23,000 --> 00:12:25,000
+I use request parameter notation.
+
+147
+00:12:25,000 --> 00:12:35,000
+After it I specified this parameter in this list parameter will put values associated with one key that
+
+148
+00:12:35,000 --> 00:12:37,000
+is called is is it.
+
+149
+00:12:39,000 --> 00:12:43,000
+After that I will just join all the values into one single string.
+
+150
+00:12:44,000 --> 00:12:48,000
+We'll put it into the model and we'll forward to The View.
+
+151
+00:12:49,000 --> 00:12:56,000
+Let me show you what we received a copy the map and paste it into the web browser.
+
+152
+00:12:57,000 --> 00:13:05,000
+Now I put a question mark I this parameter name and pass multiple values separated by commas.
+
+153
+00:13:06,000 --> 00:13:11,000
+After sending this request, we receive all values in one combined line.
+
+154
+00:13:11,000 --> 00:13:15,000
+That's how you can pass multi value parameter.
+
+155
+00:13:16,000 --> 00:13:22,000
+The next thing that I would like to do is to show you another notation that can be used with the local
+
+156
+00:13:22,000 --> 00:13:25,000
+variables inside the method.
+
+157
+00:13:25,000 --> 00:13:28,000
+I'm talking about past variable annotation.
+
+158
+00:13:29,000 --> 00:13:31,000
+This one would be extremely important.
+
+159
+00:13:31,000 --> 00:13:37,000
+One will start developing our controllers using the rest architecture approach.
+
+160
+00:13:38,000 --> 00:13:41,000
+We are also going to have a separate lessons above rest architecture.
+
+161
+00:13:42,000 --> 00:13:44,000
+For now, I just want you to remember this.
+
+162
+00:13:45,000 --> 00:13:47,000
+This is a request map.
+
+163
+00:13:47,000 --> 00:13:51,000
+We can define the map for our path variable.
+
+164
+00:13:52,000 --> 00:13:59,000
+Here it is in the curly braces, the seed, and in the message parameters.
+
+165
+00:13:59,000 --> 00:14:01,000
+I can use best verbal annotation.
+
+166
+00:14:01,000 --> 00:14:05,000
+We know that the map was variable with the local method argument.
+
+167
+00:14:06,000 --> 00:14:08,000
+A few important things here.
+
+168
+00:14:09,000 --> 00:14:12,000
+First of all, thus variable is required by default.
+
+169
+00:14:13,000 --> 00:14:20,000
+This is logically correct because in case you make variable part of your pass, you expect this value
+
+170
+00:14:20,000 --> 00:14:21,000
+to be here.
+
+171
+00:14:22,000 --> 00:14:29,000
+For example, you can configure request mapping to the user's resource and depending on the ID value
+
+172
+00:14:29,000 --> 00:14:32,000
+passed, you can return related user.
+
+173
+00:14:32,000 --> 00:14:36,000
+So in any case, you would count on the pass variable.
+
+174
+00:14:37,000 --> 00:14:43,000
+But just in case you want to see this plus variable as an optional, you can set the required attribute
+
+175
+00:14:43,000 --> 00:14:44,000
+to false.
+
+176
+00:14:44,000 --> 00:14:48,000
+But as I said, I can't imagine the case.
+
+177
+00:14:48,000 --> 00:14:53,000
+Why would you want to use sparse variable and then would set this to false?
+
+178
+00:14:53,000 --> 00:14:57,000
+This is just one out of two annotations attributes.
+
+179
+00:14:57,000 --> 00:15:01,000
+That's why I would like to share this with you.
+
+180
+00:15:02,000 --> 00:15:06,000
+The second thing here is that auto conversion is happened here.
+
+181
+00:15:07,000 --> 00:15:16,000
+Request parameter comes to us from the address line and usually is a string, but value can be converted
+
+182
+00:15:16,000 --> 00:15:19,000
+automatically to the integer type or in.
+
+183
+00:15:20,000 --> 00:15:24,000
+This is also what spring does behind the scenes.
+
+184
+00:15:25,000 --> 00:15:32,000
+And the third important scene in case your pass variable matches with the local variable name, everything
+
+185
+00:15:32,000 --> 00:15:40,000
+is fine, but in case you have a variable name written differently, like in this example you have user
+
+186
+00:15:40,000 --> 00:15:45,000
+underscore ID is a POS variable, but is a mass that you have a variable name.
+
+187
+00:15:46,000 --> 00:15:50,000
+In this case, you need to specify the name of the POS variable.
+
+188
+00:15:51,000 --> 00:15:57,000
+Basically, inside the POS variable annotation, you can find two other attributes that we need.
+
+189
+00:15:57,000 --> 00:16:00,000
+Review the value and name.
+
+190
+00:16:00,000 --> 00:16:08,000
+Both of them exist to describe the same thing and value attribute is used as an alias is a name attribute,
+
+191
+00:16:09,000 --> 00:16:11,000
+so select the one you like the most.
+
+192
+00:16:12,000 --> 00:16:20,000
+In our example, I used name attribute and specify the name of the POS variable in the browser.
+
+193
+00:16:20,000 --> 00:16:26,000
+It will work in a similar way as previous example because we return the same view.
+
+194
+00:16:27,000 --> 00:16:36,000
+He also mentioned that for the sake of the demo, I also changed the type here to in just to show you
+
+195
+00:16:36,000 --> 00:16:43,000
+the spring can convert values to different types, reference types and primitive types too.
+
+196
+00:16:44,000 --> 00:16:51,000
+I will keep this example commanded Spring will throw an error when will send the request because there
+
+197
+00:16:51,000 --> 00:16:58,000
+will be ambiguous handler message mapped to the same request because request will look the same.
+
+198
+00:16:58,000 --> 00:17:02,000
+You can use multiple pass variables in one pass.
+
+199
+00:17:02,000 --> 00:17:07,000
+You even can use regular expression for the POS variables.
+
+200
+00:17:07,000 --> 00:17:12,000
+But I didn't see people often use regular expressions for POS variables.
+
+201
+00:17:12,000 --> 00:17:17,000
+We have just reviewed the main scenario of using POS variable.
+
+202
+00:17:17,000 --> 00:17:21,000
+That's all what I wanted to share with you about POS variable.
+
+203
+00:17:22,000 --> 00:17:27,000
+Now I'm going to share with you another interesting same string.
+
+204
+00:17:27,000 --> 00:17:35,000
+Version 4.3 introduced some very cool mass level composed annotations to smooth out the handling request
+
+205
+00:17:35,000 --> 00:17:36,000
+map.
+
+206
+00:17:36,000 --> 00:17:44,000
+In typical springtime, we see projects Spring currently supports five types of in-built annotations
+
+207
+00:17:44,000 --> 00:17:52,000
+for handling different types of incoming HTTP request methods which are get post, put, delete and
+
+208
+00:17:52,000 --> 00:17:53,000
+punch.
+
+209
+00:17:53,000 --> 00:17:56,000
+They are get mapping.
+
+210
+00:17:56,000 --> 00:17:58,000
+Of course they and.
+
+211
+00:17:59,000 --> 00:17:59,000
+Good man.
+
+212
+00:18:01,000 --> 00:18:04,000
+Delete mapping and parch mapping.
+
+213
+00:18:05,000 --> 00:18:08,000
+Take a look at these examples.
+
+214
+00:18:09,000 --> 00:18:17,000
+You can use request mapping annotation as the resource value and also to specify the request method,
+
+215
+00:18:18,000 --> 00:18:19,000
+for example.
+
+216
+00:18:20,000 --> 00:18:24,000
+Instead of this you can just use get mapping annotation.
+
+217
+00:18:25,000 --> 00:18:26,000
+From the annotation.
+
+218
+00:18:26,000 --> 00:18:33,000
+I believe that it is clear that this method is created for get request only.
+
+219
+00:18:33,000 --> 00:18:36,000
+I believe this is clear and doesn't worsen discussion.
+
+220
+00:18:37,000 --> 00:18:43,000
+We have a similar story with post mapping, mapping, mapping and parch mapping.
+
+221
+00:18:43,000 --> 00:18:51,000
+So as you may guess, the only difference will be the HTTP method that is mapped to these annotations.
+
+222
+00:18:52,000 --> 00:18:59,000
+If we open source code of these annotations, we are going to see that all of them have request mapping
+
+223
+00:19:00,000 --> 00:19:03,000
+and the respective value is a massive element.
+
+224
+00:19:04,000 --> 00:19:06,000
+We are going to use these annotations.
+
+225
+00:19:06,000 --> 00:19:09,000
+One will build our rest services.
+
+226
+00:19:10,000 --> 00:19:13,000
+We can try this example in the web browser.
+
+227
+00:19:13,000 --> 00:19:15,000
+Nothing special.
+
+228
+00:19:15,000 --> 00:19:17,000
+It will work as expected.
+
+229
+00:19:17,000 --> 00:19:20,000
+Our browser says get requests.
+
+230
+00:19:21,000 --> 00:19:25,000
+That's why everything will be okay with resurrection in this case.
+
+231
+00:19:26,000 --> 00:19:29,000
+That's all what I wanted to share with you in this lesson.
+
+232
+00:19:30,000 --> 00:19:33,000
+Let's recap what we have learned today.
+
+233
+00:19:34,000 --> 00:19:37,000
+Today we learned what the model interface is.
+
+234
+00:19:37,000 --> 00:19:44,000
+You saw how we use model as a container to parse the data to the view within the request scope.
+
+235
+00:19:45,000 --> 00:19:54,000
+Also, I showed you how we can inject a HTTP server request an HTTP session into our MVC controller.
+
+236
+00:19:54,000 --> 00:19:58,000
+Now you know how to work with request parameter notation.
+
+237
+00:19:59,000 --> 00:20:05,000
+We learn the single request parameters, mapping, mapping multiple parameters into the map and mapping
+
+238
+00:20:05,000 --> 00:20:08,000
+multivariate parameters in this list.
+
+239
+00:20:09,000 --> 00:20:13,000
+We learned how to work with sparse verbal annotation and when to use it.
+
+240
+00:20:14,000 --> 00:20:20,000
+And at the end of the lesson I showed, you get mapping, post mapping, route mapping, delete mapping
+
+241
+00:20:20,000 --> 00:20:22,000
+and parch mapping annotations.
+
+242
+00:20:23,000 --> 00:20:26,000
+That's all what I wanted to discuss with you in this lesson.
+
+243
+00:20:27,000 --> 00:20:29,000
+Thanks a lot for your attention.
+
+244
+00:20:29,000 --> 00:20:32,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/002 Source-code-examples-from-the-lesson.url b/82 - Spring MVC & Spring for WEB/002 Source-code-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..18a6166824566719a35246e74d4ef30439fb2b53
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/002 Source-code-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/blob/master/src/main/java/com/itbulls/learnit/spring/controllers/ModelDemoController.java
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/003 JSR-303-Bean-Validation.url b/82 - Spring MVC & Spring for WEB/003 JSR-303-Bean-Validation.url
new file mode 100644
index 0000000000000000000000000000000000000000..3cb5823bf5b1eb5b419aeeb9883642ae61f8f9dc
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/003 JSR-303-Bean-Validation.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://jcp.org/en/jsr/detail?id=303
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/003 Source-code-examples-from-the-lesson-Models.url b/82 - Spring MVC & Spring for WEB/003 Source-code-examples-from-the-lesson-Models.url
new file mode 100644
index 0000000000000000000000000000000000000000..b69166ffe5c08e90ee36fa1acc34e2914c72821a
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/003 Source-code-examples-from-the-lesson-Models.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/tree/master/src/main/java/com/itbulls/learnit/spring/model
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/003 Source-code-examples-from-the-lesson-UserController.url b/82 - Spring MVC & Spring for WEB/003 Source-code-examples-from-the-lesson-UserController.url
new file mode 100644
index 0000000000000000000000000000000000000000..0d0b5a053344a91961ab237c04f6dfb6ecf98384
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/003 Source-code-examples-from-the-lesson-UserController.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/blob/master/src/main/java/com/itbulls/learnit/spring/controllers/UserController.java
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/003 Spring MVC Forms, @ModelAttribute, Bean Validation_en.srt b/82 - Spring MVC & Spring for WEB/003 Spring MVC Forms, @ModelAttribute, Bean Validation_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..2fe59b26cfc2eb6c985926cb9d496773a2a215af
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/003 Spring MVC Forms, @ModelAttribute, Bean Validation_en.srt
@@ -0,0 +1,1212 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:13,000
+In this lesson, we're going to learn how to work with the spring forms, how to work with model attribute
+
+3
+00:00:13,000 --> 00:00:15,000
+and validate the model.
+
+4
+00:00:15,000 --> 00:00:22,000
+We're going to start this lesson from understanding of what spring forms are and why we need them.
+
+5
+00:00:22,000 --> 00:00:28,000
+During the lesson, we're going to have a lot of practical exercises on the real examples.
+
+6
+00:00:28,000 --> 00:00:34,000
+I'm going to show you how we can use model, attribute annotation and why we need it.
+
+7
+00:00:35,000 --> 00:00:39,000
+Also in this lesson, we're going to discuss very important topic.
+
+8
+00:00:40,000 --> 00:00:46,000
+I'm talking about validation API and GSR 303 specification.
+
+9
+00:00:47,000 --> 00:00:51,000
+I will show you how to set constraints for data values in object.
+
+10
+00:00:51,000 --> 00:00:58,000
+After that I'm going to show you how to use valid annotation and validate the object with the help of
+
+11
+00:00:58,000 --> 00:00:59,000
+Java validation.
+
+12
+00:01:00,000 --> 00:01:08,000
+Zen will understand how to work with the object of one result type and how we can get information about
+
+13
+00:01:08,000 --> 00:01:10,000
+data binding errors from it.
+
+14
+00:01:11,000 --> 00:01:18,000
+And I'm going to show you examples how data binding error handling is usually done in web applications.
+
+15
+00:01:19,000 --> 00:01:20,000
+Let's start our lesson.
+
+16
+00:01:21,000 --> 00:01:26,000
+Let's learn first what spring tests are and why do we need them.
+
+17
+00:01:26,000 --> 00:01:32,000
+I believe that by this moment in our course you are already familiar with the HTTP forms.
+
+18
+00:01:33,000 --> 00:01:39,000
+You know that usually we use forms on the frontend to submit some information to the server.
+
+19
+00:01:39,000 --> 00:01:44,000
+We are going to learn today how to use Spring MVC Form Tag Library.
+
+20
+00:01:45,000 --> 00:01:52,000
+The Spring MVC form tags as a configurable and reusable building blocks for a web page.
+
+21
+00:01:52,000 --> 00:02:00,000
+You already know what attacks are in GCP from the lessons, but still, if you want to remember such
+
+22
+00:02:00,000 --> 00:02:07,000
+basic terms as stack library descriptors, feel free to check the lessons about still in my java from
+
+23
+00:02:07,000 --> 00:02:09,000
+zero to first job course.
+
+24
+00:02:10,000 --> 00:02:15,000
+We're going to use spring tags, but the concept is the same.
+
+25
+00:02:15,000 --> 00:02:22,000
+These stacks provide us with an easy way to develop, read and maintain our JSP pages.
+
+26
+00:02:23,000 --> 00:02:31,000
+This the can be see form tags can be seen as data burning aware tags that can automatically set data
+
+27
+00:02:31,000 --> 00:02:34,000
+to Java object, bind and retrieve from it.
+
+28
+00:02:35,000 --> 00:02:40,000
+And that's probably the main difference from the regular HTML form tags.
+
+29
+00:02:40,000 --> 00:02:44,000
+You can do the same with HTML forms.
+
+30
+00:02:45,000 --> 00:02:52,000
+Spring form tax contains counterpart for similar regular HTML for tax.
+
+31
+00:02:52,000 --> 00:02:57,000
+On this slide you can see the mean spring form tax.
+
+32
+00:02:57,000 --> 00:03:04,000
+So if you are familiar with the HTML form tax, then there is nothing new for you here.
+
+33
+00:03:05,000 --> 00:03:11,000
+Also, we can map data bonding errors easily with the help of spring forms.
+
+34
+00:03:11,000 --> 00:03:14,000
+And today I am going to show you this to.
+
+35
+00:03:14,000 --> 00:03:18,000
+Feel free to press a pause for a minute and explore.
+
+36
+00:03:18,000 --> 00:03:21,000
+Spring form Tags on the slide.
+
+37
+00:03:22,000 --> 00:03:29,000
+Once you review those and read description, please feel free to proceed with the lesson.
+
+38
+00:03:30,000 --> 00:03:32,000
+So we learn theory.
+
+39
+00:03:32,000 --> 00:03:38,000
+Let's jump directly to the examples and learn the topic on real examples.
+
+40
+00:03:39,000 --> 00:03:47,000
+As always, I prepared a lot of code examples for you and you can find the source code in attachments
+
+41
+00:03:47,000 --> 00:03:48,000
+to the video.
+
+42
+00:03:48,000 --> 00:03:51,000
+First of all, let's create our model.
+
+43
+00:03:52,000 --> 00:03:55,000
+Let's imagine that we have a user with the first name LastName.
+
+44
+00:03:55,000 --> 00:03:59,000
+Email and password is clear.
+
+45
+00:03:59,000 --> 00:04:04,000
+Here is our user I market with a component annotation.
+
+46
+00:04:05,000 --> 00:04:07,000
+So here is our bin.
+
+47
+00:04:07,000 --> 00:04:08,000
+That's perfect.
+
+48
+00:04:08,000 --> 00:04:12,000
+Let's continue and create our new controller.
+
+49
+00:04:13,000 --> 00:04:13,000
+I agree.
+
+50
+00:04:13,000 --> 00:04:15,000
+User controller.
+
+51
+00:04:15,000 --> 00:04:18,000
+The base request mapping is test.
+
+52
+00:04:19,000 --> 00:04:24,000
+The first method in our request controller is for user registration form.
+
+53
+00:04:25,000 --> 00:04:32,000
+When request is sent here, we create the object of our user model and we return the view name that
+
+54
+00:04:32,000 --> 00:04:35,000
+contains our registration form.
+
+55
+00:04:36,000 --> 00:04:41,000
+The next request mapping here is created for the submit form action.
+
+56
+00:04:42,000 --> 00:04:49,000
+Pay attention that they use model attribute annotation and specify the name of the model set I expect
+
+57
+00:04:49,000 --> 00:04:51,000
+to receive and this method.
+
+58
+00:04:52,000 --> 00:04:55,000
+So what's this annotation is about?
+
+59
+00:04:55,000 --> 00:05:03,000
+More attribute is annotation that binds a massive parameter or message return value to a named model
+
+60
+00:05:03,000 --> 00:05:04,000
+attribute.
+
+61
+00:05:05,000 --> 00:05:10,000
+In this lesson, we're going to use this adaptation only with the method parameter.
+
+62
+00:05:11,000 --> 00:05:14,000
+This notation has just a few attributes.
+
+63
+00:05:14,000 --> 00:05:19,000
+They add value and name that they used as aliases.
+
+64
+00:05:20,000 --> 00:05:29,000
+This is the name of the model attribute to bind to and binding attribute allows data to be disabled
+
+65
+00:05:29,000 --> 00:05:32,000
+directly on a model attribute method parameter.
+
+66
+00:05:33,000 --> 00:05:42,000
+It is set to true by default, and I can't imagine the case right now when you would like to set this
+
+67
+00:05:42,000 --> 00:05:48,000
+one to false, because usually developers use this annotation to have automatic data binding.
+
+68
+00:05:49,000 --> 00:05:53,000
+So I assume you will never even use this attribute.
+
+69
+00:05:53,000 --> 00:05:55,000
+Let's get back to our demo.
+
+70
+00:05:56,000 --> 00:06:02,000
+You can see here that I set the value in the model attribute user.
+
+71
+00:06:02,000 --> 00:06:08,000
+It is our user model object, so the flow will look like this.
+
+72
+00:06:09,000 --> 00:06:15,000
+User opens registration form and we create object beforehand.
+
+73
+00:06:15,000 --> 00:06:24,000
+After that and user fills out the form on the from them and sends it back to the server.
+
+74
+00:06:24,000 --> 00:06:29,000
+And we receive the model populated with data from the form.
+
+75
+00:06:29,000 --> 00:06:33,000
+Can you understand now why we need the model attribute?
+
+76
+00:06:33,000 --> 00:06:41,000
+Obviously, the parameter type is user model because the parameter type should be the same as the object
+
+77
+00:06:41,000 --> 00:06:44,000
+that we want to populate with data.
+
+78
+00:06:45,000 --> 00:06:53,000
+Basically spring form will populate data into the object and will inject object into our method here.
+
+79
+00:06:53,000 --> 00:07:00,000
+There is no need for you to get request parameters and map them with each field in the new object.
+
+80
+00:07:01,000 --> 00:07:05,000
+Model attribute on a patient helps us make our lives easier.
+
+81
+00:07:06,000 --> 00:07:10,000
+In this method, I can do anything I need with my user first.
+
+82
+00:07:10,000 --> 00:07:19,000
+For example, we can proceed with storing the user into the database on this page or perform any other
+
+83
+00:07:19,000 --> 00:07:21,000
+business valuable operation.
+
+84
+00:07:21,000 --> 00:07:25,000
+Instead, for the sake of the demo, we just printed the console.
+
+85
+00:07:26,000 --> 00:07:31,000
+In this particular case, I will redirect the request to the confirmation page.
+
+86
+00:07:31,000 --> 00:07:35,000
+Let's now take a look at our view layer.
+
+87
+00:07:36,000 --> 00:07:44,000
+So this particular example consists from the two JSP pages on the view layer, the user registration
+
+88
+00:07:44,000 --> 00:07:47,000
+form and registration confirmation.
+
+89
+00:07:47,000 --> 00:07:50,000
+Let me start with the user registration form.
+
+90
+00:07:51,000 --> 00:07:57,000
+First of all, we need to specify that we are going to use spring form tag on the page.
+
+91
+00:07:58,000 --> 00:07:59,000
+On the top of the page.
+
+92
+00:07:59,000 --> 00:08:02,000
+I ad tag the page directive.
+
+93
+00:08:03,000 --> 00:08:06,000
+These tags go with spring and the library.
+
+94
+00:08:07,000 --> 00:08:14,000
+That's why, in case you add the spring, can we see into your dependency manager like I did in my x
+
+95
+00:08:14,000 --> 00:08:14,000
+amount?
+
+96
+00:08:15,000 --> 00:08:16,000
+You shouldn't be worried.
+
+97
+00:08:16,000 --> 00:08:19,000
+We are all set with using the stats.
+
+98
+00:08:20,000 --> 00:08:27,000
+After we declared that we are going to use spring form tags, we can proceed with the creation of our
+
+99
+00:08:27,000 --> 00:08:28,000
+form.
+
+100
+00:08:28,000 --> 00:08:37,000
+I use form graphics and tag form as the element of my form in the action attribute and specifies the
+
+101
+00:08:37,000 --> 00:08:42,000
+request mapping of my method that's supposed to register user.
+
+102
+00:08:43,000 --> 00:08:49,000
+I specify model attribute here to indicate which object I want to populate with data.
+
+103
+00:08:49,000 --> 00:08:58,000
+So as you remember in the Java code, I already created object of the user model and I put into the
+
+104
+00:08:58,000 --> 00:08:58,000
+model.
+
+105
+00:08:59,000 --> 00:09:05,000
+So the user object is present on this page and we are going to populate these fields.
+
+106
+00:09:06,000 --> 00:09:11,000
+You can specify a HTTP method that you want to use while submitting the form.
+
+107
+00:09:12,000 --> 00:09:14,000
+Next things that they use.
+
+108
+00:09:14,000 --> 00:09:17,000
+I use input elements to prepare data for sending.
+
+109
+00:09:18,000 --> 00:09:20,000
+You can see that they use here.
+
+110
+00:09:20,000 --> 00:09:28,000
+POS This POS name should be the same as the property name is the object that you want to populate with
+
+111
+00:09:28,000 --> 00:09:29,000
+data.
+
+112
+00:09:29,000 --> 00:09:34,000
+POS is used to inject the values into the model.
+
+113
+00:09:35,000 --> 00:09:43,000
+Tensions is growing for an attack doesn't have such a star like we used to in the HTML five.
+
+114
+00:09:44,000 --> 00:09:51,000
+That's why in case you want to use password type with asterisks to mask the password you and the input
+
+115
+00:09:51,000 --> 00:09:55,000
+you have to use form password tag.
+
+116
+00:09:56,000 --> 00:09:57,000
+The submit type.
+
+117
+00:09:57,000 --> 00:10:00,000
+I use HTML input tag of submit type.
+
+118
+00:10:00,000 --> 00:10:01,000
+That's it.
+
+119
+00:10:02,000 --> 00:10:08,000
+After user will click on the submit request will be sent to the create user controller.
+
+120
+00:10:08,000 --> 00:10:15,000
+And as we already reviewed in this particular example, we will not execute any business variable operation
+
+121
+00:10:15,000 --> 00:10:18,000
+with the user model to the console.
+
+122
+00:10:18,000 --> 00:10:24,000
+And then we're going just to force the request to another view and print the data from the object.
+
+123
+00:10:25,000 --> 00:10:28,000
+Let's review now another GSP file.
+
+124
+00:10:28,000 --> 00:10:32,000
+Here is example of the registration confirmation view.
+
+125
+00:10:32,000 --> 00:10:34,000
+Nothing special is here.
+
+126
+00:10:34,000 --> 00:10:39,000
+We just use the expression language to bring the data directly into our view.
+
+127
+00:10:40,000 --> 00:10:44,000
+I use the name of the user model property, which is simple user.
+
+128
+00:10:44,000 --> 00:10:45,000
+That's it.
+
+129
+00:10:46,000 --> 00:10:48,000
+Let's see how this example works.
+
+130
+00:10:48,000 --> 00:10:49,000
+And then.
+
+131
+00:10:50,000 --> 00:10:52,000
+I start the web server.
+
+132
+00:10:57,000 --> 00:11:02,000
+And when the web server is started, I sent the request to our source.
+
+133
+00:11:03,000 --> 00:11:04,000
+Yes.
+
+134
+00:11:04,000 --> 00:11:11,000
+And then I will copy and paste request mapping of user registration form.
+
+135
+00:11:12,000 --> 00:11:12,000
+Perfect.
+
+136
+00:11:13,000 --> 00:11:16,000
+Now we are redirected to the user registration form.
+
+137
+00:11:17,000 --> 00:11:22,000
+Let's populate each input in this form with the fake data.
+
+138
+00:11:22,000 --> 00:11:29,000
+And after that I click submit button and I am redirected to the registration confirmation page where
+
+139
+00:11:29,000 --> 00:11:36,000
+I see details that I entered, which proves that model was populated with the data entered into the
+
+140
+00:11:36,000 --> 00:11:37,000
+form.
+
+141
+00:11:38,000 --> 00:11:44,000
+Also, we can see as a result of printing, our model is a console with a recently.
+
+142
+00:11:45,000 --> 00:11:52,000
+In case something is not clear, please do not hesitate to ask your questions and I will be happy to
+
+143
+00:11:52,000 --> 00:11:53,000
+answer.
+
+144
+00:11:53,000 --> 00:11:54,000
+Let's move on.
+
+145
+00:11:55,000 --> 00:11:58,000
+Let's talk now about the model attribute validation.
+
+146
+00:11:59,000 --> 00:12:05,000
+The spring received validation is used to restrict the input provided by the user.
+
+147
+00:12:05,000 --> 00:12:11,000
+And now I'm going to show you how we can validate the user's input screen.
+
+148
+00:12:11,000 --> 00:12:13,000
+Uses the validation API.
+
+149
+00:12:14,000 --> 00:12:16,000
+What is validation API?
+
+150
+00:12:17,000 --> 00:12:26,000
+The bean validation API is a Java specification that is also known as GSR 303 which is used to apply
+
+151
+00:12:26,000 --> 00:12:28,000
+constraints on object model.
+
+152
+00:12:28,000 --> 00:12:31,000
+We are annotations in the attachments.
+
+153
+00:12:31,000 --> 00:12:36,000
+The lesson I have is a GSR 303.
+
+154
+00:12:36,000 --> 00:12:38,000
+Feel free to read it if you wish.
+
+155
+00:12:39,000 --> 00:12:45,000
+For example, we can validate the lance number, regular expression, etc..
+
+156
+00:12:46,000 --> 00:12:50,000
+Apart from that, we can also provide custom validations.
+
+157
+00:12:50,000 --> 00:12:59,000
+You have to understand that the validation API is just a specification set of rules if you want to say
+
+158
+00:12:59,000 --> 00:13:00,000
+so.
+
+159
+00:13:00,000 --> 00:13:04,000
+So it requires specific and concrete implementation.
+
+160
+00:13:04,000 --> 00:13:09,000
+For the concrete implementation, we are going to use the validator.
+
+161
+00:13:09,000 --> 00:13:15,000
+I'm going to show you today which dependencies we need to add into the class pass.
+
+162
+00:13:15,000 --> 00:13:24,000
+The validator is a fully compliant Jesus real suite implementation that allows us to express and validate
+
+163
+00:13:24,000 --> 00:13:27,000
+the application constraints On the screen.
+
+164
+00:13:27,000 --> 00:13:30,000
+You can see different validation annotations from the package.
+
+165
+00:13:30,000 --> 00:13:33,000
+Jakarta Validation constraints.
+
+166
+00:13:33,000 --> 00:13:39,000
+I added the link to the documentation in the attachments to the lesson reviews.
+
+167
+00:13:39,000 --> 00:13:49,000
+These there are a lot of them, but some popular ones are not null mean max size 14.
+
+168
+00:13:50,000 --> 00:13:52,000
+Now let's look at the code example.
+
+169
+00:13:53,000 --> 00:13:57,000
+The first thing that we need to do is to add Hibernate validator dependency.
+
+170
+00:13:58,000 --> 00:14:04,000
+In my maximal file here you can see the dependency for the Hibernate Validator.
+
+171
+00:14:04,000 --> 00:14:10,000
+The next thing that we have to do is to specify validation rules in our model.
+
+172
+00:14:10,000 --> 00:14:15,000
+I created separate clause here that is called user model valid.
+
+173
+00:14:15,000 --> 00:14:22,000
+Basically, this is a scope of our user models that we have reviewed and worked with in The lesson was
+
+174
+00:14:22,000 --> 00:14:24,000
+only a few differences here.
+
+175
+00:14:25,000 --> 00:14:25,000
+I configure it.
+
+176
+00:14:25,000 --> 00:14:27,000
+Validation rules.
+
+177
+00:14:27,000 --> 00:14:29,000
+Let me show them to you.
+
+178
+00:14:30,000 --> 00:14:35,000
+First of all, for each field I configure it, not empty constraint.
+
+179
+00:14:35,000 --> 00:14:42,000
+In each constraint you can put error message that is going to be used in case of validation failure.
+
+180
+00:14:42,000 --> 00:14:49,000
+The second things that I did here I configured zone and constraints was two fields.
+
+181
+00:14:49,000 --> 00:14:53,000
+I assume that annotations are attributes are pretty self described.
+
+182
+00:14:54,000 --> 00:15:01,000
+You can see that here specified minimum possible length and here specified maximum allowed amount of
+
+183
+00:15:01,000 --> 00:15:03,000
+characters in the string value.
+
+184
+00:15:04,000 --> 00:15:11,000
+The third things that I did, I also set email constraint for the email field in order to validate the
+
+185
+00:15:11,000 --> 00:15:15,000
+email and make sure that it is written according to the standards.
+
+186
+00:15:16,000 --> 00:15:20,000
+You can configure as much rules as you want like this.
+
+187
+00:15:20,000 --> 00:15:26,000
+You can use any other annotations from the Constraints package that we have just reviewed.
+
+188
+00:15:27,000 --> 00:15:35,000
+And also important note in case you have field of any reference type and you want to be sure that that
+
+189
+00:15:35,000 --> 00:15:43,000
+object will be also validated, you can use valid annotation whether the validation is used to mark
+
+190
+00:15:43,000 --> 00:15:45,000
+nested attributes.
+
+191
+00:15:45,000 --> 00:15:50,000
+In particular, this triggers the validation of the nested object.
+
+192
+00:15:50,000 --> 00:15:57,000
+For example, in case our user would have role attribute, we can put valid annotation above the row
+
+193
+00:15:57,000 --> 00:16:00,000
+field and it will be also validated.
+
+194
+00:16:01,000 --> 00:16:08,000
+Now it is time to get back to the controller and take a look at what changes we need to apply in our
+
+195
+00:16:08,000 --> 00:16:08,000
+controller.
+
+196
+00:16:09,000 --> 00:16:12,000
+So I open user controller again.
+
+197
+00:16:13,000 --> 00:16:16,000
+I created a similar example that we have already reviewed.
+
+198
+00:16:17,000 --> 00:16:19,000
+I just added validation.
+
+199
+00:16:19,000 --> 00:16:26,000
+Both examples stay in this file so that you could compare them with each other.
+
+200
+00:16:26,000 --> 00:16:33,000
+So in the user registration form is validation, we create object of the user model, valid type.
+
+201
+00:16:34,000 --> 00:16:39,000
+This is the type that we have just reviewed that contains validation rules.
+
+202
+00:16:39,000 --> 00:16:46,000
+In a similar way, we add it into the model and for us request those of you and this is the name of
+
+203
+00:16:46,000 --> 00:16:54,000
+another GCP file that contains the form which will be submitted to the controller map with a URL that
+
+204
+00:16:54,000 --> 00:16:57,000
+will ensure data binding validations.
+
+205
+00:16:57,000 --> 00:17:00,000
+So here is the new GCP.
+
+206
+00:17:00,000 --> 00:17:02,000
+I changed a few things.
+
+207
+00:17:02,000 --> 00:17:09,000
+I edit one style for errors and a few fields to indicate errors associated with the field.
+
+208
+00:17:09,000 --> 00:17:11,000
+I'm going to show them later.
+
+209
+00:17:12,000 --> 00:17:15,000
+Right now I want to draw attention to one simple thing.
+
+210
+00:17:16,000 --> 00:17:23,000
+You can see that in the action attribute I specified request mapping that is mapped to the method that
+
+211
+00:17:23,000 --> 00:17:30,000
+will record the results of our data binding validations, create user validation.
+
+212
+00:17:31,000 --> 00:17:34,000
+And here it is in the source code.
+
+213
+00:17:34,000 --> 00:17:40,000
+In this method we have valid annotation that goes before the model attribute.
+
+214
+00:17:41,000 --> 00:17:48,000
+In simple words, this means that data bar in this model attribute needs to be verified.
+
+215
+00:17:49,000 --> 00:17:54,000
+Constraints defined on the object and its properties are validated.
+
+216
+00:17:55,000 --> 00:18:00,000
+So the next question is how we can get know about data.
+
+217
+00:18:00,000 --> 00:18:02,000
+Abundant errors.
+
+218
+00:18:02,000 --> 00:18:03,000
+Very simple.
+
+219
+00:18:03,000 --> 00:18:08,000
+Pay attention to the parameter of the binding result type here.
+
+220
+00:18:08,000 --> 00:18:14,000
+The object of this type will be used to explore the data binding errors.
+
+221
+00:18:14,000 --> 00:18:21,000
+Based on the data binding errors, we are going to make a decision where to redirect user again.
+
+222
+00:18:22,000 --> 00:18:26,000
+Their attention to the position of the one result parameter.
+
+223
+00:18:26,000 --> 00:18:28,000
+This is important.
+
+224
+00:18:28,000 --> 00:18:35,000
+Zimbabwe result parameter should go after our model attribute that will come to us from the form.
+
+225
+00:18:36,000 --> 00:18:44,000
+To verify whether there are any data errors you can just call method has errors on the result object.
+
+226
+00:18:45,000 --> 00:18:53,000
+Usually we use this method to define where to redirect using like you can see here in case there are
+
+227
+00:18:53,000 --> 00:18:58,000
+errors in the data binding before a request to the same view.
+
+228
+00:18:59,000 --> 00:19:04,000
+And we want to indicate to the end user where exactly errors happened.
+
+229
+00:19:05,000 --> 00:19:12,000
+In case known data binding errors before the user request to the registration confirmation page.
+
+230
+00:19:13,000 --> 00:19:18,000
+Also here I left command the example of binding result API.
+
+231
+00:19:19,000 --> 00:19:26,000
+For example, you can call master to get field errors and receive the action of the whole field errors
+
+232
+00:19:26,000 --> 00:19:28,000
+where constraints were violated.
+
+233
+00:19:29,000 --> 00:19:36,000
+In this case, I iterate over each item in the collection and bring those into the console.
+
+234
+00:19:36,000 --> 00:19:38,000
+Another example here.
+
+235
+00:19:38,000 --> 00:19:42,000
+It is about how you can validate the object programmatically.
+
+236
+00:19:42,000 --> 00:19:47,000
+We create validation factory using validation clause.
+
+237
+00:19:47,000 --> 00:19:55,000
+Having factory, I can create object of validator type and have it validate that I can validate the
+
+238
+00:19:55,000 --> 00:19:59,000
+object and receives a set of constraint violation.
+
+239
+00:20:00,000 --> 00:20:01,000
+In a similar way.
+
+240
+00:20:01,000 --> 00:20:07,000
+I iterate over each constraint variation here and print each variation message to the console.
+
+241
+00:20:08,000 --> 00:20:17,000
+Just remember this API to potentially it can come in handy for you in the future, not only in the speaker
+
+242
+00:20:17,000 --> 00:20:26,000
+application because this is Java validation API that can be used separately and not only existing applications,
+
+243
+00:20:26,000 --> 00:20:31,000
+but we don't need this at the moment so I will keep it commanded.
+
+244
+00:20:32,000 --> 00:20:38,000
+Feel free to explore these lines of code and execute them when you will play with these code examples.
+
+245
+00:20:39,000 --> 00:20:41,000
+So let's continue.
+
+246
+00:20:41,000 --> 00:20:50,000
+The next thing that we need to do is to let our end user know what is wrong with the data he entered.
+
+247
+00:20:50,000 --> 00:20:51,000
+How to do this.
+
+248
+00:20:52,000 --> 00:20:59,000
+We have one result with errors, so the only things that we need to do is to force request back to the
+
+249
+00:20:59,000 --> 00:21:05,000
+same form and specify places where error messages will be shown.
+
+250
+00:21:05,000 --> 00:21:09,000
+Screen is smart enough to match errors with fields.
+
+251
+00:21:10,000 --> 00:21:15,000
+And keep binding result object in scope of the same request.
+
+252
+00:21:15,000 --> 00:21:22,000
+Let me show you our user registration form and where we put placeholders for error messages.
+
+253
+00:21:22,000 --> 00:21:27,000
+Here in the gsb you can see that I created style for error.
+
+254
+00:21:27,000 --> 00:21:35,000
+Obviously, you can put this into a separate thesis file and if you want to learn more, take a look
+
+255
+00:21:35,000 --> 00:21:37,000
+at the CSS classes in my course.
+
+256
+00:21:37,000 --> 00:21:39,000
+Java from zero to first job.
+
+257
+00:21:40,000 --> 00:21:45,000
+Anyway, for the sake of this example, I decided to keep everything in one file.
+
+258
+00:21:45,000 --> 00:21:52,000
+And here in our form you can see use form that is it is called error.
+
+259
+00:21:52,000 --> 00:21:59,000
+I post the field name, it is associated with the error and I also pause the class name for this type
+
+260
+00:21:59,000 --> 00:22:01,000
+of error message.
+
+261
+00:22:01,000 --> 00:22:08,000
+And again, you can style this as you wish and place error message wherever you want.
+
+262
+00:22:08,000 --> 00:22:11,000
+This is just one of the examples.
+
+263
+00:22:12,000 --> 00:22:16,000
+Let's look at example and how it looks like in the browser.
+
+264
+00:22:16,000 --> 00:22:22,000
+So in the browser I specify user registration form with validation.
+
+265
+00:22:23,000 --> 00:22:25,000
+I'm directed to the form.
+
+266
+00:22:26,000 --> 00:22:34,000
+Imagine the user just pressed submit button in this case will know that data binding constraints are
+
+267
+00:22:34,000 --> 00:22:39,000
+violated and we again redirect it to the same page with error messages.
+
+268
+00:22:39,000 --> 00:22:41,000
+Here is that we're.
+
+269
+00:22:42,000 --> 00:22:50,000
+And in case all validation rules will be met, I will be able to proceed to the registration confirmation
+
+270
+00:22:50,000 --> 00:22:51,000
+page.
+
+271
+00:22:51,000 --> 00:23:00,000
+Let me fill out the form with a valid date now, and after that I click submit button and here we are.
+
+272
+00:23:00,000 --> 00:23:04,000
+We're redirected to the success page holds it.
+
+273
+00:23:04,000 --> 00:23:06,000
+Now it is clear how it works.
+
+274
+00:23:07,000 --> 00:23:12,000
+Please take the source code of this example rather than your computer.
+
+275
+00:23:12,000 --> 00:23:15,000
+This will help you to understand the topic better.
+
+276
+00:23:16,000 --> 00:23:23,000
+In case you have any questions, please do not hesitate to ask your questions below the video I will
+
+277
+00:23:23,000 --> 00:23:24,000
+be happy to answer.
+
+278
+00:23:25,000 --> 00:23:33,000
+So if you remember in the previous lesson we started comparison of the HTTP request and model.
+
+279
+00:23:33,000 --> 00:23:41,000
+Both of them has a request code and both of them can be used like a container for attributes.
+
+280
+00:23:41,000 --> 00:23:48,000
+But with this lesson and belief, you can see advantages that can be provided by the model object and
+
+281
+00:23:48,000 --> 00:23:53,000
+that can be provided just by HTTP request object.
+
+282
+00:23:54,000 --> 00:24:03,000
+So answering the question about HTTP request model and when to use what we can summarize and say the
+
+283
+00:24:03,000 --> 00:24:04,000
+following things.
+
+284
+00:24:05,000 --> 00:24:10,000
+There is no such sense that something is always preferable to use.
+
+285
+00:24:10,000 --> 00:24:12,000
+It is just your wish.
+
+286
+00:24:12,000 --> 00:24:21,000
+Since both requests scope, both model, and that request exists within the scope of one single request.
+
+287
+00:24:21,000 --> 00:24:25,000
+But if you use model, you have several advantages.
+
+288
+00:24:25,000 --> 00:24:33,000
+No need to map request attributes because you can put object into the model and it will be recognized
+
+289
+00:24:33,000 --> 00:24:41,000
+on the view layer using spring forms Data binding will be easily done with the object from the model
+
+290
+00:24:41,000 --> 00:24:48,000
+and you will be able to get the object with a populated data with the help of model attribute annotation.
+
+291
+00:24:49,000 --> 00:24:56,000
+Validations can be done just by using valid annotation and with the help of one result object.
+
+292
+00:24:57,000 --> 00:25:02,000
+These are probably the main advantages of using model over this request object.
+
+293
+00:25:03,000 --> 00:25:06,000
+That's what I wanted to discuss with you today.
+
+294
+00:25:06,000 --> 00:25:10,000
+Let's recap what we have learned in this lesson.
+
+295
+00:25:12,000 --> 00:25:13,000
+Spring forms.
+
+296
+00:25:14,000 --> 00:25:18,000
+Also, I showed you how to work with model attribute.
+
+297
+00:25:18,000 --> 00:25:23,000
+We learned visualization API and source velocity.
+
+298
+00:25:23,000 --> 00:25:30,000
+After that we learned how to use valid annotation by link result type and how to validate objects with
+
+299
+00:25:30,000 --> 00:25:33,000
+the help of gearbox validation API.
+
+300
+00:25:34,000 --> 00:25:40,000
+And at the end of the lesson, we reviewed best practices of error handling in case of binding errors.
+
+301
+00:25:41,000 --> 00:25:43,000
+That's all for today.
+
+302
+00:25:43,000 --> 00:25:45,000
+Thanks a lot for your attention.
+
+303
+00:25:45,000 --> 00:25:48,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/003 Validation-constraints-annotations.url b/82 - Spring MVC & Spring for WEB/003 Validation-constraints-annotations.url
new file mode 100644
index 0000000000000000000000000000000000000000..faf305d608c16a9509d7342845a20279d01d1197
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/003 Validation-constraints-annotations.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://jakarta.ee/specifications/platform/9/apidocs/jakarta/validation/constraints/package-summary.html
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/004 Exception Handling in Spring MVC_en.srt b/82 - Spring MVC & Spring for WEB/004 Exception Handling in Spring MVC_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..31f87a57cfb2d5941c37e52cfa6df9cc231212bc
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/004 Exception Handling in Spring MVC_en.srt
@@ -0,0 +1,1264 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Jim.
+
+2
+00:00:06,000 --> 00:00:10,000
+In this lesson, we're going to learn exception handling in spring.
+
+3
+00:00:10,000 --> 00:00:15,000
+And we see there are different ways of how we can handle exceptions in spring.
+
+4
+00:00:15,000 --> 00:00:22,000
+And we see in this lesson we're going to use spring controller based exception handler using exception
+
+5
+00:00:22,000 --> 00:00:30,000
+Handler annotation Global Exception handle using controller advice, annotation and handler exception
+
+6
+00:00:30,000 --> 00:00:31,000
+resolver.
+
+7
+00:00:31,000 --> 00:00:37,000
+So basically, these are three main exception handling approaches that we are going to learn in this
+
+8
+00:00:37,000 --> 00:00:38,000
+lesson.
+
+9
+00:00:38,000 --> 00:00:45,000
+I'm going to show you how you can configure your custom exception in the spring MVC in order to associated
+
+10
+00:00:45,000 --> 00:00:53,000
+with the specific response status and exception reason, we'll then response status annotation and I'm
+
+11
+00:00:53,000 --> 00:00:57,000
+going to show you how you can use this annotation on practice.
+
+12
+00:00:57,000 --> 00:01:05,000
+Also, I will show you how we can handle 404 where in other words, not found exceptions in our spring.
+
+13
+00:01:05,000 --> 00:01:07,000
+Can we see web application?
+
+14
+00:01:07,000 --> 00:01:09,000
+Let's start our lesson.
+
+15
+00:01:10,000 --> 00:01:16,000
+If you are familiar with the basics of the web development and servlet technology in Java, you already
+
+16
+00:01:16,000 --> 00:01:23,000
+know why exception handling is important in web applications because we need to prevent sending errors
+
+17
+00:01:23,000 --> 00:01:24,000
+to the client.
+
+18
+00:01:25,000 --> 00:01:32,000
+We need to find the way how we can handle the exceptions on the server side and decide what to do in
+
+19
+00:01:32,000 --> 00:01:34,000
+each particular case.
+
+20
+00:01:34,000 --> 00:01:42,000
+In most cases this is a matter of log error and show an end user some meaningful error message that
+
+21
+00:01:42,000 --> 00:01:50,000
+contains the error root cause and recommendations about further navigation in your application.
+
+22
+00:01:50,000 --> 00:01:57,000
+Any web application requires good design for exception handling because we don't want to send back to
+
+23
+00:01:57,000 --> 00:02:05,000
+the client auto generated page by our web server when any handled exception is thrown by our application.
+
+24
+00:02:06,000 --> 00:02:11,000
+Like we have talked already while reviewing our agenda, there are different ways of how to implement
+
+25
+00:02:11,000 --> 00:02:13,000
+error handling in the spring.
+
+26
+00:02:13,000 --> 00:02:17,000
+MVC Let's review three options a little bit closer.
+
+27
+00:02:18,000 --> 00:02:24,000
+Spring Can we see Framework provides all ways to help us achieve robust exception Handler.
+
+28
+00:02:25,000 --> 00:02:27,000
+The first one is controller based.
+
+29
+00:02:28,000 --> 00:02:35,000
+One of the simplest way to define piece of code is it is going to handle exception is to declare methods
+
+30
+00:02:35,000 --> 00:02:40,000
+marked with exception handler annotation inside your controller.
+
+31
+00:02:40,000 --> 00:02:44,000
+This annotation takes exception class as an argument.
+
+32
+00:02:45,000 --> 00:02:52,000
+Basically, you can specify exceptions of which type this massive supposed to handle.
+
+33
+00:02:52,000 --> 00:03:00,000
+So if we have defined exception handler for complete exception class, then all the exceptions that
+
+34
+00:03:00,000 --> 00:03:07,000
+are compatible with a specified exception type zone by our request handler message will be handled inside
+
+35
+00:03:07,000 --> 00:03:08,000
+our controller.
+
+36
+00:03:09,000 --> 00:03:16,000
+These exception handler masses are just like other request handler masses, and we can build error response
+
+37
+00:03:16,000 --> 00:03:19,000
+and respond with different error pages.
+
+38
+00:03:20,000 --> 00:03:27,000
+If there are multiple exception handler masses, define the handler method that is closest to the exception
+
+39
+00:03:27,000 --> 00:03:29,000
+class is used.
+
+40
+00:03:29,000 --> 00:03:37,000
+For example, we have two handler masses defined for either exception and exception, and now a request
+
+41
+00:03:37,000 --> 00:03:40,000
+handler method throws either exception.
+
+42
+00:03:40,000 --> 00:03:44,000
+The handler method for either exception will get executed.
+
+43
+00:03:44,000 --> 00:03:51,000
+The second way of error handling in squinting we see can be named as global exception handler that is
+
+44
+00:03:51,000 --> 00:03:53,000
+implemented with the controller advice.
+
+45
+00:03:54,000 --> 00:03:58,000
+What advice is and what aspects are in the program?
+
+46
+00:03:58,000 --> 00:04:05,000
+We are going to learn and other lessons, but Ensure advice describes a class of functions which modify
+
+47
+00:04:05,000 --> 00:04:08,000
+other functions when the later are wrong.
+
+48
+00:04:08,000 --> 00:04:16,000
+It is a certain function method or procedure that is to be applied at a given point of a program.
+
+49
+00:04:16,000 --> 00:04:18,000
+What is a join point?
+
+50
+00:04:19,000 --> 00:04:25,000
+This is another term from the aspect oriented program that will run in separate classes.
+
+51
+00:04:25,000 --> 00:04:30,000
+But still I will make a reference here to help you understand the context.
+
+52
+00:04:30,000 --> 00:04:38,000
+At one point is a specific point in the application, such as method, execution, exception handling,
+
+53
+00:04:38,000 --> 00:04:46,000
+change, an object, variable values, etc. In spring AOP, a German point is always the execution of
+
+54
+00:04:46,000 --> 00:04:48,000
+a massive exception.
+
+55
+00:04:48,000 --> 00:04:51,000
+Handling is a cross-cutting concern.
+
+56
+00:04:51,000 --> 00:04:55,000
+It should be done for all point cuts in our application.
+
+57
+00:04:56,000 --> 00:04:57,000
+And again, here we are.
+
+58
+00:04:57,000 --> 00:05:03,000
+One more charm from the aspect oriented program from AOP.
+
+59
+00:05:03,000 --> 00:05:10,000
+Point Corp is a set of one or more join points where an advice should be executed.
+
+60
+00:05:11,000 --> 00:05:18,000
+Spring provides controller advice on a patient that we can use with any class to define our global exception
+
+61
+00:05:18,000 --> 00:05:19,000
+Handler.
+
+62
+00:05:19,000 --> 00:05:27,000
+The handler message in global controller advice as the same as controller based exception methods with
+
+63
+00:05:27,000 --> 00:05:34,000
+the exception handler annotation and use one controller class is not able to handle the exception,
+
+64
+00:05:35,000 --> 00:05:42,000
+and the sad way to implement exception handling in the speaking we see is with handler exception resolver
+
+65
+00:05:42,000 --> 00:05:50,000
+for generic exceptions, most of the times we serve static pages spring framework provides handler exception
+
+66
+00:05:50,000 --> 00:05:56,000
+resolver interface that we can implement the create global exception handler.
+
+67
+00:05:57,000 --> 00:06:03,000
+The reason behind this additional way to define global exception handler is that string framework also
+
+68
+00:06:03,000 --> 00:06:10,000
+provides the default implementation classes that we can define in our spring bin configuration file
+
+69
+00:06:10,000 --> 00:06:14,000
+to get string framework Exception Handler Benefits.
+
+70
+00:06:15,000 --> 00:06:20,000
+Simple map and exception resolver is a default implementation class.
+
+71
+00:06:20,000 --> 00:06:28,000
+It allows us to configure exception mappings where we can specify which resource to use for a particular
+
+72
+00:06:28,000 --> 00:06:28,000
+exception.
+
+73
+00:06:29,000 --> 00:06:37,000
+We can also override to create our own global handler with our application specific changes such as
+
+74
+00:06:37,000 --> 00:06:40,000
+logging of exception messages.
+
+75
+00:06:40,000 --> 00:06:47,000
+I assume that we learned enough theory by this moment, and I believe you will be able to understand
+
+76
+00:06:47,000 --> 00:06:50,000
+this topic better with examples.
+
+77
+00:06:50,000 --> 00:06:55,000
+So let me start screen sharing and show you the examples that I prepared for you.
+
+78
+00:06:56,000 --> 00:07:00,000
+As always, you can find code examples in attachments to the video.
+
+79
+00:07:01,000 --> 00:07:08,000
+We have a lot of different examples during the lesson, but first, let me show you how we can define
+
+80
+00:07:08,000 --> 00:07:12,000
+our custom exception and use it in spring MVC.
+
+81
+00:07:13,000 --> 00:07:16,000
+I open user found Exception class.
+
+82
+00:07:16,000 --> 00:07:23,000
+If you are a student of my Java from zero to first job course, then you already know how to create
+
+83
+00:07:23,000 --> 00:07:24,000
+exceptions.
+
+84
+00:07:24,000 --> 00:07:28,000
+We extend our class from exception class.
+
+85
+00:07:28,000 --> 00:07:36,000
+We create the constructor just to take an email of the users that can't be found and we call the super
+
+86
+00:07:36,000 --> 00:07:39,000
+constructor to pass the exception message.
+
+87
+00:07:40,000 --> 00:07:43,000
+Referential to the response status annotation.
+
+88
+00:07:43,000 --> 00:07:50,000
+With the help of this annotation, you can configure which response code will be returned to the client
+
+89
+00:07:50,000 --> 00:07:52,000
+in case such error is wrong.
+
+90
+00:07:53,000 --> 00:08:01,000
+With this annotation we can mark a method or exception clause in the code attribute, we should specify
+
+91
+00:08:01,000 --> 00:08:03,000
+status code of the response.
+
+92
+00:08:03,000 --> 00:08:07,000
+You can see that the use http status enum.
+
+93
+00:08:08,000 --> 00:08:13,000
+Each enum is mapped with a specific numeric code status.
+
+94
+00:08:13,000 --> 00:08:22,000
+Reason attribute can be used for response in case we use reason HDP server response send error message
+
+95
+00:08:22,000 --> 00:08:23,000
+is used.
+
+96
+00:08:23,000 --> 00:08:26,000
+That's how you can create your exception.
+
+97
+00:08:26,000 --> 00:08:29,000
+Later, I'm going to show you how we can use it.
+
+98
+00:08:30,000 --> 00:08:39,000
+Now we're going to the examples with different types of handlers, namely controller based level exception
+
+99
+00:08:39,000 --> 00:08:42,000
+handler and handler exception resolver.
+
+100
+00:08:42,000 --> 00:08:47,000
+And after that, we'll run the set to review all these examples.
+
+101
+00:08:48,000 --> 00:08:52,000
+Let's start with the example of controller based exception handle.
+
+102
+00:08:53,000 --> 00:08:57,000
+I open example that is called exception handler controller.
+
+103
+00:08:57,000 --> 00:09:00,000
+It is marked with the controller annotation.
+
+104
+00:09:01,000 --> 00:09:05,000
+As always, I set basic mapping to the test URL.
+
+105
+00:09:05,000 --> 00:09:06,000
+Let's run now.
+
+106
+00:09:06,000 --> 00:09:08,000
+What is written here?
+
+107
+00:09:08,000 --> 00:09:16,000
+I have request mapping here mapped with a URL and email pos variable depending on the email value.
+
+108
+00:09:17,000 --> 00:09:19,000
+I deliberately throw different exception.
+
+109
+00:09:19,000 --> 00:09:26,000
+In order to show you which exception handler in our application will handle the exception.
+
+110
+00:09:26,000 --> 00:09:34,000
+You can see that in case of the first user email I throw user not found exception that we have just
+
+111
+00:09:34,000 --> 00:09:38,000
+created with you in case email is equal to the SQL.
+
+112
+00:09:38,000 --> 00:09:47,000
+I throw SQL exception in case email is equal to the IO, then I throw IO exception in case email will
+
+113
+00:09:47,000 --> 00:09:49,000
+be equal to John Doe.
+
+114
+00:09:49,000 --> 00:09:54,000
+In this case I will create user object, put it into the model and go for it.
+
+115
+00:09:54,000 --> 00:09:57,000
+Request is a user view.
+
+116
+00:09:57,000 --> 00:10:03,000
+In all other cases, new exception will be thrown is clear.
+
+117
+00:10:04,000 --> 00:10:07,000
+What else do we have here in the class?
+
+118
+00:10:07,000 --> 00:10:11,000
+We have another method here that is marked with the annotation exception handler.
+
+119
+00:10:12,000 --> 00:10:19,000
+As we discussed during the presentation Review Exception Handler annotation takes class of the exception
+
+120
+00:10:19,000 --> 00:10:22,000
+that is supposed to be handled.
+
+121
+00:10:22,000 --> 00:10:27,000
+This means that in case user mode found exception will be thrown.
+
+122
+00:10:27,000 --> 00:10:31,000
+This code will be executed and exception will be handled here.
+
+123
+00:10:32,000 --> 00:10:35,000
+This approach has significant drawback.
+
+124
+00:10:35,000 --> 00:10:44,000
+The exception Handler annotated method is only active for the particular control, not globally for
+
+125
+00:10:44,000 --> 00:10:45,000
+the entire application.
+
+126
+00:10:46,000 --> 00:10:53,000
+Of course, adding this to every controller makes it not well suited for a general exception handling
+
+127
+00:10:53,000 --> 00:10:54,000
+mechanism.
+
+128
+00:10:54,000 --> 00:10:59,000
+That's why let's review other more general solutions.
+
+129
+00:11:00,000 --> 00:11:08,000
+Now let's review example of the global error handler implemented with the controller advice I Open Source
+
+130
+00:11:08,000 --> 00:11:10,000
+Error Controller Advisor.
+
+131
+00:11:10,000 --> 00:11:16,000
+Pay attention that this class is annotated with a controller advice annotation.
+
+132
+00:11:16,000 --> 00:11:23,000
+By default, the masses in controller advice apply globally to all controllers.
+
+133
+00:11:23,000 --> 00:11:29,000
+Pay attention that all the masses here are marked with the exception handler annotation.
+
+134
+00:11:30,000 --> 00:11:32,000
+We have just reviewed this annotation.
+
+135
+00:11:33,000 --> 00:11:41,000
+The important fact to know in the handle circle exception method which you name as a response page.
+
+136
+00:11:41,000 --> 00:11:44,000
+So the response code will be 200.
+
+137
+00:11:46,000 --> 00:11:49,000
+But in the case of the IO exception, we return nothing.
+
+138
+00:11:50,000 --> 00:11:52,000
+The return type is void.
+
+139
+00:11:52,000 --> 00:11:54,000
+What does it mean for us?
+
+140
+00:11:54,000 --> 00:12:00,000
+This means that response status code will be not found for a four.
+
+141
+00:12:00,000 --> 00:12:04,000
+Basically, the exception handler will be found.
+
+142
+00:12:04,000 --> 00:12:06,000
+Request will be processed.
+
+143
+00:12:06,000 --> 00:12:07,000
+Handle.
+
+144
+00:12:07,000 --> 00:12:11,000
+And four of four status code will be returned.
+
+145
+00:12:11,000 --> 00:12:18,000
+Even in case we have exception handler for not found exceptions, it won't be triggered in this case
+
+146
+00:12:19,000 --> 00:12:21,000
+because we have handling.
+
+147
+00:12:21,000 --> 00:12:29,000
+We processed the request and we deliberately sending four or four response status to the client.
+
+148
+00:12:29,000 --> 00:12:30,000
+Is it clear?
+
+149
+00:12:30,000 --> 00:12:37,000
+But another good question is how to create exception handler for not found exceptions.
+
+150
+00:12:37,000 --> 00:12:42,000
+Because there is no code that would throw for a for exception.
+
+151
+00:12:43,000 --> 00:12:47,000
+Let's understand how we can implement such kind of exception handler.
+
+152
+00:12:48,000 --> 00:12:55,000
+And this is relevant question because in the case of us, exceptions from our examples, exceptions
+
+153
+00:12:55,000 --> 00:13:00,000
+happen inside the code and thrown from the code.
+
+154
+00:13:00,000 --> 00:13:07,000
+But how exception can be thrown in case client just requested zero source.
+
+155
+00:13:07,000 --> 00:13:09,000
+This is absent in the mapping.
+
+156
+00:13:09,000 --> 00:13:12,000
+So how to throw exception in this case?
+
+157
+00:13:13,000 --> 00:13:15,000
+In case there is no code that throws exception.
+
+158
+00:13:15,000 --> 00:13:17,000
+You understand my question?
+
+159
+00:13:17,000 --> 00:13:22,000
+That's why this is a question that my students often ask me.
+
+160
+00:13:23,000 --> 00:13:28,000
+Actually, there are different ways how to handle for or for error.
+
+161
+00:13:28,000 --> 00:13:34,000
+I'm going to show you the one that I use to handle four of four errors.
+
+162
+00:13:34,000 --> 00:13:36,000
+We need to make few adjustments.
+
+163
+00:13:37,000 --> 00:13:39,000
+I open error controller advisor.
+
+164
+00:13:40,000 --> 00:13:42,000
+Here you can find exception handler massive.
+
+165
+00:13:42,000 --> 00:13:47,000
+That's supposed to handle no handler found exception.
+
+166
+00:13:47,000 --> 00:13:51,000
+This is a method that will handle our four or four exceptions.
+
+167
+00:13:51,000 --> 00:13:54,000
+Apparently there is no handler found.
+
+168
+00:13:54,000 --> 00:13:56,000
+Exception should be thrown.
+
+169
+00:13:56,000 --> 00:13:58,000
+How to do this?
+
+170
+00:13:58,000 --> 00:14:02,000
+Let's open configuration of our dispatcher server.
+
+171
+00:14:02,000 --> 00:14:05,000
+It is located in the class main web app.
+
+172
+00:14:05,000 --> 00:14:07,000
+Initialize it.
+
+173
+00:14:07,000 --> 00:14:13,000
+We need to set a parameter that is called zero exception if no handler found.
+
+174
+00:14:13,000 --> 00:14:18,000
+So in this line I set the value of this parameter to true.
+
+175
+00:14:18,000 --> 00:14:25,000
+Now, in case client will request resource for which there is no handler, new exception will be thrown.
+
+176
+00:14:26,000 --> 00:14:33,000
+And in this case, our exception handler from the controller advice will be able to handle the exception.
+
+177
+00:14:33,000 --> 00:14:34,000
+Is it clear?
+
+178
+00:14:35,000 --> 00:14:41,000
+Even in case you have any questions, please post your questions below the video and I will be happy
+
+179
+00:14:41,000 --> 00:14:42,000
+to answer.
+
+180
+00:14:43,000 --> 00:14:44,000
+Let's continue now.
+
+181
+00:14:45,000 --> 00:14:52,000
+As you can see, we still have some exceptions to handle, namely in our example from exception handler
+
+182
+00:14:52,000 --> 00:14:53,000
+controller.
+
+183
+00:14:53,000 --> 00:14:57,000
+We can see that we have handler for user defined exception.
+
+184
+00:14:57,000 --> 00:14:58,000
+For special exception.
+
+185
+00:14:59,000 --> 00:15:00,000
+For IO exception.
+
+186
+00:15:01,000 --> 00:15:04,000
+We just to implement handler for the general exception.
+
+187
+00:15:04,000 --> 00:15:04,000
+Correct.
+
+188
+00:15:05,000 --> 00:15:06,000
+I have.
+
+189
+00:15:06,000 --> 00:15:08,000
+This was one handler exception resolver.
+
+190
+00:15:08,000 --> 00:15:10,000
+Let's take a look at it.
+
+191
+00:15:11,000 --> 00:15:16,000
+To implement this approach, we need to declare being of handler exception resolver type.
+
+192
+00:15:17,000 --> 00:15:21,000
+This will resolve any exceptions thrown by the application.
+
+193
+00:15:21,000 --> 00:15:28,000
+There are options to use already existing implementations of the handler exception resolver interface
+
+194
+00:15:29,000 --> 00:15:32,000
+or define the custom implementation.
+
+195
+00:15:32,000 --> 00:15:35,000
+It is up to you which way to choose.
+
+196
+00:15:35,000 --> 00:15:39,000
+Let me quickly make an overview of the main implementations.
+
+197
+00:15:40,000 --> 00:15:42,000
+Exception Handler Exception Resolver.
+
+198
+00:15:43,000 --> 00:15:51,000
+This is actually the core component of how the exception mechanism presented earlier works.
+
+199
+00:15:51,000 --> 00:15:54,000
+Default handler Exception resolver.
+
+200
+00:15:54,000 --> 00:16:02,000
+It is used to resolve standards, bring exceptions to their corresponding HTTP status codes, namely
+
+201
+00:16:02,000 --> 00:16:04,000
+client errors and server errors.
+
+202
+00:16:04,000 --> 00:16:05,000
+Status codes.
+
+203
+00:16:05,000 --> 00:16:13,000
+While it does set the status code of the response properly, one limitation is that it doesn't set anything
+
+204
+00:16:13,000 --> 00:16:15,000
+to the body of the response.
+
+205
+00:16:15,000 --> 00:16:22,000
+And for the rest API that we are going to learn the status quo is really not enough information to present
+
+206
+00:16:22,000 --> 00:16:23,000
+to the client.
+
+207
+00:16:23,000 --> 00:16:30,000
+So response has to have a body as well to allow the application to give additional information about
+
+208
+00:16:30,000 --> 00:16:31,000
+the failure.
+
+209
+00:16:32,000 --> 00:16:39,000
+This can be solved by configuring resolution and rendering error content through model and view, but
+
+210
+00:16:39,000 --> 00:16:42,000
+the solution is clearly not optimal.
+
+211
+00:16:43,000 --> 00:16:45,000
+Response status exception resolved.
+
+212
+00:16:46,000 --> 00:16:52,000
+Its main responsibility is to use response status on the patient available on custom exceptions, and
+
+213
+00:16:52,000 --> 00:17:02,000
+to map these exceptions to HTTP status codes and simple map and exception resolver implementations.
+
+214
+00:17:02,000 --> 00:17:10,000
+It allows for mapping exception class names to view names is a first set of given handlers or for all
+
+215
+00:17:10,000 --> 00:17:12,000
+handlers in the dispatcher server.
+
+216
+00:17:13,000 --> 00:17:17,000
+Let's have a custom implementation of the handler exception resolver.
+
+217
+00:17:18,000 --> 00:17:24,000
+Basically, we just need to give implementation of the one method that is called resolve exception.
+
+218
+00:17:24,000 --> 00:17:31,000
+I open web config class because in our demo project we declare beans here.
+
+219
+00:17:31,000 --> 00:17:37,000
+If you want to declare being in the eczema, you're welcome to do too.
+
+220
+00:17:37,000 --> 00:17:42,000
+In our previous lessons we learned how to declare beans in the eczema.
+
+221
+00:17:42,000 --> 00:17:47,000
+So here I declare bean of the handler exception resolver.
+
+222
+00:17:47,000 --> 00:17:54,000
+I return the instance of the anonymous class and I give implementation of the result exception method.
+
+223
+00:17:55,000 --> 00:18:02,000
+According to the interface result, exception method returns an instance of model and views the form
+
+224
+00:18:02,000 --> 00:18:03,000
+and error page.
+
+225
+00:18:04,000 --> 00:18:09,000
+The implementations are typically registered as beans in the application context.
+
+226
+00:18:10,000 --> 00:18:17,000
+In the method we have access to the HTTP server request and HTTP select response to the handler and
+
+227
+00:18:17,000 --> 00:18:18,000
+exception object.
+
+228
+00:18:19,000 --> 00:18:26,000
+So what these parameters are, I'm sure that you don't have any doubts about the first two parameters
+
+229
+00:18:26,000 --> 00:18:32,000
+from this list, but I think that we need to review the set and the force parameter.
+
+230
+00:18:32,000 --> 00:18:37,000
+So handler of type object is executed.
+
+231
+00:18:37,000 --> 00:18:45,000
+Handler Or now if not chosen at the time of the exception, an exception parameter is actually the exception
+
+232
+00:18:45,000 --> 00:18:46,000
+thrown.
+
+233
+00:18:47,000 --> 00:18:50,000
+This message returns us model and value.
+
+234
+00:18:50,000 --> 00:18:55,000
+According to the contract, we didn't work a lot with this type yet.
+
+235
+00:18:56,000 --> 00:18:56,000
+That's why.
+
+236
+00:18:56,000 --> 00:18:59,000
+Let me make a quick overview of this type.
+
+237
+00:19:00,000 --> 00:19:06,000
+This type is a holder for both model and view is a web framework.
+
+238
+00:19:07,000 --> 00:19:15,000
+This class mainly holds both to make it possible for the controller to return both model and view in
+
+239
+00:19:15,000 --> 00:19:16,000
+a single return value.
+
+240
+00:19:17,000 --> 00:19:23,000
+You can see that I create an object here and the name of the view into the constructor.
+
+241
+00:19:24,000 --> 00:19:28,000
+After that I added exception and handler into the model.
+
+242
+00:19:28,000 --> 00:19:31,000
+We're going to print them on the error page.
+
+243
+00:19:31,000 --> 00:19:35,000
+By the way, let me show you the error page.
+
+244
+00:19:35,000 --> 00:19:37,000
+The error page looks simple.
+
+245
+00:19:37,000 --> 00:19:40,000
+I just print exception and handler here.
+
+246
+00:19:40,000 --> 00:19:41,000
+That's it.
+
+247
+00:19:42,000 --> 00:19:47,000
+So it looks like that we created all possible examples for error handling.
+
+248
+00:19:47,000 --> 00:19:53,000
+Now it is time to look how all exception handlers work in case of exceptions.
+
+249
+00:19:53,000 --> 00:19:55,000
+I run the web server now.
+
+250
+00:19:56,000 --> 00:20:01,000
+We're going to start from the verification of our exception handler controller.
+
+251
+00:20:01,000 --> 00:20:05,000
+Let's trigger user not found exception for this.
+
+252
+00:20:05,000 --> 00:20:09,000
+Let me paste your rule with the first user email.
+
+253
+00:20:10,000 --> 00:20:17,000
+User account exception is triggered and in this case, exception handler for user found exception is
+
+254
+00:20:17,000 --> 00:20:18,000
+triggered.
+
+255
+00:20:18,000 --> 00:20:24,000
+We are redirected to the error JSP page that prints exception and the URL.
+
+256
+00:20:25,000 --> 00:20:27,000
+Everything works as expected.
+
+257
+00:20:32,000 --> 00:20:38,000
+The second scenario is that we have to this is how our single exception will be handled.
+
+258
+00:20:39,000 --> 00:20:46,000
+According to our logic, SQL exception is triggered in case I send SQL instead of email.
+
+259
+00:20:46,000 --> 00:20:50,000
+Let me adjust the URL here instead of the email.
+
+260
+00:20:50,000 --> 00:20:52,000
+I cross SQL here.
+
+261
+00:20:53,000 --> 00:21:01,000
+Now SQL Exceptions Trigger exception handler for the SQL exception is located on the level of controller
+
+262
+00:21:01,000 --> 00:21:01,000
+advice.
+
+263
+00:21:02,000 --> 00:21:03,000
+Here it is.
+
+264
+00:21:03,000 --> 00:21:06,000
+The error Controller Advisor.
+
+265
+00:21:06,000 --> 00:21:08,000
+In case I would have an exception.
+
+266
+00:21:08,000 --> 00:21:13,000
+Handler for SQL exception in the exception Handler Controller class.
+
+267
+00:21:13,000 --> 00:21:18,000
+In that case, that exception handler would be triggered.
+
+268
+00:21:18,000 --> 00:21:26,000
+But since I have SQL exception handler on the level of the controller advice only then this one is triggered
+
+269
+00:21:26,000 --> 00:21:30,000
+and we are redirected to the SQL error JSP page.
+
+270
+00:21:31,000 --> 00:21:34,000
+The next thing here is your exception.
+
+271
+00:21:34,000 --> 00:21:40,000
+If you remember, we implement Handler in the way that it will return us for a for exception.
+
+272
+00:21:41,000 --> 00:21:46,000
+I need to adjust pass parameter and change it to IO.
+
+273
+00:21:46,000 --> 00:21:51,000
+And here we can see four of four response and messages.
+
+274
+00:21:51,000 --> 00:21:58,000
+So that proves that I actually entered handler IO exception method from the error controller at this
+
+275
+00:21:58,000 --> 00:21:59,000
+class.
+
+276
+00:22:00,000 --> 00:22:07,000
+Pay attention that in reality we found the handler and we deliberately sent four for exception.
+
+277
+00:22:08,000 --> 00:22:13,000
+And in case I would adjust zero to not exist in resource.
+
+278
+00:22:13,000 --> 00:22:20,000
+In this case, our four or four exception handler for no handler found exception will be triggered.
+
+279
+00:22:21,000 --> 00:22:22,000
+Is that clear?
+
+280
+00:22:22,000 --> 00:22:25,000
+I hope that you are not confused so far.
+
+281
+00:22:26,000 --> 00:22:31,000
+That's why I prepared a lot of examples for you and I keep them separate.
+
+282
+00:22:32,000 --> 00:22:39,000
+Download the code, play with these examples, Spend some time just trying to trigger exceptions and
+
+283
+00:22:39,000 --> 00:22:42,000
+see which handler will be involved.
+
+284
+00:22:42,000 --> 00:22:49,000
+This will help you to understand the topic better and even in case something would still be not clear.
+
+285
+00:22:49,000 --> 00:22:54,000
+Please let me know and I will be happy to answer your questions.
+
+286
+00:22:54,000 --> 00:23:01,000
+The happy case scenario is that here is found and we are redirected to the user JSP page.
+
+287
+00:23:01,000 --> 00:23:09,000
+We hardcoded values, so in case we pass John Doe email, we are redirected to the JSP page without
+
+288
+00:23:09,000 --> 00:23:10,000
+any errors.
+
+289
+00:23:11,000 --> 00:23:15,000
+And the last but not the least case is a generic error, however.
+
+290
+00:23:16,000 --> 00:23:24,000
+In the get user method we have ls block that throws exception and we have declared the handler exception
+
+291
+00:23:24,000 --> 00:23:32,000
+resolver being the handle general exceptions that are not handled by the exception handlers in the web
+
+292
+00:23:32,000 --> 00:23:33,000
+config.
+
+293
+00:23:33,000 --> 00:23:37,000
+Here we declare the being of handler exception resolved.
+
+294
+00:23:37,000 --> 00:23:40,000
+We are going to be redirected to the error page.
+
+295
+00:23:41,000 --> 00:23:42,000
+Let's check this.
+
+296
+00:23:43,000 --> 00:23:50,000
+Does this let me just write any other value instead of the email pos variable in the browser?
+
+297
+00:23:50,000 --> 00:23:56,000
+And we can see that we are forwarded to the generic exception handler, GCP page.
+
+298
+00:23:57,000 --> 00:24:03,000
+Basically, those are all exception handlers that I prepared for our lesson today that I want you to
+
+299
+00:24:03,000 --> 00:24:04,000
+learn.
+
+300
+00:24:04,000 --> 00:24:07,000
+Spend your time by investigating the source code.
+
+301
+00:24:08,000 --> 00:24:15,000
+I know that this topic may sound a little bit challenging, but I tried the best it can to simplify
+
+302
+00:24:15,000 --> 00:24:19,000
+your learning post by providing examples to each case.
+
+303
+00:24:19,000 --> 00:24:22,000
+I hope that you enjoyed the lesson.
+
+304
+00:24:22,000 --> 00:24:26,000
+Let's recap what we have learned in this lesson.
+
+305
+00:24:27,000 --> 00:24:28,000
+In this lesson.
+
+306
+00:24:28,000 --> 00:24:36,000
+The exception In the spring MVC, we learned different approaches of how exception handling can be done.
+
+307
+00:24:37,000 --> 00:24:44,000
+The learned controller based exception handler also learned how to implement the global exception handler
+
+308
+00:24:44,000 --> 00:24:48,000
+whose controller advise and with handler exception resolver.
+
+309
+00:24:49,000 --> 00:24:57,000
+During the lesson I showed you how to create our custom exception and associate it with a specific response
+
+310
+00:24:57,000 --> 00:24:58,000
+status code.
+
+311
+00:24:58,000 --> 00:25:05,000
+And the reason we learn such annotation as response status and how to use it on practice.
+
+312
+00:25:06,000 --> 00:25:12,000
+And I showed you how to handle four or four not found exceptions in the spring MVC.
+
+313
+00:25:13,000 --> 00:25:14,000
+That's it.
+
+314
+00:25:14,000 --> 00:25:16,000
+That's all for this lesson.
+
+315
+00:25:16,000 --> 00:25:18,000
+Thanks a lot for your attention.
+
+316
+00:25:18,000 --> 00:25:22,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/004 Source-code-examples-from-the-lesson.url b/82 - Spring MVC & Spring for WEB/004 Source-code-examples-from-the-lesson.url
new file mode 100644
index 0000000000000000000000000000000000000000..353ec429c20085211b27fb8ada7247fbd638fb28
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/004 Source-code-examples-from-the-lesson.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/tree/master/src/main/java/com/itbulls/learnit/spring/errors
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/005 Serving Static Resources in Spring MVC_en.srt b/82 - Spring MVC & Spring for WEB/005 Serving Static Resources in Spring MVC_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..bf6bb522720bcdfdd4866e258370fa5f0fcf9b9a
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/005 Serving Static Resources in Spring MVC_en.srt
@@ -0,0 +1,696 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:13,000
+We already learned how to map our controllers with URLs and how to configure view resolvers to map our
+
+3
+00:00:13,000 --> 00:00:16,000
+presentation files out of use.
+
+4
+00:00:16,000 --> 00:00:24,000
+But we didn't discuss yet how to configure mapping for our static resources because without this configuration,
+
+5
+00:00:24,000 --> 00:00:32,000
+Sprint won't be able to map your CSS and JavaScript files, for example, and all requests to these
+
+6
+00:00:32,000 --> 00:00:37,000
+resources will simply return for or for status code not found.
+
+7
+00:00:38,000 --> 00:00:44,000
+So in this video lesson, we're going to review different approaches for configuration of mapping for
+
+8
+00:00:44,000 --> 00:00:51,000
+our static resources, both in the XML and with the Java based configuration.
+
+9
+00:00:52,000 --> 00:00:58,000
+We're going to start our lesson from learning XML based configuration to serve static resources.
+
+10
+00:00:59,000 --> 00:01:01,000
+After that, we'll review Java based configuration.
+
+11
+00:01:01,000 --> 00:01:07,000
+We'll learn what the Resource Handler Registry is and how to use it on real examples.
+
+12
+00:01:07,000 --> 00:01:12,000
+I'm going to show you how to serve static resources from the same VAR file.
+
+13
+00:01:13,000 --> 00:01:19,000
+We'll learn how to serve static resources from the file system and how to serve resources from multiple
+
+14
+00:01:19,000 --> 00:01:20,000
+locations.
+
+15
+00:01:20,000 --> 00:01:28,000
+We'll learn new resource resolvers, namely POS, resource resolver and encode resource resolver.
+
+16
+00:01:28,000 --> 00:01:31,000
+I will show you how we can change resource resolvers.
+
+17
+00:01:31,000 --> 00:01:37,000
+And at the end of the lesson, we're going to learn an important spring security configuration to enable
+
+18
+00:01:37,000 --> 00:01:40,000
+in order to serve static resources.
+
+19
+00:01:40,000 --> 00:01:45,000
+Let's start our lesson and help you understand this topic better.
+
+20
+00:01:45,000 --> 00:01:49,000
+Let me start screen sharing and let me show you examples.
+
+21
+00:01:49,000 --> 00:01:54,000
+You will understand the challenge that we have and solution.
+
+22
+00:01:54,000 --> 00:01:58,000
+We're going to start from the challenge that we need to solve.
+
+23
+00:01:58,000 --> 00:02:01,000
+Here you can see test JSP page.
+
+24
+00:02:01,000 --> 00:02:08,000
+I also configured controller in order to forwards request to this view according to MVC pattern.
+
+25
+00:02:08,000 --> 00:02:11,000
+Everything what we have learned already in the previous lessons.
+
+26
+00:02:11,000 --> 00:02:18,000
+What's important to note is that I tried to enable some synthesis file on this page from CSS folder
+
+27
+00:02:18,000 --> 00:02:27,000
+in my web app source folder, and also I want to enable GS file on this page from GS folder.
+
+28
+00:02:27,000 --> 00:02:31,000
+This is supposed to color our text in red.
+
+29
+00:02:31,000 --> 00:02:39,000
+According to the class CSS selector and in the GS file, I place the code for the click event handler
+
+30
+00:02:39,000 --> 00:02:43,000
+for our button just to show alert message.
+
+31
+00:02:43,000 --> 00:02:45,000
+This is not critically important.
+
+32
+00:02:45,000 --> 00:02:47,000
+It is just a simple example.
+
+33
+00:02:48,000 --> 00:02:53,000
+Pay attention that I used core JSTOR Library here to specify URL.
+
+34
+00:02:53,000 --> 00:02:58,000
+Why I did this in order to stay context agnostic.
+
+35
+00:02:59,000 --> 00:03:04,000
+In this case, you can specify relative paths to your source folder.
+
+36
+00:03:04,000 --> 00:03:06,000
+In our case, to the web app.
+
+37
+00:03:06,000 --> 00:03:11,000
+In case I would specify this path directly in the HTML tag.
+
+38
+00:03:11,000 --> 00:03:14,000
+In this case, context would be taken into account.
+
+39
+00:03:14,000 --> 00:03:20,000
+And in case I am not in the root of my application, then the path would be wrong.
+
+40
+00:03:21,000 --> 00:03:23,000
+Just be attentive with this post.
+
+41
+00:03:23,000 --> 00:03:27,000
+You can check different options, but this is the right way to go.
+
+42
+00:03:27,000 --> 00:03:30,000
+You can just believe me or check by yourself.
+
+43
+00:03:31,000 --> 00:03:37,000
+The right way is always checking because in this way you will be able to understand how everything works
+
+44
+00:03:37,000 --> 00:03:38,000
+under the hood.
+
+45
+00:03:38,000 --> 00:03:44,000
+Let me open the browser and show you the problem that we have right now.
+
+46
+00:03:45,000 --> 00:03:50,000
+I send a request to my controller that is mapped to the test surf static.
+
+47
+00:03:50,000 --> 00:03:55,000
+I also opened dev tools in the network tab.
+
+48
+00:03:55,000 --> 00:04:01,000
+I see that resources are not loaded and we can see four or four error code resource not found.
+
+49
+00:04:02,000 --> 00:04:10,000
+Basically, Sprint can't resolve mapping to these resources and you see it shows resource can be found.
+
+50
+00:04:10,000 --> 00:04:16,000
+Obviously styles are not applied with the styles in this source file.
+
+51
+00:04:16,000 --> 00:04:26,000
+We wanted to set up the color for the text to read and also the script also doesn't work in the script
+
+52
+00:04:26,000 --> 00:04:29,000
+I put on click event handler for the bottom.
+
+53
+00:04:30,000 --> 00:04:34,000
+We can check this simply by clicking on the sources.
+
+54
+00:04:34,000 --> 00:04:37,000
+So as you can see, Mrs. C.
+
+55
+00:04:37,000 --> 00:04:39,000
+S file or G.
+
+56
+00:04:39,000 --> 00:04:42,000
+S file is accessible, resource is not found.
+
+57
+00:04:43,000 --> 00:04:45,000
+But why this happens?
+
+58
+00:04:45,000 --> 00:04:51,000
+This is because we use spring and we see and we configure it viewers over to resolve our views.
+
+59
+00:04:51,000 --> 00:04:55,000
+But we did nothing to configure resolving of our sources.
+
+60
+00:04:56,000 --> 00:04:59,000
+First of all, this is done for security reasons.
+
+61
+00:04:59,000 --> 00:05:04,000
+In order nobody could access the resources we didn't allow to access.
+
+62
+00:05:05,000 --> 00:05:10,000
+So now let me show you how we're going to configure access to the static resources.
+
+63
+00:05:11,000 --> 00:05:14,000
+As always, there are multiple ways of how we can do this.
+
+64
+00:05:14,000 --> 00:05:20,000
+We can configure serving of static resources in XML or with Java based configuration.
+
+65
+00:05:21,000 --> 00:05:28,000
+Let me start from the XML based configuration in case we use XML based configuration in our web config
+
+66
+00:05:28,000 --> 00:05:33,000
+file, we just to specify MVC resources.
+
+67
+00:05:33,000 --> 00:05:41,000
+You can see here the mapping it is for URL mapping and location Specifies the real folders in your web
+
+68
+00:05:41,000 --> 00:05:45,000
+app source folder where the resources allocated.
+
+69
+00:05:46,000 --> 00:05:54,000
+In this case, this means that every time request will be sent to any resource starting from the CSS,
+
+70
+00:05:54,000 --> 00:05:59,000
+the resource will be searched in this folder in the web app.
+
+71
+00:06:00,000 --> 00:06:01,000
+Is that clear?
+
+72
+00:06:02,000 --> 00:06:06,000
+In the similar way we did with the JavaScript resources.
+
+73
+00:06:06,000 --> 00:06:11,000
+Now let's restart the server and get back to the web browser.
+
+74
+00:06:17,000 --> 00:06:25,000
+And in case I reload the page, I can see that all resources are load styles are applied to the text.
+
+75
+00:06:25,000 --> 00:06:30,000
+We have read text now and JavaScript handles the click event on the bottom.
+
+76
+00:06:30,000 --> 00:06:33,000
+Everything works as expected.
+
+77
+00:06:33,000 --> 00:06:34,000
+Amazing.
+
+78
+00:06:35,000 --> 00:06:42,000
+Now let me show you how we can do the similar configuration, but with Java based configuration.
+
+79
+00:06:43,000 --> 00:06:44,000
+Starting from the spring.
+
+80
+00:06:44,000 --> 00:06:53,000
+3.10 is the Resource Handler Registry to configure resource HTTP request handlers for serving static
+
+81
+00:06:53,000 --> 00:06:57,000
+resources from the class pass bar or as a file system.
+
+82
+00:06:57,000 --> 00:07:04,000
+We can configure the resource Handler registry programmatically inside our web context Configuration
+
+83
+00:07:04,000 --> 00:07:05,000
+class.
+
+84
+00:07:05,000 --> 00:07:13,000
+So object of resource handler registry type stores, registrations of resource handlers for serving
+
+85
+00:07:13,000 --> 00:07:22,000
+static resources such as images, CSS files and orders through spring MVC, including setting cache
+
+86
+00:07:22,000 --> 00:07:26,000
+headers optimized for efficient loading in a web browser.
+
+87
+00:07:27,000 --> 00:07:34,000
+Resources can be served out of locations on the web application route from the Class Pass and others.
+
+88
+00:07:35,000 --> 00:07:38,000
+Let me open now the web config file.
+
+89
+00:07:38,000 --> 00:07:43,000
+Pay attention to the overridden method here with name add resource handlers.
+
+90
+00:07:44,000 --> 00:07:47,000
+It takes resource handler registry as method parameter.
+
+91
+00:07:47,000 --> 00:07:55,000
+It is injected here and basically I would use this registry to register resource handler and resource
+
+92
+00:07:55,000 --> 00:07:56,000
+locations.
+
+93
+00:07:56,000 --> 00:08:03,000
+Pay attention that with this Java base configuration, I can list resource mapping and resource locations
+
+94
+00:08:03,000 --> 00:08:04,000
+with the comma.
+
+95
+00:08:04,000 --> 00:08:06,000
+Basically, that's it.
+
+96
+00:08:07,000 --> 00:08:13,000
+Let me restart the server and let's check that everything works as expected on our page.
+
+97
+00:08:14,000 --> 00:08:22,000
+I open the web browser, I reload the page and you can see that everything works as expected and all
+
+98
+00:08:22,000 --> 00:08:23,000
+resources were successfully loaded.
+
+99
+00:08:24,000 --> 00:08:26,000
+I will keep both solutions in the source code.
+
+100
+00:08:26,000 --> 00:08:29,000
+I will keep commanded XML configuration.
+
+101
+00:08:29,000 --> 00:08:36,000
+Don't worry, you will be able also to find the source code in attachments to the video and check the
+
+102
+00:08:36,000 --> 00:08:37,000
+examples.
+
+103
+00:08:37,000 --> 00:08:40,000
+Let's continue right now.
+
+104
+00:08:40,000 --> 00:08:44,000
+We reviewed the most popular and widespread case in my opinion.
+
+105
+00:08:44,000 --> 00:08:49,000
+It is when resources are packaged in the same VAR file.
+
+106
+00:08:49,000 --> 00:08:54,000
+But let's imagine the case that we need to map resources from the file system.
+
+107
+00:08:55,000 --> 00:08:57,000
+What to do in this case.
+
+108
+00:08:57,000 --> 00:08:59,000
+Here you can see command lines.
+
+109
+00:09:00,000 --> 00:09:08,000
+Basically, you still specify your own mapping for resources, and after that, when you specify location,
+
+110
+00:09:08,000 --> 00:09:14,000
+you specify file system protocol and specific POS in your file system.
+
+111
+00:09:14,000 --> 00:09:20,000
+In this particular case, images zero mapping will be mapped with the images folder in the disk.
+
+112
+00:09:20,000 --> 00:09:26,000
+See from my file system it is pretty intuitive, don't you think so?
+
+113
+00:09:27,000 --> 00:09:33,000
+Another example which is commanded here is a case when you want to look up for a source in multiple
+
+114
+00:09:33,000 --> 00:09:40,000
+locations, the list of locations will be searched in order until the resource is found.
+
+115
+00:09:40,000 --> 00:09:47,000
+So in this particular example, in case you would request some resource mapped with the resource URL
+
+116
+00:09:47,000 --> 00:09:50,000
+like it is shown here is a request.
+
+117
+00:09:50,000 --> 00:09:57,000
+A resource will be searched in either the applications web app resources or the other resources folder
+
+118
+00:09:57,000 --> 00:09:58,000
+in the class pass.
+
+119
+00:09:59,000 --> 00:10:03,000
+Starting from spring 4.10 New resource resolvers.
+
+120
+00:10:04,000 --> 00:10:10,000
+Different types of resource resolvers that can be used to optimize browser performance when loading
+
+121
+00:10:10,000 --> 00:10:11,000
+static resources.
+
+122
+00:10:11,000 --> 00:10:17,000
+These resolvers can be chained and cached in the browser to optimize request handling.
+
+123
+00:10:18,000 --> 00:10:21,000
+Let me make a brief overview of these resolvers.
+
+124
+00:10:22,000 --> 00:10:25,000
+Let's start from the review of past resource resolver.
+
+125
+00:10:26,000 --> 00:10:32,000
+This is the simplest resolver and its purpose is to find the resource given the public URL port.
+
+126
+00:10:33,000 --> 00:10:35,000
+Let's look at the example on the slide.
+
+127
+00:10:36,000 --> 00:10:40,000
+I would like to draw your attention to a few things here.
+
+128
+00:10:40,000 --> 00:10:48,000
+We are registering the past resource resolver in the resource chain as the sole resource resolver in
+
+129
+00:10:48,000 --> 00:10:48,000
+it.
+
+130
+00:10:49,000 --> 00:10:55,000
+The resources served will be cached in the browser for 3600 seconds.
+
+131
+00:10:56,000 --> 00:11:00,000
+You can see that value is set in set cache period.
+
+132
+00:11:01,000 --> 00:11:07,000
+The chain is finally configured with the method resource chain set to true.
+
+133
+00:11:07,000 --> 00:11:08,000
+Is this clear?
+
+134
+00:11:09,000 --> 00:11:11,000
+Anyway, in case you have any questions.
+
+135
+00:11:11,000 --> 00:11:17,000
+You are always welcome to ask your questions below the video and I will be happy to answer.
+
+136
+00:11:18,000 --> 00:11:24,000
+Now let's discuss in code resource resolver what is key features.
+
+137
+00:11:24,000 --> 00:11:31,000
+This resolver attempts to find an encoded resource based on the accept encoding request header value.
+
+138
+00:11:31,000 --> 00:11:39,000
+For example, we may need to optimize bandwidth by serving the compressed version of static resource
+
+139
+00:11:39,000 --> 00:11:42,000
+using JS Content coding.
+
+140
+00:11:42,000 --> 00:11:44,000
+Explore example on this slide.
+
+141
+00:11:45,000 --> 00:11:46,000
+On the bottom of the slide.
+
+142
+00:11:46,000 --> 00:11:49,000
+You can also find cool request.
+
+143
+00:11:49,000 --> 00:11:57,000
+You can see that they specify a request header, accept encoding to GZIP and send request to extract
+
+144
+00:11:57,000 --> 00:12:02,000
+zip version of the example html located in the file system.
+
+145
+00:12:03,000 --> 00:12:09,000
+And now the important thing to learn is that you can change resource resolvers one after another to
+
+146
+00:12:09,000 --> 00:12:12,000
+optimize resource lookup.
+
+147
+00:12:12,000 --> 00:12:17,000
+Resource resolvers can delegate the handling of resources to other resolvers.
+
+148
+00:12:17,000 --> 00:12:25,000
+The only resolver that can't delegate to the chain is the POS resource resolver, which we should add
+
+149
+00:12:25,000 --> 00:12:27,000
+at the end of the chain.
+
+150
+00:12:27,000 --> 00:12:31,000
+In case we don't pass through to the resource chain method.
+
+151
+00:12:31,000 --> 00:12:38,000
+Then by default only POS resource resolver will be used to serve resources.
+
+152
+00:12:39,000 --> 00:12:45,000
+In the example on the slide, you can see change the password source resolver to resolve the resource.
+
+153
+00:12:45,000 --> 00:12:49,000
+If the GZIP resource resolver is unsuccessful.
+
+154
+00:12:50,000 --> 00:12:52,000
+The important thing to mention here.
+
+155
+00:12:52,000 --> 00:13:00,000
+Be aware that starting from Spring Framework 5.1, the GC process resolver has been deprecated in favor
+
+156
+00:13:00,000 --> 00:13:02,000
+of the encoded resource resolver.
+
+157
+00:13:02,000 --> 00:13:06,000
+Therefore, we should avoid using it in the future.
+
+158
+00:13:07,000 --> 00:13:09,000
+One more important thing.
+
+159
+00:13:09,000 --> 00:13:16,000
+In this course, we're going to learn spring security to ensure spring security sets additional checks
+
+160
+00:13:16,000 --> 00:13:23,000
+to control who is allowed to assess which resources based on the roles they have in the system.
+
+161
+00:13:24,000 --> 00:13:27,000
+Even despite spring, security is a separate topic.
+
+162
+00:13:27,000 --> 00:13:32,000
+I am sure that it is important to flag important thing in this lesson.
+
+163
+00:13:32,000 --> 00:13:37,000
+In case we use spring security in our project, we need to allow access to static resources.
+
+164
+00:13:38,000 --> 00:13:44,000
+This can easily be done by setting access to permit all like you see in the example on the slide.
+
+165
+00:13:45,000 --> 00:13:48,000
+That's all what I wanted to share with you in this lesson.
+
+166
+00:13:49,000 --> 00:13:51,000
+Let's recap what we have learned today.
+
+167
+00:13:52,000 --> 00:13:59,000
+In this lesson, we learn how to serve static resources in spring and we see we learned XML and Java
+
+168
+00:13:59,000 --> 00:14:02,000
+based configuration to serve static resources.
+
+169
+00:14:02,000 --> 00:14:11,000
+Also, I explained how to serve resources from the VAR file, from file system and from multiple locations.
+
+170
+00:14:11,000 --> 00:14:18,000
+We learned new resource resolvers, including POS, resource resolver and an audit resource resolver
+
+171
+00:14:18,000 --> 00:14:23,000
+and reviewed spring security configuration to ensure a serving of static resources.
+
+172
+00:14:24,000 --> 00:14:25,000
+That's all for today.
+
+173
+00:14:26,000 --> 00:14:27,000
+Thanks a lot for your attention.
+
+174
+00:14:27,000 --> 00:14:31,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/005 Source-code-of-examples-commit-with-changes-.url b/82 - Spring MVC & Spring for WEB/005 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..42379f02d765f80974c3564a46eb015c4e8bdf50
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/005 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/efe19f3a7ff0774008b1d2db3cb30675686fb083
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/006 Source-code-of-examples-commit-with-changes-.url b/82 - Spring MVC & Spring for WEB/006 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..11fa9873a89c52ecf3d3aa17acb7957e558ca915
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/006 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/55e4399d80aafe4f4db45a719f111ac61bb3cf19
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/006 WebFilters & HandlerInterceptor in Spring MVC_en.srt b/82 - Spring MVC & Spring for WEB/006 WebFilters & HandlerInterceptor in Spring MVC_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..e41df63c877e6b7185e4af0e42f9f7835fd1a28c
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/006 WebFilters & HandlerInterceptor in Spring MVC_en.srt
@@ -0,0 +1,880 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:09,000
+Today we're going to have important and really interesting lesson.
+
+3
+00:00:09,000 --> 00:00:14,000
+We're going to learn with you how to work with filters and interceptors in spring.
+
+4
+00:00:14,000 --> 00:00:21,000
+And we see we're going to start our lesson from remembering of what Web filters are.
+
+5
+00:00:21,000 --> 00:00:25,000
+We already learned Web filters in my Java from zero to first job course.
+
+6
+00:00:25,000 --> 00:00:32,000
+But still, it is important for us to remember that filters in order to help you understand the concept
+
+7
+00:00:32,000 --> 00:00:36,000
+of handler interceptor by making the parallels.
+
+8
+00:00:36,000 --> 00:00:44,000
+After that, we will be ready to discuss and understand what handler interceptor in spring MVC is will
+
+9
+00:00:44,000 --> 00:00:46,000
+review goals of interceptors.
+
+10
+00:00:46,000 --> 00:00:51,000
+I'm going to explain to you the difference between handler, interceptor and Web filters.
+
+11
+00:00:52,000 --> 00:00:58,000
+As usual, I prepared for you practical examples, and we are going to review code in examples today
+
+12
+00:00:58,000 --> 00:01:06,000
+and at the end of the lesson will make conclusions to understand when to use what, namely when to use
+
+13
+00:01:06,000 --> 00:01:08,000
+filters and handler interceptors.
+
+14
+00:01:09,000 --> 00:01:11,000
+Let's start our lesson.
+
+15
+00:01:11,000 --> 00:01:15,000
+Let's start from understanding of what web filter is.
+
+16
+00:01:15,000 --> 00:01:22,000
+If you watched my course Java from zero to first job, then you remember lessons about Web filters.
+
+17
+00:01:22,000 --> 00:01:27,000
+Because Web filters is it is something what exists in Java Enterprise edition stack.
+
+18
+00:01:27,000 --> 00:01:31,000
+We use often Web filters and applications even without spring.
+
+19
+00:01:31,000 --> 00:01:35,000
+And we see the idea of Web filters is simple.
+
+20
+00:01:35,000 --> 00:01:43,000
+You have get to validate the request, modify it if needed, or even prevent request going further to
+
+21
+00:01:43,000 --> 00:01:44,000
+your source.
+
+22
+00:01:44,000 --> 00:01:52,000
+And also filter may be used to modify your response back to the client and you can put any logic in
+
+23
+00:01:52,000 --> 00:01:54,000
+place to make your filter work.
+
+24
+00:01:54,000 --> 00:02:01,000
+For example, this can be authorization tasks in order to check access rights of the client who sends
+
+25
+00:02:01,000 --> 00:02:04,000
+requests to access the resource.
+
+26
+00:02:04,000 --> 00:02:11,000
+It can be some work with headers, configuring of caching headers over refine existing headers in order
+
+27
+00:02:11,000 --> 00:02:19,000
+to allow access to the resource or block this access and many other cases when web filters come in handy.
+
+28
+00:02:19,000 --> 00:02:25,000
+Moreover, you can build chain of filters that will process your request one after another.
+
+29
+00:02:26,000 --> 00:02:29,000
+Filters are used in the Spring Security project.
+
+30
+00:02:29,000 --> 00:02:35,000
+We are going to run spring security separately, but I can already tell you that the web filter concept
+
+31
+00:02:35,000 --> 00:02:39,000
+is used in the spring security for authentication and authorization.
+
+32
+00:02:39,000 --> 00:02:42,000
+We'll review this in details in a separate lesson.
+
+33
+00:02:43,000 --> 00:02:47,000
+Now let's learn what handler interceptor in spring MVC is.
+
+34
+00:02:48,000 --> 00:02:53,000
+To understand how interceptor works in spring, we need to understand first handler mapping.
+
+35
+00:02:54,000 --> 00:03:00,000
+The main goal of handler mapping is to map specific method in our code with a URL.
+
+36
+00:03:00,000 --> 00:03:03,000
+Do you remember how we did request mapping?
+
+37
+00:03:03,000 --> 00:03:11,000
+We mapped specific method with the URL and in this case DISPATCHER Servlet will be able to identify
+
+38
+00:03:11,000 --> 00:03:18,000
+mapped method and will invoke it when there will be need to process the request.
+
+39
+00:03:18,000 --> 00:03:19,000
+In turn.
+
+40
+00:03:19,000 --> 00:03:24,000
+DISPATCHER Servlet uses the handler adapter to invoke the method.
+
+41
+00:03:24,000 --> 00:03:31,000
+Why I explained you all this in order you to understand how handler interceptor works.
+
+42
+00:03:31,000 --> 00:03:39,000
+So basically there is room between the request access and dispatcher servlet and actual method invocation.
+
+43
+00:03:39,000 --> 00:03:40,000
+Correct.
+
+44
+00:03:41,000 --> 00:03:48,000
+The concept of interceptors is to intercept the request between the dispatcher servlet and actual mapped
+
+45
+00:03:48,000 --> 00:03:49,000
+method invocation.
+
+46
+00:03:50,000 --> 00:03:56,000
+So we understood what handler interceptors are, but why do we need them at all?
+
+47
+00:03:56,000 --> 00:04:01,000
+The main goal of interceptors is to reduce the amount of repetitive code.
+
+48
+00:04:01,000 --> 00:04:08,000
+Another goal is to make sure that we have possibility to inject some logic pre-processing of the request
+
+49
+00:04:08,000 --> 00:04:11,000
+before it hits the source.
+
+50
+00:04:11,000 --> 00:04:14,000
+But that is something what filters do, right?
+
+51
+00:04:14,000 --> 00:04:19,000
+We can configure login and filters and in handler interceptors, correct?
+
+52
+00:04:19,000 --> 00:04:21,000
+That is correct.
+
+53
+00:04:21,000 --> 00:04:23,000
+But they work in different ways.
+
+54
+00:04:23,000 --> 00:04:27,000
+Let's understand better what the difference is.
+
+55
+00:04:27,000 --> 00:04:31,000
+Usually my students are confused at this point at some degree.
+
+56
+00:04:31,000 --> 00:04:34,000
+They are confused mainly with the question.
+
+57
+00:04:34,000 --> 00:04:39,000
+So what is the difference between web filters and handler interceptors in spring?
+
+58
+00:04:40,000 --> 00:04:43,000
+If you have the same question, we are going to answer it now.
+
+59
+00:04:44,000 --> 00:04:46,000
+Take a look at the slide.
+
+60
+00:04:46,000 --> 00:04:53,000
+The first difference is the moment when logic that is described in filter and handler interceptor will
+
+61
+00:04:53,000 --> 00:04:54,000
+be applied.
+
+62
+00:04:54,000 --> 00:05:00,000
+As you can see on the slide, filters are applied before the request hit the dispatcher Servlet.
+
+63
+00:05:01,000 --> 00:05:07,000
+Handler interceptors work when the request is forwarded from the dispatcher servlet to the controller.
+
+64
+00:05:07,000 --> 00:05:09,000
+Do you see the difference?
+
+65
+00:05:10,000 --> 00:05:16,000
+Another difference is that filter and handler interceptor have access to the different objects.
+
+66
+00:05:16,000 --> 00:05:23,000
+For example, the filter method accepts servlet request, servlet response and filter chain, which
+
+67
+00:05:23,000 --> 00:05:27,000
+is great, and you can build your logic around these arguments.
+
+68
+00:05:27,000 --> 00:05:35,000
+That is also fine, but everything depends on the goals that you want to achieve because in the interceptors
+
+69
+00:05:35,000 --> 00:05:42,000
+in the post handle method, for example, you have access to the request response handler, object and
+
+70
+00:05:42,000 --> 00:05:43,000
+model and view object.
+
+71
+00:05:43,000 --> 00:05:46,000
+With this set of arguments, you can achieve different things.
+
+72
+00:05:47,000 --> 00:05:50,000
+After today's lesson, you are going to learn when to use what.
+
+73
+00:05:50,000 --> 00:05:56,000
+But before answering this question and be ready to make the right choice, let's have a quick demo.
+
+74
+00:05:57,000 --> 00:06:02,000
+So let's have a demo now and understand how we can use web filters and handler interceptors.
+
+75
+00:06:03,000 --> 00:06:05,000
+As always, I prepared for this lesson.
+
+76
+00:06:05,000 --> 00:06:11,000
+Special examples and you will be able to find the reference to the source code in attachments to the
+
+77
+00:06:11,000 --> 00:06:11,000
+video.
+
+78
+00:06:12,000 --> 00:06:15,000
+Let me start with the demo of the web filters.
+
+79
+00:06:15,000 --> 00:06:22,000
+I know that we already learned Web filters in previous lessons, but to stay consistent, let me quickly
+
+80
+00:06:22,000 --> 00:06:24,000
+share with you Web filter example.
+
+81
+00:06:25,000 --> 00:06:29,000
+Still, I believe this will be useful for you to refresh your knowledge.
+
+82
+00:06:29,000 --> 00:06:32,000
+So in the filters package, you can see.
+
+83
+00:06:32,000 --> 00:06:34,000
+Demo filter class.
+
+84
+00:06:34,000 --> 00:06:35,000
+Let me open it.
+
+85
+00:06:35,000 --> 00:06:41,000
+You can declare web filters either in the web XML or with the annotation web filter.
+
+86
+00:06:41,000 --> 00:06:47,000
+You don't need to add any other annotations like, for example, component in order to make screen to
+
+87
+00:06:47,000 --> 00:06:48,000
+detect it.
+
+88
+00:06:48,000 --> 00:06:53,000
+No need in case class is annotated with web filter annotation.
+
+89
+00:06:53,000 --> 00:06:57,000
+The instance of the web filter will be created and will be instantiated.
+
+90
+00:06:58,000 --> 00:07:03,000
+You can see that we specified mapping next to the web filter annotation.
+
+91
+00:07:03,000 --> 00:07:09,000
+This is pardon for your requests that should be processed by this web filter.
+
+92
+00:07:09,000 --> 00:07:13,000
+When we create web filter, we need to implement filter interface.
+
+93
+00:07:13,000 --> 00:07:19,000
+Namely, we need to implement three methods that describe web filter lifecycle.
+
+94
+00:07:19,000 --> 00:07:25,000
+They are init method that is invoked when the instance of the filter is instantiated.
+
+95
+00:07:25,000 --> 00:07:29,000
+It is called just once during the lifecycle of the filter.
+
+96
+00:07:29,000 --> 00:07:35,000
+As you can see, we have the reference to the filter config object inside this method.
+
+97
+00:07:36,000 --> 00:07:42,000
+Filter conflict can be used when we need to get the reference to the servlet context object or extract
+
+98
+00:07:42,000 --> 00:07:44,000
+any parameters of the web filter.
+
+99
+00:07:45,000 --> 00:07:46,000
+Do filter methods.
+
+100
+00:07:46,000 --> 00:07:52,000
+It is invoked each time a request is sent to the mapped resources, it takes a request.
+
+101
+00:07:52,000 --> 00:07:58,000
+So let response and filter chain arguments once your logic is executed.
+
+102
+00:07:58,000 --> 00:08:04,000
+We call the filter method on the filter chain object in order to pass the request and response further
+
+103
+00:08:04,000 --> 00:08:11,000
+down the chain and destroy method that is invoked only once during the lifecycle of the servlet.
+
+104
+00:08:11,000 --> 00:08:14,000
+Once the instance of the servlet is destroyed.
+
+105
+00:08:14,000 --> 00:08:16,000
+That's web filter.
+
+106
+00:08:16,000 --> 00:08:20,000
+Let me run the program and we'll explore console output.
+
+107
+00:08:22,000 --> 00:08:24,000
+When the web server is started.
+
+108
+00:08:24,000 --> 00:08:28,000
+Let's navigate to the any resource that will trigger our web filter.
+
+109
+00:08:29,000 --> 00:08:34,000
+If you remember, we configured mapping for all resources, starting with the test.
+
+110
+00:08:34,000 --> 00:08:40,000
+So I will write here test and hello dash world.
+
+111
+00:08:41,000 --> 00:08:42,000
+This is just for example.
+
+112
+00:08:42,000 --> 00:08:44,000
+And just to trigger the web filter.
+
+113
+00:08:45,000 --> 00:08:51,000
+And when I navigate to the Hello world, we see in console that we printed the application filter config
+
+114
+00:08:51,000 --> 00:08:56,000
+from the method and we'll print the text from the filter method.
+
+115
+00:08:56,000 --> 00:09:02,000
+You will see text from the destroy method when filter will be destroyed.
+
+116
+00:09:03,000 --> 00:09:06,000
+Basically that's how to work with the Web filters.
+
+117
+00:09:06,000 --> 00:09:07,000
+Let's continue.
+
+118
+00:09:08,000 --> 00:09:12,000
+Now let's understand how to work with handler interceptors.
+
+119
+00:09:12,000 --> 00:09:17,000
+Let me open Demo handler Interceptor class from the interceptors package.
+
+120
+00:09:17,000 --> 00:09:19,000
+Few more words about interceptors.
+
+121
+00:09:20,000 --> 00:09:26,000
+To make it simple, Spring Interceptor is a class that implements a handler interceptor interface.
+
+122
+00:09:26,000 --> 00:09:29,000
+Let me open the source code of this interface.
+
+123
+00:09:30,000 --> 00:09:34,000
+We have three default masses here that can be overridden when necessary.
+
+124
+00:09:34,000 --> 00:09:37,000
+They are per handle.
+
+125
+00:09:37,000 --> 00:09:43,000
+Following its name, you may guess that this method is invoked before the execution of the handler.
+
+126
+00:09:44,000 --> 00:09:50,000
+From the list of parameters, you can see that http servlet request http servlet response objects will
+
+127
+00:09:50,000 --> 00:09:58,000
+be passed here in each method from this interface there is also reference to the handler object.
+
+128
+00:09:58,000 --> 00:10:04,000
+During the demo you are going to understand what handler object actually is and what its type.
+
+129
+00:10:05,000 --> 00:10:05,000
+Pay attention.
+
+130
+00:10:05,000 --> 00:10:07,000
+That message returns boolean value.
+
+131
+00:10:08,000 --> 00:10:09,000
+True or false?
+
+132
+00:10:10,000 --> 00:10:11,000
+True value tells Spring.
+
+133
+00:10:11,000 --> 00:10:17,000
+To process the request further and false means stop further processing.
+
+134
+00:10:17,000 --> 00:10:22,000
+Post handle this method is called after the handler is executed.
+
+135
+00:10:23,000 --> 00:10:30,000
+That means after method controller has been executed, but before dispatcher server that renders the
+
+136
+00:10:30,000 --> 00:10:36,000
+view in addition to all parameters, you have model and view object available here.
+
+137
+00:10:36,000 --> 00:10:43,000
+That means that before rendering the view, you can still modify or verify your model and view object.
+
+138
+00:10:44,000 --> 00:10:45,000
+After completion.
+
+139
+00:10:45,000 --> 00:10:52,000
+This method is invoked after the complete request is finished and the view is rendered will be called
+
+140
+00:10:52,000 --> 00:10:55,000
+on any outcome of handler execution.
+
+141
+00:10:56,000 --> 00:10:59,000
+Thus allows for proper resource cleanup.
+
+142
+00:11:00,000 --> 00:11:06,000
+By overriding these methods, you can easily achieve the flexibility to do all kinds of required pre
+
+143
+00:11:06,000 --> 00:11:07,000
+and post processing.
+
+144
+00:11:08,000 --> 00:11:13,000
+Let's get back to our demo interceptor and override these three methods.
+
+145
+00:11:13,000 --> 00:11:15,000
+Just for the sake of the demo.
+
+146
+00:11:15,000 --> 00:11:23,000
+We'll override them and we'll just print text to console and also in the handler method will print the
+
+147
+00:11:23,000 --> 00:11:24,000
+handler to console.
+
+148
+00:11:25,000 --> 00:11:31,000
+The last thing that we have to do is to configure our interceptor and make Sprint track it.
+
+149
+00:11:32,000 --> 00:11:33,000
+For this.
+
+150
+00:11:33,000 --> 00:11:43,000
+Let me open web MVC configure the class web config in our example implements web MVC configure, we'll
+
+151
+00:11:43,000 --> 00:11:46,000
+override method that is called add interceptors.
+
+152
+00:11:46,000 --> 00:11:53,000
+We use interceptor registry argument in order to add interceptor that we have created.
+
+153
+00:11:53,000 --> 00:11:57,000
+We pass instance of our interceptor to the add interceptor message.
+
+154
+00:11:58,000 --> 00:12:02,000
+After this, our interceptor will handle all the requests.
+
+155
+00:12:02,000 --> 00:12:08,000
+But in case you want to map your interceptor with a specific resources, we have to map it with the
+
+156
+00:12:08,000 --> 00:12:15,000
+Spartan I call method at Spartans and parses a URL of one specific controller.
+
+157
+00:12:16,000 --> 00:12:21,000
+Most likely in real life, you are going to have some -- that would cover a group of resources.
+
+158
+00:12:22,000 --> 00:12:24,000
+Our web server is up and running.
+
+159
+00:12:24,000 --> 00:12:32,000
+Let me just change the URL in the web browser and let me try to access resource that is called Simple
+
+160
+00:12:32,000 --> 00:12:33,000
+model demo.
+
+161
+00:12:34,000 --> 00:12:40,000
+And in console you can see that our do filter method was invoked first.
+
+162
+00:12:40,000 --> 00:12:47,000
+That is because we reached filter before request reached dispatcher, server and controller itself.
+
+163
+00:12:48,000 --> 00:12:52,000
+After that you can see the console output from our handler interceptor.
+
+164
+00:12:52,000 --> 00:12:54,000
+And pay attention.
+
+165
+00:12:54,000 --> 00:12:55,000
+Here is the answer.
+
+166
+00:12:55,000 --> 00:13:03,000
+What handler object is Handler type is handler method and which method is the method that is mapped
+
+167
+00:13:03,000 --> 00:13:08,000
+with my controller, namely simple model demo method.
+
+168
+00:13:09,000 --> 00:13:15,000
+I believe that now you have clear vision and understanding of what handler interceptor is.
+
+169
+00:13:15,000 --> 00:13:21,000
+And now we need to answer the last question for today, namely when to use what.
+
+170
+00:13:22,000 --> 00:13:24,000
+So you saw the examples.
+
+171
+00:13:24,000 --> 00:13:28,000
+You understand the difference between filters and interceptors.
+
+172
+00:13:28,000 --> 00:13:35,000
+Let's understand now when to use what handler interceptor is basically similar to a servlet filter,
+
+173
+00:13:35,000 --> 00:13:43,000
+but in contrast to the later, it just allows custom preprocessing with the option of prohibiting the
+
+174
+00:13:43,000 --> 00:13:45,000
+execution of the handler itself.
+
+175
+00:13:45,000 --> 00:13:49,000
+And custom post-processing filters are more powerful.
+
+176
+00:13:49,000 --> 00:13:55,000
+For example, they allow for exchanging the request and response objects that are handed down to the
+
+177
+00:13:55,000 --> 00:13:58,000
+chain as a basic guideline.
+
+178
+00:13:58,000 --> 00:14:05,000
+Fine grained handler related preprocessing tasks are candidates for handler interceptor implementations,
+
+179
+00:14:05,000 --> 00:14:10,000
+especially factoring out common handler code and authorization checks.
+
+180
+00:14:11,000 --> 00:14:18,000
+On the other hand, a filter is well suited for request content and view content handling like multipart
+
+181
+00:14:18,000 --> 00:14:20,000
+forms and GZIP compression.
+
+182
+00:14:21,000 --> 00:14:28,000
+This typically shows when one needs to map the filter to certain content types like images or to all
+
+183
+00:14:28,000 --> 00:14:29,000
+requests.
+
+184
+00:14:30,000 --> 00:14:36,000
+A handler interceptor gives you more fine grained control than a filter because you have access to the
+
+185
+00:14:36,000 --> 00:14:39,000
+actual target handler.
+
+186
+00:14:39,000 --> 00:14:46,000
+This means that whatever action you perform can vary depending on what the request is actually doing,
+
+187
+00:14:46,000 --> 00:14:52,000
+whereas the servlet filter is generally applied to all requests, only able to take into account the
+
+188
+00:14:52,000 --> 00:14:54,000
+parameters of each request.
+
+189
+00:14:54,000 --> 00:15:01,000
+The handler Interceptor also provides three different methods so that you can apply behavior prior to
+
+190
+00:15:01,000 --> 00:15:07,000
+calling a handler after the handler has completed, but prior to view rendering where you may even bypass
+
+191
+00:15:07,000 --> 00:15:12,000
+view rendering altogether or after the view itself has been rendered.
+
+192
+00:15:12,000 --> 00:15:17,000
+Also, you can set up different interceptors for different groups of handlers.
+
+193
+00:15:17,000 --> 00:15:24,000
+The interceptors are configured on the handler mapping and there may be multiple handler mappings to
+
+194
+00:15:24,000 --> 00:15:25,000
+understand when to use what.
+
+195
+00:15:25,000 --> 00:15:31,000
+Let's one more time compared to filter method from filter and post handler method from interceptor.
+
+196
+00:15:32,000 --> 00:15:40,000
+Post handler will be called after handler method invocation but before the view being rendered so you
+
+197
+00:15:40,000 --> 00:15:48,000
+can add more model objects to the View, but you cannot change the HTTP servlet response since it's
+
+198
+00:15:48,000 --> 00:15:49,000
+already committed.
+
+199
+00:15:49,000 --> 00:15:53,000
+Do Filter is much more versatile than the post handle.
+
+200
+00:15:54,000 --> 00:16:00,000
+You can change the request or response and pass it to the chain or even block the request processing.
+
+201
+00:16:01,000 --> 00:16:07,000
+Also in pre handle and post handle methods, you have access to the handler method that process the
+
+202
+00:16:07,000 --> 00:16:08,000
+request.
+
+203
+00:16:09,000 --> 00:16:14,000
+So you can add proposed processing logic based on the handler itself.
+
+204
+00:16:14,000 --> 00:16:20,000
+For example, you can add a logic for handler methods that have some annotations.
+
+205
+00:16:21,000 --> 00:16:28,000
+So my final conclusion about when to use what will sound like this if you have a need to do something
+
+206
+00:16:28,000 --> 00:16:34,000
+completely generic, for example, lock all requests, then a filter is sufficient.
+
+207
+00:16:34,000 --> 00:16:41,000
+But if the behavior depends on the target handler or you want to do something between the request handling
+
+208
+00:16:41,000 --> 00:16:46,000
+and view rendering, then the handler interceptor provides that flexibility.
+
+209
+00:16:47,000 --> 00:16:50,000
+That's all what I wanted to discuss with you in this lesson.
+
+210
+00:16:50,000 --> 00:16:52,000
+Let's recap what we have learned today.
+
+211
+00:16:53,000 --> 00:16:56,000
+In this lesson, we remember it one more time.
+
+212
+00:16:56,000 --> 00:16:57,000
+What a web filter is.
+
+213
+00:16:57,000 --> 00:17:00,000
+We learned what handler interceptor in spring.
+
+214
+00:17:00,000 --> 00:17:00,000
+Can we see?
+
+215
+00:17:00,000 --> 00:17:07,000
+As I explained to you, the goals of handler interceptor, we discussed the difference between handler,
+
+216
+00:17:07,000 --> 00:17:09,000
+interceptor and filter.
+
+217
+00:17:09,000 --> 00:17:15,000
+We reviewed real examples and demo of web, filter and interceptor.
+
+218
+00:17:15,000 --> 00:17:19,000
+And at the end of the lesson we learned when to use what.
+
+219
+00:17:19,000 --> 00:17:21,000
+Thanks a lot for your attention.
+
+220
+00:17:21,000 --> 00:17:25,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/007 L10N & I18N in Spring MVC_en.srt b/82 - Spring MVC & Spring for WEB/007 L10N & I18N in Spring MVC_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..57b06741b86edbeb00e9debfc92575f65d8198ad
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/007 L10N & I18N in Spring MVC_en.srt
@@ -0,0 +1,728 @@
+1
+00:00:06,000 --> 00:00:07,000
+Hello, Jim.
+
+2
+00:00:07,000 --> 00:00:11,000
+Today we're going to learn internationalization and localization.
+
+3
+00:00:11,000 --> 00:00:15,000
+We already learned this topic in my course, Java from zero to first job.
+
+4
+00:00:15,000 --> 00:00:20,000
+And I explained you how to work with resource bundles and locales and lots more.
+
+5
+00:00:20,000 --> 00:00:28,000
+But today, we'll focus our attention on the specifics of internationalization and localization in spring
+
+6
+00:00:28,000 --> 00:00:29,000
+MVC.
+
+7
+00:00:30,000 --> 00:00:36,000
+We're going to start our lesson from general overview of what localization and internationalization
+
+8
+00:00:36,000 --> 00:00:36,000
+is.
+
+9
+00:00:37,000 --> 00:00:42,000
+I prepared special coding examples for you that will help you to understand the topic better.
+
+10
+00:00:43,000 --> 00:00:50,000
+So most of the lesson we are going to review coding exercises during the review of code.
+
+11
+00:00:50,000 --> 00:00:57,000
+I'm going to explain you how to configure Sprint and B see including explanation of what message source
+
+12
+00:00:57,000 --> 00:01:05,000
+bin is, what local resolver bin is, and its main implementations like accept header, local resolver,
+
+13
+00:01:05,000 --> 00:01:12,000
+fixed local resolver session, local resolver, cookie local resolver and when to use local context
+
+14
+00:01:12,000 --> 00:01:13,000
+holder class.
+
+15
+00:01:14,000 --> 00:01:16,000
+Let's start our lesson.
+
+16
+00:01:17,000 --> 00:01:24,000
+As I said in the beginning of the lesson, we already learned what localization and internationalization
+
+17
+00:01:24,000 --> 00:01:24,000
+is.
+
+18
+00:01:24,000 --> 00:01:29,000
+That's why I will not stop on the definitions for too long.
+
+19
+00:01:29,000 --> 00:01:31,000
+But let's just quickly recap.
+
+20
+00:01:31,000 --> 00:01:39,000
+In order to stay efficient during the lesson, internationalization is the design and development of
+
+21
+00:01:39,000 --> 00:01:47,000
+a product application or document content that enables easier localization for target audiences that
+
+22
+00:01:47,000 --> 00:01:51,000
+vary in culture, region or language.
+
+23
+00:01:52,000 --> 00:01:59,000
+Localization refers to the adaptation of a product application or document content to meet the language,
+
+24
+00:01:59,000 --> 00:02:05,000
+cultural and other requirements of a specific target market and locale.
+
+25
+00:02:06,000 --> 00:02:14,000
+In other words, internationalization allows applications to support and satisfy the needs of multiple
+
+26
+00:02:14,000 --> 00:02:15,000
+locales.
+
+27
+00:02:15,000 --> 00:02:23,000
+Thus, in enabling localization, the act of adapting your program so that it isn't fixed to a single
+
+28
+00:02:23,000 --> 00:02:28,000
+language or region is known as internationalization.
+
+29
+00:02:28,000 --> 00:02:36,000
+Localization is the process of including the necessary resources in your program to support a specific
+
+30
+00:02:36,000 --> 00:02:38,000
+language or locale.
+
+31
+00:02:38,000 --> 00:02:46,000
+It's beneficial to distinguish between them, since in theory, after your program has undergone the
+
+32
+00:02:46,000 --> 00:02:52,000
+internet zation process, you may iterate as many localization processes as you need.
+
+33
+00:02:53,000 --> 00:02:58,000
+Also, we use localization and internationalization in similar context.
+
+34
+00:02:58,000 --> 00:03:00,000
+They have different meanings.
+
+35
+00:03:00,000 --> 00:03:08,000
+Most of the web application frameworks provide easy ways to localize the application based on user local
+
+36
+00:03:08,000 --> 00:03:09,000
+settings.
+
+37
+00:03:09,000 --> 00:03:16,000
+Spring also follows the pattern and provides extensive support for internationalization through the
+
+38
+00:03:16,000 --> 00:03:23,000
+use of sprint interceptors, local resolvers and resource bundles for different locales.
+
+39
+00:03:24,000 --> 00:03:31,000
+I believe that now we refreshed our knowledge about localization and internationalization and it is
+
+40
+00:03:31,000 --> 00:03:36,000
+time to learn how to configure localization and internationalization in spring MVC.
+
+41
+00:03:37,000 --> 00:03:44,000
+In our today's demo, we're going to create web pages, declare required beans, interceptors, create
+
+42
+00:03:44,000 --> 00:03:50,000
+resource bundles, and configure everything we need in order to support localization.
+
+43
+00:03:51,000 --> 00:03:55,000
+The first thing that we need to do is to define our source bundle.
+
+44
+00:03:55,000 --> 00:03:58,000
+This is something where we start.
+
+45
+00:03:58,000 --> 00:04:05,000
+We need to have localized resources for language and country that we plan to support in our application.
+
+46
+00:04:06,000 --> 00:04:13,000
+For the sake of example, let's imagine that our application supports work with English and French languages
+
+47
+00:04:13,000 --> 00:04:15,000
+in the CRC.
+
+48
+00:04:15,000 --> 00:04:16,000
+Main Resources.
+
+49
+00:04:16,000 --> 00:04:19,000
+I create two files with properties extension.
+
+50
+00:04:19,000 --> 00:04:21,000
+You can see them here.
+
+51
+00:04:21,000 --> 00:04:26,000
+Their name message underscore and and message underscore four.
+
+52
+00:04:26,000 --> 00:04:28,000
+Let me open these files.
+
+53
+00:04:29,000 --> 00:04:30,000
+Nothing special is here.
+
+54
+00:04:31,000 --> 00:04:35,000
+Just some random text and labels for buttons to change language.
+
+55
+00:04:36,000 --> 00:04:39,000
+Now let's create a simple controller.
+
+56
+00:04:39,000 --> 00:04:44,000
+I already prepared all examples in order to save your time during the lesson.
+
+57
+00:04:44,000 --> 00:04:48,000
+The controller is called Localization Controller Demo.
+
+58
+00:04:49,000 --> 00:04:50,000
+Let me open it.
+
+59
+00:04:50,000 --> 00:04:54,000
+It is mapped to the test URL as usual.
+
+60
+00:04:54,000 --> 00:04:59,000
+And here we have simple method that is mapped with the land demo URL.
+
+61
+00:04:59,000 --> 00:05:02,000
+It just returns the name of the view to be resolved.
+
+62
+00:05:03,000 --> 00:05:07,000
+All of the things we are going to review later during the demo.
+
+63
+00:05:07,000 --> 00:05:11,000
+Let's now explore the view in the webinar view.
+
+64
+00:05:11,000 --> 00:05:15,000
+We have a JSP page that is called LAN Demo, JSP.
+
+65
+00:05:16,000 --> 00:05:17,000
+I open it.
+
+66
+00:05:17,000 --> 00:05:23,000
+It is relatively simple, but still it is enough to show you how language switcher works.
+
+67
+00:05:24,000 --> 00:05:26,000
+Pay attention on the top of the file.
+
+68
+00:05:27,000 --> 00:05:30,000
+I added tags from the spring MVC library.
+
+69
+00:05:30,000 --> 00:05:34,000
+In case you have sprinkled the C jar in your class pass.
+
+70
+00:05:34,000 --> 00:05:36,000
+You have nothing to worry about.
+
+71
+00:05:36,000 --> 00:05:40,000
+You have all required tags in your class pass.
+
+72
+00:05:40,000 --> 00:05:43,000
+We're going to print random text first.
+
+73
+00:05:44,000 --> 00:05:46,000
+Look at the syntax in the row.
+
+74
+00:05:46,000 --> 00:05:52,000
+I use message tag from the spring tag library and pass just the code of the message.
+
+75
+00:05:53,000 --> 00:05:53,000
+That's it.
+
+76
+00:05:54,000 --> 00:05:59,000
+You don't need to manage bundles on the page or manually change them.
+
+77
+00:05:59,000 --> 00:06:04,000
+Spring will resolves the message based on the actual locale.
+
+78
+00:06:04,000 --> 00:06:06,000
+But how we can change locale.
+
+79
+00:06:06,000 --> 00:06:10,000
+There are different ways of how you can change local in spring.
+
+80
+00:06:10,000 --> 00:06:16,000
+But probably the most popular option is to change local with the help of the request parameter.
+
+81
+00:06:16,000 --> 00:06:18,000
+Here you can see two buttons.
+
+82
+00:06:18,000 --> 00:06:26,000
+One sends a request with the length and parameter, and another sends request with a four length parameter.
+
+83
+00:06:27,000 --> 00:06:30,000
+Now it is time to look at the configuration.
+
+84
+00:06:30,000 --> 00:06:32,000
+Let me open the config class.
+
+85
+00:06:32,000 --> 00:06:35,000
+We are going to declare a few important beans here.
+
+86
+00:06:35,000 --> 00:06:38,000
+We need to declare message source Bean.
+
+87
+00:06:38,000 --> 00:06:44,000
+You can inject this bean later in your classes and resolve messages with its help.
+
+88
+00:06:44,000 --> 00:06:47,000
+I'm going to show you how to do this later today.
+
+89
+00:06:48,000 --> 00:06:53,000
+You can see here that we need to set up the base name of our source models.
+
+90
+00:06:53,000 --> 00:06:56,000
+In our case, this is MSG.
+
+91
+00:06:56,000 --> 00:07:02,000
+I also set default and code in UTF eight to be able to read different characters.
+
+92
+00:07:02,000 --> 00:07:09,000
+I use resource bundle message source as implementation of message Source Interface Message Source has
+
+93
+00:07:09,000 --> 00:07:11,000
+huge Iraqi.
+
+94
+00:07:11,000 --> 00:07:18,000
+When I open the source code of message source interface and want to explore the Iraqi, you can see
+
+95
+00:07:18,000 --> 00:07:24,000
+the different interfaces X stands this type feel free to export the Iraqi.
+
+96
+00:07:24,000 --> 00:07:28,000
+I would keep your focus on the most popular implementations.
+
+97
+00:07:28,000 --> 00:07:35,000
+It is used in most cases because otherwise we would need a lot of hours just to reduce this Iraqi,
+
+98
+00:07:36,000 --> 00:07:42,000
+because sometimes the interface extended by the interfaces and they have different implementations.
+
+99
+00:07:42,000 --> 00:07:47,000
+You should remember that in case of any questions, you are always welcome to ask your questions below
+
+100
+00:07:47,000 --> 00:07:50,000
+the video and I will be happy to answer.
+
+101
+00:07:51,000 --> 00:07:58,000
+It is worse to know that spring will load all the messages, properties, files, content and store
+
+102
+00:07:58,000 --> 00:07:59,000
+in memory.
+
+103
+00:08:00,000 --> 00:08:00,000
+Czars.
+
+104
+00:08:00,000 --> 00:08:07,000
+If in any case, we want to update the messages properties file and expect the changes are updated to
+
+105
+00:08:07,000 --> 00:08:14,000
+the system at runtime, we can consider using the Reloadable Resource Bundle message source instead.
+
+106
+00:08:14,000 --> 00:08:19,000
+The next being that I declared here is local resolver beam.
+
+107
+00:08:19,000 --> 00:08:23,000
+It helps to identify which locale is being used.
+
+108
+00:08:24,000 --> 00:08:33,000
+Spring provides for concrete implementations of local resolver za accept header Local resolver uses
+
+109
+00:08:33,000 --> 00:08:38,000
+the primary local specified in the accept language header of the HTTP request.
+
+110
+00:08:39,000 --> 00:08:40,000
+Fixed local resolver.
+
+111
+00:08:41,000 --> 00:08:48,000
+Always return a fixed default locale and optionally time zone session local resolver.
+
+112
+00:08:48,000 --> 00:08:56,000
+Use the local attribute in the user session with a fallback to the specified default local or the request
+
+113
+00:08:56,000 --> 00:08:58,000
+accept header locale.
+
+114
+00:08:59,000 --> 00:09:00,000
+Go to your local resolver.
+
+115
+00:09:00,000 --> 00:09:06,000
+Persist a custom local and or a timezone information as the browser cookie.
+
+116
+00:09:06,000 --> 00:09:12,000
+We use this cookie local resolver in case the application has to be stateless.
+
+117
+00:09:12,000 --> 00:09:17,000
+In this particular example I use the cookie local resolver.
+
+118
+00:09:17,000 --> 00:09:19,000
+What else do we need?
+
+119
+00:09:19,000 --> 00:09:23,000
+In previous lesson we learn what interceptors are.
+
+120
+00:09:23,000 --> 00:09:29,000
+This time we need to configure one more interceptor that will intercept specific request parameter.
+
+121
+00:09:29,000 --> 00:09:32,000
+This is responsible for the language change.
+
+122
+00:09:32,000 --> 00:09:34,000
+Let me show you this.
+
+123
+00:09:35,000 --> 00:09:38,000
+In the previous lesson, we override add interceptors message.
+
+124
+00:09:39,000 --> 00:09:42,000
+This time I just create local change interceptor.
+
+125
+00:09:42,000 --> 00:09:46,000
+Inside this method I set parameter name.
+
+126
+00:09:46,000 --> 00:09:52,000
+This is the name of parameter that we are going to track each time we handle the request.
+
+127
+00:09:52,000 --> 00:10:00,000
+The value of this parameter length parameter will be used to configure local inside our application.
+
+128
+00:10:00,000 --> 00:10:05,000
+And now I can confirm that we configured everything what we need.
+
+129
+00:10:05,000 --> 00:10:09,000
+Let me start the web server and show you what we have.
+
+130
+00:10:10,000 --> 00:10:11,000
+Is a web browser.
+
+131
+00:10:11,000 --> 00:10:14,000
+Lets navigate to the Test land demo.
+
+132
+00:10:15,000 --> 00:10:22,000
+Here you can see English text by default, but when I click on the button to change language to French,
+
+133
+00:10:22,000 --> 00:10:30,000
+the content on the page is rewarded because I have French local right now and spring results the messages
+
+134
+00:10:30,000 --> 00:10:32,000
+from the French Resource bundle.
+
+135
+00:10:33,000 --> 00:10:39,000
+I can switch back to English and voila, text is in English again.
+
+136
+00:10:39,000 --> 00:10:40,000
+Isn't this cool?
+
+137
+00:10:41,000 --> 00:10:47,000
+You can compare the amount of actions that you need to do to configure localization without speaking.
+
+138
+00:10:47,000 --> 00:10:54,000
+We see and we spring and we see, as you can see with the spring of see, you can save significant amount
+
+139
+00:10:54,000 --> 00:10:55,000
+of time during the development.
+
+140
+00:10:56,000 --> 00:11:01,000
+And the last but not the least, think for the days that I would like to show you is how to work with
+
+141
+00:11:01,000 --> 00:11:06,000
+message source Bim Do remember that we declared such been in our web config.
+
+142
+00:11:07,000 --> 00:11:12,000
+It can happen that you need to resolve localized message inside your code.
+
+143
+00:11:12,000 --> 00:11:16,000
+For example, very soon you are going to have the homework.
+
+144
+00:11:16,000 --> 00:11:22,000
+It is about applying spring MVC to the online shop is that we do together with my students from scratch
+
+145
+00:11:22,000 --> 00:11:30,000
+during the all course and in the homework there are specific validation rules and messages are set based
+
+146
+00:11:30,000 --> 00:11:32,000
+on the rule that was violated.
+
+147
+00:11:32,000 --> 00:11:39,000
+So it can happen that in the controller you need to set the localized attribute.
+
+148
+00:11:39,000 --> 00:11:41,000
+Let me show it to you.
+
+149
+00:11:41,000 --> 00:11:44,000
+I open localization controller demo.
+
+150
+00:11:44,000 --> 00:11:51,000
+Again, pay attention that we have message source being here injected and we have another method that
+
+151
+00:11:51,000 --> 00:11:53,000
+is mapped to the message source demo.
+
+152
+00:11:54,000 --> 00:11:56,000
+We inject session object here.
+
+153
+00:11:57,000 --> 00:12:03,000
+You can imagine that there is some validation logic is here on place and I use session object to inject
+
+154
+00:12:03,000 --> 00:12:06,000
+attribute with the name test message.
+
+155
+00:12:07,000 --> 00:12:14,000
+I use message source to invoke get message message in order to resolve random text from the resource
+
+156
+00:12:14,000 --> 00:12:18,000
+bundle according to the current default locale.
+
+157
+00:12:18,000 --> 00:12:24,000
+And you already know that local will be changed by interceptor that we have configured.
+
+158
+00:12:24,000 --> 00:12:26,000
+I use special types.
+
+159
+00:12:26,000 --> 00:12:28,000
+It is called local context holder.
+
+160
+00:12:29,000 --> 00:12:36,000
+You can extract the current local for the threat using get local pay attention to this API.
+
+161
+00:12:36,000 --> 00:12:40,000
+Get message may take array of arguments.
+
+162
+00:12:40,000 --> 00:12:44,000
+This is a way of arguments that can be injected into the text message.
+
+163
+00:12:45,000 --> 00:12:47,000
+In our case, we have nothing to inject.
+
+164
+00:12:47,000 --> 00:12:53,000
+That's why we pass new here in the message source demo JSP file.
+
+165
+00:12:54,000 --> 00:12:57,000
+I have the same two buttons to change local.
+
+166
+00:12:58,000 --> 00:13:04,000
+And I use JSP expression language to extract our test message from the session and print it to console.
+
+167
+00:13:05,000 --> 00:13:08,000
+Now let's look how this works in browser.
+
+168
+00:13:09,000 --> 00:13:14,000
+I change the URL to message source demo and here it is.
+
+169
+00:13:14,000 --> 00:13:20,000
+In the same way I can switch the language and message source will return the message from different
+
+170
+00:13:20,000 --> 00:13:21,000
+resource bundle.
+
+171
+00:13:22,000 --> 00:13:26,000
+All source code examples you can find in attachments to the video.
+
+172
+00:13:26,000 --> 00:13:31,000
+Feel free to explore the code, play with it to understand it better.
+
+173
+00:13:32,000 --> 00:13:34,000
+That's all what I wanted to share with you today.
+
+174
+00:13:35,000 --> 00:13:38,000
+Let's recap what we have learned in the lesson.
+
+175
+00:13:39,000 --> 00:13:43,000
+In this video, we learn localization and internationalization.
+
+176
+00:13:43,000 --> 00:13:47,000
+We review practical demo and coding exercises.
+
+177
+00:13:48,000 --> 00:13:54,000
+I explained you how to configure sprinkle receipt, including message source Bing local resolver being
+
+178
+00:13:54,000 --> 00:14:01,000
+included in its key implementations like accept header, local resolver, fixed local resolver session,
+
+179
+00:14:01,000 --> 00:14:08,000
+local resolver, Kuki local resolver and how to use local context holder class.
+
+180
+00:14:09,000 --> 00:14:10,000
+That's all for this lesson.
+
+181
+00:14:10,000 --> 00:14:12,000
+Thanks a lot for your attention.
+
+182
+00:14:12,000 --> 00:14:15,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/007 Source-code-of-examples-commit-with-changes-.url b/82 - Spring MVC & Spring for WEB/007 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..e652b484846b7b115f922a6e17395227d72a0bfd
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/007 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/3087cf3027ac07c39becdbd031e36c01cf3fa0e2
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/008 Redirect & Forward in Spring MVC_en.srt b/82 - Spring MVC & Spring for WEB/008 Redirect & Forward in Spring MVC_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..a94eb0a92035ec840a8abcefa901525a5a0232a6
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/008 Redirect & Forward in Spring MVC_en.srt
@@ -0,0 +1,792 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello.
+
+2
+00:00:07,000 --> 00:00:12,000
+In this video, we're going to learn how to use request redirection and request forwarding in spring
+
+3
+00:00:12,000 --> 00:00:13,000
+MVC.
+
+4
+00:00:13,000 --> 00:00:16,000
+We'll start from the redirect topic.
+
+5
+00:00:16,000 --> 00:00:21,000
+We'll learn how to forward requests to the View and how to resolve the view.
+
+6
+00:00:21,000 --> 00:00:26,000
+But what to do in case we need to redirect the request to another resource.
+
+7
+00:00:26,000 --> 00:00:34,000
+Similarly to the central direct message from the Servlet API, we'll understand why and when we need
+
+8
+00:00:34,000 --> 00:00:35,000
+to use redirect.
+
+9
+00:00:35,000 --> 00:00:42,000
+And we'll learn different ways of how to redirect requests, including redirect with prefix, redirect
+
+10
+00:00:42,000 --> 00:00:43,000
+with module and view.
+
+11
+00:00:43,000 --> 00:00:46,000
+Redirect with redirect view object.
+
+12
+00:00:47,000 --> 00:00:54,000
+In case we didn't need to resolve the view instantly, but instead we need to forward a request to another
+
+13
+00:00:54,000 --> 00:00:55,000
+resource.
+
+14
+00:00:55,000 --> 00:00:58,000
+We need to know how to use request forwarding.
+
+15
+00:00:58,000 --> 00:01:03,000
+I'm going to explain how to use for graphics during the lesson.
+
+16
+00:01:03,000 --> 00:01:08,000
+You are going to learn what flash attributes are and how to use them.
+
+17
+00:01:09,000 --> 00:01:10,000
+Let's start our lesson.
+
+18
+00:01:11,000 --> 00:01:19,000
+But before we jump directly to example, let's understand first in which cases we need to use redirect.
+
+19
+00:01:20,000 --> 00:01:26,000
+For example, do you remember PIRG pattern post rhetoric Get pattern.
+
+20
+00:01:26,000 --> 00:01:31,000
+We discussed this pattern in my course Java from zero to first job.
+
+21
+00:01:31,000 --> 00:01:34,000
+But I will quickly remind you what it is about.
+
+22
+00:01:35,000 --> 00:01:43,000
+This pattern is about avoidance of double submission of form after client submitted it with the post
+
+23
+00:01:43,000 --> 00:01:43,000
+message.
+
+24
+00:01:44,000 --> 00:01:52,000
+Because during the refresh, the page and browser browser will execute the last request and form will
+
+25
+00:01:52,000 --> 00:01:59,000
+be submitted again, which can cause inconsistencies and unexpected behavior of the application.
+
+26
+00:01:59,000 --> 00:02:07,000
+To avoid this, according to the p r g pattern, we redirect the request after sending post message.
+
+27
+00:02:07,000 --> 00:02:14,000
+Or imagine that you simply need to start another execution flow and delegate the request to another
+
+28
+00:02:14,000 --> 00:02:15,000
+controller.
+
+29
+00:02:15,000 --> 00:02:18,000
+What is also can be important.
+
+30
+00:02:18,000 --> 00:02:25,000
+You would like to show the client that another resource is accessed by changing the URL in browser.
+
+31
+00:02:26,000 --> 00:02:34,000
+I believe you remember that when we use redirect, the actual URL in ad lib is also changed.
+
+32
+00:02:34,000 --> 00:02:37,000
+I'm going to show you this today to.
+
+33
+00:02:38,000 --> 00:02:41,000
+All topics today we're going to learn on examples.
+
+34
+00:02:41,000 --> 00:02:48,000
+So let me start screen share and straight away and jump to the coding examples that I prepared for you.
+
+35
+00:02:48,000 --> 00:02:52,000
+We're going to start our lesson with the rhetoric examples in spring.
+
+36
+00:02:52,000 --> 00:02:59,000
+Can we see let me open the file from the controller's package that is called Redirect Forward demo.
+
+37
+00:03:00,000 --> 00:03:04,000
+All examples related with redirect will be located in this file.
+
+38
+00:03:05,000 --> 00:03:11,000
+Just to remind you that as usual, you can find all source code examples in attachments to the video.
+
+39
+00:03:11,000 --> 00:03:17,000
+You can copy code examples and play with the source code to understand better.
+
+40
+00:03:18,000 --> 00:03:20,000
+There are different ways of how to execute.
+
+41
+00:03:20,000 --> 00:03:25,000
+Rhetoric in spring can be seen, in my opinion and based on my experience.
+
+42
+00:03:25,000 --> 00:03:31,000
+The most popular option is by using rhetoric traffics in the method rhetoric.
+
+43
+00:03:31,000 --> 00:03:38,000
+With graphics you can see that I use rhetoric, graphics and after that I use column.
+
+44
+00:03:38,000 --> 00:03:42,000
+And then we put the rhetoric Hero, pay attention.
+
+45
+00:03:42,000 --> 00:03:44,000
+This is not just the view.
+
+46
+00:03:44,000 --> 00:03:47,000
+This will not be resolved as a view.
+
+47
+00:03:47,000 --> 00:03:52,000
+This will be resolved as a URL where request will be said.
+
+48
+00:03:53,000 --> 00:03:58,000
+In this case, the request will be redirected to the controller in this application.
+
+49
+00:03:58,000 --> 00:04:01,000
+This is map with the rhetoric demo URL.
+
+50
+00:04:02,000 --> 00:04:05,000
+Here is the method that will handle this request.
+
+51
+00:04:06,000 --> 00:04:10,000
+And now in this method the view will be actually resolved.
+
+52
+00:04:11,000 --> 00:04:15,000
+The content of the view is not important in scope of this example.
+
+53
+00:04:16,000 --> 00:04:20,000
+That's why I will not show you the actual JSP page.
+
+54
+00:04:21,000 --> 00:04:28,000
+Let's start the Web server and let's check this first example of the Web server is started.
+
+55
+00:04:28,000 --> 00:04:35,000
+I send request to the test redirect graphics and you can see that redirect happened.
+
+56
+00:04:36,000 --> 00:04:41,000
+The URL is changed now and everything works as expected.
+
+57
+00:04:42,000 --> 00:04:44,000
+Let's get back to the source core.
+
+58
+00:04:45,000 --> 00:04:51,000
+I hope that you understood that redirect happens to the relatively to the context.
+
+59
+00:04:51,000 --> 00:04:54,000
+You are also allowed to use.
+
+60
+00:04:54,000 --> 00:04:54,000
+Absolutely.
+
+61
+00:04:54,000 --> 00:05:00,000
+Your role here in case it is needed to redirect request to other domain.
+
+62
+00:05:00,000 --> 00:05:09,000
+You can see example with a redirect google I use prefix and after that I specify protocol and you will
+
+63
+00:05:09,000 --> 00:05:11,000
+adjust where redirection should happen.
+
+64
+00:05:12,000 --> 00:05:14,000
+Let me show you this example in browser.
+
+65
+00:05:14,000 --> 00:05:21,000
+I type here regular Google and be redirected to the external website via absolute hero rule.
+
+66
+00:05:22,000 --> 00:05:25,000
+Now let's review another interesting example.
+
+67
+00:05:26,000 --> 00:05:34,000
+Imagine that you need to redirect request to another resource, but still you want to pass some attributes
+
+68
+00:05:34,000 --> 00:05:36,000
+to be resolved on the another view.
+
+69
+00:05:37,000 --> 00:05:38,000
+How to do this?
+
+70
+00:05:39,000 --> 00:05:45,000
+You still can use modeling view and set attributes into it and redirect with the model and view.
+
+71
+00:05:46,000 --> 00:05:48,000
+Let me show you this.
+
+72
+00:05:48,000 --> 00:05:51,000
+Here you can see Massob rhetoric model.
+
+73
+00:05:52,000 --> 00:05:57,000
+And now attention, because terminology may sound confusing.
+
+74
+00:05:57,000 --> 00:06:02,000
+I have just told you that you can redirect more with attributes, which is, technically speaking,
+
+75
+00:06:02,000 --> 00:06:04,000
+not correct.
+
+76
+00:06:04,000 --> 00:06:06,000
+But it is looks so.
+
+77
+00:06:07,000 --> 00:06:08,000
+Let me explain.
+
+78
+00:06:08,000 --> 00:06:17,000
+I inject model map here because later we're going to use constructor of model and view that accepts
+
+79
+00:06:17,000 --> 00:06:18,000
+map of parameters.
+
+80
+00:06:19,000 --> 00:06:27,000
+And even despite the fact that we use API of model map and call method add attribute and even despite
+
+81
+00:06:27,000 --> 00:06:35,000
+we return new object of modeling view, we should remember that redirection will happen and using the
+
+82
+00:06:35,000 --> 00:06:43,000
+redirection is a new request object is usually created so it will not be possible to pass attributes.
+
+83
+00:06:43,000 --> 00:06:53,000
+But how sprint will resolve this instead of attributes, values will be passed as request query parameters.
+
+84
+00:06:53,000 --> 00:07:00,000
+And it is important to understand because when you will try to resolve these values, you should remember
+
+85
+00:07:00,000 --> 00:07:03,000
+that they will be passed as request query parameters.
+
+86
+00:07:04,000 --> 00:07:06,000
+Let me show you the rhetoric.
+
+87
+00:07:06,000 --> 00:07:07,000
+Demo JSP.
+
+88
+00:07:07,000 --> 00:07:13,000
+On this view you can see that I use implicit object param that is present on the page.
+
+89
+00:07:14,000 --> 00:07:21,000
+I use it to extract requests param because our string will be passed as a request query parameter.
+
+90
+00:07:21,000 --> 00:07:23,000
+Let me show you this in browser.
+
+91
+00:07:24,000 --> 00:07:25,000
+In the browser.
+
+92
+00:07:25,000 --> 00:07:31,000
+I send a request to the redirect model and you can see that we are redirected to the rhetoric demo resource
+
+93
+00:07:32,000 --> 00:07:37,000
+and that request query parameter has been added once the page.
+
+94
+00:07:37,000 --> 00:07:40,000
+We managed to resolve this parameter successfully.
+
+95
+00:07:40,000 --> 00:07:44,000
+And again, I draw your attention to the semantics here.
+
+96
+00:07:44,000 --> 00:07:53,000
+I wrote that this is an attribute from the model because we used API that is named add attribute, but
+
+97
+00:07:53,000 --> 00:07:59,000
+in reality we resolve request query parameter here on the page.
+
+98
+00:08:00,000 --> 00:08:09,000
+That's why in the parentheses I specified the details and we can't resolve this value from the request
+
+99
+00:08:09,000 --> 00:08:13,000
+code because the new request was created during the redirect.
+
+100
+00:08:14,000 --> 00:08:19,000
+But when will use forward prefix to forward the request?
+
+101
+00:08:19,000 --> 00:08:27,000
+In that case we will be able to store attribute in the request object and resolve it from the request.
+
+102
+00:08:28,000 --> 00:08:31,000
+You're going to see this later during the demo.
+
+103
+00:08:31,000 --> 00:08:37,000
+You should also understand all consequences of passing request parameters.
+
+104
+00:08:37,000 --> 00:08:43,000
+If you follow attentively my course java from zero to first job, then you should remember that your
+
+105
+00:08:43,000 --> 00:08:47,000
+URL has maximum limit of amount of characters.
+
+106
+00:08:47,000 --> 00:08:52,000
+That means that you can't pass endless amount of characters.
+
+107
+00:08:53,000 --> 00:08:58,000
+Also, this limits the variety of data types that you can pass.
+
+108
+00:08:58,000 --> 00:09:06,000
+Obviously, string objects will be resolved successfully, but it will be hard for you to pass custom
+
+109
+00:09:06,000 --> 00:09:08,000
+reference types of data.
+
+110
+00:09:08,000 --> 00:09:17,000
+So be attentive and put as parameter strings or other objects that can be converted to a string.
+
+111
+00:09:18,000 --> 00:09:23,000
+The next thing that we are going to discuss today is redirect with redirect view object.
+
+112
+00:09:24,000 --> 00:09:26,000
+Let's jump directly to the example.
+
+113
+00:09:27,000 --> 00:09:30,000
+You can see that I injected redirect attributes here.
+
+114
+00:09:31,000 --> 00:09:37,000
+It is just another API that you can use when you need to pass parameters during the redirect.
+
+115
+00:09:38,000 --> 00:09:45,000
+The most interesting thing of this type is possibility to add flash attributes a little bit later during
+
+116
+00:09:45,000 --> 00:09:50,000
+the lesson I'm going to show you example with Flash attribute.
+
+117
+00:09:50,000 --> 00:09:58,000
+So when you redirect with retrograde view, you just return redirect view object with a URL that needs
+
+118
+00:09:58,000 --> 00:09:59,000
+to be resolved.
+
+119
+00:10:00,000 --> 00:10:00,000
+Pay attention.
+
+120
+00:10:00,000 --> 00:10:05,000
+The given URL will be considered as relative to the web server.
+
+121
+00:10:05,000 --> 00:10:07,000
+This is important.
+
+122
+00:10:07,000 --> 00:10:08,000
+That's it.
+
+123
+00:10:08,000 --> 00:10:14,000
+In this case, test parameter also will be resolved as a request parameter.
+
+124
+00:10:14,000 --> 00:10:20,000
+Don't worry, I'm going to share with you the reference to the source code and you will be able to check
+
+125
+00:10:20,000 --> 00:10:22,000
+all examples by yourself.
+
+126
+00:10:23,000 --> 00:10:30,000
+You can send a request to redirect, redirect you request, and the result will be the same as in previous
+
+127
+00:10:30,000 --> 00:10:31,000
+examples.
+
+128
+00:10:32,000 --> 00:10:35,000
+You can send a request to redirect with redirect view.
+
+129
+00:10:36,000 --> 00:10:44,000
+As a result, we are going to have four of four because redirect happens relatively to the server,
+
+130
+00:10:45,000 --> 00:10:48,000
+but not relatively to the servlet context.
+
+131
+00:10:48,000 --> 00:10:51,000
+Can you see that name of our context?
+
+132
+00:10:51,000 --> 00:10:57,000
+Disappeared after redirection and we don't have spring web here.
+
+133
+00:10:58,000 --> 00:10:59,000
+Let's continue.
+
+134
+00:11:00,000 --> 00:11:08,000
+Now, let me show you examples with the flash attributes here in the next method rhetoric with flesh
+
+135
+00:11:08,000 --> 00:11:09,000
+attributes.
+
+136
+00:11:09,000 --> 00:11:15,000
+In the similar way I inject rhetoric attributes, and I add flesh attribute.
+
+137
+00:11:15,000 --> 00:11:19,000
+I can pass either flesh attributes or regular attributes.
+
+138
+00:11:19,000 --> 00:11:21,000
+Let's learn the difference.
+
+139
+00:11:22,000 --> 00:11:30,000
+Flash attributes provide a way for one request to store attributes intended for use in another.
+
+140
+00:11:30,000 --> 00:11:33,000
+This is most commonly needed when redirecting.
+
+141
+00:11:33,000 --> 00:11:37,000
+For example, the post redirect get pardon.
+
+142
+00:11:38,000 --> 00:11:42,000
+Flash attributes are saved temporarily before the redirect.
+
+143
+00:11:43,000 --> 00:11:50,000
+Typically in the session to be made available to the request after the rhetoric and removed immediately.
+
+144
+00:11:51,000 --> 00:11:56,000
+In our example, the request is redirected to the redirect flash resource.
+
+145
+00:11:56,000 --> 00:12:02,000
+Inside this method I extract slash attribute and print it to console.
+
+146
+00:12:02,000 --> 00:12:09,000
+This is the only way to prove that attribute is present in the model because it will be absent in the
+
+147
+00:12:09,000 --> 00:12:11,000
+request parameters.
+
+148
+00:12:11,000 --> 00:12:13,000
+Let me show you this.
+
+149
+00:12:13,000 --> 00:12:22,000
+In the areas we write redirect with slash attribute and we are redirected attention that only parameters
+
+150
+00:12:22,000 --> 00:12:27,000
+that we added with the add attribute message is displayed here in the URL.
+
+151
+00:12:28,000 --> 00:12:32,000
+And in the console we can see that we printed flash attribute.
+
+152
+00:12:33,000 --> 00:12:36,000
+It is disappeared after redirection is happened.
+
+153
+00:12:37,000 --> 00:12:40,000
+Also you can use flash map type.
+
+154
+00:12:41,000 --> 00:12:45,000
+This type also allows you to add flash attributes.
+
+155
+00:12:46,000 --> 00:12:53,000
+Now you know this API and you can use it when it will be needed depending on your business case.
+
+156
+00:12:53,000 --> 00:12:54,000
+Let's continue.
+
+157
+00:12:55,000 --> 00:12:56,000
+In this lesson.
+
+158
+00:12:56,000 --> 00:13:00,000
+I want also to show you another practice that we can use.
+
+159
+00:13:00,000 --> 00:13:04,000
+I want to show you examples of forward practice.
+
+160
+00:13:04,000 --> 00:13:09,000
+Let's understand first what is the difference between rhetoric and forward practices.
+
+161
+00:13:10,000 --> 00:13:16,000
+Basically, the difference is similar to differences between central direct method and forward message
+
+162
+00:13:16,000 --> 00:13:26,000
+that we learned when we reviewed servlet API redirect will respond with the 302 and the new URL in the
+
+163
+00:13:26,000 --> 00:13:27,000
+location header.
+
+164
+00:13:27,000 --> 00:13:36,000
+The browser client will then make another request using you your role for what happens entirely on the
+
+165
+00:13:36,000 --> 00:13:37,000
+server side.
+
+166
+00:13:37,000 --> 00:13:42,000
+The server container forwards the same request to the target URL.
+
+167
+00:13:43,000 --> 00:13:46,000
+The euro won't change in the browser.
+
+168
+00:13:46,000 --> 00:13:49,000
+Want to use forward graphics.
+
+169
+00:13:49,000 --> 00:13:57,000
+Usually screen controller results for you was a recurrent string or model and view object, for example.
+
+170
+00:13:57,000 --> 00:14:05,000
+But with forward you can forward the same request, object to another resource and not resolve you instantly.
+
+171
+00:14:06,000 --> 00:14:09,000
+Let's look at example in the class.
+
+172
+00:14:09,000 --> 00:14:12,000
+We have methods of the scope for demo.
+
+173
+00:14:12,000 --> 00:14:15,000
+I pass model map as a parameter.
+
+174
+00:14:15,000 --> 00:14:18,000
+I add attribute to the model map.
+
+175
+00:14:18,000 --> 00:14:24,000
+In this case, I want to show you that the attribute will be added to the request object and will not
+
+176
+00:14:24,000 --> 00:14:27,000
+be passed as a parameter on The View.
+
+177
+00:14:28,000 --> 00:14:32,000
+We will be able to resolve this value from the implicit object request scope.
+
+178
+00:14:33,000 --> 00:14:40,000
+As you can see, I specify forward graphics and specify the URL for the sake of the demo.
+
+179
+00:14:40,000 --> 00:14:45,000
+I will forward request to the same rhetoric demo URL that we already used.
+
+180
+00:14:45,000 --> 00:14:47,000
+That will just resolve the view.
+
+181
+00:14:48,000 --> 00:14:50,000
+Let's look at how this works.
+
+182
+00:14:51,000 --> 00:14:58,000
+In the web browser, I send a request to the forward euro and we can see the URL is not changed.
+
+183
+00:14:58,000 --> 00:15:05,000
+That is because I used forward graphics instead of the rhetoric and also not the important thing.
+
+184
+00:15:06,000 --> 00:15:08,000
+I don't have requests query parameter.
+
+185
+00:15:09,000 --> 00:15:12,000
+Instead, I resolve attribute from the request object.
+
+186
+00:15:12,000 --> 00:15:14,000
+Is everything clear?
+
+187
+00:15:14,000 --> 00:15:21,000
+In case you have any questions, do not hesitate to ask your questions below the video and I will be
+
+188
+00:15:21,000 --> 00:15:23,000
+happy to answer.
+
+189
+00:15:24,000 --> 00:15:26,000
+That's all what I wanted to share with you today.
+
+190
+00:15:27,000 --> 00:15:30,000
+Let's recap what we have learned in this lesson.
+
+191
+00:15:32,000 --> 00:15:38,000
+In the lesson we learned how rhetoric works in spring and we see and when we need to use rhetoric,
+
+192
+00:15:39,000 --> 00:15:42,000
+we learn different ways of redirection.
+
+193
+00:15:42,000 --> 00:15:47,000
+For example, with the help of rhetoric graphics using absolute relative paths.
+
+194
+00:15:48,000 --> 00:15:54,000
+I also showed you rhetorics with modeling, view object and with rhetoric view object.
+
+195
+00:15:54,000 --> 00:16:01,000
+I explained you how attributes are resolved during the resurrection and what flesh attributes are.
+
+196
+00:16:01,000 --> 00:16:07,000
+And at the end of the lesson, we learned how to make requests forward with the forward graphics.
+
+197
+00:16:08,000 --> 00:16:10,000
+Thanks a lot for your attention, team.
+
+198
+00:16:10,000 --> 00:16:13,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/008 Source-code-of-examples-commit-with-changes-.url b/82 - Spring MVC & Spring for WEB/008 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..df97ee48391c33fbae50bee3cf99ffff0cfbd327
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/008 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/4f5e51b45a9e8fdb2977269c9d1333fc3ae9ab69
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/009 Source-code-of-examples-commit-with-changes-COOKIES.url b/82 - Spring MVC & Spring for WEB/009 Source-code-of-examples-commit-with-changes-COOKIES.url
new file mode 100644
index 0000000000000000000000000000000000000000..e55c85515664474a01462a39e3a66adf1997e450
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/009 Source-code-of-examples-commit-with-changes-COOKIES.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/22b6853624b800f17f435d46780f057b569c0fd4
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/009 Source-code-of-examples-commit-with-changes-PROPERTIES.url b/82 - Spring MVC & Spring for WEB/009 Source-code-of-examples-commit-with-changes-PROPERTIES.url
new file mode 100644
index 0000000000000000000000000000000000000000..1172227139d7fab842f59d87b1c99aa6a8d55ddd
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/009 Source-code-of-examples-commit-with-changes-PROPERTIES.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/483d9c3b2751193dfcf575478d20e8e214637149
\ No newline at end of file
diff --git a/82 - Spring MVC & Spring for WEB/009 Spring API - Work with Cookies in Spring MVC & Work with Properties_en.srt b/82 - Spring MVC & Spring for WEB/009 Spring API - Work with Cookies in Spring MVC & Work with Properties_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..905c948f5258d453458dd0bcdb32e03c3d4d877d
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/009 Spring API - Work with Cookies in Spring MVC & Work with Properties_en.srt
@@ -0,0 +1,456 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:09,000
+Today we're going to have short lesson.
+
+3
+00:00:09,000 --> 00:00:14,000
+In this video, we're going to discuss topics which in my opinion, are relatively small for the separate
+
+4
+00:00:14,000 --> 00:00:18,000
+lesson, but still super important to know.
+
+5
+00:00:18,000 --> 00:00:24,000
+In this video, we're going to learn how to work with cookies in spring and week and how to work with
+
+6
+00:00:24,000 --> 00:00:25,000
+spring properties.
+
+7
+00:00:26,000 --> 00:00:33,000
+We'll start our lesson from learning how to set cookies and how with cookies with the spring MVC API
+
+8
+00:00:33,000 --> 00:00:40,000
+take into account cookies is not a new topic for you because we already reviewed this topic when we
+
+9
+00:00:40,000 --> 00:00:44,000
+learned servlet API in my course Java from zero to first job.
+
+10
+00:00:45,000 --> 00:00:49,000
+I'm sure that you will grasp the new knowledge easily.
+
+11
+00:00:49,000 --> 00:00:54,000
+After that we'll review code examples and we'll learn how to work with properties.
+
+12
+00:00:54,000 --> 00:00:55,000
+In spring.
+
+13
+00:00:55,000 --> 00:01:01,000
+I'm going to explain how to configure property sources with properties, source and property sources.
+
+14
+00:01:01,000 --> 00:01:07,000
+Annotations, and how to inject properties into the fields with the value annotation.
+
+15
+00:01:07,000 --> 00:01:09,000
+Let's start our lesson.
+
+16
+00:01:10,000 --> 00:01:13,000
+Let's jump directly to code examples.
+
+17
+00:01:13,000 --> 00:01:20,000
+We're going to start from learning of how to work with cookies in spring, and we see in this lesson,
+
+18
+00:01:20,000 --> 00:01:26,000
+I will not stop on explaining what cookies are because we already learn this in our previous lessons.
+
+19
+00:01:27,000 --> 00:01:34,000
+I just can briefly highlight that cookies are small pieces of text sent to your browser by a website
+
+20
+00:01:34,000 --> 00:01:35,000
+you visit.
+
+21
+00:01:36,000 --> 00:01:42,000
+They help that website remember information about your visit, which can both make it easier to visit
+
+22
+00:01:42,000 --> 00:01:46,000
+the site again and make the site more useful to you.
+
+23
+00:01:47,000 --> 00:01:51,000
+I opened the file that is called Cookie Demo Controller.
+
+24
+00:01:51,000 --> 00:01:55,000
+Let's start from learning how we can set cookie.
+
+25
+00:01:55,000 --> 00:02:02,000
+If you follow my course Java from zero to first job, then you remember lesson from the servlet API
+
+26
+00:02:02,000 --> 00:02:03,000
+section.
+
+27
+00:02:03,000 --> 00:02:05,000
+How we worked with cookies.
+
+28
+00:02:05,000 --> 00:02:08,000
+Actually a lot of similarities in here.
+
+29
+00:02:09,000 --> 00:02:11,000
+Namely, we want to set cookie.
+
+30
+00:02:12,000 --> 00:02:18,000
+For this we'll use http servlet response class method at cookie spring.
+
+31
+00:02:18,000 --> 00:02:27,000
+Doesn't provide any fancy way to set HTTP cookie because it's already taken care by servlet http servlet
+
+32
+00:02:27,000 --> 00:02:29,000
+response class.
+
+33
+00:02:29,000 --> 00:02:37,000
+All you need to do is to use just one method at cookie spring and this can be used to get the response
+
+34
+00:02:37,000 --> 00:02:44,000
+object here in the set cookie method, you can see that we asked spring to give us a reference to the
+
+35
+00:02:44,000 --> 00:02:51,000
+response object once we have this object, we can easily add any cookie we need.
+
+36
+00:02:51,000 --> 00:02:56,000
+I add task cookie and resolve the view by its name.
+
+37
+00:02:56,000 --> 00:02:58,000
+Nothing is complex here.
+
+38
+00:02:59,000 --> 00:03:07,000
+Let's execute this URL in the web browser and check that cookie is actually added to check that cookie
+
+39
+00:03:07,000 --> 00:03:08,000
+is added.
+
+40
+00:03:08,000 --> 00:03:12,000
+I'm going to use dev console in Google Chrome browser.
+
+41
+00:03:13,000 --> 00:03:16,000
+Is a web browser I call set cookie URL.
+
+42
+00:03:16,000 --> 00:03:21,000
+And when I hit this resource, let's check the dev console.
+
+43
+00:03:22,000 --> 00:03:25,000
+I clicked F12 to open dev console.
+
+44
+00:03:25,000 --> 00:03:31,000
+I open the application tab and after that I check cookie tab.
+
+45
+00:03:31,000 --> 00:03:34,000
+And here I can find test cookie.
+
+46
+00:03:35,000 --> 00:03:37,000
+So here is nothing new for you.
+
+47
+00:03:38,000 --> 00:03:40,000
+Let's learn how to extract cookie.
+
+48
+00:03:41,000 --> 00:03:43,000
+And here is pre introduced.
+
+49
+00:03:43,000 --> 00:03:46,000
+Nice API to work with cookie.
+
+50
+00:03:47,000 --> 00:03:49,000
+In the method extract cookie.
+
+51
+00:03:49,000 --> 00:03:52,000
+You can see that I use annotation cookie value.
+
+52
+00:03:52,000 --> 00:03:59,000
+With this annotation I specify cookie name that I want to extract from the request.
+
+53
+00:03:59,000 --> 00:04:07,000
+Pay attention that in case there will not be cookie with the value you specified, there will be an
+
+54
+00:04:07,000 --> 00:04:07,000
+error.
+
+55
+00:04:08,000 --> 00:04:14,000
+That's why I recommend you to specify the default value to just in case.
+
+56
+00:04:15,000 --> 00:04:22,000
+This is pretty useful when you know the name of the cookie you need to work with, but still you can
+
+57
+00:04:22,000 --> 00:04:30,000
+use Servlet API and extract all cookies from the request and iterate over an array of cookies.
+
+58
+00:04:30,000 --> 00:04:33,000
+If you wish to then use this method.
+
+59
+00:04:33,000 --> 00:04:38,000
+I need to send requests to another resource in the web browser.
+
+60
+00:04:38,000 --> 00:04:48,000
+I type extract cookie and after I hit that resource we print the cookie value to console and here is
+
+61
+00:04:48,000 --> 00:04:51,000
+our test value is in console.
+
+62
+00:04:52,000 --> 00:04:56,000
+That's how easily you can work with cookies in spring MVC.
+
+63
+00:04:57,000 --> 00:05:03,000
+And the last but not the least for today that I wanted to discuss with you is how to work with properties
+
+64
+00:05:03,000 --> 00:05:04,000
+in spring.
+
+65
+00:05:05,000 --> 00:05:09,000
+You already know that sometimes we need to store some configurations.
+
+66
+00:05:09,000 --> 00:05:17,000
+For example, default amount of products on product listing page, maybe the property that is also need
+
+67
+00:05:17,000 --> 00:05:19,000
+to be stored somewhere.
+
+68
+00:05:19,000 --> 00:05:26,000
+You always have an option to store application specific properties in the database, but this is not
+
+69
+00:05:26,000 --> 00:05:27,000
+always convenient.
+
+70
+00:05:27,000 --> 00:05:36,000
+Storing properties values in the source code also is not the best option because your code will be compiled
+
+71
+00:05:36,000 --> 00:05:38,000
+and built multiple times.
+
+72
+00:05:39,000 --> 00:05:46,000
+That's why storing properties in the special properties files that are not compiled might sound like
+
+73
+00:05:46,000 --> 00:05:50,000
+option for you during the runtime and execution of your program.
+
+74
+00:05:50,000 --> 00:05:54,000
+You can inject these properties when it will be needed.
+
+75
+00:05:55,000 --> 00:05:57,000
+Let me show you how to do this.
+
+76
+00:05:58,000 --> 00:06:02,000
+The first thing that we need to do is to have properties file.
+
+77
+00:06:02,000 --> 00:06:08,000
+We can declare properties in the properties files in the SC Main resources.
+
+78
+00:06:08,000 --> 00:06:18,000
+I create test properties, file and test two properties file just for the sake of example, each file
+
+79
+00:06:18,000 --> 00:06:20,000
+contains random set of properties.
+
+80
+00:06:21,000 --> 00:06:25,000
+I have values of different types integer and string.
+
+81
+00:06:26,000 --> 00:06:33,000
+The next thing that we need to do is to register the properties, file inside our configuration.
+
+82
+00:06:33,000 --> 00:06:35,000
+I open the config class.
+
+83
+00:06:36,000 --> 00:06:40,000
+You can declare one property file using the property source annotation.
+
+84
+00:06:41,000 --> 00:06:47,000
+Or you can declare multiple property files using property sources annotation.
+
+85
+00:06:48,000 --> 00:06:54,000
+In this particular example, I want to show you how to declare multiple property files.
+
+86
+00:06:54,000 --> 00:06:59,000
+Actually, there are different combinations that you can use to declare properties.
+
+87
+00:07:00,000 --> 00:07:08,000
+For example, you can use multiple property source annotations or you can group them inside property
+
+88
+00:07:08,000 --> 00:07:09,000
+sources.
+
+89
+00:07:09,000 --> 00:07:10,000
+It is up to you.
+
+90
+00:07:10,000 --> 00:07:16,000
+Here you can see that I registered to our properties files.
+
+91
+00:07:16,000 --> 00:07:23,000
+And now another important question how to use properties and how to extract values.
+
+92
+00:07:24,000 --> 00:07:29,000
+There is a special API in spring that allows you to inject property values easily.
+
+93
+00:07:30,000 --> 00:07:33,000
+Let me open Properties Demo Controller.
+
+94
+00:07:33,000 --> 00:07:36,000
+Here you can see properties of the class.
+
+95
+00:07:36,000 --> 00:07:41,000
+I use value annotation and pause the key from the properties file.
+
+96
+00:07:42,000 --> 00:07:49,000
+Key is passed with the help of the spring expression, language and spring will inject the value.
+
+97
+00:07:49,000 --> 00:07:56,000
+And for the sake of the demo, let me print the values to console to prove you that values were actually
+
+98
+00:07:56,000 --> 00:07:57,000
+injected.
+
+99
+00:07:58,000 --> 00:08:05,000
+Another way to extract properties is to inject environment, object and call get property method to
+
+100
+00:08:05,000 --> 00:08:07,000
+extract the properties that we need.
+
+101
+00:08:07,000 --> 00:08:12,000
+Like you can see here, pay attention that we don't use expression language here.
+
+102
+00:08:12,000 --> 00:08:15,000
+We just specify the key of the property.
+
+103
+00:08:16,000 --> 00:08:18,000
+Let's check how this works.
+
+104
+00:08:18,000 --> 00:08:25,000
+Let me send a request to the property demo and we will explore what is in console.
+
+105
+00:08:26,000 --> 00:08:34,000
+And after I sent request to the props demo, I see all the properties printed in console as expected.
+
+106
+00:08:35,000 --> 00:08:38,000
+Let's recap what we have learned in this video.
+
+107
+00:08:38,000 --> 00:08:43,000
+In this lesson, we learned how to set cookies, how to read cookies and spring.
+
+108
+00:08:43,000 --> 00:08:44,000
+And we see.
+
+109
+00:08:45,000 --> 00:08:52,000
+We also learned how to work with properties in spring, namely now, you know, such annotations as
+
+110
+00:08:52,000 --> 00:08:55,000
+properties, source and properties sources.
+
+111
+00:08:56,000 --> 00:09:00,000
+You saw how to inject values with the value annotation.
+
+112
+00:09:00,000 --> 00:09:01,000
+That's it.
+
+113
+00:09:01,000 --> 00:09:03,000
+Thanks a lot for your attention.
+
+114
+00:09:03,000 --> 00:09:07,000
+Have a great day and see you in the next lesson.
+
diff --git a/82 - Spring MVC & Spring for WEB/external-links.txt b/82 - Spring MVC & Spring for WEB/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..93005f47c880ea8b3f29aae023034a173d979915
--- /dev/null
+++ b/82 - Spring MVC & Spring for WEB/external-links.txt
@@ -0,0 +1,42 @@
+
+001 Java-Spring-MVC-source-code-examples-from-the-lesson-Repository
+https://github.com/AndriiPiatakha/java-learnit-spring-web
+
+001 Commit-with-the-changes-for-this-lesson
+https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/9473121ad8a02e27bbb26c423100a7ddf4dea060
+
+002 Source-code-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-spring-web/blob/master/src/main/java/com/itbulls/learnit/spring/controllers/ModelDemoController.java
+
+003 JSR-303-Bean-Validation
+https://jcp.org/en/jsr/detail?id=303
+
+003 Validation-constraints-annotations
+https://jakarta.ee/specifications/platform/9/apidocs/jakarta/validation/constraints/package-summary.html
+
+003 Source-code-examples-from-the-lesson-Models
+https://github.com/AndriiPiatakha/java-learnit-spring-web/tree/master/src/main/java/com/itbulls/learnit/spring/model
+
+003 Source-code-examples-from-the-lesson-UserController
+https://github.com/AndriiPiatakha/java-learnit-spring-web/blob/master/src/main/java/com/itbulls/learnit/spring/controllers/UserController.java
+
+004 Source-code-examples-from-the-lesson
+https://github.com/AndriiPiatakha/java-learnit-spring-web/tree/master/src/main/java/com/itbulls/learnit/spring/errors
+
+005 Source-code-of-examples-commit-with-changes-
+https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/efe19f3a7ff0774008b1d2db3cb30675686fb083
+
+006 Source-code-of-examples-commit-with-changes-
+https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/55e4399d80aafe4f4db45a719f111ac61bb3cf19
+
+007 Source-code-of-examples-commit-with-changes-
+https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/3087cf3027ac07c39becdbd031e36c01cf3fa0e2
+
+008 Source-code-of-examples-commit-with-changes-
+https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/4f5e51b45a9e8fdb2977269c9d1333fc3ae9ab69
+
+009 Source-code-of-examples-commit-with-changes-COOKIES
+https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/22b6853624b800f17f435d46780f057b569c0fd4
+
+009 Source-code-of-examples-commit-with-changes-PROPERTIES
+https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/483d9c3b2751193dfcf575478d20e8e214637149
diff --git a/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/001 EXAM Spring Core & Spring MVC_en.srt b/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/001 EXAM Spring Core & Spring MVC_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..817bc09f28b7acd7e8eed4f38b5cd2567e03037a
--- /dev/null
+++ b/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/001 EXAM Spring Core & Spring MVC_en.srt
@@ -0,0 +1,1852 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:11,000
+By this moment in our course, we have learned a lot about Spring Corps and Spring.
+
+3
+00:00:11,000 --> 00:00:15,000
+And we see now this time to practice your skills.
+
+4
+00:00:15,000 --> 00:00:22,000
+And I spent a lot of time in order to prepare for your special production related tasks.
+
+5
+00:00:22,000 --> 00:00:29,000
+Uses a whole course Java from zero to first job together with all my students who develop online shop
+
+6
+00:00:29,000 --> 00:00:31,000
+web application.
+
+7
+00:00:31,000 --> 00:00:37,000
+Usually, after learning each new topic, we apply our knowledge to improve our solution.
+
+8
+00:00:37,000 --> 00:00:44,000
+Today we are going to make the same scene in order to practice the skills and knowledge that we get
+
+9
+00:00:44,000 --> 00:00:52,000
+After learning Spring Corps and Spring and we see topics on the screen, you can see the task description.
+
+10
+00:00:52,000 --> 00:00:57,000
+You can find the reference to this document in attachments to the video.
+
+11
+00:00:57,000 --> 00:01:04,000
+Let me describe the task and explain to you what is expected from you during this task.
+
+12
+00:01:05,000 --> 00:01:14,000
+So the first thing that you have to do to a complete project of online shop that is completely working
+
+13
+00:01:14,000 --> 00:01:15,000
+Web application.
+
+14
+00:01:15,000 --> 00:01:19,000
+It just doesn't have spring integration yet.
+
+15
+00:01:20,000 --> 00:01:24,000
+We will take this solution and will improve it.
+
+16
+00:01:24,000 --> 00:01:31,000
+I believe that this is just a great task for all my students because when you refactor the code within
+
+17
+00:01:31,000 --> 00:01:38,000
+the service and you integrate spring core and spring and we see it is easier for you to build analogy
+
+18
+00:01:38,000 --> 00:01:46,000
+between servlet and spring and we see thus it is easier for you to understand how all these things work.
+
+19
+00:01:46,000 --> 00:01:53,000
+That's why I believe that this is just an amazing exercise for students after completing it using the
+
+20
+00:01:53,000 --> 00:01:59,000
+templates provided, I give you the guarantees that you would understand Spring Corps and Spring and
+
+21
+00:01:59,000 --> 00:02:02,000
+you see like never before.
+
+22
+00:02:02,000 --> 00:02:04,000
+Let's continue.
+
+23
+00:02:04,000 --> 00:02:08,000
+As you can see, this is Maimon Memorial project.
+
+24
+00:02:08,000 --> 00:02:11,000
+The second step is kind of generic one.
+
+25
+00:02:11,000 --> 00:02:17,000
+Just make sure that you can run the project and that it can be started easily.
+
+26
+00:02:17,000 --> 00:02:23,000
+Please follow the steps from the file in order to configure the database on your local environment.
+
+27
+00:02:24,000 --> 00:02:25,000
+The next step.
+
+28
+00:02:25,000 --> 00:02:28,000
+Understand how application works.
+
+29
+00:02:28,000 --> 00:02:36,000
+Navigate through the application on the stand and scenarios just in case I left here as a reference
+
+30
+00:02:36,000 --> 00:02:39,000
+to the business requirements for the application.
+
+31
+00:02:39,000 --> 00:02:41,000
+Feel free to read through them.
+
+32
+00:02:42,000 --> 00:02:48,000
+Knowing the way how our online shop should behave, it will be easier for you to understand what should
+
+33
+00:02:48,000 --> 00:02:51,000
+be fixed and how application should work.
+
+34
+00:02:51,000 --> 00:03:00,000
+After factoring and finally the poor piece of our exam task, we have to integrate spring or spring.
+
+35
+00:03:00,000 --> 00:03:06,000
+Can we see into this project what can be considered as integration of screen and screen?
+
+36
+00:03:06,000 --> 00:03:12,000
+We see we need to be specific in the definition of the success criteria so far.
+
+37
+00:03:12,000 --> 00:03:15,000
+This project uses silhouettes technology.
+
+38
+00:03:15,000 --> 00:03:21,000
+You need to make a revision of the project and make appropriate changes.
+
+39
+00:03:21,000 --> 00:03:24,000
+First of all, we need to define spring context.
+
+40
+00:03:24,000 --> 00:03:28,000
+It is up to you what type of configuration you would like to use.
+
+41
+00:03:28,000 --> 00:03:31,000
+Annotation based or XML based.
+
+42
+00:03:31,000 --> 00:03:38,000
+My course will use different types of configuration and you already understand that this is a matter
+
+43
+00:03:38,000 --> 00:03:41,000
+of style rather than some strict rules here.
+
+44
+00:03:41,000 --> 00:03:47,000
+One or another approach so describes a configuration.
+
+45
+00:03:47,000 --> 00:03:49,000
+Define the spring beans.
+
+46
+00:03:49,000 --> 00:03:57,000
+Configure other beans using dependency injection with regards to the screen can be see you have to configure
+
+47
+00:03:57,000 --> 00:03:58,000
+dispatch server.
+
+48
+00:03:59,000 --> 00:04:04,000
+Also view all the existence of lets and configure request mappings.
+
+49
+00:04:04,000 --> 00:04:08,000
+Feel free to refactor the code as you feel needed.
+
+50
+00:04:09,000 --> 00:04:15,000
+Take advantage of using the request forum and modal attribute integrate hibernate validation of model
+
+51
+00:04:15,000 --> 00:04:21,000
+attributes, integrate properties and use property source for the application.
+
+52
+00:04:21,000 --> 00:04:28,000
+Also, do not forget about implementation of the localization and internationalization.
+
+53
+00:04:28,000 --> 00:04:36,000
+The main success criteria is that application is still working as expected and all scenarios work.
+
+54
+00:04:36,000 --> 00:04:37,000
+End to end.
+
+55
+00:04:37,000 --> 00:04:42,000
+After you're done with integration of Sprint core and speed.
+
+56
+00:04:42,000 --> 00:04:42,000
+And we see.
+
+57
+00:04:43,000 --> 00:04:44,000
+Is that clear?
+
+58
+00:04:45,000 --> 00:04:48,000
+In case you have any questions regarding task.
+
+59
+00:04:48,000 --> 00:04:53,000
+Feel free to post your questions below this video and I will be happy to answer.
+
+60
+00:04:54,000 --> 00:05:01,000
+Now I recommend you to put on pause the video and try to implement the task by yourself.
+
+61
+00:05:02,000 --> 00:05:09,000
+Feel free to use examples from the previous lessons and remember in this task you don't leave any signals.
+
+62
+00:05:09,000 --> 00:05:12,000
+What we do them in previous lessons.
+
+63
+00:05:12,000 --> 00:05:18,000
+So the information and the knowledge you gained from the previous lessons should be enough in order
+
+64
+00:05:18,000 --> 00:05:20,000
+to complete this task.
+
+65
+00:05:21,000 --> 00:05:29,000
+Once you try to implement the solution, then proceed with this video because right now I'm going to
+
+66
+00:05:29,000 --> 00:05:35,000
+share with you my solution and give my comments as we go over it.
+
+67
+00:05:35,000 --> 00:05:42,000
+By the way, here you can find the reference to the repository with the solution and reference to the
+
+68
+00:05:42,000 --> 00:05:42,000
+commit.
+
+69
+00:05:43,000 --> 00:05:44,000
+It contains the difference.
+
+70
+00:05:45,000 --> 00:05:52,000
+Probably it would be interesting for you to go over the changes only and understand what has been changed
+
+71
+00:05:52,000 --> 00:05:54,000
+in competition within it.
+
+72
+00:05:54,000 --> 00:05:55,000
+Commit.
+
+73
+00:05:56,000 --> 00:06:01,000
+Let me now start sharing the source code and walk you through my solution.
+
+74
+00:06:01,000 --> 00:06:09,000
+So the first thing that I did, I adjusted for maximum file to include required dependencies.
+
+75
+00:06:09,000 --> 00:06:18,000
+We have maximal files on different levels because we have multi module project on the global level.
+
+76
+00:06:18,000 --> 00:06:27,000
+I added spring core spring beans and spring context dependencies in the form XML of persistence module.
+
+77
+00:06:27,000 --> 00:06:36,000
+I substituted Jakarta persistence API with Java x Persistence API because as you remember, in order
+
+78
+00:06:36,000 --> 00:06:42,000
+to use spring, we need to use Java API instead of Jakarta.
+
+79
+00:06:43,000 --> 00:06:48,000
+Please don't forget to update hibernate core version as well.
+
+80
+00:06:48,000 --> 00:06:52,000
+Again, you need to use compatible version with Xerox API.
+
+81
+00:06:53,000 --> 00:06:55,000
+The latest Hibernate core versions.
+
+82
+00:06:55,000 --> 00:07:02,000
+It is compatible with Java API is 5.6. 14 final.
+
+83
+00:07:02,000 --> 00:07:11,000
+Also, I added Hibernate validator dependency and inside the web module I added sprint and C dependency.
+
+84
+00:07:11,000 --> 00:07:18,000
+Also, I removed Jakarta API dependency and added Java servlet dependency stat.
+
+85
+00:07:18,000 --> 00:07:28,000
+I remove the Jakarta annotation API and edit Java annotation API instead and also I edit Java, GCP
+
+86
+00:07:28,000 --> 00:07:30,000
+API and Java servlet.
+
+87
+00:07:30,000 --> 00:07:32,000
+JSP dependencies.
+
+88
+00:07:33,000 --> 00:07:35,000
+Let's start now from the core module.
+
+89
+00:07:35,000 --> 00:07:38,000
+I open facades package.
+
+90
+00:07:38,000 --> 00:07:43,000
+I put service annotation above the each implementation of required facade.
+
+91
+00:07:44,000 --> 00:07:52,000
+Remember, you have to put annotation above the complete plus, but not above the interface because
+
+92
+00:07:52,000 --> 00:07:57,000
+spring needs some classes that will allow it to create object.
+
+93
+00:07:57,000 --> 00:08:01,000
+If you remember I implemented singleton component here.
+
+94
+00:08:02,000 --> 00:08:09,000
+And now we don't need it because we are going to have spring container who will manage lifecycle of
+
+95
+00:08:09,000 --> 00:08:10,000
+our builds.
+
+96
+00:08:11,000 --> 00:08:19,000
+That's why we can do small refactor here and remove all the code as it was responsible for single component
+
+97
+00:08:19,000 --> 00:08:20,000
+implementation.
+
+98
+00:08:21,000 --> 00:08:23,000
+When you will check the difference.
+
+99
+00:08:23,000 --> 00:08:23,000
+Indeed.
+
+100
+00:08:23,000 --> 00:08:31,000
+You will find that I removed static field private constructor and static method here that instantiate
+
+101
+00:08:31,000 --> 00:08:33,000
+an instance of this type.
+
+102
+00:08:34,000 --> 00:08:41,000
+Also I added out-of-order annotation in order to inject the beans into the properties in this class.
+
+103
+00:08:42,000 --> 00:08:49,000
+Since I am going to use spring, I don't use manually to instantiate objects, I need just to configure
+
+104
+00:08:49,000 --> 00:08:54,000
+the dependencies and let spring to manage all the required injections.
+
+105
+00:08:55,000 --> 00:09:00,000
+I did the similar refactoring in all other facade classes implementations.
+
+106
+00:09:01,000 --> 00:09:02,000
+Let's move on.
+
+107
+00:09:02,000 --> 00:09:07,000
+The same thing I did was the default mail sender.
+
+108
+00:09:07,000 --> 00:09:10,000
+I marked it with service annotation.
+
+109
+00:09:11,000 --> 00:09:15,000
+The next package in our list here is services annotation.
+
+110
+00:09:16,000 --> 00:09:24,000
+We need to do the similar exercise more classes with service annotation and configure dependency injection
+
+111
+00:09:24,000 --> 00:09:26,000
+where this will be needed.
+
+112
+00:09:27,000 --> 00:09:33,000
+Basically, those are all adjustments that we need to do in the core module.
+
+113
+00:09:33,000 --> 00:09:38,000
+Let's proceed with the persistence module in the persistence module.
+
+114
+00:09:38,000 --> 00:09:45,000
+We need to make the similar exercise, but instead of service annotation I'm going to put repository
+
+115
+00:09:45,000 --> 00:09:46,000
+annotation.
+
+116
+00:09:46,000 --> 00:09:54,000
+I will update all the implementations that I started with the GP because in scope of this exam we're
+
+117
+00:09:54,000 --> 00:09:56,000
+going to use GP for persistence.
+
+118
+00:09:56,000 --> 00:10:04,000
+Later, a little bit later in all the lessons, we're going to learn to speak data separately and we'll
+
+119
+00:10:04,000 --> 00:10:06,000
+update this too.
+
+120
+00:10:06,000 --> 00:10:12,000
+Also, we had my SQL JDBC implementations of our interfaces.
+
+121
+00:10:12,000 --> 00:10:17,000
+I decided to delete them in order to not keep the code that we don't use anymore.
+
+122
+00:10:18,000 --> 00:10:28,000
+The next released web DX tool package lets mark with the service annotations converters because we are
+
+123
+00:10:28,000 --> 00:10:34,000
+going to use them in our facades on the business level as you will go over these.
+
+124
+00:10:34,000 --> 00:10:37,000
+Pay attention to the dependency injection.
+
+125
+00:10:37,000 --> 00:10:41,000
+In some classes you need to configure dependency injection.
+
+126
+00:10:42,000 --> 00:10:45,000
+I did this with the help of auto annotation.
+
+127
+00:10:46,000 --> 00:10:53,000
+Actually the fuel you can keep without changes because they will be used for GP only.
+
+128
+00:10:54,000 --> 00:10:59,000
+And objects will be created using the object relational database mapping.
+
+129
+00:10:59,000 --> 00:11:01,000
+So I skip this.
+
+130
+00:11:02,000 --> 00:11:06,000
+The same story is with the entities classes here.
+
+131
+00:11:06,000 --> 00:11:13,000
+I removed package validation because we are going to implement validation with the hibernate data.
+
+132
+00:11:13,000 --> 00:11:22,000
+Now, in the previous solution we configure it validation for default user only a little bit later during
+
+133
+00:11:22,000 --> 00:11:23,000
+the solution review.
+
+134
+00:11:23,000 --> 00:11:27,000
+We are going to take a look at how I configured validation here.
+
+135
+00:11:28,000 --> 00:11:32,000
+I removed the beauteous glass because we don't use it anymore.
+
+136
+00:11:33,000 --> 00:11:38,000
+Also, I removed the BCP connection pool class because of the same reason.
+
+137
+00:11:38,000 --> 00:11:43,000
+Make sure that code is not used anymore before deleting it.
+
+138
+00:11:43,000 --> 00:11:51,000
+Just perform some search and investigation whether this class is used somewhere in the project.
+
+139
+00:11:51,000 --> 00:11:57,000
+In Eclipse, you can use search tools by pressing control and edge button simultaneously.
+
+140
+00:11:57,000 --> 00:12:03,000
+So after making sure that class is not used anywhere, you can delete it.
+
+141
+00:12:03,000 --> 00:12:08,000
+That's it was a persistence model and that's the important thing.
+
+142
+00:12:09,000 --> 00:12:18,000
+Considering Springworks with Java API and doesn't work with Jakarta API, we need to adjust input statements
+
+143
+00:12:18,000 --> 00:12:20,000
+across all different modules.
+
+144
+00:12:21,000 --> 00:12:26,000
+You can use eclipse search by pressing console and key simultaneously.
+
+145
+00:12:27,000 --> 00:12:32,000
+After that, try to search source java files for input space.
+
+146
+00:12:32,000 --> 00:12:37,000
+Jakarta point You can replace all things involved.
+
+147
+00:12:38,000 --> 00:12:40,000
+Just click replace here.
+
+148
+00:12:40,000 --> 00:12:47,000
+New window will pop up and you would need to specify with what you would like to substitute.
+
+149
+00:12:47,000 --> 00:12:52,000
+Adjust everything from Jakarta import to Java import.
+
+150
+00:12:53,000 --> 00:12:54,000
+I already did that.
+
+151
+00:12:55,000 --> 00:13:02,000
+That's why I can search for input box point in order to show the navigation is eclipse.
+
+152
+00:13:02,000 --> 00:13:13,000
+Basically, here you need to specify old value and here to specify the new value and click replace button.
+
+153
+00:13:13,000 --> 00:13:14,000
+That's it.
+
+154
+00:13:15,000 --> 00:13:23,000
+After changing the inputs, you're going to have compilation errors in all GP dot classes because we
+
+155
+00:13:23,000 --> 00:13:31,000
+used try with the resource block for entity manager factory and entity manager, which is okay for Jakarta
+
+156
+00:13:31,000 --> 00:13:40,000
+API but which is not okay for Java Persistence API because back then all the possible interface hasn't
+
+157
+00:13:40,000 --> 00:13:45,000
+been implemented yet in entity manager factor and in entity.
+
+158
+00:13:45,000 --> 00:13:53,000
+Managing these minor API differences is that we should be aware of and be ready to fix when it will
+
+159
+00:13:53,000 --> 00:13:54,000
+be necessary.
+
+160
+00:13:55,000 --> 00:13:59,000
+Like for example, in such case I open GP category.
+
+161
+00:14:00,000 --> 00:14:03,000
+I didn't so much changes here.
+
+162
+00:14:03,000 --> 00:14:09,000
+Basically I just substituted trial resources block with try final block.
+
+163
+00:14:10,000 --> 00:14:15,000
+Yes, it is a little bit more lines of code, but it is what it is.
+
+164
+00:14:15,000 --> 00:14:18,000
+Still, we achieve the same result.
+
+165
+00:14:18,000 --> 00:14:24,000
+And I close entity manager, factory and entity manager is a final block.
+
+166
+00:14:25,000 --> 00:14:31,000
+After factoring all these, you should get rid of the compilation errors and you can proceed.
+
+167
+00:14:31,000 --> 00:14:39,000
+And now the things that we shouldn't forget to update is persistence XML configuration in the persistence
+
+168
+00:14:39,000 --> 00:14:39,000
+module.
+
+169
+00:14:40,000 --> 00:14:44,000
+Just to remind you that we don't use Jakarta with spring.
+
+170
+00:14:44,000 --> 00:14:51,000
+That's why we need to adjust this file to and configure it with Java API.
+
+171
+00:14:51,000 --> 00:14:57,000
+I did this by substituting Jakarta word with Java here and that's it.
+
+172
+00:14:58,000 --> 00:15:03,000
+Also taking into account we changed the version of the hybrid core.
+
+173
+00:15:03,000 --> 00:15:11,000
+We also need to change the dialect, otherwise we are going to get different strange errors.
+
+174
+00:15:11,000 --> 00:15:14,000
+And one more important things that I did here.
+
+175
+00:15:14,000 --> 00:15:17,000
+Also, it is related with the version we used.
+
+176
+00:15:18,000 --> 00:15:26,000
+The reason error in case index will be created on the fields that are longer than 1000 bytes.
+
+177
+00:15:26,000 --> 00:15:34,000
+This error tells us that there is no sense to create index on such long fields because you wouldn't
+
+178
+00:15:34,000 --> 00:15:36,000
+be able to benefit from that.
+
+179
+00:15:37,000 --> 00:15:40,000
+You might be wondering and where we created indices.
+
+180
+00:15:41,000 --> 00:15:43,000
+Let me open the user data across.
+
+181
+00:15:43,000 --> 00:15:52,000
+In this class you can find that we use unique constraints on the email and on the partner code fields.
+
+182
+00:15:52,000 --> 00:16:00,000
+Let's specify length field for these columns in order to avoid error with very long indices.
+
+183
+00:16:00,000 --> 00:16:05,000
+I believe that's it with regards to the persistence module.
+
+184
+00:16:05,000 --> 00:16:08,000
+Now it is time to look at the Web model.
+
+185
+00:16:09,000 --> 00:16:16,000
+Let's look through the whole controllers category server that can be renamed to the category controller.
+
+186
+00:16:17,000 --> 00:16:23,000
+Product facade should be injected with the help of dependency injection tools of spring.
+
+187
+00:16:24,000 --> 00:16:33,000
+Also, lets add controller annotation and remove web servlet annotation and add request mapping or get
+
+188
+00:16:33,000 --> 00:16:35,000
+mapping annotation for the master.
+
+189
+00:16:36,000 --> 00:16:42,000
+If you follow my course, then you already know the difference between these two jobs.
+
+190
+00:16:43,000 --> 00:16:50,000
+We'll keep the same euro as it was before, but instead of keeping it with the web server, annotation
+
+191
+00:16:50,000 --> 00:16:58,000
+will pass it to the request modeling annotation or get mapping annotation or post mapping quotation
+
+192
+00:16:58,000 --> 00:17:00,000
+depending on each case.
+
+193
+00:17:01,000 --> 00:17:09,000
+Also, since this is not a server anymore, we can remove extends http server red and leave it like
+
+194
+00:17:09,000 --> 00:17:09,000
+this.
+
+195
+00:17:10,000 --> 00:17:13,000
+Let's make the similar changes in all servers.
+
+196
+00:17:14,000 --> 00:17:20,000
+When I worked on this I recommended to not refactor the whole scenes at once.
+
+197
+00:17:20,000 --> 00:17:27,000
+Just try to channel your service into the controllers and apply so can see configuration.
+
+198
+00:17:28,000 --> 00:17:32,000
+The rest of the code you will refactor after that.
+
+199
+00:17:32,000 --> 00:17:37,000
+Because the most challenging would be to build and run your application.
+
+200
+00:17:37,000 --> 00:17:41,000
+Once you will be sure that your application is built.
+
+201
+00:17:41,000 --> 00:17:46,000
+You can continue with massive refactoring to use all the features of Sprint.
+
+202
+00:17:46,000 --> 00:17:49,000
+And we see we'll get this soon.
+
+203
+00:17:50,000 --> 00:17:56,000
+Right now I just want to click through each server and show you that in each server.
+
+204
+00:17:56,000 --> 00:18:04,000
+I did the following things changed the class name to highlight the controller status, removed extents,
+
+205
+00:18:04,000 --> 00:18:13,000
+http server removed web server annotation, added request mapping annotation configured dependency injection
+
+206
+00:18:13,000 --> 00:18:14,000
+where it was needed.
+
+207
+00:18:15,000 --> 00:18:19,000
+The next thing in our list here are web filters.
+
+208
+00:18:19,000 --> 00:18:26,000
+You don't have to do a lot of things because spring be has special support for scanning classes annotated
+
+209
+00:18:26,000 --> 00:18:28,000
+with web filter annotations.
+
+210
+00:18:29,000 --> 00:18:36,000
+The only things that we have to change is that in previous solution we extended our classes from the
+
+211
+00:18:36,000 --> 00:18:39,000
+HTP filter from the Jakarta API.
+
+212
+00:18:39,000 --> 00:18:46,000
+But since we don't use Jakarta API anymore, we need to implement filter interface here.
+
+213
+00:18:47,000 --> 00:18:52,000
+Filter interface makes us to implement init and destroy methods.
+
+214
+00:18:53,000 --> 00:18:56,000
+You shouldn't be bothered about this too much.
+
+215
+00:18:56,000 --> 00:18:59,000
+We don't have any business necessity to implement them.
+
+216
+00:18:59,000 --> 00:19:05,000
+Just leave them as this take into account that we don't have servants anymore.
+
+217
+00:19:05,000 --> 00:19:13,000
+Let's change mappings of management filter from server names to the URL mappings.
+
+218
+00:19:13,000 --> 00:19:21,000
+Previously in the template solution we specified here server names to trigger filter only for those
+
+219
+00:19:21,000 --> 00:19:22,000
+servers.
+
+220
+00:19:22,000 --> 00:19:29,000
+But now we changed this attribute to specify resource mapping of zero related controllers.
+
+221
+00:19:30,000 --> 00:19:33,000
+This is purchase and fulfillment controller.
+
+222
+00:19:34,000 --> 00:19:35,000
+Okay.
+
+223
+00:19:35,000 --> 00:19:36,000
+We're good with filters.
+
+224
+00:19:36,000 --> 00:19:37,000
+Let's move on.
+
+225
+00:19:38,000 --> 00:19:46,000
+We had that package before, but I investigated it and realized that we don't use code from there anymore.
+
+226
+00:19:47,000 --> 00:19:48,000
+That's why I removed it.
+
+227
+00:19:49,000 --> 00:19:50,000
+By the way.
+
+228
+00:19:50,000 --> 00:19:52,000
+Make a note about this, too.
+
+229
+00:19:52,000 --> 00:19:57,000
+Always challenge yourself whether some code is still used.
+
+230
+00:19:57,000 --> 00:20:03,000
+Now we have relatively not huge, but also not small application here.
+
+231
+00:20:03,000 --> 00:20:08,000
+And you can see that it can happen that we forget to remove some code.
+
+232
+00:20:08,000 --> 00:20:14,000
+That's why always ask yourself what zip code is still in use now.
+
+233
+00:20:15,000 --> 00:20:18,000
+And in case it is not used, remove it.
+
+234
+00:20:19,000 --> 00:20:23,000
+But be 1,000% sure that it is not used.
+
+235
+00:20:24,000 --> 00:20:27,000
+The next package here is utils.
+
+236
+00:20:27,000 --> 00:20:35,000
+In utils we have just one class and this is encryption service that we use in different scenarios,
+
+237
+00:20:35,000 --> 00:20:39,000
+like for example, user registration and logging.
+
+238
+00:20:40,000 --> 00:20:48,000
+I market with the service annotation and I already configure dependency injection in all places where
+
+239
+00:20:48,000 --> 00:20:48,000
+it is used.
+
+240
+00:20:49,000 --> 00:20:57,000
+Now let's configure that and we see configuration and web application in action.
+
+241
+00:20:57,000 --> 00:21:04,000
+If you followed the course attentively, you can just copy and paste configurations that we created
+
+242
+00:21:04,000 --> 00:21:07,000
+together with you during our lessons.
+
+243
+00:21:07,000 --> 00:21:10,000
+Here is my main web app initialization.
+
+244
+00:21:10,000 --> 00:21:19,000
+We already reviewed each line of code from this class when we created it the first time I configure
+
+245
+00:21:19,000 --> 00:21:21,000
+my dispatcher servlet here.
+
+246
+00:21:21,000 --> 00:21:27,000
+And here is web config that implements web MVC configure.
+
+247
+00:21:27,000 --> 00:21:34,000
+We reviewed a lot of lines of code from this file, and during this video I will highlight the scenes
+
+248
+00:21:34,000 --> 00:21:36,000
+that I added here.
+
+249
+00:21:36,000 --> 00:21:43,000
+I want to highlight the configuration of resource handlers because in the web project we already had
+
+250
+00:21:43,000 --> 00:21:48,000
+some web resources and we will not move them to different folders.
+
+251
+00:21:48,000 --> 00:21:55,000
+We just need to tell Sprint and we see how to map resources properly inside our application.
+
+252
+00:21:55,000 --> 00:22:00,000
+Taking into account I implements web and DC configure.
+
+253
+00:22:00,000 --> 00:22:07,000
+I just need to override add resource and this massive it takes resource handler registry.
+
+254
+00:22:08,000 --> 00:22:16,000
+I post strings to which requests from our view layers are sent in to add the resource handler message
+
+255
+00:22:16,000 --> 00:22:19,000
+and in the add resource locations.
+
+256
+00:22:19,000 --> 00:22:25,000
+I added the name of the folder house called in my web resources.
+
+257
+00:22:26,000 --> 00:22:27,000
+Is that clear?
+
+258
+00:22:28,000 --> 00:22:32,000
+So these are just few lines of code, but important ones.
+
+259
+00:22:33,000 --> 00:22:34,000
+Congratulations.
+
+260
+00:22:34,000 --> 00:22:36,000
+We have done a lot of refactoring since.
+
+261
+00:22:36,000 --> 00:22:41,000
+Already we try to make similar updates and updates involved.
+
+262
+00:22:41,000 --> 00:22:47,000
+Now let's get deeper into the details and review specific parts of the implementation.
+
+263
+00:22:48,000 --> 00:22:55,000
+Let's learn how we can approach the question of localization and internationalization in Sprint.
+
+264
+00:22:55,000 --> 00:23:03,000
+And we see because if you already know this in template application, based on the seven we used resource
+
+265
+00:23:03,000 --> 00:23:12,000
+bundles, we add separate services which is local and we have special tags on the GCP page to print
+
+266
+00:23:12,000 --> 00:23:14,000
+localized message.
+
+267
+00:23:14,000 --> 00:23:18,000
+How we can address the same challenge is a sprint and we see.
+
+268
+00:23:19,000 --> 00:23:25,000
+First of all, I removed change because we don't need it anymore.
+
+269
+00:23:26,000 --> 00:23:30,000
+The next thing that I did, I declared few beans.
+
+270
+00:23:30,000 --> 00:23:30,000
+Here.
+
+271
+00:23:30,000 --> 00:23:31,000
+Let me show you.
+
+272
+00:23:32,000 --> 00:23:35,000
+I open close this code web config.
+
+273
+00:23:35,000 --> 00:23:39,000
+I declare bean of message source.
+
+274
+00:23:39,000 --> 00:23:43,000
+I create object of reward resource bundle.
+
+275
+00:23:43,000 --> 00:23:44,000
+Message source.
+
+276
+00:23:44,000 --> 00:23:53,000
+This implementation will update resource messages in case it will be updated without reloading the server.
+
+277
+00:23:53,000 --> 00:24:00,000
+If you would start explore the Iraq of message source interface, you're going to see that there are
+
+278
+00:24:00,000 --> 00:24:04,000
+huge variety of OSR interfaces and classes.
+
+279
+00:24:05,000 --> 00:24:10,000
+Feel free to explore this Iraq deeper by reading the official documentation.
+
+280
+00:24:11,000 --> 00:24:16,000
+In case I would tell the hosting documentation, we wouldn't have enough time.
+
+281
+00:24:17,000 --> 00:24:20,000
+Of the creation of the object of message source.
+
+282
+00:24:20,000 --> 00:24:22,000
+We configure base name.
+
+283
+00:24:23,000 --> 00:24:27,000
+If you remember since about localization and internationalization.
+
+284
+00:24:28,000 --> 00:24:35,000
+The base name is the basis name of our source bundles without language and country code.
+
+285
+00:24:35,000 --> 00:24:42,000
+In our particular case, the base name is Online Shop Resource Bundle.
+
+286
+00:24:43,000 --> 00:24:50,000
+I can add plus more brackets here in order to tell spring that my resource bundles are located in the
+
+287
+00:24:50,000 --> 00:24:52,000
+class pass of the project.
+
+288
+00:24:52,000 --> 00:24:59,000
+I also set default encoding to UTF eight in order to support most of the Unicode characters.
+
+289
+00:25:00,000 --> 00:25:03,000
+Additionally, we need to declare a local resolver.
+
+290
+00:25:03,000 --> 00:25:08,000
+Being set helps to identify which locale is being used.
+
+291
+00:25:09,000 --> 00:25:13,000
+There are such popular concrete implementations of local resolver.
+
+292
+00:25:14,000 --> 00:25:23,000
+Accept how the local resolver uses a primary locale specified in SAP plan which had.
+
+293
+00:25:23,000 --> 00:25:24,000
+Of the HTP request.
+
+294
+00:25:25,000 --> 00:25:26,000
+Six.
+
+295
+00:25:26,000 --> 00:25:34,000
+The local resolver always return a fixed default, local and optionally time zone session.
+
+296
+00:25:34,000 --> 00:25:43,000
+Local resolver uses a local attribute in the user session with a fallback to the specified default locale
+
+297
+00:25:43,000 --> 00:25:44,000
+of the request.
+
+298
+00:25:44,000 --> 00:25:53,000
+Accept how the local local resolver persists a custom, local and or time zone information.
+
+299
+00:25:53,000 --> 00:25:59,000
+As a browser cookie, you're welcome to use any implementations that you wish.
+
+300
+00:26:00,000 --> 00:26:06,000
+I decided to use local resolver and also we need to add interceptor.
+
+301
+00:26:07,000 --> 00:26:15,000
+We need to register a local change interceptor to allow specify the desired local on average request.
+
+302
+00:26:15,000 --> 00:26:23,000
+You can see that I create object of local change interceptor and specify the name of the request parameter
+
+303
+00:26:23,000 --> 00:26:25,000
+that will be used to specify the language.
+
+304
+00:26:26,000 --> 00:26:33,000
+Pay attention that I override the mask that exists to register all possible interceptors.
+
+305
+00:26:33,000 --> 00:26:37,000
+We get interceptor register here as my set argument.
+
+306
+00:26:38,000 --> 00:26:41,000
+I use it to add my interceptor.
+
+307
+00:26:41,000 --> 00:26:42,000
+Okay.
+
+308
+00:26:42,000 --> 00:26:48,000
+Now we're good and required all required builds to support localization.
+
+309
+00:26:49,000 --> 00:26:54,000
+The next thing that we have to do is to make proper changes on the view level.
+
+310
+00:26:54,000 --> 00:27:00,000
+In the project template, we use the localization only in the header element.
+
+311
+00:27:00,000 --> 00:27:07,000
+As example, while I'm totally okay to implement localization and internationalization support across
+
+312
+00:27:07,000 --> 00:27:11,000
+the whole application, this approach would be the same.
+
+313
+00:27:12,000 --> 00:27:15,000
+That's why I would show you only other example.
+
+314
+00:27:16,000 --> 00:27:23,000
+Let me open the header file in the header with language switch that changes language.
+
+315
+00:27:24,000 --> 00:27:29,000
+So the first thing that we need to add here is to add spring tags.
+
+316
+00:27:29,000 --> 00:27:34,000
+You can see here on top tag directive for spring tags.
+
+317
+00:27:35,000 --> 00:27:38,000
+It goes with Spirit and we see library.
+
+318
+00:27:38,000 --> 00:27:41,000
+So if you add a sprinkle, you see in the Maven X.
+
+319
+00:27:42,000 --> 00:27:45,000
+You don't have to add any other dependencies.
+
+320
+00:27:46,000 --> 00:27:53,000
+Now, the only thing that remains to do is to use Sprint message tag and pause the name of the message
+
+321
+00:27:53,000 --> 00:27:55,000
+that we want to use.
+
+322
+00:27:55,000 --> 00:27:57,000
+Everything is super simple.
+
+323
+00:27:57,000 --> 00:28:04,000
+You don't need to be bothered about uploading resource bundles into the file, declaring variables of
+
+324
+00:28:04,000 --> 00:28:05,000
+resource bundles.
+
+325
+00:28:05,000 --> 00:28:08,000
+The rest sprint will handle by itself.
+
+326
+00:28:09,000 --> 00:28:15,000
+And to actually handle change of locale, we need to send a request with the LAN parameter.
+
+327
+00:28:16,000 --> 00:28:24,000
+Do remember we have just configured interceptor, so we have to use the same parameter that we specified
+
+328
+00:28:24,000 --> 00:28:25,000
+in the intercept.
+
+329
+00:28:26,000 --> 00:28:30,000
+Here you can see that the use links with length parameters.
+
+330
+00:28:31,000 --> 00:28:35,000
+Basically when the link is clicked, request is sent.
+
+331
+00:28:35,000 --> 00:28:43,000
+Sprint intercept request verifies the value of request parameter changes local inside the context and
+
+332
+00:28:43,000 --> 00:28:47,000
+reload all the localized resources on the page.
+
+333
+00:28:48,000 --> 00:28:49,000
+Is that clear?
+
+334
+00:28:49,000 --> 00:28:55,000
+If you noticed, we also used resource bundles inside the classes.
+
+335
+00:28:55,000 --> 00:29:03,000
+For example, we use resource bundles in the edit profile controller, checkout controller and in the
+
+336
+00:29:03,000 --> 00:29:08,000
+sign up controller instead of the object of resource bundle.
+
+337
+00:29:08,000 --> 00:29:10,000
+We have message source now.
+
+338
+00:29:11,000 --> 00:29:17,000
+So in these classes you can configure the dependency injection of the message source Bing.
+
+339
+00:29:18,000 --> 00:29:20,000
+It has slightly different API.
+
+340
+00:29:20,000 --> 00:29:24,000
+It doesn't have gets to method like resource bundle type does it?
+
+341
+00:29:24,000 --> 00:29:26,000
+Does get message message.
+
+342
+00:29:27,000 --> 00:29:30,000
+I'm going to use get message method with three arguments.
+
+343
+00:29:31,000 --> 00:29:35,000
+The first parameter is our message code from our source bundle.
+
+344
+00:29:35,000 --> 00:29:37,000
+The key of the message.
+
+345
+00:29:38,000 --> 00:29:44,000
+The second parameter is array of arguments that we will use to inject into the messages.
+
+346
+00:29:44,000 --> 00:29:47,000
+And the third parameter is local.
+
+347
+00:29:47,000 --> 00:29:51,000
+Taking the account Spring changes local.
+
+348
+00:29:51,000 --> 00:29:58,000
+We'll just use massive default from local class because it returns the current local.
+
+349
+00:29:58,000 --> 00:30:05,000
+Is it clear to even in case you have any questions, please do not hesitate to ask questions below the
+
+350
+00:30:05,000 --> 00:30:08,000
+video and I will be happy to answer.
+
+351
+00:30:09,000 --> 00:30:12,000
+The next thing that we have to configure is exception handling.
+
+352
+00:30:13,000 --> 00:30:15,000
+You already saw the lesson about exception handling.
+
+353
+00:30:16,000 --> 00:30:19,000
+That's why there will be nothing new for you.
+
+354
+00:30:20,000 --> 00:30:25,000
+This web config class will declare the handler exception resolver.
+
+355
+00:30:25,000 --> 00:30:33,000
+So this one supposed to handle all exceptions without handlers and forwards in request is an error page.
+
+356
+00:30:33,000 --> 00:30:36,000
+I added this JSP to this.
+
+357
+00:30:36,000 --> 00:30:39,000
+This is from our lesson about exception handling.
+
+358
+00:30:39,000 --> 00:30:40,000
+And this.
+
+359
+00:30:40,000 --> 00:30:40,000
+Can we see.
+
+360
+00:30:41,000 --> 00:30:51,000
+His main position was, I said, strong exception if no ever found property in our dispatch server to
+
+361
+00:30:51,000 --> 00:30:51,000
+true.
+
+362
+00:30:52,000 --> 00:30:57,000
+And also I declare the error controller advisor in the exception package.
+
+363
+00:30:58,000 --> 00:31:03,000
+It handles our not found exceptions and for that request is not found.
+
+364
+00:31:03,000 --> 00:31:04,000
+JSP page.
+
+365
+00:31:05,000 --> 00:31:06,000
+That's it.
+
+366
+00:31:06,000 --> 00:31:14,000
+With regards to exceptions, it is also can be considered as a good thing to refactor exists in masses
+
+367
+00:31:14,000 --> 00:31:21,000
+in controllers that will work with HTTP server request and h to be server response.
+
+368
+00:31:21,000 --> 00:31:22,000
+No doubt.
+
+369
+00:31:23,000 --> 00:31:30,000
+But we end the process of and we see integration in order to take advantage of using it in our code.
+
+370
+00:31:30,000 --> 00:31:38,000
+I'm talking about not extracting request parameters from the server request with a separate method calls
+
+371
+00:31:38,000 --> 00:31:43,000
+not perform mapping between the form and the entity manually.
+
+372
+00:31:43,000 --> 00:31:45,000
+Let's use spring for all these routine.
+
+373
+00:31:47,000 --> 00:31:53,000
+Also, we'll get rid of request forwarding through the dispatcher servlet like we did before.
+
+374
+00:31:53,000 --> 00:31:58,000
+Let's review each controller one by one and make appropriate changes.
+
+375
+00:31:58,000 --> 00:32:01,000
+We start from the category controller.
+
+376
+00:32:02,000 --> 00:32:09,000
+I added a few request parameters here instead of extracting them from the request object, I injected
+
+377
+00:32:09,000 --> 00:32:18,000
+model and I returned street value of the view where for the request to in checkout controller and in
+
+378
+00:32:18,000 --> 00:32:22,000
+some other places pay extra attention is redirect.
+
+379
+00:32:22,000 --> 00:32:30,000
+You know that there can be different reasons for redirecting request instead of the forwarding request
+
+380
+00:32:30,000 --> 00:32:31,000
+ignores the view.
+
+381
+00:32:31,000 --> 00:32:37,000
+In this particular case, according to our business logic, we would like to make redirect after the
+
+382
+00:32:37,000 --> 00:32:42,000
+checkout the different ways about how to make redirects.
+
+383
+00:32:42,000 --> 00:32:49,000
+But in my opinion, the simplest one is to use redirect graphics before the union.
+
+384
+00:32:50,000 --> 00:32:50,000
+That's it.
+
+385
+00:32:51,000 --> 00:32:58,000
+Walks through the controllers attentively and refactor all the masses attentively, just in case.
+
+386
+00:32:58,000 --> 00:33:07,000
+You can always look at my solution, taking into account the changes as similar in all classes, I wouldn't
+
+387
+00:33:07,000 --> 00:33:11,000
+stop on each controller, just try to make changes.
+
+388
+00:33:11,000 --> 00:33:17,000
+By analogy, there is sign up controller that also requires updates.
+
+389
+00:33:17,000 --> 00:33:25,000
+In the related view, I recommend here to implement smooth forms, use model attributes, feature and
+
+390
+00:33:25,000 --> 00:33:27,000
+validation feature.
+
+391
+00:33:27,000 --> 00:33:35,000
+Let me show it to you In the get method, I put the object of the user into the model and therefore
+
+392
+00:33:35,000 --> 00:33:36,000
+to request a view.
+
+393
+00:33:37,000 --> 00:33:38,000
+Let me open now.
+
+394
+00:33:38,000 --> 00:33:40,000
+Sign up JSP page.
+
+395
+00:33:41,000 --> 00:33:42,000
+On top of the page.
+
+396
+00:33:42,000 --> 00:33:46,000
+You can see that I used spring forms directly.
+
+397
+00:33:47,000 --> 00:33:50,000
+It also goes with the Spring MVC library.
+
+398
+00:33:50,000 --> 00:33:56,000
+After that I change each HTML tag form with spring form tag.
+
+399
+00:33:57,000 --> 00:34:00,000
+I add modal attribute to the form.
+
+400
+00:34:00,000 --> 00:34:09,000
+I substitute all HTML input tags with spring form input dates and the specifies the POS attribute instead
+
+401
+00:34:09,000 --> 00:34:12,000
+of the name in order to set the values.
+
+402
+00:34:12,000 --> 00:34:20,000
+It is a model object that tensions and previously with POS repeat passwords as a separate argument.
+
+403
+00:34:20,000 --> 00:34:28,000
+And now, since we have binding all form parameters with the object, we need to add one more field
+
+404
+00:34:28,000 --> 00:34:35,000
+for a password into the default user object and also getters and status free.
+
+405
+00:34:36,000 --> 00:34:37,000
+Okay.
+
+406
+00:34:37,000 --> 00:34:43,000
+After submitting this form, we can extract the user object in the sign up controller with the model
+
+407
+00:34:43,000 --> 00:34:44,000
+attribute annotation.
+
+408
+00:34:45,000 --> 00:34:52,000
+You can see that I also added bind binding result object that goes right after our model for the model
+
+409
+00:34:52,000 --> 00:34:53,000
+validation.
+
+410
+00:34:53,000 --> 00:35:02,000
+I edit valid annotation to validate the model attribute and inside the default user class, I also configured
+
+411
+00:35:02,000 --> 00:35:03,000
+validation rules.
+
+412
+00:35:04,000 --> 00:35:12,000
+I added validation rules for the first name, last name and email and in case binding results have errors,
+
+413
+00:35:12,000 --> 00:35:15,000
+referred user back to the signup page.
+
+414
+00:35:15,000 --> 00:35:19,000
+If no, then we continue our business logic here.
+
+415
+00:35:19,000 --> 00:35:25,000
+And the next thing that we have to do is to verify the proof key with the partner code to implement
+
+416
+00:35:25,000 --> 00:35:27,000
+our referral program.
+
+417
+00:35:28,000 --> 00:35:35,000
+The next thing that we do here is extract the value from the key in case there is any partner code in
+
+418
+00:35:35,000 --> 00:35:35,000
+it.
+
+419
+00:35:36,000 --> 00:35:43,000
+We will speak MVC instead of iterating over all cookies until we find the right one with the name that
+
+420
+00:35:43,000 --> 00:35:43,000
+we need.
+
+421
+00:35:44,000 --> 00:35:50,000
+I just use quick value annotation and pass it in the mass parameters.
+
+422
+00:35:50,000 --> 00:35:54,000
+I specify the name of the cookie and the default value.
+
+423
+00:35:55,000 --> 00:35:58,000
+Pay attention in case there will not be a cookie.
+
+424
+00:35:59,000 --> 00:36:01,000
+Then spring will throw an exception.
+
+425
+00:36:02,000 --> 00:36:10,000
+That's why it is important to set default value in order to avoid exception and using this cookie value.
+
+426
+00:36:10,000 --> 00:36:12,000
+I work with it in the code.
+
+427
+00:36:13,000 --> 00:36:19,000
+And the last but not the least thing taking into account we use spring court now.
+
+428
+00:36:19,000 --> 00:36:24,000
+There is no need for us to store configurations in the constants.
+
+429
+00:36:24,000 --> 00:36:31,000
+Let's keep all application related properties outside of our code in the separate properties file.
+
+430
+00:36:31,000 --> 00:36:35,000
+Let me show you how easily we can configure this.
+
+431
+00:36:35,000 --> 00:36:39,000
+I added properties file in my resource folder.
+
+432
+00:36:39,000 --> 00:36:46,000
+Basically, what I did here, I just moved all the properties from the configurations interface to the
+
+433
+00:36:46,000 --> 00:36:48,000
+properties file.
+
+434
+00:36:48,000 --> 00:36:57,000
+The next thing I did, I verified where I have completion error and then I injected the required property
+
+435
+00:36:57,000 --> 00:36:58,000
+values there.
+
+436
+00:36:59,000 --> 00:37:01,000
+Let me show you one example.
+
+437
+00:37:01,000 --> 00:37:04,000
+For example, I open search controller.
+
+438
+00:37:05,000 --> 00:37:12,000
+Previously I used here pagination limit constant value from the configurations interface in order to
+
+439
+00:37:12,000 --> 00:37:17,000
+tell my facade how many records I expect to get on the page.
+
+440
+00:37:17,000 --> 00:37:24,000
+And now, instead of using the constant from the configurations interface, I inject the property from
+
+441
+00:37:24,000 --> 00:37:26,000
+the properties file.
+
+442
+00:37:26,000 --> 00:37:31,000
+I inject it using value annotation and string expression language.
+
+443
+00:37:31,000 --> 00:37:38,000
+But in order to use properties like this from the properties file, you need to register property file
+
+444
+00:37:38,000 --> 00:37:39,000
+in the spring.
+
+445
+00:37:40,000 --> 00:37:43,000
+I open web config class.
+
+446
+00:37:43,000 --> 00:37:46,000
+I use this class as a configuration.
+
+447
+00:37:46,000 --> 00:37:53,000
+And you can see that I added here another annotation that is called Properties source and I post app
+
+448
+00:37:53,000 --> 00:37:55,000
+properties value there.
+
+449
+00:37:56,000 --> 00:37:57,000
+So that's it.
+
+450
+00:37:57,000 --> 00:38:02,000
+Now we can say that we are ready to use properties in our application.
+
+451
+00:38:03,000 --> 00:38:06,000
+Basically that all changes that they did.
+
+452
+00:38:07,000 --> 00:38:10,000
+Compare your solution with my solution.
+
+453
+00:38:10,000 --> 00:38:16,000
+Ask your questions below the video and verify end to end behavior of the application.
+
+454
+00:38:17,000 --> 00:38:23,000
+Remember, you have the reference to all the requirements in order to verify all behavior.
+
+455
+00:38:23,000 --> 00:38:32,000
+And then I'm sure that this exercise helps you a lot in getting practical skills of work with this framework.
+
+456
+00:38:32,000 --> 00:38:35,000
+This task is really comprehensive.
+
+457
+00:38:35,000 --> 00:38:39,000
+Now we integrate the Sprint core and sprint and we see.
+
+458
+00:38:39,000 --> 00:38:41,000
+But we are not done yet.
+
+459
+00:38:41,000 --> 00:38:44,000
+We have a lot of lessons ahead.
+
+460
+00:38:44,000 --> 00:38:45,000
+So stay tuned.
+
+461
+00:38:46,000 --> 00:38:53,000
+We are going to improve this online shop with implementation of other cool features from this framework.
+
+462
+00:38:53,000 --> 00:38:55,000
+Thanks a lot for your attention.
+
+463
+00:38:55,000 --> 00:38:58,000
+Have a great day and see you in the next lesson.
+
diff --git a/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/001 Task-description-reference-to-the-solution-and-the-source-code.url b/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/001 Task-description-reference-to-the-solution-and-the-source-code.url
new file mode 100644
index 0000000000000000000000000000000000000000..36a0ac1dfbf37db80b5aa95b0b4f2b31a814dc7e
--- /dev/null
+++ b/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/001 Task-description-reference-to-the-solution-and-the-source-code.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://docs.google.com/document/d/1sCd2OpRMFyeTZzkZ_mDPQFvtECu8pLqFm3lPJW9lf_U/edit?usp=sharing
\ No newline at end of file
diff --git a/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/external-links.txt b/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/external-links.txt
new file mode 100644
index 0000000000000000000000000000000000000000..56f9cfd06bf796c4c710653de22b6de10bca9ae6
--- /dev/null
+++ b/83 - ===== EXAM Spring Core & Spring MVC - Online Shop =====/external-links.txt
@@ -0,0 +1,3 @@
+
+001 Task-description-reference-to-the-solution-and-the-source-code
+https://docs.google.com/document/d/1sCd2OpRMFyeTZzkZ_mDPQFvtECu8pLqFm3lPJW9lf_U/edit?usp=sharing
diff --git a/84 - Spring Security/001 Spring Security Introduction_en.srt b/84 - Spring Security/001 Spring Security Introduction_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..67cc622fe44534cf6a5ded44a2d72a2d739db958
--- /dev/null
+++ b/84 - Spring Security/001 Spring Security Introduction_en.srt
@@ -0,0 +1,792 @@
+1
+00:00:06,000 --> 00:00:13,000
+Hello team with this video will start new important and interesting topic spring security take into
+
+2
+00:00:13,000 --> 00:00:14,000
+account.
+
+3
+00:00:14,000 --> 00:00:16,000
+This is the first lesson in the topic.
+
+4
+00:00:16,000 --> 00:00:22,000
+We are going to start from the Spring Security Introduction and Spring Security Overview.
+
+5
+00:00:22,000 --> 00:00:27,000
+Spring Security focuses on authentication and authorization processes.
+
+6
+00:00:27,000 --> 00:00:34,000
+That's why I believe it is important to learn what authentication and authorization are.
+
+7
+00:00:34,000 --> 00:00:37,000
+And what is the difference between these two terms.
+
+8
+00:00:37,000 --> 00:00:42,000
+We're going to run technologies that support Sprint security integration.
+
+9
+00:00:43,000 --> 00:00:49,000
+I will highlight spring security advantages in order You could understand why we need it.
+
+10
+00:00:49,000 --> 00:00:55,000
+After that, we'll review spring security features and its key modules.
+
+11
+00:00:55,000 --> 00:01:01,000
+And at the end of the lesson, we'll review high level spring security, authentication and authorization
+
+12
+00:01:01,000 --> 00:01:05,000
+architecture, which will be critically important to understand.
+
+13
+00:01:05,000 --> 00:01:08,000
+Before we jump to practical coding examples.
+
+14
+00:01:08,000 --> 00:01:10,000
+Let's start our lesson.
+
+15
+00:01:11,000 --> 00:01:16,000
+Let's start the lesson from the short overview and introduction of spring security.
+
+16
+00:01:16,000 --> 00:01:24,000
+Spring Security is a framework which provides various security features like authentication authorization
+
+17
+00:01:24,000 --> 00:01:28,000
+to create secure Java Enterprise applications.
+
+18
+00:01:28,000 --> 00:01:34,000
+It was started as a subproject of the Spring framework long time ago in 2003.
+
+19
+00:01:35,000 --> 00:01:41,000
+A little bit later it became a separate project released under the partial license as spring security.
+
+20
+00:01:42,000 --> 00:01:49,000
+The main focus of this project is authorization and authentication in the applications.
+
+21
+00:01:49,000 --> 00:01:55,000
+During my course Java from zero to first job, we already learned what authorization and authentication
+
+22
+00:01:55,000 --> 00:01:56,000
+is.
+
+23
+00:01:56,000 --> 00:01:59,000
+But take into account we start new topic.
+
+24
+00:01:59,000 --> 00:02:03,000
+I believe it is important to cover these terms one more time.
+
+25
+00:02:04,000 --> 00:02:05,000
+Let's understand what.
+
+26
+00:02:05,000 --> 00:02:07,000
+Authentication first.
+
+27
+00:02:07,000 --> 00:02:13,000
+Authentication is the act of validating that users are who they claim to be.
+
+28
+00:02:13,000 --> 00:02:17,000
+This is the first step in any security process.
+
+29
+00:02:17,000 --> 00:02:25,000
+How authentication process is usually built in applications, for example, passwords, usernames and
+
+30
+00:02:25,000 --> 00:02:28,000
+passwords as the most common authentication factors.
+
+31
+00:02:29,000 --> 00:02:36,000
+If a user enters the correct data, the system assumes the identity is valid and grants access.
+
+32
+00:02:36,000 --> 00:02:42,000
+One time pins grant access for only one session or transaction.
+
+33
+00:02:43,000 --> 00:02:46,000
+Authentication apps generate security codes.
+
+34
+00:02:46,000 --> 00:02:50,000
+We are an outside party that grants access.
+
+35
+00:02:50,000 --> 00:02:57,000
+Biometrics A user presents a fingerprint or scan to gain access to the system.
+
+36
+00:02:57,000 --> 00:03:04,000
+In some instances, systems requires a successful verification of more than one factor before granting
+
+37
+00:03:04,000 --> 00:03:05,000
+access.
+
+38
+00:03:05,000 --> 00:03:13,000
+If you use such popular services as Gmail, Facebook, Instagram and lots more, most of them offers
+
+39
+00:03:13,000 --> 00:03:21,000
+you two factor authentication with your mobile phone to authenticate you to confirm that the user who
+
+40
+00:03:21,000 --> 00:03:25,000
+tries to access the application is the one he claims to be.
+
+41
+00:03:26,000 --> 00:03:33,000
+The multifactor authentication requirement is often deployed to increase security beyond what passwords
+
+42
+00:03:33,000 --> 00:03:34,000
+alone can provide.
+
+43
+00:03:35,000 --> 00:03:38,000
+Let's learn now what authorization is.
+
+44
+00:03:39,000 --> 00:03:47,000
+Authorization in system security is the process of giving the user permission to access a specific resource
+
+45
+00:03:47,000 --> 00:03:48,000
+or function.
+
+46
+00:03:48,000 --> 00:03:55,000
+This term is often used interchangeably with access control or client privilege.
+
+47
+00:03:55,000 --> 00:04:02,000
+Given some permission to download a particular file on a server or provide an individual users with
+
+48
+00:04:02,000 --> 00:04:05,000
+administrative access to an application.
+
+49
+00:04:05,000 --> 00:04:09,000
+Good Examples of authorization In secure environments.
+
+50
+00:04:09,000 --> 00:04:13,000
+Authorization must always follow authentication.
+
+51
+00:04:14,000 --> 00:04:22,000
+Users should first prove that their identities are real before an organization's administrators grant
+
+52
+00:04:22,000 --> 00:04:25,000
+them access to the requested resources.
+
+53
+00:04:25,000 --> 00:04:32,000
+Despite the similar sounding terms, authentication and authorization are separate steps in the login
+
+54
+00:04:32,000 --> 00:04:33,000
+process.
+
+55
+00:04:34,000 --> 00:04:38,000
+Understanding the difference between these two is important.
+
+56
+00:04:38,000 --> 00:04:42,000
+Let's use an analogy to outline the differences.
+
+57
+00:04:42,000 --> 00:04:45,000
+Imagine the nanny for your children.
+
+58
+00:04:45,000 --> 00:04:52,000
+You are leaving for vacation or to work and you need somebody to stay with your children to babysit
+
+59
+00:04:52,000 --> 00:04:52,000
+them.
+
+60
+00:04:52,000 --> 00:04:57,000
+What nanny needs she or he needs two things.
+
+61
+00:04:57,000 --> 00:04:59,000
+The first one, authentication.
+
+62
+00:04:59,000 --> 00:05:02,000
+It is a key to your door.
+
+63
+00:05:02,000 --> 00:05:09,000
+Only by opening the door, we can say that nanny will get access to your children in the similar way.
+
+64
+00:05:09,000 --> 00:05:14,000
+System should let him only users who have valid credentials.
+
+65
+00:05:14,000 --> 00:05:21,000
+And the second thing and then it needs is authorization is actually permission of parents to stay with
+
+66
+00:05:21,000 --> 00:05:22,000
+children.
+
+67
+00:05:22,000 --> 00:05:25,000
+Permission to use kitchen bathroom.
+
+68
+00:05:25,000 --> 00:05:30,000
+But nanny may not have permission to enter parent's bedroom, for example.
+
+69
+00:05:30,000 --> 00:05:37,000
+That is authorization authentication and authorization work together in this example.
+
+70
+00:05:38,000 --> 00:05:45,000
+In the web application, we can apply authorization to authorize web request methods and access to individual
+
+71
+00:05:45,000 --> 00:05:46,000
+domain.
+
+72
+00:05:47,000 --> 00:05:53,000
+There are different technologies for authorization and authentication, and spring security supports
+
+73
+00:05:53,000 --> 00:05:56,000
+a wide range of authentication models.
+
+74
+00:05:56,000 --> 00:06:01,000
+This models is provided by the third parties or framework itself.
+
+75
+00:06:01,000 --> 00:06:07,000
+Screen Security supports integration with all of these technologies that you can see on the slide.
+
+76
+00:06:08,000 --> 00:06:17,000
+They are HTTP basic authentication headers, HTTP Digest authentication headers, http x 509 Client
+
+77
+00:06:17,000 --> 00:06:26,000
+Certificate Exchange LDAP Lightweight Directory Access Protocol form based authentication Open Idea
+
+78
+00:06:26,000 --> 00:06:34,000
+Authentication Automatic Remember me Authentication Kerberos Java Open Source single sign on app for
+
+79
+00:06:34,000 --> 00:06:39,000
+use 108 new ESB Direct web request.
+
+80
+00:06:40,000 --> 00:06:47,000
+The beauty of spring security framework is in its flexible authentication nature to integrate with any
+
+81
+00:06:47,000 --> 00:06:48,000
+software solution.
+
+82
+00:06:48,000 --> 00:06:55,000
+Sometimes developers want to integrate with a legacy system that doesn't follow any security standard.
+
+83
+00:06:56,000 --> 00:06:59,000
+Their spring security works nicely to.
+
+84
+00:07:00,000 --> 00:07:05,000
+To understand spring security better, lets review its advantages.
+
+85
+00:07:05,000 --> 00:07:11,000
+Understanding of spring security advantages will give you other point of view on why we need it.
+
+86
+00:07:12,000 --> 00:07:15,000
+Some of the advantages are described on the slide.
+
+87
+00:07:15,000 --> 00:07:20,000
+Among them comprehensive support for syndication and authorization.
+
+88
+00:07:20,000 --> 00:07:23,000
+Protection against common tasks.
+
+89
+00:07:23,000 --> 00:07:25,000
+Civil API Integration.
+
+90
+00:07:25,000 --> 00:07:32,000
+Spring Security uses the Java Standard filters to start the security check for our web application.
+
+91
+00:07:32,000 --> 00:07:36,000
+Integration with Spring MVC Portability.
+
+92
+00:07:36,000 --> 00:07:39,000
+CSR Protection.
+
+93
+00:07:39,000 --> 00:07:42,000
+We're going to discuss this separately too.
+
+94
+00:07:42,000 --> 00:07:48,000
+But see, as REF stands for Cross-Site Request Forgery Java Configuration Support.
+
+95
+00:07:49,000 --> 00:07:52,000
+Let's review spring security features.
+
+96
+00:07:52,000 --> 00:07:57,000
+There are numerous features, but let me cover the most important ones.
+
+97
+00:07:57,000 --> 00:08:01,000
+LDAP Lightweight Directory Access Protocol.
+
+98
+00:08:01,000 --> 00:08:08,000
+It is an open application protocol for maintaining and accessing distributed directory information services
+
+99
+00:08:08,000 --> 00:08:12,000
+over an Internet protocol single sign on.
+
+100
+00:08:13,000 --> 00:08:20,000
+This feature allows a user to access multiple applications with the help of single account username
+
+101
+00:08:20,000 --> 00:08:20,000
+and password.
+
+102
+00:08:21,000 --> 00:08:26,000
+Java Authentication and Authorization Service Login Module.
+
+103
+00:08:26,000 --> 00:08:34,000
+It is a Pluggable authentication module implemented in Java Spring Security support for its authentication
+
+104
+00:08:34,000 --> 00:08:35,000
+process.
+
+105
+00:08:36,000 --> 00:08:38,000
+Basic Access Authentication.
+
+106
+00:08:38,000 --> 00:08:40,000
+Spring Security Supports.
+
+107
+00:08:40,000 --> 00:08:45,000
+Basic access authentication that is used to provide username and password while making a request over
+
+108
+00:08:45,000 --> 00:08:49,000
+the Network Digest Access authentication.
+
+109
+00:08:49,000 --> 00:08:56,000
+This feature allows us to make authentication process more secure than basic access to sanctification.
+
+110
+00:08:56,000 --> 00:09:04,000
+It asks to the browser to confirm the identity of the user before sending sensitive data over the network.
+
+111
+00:09:05,000 --> 00:09:06,000
+Remember me.
+
+112
+00:09:06,000 --> 00:09:11,000
+Screen Security supports this feature with the help of HTTP cookies.
+
+113
+00:09:11,000 --> 00:09:18,000
+It remembers the user and avoid login again from the same machine until the user log out.
+
+114
+00:09:19,000 --> 00:09:21,000
+Web form authentication.
+
+115
+00:09:21,000 --> 00:09:27,000
+In this process, web form collects and authenticate user credentials from the web browser.
+
+116
+00:09:27,000 --> 00:09:29,000
+Spring Security supports it.
+
+117
+00:09:29,000 --> 00:09:37,000
+While we want to implement web form or syndication authorization, Spring Security provides this feature
+
+118
+00:09:37,000 --> 00:09:40,000
+to authorize the user before accessing resources.
+
+119
+00:09:40,000 --> 00:09:48,000
+It allows developers to define access policies against the resources HTTP authorization.
+
+120
+00:09:48,000 --> 00:09:54,000
+Screen provides this feature for HTTP authorization of Web request URLs.
+
+121
+00:09:54,000 --> 00:09:57,000
+OAuth 2.0 Login.
+
+122
+00:09:57,000 --> 00:10:04,000
+This feature provides a facility to the user to login into the application by using their existing account
+
+123
+00:10:04,000 --> 00:10:05,000
+at GitHub or Google.
+
+124
+00:10:06,000 --> 00:10:11,000
+Reactive support from version Sprint Security 5.0.
+
+125
+00:10:11,000 --> 00:10:19,000
+It provides reactive programming and reactive web runtime support, and even we can integrate with spring
+
+126
+00:10:19,000 --> 00:10:20,000
+Flux.
+
+127
+00:10:20,000 --> 00:10:23,000
+We'll talk later with spring that flux is.
+
+128
+00:10:24,000 --> 00:10:27,000
+Modernized password and coding.
+
+129
+00:10:28,000 --> 00:10:29,000
+Spring Security 5.0.
+
+130
+00:10:29,000 --> 00:10:37,000
+Introduced new password and code delegating password and coder, which is more modernized and solve
+
+131
+00:10:37,000 --> 00:10:39,000
+all the problems of previous encoder.
+
+132
+00:10:39,000 --> 00:10:42,000
+No password and coder.
+
+133
+00:10:42,000 --> 00:10:49,000
+This pretty security is a security module comprises separate files based on its functionality.
+
+134
+00:10:49,000 --> 00:10:54,000
+The primary use is to allow the user to integrate according to the requirements.
+
+135
+00:10:55,000 --> 00:11:02,000
+This topic is important to understand before we start connecting dependencies to our project, so one
+
+136
+00:11:02,000 --> 00:11:04,000
+will come to the practical examples.
+
+137
+00:11:04,000 --> 00:11:09,000
+You should already recognize the difference between some basic modules.
+
+138
+00:11:09,000 --> 00:11:11,000
+They are core.
+
+139
+00:11:11,000 --> 00:11:19,000
+This module contains core authentication and access control related classes, Basic provisioning APIs.
+
+140
+00:11:20,000 --> 00:11:27,000
+This is mandatory for providing security to any Java to E based enterprise application.
+
+141
+00:11:28,000 --> 00:11:31,000
+This module supports non web applications to.
+
+142
+00:11:32,000 --> 00:11:40,000
+That this module contains filters and web based authentication like access control for URLs in the servlet
+
+143
+00:11:40,000 --> 00:11:41,000
+environment.
+
+144
+00:11:42,000 --> 00:11:50,000
+This module is responsible to provide security to your spring MVC or any other web application config.
+
+145
+00:11:50,000 --> 00:11:59,000
+This module used to use the screen security XML namespace LDAP module supporting the LDAP authentication.
+
+146
+00:11:59,000 --> 00:12:05,000
+We may need this if you want to have LDAP authentication for our application.
+
+147
+00:12:06,000 --> 00:12:10,000
+OAuth 2.0 CORE provides supports for all else.
+
+148
+00:12:10,000 --> 00:12:21,000
+2.0 authorization allows 2.0 client three securities client support for hours, 2.0 authorization framework
+
+149
+00:12:21,000 --> 00:12:28,000
+and open ID Connect CORE 1.0 allows 2.0 G or C.
+
+150
+00:12:28,000 --> 00:12:36,000
+It provides print security support for the G or C that stands for JavaScript object signing and Encryption
+
+151
+00:12:36,000 --> 00:12:37,000
+Framework.
+
+152
+00:12:37,000 --> 00:12:38,000
+The G.
+
+153
+00:12:38,000 --> 00:12:43,000
+S E framework provides methods to establish secure connection between clients.
+
+154
+00:12:44,000 --> 00:12:56,000
+It contains following collection of specifications g w json token g w s json web signature g w e JSON
+
+155
+00:12:56,000 --> 00:12:58,000
+web Encryption.
+
+156
+00:12:58,000 --> 00:13:01,000
+JWT JSON web Key.
+
+157
+00:13:02,000 --> 00:13:09,000
+Remote in this jar is used to integrate security feature into the spring remote application.
+
+158
+00:13:09,000 --> 00:13:16,000
+We don't need it until or unless we're creating a remote application ACL.
+
+159
+00:13:16,000 --> 00:13:22,000
+This jar is used to apply security to domain object in the application.
+
+160
+00:13:23,000 --> 00:13:26,000
+ACL stands for Access Control List.
+
+161
+00:13:27,000 --> 00:13:37,000
+Case, it is required for screen security case client integration Case stands for Central Authentication
+
+162
+00:13:37,000 --> 00:13:37,000
+Service.
+
+163
+00:13:37,000 --> 00:13:45,000
+We can use it to integrate screen security web authentication with CSS single sign on server.
+
+164
+00:13:46,000 --> 00:13:47,000
+Open ID.
+
+165
+00:13:47,000 --> 00:13:51,000
+This jar is used for open ID web authentication support.
+
+166
+00:13:51,000 --> 00:13:57,000
+We can use it to authenticate users against an external open ID server.
+
+167
+00:13:58,000 --> 00:13:59,000
+Test.
+
+168
+00:13:59,000 --> 00:14:04,000
+This jar provides supports for testing screen security application.
+
+169
+00:14:05,000 --> 00:14:10,000
+And the last but not the least, things that I would like to cover with you today is a high level architecture
+
+170
+00:14:10,000 --> 00:14:14,000
+of authentication and authorization in screen security.
+
+171
+00:14:15,000 --> 00:14:18,000
+Pay attention to the slide number one.
+
+172
+00:14:18,000 --> 00:14:25,000
+The filter security interceptor obtains an authentication from the security context holder.
+
+173
+00:14:26,000 --> 00:14:34,000
+Number two, Filter Security interceptor creates a filter invocation from the HTTP server request,
+
+174
+00:14:34,000 --> 00:14:41,000
+HTTP servlet response and filter chain that are passed into the filter security interceptor.
+
+175
+00:14:41,000 --> 00:14:50,000
+Number three, it passes the filter invocation to security method data source to get the config attributes.
+
+176
+00:14:50,000 --> 00:14:58,000
+Number four, it passes the authentication filter invocation and config attributes to the Access Decision
+
+177
+00:14:58,000 --> 00:14:58,000
+Manager.
+
+178
+00:14:59,000 --> 00:15:05,000
+Number five If authorization is denied and access denied exception is thrown.
+
+179
+00:15:06,000 --> 00:15:12,000
+In this case, the exception translation filter handles the access denied exception.
+
+180
+00:15:12,000 --> 00:15:15,000
+Number six if access is granted.
+
+181
+00:15:15,000 --> 00:15:23,000
+Filter Security interceptor continues with the filter chain, which lets the application process normally
+
+182
+00:15:23,000 --> 00:15:25,000
+by default.
+
+183
+00:15:25,000 --> 00:15:30,000
+Spring Security's authorization requires all requests to be authenticated.
+
+184
+00:15:31,000 --> 00:15:35,000
+Don't worry, this is high level overview and just introduction.
+
+185
+00:15:35,000 --> 00:15:41,000
+In the following lessons, we are going to have more practical examples and you will understand it better
+
+186
+00:15:41,000 --> 00:15:44,000
+after doing some coding exercises with me.
+
+187
+00:15:45,000 --> 00:15:46,000
+That's it.
+
+188
+00:15:46,000 --> 00:15:49,000
+Let's recap what we have learned today.
+
+189
+00:15:50,000 --> 00:15:54,000
+In this lesson, we learned what Spring Security Project is about.
+
+190
+00:15:54,000 --> 00:16:01,000
+I explained what authentication and authorization are and what is the difference between them.
+
+191
+00:16:01,000 --> 00:16:05,000
+We review technologies that support screen security integration.
+
+192
+00:16:05,000 --> 00:16:09,000
+Also, we talked about spring security advantages.
+
+193
+00:16:09,000 --> 00:16:14,000
+We discussed spring security features and its modules.
+
+194
+00:16:14,000 --> 00:16:20,000
+And at the end of the lesson, we reviewed high level screen security, authentication and authorization
+
+195
+00:16:20,000 --> 00:16:21,000
+architecture.
+
+196
+00:16:22,000 --> 00:16:23,000
+That's all for this lesson.
+
+197
+00:16:23,000 --> 00:16:25,000
+Thanks a lot for your attention.
+
+198
+00:16:25,000 --> 00:16:28,000
+Have a great day and see you in the next lesson.
+
diff --git a/84 - Spring Security/002 First Login Form & First Security Filter Configuration_en.srt b/84 - Spring Security/002 First Login Form & First Security Filter Configuration_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..e0164e8d48e8ea186f9da6142d0244ba533cf111
--- /dev/null
+++ b/84 - Spring Security/002 First Login Form & First Security Filter Configuration_en.srt
@@ -0,0 +1,1680 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, Kim.
+
+2
+00:00:06,000 --> 00:00:10,000
+In the previous lesson, we already learned what spring security is.
+
+3
+00:00:10,000 --> 00:00:12,000
+And we hold an overview.
+
+4
+00:00:13,000 --> 00:00:17,000
+Now it is time for us to get more practical experience.
+
+5
+00:00:17,000 --> 00:00:20,000
+In this video, we're going to create our spring security.
+
+6
+00:00:20,000 --> 00:00:21,000
+Hello, world.
+
+7
+00:00:21,000 --> 00:00:24,000
+Our first spring security login form.
+
+8
+00:00:25,000 --> 00:00:29,000
+We'll start our lesson from configuring our first spring security project.
+
+9
+00:00:29,000 --> 00:00:36,000
+We'll add all required dependencies and we'll jump to configuration of the Spring Security project.
+
+10
+00:00:37,000 --> 00:00:42,000
+During the configuration of spring security, we are going to learn different types and beans, for
+
+11
+00:00:42,000 --> 00:00:49,000
+example, in memory user details, manager password, encoder, security, filter chain and others.
+
+12
+00:00:50,000 --> 00:00:52,000
+I will briefly explain what C.
+
+13
+00:00:52,000 --> 00:00:56,000
+S F is as a set today.
+
+14
+00:00:56,000 --> 00:00:59,000
+We're going to have a lot of practical examples.
+
+15
+00:00:59,000 --> 00:01:04,000
+I want to show you an end to end flow of login and log out with spring security.
+
+16
+00:01:04,000 --> 00:01:10,000
+I'm going to explain you the difference between anonymous and permit all requests.
+
+17
+00:01:10,000 --> 00:01:18,000
+We'll talk about different handlers that can be configured to support our login process, namely will
+
+18
+00:01:18,000 --> 00:01:23,000
+learn authentication, favor handler and log out success handler.
+
+19
+00:01:23,000 --> 00:01:30,000
+After making all required configurations, you will be able to see how log in with spring security works.
+
+20
+00:01:30,000 --> 00:01:37,000
+How we'll show you login with a custom login form and with the default login form that is provided by
+
+21
+00:01:37,000 --> 00:01:39,000
+spring security out of the box.
+
+22
+00:01:39,000 --> 00:01:41,000
+A lot of things to learn today.
+
+23
+00:01:41,000 --> 00:01:43,000
+Let's start our lesson.
+
+24
+00:01:43,000 --> 00:01:50,000
+And as I recommended at the beginning of our lesson, let's make this lesson completely focused on the
+
+25
+00:01:50,000 --> 00:01:53,000
+practical examples and coding exercises.
+
+26
+00:01:53,000 --> 00:01:59,000
+Let me start screen sharing and share with you examples that I prepared for you.
+
+27
+00:01:59,000 --> 00:02:05,000
+As always, you can find all source code examples in attachments to the video lesson.
+
+28
+00:02:06,000 --> 00:02:07,000
+The first thing.
+
+29
+00:02:07,000 --> 00:02:13,000
+What we need to discuss is adding all required dependencies into our PUM XML file.
+
+30
+00:02:13,000 --> 00:02:16,000
+We need to add the following dependencies.
+
+31
+00:02:16,000 --> 00:02:20,000
+Security Core web module config module.
+
+32
+00:02:21,000 --> 00:02:27,000
+A little bit later in the course when we'll learn spring boot, you will be able to add just one dependency.
+
+33
+00:02:27,000 --> 00:02:30,000
+This is called sprint boot starter security.
+
+34
+00:02:31,000 --> 00:02:33,000
+That dependency will add everything.
+
+35
+00:02:33,000 --> 00:02:37,000
+What is needed to enable sprint security feature in your application.
+
+36
+00:02:38,000 --> 00:02:44,000
+But if you don't use Sprint boot, you need to add multiple dependencies into your project.
+
+37
+00:02:44,000 --> 00:02:50,000
+In the previous lesson, we'll already discussed what modules exist in Sprint security.
+
+38
+00:02:50,000 --> 00:02:53,000
+If you skipped previous lesson place, watch it.
+
+39
+00:02:54,000 --> 00:02:58,000
+So you need to decide which version to add.
+
+40
+00:02:58,000 --> 00:03:05,000
+Pay attention that libraries of sprint security, starting from the version six relies on the Jakarta
+
+41
+00:03:05,000 --> 00:03:08,000
+API but not Java EE.
+
+42
+00:03:08,000 --> 00:03:10,000
+This is important to know.
+
+43
+00:03:11,000 --> 00:03:15,000
+Even despite that, API itself is not changed dramatically.
+
+44
+00:03:15,000 --> 00:03:22,000
+Jakarta API has different package naming and it can impact development and execution.
+
+45
+00:03:22,000 --> 00:03:29,000
+So I add Sprint security version five from the MAVEN repository to have the same version in different
+
+46
+00:03:29,000 --> 00:03:31,000
+spring security modules.
+
+47
+00:03:31,000 --> 00:03:36,000
+I introduce MAVEN variable and refer to it in the version field.
+
+48
+00:03:37,000 --> 00:03:40,000
+After we added all required dependencies.
+
+49
+00:03:40,000 --> 00:03:42,000
+Let's continue with the configuration.
+
+50
+00:03:42,000 --> 00:03:48,000
+I open web config class because this is a class of our configuration.
+
+51
+00:03:48,000 --> 00:03:51,000
+The first thing that I need to do is to add annotation.
+
+52
+00:03:51,000 --> 00:03:53,000
+Enable web security.
+
+53
+00:03:54,000 --> 00:03:57,000
+The enable web security is a marker annotation.
+
+54
+00:03:58,000 --> 00:04:06,000
+It allows Sprint to find its configuration and automatically applies the class to the global web security.
+
+55
+00:04:06,000 --> 00:04:12,000
+And now we need to declare required beans here in order to start use spring security.
+
+56
+00:04:13,000 --> 00:04:15,000
+What beans do we need to declare?
+
+57
+00:04:16,000 --> 00:04:18,000
+Let's go one by one.
+
+58
+00:04:18,000 --> 00:04:22,000
+Taking into account, this is our first practical example with spring security.
+
+59
+00:04:22,000 --> 00:04:25,000
+I will not make it super complex.
+
+60
+00:04:25,000 --> 00:04:31,000
+I want it looks like simple Hello world example and gradually will make it more complex.
+
+61
+00:04:31,000 --> 00:04:38,000
+That's why we'll not use databases right now to work with users in this example, we are going to use
+
+62
+00:04:38,000 --> 00:04:44,000
+in-memory user details Manager that we'll use pre-configured users from the memory.
+
+63
+00:04:44,000 --> 00:04:52,000
+Mainly it is used for testing and demonstration purposes where a full blown persistent system isn't
+
+64
+00:04:52,000 --> 00:04:52,000
+required.
+
+65
+00:04:53,000 --> 00:04:58,000
+Also, we have to define passwords, encoder and security filter chain bin.
+
+66
+00:04:58,000 --> 00:05:06,000
+Let's review implementation and understand how we configure these bins to configure in memory details.
+
+67
+00:05:06,000 --> 00:05:07,000
+Manager.
+
+68
+00:05:07,000 --> 00:05:09,000
+We need to create user details.
+
+69
+00:05:09,000 --> 00:05:12,000
+User details is an interface.
+
+70
+00:05:12,000 --> 00:05:18,000
+Its implementations are not used directly by spring security for security purposes.
+
+71
+00:05:19,000 --> 00:05:25,000
+The simplest store user information which is later encapsulated into authentication objects.
+
+72
+00:05:26,000 --> 00:05:33,000
+This allows non security related user information such as email addresses, telephone numbers, etc.
+
+73
+00:05:33,000 --> 00:05:37,000
+to be stored in a convenient location.
+
+74
+00:05:37,000 --> 00:05:42,000
+To create user details, we use implementation of this interface user class.
+
+75
+00:05:42,000 --> 00:05:47,000
+It acts like a builder that allows us to build user details.
+
+76
+00:05:47,000 --> 00:05:48,000
+Object.
+
+77
+00:05:48,000 --> 00:05:56,000
+If you would try to read the code, I bet you can understand what is happening here because code is
+
+78
+00:05:56,000 --> 00:05:59,000
+super readable because of the nice API.
+
+79
+00:06:00,000 --> 00:06:07,000
+Let's review just one user details example and I'm sure it will not be a challenge for you to understand
+
+80
+00:06:07,000 --> 00:06:09,000
+other similar examples.
+
+81
+00:06:09,000 --> 00:06:12,000
+I use method with user name.
+
+82
+00:06:13,000 --> 00:06:15,000
+This first method is a method.
+
+83
+00:06:15,000 --> 00:06:20,000
+Chain invocation creates user builder object with a specified user name.
+
+84
+00:06:20,000 --> 00:06:28,000
+All the methods already invoked on the user builder object password method will populate password.
+
+85
+00:06:29,000 --> 00:06:34,000
+We are going to use password encoder to encode our test password.
+
+86
+00:06:34,000 --> 00:06:37,000
+Each user may have multiple roles.
+
+87
+00:06:37,000 --> 00:06:45,000
+These roles will be used to authorize users access to different resources roles.
+
+88
+00:06:45,000 --> 00:06:53,000
+Mass takes string variable argument, but for the sake of the demo, we'll pass one role for each user.
+
+89
+00:06:53,000 --> 00:06:56,000
+Let's imagine that we have role customer.
+
+90
+00:06:57,000 --> 00:07:03,000
+This is the most generic role in our application and we have role admin.
+
+91
+00:07:03,000 --> 00:07:08,000
+The admin has access to the resources to which customer doesn't have access.
+
+92
+00:07:09,000 --> 00:07:16,000
+In the similar way I configured all the user details and I created the new object often memory user
+
+93
+00:07:16,000 --> 00:07:18,000
+details, manager and post.
+
+94
+00:07:18,000 --> 00:07:21,000
+There's a reference to the user details.
+
+95
+00:07:21,000 --> 00:07:24,000
+That's how I configured this bin.
+
+96
+00:07:24,000 --> 00:07:31,000
+Later in the course I'm going to teach you how to read information about users from the persistent storage,
+
+97
+00:07:31,000 --> 00:07:34,000
+like, for example, from our database.
+
+98
+00:07:34,000 --> 00:07:35,000
+Let's move on.
+
+99
+00:07:36,000 --> 00:07:42,000
+The next bins that I'm going to configure is password encoder being password encoder.
+
+100
+00:07:42,000 --> 00:07:49,000
+It is also an interface from the Spring Security library, just an interface for encoding passwords.
+
+101
+00:07:50,000 --> 00:07:54,000
+The preferred implementation is decrypt password encoder.
+
+102
+00:07:54,000 --> 00:07:58,000
+As you can see, the interface is pretty straightforward.
+
+103
+00:07:58,000 --> 00:08:07,000
+Most likely you will use these two methods and the code and matches and code will encode your password.
+
+104
+00:08:07,000 --> 00:08:15,000
+Usually you call it before storing password into the database and matches you will use to verify raw
+
+105
+00:08:15,000 --> 00:08:19,000
+password versus encoded password from the database.
+
+106
+00:08:19,000 --> 00:08:25,000
+I just create instance of decrypt passwords encoder and we are done with configuration of this bin.
+
+107
+00:08:26,000 --> 00:08:30,000
+The next important bin to configure is security filter chain.
+
+108
+00:08:31,000 --> 00:08:38,000
+This is exactly the filter that will authorize access to the resources depending on the client role.
+
+109
+00:08:38,000 --> 00:08:42,000
+We inject HTTP security object in order to configure the bin.
+
+110
+00:08:43,000 --> 00:08:51,000
+Just to remind you that HTTP security object will be instantiated after using of enabled web security
+
+111
+00:08:51,000 --> 00:08:52,000
+annotation.
+
+112
+00:08:52,000 --> 00:08:56,000
+And after that you can see complex method invocation chain.
+
+113
+00:08:56,000 --> 00:09:01,000
+See SRF method enables cross-site request forgery.
+
+114
+00:09:01,000 --> 00:09:09,000
+If you don't know what it is, please refer to my course java from zero to first job and section about
+
+115
+00:09:09,000 --> 00:09:11,000
+secure coding and ASP top ten.
+
+116
+00:09:12,000 --> 00:09:16,000
+We learned in details what CSR is.
+
+117
+00:09:17,000 --> 00:09:24,000
+But in short, and just to help you to remember, cross-site request, forgery is an attack that forces
+
+118
+00:09:24,000 --> 00:09:32,000
+an end user to execute unwanted actions on a web application in which they're currently authenticated
+
+119
+00:09:33,000 --> 00:09:39,000
+with a little help of social engineering, such as sending a link to email or chat.
+
+120
+00:09:39,000 --> 00:09:47,000
+And a talker may trick the users of a web application into executing actions of the attackers, choosing
+
+121
+00:09:47,000 --> 00:09:49,000
+if the victim is a normal user.
+
+122
+00:09:49,000 --> 00:09:58,000
+A successful CSR attack can force the user to perform state change in requests like transferring fonts,
+
+123
+00:09:58,000 --> 00:10:02,000
+changing their email addresses and so forth.
+
+124
+00:10:02,000 --> 00:10:09,000
+If the victim is an administrative account, CSR can compromise the entire web application.
+
+125
+00:10:10,000 --> 00:10:19,000
+So this method sees REF returns, configure and disable method removes configure.
+
+126
+00:10:19,000 --> 00:10:23,000
+After doing so, a fresh version of the configuration can be applied.
+
+127
+00:10:24,000 --> 00:10:32,000
+So if seas are making our application more secure, then why we're disabling it.
+
+128
+00:10:32,000 --> 00:10:35,000
+Spring recommendation is to use C.
+
+129
+00:10:35,000 --> 00:10:41,000
+S r f protection for any request that could be processed by a browser by normal users.
+
+130
+00:10:42,000 --> 00:10:48,000
+If you are only creating a service that is used by non browser clients, you will likely want to disable
+
+131
+00:10:48,000 --> 00:10:49,000
+C.
+
+132
+00:10:49,000 --> 00:10:50,000
+S RF protection.
+
+133
+00:10:51,000 --> 00:10:54,000
+There are also going to be other reasons to disable c.
+
+134
+00:10:54,000 --> 00:10:55,000
+F.
+
+135
+00:10:55,000 --> 00:11:02,000
+For example, you are using another token mechanism for authentication and authorization.
+
+136
+00:11:03,000 --> 00:11:08,000
+Or if you want to simplify interactions between the client and the server.
+
+137
+00:11:08,000 --> 00:11:14,000
+Indeed, using CSR ref protection will make us to follow some other rules.
+
+138
+00:11:15,000 --> 00:11:16,000
+Take you into account.
+
+139
+00:11:16,000 --> 00:11:20,000
+This is our first practical experience with spring security.
+
+140
+00:11:20,000 --> 00:11:22,000
+I recommend to disable it.
+
+141
+00:11:23,000 --> 00:11:30,000
+After that I call authorize HTTP request method that returns us object of type Authorization Manager
+
+142
+00:11:30,000 --> 00:11:32,000
+Request Mature Registry.
+
+143
+00:11:33,000 --> 00:11:38,000
+This object will store information about resources and rules configured.
+
+144
+00:11:39,000 --> 00:11:44,000
+Now we can call request matures and parses the resource patterns.
+
+145
+00:11:45,000 --> 00:11:48,000
+This method takes variable amount of string arguments.
+
+146
+00:11:49,000 --> 00:11:57,000
+Usually we pass here some neuro mapping that we use during the declaration of our controllers.
+
+147
+00:11:57,000 --> 00:12:04,000
+Here you can see that in case request will be sent to admin resources only users with the role admin
+
+148
+00:12:04,000 --> 00:12:12,000
+will be able to access the resource in case request will be sent to the anonymous URL.
+
+149
+00:12:12,000 --> 00:12:18,000
+Then user with any role and even without role will be able to access the resource.
+
+150
+00:12:19,000 --> 00:12:26,000
+And for logging resource, we need to allow access for everyone because in case nobody can access login
+
+151
+00:12:26,000 --> 00:12:29,000
+page, then it makes no sense.
+
+152
+00:12:30,000 --> 00:12:36,000
+Most likely you have a question at this moment, but what is the difference between anonymous and permit?
+
+153
+00:12:36,000 --> 00:12:36,000
+All?
+
+154
+00:12:37,000 --> 00:12:38,000
+That's a good question.
+
+155
+00:12:39,000 --> 00:12:47,000
+Note that there is no real conceptual difference between a user who is anonymously authenticated and
+
+156
+00:12:47,000 --> 00:12:49,000
+an unauthenticated user.
+
+157
+00:12:49,000 --> 00:12:56,000
+Spring Security's anonymous authentication just gives you a more convenient way to configure your access
+
+158
+00:12:56,000 --> 00:12:58,000
+control attributes.
+
+159
+00:12:58,000 --> 00:13:07,000
+Using the permit all will configure the authorization so that all requests both from anonymous and logged
+
+160
+00:13:07,000 --> 00:13:11,000
+in users are allowed on that particular pass.
+
+161
+00:13:11,000 --> 00:13:18,000
+The anonymous expression mainly refers to the status of the user logged in or not.
+
+162
+00:13:19,000 --> 00:13:24,000
+Basically, until the user is authenticated, it is anonymous user.
+
+163
+00:13:24,000 --> 00:13:27,000
+It is like having a default role for everybody.
+
+164
+00:13:28,000 --> 00:13:32,000
+The next method in the method chain is any request.
+
+165
+00:13:32,000 --> 00:13:40,000
+Like you may guess, this refers to any request sent to our web application and there is possibility
+
+166
+00:13:40,000 --> 00:13:48,000
+to say that any request needs to be authenticated and pay attention in which sequence I declared these
+
+167
+00:13:48,000 --> 00:13:49,000
+rules.
+
+168
+00:13:49,000 --> 00:13:56,000
+We started from the specific rule and to more general rule and not vice versa.
+
+169
+00:13:56,000 --> 00:13:57,000
+This is important.
+
+170
+00:13:58,000 --> 00:14:01,000
+Let's continue when we configure it.
+
+171
+00:14:01,000 --> 00:14:02,000
+Authorization Rules.
+
+172
+00:14:03,000 --> 00:14:05,000
+There is one more thing to configure.
+
+173
+00:14:06,000 --> 00:14:11,000
+We can configure login page custom one or default one.
+
+174
+00:14:12,000 --> 00:14:21,000
+Taking into account, we said that any request should be authenticated in case user is not authenticated,
+
+175
+00:14:21,000 --> 00:14:27,000
+he or she will be redirected to the login form to continue using HTTP security builder.
+
+176
+00:14:27,000 --> 00:14:29,000
+We need to call and method.
+
+177
+00:14:30,000 --> 00:14:39,000
+It returns the HTTP security builder when we're done with using the authorize HTTP request configure.
+
+178
+00:14:39,000 --> 00:14:42,000
+This is useful for mass chaining.
+
+179
+00:14:43,000 --> 00:14:51,000
+It returns the HTTP security builder for further customizations form log in method returns reference
+
+180
+00:14:51,000 --> 00:14:55,000
+to the object of form login configure type in order.
+
+181
+00:14:55,000 --> 00:14:58,000
+We could proceed with further customizations.
+
+182
+00:14:58,000 --> 00:15:03,000
+Login page sets the path to the custom login page.
+
+183
+00:15:03,000 --> 00:15:08,000
+For the sake of the demo I created controller that resolves the login view.
+
+184
+00:15:09,000 --> 00:15:13,000
+You can find login controller in the controller package.
+
+185
+00:15:13,000 --> 00:15:15,000
+Nothing is special here.
+
+186
+00:15:16,000 --> 00:15:19,000
+Let's look at the login JSP page.
+
+187
+00:15:19,000 --> 00:15:20,000
+Here it is.
+
+188
+00:15:21,000 --> 00:15:22,000
+Few important things here.
+
+189
+00:15:23,000 --> 00:15:30,000
+First of all, spring security automatically recognize such form attributes as username and password.
+
+190
+00:15:30,000 --> 00:15:34,000
+Using such name in the login form is mandatory by default.
+
+191
+00:15:35,000 --> 00:15:42,000
+In case you don't want to use username, but you want to use email attribute name for example, or you
+
+192
+00:15:42,000 --> 00:15:45,000
+don't want to use password and you want to use pass.
+
+193
+00:15:45,000 --> 00:15:49,000
+For some reasons I don't know why, but you are free to do so.
+
+194
+00:15:49,000 --> 00:15:56,000
+But in this case, do not forget that additional configuration into the login form.
+
+195
+00:15:56,000 --> 00:16:02,000
+So while configuring login form, we need to call user name parameter.
+
+196
+00:16:02,000 --> 00:16:08,000
+If we want to use different attribute name in the login form and password parameter in the case, we
+
+197
+00:16:08,000 --> 00:16:12,000
+want to use different attribute name in the login form for password.
+
+198
+00:16:12,000 --> 00:16:16,000
+But now example I I'm more than happy to use default naming.
+
+199
+00:16:17,000 --> 00:16:20,000
+The next important thing is about action attitude.
+
+200
+00:16:21,000 --> 00:16:25,000
+So a lot of my students have challenges exactly with this.
+
+201
+00:16:25,000 --> 00:16:26,000
+Let me explain you.
+
+202
+00:16:27,000 --> 00:16:30,000
+I will start a little bit from the side.
+
+203
+00:16:30,000 --> 00:16:36,000
+When we develop application, we also want to make it secure and to make it secure.
+
+204
+00:16:36,000 --> 00:16:43,000
+We don't want to expose the fact that we use spring security on the backend of our application, because
+
+205
+00:16:43,000 --> 00:16:46,000
+in this case, in case vulnerability will be found.
+
+206
+00:16:47,000 --> 00:16:52,000
+It will be super easy for hackers to find login forms that use spring security.
+
+207
+00:16:53,000 --> 00:16:58,000
+That's why it is recommended to use not default, but custom action value.
+
+208
+00:16:59,000 --> 00:17:06,000
+In this case, developers can configure any action value where form will be submitted without worrying
+
+209
+00:17:06,000 --> 00:17:12,000
+that anyone will understand that we use spring security because of the specific action value.
+
+210
+00:17:12,000 --> 00:17:19,000
+For example, before spring security version for the values that should be used in action field was
+
+211
+00:17:19,000 --> 00:17:21,000
+called G Spring Security Check.
+
+212
+00:17:22,000 --> 00:17:26,000
+From its name, it was easy to understand that we use spring security.
+
+213
+00:17:26,000 --> 00:17:34,000
+So like I said, the rule of thumb is to specify custom action here during the configuration of login
+
+214
+00:17:34,000 --> 00:17:34,000
+form.
+
+215
+00:17:34,000 --> 00:17:37,000
+We also use login process in URL.
+
+216
+00:17:37,000 --> 00:17:42,000
+This is the URL that should be used by the login form in order.
+
+217
+00:17:42,000 --> 00:17:44,000
+Spring could process the request.
+
+218
+00:17:44,000 --> 00:17:47,000
+Pay attention that I have here.
+
+219
+00:17:47,000 --> 00:17:56,000
+Test perform login URL and in the JSP page I have just perform login because this view will be resolved
+
+220
+00:17:56,000 --> 00:18:00,000
+when I will send request to the test login page.
+
+221
+00:18:00,000 --> 00:18:09,000
+So we will build ready in the test pass and we would need just to send a request to perform login.
+
+222
+00:18:10,000 --> 00:18:15,000
+The main thing is the fact that the form should be submitted exactly to the pass.
+
+223
+00:18:15,000 --> 00:18:20,000
+Is it specified in the login process in URL method?
+
+224
+00:18:20,000 --> 00:18:26,000
+Knowing this, you can easily troubleshoot issues in case something doesn't work.
+
+225
+00:18:26,000 --> 00:18:29,000
+That's all regarding login JSP page.
+
+226
+00:18:30,000 --> 00:18:37,000
+And now the interesting thing in case you will not use login page, spring security would show you a
+
+227
+00:18:37,000 --> 00:18:39,000
+nice looking default login page.
+
+228
+00:18:39,000 --> 00:18:46,000
+During the demo I'm going to show you login flow with the customer login form and with the default one.
+
+229
+00:18:47,000 --> 00:18:55,000
+Log in process in URL sets the URL of controller that will process the login usernames and passwords
+
+230
+00:18:55,000 --> 00:18:56,000
+provided.
+
+231
+00:18:57,000 --> 00:19:05,000
+The URL should validate the credentials and we discussed with you that this login processing URL is
+
+232
+00:19:05,000 --> 00:19:10,000
+the same URL that you should receive when you submit your form.
+
+233
+00:19:11,000 --> 00:19:19,000
+Default success URL sets the default URL where user should be redirected after successful login.
+
+234
+00:19:19,000 --> 00:19:22,000
+The second parameter is interesting and might be useful.
+
+235
+00:19:23,000 --> 00:19:30,000
+The second boolean parameter tells where the user should be always redirected to the page after successful
+
+236
+00:19:30,000 --> 00:19:30,000
+login or.
+
+237
+00:19:32,000 --> 00:19:33,000
+In case it is true.
+
+238
+00:19:33,000 --> 00:19:40,000
+User will be always redirected to the success page no matter where user was before.
+
+239
+00:19:41,000 --> 00:19:41,000
+Failure.
+
+240
+00:19:41,000 --> 00:19:48,000
+Earl is the Earl where requests should be redirected in case of the unsuccessful login.
+
+241
+00:19:49,000 --> 00:19:56,000
+Very often developers pass some request parameter to indicate that we opened login form after failure.
+
+242
+00:19:56,000 --> 00:20:02,000
+This would help you to improve user experience by adding some details and visualization of the page
+
+243
+00:20:03,000 --> 00:20:04,000
+based on the request attribute.
+
+244
+00:20:05,000 --> 00:20:11,000
+Pay attention that in case you would set authentication failure handler, you won't be redirected to
+
+245
+00:20:11,000 --> 00:20:15,000
+this URL and handler will process a failure.
+
+246
+00:20:15,000 --> 00:20:19,000
+I'm going to explain what authentication failure handler now.
+
+247
+00:20:20,000 --> 00:20:23,000
+The next message is failure handler.
+
+248
+00:20:23,000 --> 00:20:30,000
+This method specifies the authentication failure handler to use when authentication fails.
+
+249
+00:20:30,000 --> 00:20:37,000
+The default is redirecting to login error using simple URL authentication failure handler.
+
+250
+00:20:38,000 --> 00:20:43,000
+But we have an opportunity to set our customer's indication failure handler.
+
+251
+00:20:43,000 --> 00:20:51,000
+By default, Sprint redirects the user back to the login page with a request parameter containing information
+
+252
+00:20:51,000 --> 00:20:52,000
+about the error.
+
+253
+00:20:52,000 --> 00:21:01,000
+In this, handler will return a 401 response that contains information about the error as well as a
+
+254
+00:21:01,000 --> 00:21:03,000
+timestamp of its occurrence.
+
+255
+00:21:03,000 --> 00:21:10,000
+You can see that I created been of our own failure handler and the implementation of this interface
+
+256
+00:21:10,000 --> 00:21:12,000
+is located in the security package.
+
+257
+00:21:13,000 --> 00:21:18,000
+Basically, we just need to implement on authentication failure method.
+
+258
+00:21:18,000 --> 00:21:25,000
+Having access to the request response and the exception object, you can build any logic that you need
+
+259
+00:21:25,000 --> 00:21:27,000
+while handling the failure.
+
+260
+00:21:28,000 --> 00:21:33,000
+There are the handlers that we can use depending on what we want to do.
+
+261
+00:21:34,000 --> 00:21:41,000
+Delegating authentication Failure handler Delegates Authentication Exception subclasses to different
+
+262
+00:21:41,000 --> 00:21:43,000
+authentication failure handlers.
+
+263
+00:21:43,000 --> 00:21:49,000
+Meaning we can create different behaviors for different instances of authentication.
+
+264
+00:21:49,000 --> 00:21:50,000
+Exception.
+
+265
+00:21:50,000 --> 00:21:57,000
+Exception mapping or syndication failure Handler redirects the user to a specific URL depending on the
+
+266
+00:21:57,000 --> 00:21:58,000
+authentication exceptions.
+
+267
+00:21:58,000 --> 00:22:08,000
+Full class name for authentication failure handler will forward the user to the specified URL regardless
+
+268
+00:22:08,000 --> 00:22:10,000
+of the type of the authentication exception.
+
+269
+00:22:11,000 --> 00:22:17,000
+Simple URL authentication failure handler is a component that is used by default.
+
+270
+00:22:17,000 --> 00:22:21,000
+It will redirect the user to fail URL if specified.
+
+271
+00:22:21,000 --> 00:22:25,000
+Otherwise it will simply return a 401 response.
+
+272
+00:22:26,000 --> 00:22:30,000
+So let's get back to the configuration of our security filter chain.
+
+273
+00:22:31,000 --> 00:22:33,000
+We need just to configure logout.
+
+274
+00:22:33,000 --> 00:22:39,000
+Now we again use and after that I call log out method.
+
+275
+00:22:39,000 --> 00:22:43,000
+It returns reference to the object of logout configure type.
+
+276
+00:22:43,000 --> 00:22:46,000
+And after that you can configure logout process.
+
+277
+00:22:47,000 --> 00:22:49,000
+I specify a logout URL.
+
+278
+00:22:49,000 --> 00:22:59,000
+This is a URL that triggers logout to occur if CSR protection is enabled like by default.
+
+279
+00:22:59,000 --> 00:23:02,000
+Then the request must also be a post.
+
+280
+00:23:03,000 --> 00:23:09,000
+This means that by default post logout is required to trigger a logout.
+
+281
+00:23:10,000 --> 00:23:16,000
+If CSR protection is disabled, then any HTTP method is allowed.
+
+282
+00:23:16,000 --> 00:23:19,000
+In our case, we disabled CSR ref.
+
+283
+00:23:19,000 --> 00:23:24,000
+That means that we can log out with HTTP get request to.
+
+284
+00:23:25,000 --> 00:23:27,000
+Logout success URL.
+
+285
+00:23:27,000 --> 00:23:34,000
+This method sets the URL which will be used in case of the successful logout in case there is no logout
+
+286
+00:23:34,000 --> 00:23:43,000
+success handler, because in the case logout success handler is configured, then Logout Success zero
+
+287
+00:23:43,000 --> 00:23:44,000
+will be ignored.
+
+288
+00:23:45,000 --> 00:23:47,000
+What this handler is about.
+
+289
+00:23:47,000 --> 00:23:49,000
+I'm going to explain to you in a minute.
+
+290
+00:23:50,000 --> 00:23:56,000
+Delete cookies must allow us to delete cookies during the logout by the specified names.
+
+291
+00:23:56,000 --> 00:24:02,000
+In our specific example, let me just vividly clear this session id.
+
+292
+00:24:02,000 --> 00:24:09,000
+If you remember, this is a cookie that is generated automatically by our Tomcat web server when we
+
+293
+00:24:09,000 --> 00:24:10,000
+create a session.
+
+294
+00:24:11,000 --> 00:24:17,000
+And the last method invocations that we do in this chain is log out success handler to set up the handler
+
+295
+00:24:17,000 --> 00:24:20,000
+that will be used during the log out.
+
+296
+00:24:20,000 --> 00:24:28,000
+For the sake of example, I configure it simple beam and implement the required interface in the implementation.
+
+297
+00:24:28,000 --> 00:24:30,000
+I just print text to console.
+
+298
+00:24:31,000 --> 00:24:37,000
+In the real life, you can implement any logic you wish that is associated with the successful logout,
+
+299
+00:24:38,000 --> 00:24:43,000
+clearing some cash for example, or other business variable activity.
+
+300
+00:24:44,000 --> 00:24:46,000
+The great object of security filter chain.
+
+301
+00:24:46,000 --> 00:24:50,000
+We need to call build method on the HTTP security object.
+
+302
+00:24:51,000 --> 00:24:56,000
+After we configured security filter chain and declared all the necessary beans.
+
+303
+00:24:56,000 --> 00:24:59,000
+Let's configure our MVC initializing.
+
+304
+00:24:59,000 --> 00:25:06,000
+I open main web app initialize and I add filter to the servlet context.
+
+305
+00:25:06,000 --> 00:25:08,000
+Just look at these lines.
+
+306
+00:25:09,000 --> 00:25:11,000
+The first argument is a filter name.
+
+307
+00:25:11,000 --> 00:25:14,000
+We'll call our filter security filter.
+
+308
+00:25:15,000 --> 00:25:18,000
+The second argument is actually the filter.
+
+309
+00:25:18,000 --> 00:25:25,000
+I create the object of delegated filter proxy and parses the name of the bin Spring Security Filter
+
+310
+00:25:25,000 --> 00:25:25,000
+chain.
+
+311
+00:25:26,000 --> 00:25:33,000
+Enable Web Security Annotation enables Spring Security's default configuration, which creates a servlet
+
+312
+00:25:33,000 --> 00:25:37,000
+filter as a being named Spring security filter chain.
+
+313
+00:25:37,000 --> 00:25:45,000
+This bin is responsible for all the security protecting the application URLs, validate submitted username
+
+314
+00:25:45,000 --> 00:25:50,000
+and password, redirect into the login form and so on within your application.
+
+315
+00:25:51,000 --> 00:25:57,000
+It will also use all necessary beans that are stored in context.
+
+316
+00:25:58,000 --> 00:26:04,000
+Basically, the delegate and filter proxy is used to retrieve filter object with a big name from the
+
+317
+00:26:04,000 --> 00:26:05,000
+sprint context.
+
+318
+00:26:06,000 --> 00:26:10,000
+After that I call method ad mapping for URL patterns.
+
+319
+00:26:10,000 --> 00:26:14,000
+The first argument is an enum of dispatcher types.
+
+320
+00:26:15,000 --> 00:26:22,000
+We need to specify here either the dispatcher types of the filter mapping or null if the default dispatcher
+
+321
+00:26:22,000 --> 00:26:24,000
+type request is to be used.
+
+322
+00:26:24,000 --> 00:26:29,000
+DISPATCHER type can be forward include request, async and error.
+
+323
+00:26:30,000 --> 00:26:34,000
+In our case, I pose no to use the default request dispatcher type.
+
+324
+00:26:35,000 --> 00:26:41,000
+The second argument is a boolean argument that is called is much after is much after true.
+
+325
+00:26:41,000 --> 00:26:49,000
+If the given filter mapping should be matched after any declared filter mappings and false if it is
+
+326
+00:26:49,000 --> 00:26:56,000
+supposed to be matched before any declared filter mappings of the servlet context from which the filter
+
+327
+00:26:56,000 --> 00:26:59,000
+registration was obtained.
+
+328
+00:26:59,000 --> 00:27:05,000
+I put false because there is no need to match a given filter mapping after each declared filter.
+
+329
+00:27:06,000 --> 00:27:10,000
+And the last argument here is the URL pattern for filter.
+
+330
+00:27:10,000 --> 00:27:16,000
+We configure the filter for the all resources within the context Super.
+
+331
+00:27:17,000 --> 00:27:21,000
+Now we are ready to see the live demo of everything what we have configured here.
+
+332
+00:27:22,000 --> 00:27:24,000
+Let me run the application on the web server.
+
+333
+00:27:30,000 --> 00:27:37,000
+And based on our configuration, no matter which resource I will try to access, I will be redirected
+
+334
+00:27:37,000 --> 00:27:38,000
+to the login form.
+
+335
+00:27:38,000 --> 00:27:45,000
+Because in my configuration, I set that request to any resource should be authenticated.
+
+336
+00:27:46,000 --> 00:27:53,000
+Besides the login form where we are allowed access to everyone and also there is anonymous resource.
+
+337
+00:27:53,000 --> 00:27:57,000
+For the sake of the demo, I need some fake controllers.
+
+338
+00:27:57,000 --> 00:28:02,000
+Here you can see the class that is called Fake Controllers for Spring Security Demo.
+
+339
+00:28:03,000 --> 00:28:06,000
+I implemented all fake controllers here.
+
+340
+00:28:06,000 --> 00:28:13,000
+For example, in case you will try to access an anonymous resource, you can do it without any authorization
+
+341
+00:28:13,000 --> 00:28:15,000
+and without any authentication.
+
+342
+00:28:15,000 --> 00:28:21,000
+In case we will try to access admin resource, we will be redirected to the login form.
+
+343
+00:28:22,000 --> 00:28:29,000
+Now, in case I use credentials of the user with the customer, then I will not be able to access admin
+
+344
+00:28:29,000 --> 00:28:30,000
+resource.
+
+345
+00:28:31,000 --> 00:28:35,000
+Username is user one and password is test one.
+
+346
+00:28:35,000 --> 00:28:38,000
+Let's try and take it into account.
+
+347
+00:28:38,000 --> 00:28:40,000
+This user has zero customer.
+
+348
+00:28:40,000 --> 00:28:43,000
+We receive forbidden status code.
+
+349
+00:28:43,000 --> 00:28:50,000
+This user can't access this resource, but pay attention to one more thing.
+
+350
+00:28:50,000 --> 00:28:55,000
+Do remember we used false attribute for default success hero.
+
+351
+00:28:55,000 --> 00:29:03,000
+That means that after the login user will be redirected to the resource which he or she requested initially.
+
+352
+00:29:04,000 --> 00:29:12,000
+Like in our example, initially I requested admin resource and after successful login I was redirected
+
+353
+00:29:12,000 --> 00:29:17,000
+not to the success page but to the resource that I originally requested.
+
+354
+00:29:17,000 --> 00:29:20,000
+To understand now how this works.
+
+355
+00:29:20,000 --> 00:29:22,000
+Let's make the log out.
+
+356
+00:29:23,000 --> 00:29:29,000
+According to our configuration to make logout, we need to send a request to the perform logout.
+
+357
+00:29:30,000 --> 00:29:35,000
+And now important thing to them as much things as possible.
+
+358
+00:29:35,000 --> 00:29:39,000
+I mixed two things, but I want you to understand the difference.
+
+359
+00:29:40,000 --> 00:29:47,000
+You can use logout success URL and during the logout in case of success you will be redirected to the
+
+360
+00:29:47,000 --> 00:29:48,000
+configure it URL.
+
+361
+00:29:48,000 --> 00:29:55,000
+But in case you use logout success handler like I do here in the configuration.
+
+362
+00:29:55,000 --> 00:30:02,000
+In this case, logout is processed by this handler and in case you want to make rhetoric to some specific
+
+363
+00:30:02,000 --> 00:30:07,000
+page, need to handle it manually, pay attention.
+
+364
+00:30:07,000 --> 00:30:11,000
+In my logout success handler, I redirect request to the login page.
+
+365
+00:30:11,000 --> 00:30:13,000
+The important thing to note.
+
+366
+00:30:14,000 --> 00:30:17,000
+Now I want to use admin user credentials.
+
+367
+00:30:17,000 --> 00:30:23,000
+I use admin as a username and root as a password and I'm redirected to the home page.
+
+368
+00:30:23,000 --> 00:30:24,000
+Why?
+
+369
+00:30:24,000 --> 00:30:30,000
+Because this is success here as well where I should be redirected in case of the successful login.
+
+370
+00:30:31,000 --> 00:30:38,000
+And previously I didn't request any other resource because after logout I was redirected directly to
+
+371
+00:30:38,000 --> 00:30:40,000
+the login page.
+
+372
+00:30:40,000 --> 00:30:42,000
+I hope I didn't confuse you.
+
+373
+00:30:43,000 --> 00:30:49,000
+Just remember that you always have access to the source code and you can repeat all the steps that I
+
+374
+00:30:49,000 --> 00:30:52,000
+do in the video in order to understand the topic better.
+
+375
+00:30:53,000 --> 00:30:58,000
+And even in case you have any questions, please let me know.
+
+376
+00:30:58,000 --> 00:31:02,000
+You can ask your questions below the video and I will be happy to answer.
+
+377
+00:31:03,000 --> 00:31:05,000
+Let me log out now.
+
+378
+00:31:06,000 --> 00:31:11,000
+Now I want to show you a scenario with the unsuccessful login.
+
+379
+00:31:11,000 --> 00:31:16,000
+I will just use some fake data for the login and let's see what we would receive.
+
+380
+00:31:17,000 --> 00:31:21,000
+Taking into account I have favor handler configured.
+
+381
+00:31:21,000 --> 00:31:27,000
+It handles the favor and it returns me timestamp and exception message like we configure it.
+
+382
+00:31:28,000 --> 00:31:35,000
+Pay attention that in case authentication failure handler is set in this case will not be redirected
+
+383
+00:31:35,000 --> 00:31:39,000
+to the URL that we set with failure URL.
+
+384
+00:31:40,000 --> 00:31:45,000
+So we revealed how to work with spring security and custom login form.
+
+385
+00:31:45,000 --> 00:31:47,000
+Congratulations.
+
+386
+00:31:47,000 --> 00:31:54,000
+And also I promise to show you the default login form that spring security provides out of the box.
+
+387
+00:31:55,000 --> 00:31:57,000
+Let me just command login page.
+
+388
+00:31:57,000 --> 00:31:59,000
+Login process in the URL.
+
+389
+00:31:59,000 --> 00:32:00,000
+Failure.
+
+390
+00:32:00,000 --> 00:32:02,000
+URL Failure Handler.
+
+391
+00:32:02,000 --> 00:32:09,000
+And after commenting and saying I restart the server, let's wait a couple of seconds.
+
+392
+00:32:15,000 --> 00:32:20,000
+And when the server is started, you can see nice look in default login form.
+
+393
+00:32:21,000 --> 00:32:26,000
+In case I use invalid credentials, I would see error message here.
+
+394
+00:32:26,000 --> 00:32:28,000
+Credentials are invalid.
+
+395
+00:32:28,000 --> 00:32:35,000
+As you can see, there is even some error handling out of the box in case I use valid credentials.
+
+396
+00:32:35,000 --> 00:32:37,000
+I am successfully logged in.
+
+397
+00:32:38,000 --> 00:32:40,000
+Taking into account.
+
+398
+00:32:40,000 --> 00:32:43,000
+We are going to use this project for our future examples.
+
+399
+00:32:43,000 --> 00:32:47,000
+I will leave some lines commanded and some of them not.
+
+400
+00:32:47,000 --> 00:32:54,000
+But when you will close this repository, feel free to uncommon relevant lines that you would like to
+
+401
+00:32:54,000 --> 00:32:54,000
+check.
+
+402
+00:32:55,000 --> 00:32:57,000
+That's all what I wanted to share with you today.
+
+403
+00:32:58,000 --> 00:33:01,000
+Let's recap what we have learned in this lesson.
+
+404
+00:33:02,000 --> 00:33:02,000
+Wow.
+
+405
+00:33:02,000 --> 00:33:05,000
+We have learned really a lot today.
+
+406
+00:33:05,000 --> 00:33:10,000
+First of all, I want to congratulate you with configuring spring security in your Web project.
+
+407
+00:33:11,000 --> 00:33:14,000
+This is our first project with spring Security.
+
+408
+00:33:14,000 --> 00:33:20,000
+We learned what spring security dependencies to use and how to configure spring security.
+
+409
+00:33:20,000 --> 00:33:27,000
+Namely, together, we declared all required means and configuration in order to make spring security
+
+410
+00:33:27,000 --> 00:33:28,000
+work.
+
+411
+00:33:28,000 --> 00:33:31,000
+During the configuration of the authentication rules.
+
+412
+00:33:31,000 --> 00:33:37,000
+I explained to you what is the difference between anonymous access and permit all access.
+
+413
+00:33:38,000 --> 00:33:45,000
+We learned different handlers that can be used during the login, namely we learned authentication failure
+
+414
+00:33:45,000 --> 00:33:48,000
+handler and log out success handler.
+
+415
+00:33:48,000 --> 00:33:55,000
+During the demo I showed you end to end flow with login wear custom login form, and with a default
+
+416
+00:33:55,000 --> 00:33:56,000
+login form.
+
+417
+00:33:56,000 --> 00:33:59,000
+It is provided by spring security by default.
+
+418
+00:34:00,000 --> 00:34:04,000
+I hope that you like the lesson and that it was useful for you.
+
+419
+00:34:05,000 --> 00:34:07,000
+Thank you all for your attention.
+
+420
+00:34:07,000 --> 00:34:10,000
+Have a great day and see you in the next lesson.
+
diff --git a/84 - Spring Security/002 Source-code-of-examples-commit-with-changes-.url b/84 - Spring Security/002 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..7afb063fdfb49f5f80983893af9c7e11deb56520
--- /dev/null
+++ b/84 - Spring Security/002 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/fa1f32b831ae40f681525076f3c8bd8928807f48
\ No newline at end of file
diff --git a/84 - Spring Security/003 Login with Database Users, Roles & Privileges_en.srt b/84 - Spring Security/003 Login with Database Users, Roles & Privileges_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..754e2e7e1724fa35c69b8a030fb009895ecb4ad4
--- /dev/null
+++ b/84 - Spring Security/003 Login with Database Users, Roles & Privileges_en.srt
@@ -0,0 +1,1228 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello, Tim.
+
+2
+00:00:06,000 --> 00:00:09,000
+In the previous lesson, we have learned a lot.
+
+3
+00:00:09,000 --> 00:00:14,000
+We did our first spring security project with default and custom login form.
+
+4
+00:00:14,000 --> 00:00:22,000
+We learned how to log out, how to use custom handlers during the login and log out and many other different
+
+5
+00:00:22,000 --> 00:00:26,000
+things, including what roles are.
+
+6
+00:00:26,000 --> 00:00:29,000
+But we still have a lot of things to learn.
+
+7
+00:00:29,000 --> 00:00:36,000
+In the previous lesson, we learned examples with the memory registered users, and I explained to you
+
+8
+00:00:36,000 --> 00:00:40,000
+that in memory, users are often used for demo purposes.
+
+9
+00:00:40,000 --> 00:00:47,000
+In this lesson, we're going to use persistence storage to use users for authentication.
+
+10
+00:00:47,000 --> 00:00:54,000
+I would say that this is one of the most important goals of this lesson, but also we're going to learn
+
+11
+00:00:54,000 --> 00:00:58,000
+such concepts as privilege and authority.
+
+12
+00:00:58,000 --> 00:01:04,000
+I will explain how it is different from the roles that we have learned in the previous lesson.
+
+13
+00:01:04,000 --> 00:01:12,000
+We'll create data structure and build relationships with the entities user role privilege.
+
+14
+00:01:13,000 --> 00:01:17,000
+I will show you how we can configure access based on the privilege.
+
+15
+00:01:18,000 --> 00:01:26,000
+Together will implement custom user details service to authenticate users from the database, even despite
+
+16
+00:01:26,000 --> 00:01:30,000
+the fact that there are no so much words in the agenda for this lesson.
+
+17
+00:01:30,000 --> 00:01:33,000
+We're going to dive really deep today.
+
+18
+00:01:33,000 --> 00:01:39,000
+So let's start our lesson before we jump to practical examples.
+
+19
+00:01:39,000 --> 00:01:45,000
+Let's understand such key concept as privilege and how it is different from the role.
+
+20
+00:01:46,000 --> 00:01:52,000
+We may come up with a requirement where we would like to provide access to the application based on
+
+21
+00:01:52,000 --> 00:01:54,000
+the user roles and privileges.
+
+22
+00:01:55,000 --> 00:02:02,000
+Let's take example of a simple backend application managing the Commerce Store on the basis of management
+
+23
+00:02:02,000 --> 00:02:03,000
+of single order.
+
+24
+00:02:04,000 --> 00:02:07,000
+Imagine that we have admin user.
+
+25
+00:02:07,000 --> 00:02:11,000
+This is the main administrator who can do everything.
+
+26
+00:02:11,000 --> 00:02:17,000
+He can view orders, he can add it, order information and he can delete order.
+
+27
+00:02:17,000 --> 00:02:21,000
+We also have manager role in our system.
+
+28
+00:02:21,000 --> 00:02:29,000
+Manager can view orders and edit them and the user can view orders and just submit a request for editing
+
+29
+00:02:29,000 --> 00:02:31,000
+order which will be updated by manager.
+
+30
+00:02:32,000 --> 00:02:37,000
+In this very, very simplified example, we have three roles and three privileges.
+
+31
+00:02:37,000 --> 00:02:45,000
+They are admin role with read, write, delete privilege manager role with read write privilege user
+
+32
+00:02:45,000 --> 00:02:47,000
+role with read privilege.
+
+33
+00:02:47,000 --> 00:02:49,000
+Does it make sense?
+
+34
+00:02:49,000 --> 00:02:56,000
+Spring security makes it more easy to build these types of rules using the roles and privileges.
+
+35
+00:02:57,000 --> 00:03:02,000
+We can assign roles and privileges to the user during the registration creation.
+
+36
+00:03:03,000 --> 00:03:08,000
+So let's sum it up and come up with the definitions for roles and privileges.
+
+37
+00:03:09,000 --> 00:03:16,000
+Role represents high level role in the system, for example, admin manager, etc..
+
+38
+00:03:16,000 --> 00:03:24,000
+Each role can have low level privileges authorities to do something in the system.
+
+39
+00:03:24,000 --> 00:03:29,000
+The privilege defines a low level of security for a role.
+
+40
+00:03:29,000 --> 00:03:35,000
+For example, admin can read, write, delete, but manager can only read and write.
+
+41
+00:03:35,000 --> 00:03:36,000
+Is it clear?
+
+42
+00:03:37,000 --> 00:03:41,000
+So let me now share with you context of our coding exercise today.
+
+43
+00:03:42,000 --> 00:03:48,000
+In our application we are also going to have three roles and three privileges like we have discussed.
+
+44
+00:03:48,000 --> 00:03:56,000
+Our goal would be to configure access in the following way users with an admin role and read write delete
+
+45
+00:03:56,000 --> 00:04:03,000
+privileges should have access to the admin resource manager resource and home page resource users with
+
+46
+00:04:03,000 --> 00:04:09,000
+the manager role and read write privileges should have access to the manager resource and home page
+
+47
+00:04:09,000 --> 00:04:17,000
+resource and users with the user role and just read privilege should have access to the home page resource
+
+48
+00:04:17,000 --> 00:04:17,000
+only.
+
+49
+00:04:18,000 --> 00:04:25,000
+I believe that it is clear to use a name of the resources is just an example in the production ready
+
+50
+00:04:25,000 --> 00:04:30,000
+application or during the exam task that you are going to have a little bit later.
+
+51
+00:04:30,000 --> 00:04:35,000
+In this course you can configure accesses to different resources.
+
+52
+00:04:35,000 --> 00:04:38,000
+I believe now we are ready for the demo.
+
+53
+00:04:39,000 --> 00:04:43,000
+Today we're going to have a lot of examples and demo.
+
+54
+00:04:43,000 --> 00:04:49,000
+And I want to warn you that in this lesson we are going to use GP Hibernate.
+
+55
+00:04:49,000 --> 00:04:57,000
+That means that in case you are not familiar with GPA concept, something may be unclear for you.
+
+56
+00:04:57,000 --> 00:05:02,000
+In this case I recommend you to watch section about GPA in my course.
+
+57
+00:05:02,000 --> 00:05:03,000
+Java from zero to.
+
+58
+00:05:03,000 --> 00:05:05,000
+This job where we review each topic.
+
+59
+00:05:05,000 --> 00:05:12,000
+One of the notes in the strict sequence, taking into account this lesson about spring security, will
+
+60
+00:05:12,000 --> 00:05:16,000
+put all our focus on the spring security configuration.
+
+61
+00:05:17,000 --> 00:05:23,000
+As always, you can find all source code examples from the video in attachments to the lesson.
+
+62
+00:05:23,000 --> 00:05:27,000
+To start with, let's add all the necessary dependencies.
+
+63
+00:05:27,000 --> 00:05:31,000
+I add GPA and hibernate related dependencies.
+
+64
+00:05:31,000 --> 00:05:37,000
+For the database, I will use my SQL and use my SQL driver for connection.
+
+65
+00:05:37,000 --> 00:05:44,000
+I will not stop on this too much because I want to focus all your attention on the spring security GPA.
+
+66
+00:05:44,000 --> 00:05:51,000
+Hibernate Configuration file is located in the resources source folder in the matter folder.
+
+67
+00:05:52,000 --> 00:05:56,000
+Let's proceed with the review of the main entities that will be used during the lesson.
+
+68
+00:05:57,000 --> 00:06:00,000
+We are going to have user role and privilege.
+
+69
+00:06:01,000 --> 00:06:08,000
+I believe that even on the level of your intuition, you understand what are these entities for?
+
+70
+00:06:08,000 --> 00:06:16,000
+What we need to do is to define these entities and define database design before we proceed with spring
+
+71
+00:06:16,000 --> 00:06:17,000
+security configuration.
+
+72
+00:06:18,000 --> 00:06:25,000
+We need to understand data structure and how these entities will be connected between each other.
+
+73
+00:06:25,000 --> 00:06:32,000
+Because our spring security rules will rely on the information that will fetch from the database.
+
+74
+00:06:32,000 --> 00:06:38,000
+I need to say that the solution proposed in this lesson is just one of the possible solutions about
+
+75
+00:06:38,000 --> 00:06:45,000
+how you can organize user role and privilege entities between each other, which is, in my opinion,
+
+76
+00:06:45,000 --> 00:06:47,000
+the easiest for our understanding.
+
+77
+00:06:47,000 --> 00:06:50,000
+But nevertheless, you can find all the possible solutions.
+
+78
+00:06:51,000 --> 00:06:53,000
+I open user entity.
+
+79
+00:06:53,000 --> 00:06:58,000
+It is located in the persistence package in the entity sub package.
+
+80
+00:06:58,000 --> 00:07:02,000
+Here you can see more or less standard set of fields.
+
+81
+00:07:02,000 --> 00:07:09,000
+First name, last name, email, password and boolean flag to indicate what the user is enabled or disabled.
+
+82
+00:07:10,000 --> 00:07:14,000
+And collection of roles that can be associated with this user.
+
+83
+00:07:15,000 --> 00:07:22,000
+User can have multiple roles and here you can find GP configuration to establish relationship between
+
+84
+00:07:22,000 --> 00:07:23,000
+user and role entity.
+
+85
+00:07:24,000 --> 00:07:29,000
+As I already highlighted, will not cover Gpe in this lesson.
+
+86
+00:07:29,000 --> 00:07:36,000
+If this piece of configuration is not clear, please refer to the GPU hibernate section of my course.
+
+87
+00:07:36,000 --> 00:07:38,000
+Java from zero to first job.
+
+88
+00:07:39,000 --> 00:07:42,000
+The next entity is a role entity.
+
+89
+00:07:42,000 --> 00:07:49,000
+We have a role name here and collection of users because there is many too many relation between the
+
+90
+00:07:49,000 --> 00:07:51,000
+user and the role entity.
+
+91
+00:07:52,000 --> 00:07:58,000
+Another important thing is that role entity has the reference to the collection of the associated privileges.
+
+92
+00:07:59,000 --> 00:08:05,000
+Like we also discussed during the slide review that each role can have multiple privileges.
+
+93
+00:08:05,000 --> 00:08:09,000
+And here is configuration of the mapping between role and privilege entity.
+
+94
+00:08:10,000 --> 00:08:12,000
+There is many to many relation.
+
+95
+00:08:12,000 --> 00:08:19,000
+Each privilege can be assigned to multiple roles, and each role can have multiple privileges.
+
+96
+00:08:20,000 --> 00:08:24,000
+And the last but not the least entity is a privileged entity.
+
+97
+00:08:24,000 --> 00:08:30,000
+It has a name and reference to the collection of roles like we have discussed.
+
+98
+00:08:30,000 --> 00:08:36,000
+There is many to many relationship to support basic operations with these entities.
+
+99
+00:08:36,000 --> 00:08:41,000
+I also created multiple repositories in the REPOSITORIES package.
+
+100
+00:08:41,000 --> 00:08:45,000
+You can find interfaces and implementations.
+
+101
+00:08:45,000 --> 00:08:51,000
+All of them provide basic interface to find entity by name and to save entity.
+
+102
+00:08:51,000 --> 00:08:56,000
+That is enough for the basic requirements of our code and exercise.
+
+103
+00:08:56,000 --> 00:09:01,000
+Take your time to investigate the implementations later if you wish.
+
+104
+00:09:01,000 --> 00:09:07,000
+Like I said, you can find this code examples in attachments to the video lesson.
+
+105
+00:09:07,000 --> 00:09:08,000
+Pay attention here.
+
+106
+00:09:08,000 --> 00:09:11,000
+That one we want to find entity in the database.
+
+107
+00:09:11,000 --> 00:09:20,000
+We use stream API find first it returns this object of optional type because in case we would call get
+
+108
+00:09:20,000 --> 00:09:23,000
+single result and there won't be any result.
+
+109
+00:09:23,000 --> 00:09:27,000
+Exception would be thrown no result exception.
+
+110
+00:09:27,000 --> 00:09:35,000
+So this line helps us to use more than Java API in order to avoid no result exception to implement the
+
+111
+00:09:35,000 --> 00:09:36,000
+code in exercise.
+
+112
+00:09:36,000 --> 00:09:42,000
+According to the requirements that we have discussed, we need to adjust our controllers.
+
+113
+00:09:42,000 --> 00:09:46,000
+Let me open fake controllers for Spring Security demo class.
+
+114
+00:09:46,000 --> 00:09:50,000
+Here I implemented End Point for the manager resource.
+
+115
+00:09:50,000 --> 00:09:56,000
+It will forward us to the manager source, which is simple JSP page.
+
+116
+00:09:56,000 --> 00:09:57,000
+Nothing special.
+
+117
+00:09:58,000 --> 00:10:01,000
+Let me now open user controller.
+
+118
+00:10:01,000 --> 00:10:05,000
+I also updated it in order to support user registration flow.
+
+119
+00:10:05,000 --> 00:10:12,000
+You can see here one point that simply read for access to the JSP page with a registration form.
+
+120
+00:10:12,000 --> 00:10:18,000
+We reviewed with your registration process in the GP port of the learning course Java from zero to first
+
+121
+00:10:18,000 --> 00:10:19,000
+job.
+
+122
+00:10:19,000 --> 00:10:22,000
+That's why I will not stop on it for too long.
+
+123
+00:10:23,000 --> 00:10:23,000
+Pay attention.
+
+124
+00:10:24,000 --> 00:10:32,000
+During the registration of the new user, we assign user role to the new user and save it into the database.
+
+125
+00:10:33,000 --> 00:10:35,000
+Also, I use password and coder.
+
+126
+00:10:35,000 --> 00:10:39,000
+Been to store the password in the database in the encoded format.
+
+127
+00:10:40,000 --> 00:10:47,000
+Now we need to make sure that all required roles, privileges and users exist on the moment of starting
+
+128
+00:10:47,000 --> 00:10:48,000
+of our application.
+
+129
+00:10:49,000 --> 00:10:51,000
+That's why I created class.
+
+130
+00:10:51,000 --> 00:10:53,000
+That is called setup data loader.
+
+131
+00:10:54,000 --> 00:11:00,000
+It implements application listener that is parameterized by context refresh event.
+
+132
+00:11:01,000 --> 00:11:06,000
+We can say that this is implementation of observer design pattern.
+
+133
+00:11:06,000 --> 00:11:14,000
+Also, if you want to learn or design patterns better, please refer to the section Golf patterns of
+
+134
+00:11:14,000 --> 00:11:15,000
+my course.
+
+135
+00:11:15,000 --> 00:11:17,000
+Java from zero to first job.
+
+136
+00:11:17,000 --> 00:11:22,000
+There is a mass that we need to implement and that is called on application event.
+
+137
+00:11:23,000 --> 00:11:30,000
+When this method will be triggered, it will create all required entities to not execute steps once
+
+138
+00:11:30,000 --> 00:11:32,000
+they're executed.
+
+139
+00:11:32,000 --> 00:11:36,000
+I introduced the property it is called is already configured.
+
+140
+00:11:36,000 --> 00:11:41,000
+So in case it is true, we returned from the method.
+
+141
+00:11:41,000 --> 00:11:46,000
+But in case it is false, we proceed with the configuration.
+
+142
+00:11:46,000 --> 00:11:53,000
+We need this boolean variable simply because the context refresh event may be fired multiple times depending
+
+143
+00:11:53,000 --> 00:11:57,000
+on how many contexts we have configured in our application.
+
+144
+00:11:57,000 --> 00:12:00,000
+And we only want to run the setup once.
+
+145
+00:12:01,000 --> 00:12:05,000
+I create three privileges that we discussed, read, write and delete.
+
+146
+00:12:06,000 --> 00:12:12,000
+There are special methods that I created that creates privileges only in case they are not found in
+
+147
+00:12:12,000 --> 00:12:13,000
+the database.
+
+148
+00:12:13,000 --> 00:12:21,000
+As you can see, I use privilege repository to extract privilege by name and in case it is null, I
+
+149
+00:12:21,000 --> 00:12:24,000
+create new privilege and save it into the database.
+
+150
+00:12:25,000 --> 00:12:27,000
+In the similar way, I created three privileges.
+
+151
+00:12:28,000 --> 00:12:35,000
+The next thing that I do, I create a list of privileges that will be associated with the roles.
+
+152
+00:12:35,000 --> 00:12:41,000
+The list of admin privileges consists of read, write and delete privileges.
+
+153
+00:12:41,000 --> 00:12:46,000
+The list of manager privileges consists of read and write privileges.
+
+154
+00:12:47,000 --> 00:12:50,000
+The next thing is to create required roles.
+
+155
+00:12:50,000 --> 00:12:55,000
+I have special masses that creates role in case it wasn't found by name.
+
+156
+00:12:55,000 --> 00:13:00,000
+So I use the role repository to find the role by name.
+
+157
+00:13:00,000 --> 00:13:08,000
+And in case a role wasn't found, I create a new one and set the collection of the associated privileges
+
+158
+00:13:08,000 --> 00:13:10,000
+and save the role.
+
+159
+00:13:10,000 --> 00:13:15,000
+In a similar way, I create three roles admin manager and user.
+
+160
+00:13:16,000 --> 00:13:19,000
+Pay attention that it is important to use prefix role.
+
+161
+00:13:19,000 --> 00:13:25,000
+The score because spring security adds the prefix roll underscore by default.
+
+162
+00:13:26,000 --> 00:13:33,000
+That's why in order we want to refer to the admin row in the database, it should be saved as a row
+
+163
+00:13:33,000 --> 00:13:34,000
+admin.
+
+164
+00:13:35,000 --> 00:13:42,000
+You can change this prefix if you want, but usually there is no specific business need in this.
+
+165
+00:13:42,000 --> 00:13:48,000
+In the next slides I extract rows from the database before configuring users.
+
+166
+00:13:48,000 --> 00:13:51,000
+I want to create two users.
+
+167
+00:13:51,000 --> 00:13:56,000
+One will have admin row and another will have manager row.
+
+168
+00:13:56,000 --> 00:14:04,000
+I want to create them from the code and user with the user role will be created during the registration
+
+169
+00:14:05,000 --> 00:14:12,000
+because usually you don't have public registration of admins and managers in order to not allow everyone
+
+170
+00:14:12,000 --> 00:14:15,000
+to register account and the system as admin.
+
+171
+00:14:16,000 --> 00:14:22,000
+So the reason I said is it creates user in case it is not found in the database.
+
+172
+00:14:22,000 --> 00:14:27,000
+We create two users with the different emails and different passwords.
+
+173
+00:14:27,000 --> 00:14:31,000
+Conversely, there is always room for some more customization.
+
+174
+00:14:31,000 --> 00:14:38,000
+You can also extract first name and last name as message parameters, but this is not critical for the
+
+175
+00:14:38,000 --> 00:14:39,000
+sake of the current example.
+
+176
+00:14:40,000 --> 00:14:47,000
+When users are configured, we change value of our is already configured variable to true in order to
+
+177
+00:14:47,000 --> 00:14:50,000
+not run this code again next time.
+
+178
+00:14:51,000 --> 00:14:56,000
+So if you remember in previous lesson we used in memory User details manager.
+
+179
+00:14:57,000 --> 00:15:04,000
+This time we need to use all the user details service in order to authenticate users from the database.
+
+180
+00:15:04,000 --> 00:15:08,000
+That's why I create a default user Details service.
+
+181
+00:15:08,000 --> 00:15:10,000
+Let's review it together.
+
+182
+00:15:10,000 --> 00:15:16,000
+The main method that we have to implement here is load by user name.
+
+183
+00:15:17,000 --> 00:15:24,000
+I use user repository to extract the user from the database by the email in case user is not found.
+
+184
+00:15:24,000 --> 00:15:32,000
+I return user details without username and without password, but with the user authorities.
+
+185
+00:15:32,000 --> 00:15:39,000
+Important thing to note that in spring API, what we call privilege is also called authority.
+
+186
+00:15:39,000 --> 00:15:44,000
+It is like authority to do something inside the application.
+
+187
+00:15:45,000 --> 00:15:47,000
+This is just a semantic thing.
+
+188
+00:15:47,000 --> 00:15:53,000
+You will see that usually privilege and authority in spring API are used interchangeably.
+
+189
+00:15:53,000 --> 00:15:58,000
+This can be useful if you want to configure guest access in your application.
+
+190
+00:15:59,000 --> 00:16:03,000
+You can see that I use instance of the user class from the Spring Security library.
+
+191
+00:16:04,000 --> 00:16:11,000
+This is a class that implements interface of user details in order to meet the requirements of the interface.
+
+192
+00:16:11,000 --> 00:16:21,000
+We also need to pass such values as IS enabled account, not export credentials not export based on
+
+193
+00:16:21,000 --> 00:16:23,000
+the name of these properties.
+
+194
+00:16:23,000 --> 00:16:31,000
+I bet it is clear that account not export sets the boolean value to reflect was account is export or
+
+195
+00:16:31,000 --> 00:16:33,000
+not, and so forth.
+
+196
+00:16:33,000 --> 00:16:41,000
+Even in case you have any questions, please do not hesitate to ask your questions below the video and
+
+197
+00:16:41,000 --> 00:16:50,000
+I will be happy to answer in case we found user, we populate username, password and his privileges.
+
+198
+00:16:50,000 --> 00:16:57,000
+Here I have mastered that extract all privileges that are associated with the user role and rub them
+
+199
+00:16:57,000 --> 00:17:00,000
+into the list of granted authority objects.
+
+200
+00:17:00,000 --> 00:17:09,000
+So one more time, according to the user API, we need to pass the list of granted authority objects,
+
+201
+00:17:09,000 --> 00:17:13,000
+but we need to create these objects.
+
+202
+00:17:13,000 --> 00:17:21,000
+We can create these objects based on the privileges and to fetch all associated privileges, we need
+
+203
+00:17:21,000 --> 00:17:24,000
+to know the roles of the user.
+
+204
+00:17:24,000 --> 00:17:32,000
+So here is the method that extracts list of privileges for all roles of the user.
+
+205
+00:17:32,000 --> 00:17:36,000
+This list is used as an input argument for the next method.
+
+206
+00:17:36,000 --> 00:17:43,000
+It returns a list of simple granted authority objects based on all privileges.
+
+207
+00:17:43,000 --> 00:17:44,000
+Is it clear?
+
+208
+00:17:45,000 --> 00:17:52,000
+I understand that this may seem confusing, especially when you see this the first time in your life.
+
+209
+00:17:53,000 --> 00:18:00,000
+So just press a pause for a few minutes or just close the repository with the source code examples and
+
+210
+00:18:00,000 --> 00:18:02,000
+explore the code without rush.
+
+211
+00:18:03,000 --> 00:18:10,000
+I'm sure that after spending some time with code reading it line by line, everything will become clear.
+
+212
+00:18:10,000 --> 00:18:16,000
+And in case of any questions, please let me know in the comments below this video.
+
+213
+00:18:18,000 --> 00:18:21,000
+Och, we're done with user details service.
+
+214
+00:18:21,000 --> 00:18:28,000
+And the last thing that we need to do before running the application is adjustment of sprint configuration
+
+215
+00:18:28,000 --> 00:18:29,000
+itself.
+
+216
+00:18:29,000 --> 00:18:32,000
+Let me open web config class.
+
+217
+00:18:32,000 --> 00:18:37,000
+I commanded some configuration from the previous lesson because we will make adjustments.
+
+218
+00:18:38,000 --> 00:18:43,000
+Namely I command it in memory, user details, service and filter chain configuration.
+
+219
+00:18:44,000 --> 00:18:45,000
+For this lesson.
+
+220
+00:18:45,000 --> 00:18:49,000
+You can find configuration a little bit lower here.
+
+221
+00:18:49,000 --> 00:18:56,000
+Let's configure filter chain and I will highlight what is the difference here from what we learned in
+
+222
+00:18:56,000 --> 00:18:57,000
+previous lesson.
+
+223
+00:18:57,000 --> 00:19:04,000
+First of all, pay attention that you can keep using has a role method to restrict access besides the
+
+224
+00:19:04,000 --> 00:19:07,000
+authenticated users with a specific role.
+
+225
+00:19:07,000 --> 00:19:16,000
+I use string admin here but not role underscore admin like we did during the creation of the role because
+
+226
+00:19:16,000 --> 00:19:21,000
+the prefix role underscore is added automatically by spring.
+
+227
+00:19:22,000 --> 00:19:27,000
+The next request matcher that I added is for the manager resource.
+
+228
+00:19:27,000 --> 00:19:31,000
+Pay attention that you can use has authority mass.
+
+229
+00:19:32,000 --> 00:19:38,000
+This method will grant access to the resource based on the authority that the user has.
+
+230
+00:19:38,000 --> 00:19:42,000
+And you remember how we implemented our user details.
+
+231
+00:19:42,000 --> 00:19:44,000
+We specify here.
+
+232
+00:19:44,000 --> 00:19:44,000
+Right?
+
+233
+00:19:44,000 --> 00:19:48,000
+Or sorry, what does it mean for our application?
+
+234
+00:19:48,000 --> 00:19:56,000
+According to our configuration users with admin role and with manager role as write authority, that
+
+235
+00:19:56,000 --> 00:20:03,000
+means that users with the role admin and manager will be able to access this resource.
+
+236
+00:20:04,000 --> 00:20:04,000
+Is it clear?
+
+237
+00:20:06,000 --> 00:20:11,000
+This mapping between the roles and privileges makes the entire security configuration highly flexible
+
+238
+00:20:11,000 --> 00:20:12,000
+and powerful.
+
+239
+00:20:13,000 --> 00:20:17,000
+We can mix and match roles and privileges as granular as necessary.
+
+240
+00:20:18,000 --> 00:20:23,000
+These are the main differences in the configuration of security filter chain.
+
+241
+00:20:24,000 --> 00:20:29,000
+We also need to declare min of default user data service that we have already reviewed.
+
+242
+00:20:30,000 --> 00:20:33,000
+We did a lot of configuration, don't we?
+
+243
+00:20:34,000 --> 00:20:39,000
+So when you heard about Spring Framework, it makes things easier.
+
+244
+00:20:39,000 --> 00:20:47,000
+Now you know what stands behind this Easier on big scale enterprise application, you can save a lot
+
+245
+00:20:47,000 --> 00:20:55,000
+of efforts, but also what is important to achieve stable and predictable execution of your application
+
+246
+00:20:55,000 --> 00:21:00,000
+that is written and configured in the strict but scalable way.
+
+247
+00:21:00,000 --> 00:21:07,000
+But this comes with the requirement of having spring framework related specific knowledge about configuration
+
+248
+00:21:07,000 --> 00:21:09,000
+and what is happening under the hood.
+
+249
+00:21:10,000 --> 00:21:16,000
+We are done with configuration and we are ready for the running of our application.
+
+250
+00:21:16,000 --> 00:21:24,000
+So my recommendation before the first round, please open persistence, XML configuration and check
+
+251
+00:21:24,000 --> 00:21:26,000
+database name first.
+
+252
+00:21:26,000 --> 00:21:29,000
+In this case, database name is Spring.
+
+253
+00:21:29,000 --> 00:21:36,000
+That please is a create such schema in your database or update the name here.
+
+254
+00:21:37,000 --> 00:21:44,000
+Also, in case you don't use my SQL or in case you don't use the default port, feel free to update
+
+255
+00:21:44,000 --> 00:21:45,000
+the whole URL here.
+
+256
+00:21:46,000 --> 00:21:51,000
+Also update schema generation property to the drop and create.
+
+257
+00:21:51,000 --> 00:21:56,000
+This is required in order to create all necessary tables during the first run.
+
+258
+00:21:57,000 --> 00:21:58,000
+Let me show you.
+
+259
+00:21:58,000 --> 00:22:02,000
+So I run the application now.
+
+260
+00:22:02,000 --> 00:22:09,000
+Once application is started, that means that all required schemas are created in the database.
+
+261
+00:22:09,000 --> 00:22:14,000
+I recommend you to change the schema generation property to update for the future.
+
+262
+00:22:15,000 --> 00:22:19,000
+Leave it like this and restart server one more time.
+
+263
+00:22:20,000 --> 00:22:22,000
+When our application is started.
+
+264
+00:22:22,000 --> 00:22:28,000
+Let's check our configurations and make sure that we configured everything properly.
+
+265
+00:22:28,000 --> 00:22:39,000
+To start with, let's enter credentials of the admin user admin, add test dot com and password is admin.
+
+266
+00:22:39,000 --> 00:22:43,000
+So admin user has access to the home page.
+
+267
+00:22:43,000 --> 00:22:44,000
+It is obvious.
+
+268
+00:22:45,000 --> 00:22:52,000
+Admin user also has access to the manager resource and also to the admin resource.
+
+269
+00:22:53,000 --> 00:22:56,000
+Let's look out to log out.
+
+270
+00:22:56,000 --> 00:23:01,000
+I send a request to the perform underscore log out resource.
+
+271
+00:23:02,000 --> 00:23:05,000
+Now let's try management credentials.
+
+272
+00:23:06,000 --> 00:23:10,000
+Managers at test dot com.
+
+273
+00:23:10,000 --> 00:23:12,000
+And password is manager.
+
+274
+00:23:13,000 --> 00:23:16,000
+Manager has access to the home page.
+
+275
+00:23:16,000 --> 00:23:20,000
+Also he has access to the manager resource.
+
+276
+00:23:20,000 --> 00:23:25,000
+But when I try to access admin resource, I see forbidden status code.
+
+277
+00:23:26,000 --> 00:23:28,000
+Everything like we expected.
+
+278
+00:23:29,000 --> 00:23:30,000
+Let me now perform.
+
+279
+00:23:30,000 --> 00:23:31,000
+Log out.
+
+280
+00:23:32,000 --> 00:23:36,000
+Let's register regular user, the register.
+
+281
+00:23:36,000 --> 00:23:37,000
+Regular user.
+
+282
+00:23:37,000 --> 00:23:39,000
+We need to open registration form.
+
+283
+00:23:40,000 --> 00:23:45,000
+Do you remember we created special end points that is called user registration form security demo.
+
+284
+00:23:47,000 --> 00:23:50,000
+And we redirect it to the registration form.
+
+285
+00:23:50,000 --> 00:23:53,000
+Let's come up with some fake data.
+
+286
+00:23:53,000 --> 00:23:58,000
+After we submit the registration form, we are redirected to the login page.
+
+287
+00:23:59,000 --> 00:24:05,000
+Let's enter the email and password that we have just used during the registration.
+
+288
+00:24:06,000 --> 00:24:15,000
+Okay, we're in and we have access to the home page as expected and taking into account all new users
+
+289
+00:24:15,000 --> 00:24:17,000
+are registered with the user role.
+
+290
+00:24:17,000 --> 00:24:23,000
+That means that the user shouldn't have access to the manager, source and admin resource.
+
+291
+00:24:24,000 --> 00:24:25,000
+Let's check this.
+
+292
+00:24:26,000 --> 00:24:32,000
+As you can see, I received forbidden response code when I tried to access manager source.
+
+293
+00:24:32,000 --> 00:24:36,000
+And the same situation is with admin resource.
+
+294
+00:24:36,000 --> 00:24:41,000
+So that proves that our configuration works as expected.
+
+295
+00:24:41,000 --> 00:24:43,000
+Congratulations.
+
+296
+00:24:44,000 --> 00:24:47,000
+That's all what we planned to review in this lesson.
+
+297
+00:24:48,000 --> 00:24:51,000
+Let's recap what we have learned in the lesson.
+
+298
+00:24:52,000 --> 00:24:57,000
+Today we learn how to use users from the database for authentication.
+
+299
+00:24:57,000 --> 00:25:03,000
+I explained to you what privilege authority is and how it is different from the role.
+
+300
+00:25:04,000 --> 00:25:08,000
+We reviewed sample data structure for user role and privilege.
+
+301
+00:25:08,000 --> 00:25:16,000
+I showed you an example of Gpe and how relationships between these entities can be built.
+
+302
+00:25:17,000 --> 00:25:24,000
+Together, we configure IT access based on the privilege and we implement the custom user details service
+
+303
+00:25:24,000 --> 00:25:27,000
+to authenticate users from the database.
+
+304
+00:25:28,000 --> 00:25:29,000
+That's it.
+
+305
+00:25:29,000 --> 00:25:32,000
+I hope you liked the lesson.
+
+306
+00:25:32,000 --> 00:25:34,000
+I'm sure it was useful.
+
+307
+00:25:35,000 --> 00:25:39,000
+Thanks a lot for your attention and see you in the next lesson.
+
diff --git a/84 - Spring Security/003 Source-code-of-examples-commit-with-changes-.url b/84 - Spring Security/003 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..2c0290fb217d47288fa8f983da2c2900d7cca5d9
--- /dev/null
+++ b/84 - Spring Security/003 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/54608d3a38dc7bf0ec826a5210082f931bcf4ce4
\ No newline at end of file
diff --git a/84 - Spring Security/004 Remember Me & Methods Security_en.srt b/84 - Spring Security/004 Remember Me & Methods Security_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..f580583a741342eafbe93b81bbd1f9b9109dfc34
--- /dev/null
+++ b/84 - Spring Security/004 Remember Me & Methods Security_en.srt
@@ -0,0 +1,780 @@
+1
+00:00:06,000 --> 00:00:06,000
+Hello, team.
+
+2
+00:00:06,000 --> 00:00:13,000
+In this lesson, we're going to learn how to implement such feature as Remember Me with spring security.
+
+3
+00:00:14,000 --> 00:00:18,000
+Taking into account this is relatively not big topic for one lesson.
+
+4
+00:00:18,000 --> 00:00:26,000
+We'll also learn method security in the same video because it is often happens that there is some important
+
+5
+00:00:26,000 --> 00:00:30,000
+topic but relatively short for one video lesson.
+
+6
+00:00:30,000 --> 00:00:32,000
+And I still want to share it with you.
+
+7
+00:00:33,000 --> 00:00:36,000
+That's why we have multiple topics in one video.
+
+8
+00:00:37,000 --> 00:00:42,000
+We'll start from Learning to Remember Me feature talking about Remember Me feature.
+
+9
+00:00:42,000 --> 00:00:45,000
+As an experienced user of other web applications.
+
+10
+00:00:45,000 --> 00:00:52,000
+Probably you use a lot of times Remember Me feature on other websites.
+
+11
+00:00:52,000 --> 00:00:59,000
+It is pretty useful in order to avoid redundant login for the same user in the same application over
+
+12
+00:00:59,000 --> 00:01:01,000
+some period of time.
+
+13
+00:01:01,000 --> 00:01:06,000
+And in this lesson, I'm going to show you how it works on real example.
+
+14
+00:01:06,000 --> 00:01:13,000
+Also, we will learn how spring security can help us with authorization on the level of the masses.
+
+15
+00:01:13,000 --> 00:01:21,000
+We'll learn different annotations that will help us in configuration access rules on the level of the
+
+16
+00:01:21,000 --> 00:01:21,000
+method.
+
+17
+00:01:22,000 --> 00:01:31,000
+I'm talking about such annotations as pre authorized post, authorize, secured and enable mass security.
+
+18
+00:01:32,000 --> 00:01:34,000
+Let's start our lesson.
+
+19
+00:01:35,000 --> 00:01:41,000
+Remember Me is a feature that allows the user to enter the application without religion.
+
+20
+00:01:42,000 --> 00:01:50,000
+User's login session terminates after closing the browser, and if user again access the application
+
+21
+00:01:50,000 --> 00:01:54,000
+by opening browser, it prompts for login.
+
+22
+00:01:54,000 --> 00:01:59,000
+But we can avoid this login by using Remember me feature.
+
+23
+00:01:59,000 --> 00:02:07,000
+It stores user's identity into the cookie or database and identifies the user when he's back again.
+
+24
+00:02:08,000 --> 00:02:14,000
+This is typically accomplished by sending the cookie to the browser with the cookie being detected during
+
+25
+00:02:14,000 --> 00:02:19,000
+the future sessions and causing automated login to take place.
+
+26
+00:02:19,000 --> 00:02:26,000
+Screen security provides the necessary hoops for these operations to take place and has two concrete
+
+27
+00:02:26,000 --> 00:02:29,000
+remember me implementations.
+
+28
+00:02:29,000 --> 00:02:37,000
+One uses hashing to preserve the security of cookie based tokens and the other uses a database or other
+
+29
+00:02:37,000 --> 00:02:41,000
+persistent storage mechanism to store the generated tokens.
+
+30
+00:02:42,000 --> 00:02:47,000
+Note that both implementations require a user detailed service.
+
+31
+00:02:47,000 --> 00:02:54,000
+If you use an authentication provider that doesn't use a user detailed service, for example the LDAP
+
+32
+00:02:54,000 --> 00:03:02,000
+provider, it doesn't work unless you also have a user detailed service being in your application context.
+
+33
+00:03:02,000 --> 00:03:07,000
+To be honest, there is not so much theoretical knowledge that we need to learn before jump into the
+
+34
+00:03:07,000 --> 00:03:09,000
+coding exercises.
+
+35
+00:03:09,000 --> 00:03:11,000
+So let me proceed with the screen sharing.
+
+36
+00:03:12,000 --> 00:03:20,000
+So just to remind you that assumption that by this lesson you already learned how to configure spring
+
+37
+00:03:20,000 --> 00:03:26,000
+security on your project and you already understand how to run web application with spring security,
+
+38
+00:03:26,000 --> 00:03:29,000
+a default or custom login form.
+
+39
+00:03:29,000 --> 00:03:35,000
+That's why I will not stop on all configurations that we have learned in the previous lesson.
+
+40
+00:03:35,000 --> 00:03:39,000
+Also, you can find source code examples in attachments to the video.
+
+41
+00:03:40,000 --> 00:03:44,000
+I open class with all my web configuration.
+
+42
+00:03:44,000 --> 00:03:46,000
+It is called web config class.
+
+43
+00:03:47,000 --> 00:03:52,000
+Here in the bottom I will reuse configurations that we created during the previous lesson.
+
+44
+00:03:53,000 --> 00:03:57,000
+In reality, the configuration is relatively simple.
+
+45
+00:03:57,000 --> 00:04:02,000
+When we configure security filter chain, we need to add in configuration.
+
+46
+00:04:02,000 --> 00:04:07,000
+Remember me option and specify key like this.
+
+47
+00:04:07,000 --> 00:04:13,000
+So remember me method returns reference to the remember me configure object.
+
+48
+00:04:14,000 --> 00:04:19,000
+Feel free to explore this type because it provides a lot of configurations.
+
+49
+00:04:19,000 --> 00:04:27,000
+For example, all this remember me feature and identification of the user across different sessions
+
+50
+00:04:27,000 --> 00:04:29,000
+is done with the help of cookie mechanism.
+
+51
+00:04:30,000 --> 00:04:40,000
+So you can configure to use secure cookie only secure cookies can only be sent over an https connection
+
+52
+00:04:40,000 --> 00:04:49,000
+and thus can't be accidentally submitted over http where they could be intercepted like we already discussed.
+
+53
+00:04:49,000 --> 00:04:54,000
+Remember me feature can work only with user details service defined.
+
+54
+00:04:54,000 --> 00:05:02,000
+So in case you don't have user details service being defined in the context, you can use user details
+
+55
+00:05:02,000 --> 00:05:05,000
+Service method to set the user details service.
+
+56
+00:05:06,000 --> 00:05:08,000
+The key mass sets.
+
+57
+00:05:08,000 --> 00:05:13,000
+The key to identify tokens created for Remember me authentication.
+
+58
+00:05:13,000 --> 00:05:15,000
+Let's get back to the configuration.
+
+59
+00:05:16,000 --> 00:05:18,000
+Remember me parameter.
+
+60
+00:05:18,000 --> 00:05:24,000
+That is the name of input parameter in the login form that will be sent to the back end.
+
+61
+00:05:25,000 --> 00:05:33,000
+Let me show you for the sake of the demo I created custom login form similar to the one that we had
+
+62
+00:05:33,000 --> 00:05:35,000
+but with Remember me checkbox.
+
+63
+00:05:35,000 --> 00:05:36,000
+Here it is.
+
+64
+00:05:37,000 --> 00:05:42,000
+Pay attention that there is input type checkbox with the name.
+
+65
+00:05:42,000 --> 00:05:43,000
+Remember.
+
+66
+00:05:43,000 --> 00:05:47,000
+This is the name that we specified in the configuration.
+
+67
+00:05:48,000 --> 00:05:54,000
+Now spring security will understand what configuration to track with.
+
+68
+00:05:54,000 --> 00:05:56,000
+Remember me Cookie name.
+
+69
+00:05:56,000 --> 00:06:00,000
+You can set the name of the cookies that will be stored into the client browser.
+
+70
+00:06:01,000 --> 00:06:03,000
+Basically, that's it.
+
+71
+00:06:03,000 --> 00:06:10,000
+We just need to add this configuration to the security filter chain and make sure that we have relevant
+
+72
+00:06:10,000 --> 00:06:12,000
+checkbox on the front end.
+
+73
+00:06:12,000 --> 00:06:15,000
+So we are ready to start.
+
+74
+00:06:15,000 --> 00:06:18,000
+Let's run the application on the web server.
+
+75
+00:06:19,000 --> 00:06:20,000
+Okay.
+
+76
+00:06:20,000 --> 00:06:24,000
+At the beginning we are redirected to the login page.
+
+77
+00:06:24,000 --> 00:06:32,000
+Lets enter admin credentials, but at the beginning let's not select remember me checkbox.
+
+78
+00:06:32,000 --> 00:06:35,000
+I want to demo use a challenge first.
+
+79
+00:06:35,000 --> 00:06:40,000
+So after successful login we are redirected to the home page.
+
+80
+00:06:41,000 --> 00:06:45,000
+Let me save the URL and close the browser.
+
+81
+00:06:45,000 --> 00:06:53,000
+Now when I open the browser one more time, I paste the same URL and pay attention.
+
+82
+00:06:53,000 --> 00:06:55,000
+I'm redirected to the login page.
+
+83
+00:06:55,000 --> 00:07:02,000
+This has happened because session was interrupted and web server doesn't have information about authenticated
+
+84
+00:07:02,000 --> 00:07:05,000
+user and taking into account.
+
+85
+00:07:05,000 --> 00:07:07,000
+This is security URL.
+
+86
+00:07:07,000 --> 00:07:09,000
+I am redirected back to the login page.
+
+87
+00:07:10,000 --> 00:07:17,000
+Let me use the same credentials for the authentication, but this time let me select remember me checkbox.
+
+88
+00:07:18,000 --> 00:07:19,000
+Okay.
+
+89
+00:07:19,000 --> 00:07:21,000
+We are successfully authenticated.
+
+90
+00:07:22,000 --> 00:07:23,000
+Let's do the same thing.
+
+91
+00:07:23,000 --> 00:07:27,000
+I copy the URL and close the web browser.
+
+92
+00:07:27,000 --> 00:07:30,000
+Now I open it again and paste the URL.
+
+93
+00:07:31,000 --> 00:07:32,000
+And here we are.
+
+94
+00:07:32,000 --> 00:07:36,000
+We don't need to enter our credentials one more time.
+
+95
+00:07:37,000 --> 00:07:42,000
+This is because Spring security managed to add special cookies on the client side.
+
+96
+00:07:43,000 --> 00:07:50,000
+Let me open def tools and in cookies you can find a special cookie with the name that we configured.
+
+97
+00:07:50,000 --> 00:07:51,000
+Here it is.
+
+98
+00:07:52,000 --> 00:07:54,000
+That's how it works.
+
+99
+00:07:54,000 --> 00:08:00,000
+So I believe it is clear for you how remember me feature works.
+
+100
+00:08:00,000 --> 00:08:06,000
+Even in case you have any questions, please ask your questions below the video and I will be happy
+
+101
+00:08:06,000 --> 00:08:07,000
+to answer.
+
+102
+00:08:08,000 --> 00:08:12,000
+Let's learn now how authentication on the level of methods work.
+
+103
+00:08:13,000 --> 00:08:20,000
+Basically, spring security can help us with the authorization of access, not only on the level of
+
+104
+00:08:20,000 --> 00:08:23,000
+web resources, but also on the level of methods.
+
+105
+00:08:24,000 --> 00:08:31,000
+This is an advanced authorization feature that can be used when it is needed just to make sure clients
+
+106
+00:08:31,000 --> 00:08:37,000
+without authority can't execute a line of code that they shouldn't be able to execute.
+
+107
+00:08:38,000 --> 00:08:46,000
+For example, you can secure not just endpoint of deletion of orders, but actually securing the mass
+
+108
+00:08:47,000 --> 00:08:50,000
+that is in charge of order deletion.
+
+109
+00:08:50,000 --> 00:08:54,000
+I hope that you already understood the main rule of security.
+
+110
+00:08:54,000 --> 00:08:56,000
+There is never enough of security.
+
+111
+00:08:57,000 --> 00:08:59,000
+Let me show you an example.
+
+112
+00:09:00,000 --> 00:09:04,000
+I open class fake controllers for spring Security demo.
+
+113
+00:09:04,000 --> 00:09:09,000
+In this class, I created a new endpoint that is called delete order.
+
+114
+00:09:10,000 --> 00:09:18,000
+I also added response body annotation ensured it just tells to write into the response body, the string
+
+115
+00:09:18,000 --> 00:09:19,000
+that is returned from the method.
+
+116
+00:09:20,000 --> 00:09:27,000
+We're going to have a separate lesson where I will explain when will use response, but right now it
+
+117
+00:09:27,000 --> 00:09:29,000
+doesn't play a big difference.
+
+118
+00:09:29,000 --> 00:09:35,000
+I just don't want to create another view to be resolved for the sake of this short demo.
+
+119
+00:09:36,000 --> 00:09:43,000
+The most important thing here is annotation pre authorize this annotation takes spring expression language.
+
+120
+00:09:43,000 --> 00:09:45,000
+What expression can be used here.
+
+121
+00:09:46,000 --> 00:09:48,000
+Let me show you on the slide.
+
+122
+00:09:49,000 --> 00:09:52,000
+Just press a pause for a minute to look through the slide.
+
+123
+00:09:53,000 --> 00:09:57,000
+The method names give us understanding what they do.
+
+124
+00:09:57,000 --> 00:09:58,000
+I hope so.
+
+125
+00:09:59,000 --> 00:10:06,000
+For example, I assume that you are smart enough to understand that has a road map that just verifies
+
+126
+00:10:06,000 --> 00:10:07,000
+the role.
+
+127
+00:10:07,000 --> 00:10:15,000
+Has any role returns through if the currently authenticated user has one of the listed rows and so on.
+
+128
+00:10:15,000 --> 00:10:19,000
+These are examples of expressions that you can use in the process.
+
+129
+00:10:19,000 --> 00:10:21,000
+Rice annotation to.
+
+130
+00:10:21,000 --> 00:10:24,000
+Let's get back to the code example.
+
+131
+00:10:24,000 --> 00:10:32,000
+So in this imaginary example, let's give the right to users with the admin role and manager role to
+
+132
+00:10:32,000 --> 00:10:33,000
+execute this message.
+
+133
+00:10:34,000 --> 00:10:40,000
+Actually, there is one more annotations that can help you with method authorization.
+
+134
+00:10:40,000 --> 00:10:50,000
+It is called Host Authorize and you can see command here, both prior authorize and post authorized
+
+135
+00:10:50,000 --> 00:10:54,000
+annotations provide expression based access control.
+
+136
+00:10:55,000 --> 00:11:00,000
+So Criticas can be written using spring expression language.
+
+137
+00:11:00,000 --> 00:11:07,000
+The authorized annotation checks the given expression before entering the method, whereas the post
+
+138
+00:11:07,000 --> 00:11:12,000
+authorized annotation verifies it after the execution of the method.
+
+139
+00:11:13,000 --> 00:11:20,000
+In most business cases, there is no need to let code be executed and only after that verify something
+
+140
+00:11:21,000 --> 00:11:26,000
+from the performance standpoint and from the standpoint of consistency of the system.
+
+141
+00:11:26,000 --> 00:11:30,000
+It is better to check authority before the code gets executed.
+
+142
+00:11:31,000 --> 00:11:38,000
+That's why, in my opinion, where authorized annotation is used more often, but still you have the
+
+143
+00:11:38,000 --> 00:11:40,000
+options to choose from.
+
+144
+00:11:40,000 --> 00:11:43,000
+There is also secure annotation.
+
+145
+00:11:44,000 --> 00:11:48,000
+Security annotation doesn't support expression language.
+
+146
+00:11:48,000 --> 00:11:56,000
+Basically, if you just need to specify a role or array of roles, you can use this annotation.
+
+147
+00:11:56,000 --> 00:12:05,000
+I also kept it commanded here basically secure annotation with an array of roles like it is specified
+
+148
+00:12:05,000 --> 00:12:08,000
+here and has any role expression.
+
+149
+00:12:08,000 --> 00:12:11,000
+Language will cause the same effect.
+
+150
+00:12:11,000 --> 00:12:14,000
+It is up to you which one to choose.
+
+151
+00:12:14,000 --> 00:12:22,000
+I really don't have any specific preference just to highlight that per authorize is more flexible because
+
+152
+00:12:22,000 --> 00:12:30,000
+I can use spring expression language there, but you are welcome to clone the repository and common
+
+153
+00:12:30,000 --> 00:12:33,000
+annotations and check the effect by itself.
+
+154
+00:12:34,000 --> 00:12:42,000
+If we find ourselves using the same security annotation for every method within one class, we can consider
+
+155
+00:12:42,000 --> 00:12:45,000
+putting that annotation at class level.
+
+156
+00:12:45,000 --> 00:12:54,000
+So basically you can use the same authorized annotation on the class level or you can use multiple annotations
+
+157
+00:12:54,000 --> 00:12:55,000
+at the same time.
+
+158
+00:12:55,000 --> 00:12:57,000
+It is up to you.
+
+159
+00:12:58,000 --> 00:12:59,000
+Important thing to note.
+
+160
+00:12:59,000 --> 00:13:05,000
+By default, spring ATP production is used to apply message security.
+
+161
+00:13:05,000 --> 00:13:12,000
+We are going to learn what sprint aspect oriented programming is later, but you can imagine this as
+
+162
+00:13:12,000 --> 00:13:15,000
+method wrapping something.
+
+163
+00:13:15,000 --> 00:13:20,000
+What is executed before the method invocation and after massive invocation.
+
+164
+00:13:20,000 --> 00:13:29,000
+And if a secured method A is called by another method within the same class, security in A is ignored
+
+165
+00:13:29,000 --> 00:13:30,000
+altogether.
+
+166
+00:13:31,000 --> 00:13:37,000
+This means method A will be executed without any security checking.
+
+167
+00:13:37,000 --> 00:13:40,000
+The same applies to private masses.
+
+168
+00:13:40,000 --> 00:13:46,000
+And now the important thing is to add one more annotation to the configuration.
+
+169
+00:13:46,000 --> 00:13:50,000
+Let me open the config class here.
+
+170
+00:13:50,000 --> 00:13:57,000
+In the web config class, I added one more annotation that is called enable method security with purpose
+
+171
+00:13:57,000 --> 00:13:59,000
+enabled properties set to true.
+
+172
+00:14:00,000 --> 00:14:08,000
+This is mandatory to enable prayer post authorize annotation authorization with methods.
+
+173
+00:14:09,000 --> 00:14:16,000
+In case you want to have secured annotation enabled, you need to set secured enabled to true.
+
+174
+00:14:17,000 --> 00:14:19,000
+Now we're all set.
+
+175
+00:14:19,000 --> 00:14:22,000
+Let me open the browser and login with the test credentials.
+
+176
+00:14:22,000 --> 00:14:31,000
+Username is our test email, which is TX at TX dot com and the password is test.
+
+177
+00:14:32,000 --> 00:14:39,000
+We created this user in our previous lesson and in the URL, I want to hit delete order URL.
+
+178
+00:14:39,000 --> 00:14:46,000
+And you can see our generic exception handler that we configured in previous lessons about exception
+
+179
+00:14:46,000 --> 00:14:47,000
+handling in Sprint.
+
+180
+00:14:47,000 --> 00:14:54,000
+But from the exception message, you can see that exception appeared because of the access denied.
+
+181
+00:14:55,000 --> 00:14:56,000
+Let me log out.
+
+182
+00:14:57,000 --> 00:15:00,000
+I send a request to the performed logout resource.
+
+183
+00:15:00,000 --> 00:15:11,000
+And now I want to login with the admin credentials admin add test dot com and password admin with send
+
+184
+00:15:11,000 --> 00:15:13,000
+request to the delete order.
+
+185
+00:15:14,000 --> 00:15:16,000
+And we see that order is deleted.
+
+186
+00:15:17,000 --> 00:15:18,000
+Super.
+
+187
+00:15:18,000 --> 00:15:20,000
+That's what we expected.
+
+188
+00:15:21,000 --> 00:15:24,000
+That's all what I wanted to share with you in this lesson.
+
+189
+00:15:24,000 --> 00:15:28,000
+Let's recap what we have learned in the video.
+
+190
+00:15:28,000 --> 00:15:34,000
+In the lesson we learned how to configure Remember Me feature with the help of spring security.
+
+191
+00:15:34,000 --> 00:15:39,000
+After that, we switched our focus on the securing masses.
+
+192
+00:15:40,000 --> 00:15:48,000
+We learned how to work with, authorize, post, authorize secured and enable message security annotations.
+
+193
+00:15:49,000 --> 00:15:51,000
+That's all for this lesson.
+
+194
+00:15:51,000 --> 00:15:53,000
+Thanks a lot for your attention.
+
+195
+00:15:53,000 --> 00:15:56,000
+Have a great day and see you in the next lesson.
+
diff --git a/84 - Spring Security/004 Source-code-of-examples-commit-with-changes-.url b/84 - Spring Security/004 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..263003d72997494d471b054a3ee7453740cd5040
--- /dev/null
+++ b/84 - Spring Security/004 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/9c0322078c8402104870492f91fc9713fc5f615a
\ No newline at end of file
diff --git a/84 - Spring Security/005 Source-code-of-examples-commit-with-changes-.url b/84 - Spring Security/005 Source-code-of-examples-commit-with-changes-.url
new file mode 100644
index 0000000000000000000000000000000000000000..d2e151ff76c27446d8f2c8f00dd9c71361824458
--- /dev/null
+++ b/84 - Spring Security/005 Source-code-of-examples-commit-with-changes-.url
@@ -0,0 +1,2 @@
+[InternetShortcut]
+URL=https://github.com/AndriiPiatakha/java-learnit-spring-web/commit/8dddc2feb47bce4664713763e10e3fd9fda9648b
\ No newline at end of file
diff --git a/84 - Spring Security/005 Spring Security Architecture & Authentication Provider_en.srt b/84 - Spring Security/005 Spring Security Architecture & Authentication Provider_en.srt
new file mode 100644
index 0000000000000000000000000000000000000000..722731df15477d4e5b6070d0421ce3989593219a
--- /dev/null
+++ b/84 - Spring Security/005 Spring Security Architecture & Authentication Provider_en.srt
@@ -0,0 +1,832 @@
+1
+00:00:05,000 --> 00:00:06,000
+Hello team.
+
+2
+00:00:06,000 --> 00:00:12,000
+In this lesson we are going to learn spring security architecture in more details and also we are going
+
+3
+00:00:12,000 --> 00:00:19,000
+to learn more flexible way to authenticate users through the customization of authentication provider.
+
+4
+00:00:19,000 --> 00:00:26,000
+We are going to start this lesson from the review of the spring security architecture and understanding
+
+5
+00:00:26,000 --> 00:00:28,000
+of its key components.
+
+6
+00:00:28,000 --> 00:00:35,000
+We are going to understand what authentication filter spring security context, authentication manager,
+
+7
+00:00:35,000 --> 00:00:40,000
+authentication provider, user details, service password encoder are.
+
+8
+00:00:40,000 --> 00:00:45,000
+And we are also going to understand the connection of these items between each other.
+
+9
+00:00:45,000 --> 00:00:52,000
+To understand the big picture, I'm going to explain you the business case when you need to implement
+
+10
+00:00:52,000 --> 00:00:58,000
+your custom authentication provider and we are going to review code examples with the authentication
+
+11
+00:00:58,000 --> 00:01:00,000
+provider in action.
+
+12
+00:01:00,000 --> 00:01:02,000
+Let's start our lesson.
+
+13
+00:01:03,000 --> 00:01:09,000
+Before going further, let's review spring security architecture a little bit closer to understand the
+
+14
+00:01:09,000 --> 00:01:13,000
+place of the authentication provider on the big picture.
+
+15
+00:01:13,000 --> 00:01:18,000
+I'm going to explain you structural components of the spring security.
+
+16
+00:01:18,000 --> 00:01:24,000
+If you didn't skip previous lessons, you already have experience with the spring security.
+
+17
+00:01:24,000 --> 00:01:30,000
+And the information that I'm going to share with you on this slide is going to help you to structure
+
+18
+00:01:30,000 --> 00:01:32,000
+the knowledge that you already have.
+
+19
+00:01:33,000 --> 00:01:35,000
+Authentication Filter.
+
+20
+00:01:35,000 --> 00:01:41,000
+The first component in the chain that you can see on the slide is authentication filter.
+
+21
+00:01:41,000 --> 00:01:44,000
+Let me explain you why this is needed.
+
+22
+00:01:44,000 --> 00:01:51,000
+Basically, this is the filter that intercepts requests and attempts to authenticate it.
+
+23
+00:01:51,000 --> 00:01:59,000
+In spring security, it converts the request to an authentication object and delegates the authentication
+
+24
+00:01:59,000 --> 00:02:01,000
+to the authentication manager.
+
+25
+00:02:02,000 --> 00:02:04,000
+Spring security context.
+
+26
+00:02:04,000 --> 00:02:10,000
+On this diagram, you can see that authentication filter interacts with the spring security context.
+
+27
+00:02:11,000 --> 00:02:12,000
+What is it?
+
+28
+00:02:12,000 --> 00:02:19,000
+This is where the details of the currently authenticated user are stored on successful authentication.
+
+29
+00:02:20,000 --> 00:02:26,000
+The authentication object is then available throughout the application for the session.
+
+30
+00:02:26,000 --> 00:02:34,000
+So if we need the username or any other user details, we need to get the security context first.
+
+31
+00:02:34,000 --> 00:02:36,000
+Authentication Manager.
+
+32
+00:02:37,000 --> 00:02:44,000
+Another structural elements that our authentication filter interacts with according to the diagram is
+
+33
+00:02:44,000 --> 00:02:45,000
+authentication manager.
+
+34
+00:02:45,000 --> 00:02:49,000
+It is the main strategy interface for authentication.
+
+35
+00:02:49,000 --> 00:02:55,000
+It uses the lone method authenticate to authenticate the request.
+
+36
+00:02:56,000 --> 00:03:04,000
+The authenticate method performs the authentication and returns an authentication object on successful
+
+37
+00:03:04,000 --> 00:03:11,000
+authentication or throw an authentication exception in case of authentication failure.
+
+38
+00:03:11,000 --> 00:03:16,000
+If the method can't decide, it will return null.
+
+39
+00:03:16,000 --> 00:03:24,000
+The process of authentication in this process is delegated to the authentication provider.
+
+40
+00:03:24,000 --> 00:03:28,000
+Let's understand now what an authentication provider is.
+
+41
+00:03:29,000 --> 00:03:31,000
+Authentication Manager Delegates.
+
+42
+00:03:31,000 --> 00:03:39,000
+The process of fetching user details and persistent information about the user to one or more authentication
+
+43
+00:03:39,000 --> 00:03:40,000
+provider instances.
+
+44
+00:03:41,000 --> 00:03:46,000
+We can register multiple authentication providers in the authentication manager.
+
+45
+00:03:47,000 --> 00:03:55,000
+You can specify multiple authentication providers, for example, one that looks for users in the LDAP
+
+46
+00:03:55,000 --> 00:03:59,000
+database and another that looks in an SQL database.
+
+47
+00:04:00,000 --> 00:04:06,000
+Any class implementing the authentication provider interface must implement two methods.
+
+48
+00:04:06,000 --> 00:04:10,000
+They are authenticate and supports.
+
+49
+00:04:11,000 --> 00:04:14,000
+Let me explain you supports method first.
+
+50
+00:04:15,000 --> 00:04:21,000
+It is used to check if the particular authentication type is supported by our authentication provider
+
+51
+00:04:21,000 --> 00:04:23,000
+implementation class.
+
+52
+00:04:23,000 --> 00:04:28,000
+If it is supported, it returns true or else false.
+
+53
+00:04:29,000 --> 00:04:31,000
+Next, the authenticate method.
+
+54
+00:04:32,000 --> 00:04:35,000
+Here is where the authentication occurs.
+
+55
+00:04:35,000 --> 00:04:41,000
+If the authentication type is supported, the process of authentication is started.
+
+56
+00:04:41,000 --> 00:04:48,000
+If you remember, we already had the lesson where we implemented our custom user details service and
+
+57
+00:04:48,000 --> 00:04:54,000
+the authenticate method is exactly the place where we can use a load user by username method of the
+
+58
+00:04:54,000 --> 00:04:57,000
+user details service implementation.
+
+59
+00:04:57,000 --> 00:05:04,000
+If the user is not found, authenticate method can throw a username not found exception.
+
+60
+00:05:04,000 --> 00:05:12,000
+We can use authentication object to fetch all necessary data for the authentication, namely to find
+
+61
+00:05:12,000 --> 00:05:14,000
+user in the database.
+
+62
+00:05:14,000 --> 00:05:16,000
+We need username first.
+
+63
+00:05:16,000 --> 00:05:23,000
+After that we may need to compare password provided with the password that is stored in the database.
+
+64
+00:05:23,000 --> 00:05:30,000
+Authentication object that is passed to the authenticate method as a method argument has method that
+
+65
+00:05:30,000 --> 00:05:32,000
+is called get credentials.
+
+66
+00:05:32,000 --> 00:05:34,000
+Don't worry.
+
+67
+00:05:34,000 --> 00:05:40,000
+Today during the practical code examples, I'm going to show you more details about the structure of
+
+68
+00:05:40,000 --> 00:05:41,000
+the authentication object.
+
+69
+00:05:42,000 --> 00:05:50,000
+If two passwords match each other, I mean one from the database to the one provided by user, it is
+
+70
+00:05:50,000 --> 00:05:52,000
+a successful scenario.
+
+71
+00:05:53,000 --> 00:06:00,000
+Then we can return an authentication object from this method which will be stored in the security context.
+
+72
+00:06:00,000 --> 00:06:04,000
+So authentication manager uses authentication provider.
+
+73
+00:06:05,000 --> 00:06:07,000
+User detail service.
+
+74
+00:06:08,000 --> 00:06:15,000
+So as I told you, we use user detail service to retrieve data about our user to make decisions about
+
+75
+00:06:15,000 --> 00:06:17,000
+authentication.
+
+76
+00:06:17,000 --> 00:06:24,000
+This interface makes us provide implementation for the method that is called load user by user name.
+
+77
+00:06:24,000 --> 00:06:25,000
+Exactly.
+
+78
+00:06:25,000 --> 00:06:32,000
+In that method, we implement logic of fetching user details from the database and in the lessons it
+
+79
+00:06:32,000 --> 00:06:36,000
+is called login with database users, roles and privileges.
+
+80
+00:06:36,000 --> 00:06:41,000
+We already implemented our custom user details service together.
+
+81
+00:06:41,000 --> 00:06:46,000
+If you want to refresh your knowledge, feel free to get back to that lesson.
+
+82
+00:06:46,000 --> 00:06:52,000
+The method will throw a username not found exception if the user is not found.
+
+83
+00:06:53,000 --> 00:07:00,000
+Password and code to compare password that is stored in the database with the password provided by the
+
+84
+00:07:00,000 --> 00:07:00,000
+user.
+
+85
+00:07:00,000 --> 00:07:07,000
+We need to use password encoder because the rule of thumb is to store passwords in the database in the
+
+86
+00:07:07,000 --> 00:07:14,000
+encoded format and to make sure that the password provided by the user matches its encoded version in
+
+87
+00:07:14,000 --> 00:07:15,000
+the database.
+
+88
+00:07:15,000 --> 00:07:17,000
+We need password encoder.
+
+89
+00:07:18,000 --> 00:07:24,000
+Until spring security version for the use of the password encoder was optional.
+
+90
+00:07:24,000 --> 00:07:29,000
+The user could store plain text password using in-memory authentication.
+
+91
+00:07:29,000 --> 00:07:36,000
+But starting from the spring security version five Spring mandated the use of password encoder to store
+
+92
+00:07:36,000 --> 00:07:37,000
+passwords.
+
+93
+00:07:37,000 --> 00:07:43,000
+This includes the user's password using one of its many implementations.
+
+94
+00:07:43,000 --> 00:07:49,000
+The most common of its implementations is the decrypt password encoder.
+
+95
+00:07:49,000 --> 00:07:56,000
+Also, we can use an instance of the no op password encoder for our development purposes.
+
+96
+00:07:56,000 --> 00:08:03,000
+It will allow passwords to be stored in plain text, but it is not supposed to be used for production
+
+97
+00:08:03,000 --> 00:08:05,000
+or real world applications.
+
+98
+00:08:05,000 --> 00:08:12,000
+Let me make an overview of business need in customization of authentication provider instead of using
+
+99
+00:08:12,000 --> 00:08:14,000
+the one out of the box.
+
+100
+00:08:14,000 --> 00:08:20,000
+As you may already understand, spring Security introduces a lot of opportunities for customization
+
+101
+00:08:20,000 --> 00:08:27,000
+and optimization in order we could implement security mechanism of different level of complexity.
+
+102
+00:08:27,000 --> 00:08:34,000
+This customization starts from the custom login page that we have already learned in the previous lessons
+
+103
+00:08:34,000 --> 00:08:41,000
+to the definition of our own custom authentication providers and authentication filters.
+
+104
+00:08:41,000 --> 00:08:49,000
+So if we want, and in case of the business need, we can build authentication process with simple username
+
+105
+00:08:49,000 --> 00:08:57,000
+and password or implement some complex solution with two factor authentication using tokens and one
+
+106
+00:08:57,000 --> 00:08:59,000
+time passwords.
+
+107
+00:08:59,000 --> 00:09:07,000
+Also, there can be need to use different databases relational and non-relational using various password
+
+108
+00:09:07,000 --> 00:09:09,000
+encoders limit.
+
+109
+00:09:09,000 --> 00:09:13,000
+The amount of attempts look malicious users and lots more.
+
+110
+00:09:14,000 --> 00:09:17,000
+To customize your authentication process.
+
+111
+00:09:17,000 --> 00:09:21,000
+We need to create our own authentication provider.
+
+112
+00:09:22,000 --> 00:09:22,000
+Wow.
+
+113
+00:09:22,000 --> 00:09:28,000
+I believe we did a great and extensive overview of the spring security architecture.
+
+114
+00:09:28,000 --> 00:09:34,000
+Now it is time for us to jump to the coding exercise and review code examples that I've prepared for
+
+115
+00:09:34,000 --> 00:09:35,000
+you.
+
+116
+00:09:35,000 --> 00:09:42,000
+So the goal of our today's coding exercise is to learn how to set up an authentication provider in spring
+
+117
+00:09:42,000 --> 00:09:50,000
+security, allowing for additional flexibility compared to the standard scenario using a simple user
+
+118
+00:09:50,000 --> 00:09:52,000
+details service.
+
+119
+00:09:52,000 --> 00:09:57,000
+As always, you can find the link to the source code in attachments to the video.
+
+120
+00:09:58,000 --> 00:10:05,000
+Let's start from the definition of our custom authentication provider as a separate component.
+
+121
+00:10:05,000 --> 00:10:10,000
+In the security package, you can find the new class that I created.
+
+122
+00:10:10,000 --> 00:10:14,000
+It is called default authentication provider.
+
+123
+00:10:15,000 --> 00:10:19,000
+It implements interface of authentication provider.
+
+124
+00:10:19,000 --> 00:10:27,000
+Thus it has to implement two methods supports that will be called first and authenticate method.
+
+125
+00:10:28,000 --> 00:10:31,000
+Let's start with you from the supports method.
+
+126
+00:10:32,000 --> 00:10:39,000
+I inserted few console outputs here in order to show you the moment when we entered this message.
+
+127
+00:10:40,000 --> 00:10:46,000
+Also, I printed class of the authentication object that we received as method argument.
+
+128
+00:10:46,000 --> 00:10:51,000
+It will be username password authentication token.
+
+129
+00:10:51,000 --> 00:10:58,000
+This is a simplest extension of the abstract authentication token class that simply contains username
+
+130
+00:10:58,000 --> 00:10:59,000
+and password.
+
+131
+00:11:00,000 --> 00:11:07,000
+And if we would do everything correct with the rest of our configuration we are supposed to receive
+
+132
+00:11:07,000 --> 00:11:08,000
+here.
+
+133
+00:11:08,000 --> 00:11:16,000
+True, that would mean that we can proceed with the execution of the second method that is called authenticate.
+
+134
+00:11:17,000 --> 00:11:22,000
+This is the method where we can implement our custom logic of authentication.
+
+135
+00:11:22,000 --> 00:11:27,000
+Let's imagine that you want to limit the amount of unsuccessful attempts, for example.
+
+136
+00:11:28,000 --> 00:11:35,000
+This is exactly the place where you can implement this business logic or any other business related
+
+137
+00:11:35,000 --> 00:11:36,000
+logic.
+
+138
+00:11:36,000 --> 00:11:44,000
+In the authenticate method, I print console output just to indicate the moment when we enter this method.
+
+139
+00:11:44,000 --> 00:11:49,000
+After that I use authentication object to extract username and password.
+
+140
+00:11:50,000 --> 00:11:57,000
+I extract username with the method, get name and extract password by calling get credentials method
+
+141
+00:11:57,000 --> 00:12:00,000
+and convert and returned object to string.
+
+142
+00:12:01,000 --> 00:12:08,000
+After that, for demo and debugging purposes, I print the console authentication, object, username,
+
+143
+00:12:08,000 --> 00:12:12,000
+password and results of such methods as get details.
+
+144
+00:12:12,000 --> 00:12:20,000
+By the way, this method can be used to obtain additional details about the authentication request,
+
+145
+00:12:20,000 --> 00:12:26,000
+like for example, IP address, session ID certificate, serial number, etcetera.
+
+146
+00:12:27,000 --> 00:12:34,000
+Yet principle should return us the username in case we use username and password for authentication
+
+147
+00:12:34,000 --> 00:12:35,000
+request.
+
+148
+00:12:35,000 --> 00:12:44,000
+Many of authentication providers will return user details as principal and we also can request authorities
+
+149
+00:12:44,000 --> 00:12:49,000
+in case we use just username and password for authentication request.
+
+150
+00:12:49,000 --> 00:12:53,000
+There will not be any granted authorities by default.
+
+151
+00:12:54,000 --> 00:13:01,000
+This will be the task of our user detail service to extract granted authorities based on the configured
+
+152
+00:13:01,000 --> 00:13:03,000
+privileges and roles.
+
+153
+00:13:04,000 --> 00:13:11,000
+After that, I'm going to use bean of the user details service that I injected to the object.
+
+154
+00:13:11,000 --> 00:13:17,000
+I use this object to extract user details from the persistent storage by the username.
+
+155
+00:13:17,000 --> 00:13:24,000
+In this example, I used implementation that we have created in the one of the previous lessons when
+
+156
+00:13:24,000 --> 00:13:28,000
+we created custom implementation of the user details service.
+
+157
+00:13:28,000 --> 00:13:36,000
+That's why I wouldn't stop too much on review of this class because we created it together and I don't
+
+158
+00:13:36,000 --> 00:13:38,000
+want to repeat myself.
+
+159
+00:13:38,000 --> 00:13:46,000
+In case user detail service can't find anything where user details service you can either throw exception
+
+160
+00:13:46,000 --> 00:13:47,000
+or return a null.
+
+161
+00:13:47,000 --> 00:13:53,000
+It depends on your implementation and needs, so it is up to you.
+
+162
+00:13:53,000 --> 00:14:01,000
+In case user is not null and user details service returned us something, then we need to verify whether
+
+163
+00:14:01,000 --> 00:14:09,000
+password provided in the authentication request and encrypted password stored in the database matches.
+
+164
+00:14:09,000 --> 00:14:15,000
+For this I use password encoder bin that I also injected into this class.
+
+165
+00:14:15,000 --> 00:14:23,000
+I implemented separate method is password valid that basically verifies whether two passwords match
+
+166
+00:14:23,000 --> 00:14:24,000
+each other.
+
+167
+00:14:25,000 --> 00:14:26,000
+In case?
+
+168
+00:14:26,000 --> 00:14:26,000
+Yes.
+
+169
+00:14:27,000 --> 00:14:31,000
+Then I return username password authentication token.
+
+170
+00:14:31,000 --> 00:14:37,000
+I pass username, password and list of granted authorities to construct this object.
+
+171
+00:14:37,000 --> 00:14:43,000
+In case passwords doesn't match, I throw bad credentials exception.
+
+172
+00:14:43,000 --> 00:14:47,000
+Basically we removed all the authentication provider.
+
+173
+00:14:48,000 --> 00:14:56,000
+Now, the only remaining thing that we have to do is just to register our custom provider in the authentication
+
+174
+00:14:56,000 --> 00:14:57,000
+manager.
+
+175
+00:14:57,000 --> 00:15:00,000
+Let me show you how to do this.
+
+176
+00:15:00,000 --> 00:15:10,000
+I open class with all my configurations and where I configure beans, I open Web.config class and I
+
+177
+00:15:10,000 --> 00:15:17,000
+scroll to the bottom because at the bottom of the file I added configuration that is specific to this
+
+178
+00:15:17,000 --> 00:15:17,000
+lesson.
+
+179
+00:15:18,000 --> 00:15:26,000
+Here I even put signs that examples below are for the demo of the customer authentication provider in
+
+180
+00:15:26,000 --> 00:15:28,000
+auth manager method.
+
+181
+00:15:28,000 --> 00:15:35,000
+I get the reference to the authentication manager builder object using the HTTP security object.
+
+182
+00:15:35,000 --> 00:15:43,000
+Pay attention to these lines and the API that I use to get the reference to the builder and using builder
+
+183
+00:15:43,000 --> 00:15:52,000
+I register authentication provider and auth provider is a method that defines the bean of authentication
+
+184
+00:15:52,000 --> 00:15:53,000
+provider.
+
+185
+00:15:53,000 --> 00:16:00,000
+And here is our bean of the user details service that is injected into our authentication provider and
+
+186
+00:16:00,000 --> 00:16:05,000
+used to fetch the user details from the persistence storage.
+
+187
+00:16:05,000 --> 00:16:11,000
+Password encoder also registered as a bin in this file in previous lessons.
+
+188
+00:16:11,000 --> 00:16:16,000
+Let's run the server and see what we have at the beginning.
+
+189
+00:16:16,000 --> 00:16:20,000
+Let me insert admin credentials in the username.
+
+190
+00:16:20,000 --> 00:16:24,000
+I specify admin add test.com.
+
+191
+00:16:25,000 --> 00:16:31,000
+In the password field, I specify admin and I'm successfully logged in.
+
+192
+00:16:31,000 --> 00:16:34,000
+Let's explore the console output.
+
+193
+00:16:34,000 --> 00:16:38,000
+You can see that at the beginning we entered supports method.
+
+194
+00:16:39,000 --> 00:16:45,000
+Our supports method returned true and we were forwarded to the authenticate method.
+
+195
+00:16:46,000 --> 00:16:54,000
+Here you can find string representation of the authentication, object, username and password used.
+
+196
+00:16:54,000 --> 00:17:00,000
+Basically all system outputs that we printed for debugging and demo purposes.
+
+197
+00:17:01,000 --> 00:17:08,000
+If I change the URL to access admin restricted resource and I would type test admin here.
+
+198
+00:17:08,000 --> 00:17:14,000
+If you remember from previous lessons, this is the resource that we created in previous lessons and
+
+199
+00:17:14,000 --> 00:17:18,000
+secured it for only those who has admin role.
+
+200
+00:17:19,000 --> 00:17:27,000
+Then I'm redirected to the admin page that proves that granted, authorities were populated as expected.
+
+201
+00:17:27,000 --> 00:17:30,000
+That's all what I wanted to share with you in this lesson.
+
+202
+00:17:30,000 --> 00:17:39,000
+Let's recap what we have learned today in the lesson we learned spring security architecture and its
+
+203
+00:17:39,000 --> 00:17:46,000
+structural elements, including but not limited to authentication, filter spring security context,
+
+204
+00:17:46,000 --> 00:17:53,000
+authentication manager, authentication provider, user details, service and password encoder.
+
+205
+00:17:53,000 --> 00:17:58,000
+Also, we had practical coding exercises to see how it works all together.
+
+206
+00:17:59,000 --> 00:18:01,000
+That's all for this lesson.
+
+207
+00:18:01,000 --> 00:18:03,000
+Thanks a lot for your attention.
+
+208
+00:18:03,000 --> 00:18:06,000
+Have a great day and see you in the next lesson.
+