Skip to content

Commit 8e1f823

Browse files
committed
Allowed EntityListener to access returning properties
1 parent 7b4cf34 commit 8e1f823

File tree

16 files changed

+436
-18
lines changed

16 files changed

+436
-18
lines changed

doma-core/src/main/java/org/seasar/doma/jdbc/entity/PostDeleteContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.seasar.doma.Delete;
2020
import org.seasar.doma.DomaNullPointerException;
2121
import org.seasar.doma.jdbc.Config;
22+
import org.seasar.doma.jdbc.query.ReturningProperties;
2223

2324
/**
2425
* A context for a post process of a delete.
@@ -64,4 +65,13 @@ public interface PostDeleteContext<E> {
6465
* @throws DomaNullPointerException if {@code newEntity} is {@code null}
6566
*/
6667
void setNewEntity(E newEntity);
68+
69+
/**
70+
* Returns the instance of {@code ReturningProperties} associated with the context.
71+
*
72+
* @return the {@code ReturningProperties} instance, never {@code null}
73+
*/
74+
default ReturningProperties getReturningProperties() {
75+
return ReturningProperties.NONE;
76+
}
6777
}

doma-core/src/main/java/org/seasar/doma/jdbc/entity/PostInsertContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.seasar.doma.Insert;
2121
import org.seasar.doma.jdbc.Config;
2222
import org.seasar.doma.jdbc.query.DuplicateKeyType;
23+
import org.seasar.doma.jdbc.query.ReturningProperties;
2324

2425
/**
2526
* A context for a post process of an insert.
@@ -72,4 +73,13 @@ public interface PostInsertContext<E> {
7273
* @return the type of the duplicate key
7374
*/
7475
DuplicateKeyType getDuplicateKeyType();
76+
77+
/**
78+
* Returns the instance of {@code ReturningProperties} associated with the context.
79+
*
80+
* @return the {@code ReturningProperties} instance, never {@code null}
81+
*/
82+
default ReturningProperties getReturningProperties() {
83+
return ReturningProperties.NONE;
84+
}
7585
}

doma-core/src/main/java/org/seasar/doma/jdbc/entity/PostUpdateContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.seasar.doma.OriginalStates;
2121
import org.seasar.doma.Update;
2222
import org.seasar.doma.jdbc.Config;
23+
import org.seasar.doma.jdbc.query.ReturningProperties;
2324

2425
/**
2526
* A context for a post process of an update.
@@ -77,4 +78,13 @@ public interface PostUpdateContext<E> {
7778
* @throws DomaNullPointerException if {@code newEntity} is {@code null}
7879
*/
7980
void setNewEntity(E newEntity);
81+
82+
/**
83+
* Returns the instance of {@code ReturningProperties} associated with the context.
84+
*
85+
* @return the {@code ReturningProperties} instance, never {@code null}
86+
*/
87+
default ReturningProperties getReturningProperties() {
88+
return ReturningProperties.NONE;
89+
}
8090
}

doma-core/src/main/java/org/seasar/doma/jdbc/entity/PreDeleteContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.seasar.doma.Delete;
2020
import org.seasar.doma.DomaNullPointerException;
2121
import org.seasar.doma.jdbc.Config;
22+
import org.seasar.doma.jdbc.query.ReturningProperties;
2223

2324
/**
2425
* A context for a pre process of a delete.
@@ -64,4 +65,13 @@ public interface PreDeleteContext<E> {
6465
* @throws DomaNullPointerException if {@code newEntity} is {@code null}
6566
*/
6667
void setNewEntity(E newEntity);
68+
69+
/**
70+
* Returns the instance of {@code ReturningProperties} associated with the context.
71+
*
72+
* @return the {@code ReturningProperties} instance, never {@code null}
73+
*/
74+
default ReturningProperties getReturningProperties() {
75+
return ReturningProperties.NONE;
76+
}
6777
}

doma-core/src/main/java/org/seasar/doma/jdbc/entity/PreInsertContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.seasar.doma.Insert;
2121
import org.seasar.doma.jdbc.Config;
2222
import org.seasar.doma.jdbc.query.DuplicateKeyType;
23+
import org.seasar.doma.jdbc.query.ReturningProperties;
2324

2425
/**
2526
* A context for a pre process of an insert.
@@ -72,4 +73,13 @@ public interface PreInsertContext<E> {
7273
* @return the type of the duplicate key
7374
*/
7475
DuplicateKeyType getDuplicateKeyType();
76+
77+
/**
78+
* Returns the instance of {@code ReturningProperties} associated with the context.
79+
*
80+
* @return the {@code ReturningProperties} instance, never {@code null}
81+
*/
82+
default ReturningProperties getReturningProperties() {
83+
return ReturningProperties.NONE;
84+
}
7585
}

