FOSSology  4.4.0
Open Source License Compliance by Open Source Software
CopyrightDatabaseHandler Class Reference

Manages database related requests for agent. More...

#include <database.hpp>

Inheritance diagram for CopyrightDatabaseHandler:
Inheritance graph
Collaboration diagram for CopyrightDatabaseHandler:
Collaboration graph

Classes

struct  ColumnDef
 Holds the column related data for table creation. More...
 

Public Member Functions

 CopyrightDatabaseHandler (fo::DbManager manager)
 Constructor to initialize database handler.
 
 CopyrightDatabaseHandler (const CopyrightDatabaseHandler &)=delete
 
 CopyrightDatabaseHandler (CopyrightDatabaseHandler &&other)
 
CopyrightDatabaseHandler spawn () const
 Spawn/fork a new database handler and return it. More...
 
bool createTables () const
 Create tables required by agent. More...
 
bool insertInDatabase (DatabaseEntry &entry) const
 Insert a finding in database. More...
 
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. More...
 
- Public Member Functions inherited from fo::AgentDatabaseHandler
 AgentDatabaseHandler (DbManager dbManager)
 
 AgentDatabaseHandler (AgentDatabaseHandler &&other)
 
 AgentDatabaseHandler (const AgentDatabaseHandler &)=delete
 
virtual ~AgentDatabaseHandler ()
 
AgentDatabaseHandler operator= (const AgentDatabaseHandler &)=delete
 
bool begin () const
 BEGIN a transaction block in DB. More...
 
bool commit () const
 COMMIT a transaction block in DB. More...
 
bool rollback () const
 ROLLBACK a transaction block in DB. More...
 
char * getPFileNameForFileId (unsigned long pfileId) const
 Get the file name of a give pfile id. More...
 
std::string queryUploadTreeTableName (int uploadId)
 Get the upload tree table name for a given upload id. More...
 
std::vector< unsigned long > queryFileIdsVectorForUpload (int uploadId, bool ignoreFilesWithMimeType) const
 Get pfile ids for a given upload id. More...
 
std::vector< unsigned long > queryFileIdsVectorForUpload (int uploadId, int agentId, bool ignoreFilesWithMimeType) const
 Get pfile ids for a given upload id which agent has not scanned. More...
 

Private Member Functions

bool createTableAgentFindings () const
 Create table to store agent find data. More...
 
bool createTableClearing () const
 Create table to store user decisions. More...
 
std::string getColumnListString (const ColumnDef in[], size_t size) const
 Given a list of ColumnDef, return a comma separated list of column names. More...
 
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 database creation. More...
 

Static Private Attributes

static const ColumnDef columns []
 Columns required by agent in database. More...
 
static const ColumnDef columnsDecision []
 Columns required to store user decisions in database. More...
 

Additional Inherited Members

- Protected Attributes inherited from fo::AgentDatabaseHandler
DbManager dbManager
 DbManager to use.
 

Detailed Description

Manages database related requests for agent.

Definition at line 52 of file database.hpp.

Member Function Documentation

◆ createTableAgentFindings()

bool CopyrightDatabaseHandler::createTableAgentFindings ( ) const
private

Create table to store agent find data.

Returns
True on success, false otherwise
See also
CopyrightDatabaseHandler::columns

Definition at line 157 of file database.cc.

◆ createTableClearing()

bool CopyrightDatabaseHandler::createTableClearing ( ) const
private

Create table to store user decisions.

Returns
True on success, false otherwise
See also
CopyrightDatabaseHandler::columnsDecision

Definition at line 237 of file database.cc.

◆ createTables()

bool CopyrightDatabaseHandler::createTables ( ) const

Create tables required by agent.

Calls createTableAgentFindings() and createTableClearing() to create the tables required by the agent to work.

The function tries to create table in maximum of MAX_TABLE_CREATION_RETRIES attempts.

Returns
True if success, false otherwise

Definition at line 100 of file database.cc.

◆ getColumnCreationString()

std::string CopyrightDatabaseHandler::getColumnCreationString ( const ColumnDef  in[],
size_t  size 
) const
private

Return a comma delimited string with column elements separated by space. The string is used for database creation.

Parameters
inList of column to be parsed
sizeNumber of elements in the list
Returns
Comma delimited string
See also
CopyrightDatabaseHandler::createTableAgentFindings()

Definition at line 74 of file database.cc.

◆ getColumnListString()

std::string CopyrightDatabaseHandler::getColumnListString ( const ColumnDef  in[],
size_t  size 
) const
private

Given a list of ColumnDef, return a comma separated list of column names.

Parameters
inList to parse
sizeNumber of elements in the list
Returns
Comma separated list of column names
See also
CopyrightDatabaseHandler::ColumnDef

Definition at line 54 of file database.cc.

◆ insertInDatabase()

bool CopyrightDatabaseHandler::insertInDatabase ( DatabaseEntry entry) const

Insert a finding in database.

Parameters
entryEntry to be inserted in the database
Returns
True on success, false otherwise
See also
DatabaseEntry

Definition at line 353 of file database.cc.

◆ queryFileIdsForUpload()

std::vector< unsigned long > CopyrightDatabaseHandler::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.

Parameters
agentIdAgent id to be removed from result
uploadIdUpload id to scan for files
ignoreFilesWithMimeTypeto exclude filetypes with particular mimetype
Returns
List of pfiles on which the given agent has no findings

Definition at line 306 of file database.cc.

◆ spawn()

CopyrightDatabaseHandler CopyrightDatabaseHandler::spawn ( ) const

Spawn/fork a new database handler and return it.

Returns
CopyrightDatabaseHandler object with spawned DbManager

Definition at line 41 of file database.cc.

Member Data Documentation

◆ columns

const CopyrightDatabaseHandler::ColumnDef CopyrightDatabaseHandler::columns
staticprivate
Initial value:
=
{
#define SEQUENCE_NAME
#define COLUMN_NAME_PK
{ COLUMN_NAME_PK, "bigint", "PRIMARY KEY DEFAULT nextval('" SEQUENCE_NAME "'::regclass)"},
{"agent_fk", "bigint", "NOT NULL"},
{"pfile_fk", "bigint", "NOT NULL"},
{"content", "text", ""},
{"hash", "text", ""},
{"type", "text", ""},
{"copy_startbyte", "integer", ""},
{"copy_endbyte", "integer", ""},
{"is_enabled", "boolean", "NOT NULL DEFAULT TRUE"},
}

Columns required by agent in database.

Todo:
Removed constrain: "CHECK (type in ('statement', 'email', 'url'))"}

Definition at line 77 of file database.hpp.

◆ columnsDecision

const CopyrightDatabaseHandler::ColumnDef CopyrightDatabaseHandler::columnsDecision
staticprivate
Initial value:
= {
#define SEQUENCE_NAMEClearing
{IDENTITY"_decision_pk", "bigint", "PRIMARY KEY DEFAULT nextval('" SEQUENCE_NAMEClearing "'::regclass)"},
{"user_fk", "bigint", "NOT NULL"},
{"pfile_fk", "bigint", "NOT NULL"},
{"clearing_decision_type_fk", "bigint", "NOT NULL"},
{"description", "text", ""},
{"textFinding", "text", ""},
{"comment", "text", ""},
{"is_enabled", "boolean", "NOT NULL DEFAULT TRUE"}
}

Columns required to store user decisions in database.

Definition at line 78 of file database.hpp.


The documentation for this class was generated from the following files: