Skip to content

Commit ebda20b

Browse files
committed
dao question anwsered
1 parent b954f99 commit ebda20b

29 files changed

+394
-36
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea/
2-
Spring5Certification.iml
2+
Spring5Certification.iml
3+
target/

pom.xml

+21-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222

2323

2424
<dependencies>
25-
2625
<dependency>
2726
<groupId>org.springframework</groupId>
2827
<artifactId>spring-core</artifactId>
2928
<version>LATEST</version>
3029
</dependency>
31-
3230
<dependency>
3331
<groupId>org.springframework</groupId>
3432
<artifactId>spring-context</artifactId>
@@ -37,7 +35,7 @@
3735
<dependency>
3836
<groupId>org.projectlombok</groupId>
3937
<artifactId>lombok</artifactId>
40-
<version>1.18.4</version>
38+
<version>LATEST</version>
4139
</dependency>
4240
<dependency>
4341
<groupId>org.springframework</groupId>
@@ -47,12 +45,12 @@
4745
<dependency>
4846
<groupId>org.springframework</groupId>
4947
<artifactId>spring-web</artifactId>
50-
<version>5.1.7.RELEASE</version>
48+
<version>LATEST</version>
5149
</dependency>
5250
<dependency>
5351
<groupId>org.aspectj</groupId>
5452
<artifactId>aspectjrt</artifactId>
55-
<version>1.9.4</version>
53+
<version>LATEST</version>
5654
</dependency>
5755
<dependency>
5856
<groupId>org.aspectj</groupId>
@@ -73,13 +71,29 @@
7371
<dependency>
7472
<groupId>com.h2database</groupId>
7573
<artifactId>h2</artifactId>
76-
<version>1.4.197</version>
74+
<version>LATEST</version>
7775
</dependency>
7876
<dependency>
7977
<groupId>org.springframework</groupId>
8078
<artifactId>spring-orm</artifactId>
81-
<version>5.1.5.RELEASE</version>
79+
<version>LATEST</version>
8280
</dependency>
81+
<dependency>
82+
<groupId>javax.persistence</groupId>
83+
<artifactId>javax.persistence-api</artifactId>
84+
<version>LATEST</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.hibernate</groupId>
88+
<artifactId>hibernate-entitymanager</artifactId>
89+
<version>LATEST</version>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.springframework.data</groupId>
93+
<artifactId>spring-data-jpa</artifactId>
94+
<version>LATEST</version>
95+
</dependency>
96+
8397
</dependencies>
8498

8599
</project>

