FOSSology  4.4.0
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 };
47 
53 {
54 public:
57  CopyrightDatabaseHandler(CopyrightDatabaseHandler&& other) : fo::AgentDatabaseHandler(std::move(other)) {}; // = default
59 
60  bool createTables() const;
61  bool insertInDatabase(DatabaseEntry& entry) const;
62  std::vector<unsigned long> queryFileIdsForUpload(int agentId, int uploadId, bool ignoreFilesWithMimeType);
63 
64 private:
70  typedef struct
71  {
72  const char* name;
73  const char* type;
74  const char* creationFlags;
75  } ColumnDef;
76 
77  static const ColumnDef columns[];
78  static const ColumnDef columnsDecision[];
79 
80  bool createTableAgentFindings() const;
81  bool createTableClearing() const;
82  std::string getColumnListString(const ColumnDef in[], size_t size) const;
83  std::string getColumnCreationString(const ColumnDef in[], size_t size) const;
84 };
85 
86 #endif // DATABASE_HPP
Manages database related requests for agent.
Definition: database.hpp:53
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:306
static const ColumnDef columns[]
Columns required by agent in database.
Definition: database.hpp:77
bool createTableAgentFindings() const
Create table to store agent find data.
Definition: database.cc:157
bool insertInDatabase(DatabaseEntry &entry) const
Insert a finding in database.
Definition: database.cc:353
static const ColumnDef columnsDecision[]
Columns required to store user decisions in database.
Definition: database.hpp:78
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:54
CopyrightDatabaseHandler(fo::DbManager manager)
Constructor to initialize database handler.
Definition: database.cc:382
CopyrightDatabaseHandler spawn() const
Spawn/fork a new database handler and return it.
Definition: database.cc:41
bool createTables() const
Create tables required by agent.
Definition: database.cc:100
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:74
bool createTableClearing() const
Create table to store user decisions.
Definition: database.cc:237
Maps agent data to database schema.
Definition: database.hpp:25
int copy_startbyte
Definition: database.hpp:44
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:71