我需要在Google Appengine中使用交易吗? [英] Do I need to use transactions in google appengine

查看:99
本文介绍了我需要在Google Appengine中使用交易吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新0
我的 def post()代码已经发生了巨大变化,因为它最初是基于数字形式,复选框和文本输入字段,而不仅仅是文本输入字段,这是当前的设计更像纸张。但是,结果我还有其他问题可以通过提出的解决方案之一解决,但我不能完全遵循所提出的解决方案,所以让我试着解释新的设计和问题。



小问题是我的实现效率低下,因为在 def post()中,我创建了一个独立的<$每个输入时隙是一个长字符串< courtname>< timeslotstarthour>< timeslotstartminute> ,c $ c> name 在我的代码中,这个 name 是用嵌套的循环的循环读取的,其代码如下[非常低效,我想]。

  tempreservation = courtname + str(time [0])+ str(time [1])$ ​​b $ b name = self .request.get('tempreservation',None)

更严重的直接问题是我的 def post()代码永远不会被读取,我不知道为什么(也许它之前没有被读取,但我没有测试过)。我想知道现在的问题是,我想同时发布帖子和完成。下面第一行是post(),第二行是get()。

  return webapp2.redirect( / read /%s%location_id)
self.render_template('read.html',{'courts':court,'location':location,... etc ...}

我的新帖子()如下:注意我在代码中留下了 logging.info 来查看我是否到达那里。

  class MainPageCourt(BaseHandler):

def post(self,location_id):
logging.info(in MainPageCourt post)
startTime = self.request.get('startTime')
endTime = self.request。 get('endTime')
day = self.request.get('day')
weekday = self.request.get('weekday')
nowweekday = self.request.get 'nowweekday')
year = self.request.get('year')
month = self.request.get('month')
nowmonth = self.request.get('nowmonth ')
courtnames = self.request.get_all('court')
for courtnames:
logging.info(courtname:%s%c)
times =区间(startTime,endTime )
为法庭名称中的法院名称:
为时间中的时间:
tempreservation = courtname + str(time [0])+ str(time [1])$ ​​b $ b name = self。 request.get('tempreservation',None)
如果名称:
iden = courtname
court = db.Key.from_path('Locations',location_id,'Courts',iden)
reservation = Reservations(parent = court)
reservation.name = name
reservation.starttime = time
reservation.year = year
reservation.nowmonth = int(nowmonth)
reservation.day = int(day)
reservation.nowweekday = int(nowweekday)
reservation.put()
返回webapp2.redirect(/ read /%s%location_id)



最后,我想通过比较数据存储区中的现有预订数据与隐含的新预订来添加对上述get()代码的检查/验证,并启动一条警报,告知用户可能存在的任何潜在问题地址。



我也希望对这两个问题发表任何意见。

更新结束0



我的应用程序适用于社区网球场。我想用模拟纸张的在线数字表格替换纸张注册表单。尽管看起来不太可能,但在两次网球任命相撞时可能会出现交易性冲突。那么,我该如何给第二个预约制造商一个正面冲突的机会,同时也让成功的一方有机会像她在纸上(用橡皮擦)一样改变她的任命。



每半小时是表格上的一个时间段。在submitting之前,人们通常会一次注册多个半小时。
因此,在循环内的代码中,我执行get_all。如果任何成功,我想让用户控制是否接受put()或不。我仍然认为put()将是全部或全部,而不是选择性的。



所以我的问题是,我需要使用明确的代码交易?
$ b $ pre> class MainPageCourt(BaseHandler):

def post(self,location_id):
reservations = self.request.get_all('reservations')
day = self.request.get('day')
weekday = self.request.get('weekday')
nowweekday = self.request.get('nowweekday')
year = self.request.get('year')
month = self.request.get('month')
nowmonth = self.request.get('nowmonth')
如果不保留:
for r in reservations:
r = r.split()
iden = r [0]
temp = iden +''+ r [1] +''+ r [2]
court = db.Key.from_path('Locations',location_id,'Courts',iden)
reservation = Re
reservation.starttime = [int(r [1]),int(r [2])]
reservation.year = int(r [3])
reservation.nowmonth = int(r [4])
reservation.day = int(r [5])
reservation.nowweekday = int(nowweekday)
reservation.name = self.request。 get(temp)
reservation.put()
返回webapp2.redirect(/ read /%s%location_id)
else:
...这个重要的代码不是书面,等待...
返回webapp2.redirect(/ adjust /%s%location_id)


解决方案

