Project

General

Profile

« Previous | Next » 

Revision 2032

bin/map: Use the same XML tree for each row in DB outputs, to eliminate time spent creating the tree from the XPaths for each row

View differences:

map
226 226
                    # All put_obj()s should return the same id_node
227 227
                    nodes, id_node = xpath.put_obj(root, out, '-1', has_types,
228 228
                        '$'+str(in_)) # value is placeholder that documents name
229
                #assert id_node != None
229
                    mappings[i] = [in_, nodes]
230
                assert id_node != None
230 231
                
231 232
                if debug: # only str() if debug
232 233
                    log_debug('Put template:\n'+str(root))
233
                prep_root()
234 234
            
235 235
            def process_row(row, i):
236 236
                row_id = str(i)
237
                if id_node != None: xml_dom.set_value(id_node, row_id)
237 238
                for in_, out in mappings:
238 239
                    log_debug('Getting '+str(in_))
239 240
                    value = metadata_value(in_)
240 241
                    if value == None: value = cleanup(get_value(in_, row))
241 242
                    log_debug('Putting '+repr(value)+' to '+str(out))
242
                    if out_is_db or value != None:
243
                    if out_is_db: # out is list of XML nodes
244
                        for node in out: xml_dom.set_value(node, value)
245
                    elif value != None: # out is XPath
243 246
                        xpath.put_obj(root, out, row_id, has_types, value)
244 247
                if debug: log_debug('Putting:\n'+str(root))# only str() if debug
245 248
            return process_rows(process_row, rows, **kw_args)
......
366 369
                    ex_tracker.track(e, row_num)
367 370
                pool.share_vars(locals())
368 371
                
369
                xml_func.process(root, on_error)
370
                if not xml_dom.is_empty(root):
371
                    assert xml_dom.has_one_child(root)
372
                row_root = root.cloneNode(True) # deep copy so don't modify root
373
                xml_func.process(row_root, on_error)
374
                if not xml_dom.is_empty(row_root):
375
                    assert xml_dom.has_one_child(row_root)
372 376
                    try:
373 377
                        sql.with_savepoint(out_db,
374
                            lambda: db_xml.put(out_db, root.firstChild,
378
                            lambda: db_xml.put(out_db, row_root.firstChild,
375 379
                                row_ins_ct_ref, on_error))
376 380
                        if commit: out_db.db.commit()
377 381
                    except sql.DatabaseErrors, e: on_error(e)
378
                prep_root()
379 382
            
380 383
            row_ct = process_inputs(root, row_ready)
381 384
            sys.stdout.write('Inserted '+str(row_ins_ct_ref[0])+

Also available in: Unified diff