FOSSology  3.2.0rc1
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...
 
bool insertNoResultInDatabase (long agentId, long pFileId) const
 Insert empty findings in database to prevent scan on next upload. 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...
 

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 63 of file database.hpp.

Member Function Documentation

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 168 of file database.cc.

bool CopyrightDatabaseHandler::createTableClearing ( ) const
private

Create table to store user decisions.

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

Definition at line 248 of file database.cc.

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 111 of file database.cc.

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 85 of file database.cc.

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 65 of file database.cc.

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 385 of file database.cc.

bool CopyrightDatabaseHandler::insertNoResultInDatabase ( long  agentId,
long  pFileId 
) const

Insert empty findings in database to prevent scan on next upload.

Parameters
agentIdId of agent which did not find any statement
pFileIdId of the file on which no statements were found
Returns
True on success, false otherwise

Definition at line 364 of file database.cc.

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 317 of file database.cc.

CopyrightDatabaseHandler CopyrightDatabaseHandler::spawn ( ) const

Spawn/fork a new database handler and return it.

Returns
CopyrightDatabaseHandler object with spawned DbManager

Definition at line 52 of file database.cc.

Member Data Documentation

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 89 of file database.hpp.

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 90 of file database.hpp.


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