def _connections_for_states(base_mapper, uowtransaction, states): """Return an iterator of (state, state.dict, mapper, connection). The states are sorted according to _sort_states, then paired with the connection they should be using for the given unit of work transaction. """ # if session has a connection callable, # organize individual states with the connection # to use for update if uowtransaction.session.connection_callable: connection_callable = uowtransaction.session.connection_callable else: connection = None connection_callable = None for state in _sort_states(states): if connection_callable: connection = connection_callable(base_mapper, state.obj()) elif not connection: connection = uowtransaction.transaction.connection(base_mapper) mapper = _state_mapper(state) yield state, state.dict, mapper, connection
def _connections_for_states(base_mapper, uowtransaction, states): """Return an iterator of (state, state.dict, mapper, connection). The states are sorted according to _sort_states, then paired with the connection they should be using for the given unit of work transaction. """ # if session has a connection callable, # organize individual states with the connection # to use for update if uowtransaction.session.connection_callable: connection_callable = \ uowtransaction.session.connection_callable else: connection = uowtransaction.transaction.connection( base_mapper) connection_callable = None for state in _sort_states(states): if connection_callable: connection = connection_callable(base_mapper, state.obj()) mapper = _state_mapper(state) yield state, state.dict, mapper, connection
def remove(self, state, item, initiator): sess = session._state_session(state) if sess: prop = _state_mapper(state).get_property(self.key) # expunge pending orphans if prop.cascade.delete_orphan and \ item in sess.new and \ prop.mapper._is_orphan(attributes.instance_state(item)): sess.expunge(item)
def append(self, state, item, initiator): # process "save_update" cascade rules for when # an instance is appended to the list of another instance sess = _state_session(state) if sess: prop = _state_mapper(state).get_property(self.key) if prop.cascade.save_update and item not in sess: sess.add(item) return item
def register_object(self, state, isdelete=False, listonly=False, cancel_delete=False): if not self.session._contains_state(state): return if state not in self.states: mapper = _state_mapper(state) if mapper not in self.mappers: mapper._per_mapper_flush_actions(self) self.mappers[mapper].add(state) self.states[state] = (isdelete, listonly) else: if not listonly and (isdelete or cancel_delete): self.states[state] = (isdelete, False)
def set(self, state, newvalue, oldvalue, initiator): # process "save_update" cascade rules for when an instance # is attached to another instance if oldvalue is newvalue: return newvalue sess = _state_session(state) if sess: prop = _state_mapper(state).get_property(self.key) if newvalue is not None and \ prop.cascade.save_update and \ newvalue not in sess: sess.add(newvalue) if prop.cascade.delete_orphan and \ oldvalue in sess.new and \ prop.mapper._is_orphan(attributes.instance_state(oldvalue)): sess.expunge(oldvalue) return newvalue
def keyfunc(value): state = instance_state(value) m = _state_mapper(state) return tuple(m._get_state_attr_by_column(state, c) for c in mapping_spec)
def keyfunc(value): state = instance_state(value) m = _state_mapper(state) return m._get_state_attr_by_column(state, cols[0])