FOSSology  4.7.0-rc1
Open Source License Compliance by Open Source Software
database.hpp
1 /*
2  SPDX-FileCopyrightText: © 2014 Siemens AG
3  Author: Daniele Fognini
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #ifndef DATABASE_HPP
9 #define DATABASE_HPP
10 
11 #include <string>
12 #include <vector>
13 
16 #include "cleanEntries.hpp"
17 
18 #define MAX_TABLE_CREATION_RETRIES 5
19 
25 {
26 public:
27  DatabaseEntry();
28 
29  long agent_fk;
30  long pfile_fk;
31  std::string content;
32  std::string hash;
43  std::string type;
46  bool is_enabled;
47 };
48 
54 {
55 public:
58  CopyrightDatabaseHandler(CopyrightDatabaseHandler&& other) : fo::AgentDatabaseHandler(std::move(other)) {}; // = default
60 
61  bool createTables() const;
62  bool insertInDatabase(DatabaseEntry& entry) const;
63  bool insertDeactivatedEvents(const DatabaseEntry& entry, int uploadId,
64  const std::string& uploadTreeTableName) const;
65  std::vector<unsigned long> queryFileIdsForUpload(int agentId, int uploadId, bool ignoreFilesWithMimeType);
66 
67 private:
73  typedef struct
74  {
75  const char* name;
76  const char* type;
77  const char* creationFlags;
78  } ColumnDef;
79 
80  static const ColumnDef columns[];
81  static const ColumnDef columnsDecision[];
82 
83  bool createTableAgentFindings() const;
84  bool createTableClearing() const;
85  std::string getColumnListString(const ColumnDef in[], size_t size) const;
86  std::string getColumnCreationString(const ColumnDef in[], size_t size) const;
87 };
88 
89 #endif // DATABASE_HPP
Manages database related requests for agent.
Definition: database.hpp:54
std::vector< unsigned long > queryFileIdsForUpload(int agentId, int uploadId, bool ignoreFilesWithMimeType)
Get the list of pfile ids on which the given agent has no findings for a given upload.
Definition: database.cc:307
static const ColumnDef columns[]
Columns required by agent in database.
Definition: database.hpp:80
bool createTableAgentFindings() const
Create table to store agent find data.
Definition: database.cc:158
bool insertInDatabase(DatabaseEntry &entry) const
Insert a finding in database.
Definition: database.cc:354
static const ColumnDef columnsDecision[]
Columns required to store user decisions in database.
Definition: database.hpp:81
std::string getColumnListString(const ColumnDef in[], size_t size) const
Given a list of ColumnDef, return a comma separated list of column names.
Definition: database.cc:55
CopyrightDatabaseHandler(fo::DbManager manager)
Constructor to initialize database handler.
Definition: database.cc:416
CopyrightDatabaseHandler spawn() const
Spawn/fork a new database handler and return it.
Definition: database.cc:42
bool insertDeactivatedEvents(const DatabaseEntry &entry, int uploadId, const std::string &uploadTreeTableName) const
Insert one deactivated finding per uploadtree node for a given upload, for a given finding.
Definition: database.cc:387
bool createTables() const
Create tables required by agent.
Definition: database.cc:101
std::string getColumnCreationString(const ColumnDef in[], size_t size) const
Return a comma delimited string with column elements separated by space. The string is used for datab...
Definition: database.cc:75
bool createTableClearing() const
Create table to store user decisions.
Definition: database.cc:238
Maps agent data to database schema.
Definition: database.hpp:25
int copy_startbyte
Definition: database.hpp:44
bool is_enabled
Definition: database.hpp:46
std::string content
Definition: database.hpp:31
std::string type
Type of statement found.
Definition: database.hpp:43
std::string hash
Definition: database.hpp:32
int copy_endbyte
Definition: database.hpp:45
DatabaseEntry()
Default constructor for DatabaseEntry.
Definition: database.cc:26
Database handler for agents.
DB wrapper for agents.
DB utility functions for agents.
DB wrapper for agents.
Holds the column related data for table creation.
Definition: database.hpp:74