server/schemaserial.py
changeset 10115 6fd167b140cd
parent 10095 200bd6a601dc
child 10191 cc4b8021bdf3
equal deleted inserted replaced
10112:ff7f86d8393d 10115:6fd167b140cd
   356     # is / is_instance_of insertion
   356     # is / is_instance_of insertion
   357     eschemas.remove(schema.eschema('CWEType'))
   357     eschemas.remove(schema.eschema('CWEType'))
   358     eschemas.insert(0, schema.eschema('CWEType'))
   358     eschemas.insert(0, schema.eschema('CWEType'))
   359     for eschema in eschemas:
   359     for eschema in eschemas:
   360         execschemarql(execute, eschema, eschema2rql(eschema, groupmap))
   360         execschemarql(execute, eschema, eschema2rql(eschema, groupmap))
   361         if pb is not None:
   361         pb.update()
   362             pb.update()
       
   363     # serialize constraint types
   362     # serialize constraint types
   364     cstrtypemap = {}
   363     cstrtypemap = {}
   365     rql = 'INSERT CWConstraintType X: X name %(ct)s'
   364     rql = 'INSERT CWConstraintType X: X name %(ct)s'
   366     for cstrtype in CONSTRAINTS:
   365     for cstrtype in CONSTRAINTS:
   367         cstrtypemap[cstrtype] = execute(rql, {'ct': unicode(cstrtype)},
   366         cstrtypemap[cstrtype] = execute(rql, {'ct': unicode(cstrtype)},
   368                                         build_descr=False)[0][0]
   367                                         build_descr=False)[0][0]
   369         if pb is not None:
   368         pb.update()
   370             pb.update()
       
   371     # serialize relations
   369     # serialize relations
   372     for rschema in schema.relations():
   370     for rschema in schema.relations():
   373         # skip virtual relations such as eid, has_text and identity
   371         # skip virtual relations such as eid, has_text and identity
   374         if rschema in VIRTUAL_RTYPES:
   372         if rschema in VIRTUAL_RTYPES:
   375             if pb is not None:
   373             pb.update()
   376                 pb.update()
       
   377             continue
   374             continue
   378         if rschema.rule:
   375         if rschema.rule:
   379             execschemarql(execute, rschema, crschema2rql(rschema))
   376             execschemarql(execute, rschema, crschema2rql(rschema))
   380             if pb is not None:
   377             pb.update()
   381                 pb.update()
       
   382             continue
   378             continue
   383         execschemarql(execute, rschema, rschema2rql(rschema, addrdef=False))
   379         execschemarql(execute, rschema, rschema2rql(rschema, addrdef=False))
   384         if rschema.symmetric:
   380         if rschema.symmetric:
   385             rdefs = [rdef for k, rdef in rschema.rdefs.iteritems()
   381             rdefs = [rdef for k, rdef in rschema.rdefs.iteritems()
   386                      if (rdef.subject, rdef.object) == k]
   382                      if (rdef.subject, rdef.object) == k]
   387         else:
   383         else:
   388             rdefs = rschema.rdefs.itervalues()
   384             rdefs = rschema.rdefs.itervalues()
   389         for rdef in rdefs:
   385         for rdef in rdefs:
   390             execschemarql(execute, rdef,
   386             execschemarql(execute, rdef,
   391                           rdef2rql(rdef, cstrtypemap, groupmap))
   387                           rdef2rql(rdef, cstrtypemap, groupmap))
   392         if pb is not None:
   388         pb.update()
   393             pb.update()
       
   394     # serialize unique_together constraints
   389     # serialize unique_together constraints
   395     for eschema in eschemas:
   390     for eschema in eschemas:
   396         if eschema._unique_together:
   391         if eschema._unique_together:
   397             execschemarql(execute, eschema, uniquetogether2rqls(eschema))
   392             execschemarql(execute, eschema, uniquetogether2rqls(eschema))
   398     # serialize yams inheritance relationships
   393     # serialize yams inheritance relationships
   399     for rql, kwargs in specialize2rql(schema):
   394     for rql, kwargs in specialize2rql(schema):
   400         execute(rql, kwargs, build_descr=False)
   395         execute(rql, kwargs, build_descr=False)
   401         if pb is not None:
   396         pb.update()
   402             pb.update()
       
   403     print
   397     print
   404 
   398 
   405 
   399 
   406 # high level serialization functions
   400 # high level serialization functions
   407 
   401