-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPersistenceContext.java
More file actions
34 lines (27 loc) · 992 Bytes
/
PersistenceContext.java
File metadata and controls
34 lines (27 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.yourssu.jpa;
import java.util.HashMap;
import java.util.Map;
public class PersistenceContext<T, ID> {
private final Map<ID, T> entityMap = new HashMap<>();
private final Map<ID, T> snapshotMap = new HashMap<>();
public void merge() {
for (ID id : entityMap.keySet()) {
T instance = entityMap.get(id);
T original = snapshotMap.get(id);
if (original == null) {
System.out.println("DB에 저장되었습니다. " + instance);
RealDB.push(id, instance);
continue;
}
if (original.equals(instance)) {
continue;
}
System.out.println("DB에 저장되었습니다. " + instance);
RealDB.push(id, instance);
}
}
public void save(ID id, T instance) {
System.out.println("영속성 컨텍스트에 저장되었습니다. " + instance);
entityMap.put(id, instance);
}
}