doma-core/src/main/java/org/seasar/doma/jdbc/entity/PreUpdateContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.seasar.doma.OriginalStates;
2121
import org.seasar.doma.Update;
2222
import org.seasar.doma.jdbc.Config;
23+
import org.seasar.doma.jdbc.query.ReturningProperties;
2324

2425
/**
2526
* A context for a pre process of an update.
@@ -86,4 +87,13 @@ public interface PreUpdateContext<E> {
8687
* @throws DomaNullPointerException if {@code newEntity} is {@code null}
8788
*/
8889
void setNewEntity(E newEntity);
90+
91+
/**
92+
* Returns the instance of {@code ReturningProperties} associated with the context.
93+
*
94+
* @return the {@code ReturningProperties} instance, never {@code null}
95+
*/
96+
default ReturningProperties getReturningProperties() {
97+
return ReturningProperties.NONE;
98+
}
8999
}

doma-core/src/main/java/org/seasar/doma/jdbc/query/AutoDeleteQuery.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.seasar.doma.internal.util.AssertionUtil.assertNotNull;
1919

2020
import java.lang.reflect.Method;
21+
import java.util.Objects;
2122
import org.seasar.doma.internal.jdbc.entity.AbstractPostDeleteContext;
2223
import org.seasar.doma.internal.jdbc.entity.AbstractPreDeleteContext;
2324
import org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder;
@@ -51,7 +52,8 @@ public void prepare() {
5152
}
5253

