Skip to content

Commit

Permalink
Merge branch 'release/2020-08-rc2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-gomes committed Sep 14, 2020
2 parents a265d4e + 9e15aff commit e1a065a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
2 changes: 2 additions & 0 deletions app/dao/CommitDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public interface CommitDao extends Dao<Commit> {

Optional<Commit> findByProjectAndId(Project project, UUID id);

Optional<Commit> findByProjectAndIdResolved(Project project, UUID id);

Optional<Commit> findHeadByProject(Project project);
}
44 changes: 28 additions & 16 deletions app/dao/impl/jpa/JpaCommitDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -254,21 +255,32 @@ public List<Commit> findAllByProject(Project project) {
@Override
public Optional<Commit> findByProjectAndId(Project project, UUID id) {
return jpa.transact(em -> {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<CommitImpl> query = builder.createQuery(CommitImpl.class);
Root<CommitImpl> 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> 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<Commit> findByProjectAndId(Project project, UUID id, EntityManager em) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<CommitImpl> query = builder.createQuery(CommitImpl.class);
Root<CommitImpl> 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> commit;
try {
commit = Optional.of(em.createQuery(query).getSingleResult());
} catch (NoResultException e) {
return Optional.empty();
}
return commit;
}

@Override
public Optional<Commit> findByProjectAndIdResolved(Project project, UUID id) {
return jpa.transact(em -> {
return findByProjectAndId(project, id, em).map(PROXY_RESOLVER);
});
}

Expand All @@ -287,7 +299,7 @@ public Optional<Commit> findHeadByProject(Project project) {
} catch (NoResultException e) {
return Optional.empty();
}
return commit.map(PROXY_RESOLVER);
return commit;
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/services/CommitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<Commit> getByProjectId(UUID projectId) {
}

public Optional<Commit> 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<Commit> getHeadByProjectId(UUID projectId) {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -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")

Expand Down

0 comments on commit e1a065a

Please sign in to comment.