SearchSECODatabaseAPI
DatabaseConnection.h
1/*
2This program has been developed by students from the bachelor Computer Science at
3Utrecht University within the Software Project course.
4© Copyright Utrecht University (Department of Information and Computing Sciences)
5*/
6
7#pragma once
8#include "JobTypes.h"
9
10#include <string>
11#include <cassandra.h>
12
13#define IP "cassandra"
14#define DBPORT 8002
15#define UPDATE_JOBS_TIMEOUT 300000000 // 5 minutes.
16#define MAX_JOB_RETRIES 1
17#define RECOUNT_WAIT_TIME 600
18
19using namespace jobTypes;
20
25{
26public:
30 virtual void connect(std::string ip, int port);
31
36 virtual void uploadJob(Job job, bool newJob);
37
42 virtual Job getTopJob();
43
51 virtual Job getCurrentJob(std::string jobid);
52
59 virtual long long getCurrentJobTime(std::string jobid);
60
64 virtual long long addCurrentJob(Job job);
65
69 virtual void addFailedJob(FailedJob job);
70
74 virtual int getNumberOfJobs();
75
79 virtual int getCrawlID();
80
84 virtual void setCrawlID(int id);
85
89 virtual void updateCurrentJobs();
90
91private:
95 void deleteTopJob(CassUuid id, cass_int64_t priority);
96
100 void deleteCurrentJob(CassUuid id);
101
105 long long addCurrentJob(CassUuid id, Job job);
106
110 Job retrieveCurrentJob(const CassRow *row);
111
115 void setPreparedStatements();
116
120 virtual void updateCurrentJob(CassUuid jobid, Job job, long long currentTime);
121
125 CassSession *connection;
126
127 int numberOfJobs;
128 long long timeLastRecount = -1;
129
130 const CassPrepared *preparedGetTopJob;
131 const CassPrepared *preparedDeleteTopJob;
132 const CassPrepared *preparedAddCurrentJob;
133 const CassPrepared *preparedGetCurrentJob;
134 const CassPrepared *preparedGetCurrentJobs;
135 const CassPrepared *preparedDeleteCurrentJob;
136 const CassPrepared *preparedAddFailedJob;
137 const CassPrepared *preparedAmountOfJobs;
138 const CassPrepared *preparedUploadJob;
139 const CassPrepared *preparedUploadRetryJob;
140 const CassPrepared *preparedCrawlID;
141 const CassPrepared *preparedUpdateCrawlID;
142};
143
Handles interaction with database when dealing with job requests.
Definition: DatabaseConnection.h:25
virtual int getCrawlID()
Returns the current crawl ID in the database.
Definition: DatabaseConnection.cpp:361
virtual void updateCurrentJobs()
Regularly updates the current jobs to check for a timeout.
Definition: DatabaseConnection.cpp:455
virtual void setCrawlID(int id)
Sets the crawl ID in the database to the given value.
Definition: DatabaseConnection.cpp:390
virtual Job getTopJob()
Retrieves the url of the first job in the jobs table and returns it.
Definition: DatabaseConnection.cpp:65
virtual Job getCurrentJob(std::string jobid)
Retrieves a job with matching jobid in the currentjobs table.
Definition: DatabaseConnection.cpp:229
virtual long long getCurrentJobTime(std::string jobid)
Retrieves the time of a job with matching jobid in the currentjobs table.
Definition: DatabaseConnection.cpp:150
virtual void connect(std::string ip, int port)
Connect to the database.
Definition: DatabaseConnection.cpp:16
virtual void uploadJob(Job job, bool newJob)
Adds a job to the database given the url to a repository and a priority, together with number of prev...
Definition: DatabaseConnection.cpp:411
virtual long long addCurrentJob(Job job)
Adds a job to the currentjobs table.
Definition: DatabaseConnection.cpp:189
virtual void addFailedJob(FailedJob job)
Adds a job to the failedjobs table.
Definition: DatabaseConnection.cpp:294
virtual int getNumberOfJobs()
Returns the amount of jobs in the jobs table.
Definition: DatabaseConnection.cpp:327
Mirrors an entry of the failedjobs table in the database. Difference with Job is the addition of a re...
Definition: JobTypes.h:41
Mirrors an entry of the currentjobs table in the database.
Definition: JobTypes.h:16