90 |
90 |
91 # Computed Rtype |
91 # Computed Rtype |
92 with cnx.ensure_cnx_set: |
92 with cnx.ensure_cnx_set: |
93 tables = set(t.lower() for t in dbhelper.list_tables(cnx.cnxset.cu)) |
93 tables = set(t.lower() for t in dbhelper.list_tables(cnx.cnxset.cu)) |
94 has_computed_relations = 'cw_cwcomputedrtype' in tables |
94 has_computed_relations = 'cw_cwcomputedrtype' in tables |
95 if has_computed_relations: |
|
96 rset = cnx.execute( |
|
97 'Any X, N, R, D WHERE X is CWComputedRType, X name N, ' |
|
98 'X rule R, X description D') |
|
99 for eid, rule_name, rule, description in rset.rows: |
|
100 rtype = ybo.ComputedRelation(name=rule_name, rule=rule, eid=eid, |
|
101 description=description) |
|
102 schema.add_relation_type(rtype) |
|
103 # computed attribute |
95 # computed attribute |
104 try: |
96 try: |
105 cnx.system_sql("SELECT cw_formula FROM cw_CWAttribute") |
97 cnx.system_sql("SELECT cw_formula FROM cw_CWAttribute") |
106 has_computed_attributes = True |
98 has_computed_attributes = True |
107 except Exception: |
99 except Exception: |
175 build_descr=False): |
167 build_descr=False): |
176 etype = ETYPE_NAME_MAP.get(etype, etype) |
168 etype = ETYPE_NAME_MAP.get(etype, etype) |
177 stype = ETYPE_NAME_MAP.get(stype, stype) |
169 stype = ETYPE_NAME_MAP.get(stype, stype) |
178 schema.eschema(etype)._specialized_type = stype |
170 schema.eschema(etype)._specialized_type = stype |
179 schema.eschema(stype)._specialized_by.append(etype) |
171 schema.eschema(stype)._specialized_by.append(etype) |
|
172 if has_computed_relations: |
|
173 rset = cnx.execute( |
|
174 'Any X, N, R, D WHERE X is CWComputedRType, X name N, ' |
|
175 'X rule R, X description D') |
|
176 for eid, rule_name, rule, description in rset.rows: |
|
177 rtype = ybo.ComputedRelation(name=rule_name, rule=rule, eid=eid, |
|
178 description=description) |
|
179 rschema = schema.add_relation_type(rtype) |
|
180 set_perms(rschema, permsidx) |
180 # load every relation types |
181 # load every relation types |
181 for eid, rtype, desc, sym, il, ftc in cnx.execute( |
182 for eid, rtype, desc, sym, il, ftc in cnx.execute( |
182 'Any X,N,D,S,I,FTC WHERE X is CWRType, X name N, X description D, ' |
183 'Any X,N,D,S,I,FTC WHERE X is CWRType, X name N, X description D, ' |
183 'X symmetric S, X inlined I, X fulltext_container FTC', build_descr=False): |
184 'X symmetric S, X inlined I, X fulltext_container FTC', build_descr=False): |
184 ertidx[eid] = rtype |
185 ertidx[eid] = rtype |
373 # skip virtual relations such as eid, has_text and identity |
374 # skip virtual relations such as eid, has_text and identity |
374 if rschema in VIRTUAL_RTYPES: |
375 if rschema in VIRTUAL_RTYPES: |
375 pb.update() |
376 pb.update() |
376 continue |
377 continue |
377 if rschema.rule: |
378 if rschema.rule: |
378 execschemarql(execute, rschema, crschema2rql(rschema)) |
379 execschemarql(execute, rschema, crschema2rql(rschema, groupmap)) |
379 pb.update() |
380 pb.update() |
380 continue |
381 continue |
381 execschemarql(execute, rschema, rschema2rql(rschema, addrdef=False)) |
382 execschemarql(execute, rschema, rschema2rql(rschema, addrdef=False)) |
382 if rschema.symmetric: |
383 if rschema.symmetric: |
383 rdefs = [rdef for k, rdef in rschema.rdefs.iteritems() |
384 rdefs = [rdef for k, rdef in rschema.rdefs.iteritems() |
523 else: |
524 else: |
524 values['fulltext_container'] = rschema.fulltext_container |
525 values['fulltext_container'] = rschema.fulltext_container |
525 relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)] |
526 relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)] |
526 return relations, values |
527 return relations, values |
527 |
528 |
528 def crschema2rql(crschema): |
529 def crschema2rql(crschema, groupmap): |
529 relations, values = crschema_relations_values(crschema) |
530 relations, values = crschema_relations_values(crschema) |
530 yield 'INSERT CWComputedRType X: %s' % ','.join(relations), values |
531 yield 'INSERT CWComputedRType X: %s' % ','.join(relations), values |
|
532 if groupmap: |
|
533 for rql, args in _erperms2rql(crschema, groupmap): |
|
534 yield rql, args |
531 |
535 |
532 def crschema_relations_values(crschema): |
536 def crschema_relations_values(crschema): |
533 values = _ervalues(crschema) |
537 values = _ervalues(crschema) |
534 values['rule'] = unicode(crschema.rule) |
538 values['rule'] = unicode(crschema.rule) |
535 # XXX why oh why? |
539 # XXX why oh why? |