Сообщения

MS Lesson ?: Spring Security

  1. Ilkin olaraq sade Spring Security-ye cavab veren klas budur: /* * Copyright 2012-present the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.boot.security.autoconfigure; import java.util.ArrayList; import java.util.List; import java.util.UUID; import org.springframework.boot.context.properties. ConfigurationProperties ; import org.springframework.util.StringUtils; /** * Configuration properties for...

MS Lesson12: n + 1 problem

1. LazyInitializationException package guru.springframework.cruddemo.entity; import jakarta.persistence.CascadeType; import jakarta.persistence. Column ; import jakarta.persistence. Entity ; import jakarta.persistence.FetchType; import jakarta.persistence. GeneratedValue ; import jakarta.persistence.GenerationType; import jakarta.persistence. Id ; import jakarta.persistence. OneToMany ; import jakarta.persistence. OneToOne ; import jakarta.persistence. Table ; import lombok. AllArgsConstructor ; import lombok. Builder ; import lombok. Getter ; import lombok. NoArgsConstructor ; import lombok. Setter ; import lombok. ToString ; import java.util.ArrayList; import java.util.List; @Getter @Setter @Entity @Builder @ToString @NoArgsConstructor @AllArgsConstructor @Table (name = "persons" ) public class Person { @Id @GeneratedValue (strategy = GenerationType. IDENTITY ) private Long id ; @Column (nullable = false ) private String name ; @Column (nullable = fa...

MS Lesson11: Entity Manager, Entity relations

Изображение
0. Ön səhnə: DB, connection, transaction (Step-by-step) Təsəvvür et ki, DB = kitabxana, application = kitab gətirən maşın, connection = bu kitabxanaya açılan yol, transaction = “bir dəfəyə gətirmə qaydası”. Connection  açılır. Transaction  başlayır: “bu aralıqdakı iş ya hamısı olur, ya da heç biri”. Əsas qayda: commit  = kitablar həqiqətən rəfə gedir. rollback  = gətirdin, amma “heç nə olmamış kimi” geri qaytarırsan. 1.  EntityManagerFactory  nədir? (Step 1) EntityManagerFactory  = “mətbəx maşınlarının fabrikası”. Bir dənə olur (tipik). Sənə hər transaction üçün uyğun  yeni  EntityManager  yaratmağa  kömək edir. Yəni: EMF = fabrika EM = mətbəx (işin içində baş verir) 2.  EntityManager  nədir? (Step 2) EntityManager  = “iş vərəqi / kassa”. Sən JPA əmrlərini verəndə (find/persist/merge/remove/refresh/detach) “bu vərəq” içində baş verir. Bu vərəqin ən önəmli hissəsi var: 3. Persistence Context nədir? (Step 3 – ən kritik)...

MS Lesson10: JPA and EntityManagerFactory

  JPA 1. Method name query mes: findById(1L); 2. Native query @Query (value = " SELECT COALESCE(SUM(p.scholarship), 0) FROM persons p " , nativeQuery = true ) BigDecimal sumAllScholarshipsNative (); 3. @Modifying ve @Transactional neye gore lazimdir? @Modifying @Transactional @Query ( " UPDATE Person p SET p.scholarship = p.scholarship + :amount WHERE p.id = :id " ) int increaseScholarship ( @Param ( "id" ) Long id, @Param ( "amount" ) BigDecimal amount); @Modifying olmasa spring bunu select kimi anlayir, ve ona gore exception atir. Springe deyirki bu sorgu data deyishdirir. Bu annotasiya olmasa Spring select rejimde ishleyecek.  @Transactional olmasa atomiklik ve commit ile tetbiq olunmur. DB-de update/delete/insert transaction daxilinde olmalidir.  Hetta native query yazsaq bele yene bize bu annotasiyalar lazimdir: @Modifying @Transactional @Query (value = " UPDATE persons SET scholarship = scholarship + :amount WHERE id = :id " , nat...