--- a/server/session.py Fri Mar 29 17:39:14 2013 +0100
+++ b/server/session.py Fri Mar 29 18:00:37 2013 +0100
@@ -391,6 +391,7 @@
#: server.Repository object
self.repo = session.repo
+ self.vreg = self.repo.vreg
#: connection handling mode
self.mode = session.default_mode
@@ -664,6 +665,29 @@
"""return the source where the entity with id <eid> is located"""
return self.repo.source_from_eid(eid, self)
+ # resource accessors ######################################################
+
+ def system_sql(self, sql, args=None, rollback_on_failure=True):
+ """return a sql cursor on the system database"""
+ if sql.split(None, 1)[0].upper() != 'SELECT':
+ self.mode = 'write'
+ source = self.cnxset.source('system')
+ try:
+ return source.doexec(self, sql, args, rollback=rollback_on_failure)
+ except (source.OperationalError, source.InterfaceError):
+ if not rollback_on_failure:
+ raise
+ source.warning("trying to reconnect")
+ self.cnxset.reconnect(source)
+ return source.doexec(self, sql, args, rollback=rollback_on_failure)
+
+ def rtype_eids_rdef(self, rtype, eidfrom, eidto):
+ # use type_and_source_from_eid instead of type_from_eid for optimization
+ # (avoid two extra methods call)
+ subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0]
+ objtype = self.repo.type_and_source_from_eid(eidto, self)[0]
+ return self.vreg.schema.rschema(rtype).rdefs[(subjtype, objtype)]
+
def tx_attr(attr_name, writable=False):
"""return a property to forward attribute access to transaction.
@@ -1016,29 +1040,10 @@
# resource accessors ######################################################
- def system_sql(self, sql, args=None, rollback_on_failure=True):
- """return a sql cursor on the system database"""
- if sql.split(None, 1)[0].upper() != 'SELECT':
- self.mode = 'write'
- source = self.cnxset.source('system')
- try:
- return source.doexec(self, sql, args, rollback=rollback_on_failure)
- except (source.OperationalError, source.InterfaceError):
- if not rollback_on_failure:
- raise
- source.warning("trying to reconnect")
- self.cnxset.reconnect(source)
- return source.doexec(self, sql, args, rollback=rollback_on_failure)
-
- deleted_in_transaction = tx_meth('deleted_in_transaction')
- added_in_transaction = tx_meth('added_in_transaction')
-
- def rtype_eids_rdef(self, rtype, eidfrom, eidto):
- # use type_and_source_from_eid instead of type_from_eid for optimization
- # (avoid two extra methods call)
- subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0]
- objtype = self.repo.type_and_source_from_eid(eidto, self)[0]
- return self.vreg.schema.rschema(rtype).rdefs[(subjtype, objtype)]
+ system_sql = tx_meth('system_sql')
+ deleted_in_transaction = tx_meth('deleted_in_transaction')
+ added_in_transaction = tx_meth('added_in_transaction')
+ rtype_eids_rdef = tx_meth('rtype_eids_rdef')
# security control #########################################################