[R repo, schema] use VIRTUAL_RTYPES const
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 31 Jul 2009 23:30:56 +0200
changeset 2596 d02eed70937f
parent 2595 e76bf303c6f2
child 2597 d9c5a7e0563c
[R repo, schema] use VIRTUAL_RTYPES const
schema.py
server/checkintegrity.py
server/migractions.py
server/repository.py
server/schemaserial.py
server/sources/__init__.py
server/sqlutils.py
server/ssplanner.py
--- a/schema.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/schema.py	Fri Jul 31 23:30:56 2009 +0200
@@ -34,6 +34,9 @@
 schema.use_py_datetime()
 nodes.use_py_datetime()
 
+PURE_VIRTUAL_RTYPES = set(('identity', 'has_text',))
+VIRTUAL_RTYPES = set(('eid', 'identity', 'has_text',))
+
 #  set of meta-relations available for every entity types
 META_RELATIONS_TYPES = set((
     'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
--- a/server/checkintegrity.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/server/checkintegrity.py	Fri Jul 31 23:30:56 2009 +0200
@@ -13,6 +13,7 @@
 
 from logilab.common.shellutils import ProgressBar
 
+from cubicweb.schema import PURE_VIRTUAL_RTYPES
 from cubicweb.server.sqlutils import SQL_PREFIX
 
 def has_eid(sqlcursor, eid, eids):
@@ -196,9 +197,7 @@
     """check all relations registered in the repo system table"""
     print 'Checking relations'
     for rschema in schema.relations():
-        if rschema.is_final():
-            continue
-        if rschema == 'identity':
+        if rschema.is_final() or rschema in PURE_VIRTUAL_RTYPES:
             continue
         if rschema.inlined:
             for subjtype in rschema.subjects():
--- a/server/migractions.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/server/migractions.py	Fri Jul 31 23:30:56 2009 +0200
@@ -30,7 +30,7 @@
 from yams.schema2sql import eschema2sql, rschema2sql
 
 from cubicweb import AuthenticationError, ETYPE_NAME_MAP
-from cubicweb.schema import CubicWebRelationSchema
+from cubicweb.schema import VIRTUAL_RTYPES, CubicWebRelationSchema
 from cubicweb.dbapi import get_repository, repo_connect
 from cubicweb.common.migration import MigrationHelper, yes
 
@@ -241,7 +241,7 @@
 
     def _synchronize_permissions(self, ertype):
         """permission synchronization for an entity or relation type"""
-        if ertype in ('eid', 'has_text', 'identity'):
+        if ertype in VIRTUAL_RTYPES:
             return
         newrschema = self.fs_schema[ertype]
         teid = self.repo.schema[ertype].eid
--- a/server/repository.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/server/repository.py	Fri Jul 31 23:30:56 2009 +0200
@@ -34,8 +34,8 @@
                       ExecutionError, typed_eid,
                       CW_MIGRATION_MAP)
 from cubicweb.cwvreg import CubicWebRegistry
-from cubicweb.schema import CubicWebSchema
-
+from cubicweb.schema import VIRTUAL_RTYPES, CubicWebSchema
+from cubicweb import server
 from cubicweb.server.utils import RepoThread, LoopTask
 from cubicweb.server.pool import ConnectionsPool, LateOperation, SingleLastOperation
 from cubicweb.server.session import Session, InternalSession
@@ -115,7 +115,6 @@
     # the web interface but may occurs during test or dbapi connection (though
     # not expected for this).  So: don't do it, we pretend to ensure repository
     # consistency.
-    # XXX should probably not use unsafe_execute!
     if card[0] in '1?':
         rschema = session.repo.schema.rschema(rtype)
         if not rschema.inlined:
@@ -935,7 +934,7 @@
         eschema = self.schema.eschema(etype)
         for rschema, targetschemas, x in eschema.relation_definitions():
             rtype = rschema.type
-            if rtype == 'identity':
+            if rtype in VIRTUAL_RTYPES:
                 continue
             var = '%s%s' % (rtype.upper(), x.upper())
             if x == 'subject':
--- a/server/schemaserial.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/server/schemaserial.py	Fri Jul 31 23:30:56 2009 +0200
@@ -14,7 +14,7 @@
 
 from yams import schema as schemamod, buildobjs as ybo
 
-from cubicweb.schema import CONSTRAINTS, ETYPE_NAME_MAP
+from cubicweb.schema import CONSTRAINTS, ETYPE_NAME_MAP, VIRTUAL_RTYPES
 from cubicweb.server import sqlutils
 
 def group_mapping(cursor, interactive=True):
@@ -294,7 +294,7 @@
     groupmap = group_mapping(cursor, interactive=False)
     for ertype in aller:
         # skip eid and has_text relations
-        if ertype in ('eid', 'identity', 'has_text',):
+        if ertype in VIRTUAL_RTYPES:
             pb.update()
             continue
         for rql, kwargs in erschema2rql(schema[ertype]):
--- a/server/sources/__init__.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/server/sources/__init__.py	Fri Jul 31 23:30:56 2009 +0200
@@ -12,6 +12,7 @@
 from logging import getLogger
 
 from cubicweb import set_log_methods
+from cubicweb.schema import VIRTUAL_RTYPES
 from cubicweb.server.sqlutils import SQL_PREFIX
 
 
@@ -201,7 +202,7 @@
         # delete relations referencing one of those eids
         eidcolum = SQL_PREFIX + 'eid'
         for rschema in self.schema.relations():
-            if rschema.is_final() or rschema.type == 'identity':
+            if rschema.is_final() or rschema.type in VIRTUAL_RTYPES:
                 continue
             if rschema.inlined:
                 column = SQL_PREFIX + rschema.type
--- a/server/sqlutils.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/server/sqlutils.py	Fri Jul 31 23:30:56 2009 +0200
@@ -24,6 +24,7 @@
 from cubicweb.utils import todate, todatetime
 from cubicweb.common.uilib import remove_html_tags
 from cubicweb.toolsutils import restrict_perms_to_user
+from cubicweb.schema import PURE_VIRTUAL_RTYPES
 from cubicweb.server import SQL_CONNECT_HOOKS
 from cubicweb.server.utils import crypt_password
 
@@ -77,7 +78,7 @@
 
 def sqlschema(schema, driver, text_index=True,
               user=None, set_owner=False,
-              skip_relations=('has_text', 'identity'), skip_entities=()):
+              skip_relations=PURE_VIRTUAL_RTYPES, skip_entities=()):
     """return the system sql schema, according to the given parameters"""
     from yams.schema2sql import schema2sql
     from cubicweb.server.sources import native
