Skip to content

Commit 6ccfebb

Browse files
authored
Merge pull request #91 from Systems-Modeling/feature/ST5AS-224
ST5AS-224 fix findAllByCommitRelatedElement pagination
2 parents d46fde6 + bf9d481 commit 6ccfebb

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

app/dao/impl/jpa/JpaRelationshipDao.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import config.MetamodelProvider;
2626
import dao.RelationshipDao;
2727
import jpa.manager.JPAManager;
28+
import org.omg.sysml.internal.WorkingDataVersion;
2829
import org.omg.sysml.lifecycle.Commit;
2930
import org.omg.sysml.lifecycle.DataVersion;
3031
import org.omg.sysml.lifecycle.impl.CommitImpl;
@@ -127,8 +128,10 @@ public List<Relationship> findAllByCommitRelatedElement(Commit commit, Element r
127128
// Reverting to non-relational streaming
128129
// TODO Commit is detached at this point. This ternary mitigates by requerying for the Commit in this transaction. A better solution would be moving transaction handling up to service layer (supported by general wisdom) and optionally migrating to using Play's @Transactional/JPAApi. Pros would include removal of repetitive transaction handling at the DAO layer and ability to interface with multiple DAOs in the same transaction (consistent view). Cons include increased temptation to keep transaction open for longer than needed, e.g. during JSON serialization due to the convenience of @Transactional (deprecated in >= 2.8.x), and the service, a higher level of abstraction, becoming aware of transactions. An alternative would be DAO-to-DAO calls (generally discouraged) and delegating to non-transactional versions of methods.
129130
Commit c = em.contains(commit) ? commit : em.find(CommitImpl.class, commit.getId());
130-
return dataDao.findChangesByCommit(c, after, before, maxResults, excludeUsed, em)
131-
.stream()
131+
Stream<Relationship> stream = dataDao.getCommitIndex(c, em).getWorkingDataVersion().stream()
132+
.filter(working -> !excludeUsed || working.getSource() == null)
133+
.map(WorkingDataVersion::getDataVersion)
134+
// return dataDao.findChangesByCommit(c, after, before, maxResults, excludeUsed, em).stream()
132135
.map(DataVersion::getPayload)
133136
.filter(data -> data instanceof Relationship)
134137
.map(data -> (Relationship) data)
@@ -152,8 +155,16 @@ public List<Relationship> findAllByCommitRelatedElement(Commit commit, Element r
152155
.anyMatch(id -> id.equals(relatedElement.getElementId()));
153156
}
154157
)
158+
.map(relationship -> JpaDataDao.resolve(relationship, Relationship.class));
159+
// .collect(Collectors.toList());
160+
Paginated<Stream<Relationship>> paginatedStream = paginateStream(after, before, maxResults, stream, Relationship::getElementId);
161+
List<Relationship> result = paginatedStream.get()
155162
.map(relationship -> JpaDataDao.resolve(relationship, Relationship.class))
156163
.collect(Collectors.toList());
164+
if (paginatedStream.isReversed()) {
165+
Collections.reverse(result);
166+
}
167+
return result;
157168
});
158169
}
159170

0 commit comments

Comments
 (0)