X Tutup
Skip to content

Commit 1c24f80

Browse files
committed
iluwatar#55 Commented the Repository example code
1 parent c6cf96b commit 1c24f80

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

repository/src/main/java/com/iluwatar/App.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44

55
import org.springframework.context.support.ClassPathXmlApplicationContext;
66

7+
/**
8+
*
9+
* Repository pattern mediates between the domain and data mapping layers using a collection-like
10+
* interface for accessing domain objects. A system with complex domain model often benefits from
11+
* a layer that isolates domain objects from the details of the database access code and in such
12+
* systems it can be worthwhile to build another layer of abstraction over the mapping layer where
13+
* query construction code is concentrated. This becomes more important when there are a large
14+
* number of domain classes or heavy querying. In these cases particularly, adding this layer helps
15+
* minimize duplicate query logic.
16+
*
17+
* In this example we utilize Spring Data to automatically generate a repository for us from the Person
18+
* domain object. Using the PersonDao we perform CRUD operations on the entity. Underneath we have
19+
* configured in-memory H2 database for which schema is created and dropped on each run.
20+
*
21+
*/
722
public class App {
823

924
public static void main(String[] args) {

repository/src/main/java/com/iluwatar/Person.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import javax.persistence.GeneratedValue;
55
import javax.persistence.Id;
66

7+
/**
8+
*
9+
* Person entity
10+
*
11+
*/
712
@Entity
813
public class Person {
914

@@ -50,5 +55,4 @@ public String toString() {
5055
return "Person [id=" + id + ", name=" + name + ", surname=" + surname
5156
+ "]";
5257
}
53-
5458
}

repository/src/main/java/com/iluwatar/PersonDao.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import org.springframework.data.repository.CrudRepository;
66
import org.springframework.stereotype.Repository;
77

8+
/**
9+
*
10+
* Person repository
11+
*
12+
*/
813
@Repository
914
public interface PersonDao extends CrudRepository<Person, Long> {
1015

0 commit comments

Comments
 (0)
X Tutup