@@ -102,7 +103,7 @@
 
 
 def sqldropschema(schema, driver, text_index=True,
-                  skip_relations=('has_text', 'identity'), skip_entities=()):
+                  skip_relations=PURE_VIRTUAL_RTYPES, skip_entities=()):
     """return the sql to drop the schema, according to the given parameters"""
     from yams.schema2sql import dropschema2sql
     from cubicweb.server.sources import native
--- a/server/ssplanner.py	Fri Jul 31 23:27:53 2009 +0200
+++ b/server/ssplanner.py	Fri Jul 31 23:30:56 2009 +0200
@@ -13,6 +13,7 @@
 from rql.nodes import Constant
 
 from cubicweb import QueryError, typed_eid
+from cubicweb.schema import VIRTUAL_RTYPES
 
 def add_types_restriction(schema, rqlst, newroot=None, solutions=None):
     if newroot is None:
@@ -196,7 +197,7 @@
         relations, attrrelations = [], []
         getrschema = self.schema.rschema
         for relation in rqlst.main_relations:
-            if relation.r_type in ('eid', 'has_text', 'identity'):
+            if relation.r_type in VIRTUAL_RTYPES:
                 raise QueryError('can not assign to %r relation'
                                  % relation.r_type)
             lhs, rhs = relation.get_variable_parts()