FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ScancodeDatabaseHandler Class Reference
Inheritance diagram for ScancodeDatabaseHandler:
Inheritance graph
Collaboration diagram for ScancodeDatabaseHandler:
Collaboration graph

Classes

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

Public Member Functions

 ScancodeDatabaseHandler (fo::DbManager dbManager)
 Default constructor for ScanCode Database Handler class. More...
 
 ScancodeDatabaseHandler (ScancodeDatabaseHandler &&other)
 
ScancodeDatabaseHandler spawn () const
 Instantiate a new object spawn for ScanCode Database handler Used to create new objects for threads. More...
 
long saveLicenseMatch (int agentId, long pFileId, long licenseId, int percentMatch)
 save license match with license_ref table in license_file table Insert license if already not present in license_file table More...
 
bool insertNoResultInDatabase (int agentId, long pFileId, long licenseId)
 Insert null value of license for uploads having no licenses. More...
 
bool saveHighlightInfo (long licenseFileId, unsigned start, unsigned length)
 save highlight information in the highlight table More...
 
void insertOrCacheLicenseIdForName (std::string const &rfShortName, std::string const &rfFullname, std::string const &rfTexturl)
 calling function for selectOrInsertLicenseIdForName More...
 
unsigned long getCachedLicenseIdForName (std::string const &rfShortName) const
 for given short name search license More...
 
bool insertInDatabase (DatabaseEntry &entry) const
 insert copyright/author in scancode_copyright/scancode_author table More...
 
std::vector< unsigned long > queryFileIdsForUpload (int uploadId, bool ignoreFilesWithMimeType)
 Function to get pfile ID for uploads. More...
 
bool createTables () const
 create tables to save copyright and author informations 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

unsigned long selectOrInsertLicenseIdForName (std::string rfShortname, std::string rfFullname, std::string rfTexturl)
 insert license if not present in license_ref table and return rf_pk More...
 
bool createTableAgentEvents (string tablename) const
 create table to store agent events More...
 
bool createTableAgentFindings (string tablename) const
 create table to store agent findings More...
 
std::string getColumnCreationString (const ColumnDef in[], size_t size) const
 get string of parameters for a column for table creation
More...
 

Private Attributes

std::unordered_map< std::string, long > licenseRefCache
 

Static Private Attributes

static const ColumnDef columns_author []
 Columns required to store author information by scancode agent. More...
 
static const ColumnDef columns_copyright []
 Columns required to store copyright information by scancode agent. More...
 
static const ColumnDef columns_author_event []
 Columns required to store author deactivated statement. More...
 
static const ColumnDef columns_copyright_event []
 Columns required to store copyright deactivated statement. More...
 

Additional Inherited Members

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

Detailed Description

Definition at line 69 of file scancode_dbhandler.hpp.

Constructor & Destructor Documentation

◆ ScancodeDatabaseHandler()

ScancodeDatabaseHandler::ScancodeDatabaseHandler ( fo::DbManager  dbManager)

Default constructor for ScanCode Database Handler class.

Parameters
dbManagerDBManager to be used

Definition at line 65 of file scancode_dbhandler.cc.

Member Function Documentation

◆ createTableAgentEvents()

bool ScancodeDatabaseHandler::createTableAgentEvents ( string  tableName) const
private

create table to store agent events

Parameters
tableNamename of the table to be created
Returns
true on successful creation, false otherwise

Definition at line 612 of file scancode_dbhandler.cc.

◆ createTableAgentFindings()

bool ScancodeDatabaseHandler::createTableAgentFindings ( string  tableName) const
private

create table to store agent findings

Parameters
tableNamename of the table to be created
Returns
true on successful creation, false otherwise

Definition at line 495 of file scancode_dbhandler.cc.

◆ createTables()

bool ScancodeDatabaseHandler::createTables ( ) const

create tables to save copyright and author informations

Returns
true on successful creation, false otherwise

Definition at line 424 of file scancode_dbhandler.cc.

◆ getCachedLicenseIdForName()

unsigned long ScancodeDatabaseHandler::getCachedLicenseIdForName ( std::string const &  rfShortName) const

for given short name search license

Parameters
rfShortNamespdx license key for the license
Returns
license id if found in license_ref table, 0 otherwise

Definition at line 215 of file scancode_dbhandler.cc.

◆ getColumnCreationString()

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

get string of parameters for a column for table creation

Parameters
in[]input array of struct ColumnDef
sizesize of in[]
Returns
string of parameters

Definition at line 45 of file scancode_dbhandler.cc.

◆ insertInDatabase()

bool ScancodeDatabaseHandler::insertInDatabase ( DatabaseEntry entry) const

insert copyright/author in scancode_copyright/scancode_author table

Parameters
entryobject of DatabaseEntry class
Returns
true on success, false otherwise

Definition at line 394 of file scancode_dbhandler.cc.

◆ insertNoResultInDatabase()

bool ScancodeDatabaseHandler::insertNoResultInDatabase ( int  agentId,
long  pFileId,
long  licenseId 
)

Insert null value of license for uploads having no licenses.

Parameters
agentIdagent_pk in agent database table
pFileIdpfile_pk in pfile dataabse table
Returns
True on successful insertion, false otherwise

Definition at line 98 of file scancode_dbhandler.cc.

◆ insertOrCacheLicenseIdForName()

