del self.data[i]
i -= 1
+ def hash(self):
+ return id(self)
def _setrecord(self, item):
try:
val = self.records[item]
self.application = createfunc()
self.threadlocal = {}
self.scopes = {
- 'application' : {'call' : self._call_application, 'clear' : self._clear_application},
- 'thread' : {'call' : self._call_thread, 'clear':self._clear_thread}
+ 'application' : {'call' : self._call_application, 'clear' : self._clear_application, 'set':self._set_application},
+ 'thread' : {'call' : self._call_thread, 'clear':self._clear_thread, 'set':self._set_thread}
}
def __call__(self, scope = None):
scope = self.defaultscope
return self.scopes[scope]['call']()
+ def set(self, obj, scope = None):
+ if scope is None:
+ scope = self.defaultscope
+ return self.scopes[scope]['set'](obj)
+
def clear(self, scope = None):
if scope is None:
scope = self.defaultscope
return self.scopes[scope]['clear']()
-
+
+ def _set_thread(self, obj):
+ self.threadlocal[thread.get_ident()] = obj
+
def _call_thread(self):
try:
return self.threadlocal[thread.get_ident()]
except KeyError:
pass
+ def _set_application(self, obj):
+ self.application = obj
+
def _call_application(self):
return self.application
# assert the first one retreives the same from the identity map
nu = m.get(u.user_id)
self.assert_(u is nu)
-
+
+ print "STEP 1"
+ print repr(objectstore.identity_map)
+
# clear out the identity map, so next get forces a SELECT
objectstore.clear()
+ print "STEP 2"
+ print repr(objectstore.identity_map)
+
# check it again, identity should be different but ids the same
nu = m.get(u.user_id)
self.assert_(u is not nu and u.user_id == nu.user_id and nu.user_name == 'savetester')
# change first users name and save
u.user_name = 'modifiedname'
+ print "STEP 3"
+ print repr(objectstore.identity_map)
objectstore.uow().commit()
# select both
+ #objectstore.clear()
userlist = m.select(users.c.user_id.in_(u.user_id, u2.user_id), order_by=[users.c.user_name])
+ print repr(userlist)
# making a slight assumption here about the IN clause mechanics with regards to ordering
self.assert_(u.user_id == userlist[0].user_id and userlist[0].user_name == 'modifiedname')
self.assert_(u2.user_id == userlist[1].user_id and userlist[1].user_name == 'savetester2')