Issue ``INSERT`` and/or ``UPDATE`` statements for a list of objects. This is called within the context of a UOWTransaction during a flush operation, given a list of states to be flushed. The base mapper in an inheritance hierarchy handles the inserts/ updates for all descendant
(base_mapper, states, uowtransaction, single=False)
| 37 | |
| 38 | |
| 39 | def _save_obj(base_mapper, states, uowtransaction, single=False): |
| 40 | """Issue ``INSERT`` and/or ``UPDATE`` statements for a list |
| 41 | of objects. |
| 42 | |
| 43 | This is called within the context of a UOWTransaction during a |
| 44 | flush operation, given a list of states to be flushed. The |
| 45 | base mapper in an inheritance hierarchy handles the inserts/ |
| 46 | updates for all descendant mappers. |
| 47 | |
| 48 | """ |
| 49 | |
| 50 | # if batch=false, call _save_obj separately for each object |
| 51 | if not single and not base_mapper.batch: |
| 52 | for state in _sort_states(base_mapper, states): |
| 53 | _save_obj(base_mapper, [state], uowtransaction, single=True) |
| 54 | return |
| 55 | |
| 56 | states_to_update = [] |
| 57 | states_to_insert = [] |
| 58 | |
| 59 | for ( |
| 60 | state, |
| 61 | dict_, |
| 62 | mapper, |
| 63 | connection, |
| 64 | has_identity, |
| 65 | row_switch, |
| 66 | update_version_id, |
| 67 | ) in _organize_states_for_save(base_mapper, states, uowtransaction): |
| 68 | if has_identity or row_switch: |
| 69 | states_to_update.append( |
| 70 | (state, dict_, mapper, connection, update_version_id) |
| 71 | ) |
| 72 | else: |
| 73 | states_to_insert.append((state, dict_, mapper, connection)) |
| 74 | |
| 75 | for table, mapper in base_mapper._sorted_tables.items(): |
| 76 | if table not in mapper._pks_by_table: |
| 77 | continue |
| 78 | insert = _collect_insert_commands(table, states_to_insert) |
| 79 | |
| 80 | update = _collect_update_commands( |
| 81 | uowtransaction, table, states_to_update |
| 82 | ) |
| 83 | |
| 84 | _emit_update_statements( |
| 85 | base_mapper, |
| 86 | uowtransaction, |
| 87 | mapper, |
| 88 | table, |
| 89 | update, |
| 90 | ) |
| 91 | |
| 92 | _emit_insert_statements( |
| 93 | base_mapper, |
| 94 | uowtransaction, |
| 95 | mapper, |
| 96 | table, |
nothing calls this directly
no test coverage detected