Skip to content

Commit 0ea7e01

Browse files
author
Gerald Unterrainer
committed
Merge branch 'develop'
2 parents d3a0b1f + 307f74a commit 0ea7e01

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<modelVersion>4.0.0</modelVersion>
1919
<artifactId>http-server</artifactId>
20-
<version>0.2.31</version>
20+
<version>0.2.32</version>
2121
<name>HttpServer</name>
2222
<packaging>jar</packaging>
2323

src/main/java/info/unterrainer/commons/httpserver/GenericHandlerGroup.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ private void fullUpdate(final Context ctx) throws IOException {
184184
DaoTransaction<E> transaction = dao.getTransactionManager().beginTransaction(ctx);
185185
P jpa = hu.getJpaById(ctx, transaction.getManager(), dao);
186186
try {
187+
P detachedJpa = orikaMapper.map(jpa, jpaType);
187188
J json = jsonMapper.fromStringTo(jsonType, ctx.attribute(Attribute.REQUEST_BODY));
188189
P mappedJpa = orikaMapper.map(json, jpaType);
189190
mappedJpa.setId(jpa.getId());
@@ -192,11 +193,12 @@ private void fullUpdate(final Context ctx) throws IOException {
192193

193194
mappedJpa = extensions.runPreModify(ctx, makeAsyncExtensionContextFor(ctx), transaction.getManager(),
194195
jpa.getId(), json, jpa, mappedJpa, executorService);
196+
195197
P persistedJpa = dao.update(transaction.getManager(), mappedJpa, hu.getReadTenantIdsFrom(ctx));
196198

197199
J r = orikaMapper.map(persistedJpa, jsonType);
198200
r = extensions.runPostModify(ctx, makeAsyncExtensionContextFor(ctx), transaction.getManager(), jpa.getId(),
199-
json, jpa, mappedJpa, persistedJpa, r, executorService);
201+
json, detachedJpa, mappedJpa, persistedJpa, r, executorService);
200202

201203
ctx.attribute(Attribute.RESPONSE_OBJECT, r);
202204

src/main/java/info/unterrainer/commons/httpserver/daos/SingleQueryBuilder.java

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package info.unterrainer.commons.httpserver.daos;
22

3+
import java.util.List;
34
import java.util.Map;
45
import java.util.function.Function;
56

@@ -30,6 +31,22 @@ protected <V> V withEntityManager(final Function<EntityManager, V> func) {
3031
* @return the selected entity
3132
*/
3233
public P get() {
34+
return withEntityManager(em -> {
35+
List<P> resultList = dao.coreDao
36+
.getQuery(em, "o", null, "o.id = :id", Map.of("id", id), dao.type, null, false, null, readTenantIds)
37+
.getResultList();
38+
if (resultList.isEmpty())
39+
return null;
40+
return resultList.get(0);
41+
});
42+
}
43+
44+
/**
45+
* Get the selected entity or throw an exception if it wasn't found.
46+
*
47+
* @return the selected entity
48+
*/
49+
public P getOrException() {
3350
return withEntityManager(em -> dao.coreDao
3451
.getQuery(em, "o", null, "o.id = :id", Map.of("id", id), dao.type, null, false, null, readTenantIds)
3552
.getSingleResult());

0 commit comments

Comments
 (0)