void ScancodeDatabaseHandler::insertOrCacheLicenseIdForName ( std::string const &  rfShortName,
std::string const &  rfFullname,
std::string const &  rfTexturl 
)

calling function for selectOrInsertLicenseIdForName

Parameters
rfShortNamespdx license key for the license
rfFullNamefull name of the license
rfTextUrlreference url for license text

Definition at line 197 of file scancode_dbhandler.cc.

◆ queryFileIdsForUpload()

vector< unsigned long > ScancodeDatabaseHandler::queryFileIdsForUpload ( int  uploadId,
bool  ignoreFilesWithMimeType 
)

Function to get pfile ID for uploads.

Parameters
uploadIdUpload ID of uploads
Returns
Vector of pfile IDs

Definition at line 87 of file scancode_dbhandler.cc.

◆ saveHighlightInfo()

bool ScancodeDatabaseHandler::saveHighlightInfo ( long  licenseFileId,
unsigned  start,
unsigned  length 
)

save highlight information in the highlight table

Parameters
licenseFileIdlicense_file pk
startstart byte of highlight_text
lengthtotal no of bytes from start byte
Returns
true on success to save highlight, false on failure

Definition at line 171 of file scancode_dbhandler.cc.

◆ saveLicenseMatch()

long ScancodeDatabaseHandler::saveLicenseMatch ( int  agentId,
long  pFileId,
long  licenseId,
int  percentMatch 
)

save license match with license_ref table in license_file table Insert license if already not present in license_file table

Parameters
agantIdagent pk in agent database table
pFileIdpfile pk in pfile dataabse table
licenseIdreference pk in license_ref table for matched or inserted license
percentMatchScore got for license from scancode agent
Returns
license_file pk on success, -1 on failure to save match

Definition at line 120 of file scancode_dbhandler.cc.

◆ selectOrInsertLicenseIdForName()

unsigned long ScancodeDatabaseHandler::selectOrInsertLicenseIdForName ( std::string  rfShortname,
std::string  rfFullname,
std::string  rfTexturl 
)
private

insert license if not present in license_ref table and return rf_pk

Parameters
rfShortNamespdx license key for the license
rfFullNamefull name of the license
rfTextUrlreference url for license text
Returns
licenseId on success, 0 on failure

Definition at line 255 of file scancode_dbhandler.cc.

◆ spawn()

ScancodeDatabaseHandler ScancodeDatabaseHandler::spawn ( ) const

Instantiate a new object spawn for ScanCode Database handler Used to create new objects for threads.

Returns
DbManager object for threads

Definition at line 76 of file scancode_dbhandler.cc.

Member Data Documentation

◆ columns_author

const ScancodeDatabaseHandler::ColumnDef ScancodeDatabaseHandler::columns_author
staticprivate
Initial value:
= {
#define ASEQUENCE_NAME
#define ACOLUMN_NAME_PK
{ACOLUMN_NAME_PK, "bigint",
"PRIMARY KEY DEFAULT nextval('" ASEQUENCE_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 to store author information by scancode agent.

Definition at line 98 of file scancode_dbhandler.hpp.

◆ columns_author_event

const ScancodeDatabaseHandler::ColumnDef ScancodeDatabaseHandler::columns_author_event
staticprivate
Initial value:
= {
#define AESEQUENCE_NAME
#define AECOLUMN_NAME_PK
{AECOLUMN_NAME_PK, "bigint",
"PRIMARY KEY DEFAULT nextval('" AESEQUENCE_NAME "'::regclass)"},
{"upload_fk", "bigint", "NOT NULL"},
{"uploadtree_fk", "bigint", "NOT NULL"},
{"scancode_author_fk", "bigint", "NOT NULL"},
{"content", "text", ""},
{"hash", "text", ""},
{"is_enabled", "boolean", "NOT NULL DEFAULT FALSE"},
{"scope", "int4", "NOT NULL"},
}

Columns required to store author deactivated statement.

Definition at line 102 of file scancode_dbhandler.hpp.

◆ columns_copyright

const ScancodeDatabaseHandler::ColumnDef ScancodeDatabaseHandler::columns_copyright
staticprivate
Initial value:
= {
#define CSEQUENCE_NAME
#define CCOLUMN_NAME_PK
{CCOLUMN_NAME_PK, "bigint",
"PRIMARY KEY DEFAULT nextval('" CSEQUENCE_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 to store copyright information by scancode agent.

Definition at line 99 of file scancode_dbhandler.hpp.

◆ columns_copyright_event

const ScancodeDatabaseHandler::ColumnDef ScancodeDatabaseHandler::columns_copyright_event
staticprivate
Initial value:
= {
#define CESEQUENCE_NAME
#define CECOLUMN_NAME_PK
{CECOLUMN_NAME_PK, "bigint",
"PRIMARY KEY DEFAULT nextval('" CESEQUENCE_NAME "'::regclass)"},
{"upload_fk", "bigint", "NOT NULL"},
{"uploadtree_fk", "bigint", "NOT NULL"},
{"scancode_copyright_fk", "bigint", "NOT NULL"},
{"content", "text", ""},
{"hash", "text", ""},
{"is_enabled", "boolean", "NOT NULL DEFAULT FALSE"},
{"scope", "int4", "NOT NULL"},
}

Columns required to store copyright deactivated statement.

Definition at line 103 of file scancode_dbhandler.hpp.


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