Files
VisualSapfor/src/_VisualDVM/ComponentsServer/BugReportsDatabase.java

95 lines
3.5 KiB
Java
Raw Normal View History

2025-02-18 16:21:20 +03:00
package _VisualDVM.ComponentsServer;
2023-09-17 22:13:42 +03:00
import Common.Database.SQLITE.SQLiteDatabase;
2025-02-18 16:21:20 +03:00
import _VisualDVM.ComponentsServer.BugReport.BugReport;
import _VisualDVM.ComponentsServer.BugReport.BugReportsDBTable;
import _VisualDVM.ComponentsServer.BugReportRecipient.BugReportRecipient;
import _VisualDVM.ComponentsServer.BugReportRecipient.BugReportRecipientsDBTable;
import _VisualDVM.ComponentsServer.BugReportSetting.BugReportSetting;
2025-03-27 12:45:55 +03:00
import _VisualDVM.ComponentsServer.BugReportSetting.BugReportSettingsDBTable;
import _VisualDVM.ComponentsServer.Recipient.RecipientsDataSet;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Passes.PassCode;
2023-09-17 22:13:42 +03:00
import java.nio.file.Paths;
import java.util.Comparator;
2023-09-17 22:13:42 +03:00
import java.util.Vector;
public class BugReportsDatabase extends SQLiteDatabase {
public BugReportsDBTable bugReports;
2025-03-27 12:45:55 +03:00
public BugReportSettingsDBTable bugReportSettings;
public BugReportRecipientsDBTable bugReportRecipients;
public RecipientsDataSet recipients = new RecipientsDataSet();
2023-09-17 22:13:42 +03:00
public BugReportsDatabase() {
2025-01-18 01:36:02 +03:00
super(Paths.get(System.getProperty("user.dir"), "Data", "bug_reports.sqlite").toFile());
2023-09-17 22:13:42 +03:00
}
@Override
protected void initAllTables() throws Exception {
addTable(bugReports = new BugReportsDBTable());
2025-03-27 12:45:55 +03:00
addTable(bugReportSettings = new BugReportSettingsDBTable());
addTable(bugReportRecipients = new BugReportRecipientsDBTable());
2023-09-17 22:13:42 +03:00
}
@Override
public void Init() throws Exception {
DeleteDrafts();
//--
Patch();
2023-09-17 22:13:42 +03:00
}
@Override
2024-10-09 23:37:58 +03:00
public PassCode getSynchronizePassCode() {
return PassCode.SynchronizeBugReports;
}
2023-09-17 22:13:42 +03:00
public void DeleteDrafts() throws Exception {
Vector<BugReport> drafts = bugReports.getAllDrafts();
for (BugReport draft : drafts)
Delete(draft);
}
2025-02-18 23:45:24 +03:00
@Override
2025-02-04 16:22:42 +03:00
public void DropUI() {
2025-02-18 23:45:24 +03:00
super.DropUI();
2025-02-04 16:22:42 +03:00
bugReports.ClearUI();
recipients.ClearUI();
2025-02-04 16:22:42 +03:00
}
2025-02-18 23:45:24 +03:00
@Override
2025-02-04 16:22:42 +03:00
public void ResetUI() {
bugReports.ShowUI();
recipients.ShowUI(); //todo временно.
2025-02-18 23:45:24 +03:00
super.ResetUI();
2025-02-04 16:22:42 +03:00
}
public void saveBugreportRecipients(BugReport bugReport) throws Exception {
if (bugReport.recipients != null) {
for (BugReportRecipient recipient : bugReport.recipients) {
recipient.bugreport_id = bugReport.id;
Insert(recipient);
}
}
}
2025-03-27 12:45:55 +03:00
public void Patch() throws Exception {
int i = 0;
Vector<BugReport> sortedBugs = new Vector<>(bugReports.Data.values());
sortedBugs.sort(new Comparator<BugReport>() {
@Override
public int compare(BugReport o1, BugReport o2) {
return Long.compare(o1.date,o2.date);
}
});
//--
for (BugReport bugReport: sortedBugs){
bugReport.id_ = i;
++i;
Update(bugReport);
}
//--
for (BugReport bugReport: sortedBugs){
Vector<BugReportSetting> bugSettings = getVectorByFK(bugReport, BugReportSetting.class);
Vector<BugReportRecipient> bugReportRecipients = getVectorByFK(bugReport, BugReportRecipient.class);
for (BugReportSetting setting: bugSettings){
setting.bugreport_id_ = bugReport.id_;
Update(setting);
}
for (BugReportRecipient recipient: bugReportRecipients){
recipient.bugreport_id_ = bugReport.id_;
Update(recipient);
}
}
//--
2025-03-27 12:45:55 +03:00
}
2023-09-17 22:13:42 +03:00
}