Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Unterrainer committed Aug 12, 2021
2 parents d3a0b1f + 307f74a commit 0ea7e01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<modelVersion>4.0.0</modelVersion>
<artifactId>http-server</artifactId>
<version>0.2.31</version>
<version>0.2.32</version>
<name>HttpServer</name>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private void fullUpdate(final Context ctx) throws IOException {
DaoTransaction<E> transaction = dao.getTransactionManager().beginTransaction(ctx);
P jpa = hu.getJpaById(ctx, transaction.getManager(), dao);
try {
P detachedJpa = orikaMapper.map(jpa, jpaType);
J json = jsonMapper.fromStringTo(jsonType, ctx.attribute(Attribute.REQUEST_BODY));
P mappedJpa = orikaMapper.map(json, jpaType);
mappedJpa.setId(jpa.getId());
Expand All @@ -192,11 +193,12 @@ private void fullUpdate(final Context ctx) throws IOException {

mappedJpa = extensions.runPreModify(ctx, makeAsyncExtensionContextFor(ctx), transaction.getManager(),
jpa.getId(), json, jpa, mappedJpa, executorService);

P persistedJpa = dao.update(transaction.getManager(), mappedJpa, hu.getReadTenantIdsFrom(ctx));

J r = orikaMapper.map(persistedJpa, jsonType);
r = extensions.runPostModify(ctx, makeAsyncExtensionContextFor(ctx), transaction.getManager(), jpa.getId(),
json, jpa, mappedJpa, persistedJpa, r, executorService);
json, detachedJpa, mappedJpa, persistedJpa, r, executorService);

ctx.attribute(Attribute.RESPONSE_OBJECT, r);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package info.unterrainer.commons.httpserver.daos;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

Expand Down Expand Up @@ -30,6 +31,22 @@ protected <V> V withEntityManager(final Function<EntityManager, V> func) {
* @return the selected entity
*/
public P get() {
return withEntityManager(em -> {
List<P> resultList = dao.coreDao
.getQuery(em, "o", null, "o.id = :id", Map.of("id", id), dao.type, null, false, null, readTenantIds)
.getResultList();
if (resultList.isEmpty())
return null;
return resultList.get(0);
});
}

/**
* Get the selected entity or throw an exception if it wasn't found.
*
* @return the selected entity
*/
public P getOrException() {
return withEntityManager(em -> dao.coreDao
.getQuery(em, "o", null, "o.id = :id", Map.of("id", id), dao.type, null, false, null, readTenantIds)
.getSingleResult());
Expand Down

0 comments on commit 0ea7e01

Please sign in to comment.