SearchSECODatabaseAPI
DatabaseHandler Class Reference

Handles interaction with database. More...

#include <DatabaseHandler.h>

Public Member Functions

virtual void connect (std::string ip, int port)
 Establishes a connection to the database. More...
 
virtual bool addProject (ProjectIn project)
 Adds a project to database. More...
 
virtual void addHashToProject (ProjectIn project, int index)
 Adds a number of hashes to a project in the database, starting at some index. More...
 
virtual ProjectOut searchForProject (ProjectID projectID, Version version)
 Searches for a project in the database and returns it to the user if it exists. More...
 
virtual ProjectOut prevProject (ProjectID projectID)
 Retrieves the previous/latest version of the project present in the database. More...
 
virtual void addMethod (MethodIn method, ProjectIn project, long long prevVersion, long long parserVersion, bool newProject)
 Adds/updates a method to the tables methods and method_by_author. Takes in a method and a project and adds the method to the database with specific information of the project. More...
 
virtual std::vector< Hash > updateUnchangedFiles (std::vector< Hash > hashes, std::vector< std::string > files, ProjectIn project, long long prevVersion)
 Updates the methods in the previous version of the project that are part of an unchanged file. More...
 
virtual std::vector< MethodOuthashToMethods (std::string hash)
 Retrieves all methods with a given hash. More...
 
virtual Author idToAuthor (std::string id)
 Retrieves an author given its authorID. More...
 
virtual std::vector< MethodIDauthorToMethods (std::string authorID)
 Retrieves the methods created by an author given its authorID. More...
 

Detailed Description

Handles interaction with database.

Member Function Documentation

◆ addHashToProject()

void DatabaseHandler::addHashToProject ( ProjectIn  project,
int  index 
)
virtual

Adds a number of hashes to a project in the database, starting at some index.

Parameters
projectThe project from which the hashes should be added to the database.
indexThe starting index of the hashes which should be added to the database.

◆ addMethod()

void DatabaseHandler::addMethod ( MethodIn  method,
ProjectIn  project,
long long  prevVersion,
long long  parserVersion,
bool  newProject 
)
virtual

Adds/updates a method to the tables methods and method_by_author. Takes in a method and a project and adds the method to the database with specific information of the project.

Parameters
methodThe method to be added/updated.
projectThe project in which the method is located.
prevVersionThe previous version of the project.
parserVersionThe version of the parser.
newProjectIndication of the project being new or updated based on a previous version.

◆ addProject()

bool DatabaseHandler::addProject ( ProjectIn  project)
virtual

Adds a project to database.

Parameters
projectThe project to be added to the database.
Returns
A boolean value indicating if adding the project was successful.

◆ authorToMethods()

std::vector< MethodID > DatabaseHandler::authorToMethods ( std::string  authorID)
virtual

Retrieves the methods created by an author given its authorID.

Parameters
authorIDThe ID of the author to retrieve the methods for.
Returns
A vector with the necessary information of the methods the author has worked on.

◆ connect()

void DatabaseHandler::connect ( std::string  ip,
int  port 
)
virtual

Establishes a connection to the database.

Parameters
ipThe ip in string format.
portThe portnumber to connect to.

◆ hashToMethods()

std::vector< MethodOut > DatabaseHandler::hashToMethods ( std::string  hash)
virtual

Retrieves all methods with a given hash.

Parameters
hashThe hash to be checked.
Returns
All methods with the inputted hash.

◆ idToAuthor()

Author DatabaseHandler::idToAuthor ( std::string  id)
virtual

Retrieves an author given its authorID.

Parameters
idA string with the ID to be checked.
Returns
The author corresponding to the given ID.

◆ prevProject()

ProjectOut DatabaseHandler::prevProject ( ProjectID  projectID)
virtual

Retrieves the previous/latest version of the project present in the database.

Parameters
projectIDThe projectID of the project to be searched for.
Returns
If present, returns the previous/latest version of a project with the same projectID. Else, sets the errno to ERANGE and returns an empty project.

◆ searchForProject()

ProjectOut DatabaseHandler::searchForProject ( ProjectID  projectID,
Version  version 
)
virtual

Searches for a project in the database and returns it to the user if it exists.

Parameters
projectIDThe projectID of the project to be searched for.
versionThe version of the project to be searched for.
Returns
Returns the project corresponding to the input, if it exists. If no entry can be found, simply returns an empty project and sets the errno to ERANGE.

◆ updateUnchangedFiles()

std::vector< Hash > DatabaseHandler::updateUnchangedFiles ( std::vector< Hash >  hashes,
std::vector< std::string >  files,
ProjectIn  project,
long long  prevVersion 
)
virtual

Updates the methods in the previous version of the project that are part of an unchanged file.

Parameters
hashesA list of hashes to be checked.
filesA list of files to be checked.
projectThe added project for the projectID and new version.
prevVersionThe previous version of the project to check whether it is a correct result.
Returns
A list of hashes that are updated.

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