6 @author Oleksii <developers.hce@gmail.com> 7 @link http://hierarchical-cluster-engine.com/ 8 @copyright Copyright © 2013 IOIX Ukraine 9 @license http://hierarchical-cluster-engine.com/license/ 10 @package HCE project node API 18 from demoTask
import DemoBackLogTask
38 t1.data =
"fake data 1" 39 t2.data =
"fake data 2" 41 print self.
dbi.getErrorCode()
43 print self.
dbi.getErrorCode()
46 print db.session.query(
type(t1)).filter_by(id=t1.id, data=t1.data).all()
48 print self.
dbi.getErrorCode()
52 input_back_log_one_task = DemoBackLogTask(input_tasks[0]) 53 self.dbi.insert(input_back_log_one_task) 54 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 55 # handle insertion's error 56 print "One insert error!" 59 # do ptocessing after insertion 63 # insert array of objects 64 input_back_log_tasks = [DemoBackLogTask(input_task) for input_task in input_tasks] 65 self.dbi.insert(input_back_log_tasks) 66 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 67 # handle insertion's error 68 print "Bunch insert error!" 71 # do ptocessing after insertion 77 fetched_back_log_tasks = self.
dbi.fetch(fetch_back_log_tasks,
"id=%s"%fetch_back_log_tasks.id)
78 if self.
dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE:
80 print "One fetch error!" 85 for task
in fetched_back_log_tasks:
89 # fetch bunch of objects 90 fetch_back_log_tasks = [DemoBackLogTask(input_task) for input_task in input_tasks] 91 fetched_back_log_tasks = self.dbi.fetch(fetch_back_log_tasks) 92 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 93 # handle fetch's error 94 print "Bunch of fetch error!" 97 # do ptocessing after insertion 99 for task in fetched_back_log_tasks: 104 # fetch all for one object 105 fetch_back_log_tasks = DemoBackLogTask(input_tasks[0]) 106 fetched_back_log_tasks = self.dbi.fetchAll(fetch_back_log_tasks) 107 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 108 # handle fetch's error 109 print "fetch all for one object error!" 112 # do ptocessing after insertion 114 for task in fetched_back_log_tasks: 120 # fetch all for bunch of objects 121 fetch_back_log_tasks = [DemoBackLogTask(input_task) for input_task in input_tasks] 122 fetched_back_log_tasks = self.dbi.fetchAll(fetch_back_log_tasks) 123 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 124 # handle fetch's error 125 print "fetch all for bunch of objects error!" 128 # do ptocessing after insertion 130 for task in fetched_back_log_tasks: 137 update_back_log_tasks = DemoBackLogTask(Task(id="11111", Tries=22)) 138 updated_back_log_tasks = self.dbi.update(update_back_log_tasks, "id=%s"%update_back_log_tasks.id) 139 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 140 # handle update's error 141 print "update one object error!" 144 # do ptocessing after insertion 146 for task in updated_back_log_tasks: 152 # update bunch of objects 153 update_back_log_tasks = [DemoBackLogTask(input_task) for input_task in input_tasks] 154 updated_back_log_tasks = self.dbi.update(update_back_log_tasks) 155 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 156 # handle update's error 157 print "update bunch of objects error!" 160 # do ptocessing after insertion 162 for task in updated_back_log_tasks: 169 delete_back_log_tasks = DemoBackLogTask(Task(id="11111")) 170 deleted_back_log_tasks = self.dbi.delete(delete_back_log_tasks, "id=%s"%delete_back_log_tasks.id) 171 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 172 # handle update's error 173 print "delete one object error!" 176 # do ptocessing after insertion 178 for task in deleted_back_log_tasks: 183 # delete bunch of objects 184 delete_back_log_tasks = [DemoBackLogTask(input_task) for input_task in input_tasks] 185 deleted_back_log_tasks = self.dbi.delete(delete_back_log_tasks) 186 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 187 # handle update's error 188 print "delete bunch of objects error!" 191 # do ptocessing after insertion 193 for task in deleted_back_log_tasks: 200 deleted_back_log_tasks = self.
dbi.deleteAll(delete_back_log_tasks)
201 if self.
dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE:
203 print "delete all for one object error!" 208 for task
in deleted_back_log_tasks:
213 # delete all for bunch of objects 214 delete_back_log_tasks = [DemoBackLogTask(input_task) for input_task in input_tasks] 215 deleted_back_log_tasks = self.dbi.deleteAll(delete_back_log_tasks) 216 if self.dbi.getErrorCode() != CONSTANTS.DBI_SUCCESS_CODE: 217 # handle update's error 218 print "delete all for bunch of objects error!" 221 # do ptocessing after insertion 223 for task in deleted_back_log_tasks: 227 if __name__ ==
'__main__':
229 config = ConfigParser.ConfigParser()
230 config.read(
"dbi_demo.ini")
231 config_dic = dict(config._sections)
233 config_dic[k] = dict(config._defaults, **config_dic[k])
234 config_dic[k].pop(
'__name__',
None)
237 cdate = datetime.datetime.now()
238 tasks = [
Task(id=
"11111", Tries=11, CDate=cdate),
Task(id=
"22222", Tries=22)]
239 demo_task_manager.process(tasks)
demo object create table schema
def process(self, input_tasks)
def __init__(self, config_dic)