def loadStock(self, tuples): ''' Specialized method for laoding stock ''' #need to reestablish because some large values cause problems with scalaris ws self.conn = JSONConnection(url=self.database) self.tran = TransactionSingleOp(self.conn) stock_d = defaultdict(defaultdict) tableDef = TABLE_COLUMNS[constants.TABLENAME_STOCK] stock_idx = defaultdict(list) for tuple in tuples: stock = dict(zip(tableDef, tuple)) tuple_short = [tuple[0], tuple[2]] stock_short = dict(zip(['S_I_ID', 'S_QUANTITY'], tuple_short)) s_w_id = stock['S_W_ID'] s_i_id = stock['S_I_ID'] stock_d[s_w_id][s_i_id] = stock stock_idx[s_w_id].append(stock_short) for s in stock_d.keys(): s_key = '%s.%s.%s' % (constants.TABLENAME_WAREHOUSE, s, constants.TABLENAME_STOCK) print "key %s" % s_key print "value %s" % stock_idx[s] self.tran.write(s_key, stock_idx[s]) for w in stock_d.keys(): for i in stock_d[w].keys(): s_key = '%s.%s.%s.%s' % (constants.TABLENAME_WAREHOUSE, w, constants.TABLENAME_STOCK, i) self.tran.write(s_key, stock_d[s][i])
def loadConfig(self, config): for key in ScalarisDriver.DEFAULT_CONFIG.keys(): assert key in config, "Missing parameter '%s' in %s configuration" % ( key, self.name) self.database = str(config["database"]) self.conn = JSONConnection(url=self.database) #self.tran = self.transactionFactory() #single op is much faster for nearly all operations self.tran = TransactionSingleOp(self.conn)
def loadSimpleTuples(self, tableName, tuples): """Load a list of tuples into the target table""" self.conn = JSONConnection(url=self.database) self.tran = TransactionSingleOp(self.conn) if len(tuples) == 0: return idx = 0 tableDef = TABLE_COLUMNS[tableName] for tuple in tuples: pId = tuple[0] value = dict(zip(tableDef[1:], tuple[1:])) primaryKey = createPrimaryKey(tableName, pId, value) self.tran.write(primaryKey, value) #self.tran.commit() if idx == 500: print '%s %s' % (tableName, primaryKey) idx = 0 # self.tran.commit() idx += 1
def executeStart(self): self.conn = JSONConnection(url=self.database) #self.tran = self.transactionFactory() self.tran = TransactionSingleOp(self.conn)