forked from jan-hoelscher-mss/safmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XactCmds.h
executable file
·117 lines (100 loc) · 3.01 KB
/
XactCmds.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef _XACTCMDS_H_
#define _XACTCMDS_H_
#include "Command.h"
#include "ServiceThread.h"
#include "comdefs.h"
#include "server_operators.h"
#include "QAccessControl.h"
#include "Log.h"
#include "TransactionManager.h"
namespace safmq {
extern const char* EC_Decode(ErrorCode);
class BeginTransactionCmd : public Command {
protected:
ErrorCode response;
public:
BeginTransactionCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~BeginTransactionCmd() {}
static Command* allocate(ServiceThread* pservice) { return new BeginTransactionCmd(pservice); }
virtual void readRequest(std::istream& i) {
SAFMQ_INT32 zero;
i.read((char*)&zero, sizeof(zero));
}
virtual void writeResponse(std::ostream& o) {
o << RESPONSE_RESPONSE(response) << std::flush;
}
virtual int perform() {
// TODO: Change this to verify logged in status
bool ok = service->getTransactionManager()->BeginTransaction();
if (ok) {
response = EC_NOERROR;
} else {
response = EC_ALREADYOPEN;
}
return 0;
}
};
class CommitTransactionCmd : public Command {
public:
CommitTransactionCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~CommitTransactionCmd() {}
static Command* allocate(ServiceThread* pservice) { return new CommitTransactionCmd(pservice); }
virtual void readRequest(std::istream& i) {
SAFMQ_INT32 zero;
i.read((char*)&zero,sizeof(zero));
}
virtual void writeResponse(std::ostream& o) {
o << RESPONSE_RESPONSE(EC_NOERROR) << std::flush;
}
virtual int perform() {
// TODO: Change this to verify logged in status
service->getTransactionManager()->CommitTransaction();
return 0;
}
};
class RollbackTransactionCmd : public Command {
protected:
public:
RollbackTransactionCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~RollbackTransactionCmd() {}
static Command* allocate(ServiceThread* pservice) { return new RollbackTransactionCmd(pservice); }
virtual void readRequest(std::istream& i) {
SAFMQ_INT32 zero;
i.read((char*)&zero,sizeof(zero));
}
virtual void writeResponse(std::ostream& o) {
// TODO: Change this to verify logged in status
o << RESPONSE_RESPONSE(EC_NOERROR) << std::flush;
}
virtual int perform() {
service->getTransactionManager()->RollbackTransaction();
return 0;
}
};
class EndTransactionCmd : public Command {
protected:
ErrorCode response;
public:
EndTransactionCmd(ServiceThread* pservice) : Command(pservice) {}
virtual ~EndTransactionCmd() {}
static Command* allocate(ServiceThread* pservice) { return new EndTransactionCmd(pservice); }
virtual void readRequest(std::istream& i) {
SAFMQ_INT32 zero;
i.read((char*)&zero,sizeof(zero));
}
virtual void writeResponse(std::ostream& o) {
o << RESPONSE_RESPONSE(response) << std::flush;
}
virtual int perform() {
// TODO: Change this to verify logged in status
bool ok = service->getTransactionManager()->EndTransaction();
if (ok) {
response = EC_NOERROR;
} else {
response = EC_NOTOPEN;
}
return 0;
}
};
}
#endif