forked from r3ap3rpy/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.py
61 lines (46 loc) · 1.38 KB
/
Command.py
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
from abc import ABCMeta, abstractmethod
class Transaction(metaclass = ABCMeta):
@abstractmethod
def execute(self):
pass
class SELECT(Transaction):
def __init__(self, transaction):
self.trans = transaction
def execute(self):
self.trans.SELECT()
class INSERT(Transaction):
def __init__(self, transaction):
self.trans = transaction
def execute(self):
self.trans.INSERT()
class UPDATE(Transaction):
def __init__(self, transaction):
self.trans = transaction
def execute(self):
self.trans.UPDATE()
class TransactionManager:
def SELECT(self):
print('Performing SELECT operation!')
def INSERT(self):
print('Performing INSERT operation!')
def UPDATE(self):
print('Performing UPDATE operation!')
class TransactionBroker:
def __init__(self):
self.__transactionQeueue = []
def requestTransaction(self, transaction):
self.__transactionQeueue.append(transaction)
transaction.execute()
if __name__ == '__main__':
traction = TransactionManager()
tr_select = SELECT(traction)
tr_insert = INSERT(traction)
tr_update = UPDATE(traction)
brkr = TransactionBroker()
brkr.requestTransaction(tr_select)
brkr.requestTransaction(tr_insert)
brkr.requestTransaction(tr_insert)
brkr.requestTransaction(tr_select)
brkr.requestTransaction(tr_update)
brkr.requestTransaction(tr_insert)
brkr.requestTransaction(tr_update)