5354
protected void preDelete() {
54-
AutoPreDeleteContext<ENTITY> context = new AutoPreDeleteContext<>(entityType, method, config);
55+
AutoPreDeleteContext<ENTITY> context =
56+
new AutoPreDeleteContext<>(entityType, method, config, returning);
5557
entityType.preDelete(entity, context);
5658
if (context.getNewEntity() != null) {
5759
entity = context.getNewEntity();
@@ -92,7 +94,8 @@ public void complete() {
9294
}
9395

9496
protected void postDelete() {
95-
AutoPostDeleteContext<ENTITY> context = new AutoPostDeleteContext<>(entityType, method, config);
97+
AutoPostDeleteContext<ENTITY> context =
98+
new AutoPostDeleteContext<>(entityType, method, config, returning);
9699
entityType.postDelete(entity, context);
97100
if (context.getNewEntity() != null) {
98101
entity = context.getNewEntity();
@@ -109,15 +112,39 @@ public void setOptimisticLockExceptionSuppressed(boolean optimisticLockException
109112

110113
protected static class AutoPreDeleteContext<E> extends AbstractPreDeleteContext<E> {
111114

112-
public AutoPreDeleteContext(EntityType<E> entityType, Method method, Config config) {
115+
private final ReturningProperties returningProperties;
116+
117+
public AutoPreDeleteContext(
118+
EntityType<E> entityType,
119+
Method method,
120+
Config config,
121+
ReturningProperties returningProperties) {
113122
super(entityType, method, config);
123+
this.returningProperties = Objects.requireNonNull(returningProperties);
124+
}
125+
126+
@Override
127+
public ReturningProperties getReturningProperties() {
128+
return returningProperties;
114129
}
115130
}
116131

117132
protected static class AutoPostDeleteContext<E> extends AbstractPostDeleteContext<E> {
118133

119-
public AutoPostDeleteContext(EntityType<E> entityType, Method method, Config config) {
134+
private final ReturningProperties returningProperties;
135+
136+
public AutoPostDeleteContext(
137+
EntityType<E> entityType,
138+
Method method,
139+
Config config,
140+
ReturningProperties returningProperties) {
120141
super(entityType, method, config);
142+
this.returningProperties = Objects.requireNonNull(returningProperties);
143+
}
144+
145+
@Override
146+
public ReturningProperties getReturningProperties() {
147+
return returningProperties;
121148
}
122149
}
123150
}

doma-core/src/main/java/org/seasar/doma/jdbc/query/AutoInsertQuery.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void prepare() {
7373

7474
protected void preInsert() {
7575
AutoPreInsertContext<ENTITY> context =
76-
new AutoPreInsertContext<>(entityType, method, config, duplicateKeyType);
76+
new AutoPreInsertContext<>(entityType, method, config, duplicateKeyType, returning);
7777
entityType.preInsert(entity, context);
7878
if (context.getNewEntity() != null) {
7979
entity = context.getNewEntity();
@@ -209,7 +209,7 @@ public void complete() {
209209

210210
protected void postInsert() {
211211
AutoPostInsertContext<ENTITY> context =
212-
new AutoPostInsertContext<>(entityType, method, config, duplicateKeyType);
212+
new AutoPostInsertContext<>(entityType, method, config, duplicateKeyType, returning);
213213
entityType.postInsert(entity, context);
214214
if (context.getNewEntity() != null) {
215215
entity = context.getNewEntity();
@@ -230,17 +230,41 @@ public void setDuplicateKeyNames(String... duplicateKeyNames) {
230230

231231
protected static class AutoPreInsertContext<E> extends AbstractPreInsertContext<E> {
232232

233+
private final ReturningProperties returningProperties;
234+
233235
public AutoPreInsertContext(
234-
EntityType<E> entityType, Method method, Config config, DuplicateKeyType duplicateKeyType) {
236+
EntityType<E> entityType,
237+
Method method,
238+
Config config,
239+
DuplicateKeyType duplicateKeyType,
240+
ReturningProperties returningProperties) {
235241
super(entityType, method, config, duplicateKeyType);
242+
this.returningProperties = Objects.requireNonNull(returningProperties);
243+
}
244+
245+
@Override
246+
public ReturningProperties getReturningProperties() {
247+
return returningProperties;
236248
}
237249
}
238250

239251
protected static class AutoPostInsertContext<E> extends AbstractPostInsertContext<E> {
240252

253+
private final ReturningProperties returningProperties;
254+
241255
public AutoPostInsertContext(
242-
EntityType<E> entityType, Method method, Config config, DuplicateKeyType duplicateKeyType) {
256+
EntityType<E> entityType,
257+
Method method,
258+
Config config,
259+
DuplicateKeyType duplicateKeyType,
260+
ReturningProperties returningProperties) {
243261
super(entityType, method, config, duplicateKeyType);
262+
this.returningProperties = Objects.requireNonNull(returningProperties);
263+
}
264+
265+
@Override
266+
public ReturningProperties getReturningProperties() {
267+
return returningProperties;
244268
}
245269
}
246270
}

doma-core/src/main/java/org/seasar/doma/jdbc/query/AutoMultiInsertQuery.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected void preInsert() {
8989
while (iterator.hasNext()) {
9090
ENTITY entity = iterator.next();
9191
AutoPreInsertContext<ENTITY> context =
92-
new AutoPreInsertContext<>(entityType, method, config, duplicateKeyType);
92+
new AutoPreInsertContext<>(entityType, method, config, duplicateKeyType, returning);
9393
entityType.preInsert(entity, context);
9494
ENTITY newEntity = context.getNewEntity();
9595
if (newEntity != null) {
@@ -238,7 +238,7 @@ protected void postInsert() {
238238
while (iterator.hasNext()) {
239239
ENTITY entity = iterator.next();
240240
AutoPostInsertContext<ENTITY> context =
241-
new AutoPostInsertContext<>(entityType, method, config, duplicateKeyType);
241+
new AutoPostInsertContext<>(entityType, method, config, duplicateKeyType, returning);
242242
entityType.postInsert(entity, context);
243243
ENTITY newEntity = context.getNewEntity();
244244
if (newEntity != null) {
@@ -257,17 +257,41 @@ public void setDuplicateKeyNames(String... duplicateKeyNames) {
257257

258258
protected static class AutoPreInsertContext<E> extends AbstractPreInsertContext<E> {
259259

260+
private final ReturningProperties returningProperties;
261+
260262
public AutoPreInsertContext(
261-
EntityType<E> entityType, Method method, Config config, DuplicateKeyType duplicateKeyType) {
263+
EntityType<E> entityType,
264+
Method method,
265+
Config config,
266+
DuplicateKeyType duplicateKeyType,
267+
ReturningProperties returningProperties) {
262268
super(entityType, method, config, duplicateKeyType);
269+
this.returningProperties = Objects.requireNonNull(returningProperties);
270+
}
271+
272+
@Override
273+
public ReturningProperties getReturningProperties() {
274+
return returningProperties;
263275
}
264276
}
265277

266278
protected static class AutoPostInsertContext<E> extends AbstractPostInsertContext<E> {
267279

280+
private final ReturningProperties returningProperties;
281+
268282
public AutoPostInsertContext(
269-
EntityType<E> entityType, Method method, Config config, DuplicateKeyType duplicateKeyType) {
283+
EntityType<E> entityType,
284+
Method method,
285+
Config config,
286+
DuplicateKeyType duplicateKeyType,
287+
ReturningProperties returningProperties) {
270288
super(entityType, method, config, duplicateKeyType);
289+
this.returningProperties = Objects.requireNonNull(returningProperties);
290+
}
291+
292+
@Override
293+
public ReturningProperties getReturningProperties() {
294+
return returningProperties;
271295
}
272296
}
273297

0 commit comments

Comments
 (0)