src/main/java/data/commun/Person.java

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package data.commun;
2+
import lombok.*;
3+
import org.springframework.lang.Nullable;
4+
5+
import javax.persistence.*;
6+
import java.time.LocalDate;
7+
8+
9+
@Builder
10+
@Setter
11+
@Getter
12+
@EqualsAndHashCode
13+
@ToString
14+
@Entity(name = "Persons")
15+
public class Person {
16+
17+
@Id
18+
@Column(name = "Identifiant")
19+
@GeneratedValue(strategy = GenerationType.IDENTITY)
20+
private Integer id;
21+
22+
@Column(name = "Name")
23+
private String name;
24+
25+
@Column(name = "Age")
26+
private int age;
27+
28+
@Column(name = "Date_of_Birth")
29+
private LocalDate dateOfBirth;
30+
31+
// TODO: 07/07/2019
32+
@ManyToOne
33+
@JoinColumn(name = "Profesion_id")
34+
private Profession profession;
35+
36+
37+
38+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package data.commun;
2+
3+
4+
import lombok.*;
5+
6+
import javax.persistence.*;
7+
8+
9+
@Builder
10+
@Setter
11+
@Getter
12+
@EqualsAndHashCode
13+
@ToString
14+
@Entity(name = "Professions")
15+
public class Profession {
16+
17+
@Id
18+
@Column(name = "Identifiant")
19+
@GeneratedValue(strategy = GenerationType.IDENTITY)
20+
private Integer id;
21+
22+
@Column(name = "Name")
23+
private String name;
24+
25+
@Column(name = "Description")
26+
private String description;
27+
28+
29+
}

src/main/java/data_transaction_jpa/question_001/SpringException.java renamed to src/main/java/data/question_001/SpringException.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
package data_transaction_jpa.question_001;
1+
package data.question_001;
22

33

44
/**
55
* What is the difference between checked and unchecked exceptions?
66
* • Why does Spring prefer unchecked exceptions?
7-
* • What is the data_transaction_jpa access exception hierarchy?
7+
* • What is the data access exception hierarchy?
88
*
99
*
1010
*
1111
*
1212
* Checked exception should be managed in a try catch block or should be declared on the method signature.
1313
* unchecked exception don't have this restriction.
1414
* For this reason Spring Framework prefer to use the unchecked exception.
15-
* All the exceptions in the data_transaction_jpa access hierarchy are unchecked.
15+
* All the exceptions in the data access hierarchy are unchecked.
1616
* The purpose is to isolate the applications from particularity of vendor specification.
1717
*
1818
*/

src/main/java/data_transaction_jpa/question_02/MyDataSource.java renamed to src/main/java/data/question_02/MyDataSource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package data_transaction_jpa.question_02;
1+
package data.question_02;
22

33

44
import ioc.commun.Person;
@@ -143,8 +143,8 @@ public DataSource secondDataSource (){
143143
public DataSource thirdDataSource (){
144144
final EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
145145
.setType(EmbeddedDatabaseType.H2)
146-
.addScripts("databaseconfig/ddl.script",//ddl data_transaction_jpa definition language define database schema
147-
"databaseconfig/dml.script")//dml data_transaction_jpa manipulation language CRUD operations
146+
.addScripts("databaseconfig/ddl.script",//ddl data definition language define database schema
147+
"databaseconfig/dml.script")//dml data manipulation language CRUD operations
148148
.build();
149149
return embeddedDatabase;
150150

src/main/java/data_transaction_jpa/question_03_04_05_06_07/MyJdbcTemplate.java renamed to src/main/java/data/question_03_04_05_06_07/MyJdbcTemplate.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package data_transaction_jpa.question_03_04_05_06_07;
1+
package data.question_03_04_05_06_07;
22

33
import org.springframework.jdbc.core.JdbcTemplate;
44

@@ -18,9 +18,9 @@
1818
* 1-Template design pattern define some steps which are executed in order, the super type define this order,
1919
* the subclasses implement only some predefined steps.
2020
* 2-
21-
* a- RowMapper<Object>: allows to handle rows in a result set row by row {@link data_transaction_jpa.question_02.MyDataSource#rowMapper(JdbcTemplate)}.
21+
* a- RowMapper<Object>: allows to handle rows in a result set row by row {@link data.question_02.MyDataSource#rowMapper(JdbcTemplate)}.
2222
* b-resultSetExtractor<List<Object>>:
23-
* allows to process the entire result set {@link data_transaction_jpa.question_02.MyDataSource#resultSetExtractor(JdbcTemplate)}.
23+
* allows to process the entire result set {@link data.question_02.MyDataSource#resultSetExtractor(JdbcTemplate)}.
2424
* c-@todo example to make for the RowCallbackHandler
2525
* * 3-yes
2626
* 4-Jdbc template release the connection after every request. jdbctemplate is trade safe

src/main/java/data_transaction_jpa/question_03_04_05_06_07/SqlQuery.java renamed to src/main/java/data/question_03_04_05_06_07/SqlQuery.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package data_transaction_jpa.question_03_04_05_06_07;
1+
package data.question_03_04_05_06_07;
22

33

4-
import data_transaction_jpa.question_02.MyDataSource;
4+
import data.question_02.MyDataSource;
55
import ioc.commun.Person;
66
import org.springframework.context.ApplicationContext;
77
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

src/main/java/data_transaction_jpa/question_08_09_10_11/EnablingTransaction.java renamed to src/main/java/data/question_08_09_10_11/EnablingTransaction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package data_transaction_jpa.question_08_09_10_11;
1+
package data.question_08_09_10_11;
22
import org.springframework.context.annotation.Bean;
33
import org.springframework.context.annotation.Configuration;
44
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

src/main/java/data_transaction_jpa/question_08_09_10_11/MyTransaction.java renamed to src/main/java/data/question_08_09_10_11/MyTransaction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package data_transaction_jpa.question_08_09_10_11;
1+
package data.question_08_09_10_11;
22

33

44
/**
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package data_transaction_jpa.question_12_13;
1+
package data.question_12_13;
22

33

44
/**

src/main/java/data_transaction_jpa/question_12_13/IsolationLevel.java renamed to src/main/java/data/question_12_13/IsolationLevel.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package data_transaction_jpa.question_12_13;
1+
package data.question_12_13;
22
import org.springframework.transaction.annotation.Isolation;
33

44
/**
5-
* Problems we can get when two or more transactions are executing in parallel on the same data_transaction_jpa.
6-
* {@link IsolationLevel.READ_UNCOMMITTED} is the slowest isolation level, T1 can Read uncommitted data_transaction_jpa from T2.
5+
* Problems we can get when two or more transactions are executing in parallel on the same data.
6+
* {@link IsolationLevel.READ_UNCOMMITTED} is the slowest isolation level, T1 can Read uncommitted data from T2.
77
* This Isolation level can produces Dirty Read problem:
88
* On one cell for example, T1 read 10, T2 write 15,T1 read 15, T2 rollback, T1 get bad result.
99
* T1---10---------25---
1010
* T2---10-----15----10-
1111
*
12-
* Dirty read occurs when T1 read data_transaction_jpa that was not yet committed by another Transaction.
12+
* Dirty read occurs when T1 read data that was not yet committed by another Transaction.
1313
* To solve this problem we should use {@link IsolationLevel.READ_COMMITTED}
1414
*
1515
* With {@link IsolationLevel.READ_COMMITTED}, non-repeatable read problem can be produced.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package data_transaction_jpa.question_14_15_16_17_18_19;
1+
package data.question_14_15_16_17_18_19;
22

33
/**
44
*
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
package data_transaction_jpa.question_14_15_16_17_18_19;
2-
import org.springframework.context.annotation.Bean;
3-
import org.springframework.context.annotation.Configuration;
1+
package data.question_14_15_16_17_18_19;
42
import org.springframework.transaction.annotation.Propagation;
5-
import org.springframework.transaction.annotation.Transactional;
63

74
/**
85
*

src/main/java/data_transaction_jpa/question_20_21_22_23_24/JDBCAutoCommitMode.java renamed to src/main/java/data/question_20_21_22_23_24/JDBCAutoCommitMode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package data_transaction_jpa.question_20_21_22_23_24;
1+
package data.question_20_21_22_23_24;
22

33

44
/**

src/main/java/data_transaction_jpa/question_20_21_22_23_24/SpringJPA.java renamed to src/main/java/data/question_20_21_22_23_24/SpringJPA.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
package data_transaction_jpa.question_20_21_22_23_24;
1+
package data.question_20_21_22_23_24;
22
import javax.persistence.EntityManager;
33
import javax.persistence.EntityManagerFactory;
4-
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
5-
import org.springframework.orm.jpa.LocalEntityManagerFactoryBean;
4+
65
/**
76
*
87
* ORM (Object relational model): mapping between object oriented data to relational data.
@@ -73,7 +72,23 @@
7372
* DataSourceTransactionManager
7473
* JpaTransactionManager : single transactional resource.
7574
* What do you have to configure to use JPA with Spring? How does Spring Boot make this
76-
* easier? spring-boot-starter-data-jpa -- Spring Boot autoconfigures data access layer related beans.
75+
* easier?
76+
* *Spring: dependencies to an ORM framework, a database driver, and a transaction manager.
77+
* *Sprig boot: dependencies to spring-boot-starter-data-jpa, spring Boot autoconfigures data access layer related beans.
78+
* *implement Entity classes.
79+
* *Defining a Datasource and a Transaction Manager.
80+
* *implementing repositories interfaces.
81+
*
82+
*
83+
*
84+
*
85+
*
86+
*
87+
*
88+
*
89+
*
90+
*
91+
*
7792
*
7893
*/
7994
public class SpringJPA {

0 commit comments

Comments
 (0)