40
40
import pymongo
41
41
42
42
import constants
43
- from abstractdriver import AbstractDriver
43
+ from . abstractdriver import AbstractDriver
44
44
45
45
TABLE_COLUMNS = {
46
46
constants .TABLENAME_ITEM : [
@@ -345,9 +345,9 @@ def loadConfig(self, config):
345
345
logging .error ("ConnectionFailure %d (%s) when connected to %s: " ,
346
346
exc .code , exc .details , display_uri )
347
347
return
348
- except pymongo .errors .PyMongoError , err :
348
+ except pymongo .errors .PyMongoError as err :
349
349
logging .error ("Some general error (%s) when connected to %s: " , str (err ), display_uri )
350
- print "Got some other error: %s" % str (err )
350
+ print ( "Got some other error: %s" % str (err ) )
351
351
return
352
352
353
353
## ----------------------------------------------
@@ -408,7 +408,7 @@ def loadTuples(self, tableName, tuples):
408
408
tuple_dicts .append (dict ([(columns [i ], t [i ]) for i in num_columns ]))
409
409
## FOR
410
410
411
- self .database [tableName ].insert (tuple_dicts )
411
+ self .database [tableName ].insert_many (tuple_dicts )
412
412
## IF
413
413
414
414
return
@@ -593,7 +593,7 @@ def _doNewOrderTxn(self, s, params):
593
593
session = s )
594
594
if not d :
595
595
d1 = self .district .find_one ({"D_ID" : d_id , "D_W_ID" : w_id , "$comment" : "new order did not find district" })
596
- print d1 , w_id , d_id , c_id , i_ids , i_w_ids , s_dist_col
596
+ print ( d1 , w_id , d_id , c_id , i_ids , i_w_ids , s_dist_col )
597
597
assert d , "Couldn't find district in new order w_id %d d_id %d" % (w_id , d_id )
598
598
else :
599
599
d = self .district .find_one ({"D_ID" : d_id , "D_W_ID" : w_id , "$comment" : comment },
@@ -621,7 +621,8 @@ def _doNewOrderTxn(self, s, params):
621
621
#print constants.INVALID_ITEM_MESSAGE + ", Aborting transaction (ok for 1%)"
622
622
return None
623
623
## IF
624
- items = sorted (items , key = lambda x : i_ids .index (x ['I_ID' ]))
624
+ xxi_ids = tuple (map (lambda o : o ['I_ID' ], items ))
625
+ items = sorted (items , key = lambda x : xxi_ids .index (x ['I_ID' ]))
625
626
626
627
# getWarehouseTaxRate
627
628
w = self .warehouse .find_one ({"W_ID" : w_id , "$comment" : comment }, {"_id" :0 , "W_TAX" : 1 }, session = s )
@@ -676,7 +677,8 @@ def _doNewOrderTxn(self, s, params):
676
677
session = s ))
677
678
## IF
678
679
assert len (all_stocks ) == ol_cnt , "all_stocks len %d != ol_cnt %d" % (len (all_stocks ), ol_cnt )
679
- all_stocks = sorted (all_stocks , key = lambda x : item_w_list .index ((x ['S_I_ID' ], x ["S_W_ID" ])))
680
+ xxxi_ids = tuple (map (lambda o : (o ['S_I_ID' ], o ['S_W_ID' ]), all_stocks ))
681
+ all_stocks = sorted (all_stocks , key = lambda x : xxxi_ids .index ((x ['S_I_ID' ], x ["S_W_ID" ])))
680
682
681
683
## ----------------
682
684
## Insert Order Line, Stock Item Information
@@ -820,7 +822,7 @@ def _doOrderStatusTxn(self, s, params):
820
822
all_customers = list (self .customer .find (search_fields , return_fields , session = s ))
821
823
namecnt = len (all_customers )
822
824
assert namecnt > 0 , "No matching customer for last name %s!" % c_last
823
- index = (namecnt - 1 )/ 2
825
+ index = (namecnt - 1 )// 2
824
826
c = all_customers [index ]
825
827
c_id = c ["C_ID" ]
826
828
## IF
@@ -891,7 +893,7 @@ def _doPaymentTxn(self, s, params):
891
893
session = s )
892
894
if not d :
893
895
d1 = self .district .find_one ({"D_ID" : d_id , "D_W_ID" : w_id , "$comment" : "payment did not find district" })
894
- print d1 , w_id , d_id , h_amount , c_w_id , c_d_id , c_id , c_last , h_date
896
+ print ( d1 , w_id , d_id , h_amount , c_w_id , c_d_id , c_id , c_last , h_date )
895
897
assert d , "Couldn't find district in payment w_id %d d_id %d" % (w_id , d_id )
896
898
else :
897
899
d = self .district .find_one ({"D_W_ID" : w_id , "D_ID" : d_id , "$comment" : comment },
@@ -942,7 +944,7 @@ def _doPaymentTxn(self, s, params):
942
944
all_customers = list (self .customer .find (search_fields , return_fields , session = s ))
943
945
namecnt = len (all_customers )
944
946
assert namecnt > 0 , "No matching customer w %d d %d clast %s" % (w_id , d_id , c_last )
945
- index = (namecnt - 1 )/ 2
947
+ index = (namecnt - 1 )// 2
946
948
c = all_customers [index ]
947
949
c_id = c ["C_ID" ]
948
950
## IF
@@ -1075,9 +1077,9 @@ def _doStockLevelTxn(self, s, params):
1075
1077
ol_ids .add (ol ["OL_I_ID" ])
1076
1078
## FOR
1077
1079
1078
- result = self .stock .find ({"S_W_ID" : w_id ,
1080
+ result = self .stock .count_documents ({"S_W_ID" : w_id ,
1079
1081
"S_I_ID" : {"$in" : list (ol_ids )},
1080
- "S_QUANTITY" : {"$lt" : threshold }, "$comment" : comment }). count ()
1082
+ "S_QUANTITY" : {"$lt" : threshold }, "$comment" : comment })
1081
1083
1082
1084
return int (result )
1083
1085
@@ -1095,11 +1097,11 @@ def run_transaction(self, txn_callback, session, name, params):
1095
1097
exc .code , exc .details , name )
1096
1098
return (False , None )
1097
1099
logging .error ("Failed with unknown OperationFailure: %d" , exc .code )
1098
- print "Failed with unknown OperationFailure: %d" % exc .code
1099
- print exc .details
1100
+ print ( "Failed with unknown OperationFailure: %d" % exc .code )
1101
+ print ( exc .details )
1100
1102
raise
1101
1103
except pymongo .errors .ConnectionFailure :
1102
- print "ConnectionFailure during %s: " % name
1104
+ print ( "ConnectionFailure during %s: " % name )
1103
1105
return (False , None )
1104
1106
## TRY
1105
1107
0 commit comments