#28-Change database request

This commit is contained in:
Anton Romanov 2021-05-12 11:07:14 +04:00
parent 9ab0d9cee0
commit 1cd0f3fe31
2 changed files with 11 additions and 10 deletions

View File

@ -1,18 +1,19 @@
package ru.ulstu.extractor.model; package ru.ulstu.extractor.model;
import java.util.Date;
public class CommitTimeStatistic { public class CommitTimeStatistic {
private Date date; private final static String DATE_TEMPLATE = "%s.%s";
private Long countCommit; private final int month;
private final int year;
private final Long countCommit;
public CommitTimeStatistic(Date date, Long countCommit) { public CommitTimeStatistic(int month, int year, Long countCommit) {
this.date = date; this.month = month;
this.year = year;
this.countCommit = countCommit; this.countCommit = countCommit;
} }
public Date getDate() { public String getDate() {
return date; return String.format(DATE_TEMPLATE, month, year);
} }
public Long getCountCommit() { public Long getCountCommit() {

View File

@ -29,13 +29,13 @@ public interface CommitRepository extends JpaRepository<Commit, Integer> {
@Query("SELECT new ru.ulstu.extractor.model.CommitUrlStatistic(c.branch.repository.url, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.branch.repository.url") @Query("SELECT new ru.ulstu.extractor.model.CommitUrlStatistic(c.branch.repository.url, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.branch.repository.url")
List<CommitUrlStatistic> getCommitUrlStatistic(); List<CommitUrlStatistic> getCommitUrlStatistic();
@Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c GROUP by cast(c.date as date) ORDER by cast(c.date as date)") @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(extract(month FROM c.date) as month, extract(year FROM c.date) as year, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by extract(month from c.date), extract(year from c.date) ORDER by extract(year from c.date), extract(month from c.date)")
List<CommitTimeStatistic> getCommitTimeStatistic(); List<CommitTimeStatistic> getCommitTimeStatistic();
@Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT c.hash)) FROM Commit c JOIN c.fileChanges f GROUP by f.containsEntity") @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT c.hash)) FROM Commit c JOIN c.fileChanges f GROUP by f.containsEntity")
List<CommitEntityStatistic> getCommitEntityStatistic(); List<CommitEntityStatistic> getCommitEntityStatistic();
@Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c JOIN c.fileChanges f WHERE f.containsEntity = true GROUP by cast(c.date as date) ORDER by cast(c.date as date)") @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(EXTRACT(MONTH FROM c.date), EXTRACT(YEAR FROM c.date), COUNT(DISTINCT c.hash)) FROM Commit c JOIN c.fileChanges f WHERE f.containsEntity = true GROUP by extract(month from c.date), extract(year from c.date) ORDER by extract(year from c.date), extract(month from c.date)")
List<CommitTimeStatistic> getCommitTimeEntityStatistic(); List<CommitTimeStatistic> getCommitTimeEntityStatistic();
void deleteByBranchIsNull(); void deleteByBranchIsNull();