def get_collection(self, state, user_data=None): if user_data is None: user_data = self.get(state) try: return getattr(user_data, '_sa_adapter') except AttributeError: collections.CollectionAdapter(self, state, user_data) return getattr(user_data, '_sa_adapter')
def get_collection(self, state, user_data=None, passive=False): """retrieve the CollectionAdapter associated with the given state. Creates a new CollectionAdapter if one does not exist. """ if user_data is None: user_data = self.get(state, passive=passive) if user_data is PASSIVE_NORESULT: return user_data try: return getattr(user_data, '_sa_adapter') except AttributeError: # TODO: this codepath never occurs, and this # except/initialize should be removed collections.CollectionAdapter(self, state, user_data) return getattr(user_data, '_sa_adapter')
def initialize_collection(self, key, state, factory): user_data = factory() adapter = collections.CollectionAdapter(self.get_impl(key), state, user_data) return adapter, user_data
def _build_collection(self, state): """build a new, blank collection and return it wrapped in a CollectionAdapter.""" user_data = self.collection_factory() collection = collections.CollectionAdapter(self, state, user_data) return collection, user_data
def _build_collection(self, state): user_data = self.collection_factory() collection = collections.CollectionAdapter(self, state, user_data) return collection, user_data