package _VisualDVM.ProjectData; import Common.Database.SQLITE.SQLiteDatabase; import _VisualDVM.ProjectData.DBArray.ArraysDBTable; import _VisualDVM.ProjectData.Files.DBProjectFile; import _VisualDVM.ProjectData.Files.FileType; import _VisualDVM.ProjectData.Files.FilesDBTable; import _VisualDVM.ProjectData.Messages.Errors.ErrorsDBTable; import _VisualDVM.ProjectData.Messages.Notes.NotesDBTable; import _VisualDVM.ProjectData.Messages.Recommendations.RecommendationsDBTable; import _VisualDVM.ProjectData.Messages.Warnings.WarningsDBTable; import _VisualDVM.ProjectData.PredictorStatistic.PredictorStatisticsDBTable; import _VisualDVM.ProjectData.Project.ProjectInfoDBTable; import _VisualDVM.ProjectData.Project.db_project_info; import _VisualDVM.ProjectData.SapforData.Functions.FuncCoordinatesDBTable; import Visual_DVM_2021.Passes.PassCode_2021; import javax.swing.tree.DefaultMutableTreeNode; import java.io.File; import java.util.Vector; public class ProjectDatabase extends SQLiteDatabase { public db_project_info owner; public ProjectInfoDBTable projectInfo; public FilesDBTable files; public ArraysDBTable savedArrays; //мб в дальнейшем как то объединить эти объекты с сапфоровскими? хз. public PredictorStatisticsDBTable predictorStatistics; public NotesDBTable notes; public WarningsDBTable warnings; public ErrorsDBTable errors; public RecommendationsDBTable recommendations; public FuncCoordinatesDBTable funcCoordinates; public ProjectDatabase(db_project_info owner_in) { super(db_project_info.get_db_file((owner_in).Home)); owner = owner_in; } //---------------------------------------------------- @Override protected void initAllTables() throws Exception { addTable(projectInfo = new ProjectInfoDBTable()); addTable(files = new FilesDBTable()); addTable(savedArrays = new ArraysDBTable()); addTable(predictorStatistics = new PredictorStatisticsDBTable()); addTable(notes = new NotesDBTable()); addTable(warnings = new WarningsDBTable()); addTable(errors = new ErrorsDBTable()); addTable(recommendations = new RecommendationsDBTable()); addTable(funcCoordinates = new FuncCoordinatesDBTable()); } //Делать это только после пострения дерева версий. чтобы файлы версий не учитывались!! public DefaultMutableTreeNode get_files_r(File file) throws Exception { DefaultMutableTreeNode res = null; if (owner.isProjectDirectory(file)) { res = new DefaultMutableTreeNode(file); File[] files_ = file.listFiles(); if (files_ != null) { for (File f : files_) { DefaultMutableTreeNode node = get_files_r(f); //Null может быть если подпапки оказались от версий if (node != null) res.add(node); } } } else if (file.isFile()) { DBProjectFile pf = null; String name = owner.getInnerName(file); if (files.Data.containsKey(name)) { pf = files.Data.get(name); pf.Init(file, owner); } else { pf = new DBProjectFile(file, owner); if (pf.fileType != FileType.forbidden) Insert(pf); else return null; } res = pf.node = new DefaultMutableTreeNode(pf); //узел файла тут же надо запомнить. } return res; } @Override public void Init() throws Exception { owner.DeleteCrushedVersionIfNeed(); owner.filesTreeRoot = get_files_r(owner.Home); Vector inexisting_files = new Vector<>(); for (DBProjectFile f : files.Data.values()) if (f.father == null) inexisting_files.add(f); for (DBProjectFile f : inexisting_files) Delete(f); } @Override public PassCode_2021 getSynchronizePassCode() { return null; } //особый проход. нужен при первичной загрузке проекта. public db_project_info LoadOnlyProjectInfo() throws Exception { LoadAll(projectInfo); return projectInfo.getFirstRecord(); } }