fix query and pagination
This commit is contained in:
parent
0bd1e9e145
commit
05874f8bd5
@ -5,8 +5,13 @@
|
||||
|
||||
package ru.ulstu.extractor.model;
|
||||
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
@ -19,7 +24,9 @@ public class Branch extends BaseEntity {
|
||||
@ManyToOne
|
||||
private Repository repository;
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "branch")
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "branch_id")
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
private List<Commit> commits = new ArrayList<>();
|
||||
|
||||
public Branch() {
|
||||
|
@ -26,10 +26,10 @@ public class Commit extends BaseEntity {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private Author author;
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "commit_id", unique = true)
|
||||
@JoinColumn(name = "commit_id")
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
private List<FileChange> fileChanges = new ArrayList<>();
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Branch branch;
|
||||
|
||||
public Commit() {
|
||||
|
@ -20,7 +20,7 @@ import ru.ulstu.extractor.model.Repository;
|
||||
import java.util.List;
|
||||
|
||||
public interface CommitRepository extends JpaRepository<Commit, Integer> {
|
||||
@Query("SELECT c FROM Commit c, Repository r, Branch b, Author a, FileChange f WHERE c.branch = b AND r = b.repository AND a = c.author AND f MEMBER OF c.fileChanges AND r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%'))) AND (:entity IS NULL OR f.containsEntity = :entity)")
|
||||
@Query("SELECT DISTINCT c FROM Commit c JOIN c.branch b JOIN c.fileChanges f JOIN c.author a JOIN b.repository r WHERE r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%'))) AND (:entity IS NULL OR f.containsEntity = :entity)")
|
||||
Page<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter, @Param("entity") Boolean entity);
|
||||
|
||||
@Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name")
|
||||
|
@ -120,7 +120,7 @@
|
||||
filter=${filterForm.filter},
|
||||
entity=${filterForm.entity})}"
|
||||
th:text=${pageNumber}
|
||||
th:class="${pageNumber == filterForm.commitsPage.number} ? active"></a>
|
||||
th:class="${pageNumber == filterForm.commitsPage.number+1} ? active"></a>
|
||||
</div>
|
||||
</div>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user