From 4b298e3c70234d300bcf7da0322b317e0a8d22ca Mon Sep 17 00:00:00 2001 From: ivan-gomes Date: Mon, 14 Sep 2020 09:06:01 -0700 Subject: [PATCH 1/2] ST5AS-83 Disable forced proxy resolution of Commits when not necessary --- app/dao/CommitDao.java | 2 ++ app/dao/impl/jpa/JpaCommitDao.java | 44 +++++++++++++++++++----------- app/services/CommitService.java | 2 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/dao/CommitDao.java b/app/dao/CommitDao.java index edd9af0c..143b17e7 100644 --- a/app/dao/CommitDao.java +++ b/app/dao/CommitDao.java @@ -24,5 +24,7 @@ public interface CommitDao extends Dao { Optional findByProjectAndId(Project project, UUID id); + Optional findByProjectAndIdResolved(Project project, UUID id); + Optional findHeadByProject(Project project); } diff --git a/app/dao/impl/jpa/JpaCommitDao.java b/app/dao/impl/jpa/JpaCommitDao.java index fcb0413a..d95eaefb 100644 --- a/app/dao/impl/jpa/JpaCommitDao.java +++ b/app/dao/impl/jpa/JpaCommitDao.java @@ -16,6 +16,7 @@ import javax.inject.Inject; import javax.inject.Singleton; +import javax.persistence.EntityManager; import javax.persistence.NoResultException; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaDelete; @@ -254,21 +255,32 @@ public List findAllByProject(Project project) { @Override public Optional findByProjectAndId(Project project, UUID id) { return jpa.transact(em -> { - CriteriaBuilder builder = em.getCriteriaBuilder(); - CriteriaQuery query = builder.createQuery(CommitImpl.class); - Root root = query.from(CommitImpl.class); - query.select(root) - .where(builder.and( - builder.equal(root.get(CommitImpl_.containingProject), project), - builder.equal(root.get(CommitImpl_.id), id) - )); - Optional commit; - try { - commit = Optional.of(em.createQuery(query).getSingleResult()); - } catch (NoResultException e) { - return Optional.empty(); - } - return commit.map(PROXY_RESOLVER); + return findByProjectAndId(project, id, em); + }); + } + + protected Optional findByProjectAndId(Project project, UUID id, EntityManager em) { + CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery query = builder.createQuery(CommitImpl.class); + Root root = query.from(CommitImpl.class); + query.select(root) + .where(builder.and( + builder.equal(root.get(CommitImpl_.containingProject), project), + builder.equal(root.get(CommitImpl_.id), id) + )); + Optional commit; + try { + commit = Optional.of(em.createQuery(query).getSingleResult()); + } catch (NoResultException e) { + return Optional.empty(); + } + return commit; + } + + @Override + public Optional findByProjectAndIdResolved(Project project, UUID id) { + return jpa.transact(em -> { + return findByProjectAndId(project, id, em).map(PROXY_RESOLVER); }); } @@ -287,7 +299,7 @@ public Optional findHeadByProject(Project project) { } catch (NoResultException e) { return Optional.empty(); } - return commit.map(PROXY_RESOLVER); + return commit; }); } diff --git a/app/services/CommitService.java b/app/services/CommitService.java index 15241d9a..b3ea8a5c 100644 --- a/app/services/CommitService.java +++ b/app/services/CommitService.java @@ -32,7 +32,7 @@ public List getByProjectId(UUID projectId) { } public Optional getByProjectIdAndId(UUID projectId, UUID commitId) { - return projectDao.findById(projectId).flatMap(project -> commitDao.findByProjectAndId(project, commitId)); + return projectDao.findById(projectId).flatMap(project -> commitDao.findByProjectAndIdResolved(project, commitId)); } public Optional getHeadByProjectId(UUID projectId) { From 9e15affc9ed2fc8461cf73dffe8f88fa6e3ac6a8 Mon Sep 17 00:00:00 2001 From: ivan-gomes Date: Mon, 14 Sep 2020 09:07:33 -0700 Subject: [PATCH 2/2] Update version number to 2020-08-rc2 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index f01ba706..c2b92fcc 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ name := """SysML-v2-API-Services""" organization := "org.omg" -version := "2020-08-rc1" +version := "2020-08-rc2" javacOptions ++= Seq("-source", "11", "-target", "11", "-Xlint")