查看乐观并发控制:
http://en.wikipedia.org/wiki/Optimistic_concurrency_control

update 0 My def post() code has changed dramatically because originally it was base on a digital form which included both checkboxes and text entry fields, not just text entry fields, which is the current design to be more paper-like. However, as a result I have other problems which may be solved by one of the proposed solutions, but I cannot exactly follow that proposed solution, so let me try to explain new design and the problems.

The smaller problem is the inefficiency of my implementation because in the def post() I create a distinct name for each input timeslot which is a long string <courtname><timeslotstarthour><timeslotstartminute>. In my code this name is read in a nested for loop with the following snippet [very inefficient, I imagine].

tempreservation=courtname+str(time[0])+str(time[1])
name = self.request.get('tempreservation',None)

The more serious immediate problem is that my def post() code is never read and I cannot figure out why (and maybe it wasn't being read before, either, but I had not tested that far). I wonder if the problem is that for now I want both the post and the get to "finish" the same way. The first line below is for the post() and the second is for the get().

return webapp2.redirect("/read/%s" % location_id)
self.render_template('read.html', {'courts': courts,'location': location, ... etc ...}

My new post() is as follows. Notice I have left in the code the logging.info to see if I ever get there.

class MainPageCourt(BaseHandler):

    def post(self, location_id):
        logging.info("in MainPageCourt post  ")
        startTime = self.request.get('startTime')
        endTime = self.request.get('endTime')
        day = self.request.get('day')
        weekday = self.request.get('weekday')
        nowweekday = self.request.get('nowweekday')
        year = self.request.get('year')
        month = self.request.get('month')
        nowmonth = self.request.get('nowmonth')
        courtnames = self.request.get_all('court')
        for c in courtnames:
            logging.info("courtname: %s " % c)
        times=intervals(startTime,endTime)
        for courtname in courtnames:
            for time in times:
                tempreservation=courtname+str(time[0])+str(time[1])
                name = self.request.get('tempreservation',None)
                if name:
                    iden = courtname
                    court = db.Key.from_path('Locations',location_id,'Courts', iden)
                    reservation = Reservations(parent=court) 
                    reservation.name = name
                    reservation.starttime = time
                    reservation.year = year
                    reservation.nowmonth = int(nowmonth)
                    reservation.day = int(day)
                    reservation.nowweekday = int(nowweekday)
                    reservation.put()
        return webapp2.redirect("/read/%s" % location_id)

Eventually I want to add checking/validating to the above get() code by comparing the existing Reservations data in the datastore with the implied new reservations, and kick out to an alert which tells the user of any potential problems which she can address.

I would also appreciate any comments on these two problems.

end of update 0

My app is for a community tennis court. I want to replace the paper sign up sheet with an online digital sheet that mimics a paper sheet. As unlikely as it seems there may be "transactional" conflicts where two tennis appointments collide. So how do I give the second appointment maker a heads up to the conflict but also give the successful party the opportunity to alter her appointment like she would on paper (with an eraser).

Each half hour is a time slot on the form. People normally sign up for multiple half hours at one time before "submitting".

So in my code within a loop I do a get_all. If any get succeeds I want to give the user control over whether to accept the put() or not. I am still thinking the put() would be an all or nothing, not selective.

So my question is, do I need to make part of the code use an explicit "transaction"?

class MainPageCourt(BaseHandler):

    def post(self, location_id):
        reservations = self.request.get_all('reservations')
        day = self.request.get('day')
        weekday = self.request.get('weekday')
        nowweekday = self.request.get('nowweekday')
        year = self.request.get('year')
        month = self.request.get('month')
        nowmonth = self.request.get('nowmonth')
        if not reservations:
            for r in reservations:
                r=r.split()
                iden = r[0]
                temp = iden+' '+r[1]+' '+r[2]
                court = db.Key.from_path('Locations',location_id,'Courts', iden)
                reservation = Reservations(parent=court) 
                reservation.starttime = [int(r[1]),int(r[2])]
                reservation.year = int(r[3])
                reservation.nowmonth = int(r[4])
                reservation.day = int(r[5])
                reservation.nowweekday = int(nowweekday)
                reservation.name = self.request.get(temp)
                reservation.put()
            return webapp2.redirect("/read/%s" % location_id)
        else:
            ... this important code is not written, pending ...
            return webapp2.redirect("/adjust/%s" % location_id)

解决方案

Have a look at optimistic concurrency control: http://en.wikipedia.org/wiki/Optimistic_concurrency_control

这篇关于我需要在Google Appengine中使用交易吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