diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-08-09 19:51:36 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-08-09 19:51:36 +0000 |
commit | b0253eb9b5eca87fde3f9341e403985e1dcf74c4 (patch) | |
tree | 8ff8d3a37b8c2adc084099fcca0008d6cc7db5b9 /lib/sqlalchemy | |
parent | bdd780dd88950106df09f81e539067f3bd98a06c (diff) | |
download | sqlalchemy-b0253eb9b5eca87fde3f9341e403985e1dcf74c4.tar.gz |
- added 'object_session' as classlevel method to Session
- moved 'identity_key' to be a classmethod on Session
- some docstrings
- merged r3229 from 0.3 branch to unconditonally quote schemaname in PG-reflected default
- name fixes in dynamic unit test
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/scoping.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/session.py | 27 |
3 files changed, 23 insertions, 10 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index d3467105b..8f04eca26 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -447,7 +447,9 @@ class PGDialect(ansisql.ANSIDialect): # the default is related to a Sequence sch = table.schema if '.' not in match.group(2) and sch is not None: - default = match.group(1) + sch + '.' + match.group(2) + match.group(3) + # unconditionally quote the schema name. this could + # later be enhanced to obey quoting rules / "quote schema" + default = match.group(1) + ('"%s"' % sch) + '.' + match.group(2) + match.group(3) colargs.append(schema.PassiveDefault(sql.text(default))) table.append_column(schema.Column(name, coltype, nullable=nullable, *colargs)) diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py index fc2fba87b..86050e975 100644 --- a/lib/sqlalchemy/orm/scoping.py +++ b/lib/sqlalchemy/orm/scoping.py @@ -81,7 +81,7 @@ def clslevel(name): def do(cls, *args,**kwargs): return getattr(Session, name)(*args, **kwargs) return classmethod(do) -for prop in ('close_all',): +for prop in ('close_all','object_session', 'identity_key'): setattr(ScopedSession, prop, clslevel(prop)) class _ScopedExt(MapperExtension): diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index e7268dd98..ab12d4c14 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -502,12 +502,6 @@ class Session(object): self.uow = unitofwork.UnitOfWork(weak_identity_map=self.weak_identity_map) self.uow.echo = echo - def mapper(self, class_, entity_name=None): - """Given a ``Class``, return the primary ``Mapper`` responsible for - persisting it.""" - - return _class_mapper(class_, entity_name = entity_name) - def bind_mapper(self, mapper, bind, entity_name=None): """Bind the given `mapper` or `class` to the given ``Engine`` or ``Connection``. @@ -801,7 +795,7 @@ class Session(object): finally: _recursive.remove(mapper) - def identity_key(self, *args, **kwargs): + def identity_key(cls, *args, **kwargs): """Get an identity key. Valid call signatures: @@ -863,7 +857,14 @@ class Session(object): % ", ".join(kwargs.keys())) mapper = _object_mapper(instance) return mapper.identity_key_from_instance(instance) - + identity_key = classmethod(identity_key) + + def object_session(cls, obj): + """return the ``Session`` to which the given object belongs.""" + + return object_session(obj) + object_session = classmethod(object_session) + def _save_impl(self, object, **kwargs): if hasattr(object, '_instance_key'): if not self.identity_map.has_key(object._instance_key): @@ -942,15 +943,25 @@ class Session(object): return getattr(obj, '_sa_session_id', None) == self.hash_key def __contains__(self, obj): + """return True if the given object is associated with this session. + + The instance may be pending or persistent within the Session for a + result of True. + """ + return self._is_attached(obj) and (obj in self.uow.new or self.identity_map.has_key(obj._instance_key)) def __iter__(self): + """return an iterator of all objects which are pending or persistent within this Session.""" + return iter(list(self.uow.new) + self.uow.identity_map.values()) def _get(self, key): return self.identity_map[key] def has_key(self, key): + """return True if the given identity key is present within this Session's identity map.""" + return self.identity_map.has_key(key) dirty = property(lambda s:s.uow.locate_dirty(), |