git-extractor/src/main/java/ru/ulstu/extractor/model/Commit.java
2021-04-27 16:28:01 +04:00

101 lines
2.4 KiB
Java

/*
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
*/
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;
import java.util.Date;
import java.util.List;
@Entity
public class Commit extends BaseEntity {
private String hash;
private Date date;
private String message;
@ManyToOne(fetch = FetchType.LAZY)
private Author author;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "commit_id")
@Fetch(FetchMode.SUBSELECT)
private List<FileChange> fileChanges = new ArrayList<>();
@ManyToOne(fetch = FetchType.LAZY)
private Branch branch;
public Commit() {
}
public Commit(String message, Author author, Date date, String hash) {
this.message = message;
this.author = author;
this.date = date;
this.hash = hash;
}
public String getMessage() {
return message;
}
public Date getDate() {
return date;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public void setDate(Date date) {
this.date = date;
}
public void setMessage(String message) {
this.message = message;
}
public void setAuthor(Author author) {
this.author = author;
}
public List<FileChange> getFileChanges() {
return fileChanges;
}
public void setFileChanges(List<FileChange> fileChanges) {
this.fileChanges = fileChanges;
}
public Author getAuthor() {
return author;
}
public Branch getBranch() {
return branch;
}
public void setBranch(Branch branch) {
this.branch = branch;
}
public boolean containsEntity() {
return fileChanges != null && fileChanges.stream().anyMatch(
fileChange -> fileChange != null
&& fileChange.isContainsEntity() != null
&& fileChange.isContainsEntity()
);
}
}