-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransactionManager.h
More file actions
74 lines (58 loc) · 1.92 KB
/
TransactionManager.h
File metadata and controls
74 lines (58 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include <vector>
#include <string>
#include <chrono>
using namespace std;
struct operations{
string type; // R, W, IT, IE, D
int node; // table we want to operate on
int clientSocket;
};
struct transaction{
long long timeStamp;
vector<operations> op; // vector of operations (sort of like a chain)
};
class TransactionManager{
private:
// this will allow us to get the surrent time to do timestamp ordering
long long getTimeStamp(){
return chrono::duration_cast<chrono::milliseconds>(
chrono::system_clock::now().time_since_epoch()).count();
}
public:
transaction pickTransaction(const string& clientChoice){
transaction t; // create the transaction
t.timeStamp = getTimeStamp(); //get the timestamp
if(stoi(clientChoice) == 1){
// T1: Insert employee corresponding to a project
// hop 1: read from project table
// hop 2: insert to emplyees table
t.op.push_back({"R", 3});
t.op.push_back({"IE", 1});
}
else if(stoi(clientChoice) == 2){
// T2: add an employee to a project and insert corresponding task
// hop 1: read from projects
// hop 2: insert task
// hop 3: insert employee
t.op.push_back({"R", 1});
t.op.push_back({"IT", 2});
t.op.push_back({"IE", 1});
}
else if(stoi(clientChoice) == 3){
//T3: delete a task corresponding to a project (task complete)
// hop 1: read from projects
// hop 2: delte a task (change to update)
t.op.push_back({"R", 1});
t.op.push_back({"D", 2});
}
else if(stoi(clientChoice) == 4){
//T4: fire an employee corresponding to a project
// hop 1: read from projects
// hop 2: delte an employee
t.op.push_back({"R", 1});
t.op.push_back({"D", 3});
}
return t;
}
};