[Sqlalchemy-commits] [1324] sqlalchemy/branches/schema/test: objectstore mod->session
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-04-23 21:05:34
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1324] sqlalchemy/branches/schema/test: objectstore mod->session</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1324</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-04-23 16:05:13 -0500 (Sun, 23 Apr 2006)</dd> </dl> <h3>Log Message</h3> <pre>objectstore mod->session "objectstore" is now a real object "Objectstore" (will probably change that..)</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemybranchesschemalibsqlalchemy__init__py">sqlalchemy/branches/schema/lib/sqlalchemy/__init__.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemymodsthreadlocalpy">sqlalchemy/branches/schema/lib/sqlalchemy/mods/threadlocal.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemyorm__init__py">sqlalchemy/branches/schema/lib/sqlalchemy/orm/__init__.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormmapperpy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormpropertiespy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormquerypy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py</a></li> <li><a href="#sqlalchemybranchesschematestmapperpy">sqlalchemy/branches/schema/test/mapper.py</a></li> <li><a href="#sqlalchemybranchesschematestobjectstorepy">sqlalchemy/branches/schema/test/objectstore.py</a></li> </ul> <h3>Added Paths</h3> <ul> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormsessionpy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/session.py</a></li> </ul> <h3>Removed Paths</h3> <ul> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormobjectstorepy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/objectstore.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemybranchesschemalibsqlalchemy__init__py"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/__init__.py (1323 => 1324)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/__init__.py 2006-04-23 20:49:51 UTC (rev 1323) +++ sqlalchemy/branches/schema/lib/sqlalchemy/__init__.py 2006-04-23 21:05:13 UTC (rev 1324) </span><span class="lines">@@ -14,10 +14,10 @@ </span><span class="cx"> from sqlalchemy.orm import * </span><span class="cx"> import sqlalchemy.ext.proxy </span><span class="cx"> </span><del>-from sqlalchemy.orm.objectstore import Session, get_session </del><ins>+from sqlalchemy.orm.session import Session, get_session </ins><span class="cx"> </span><span class="cx"> create_engine = sqlalchemy.engine.create_engine </span><del>-create_session = objectstore.Session </del><ins>+create_session = sqlalchemy.orm.session.Session </ins><span class="cx"> </span><span class="cx"> def global_connect(*args, **kwargs): </span><span class="cx"> sqlalchemy.schema.default_metadata.connect(*args, **kwargs) </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemymodsthreadlocalpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/mods/threadlocal.py (1323 => 1324)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/mods/threadlocal.py 2006-04-23 20:49:51 UTC (rev 1323) +++ sqlalchemy/branches/schema/lib/sqlalchemy/mods/threadlocal.py 2006-04-23 21:05:13 UTC (rev 1324) </span><span class="lines">@@ -1,8 +1,8 @@ </span><del>-from sqlalchemy import util, engine -from sqlalchemy.orm import unitofwork, objectstore </del><ins>+from sqlalchemy import util, engine, mapper +from sqlalchemy.orm import unitofwork, session +import sqlalchemy +import sys, types </ins><span class="cx"> </span><del>-import sys - </del><span class="cx"> """this plugin installs thread-local behavior at the Engine and Session level. </span><span class="cx"> </span><span class="cx"> The default Engine strategy will be "threadlocal", producing TLocalEngine instances for create_engine by default. </span><span class="lines">@@ -19,71 +19,102 @@ </span><span class="cx"> explicit Session objects when creating instances and creating queries. </span><span class="cx"> """ </span><span class="cx"> </span><del>-get_session = objectstore.get_session </del><ins>+get_session = session.get_session </ins><span class="cx"> </span><del>-def begin(*obj): - return get_session().begin(*obj) -def commit(*obj): - return get_session().commit(*obj) </del><ins>+class Objectstore(object): + def begin(self, *obj): + return get_session().begin(*obj) + def commit(self, *obj): + return get_session().commit(*obj) + def get_session(self, obj=None): + return get_session(obj=obj) + def flush(self, *obj): + """flushes the current UnitOfWork transaction. if a transaction was begun + via begin(), flushes only those objects that were created, modified, or deleted + since that begin statement. otherwise flushes all objects that have been + changed. </ins><span class="cx"> </span><del>-def flush(*obj): - """flushes the current UnitOfWork transaction. if a transaction was begun - via begin(), flushes only those objects that were created, modified, or deleted - since that begin statement. otherwise flushes all objects that have been - changed. </del><ins>+ if individual objects are submitted, then only those objects are committed, and the + begin/commit cycle is not affected.""" + get_session().flush(*obj) </ins><span class="cx"> </span><del>- if individual objects are submitted, then only those objects are committed, and the - begin/commit cycle is not affected.""" - get_session().flush(*obj) </del><ins>+ def clear(self): + """removes all current UnitOfWorks and IdentityMaps for this thread and + establishes a new one. It is probably a good idea to discard all + current mapped object instances, as they are no longer in the Identity Map.""" + get_session().clear() </ins><span class="cx"> </span><del>-def clear(): - """removes all current UnitOfWorks and IdentityMaps for this thread and - establishes a new one. It is probably a good idea to discard all - current mapped object instances, as they are no longer in the Identity Map.""" - get_session().clear() </del><ins>+ def refresh(self, *obj): + """reloads the state of this object from the database, and cancels any in-memory + changes.""" + get_session().refresh(*obj) </ins><span class="cx"> </span><del>-def refresh(*obj): - """reloads the state of this object from the database, and cancels any in-memory - changes.""" - get_session().refresh(*obj) </del><ins>+ def expire(self, *obj): + """invalidates the data in the given objects and sets them to refresh themselves + the next time they are requested.""" + get_session().expire(*obj) </ins><span class="cx"> </span><del>-def expire(*obj): - """invalidates the data in the given objects and sets them to refresh themselves - the next time they are requested.""" - get_session().expire(*obj) </del><ins>+ def expunge(self, *obj): + get_session().expunge(*obj) </ins><span class="cx"> </span><del>-def expunge(*obj): - get_session().expunge(*obj) </del><ins>+ def delete(self, *obj): + """registers the given objects as to be deleted upon the next commit""" + s = get_session().delete(*obj) </ins><span class="cx"> </span><del>-def delete(*obj): - """registers the given objects as to be deleted upon the next commit""" - s = get_session().delete(*obj) </del><ins>+ def has_key(self, key): + """returns True if the current thread-local IdentityMap contains the given instance key""" + return get_session().has_key(key) </ins><span class="cx"> </span><del>-def has_key(key): - """returns True if the current thread-local IdentityMap contains the given instance key""" - return get_session().has_key(key) </del><ins>+ def has_instance(self, instance): + """returns True if the current thread-local IdentityMap contains the given instance""" + return get_session().has_instance(instance) </ins><span class="cx"> </span><del>-def has_instance(instance): - """returns True if the current thread-local IdentityMap contains the given instance""" - return get_session().has_instance(instance) </del><ins>+ def is_dirty(self, obj): + """returns True if the given object is in the current UnitOfWork's new or dirty list, + or if its a modified list attribute on an object.""" + return get_session().is_dirty(obj) </ins><span class="cx"> </span><del>-def is_dirty(obj): - """returns True if the given object is in the current UnitOfWork's new or dirty list, - or if its a modified list attribute on an object.""" - return get_session().is_dirty(obj) </del><ins>+ def instance_key(self, instance): + """returns the IdentityMap key for the given instance""" + return get_session().instance_key(instance) </ins><span class="cx"> </span><del>-def instance_key(instance): - """returns the IdentityMap key for the given instance""" - return get_session().instance_key(instance) </del><ins>+ def import_instance(self, instance): + return get_session().import_instance(instance) </ins><span class="cx"> </span><del>-def import_instance(instance): - return get_session().import_instance(instance) - </del><ins>+def assign_mapper(class_, *args, **params): + params.setdefault("is_primary", True) + if not isinstance(getattr(class_, '__init__'), types.MethodType): + def __init__(self, **kwargs): + for key, value in kwargs.items(): + setattr(self, key, value) + class_.__init__ = __init__ + m = mapper(class_, *args, **params) + class_.mapper = m + class_.get = m.get + class_.select = m.select + class_.select_by = m.select_by + class_.selectone = m.selectone + class_.get_by = m.get_by + def commit(self): + sqlalchemy.objectstore.commit(self) + def delete(self): + sqlalchemy.objectstore.delete(self) + def expire(self): + sqlalchemy.objectstore.expire(self) + def refresh(self): + sqlalchemy.objectstore.refresh(self) + def expunge(self): + sqlalchemy.objectstore.expunge(self) + class_.commit = commit + class_.delete = delete + class_.expire = expire + class_.refresh = refresh + class_.expunge = expunge </ins><span class="cx"> def install_plugin(): </span><del>- mod = sys.modules[__name__] - for name in ['import_instance', 'instance_key', 'has_instance', 'is_dirty', 'has_key', 'delete', 'expunge', 'expire', 'refresh', 'clear', 'flush', 'begin', 'commit']: - setattr(objectstore, name, getattr(mod, name)) - reg = util.ScopedRegistry(objectstore.Session) - objectstore._default_session = lambda *args, **kwargs: reg() </del><ins>+ reg = util.ScopedRegistry(session.Session) + session._default_session = lambda *args, **kwargs: reg() </ins><span class="cx"> engine.default_strategy = 'threadlocal' </span><ins>+ sqlalchemy.objectstore = Objectstore() + sqlalchemy.assign_mapper = assign_mapper + </ins><span class="cx"> install_plugin() </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyorm__init__py"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/__init__.py (1323 => 1324)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/__init__.py 2006-04-23 20:49:51 UTC (rev 1323) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/__init__.py 2006-04-23 21:05:13 UTC (rev 1324) </span><span class="lines">@@ -12,7 +12,7 @@ </span><span class="cx"> import sqlalchemy.schema as schema </span><span class="cx"> import sqlalchemy.engine as engine </span><span class="cx"> import sqlalchemy.util as util </span><del>-import objectstore </del><ins>+import session </ins><span class="cx"> from exceptions import * </span><span class="cx"> import types as types </span><span class="cx"> from mapper import * </span><span class="lines">@@ -20,8 +20,8 @@ </span><span class="cx"> import mapper as mapperlib </span><span class="cx"> </span><span class="cx"> __all__ = ['relation', 'backref', 'eagerload', 'lazyload', 'noload', 'deferred', 'defer', 'undefer', </span><del>- 'mapper', 'clear_mappers', 'objectstore', 'sql', 'extension', 'class_mapper', 'object_mapper', 'MapperExtension', - 'assign_mapper', 'cascade_mappers' </del><ins>+ 'mapper', 'clear_mappers', 'sql', 'extension', 'class_mapper', 'object_mapper', 'MapperExtension', + 'cascade_mappers' </ins><span class="cx"> ] </span><span class="cx"> </span><span class="cx"> def relation(*args, **kwargs): </span><span class="lines">@@ -95,35 +95,6 @@ </span><span class="cx"> </span><span class="cx"> </span><span class="cx"> </span><del>-def assign_mapper(class_, *args, **params): - params.setdefault("is_primary", True) - if not isinstance(getattr(class_, '__init__'), types.MethodType): - def __init__(self, **kwargs): - for key, value in kwargs.items(): - setattr(self, key, value) - class_.__init__ = __init__ - m = mapper(class_, *args, **params) - class_.mapper = m - class_.get = m.get - class_.select = m.select - class_.select_by = m.select_by - class_.selectone = m.selectone - class_.get_by = m.get_by - def commit(self): - objectstore.commit(self) - def delete(self): - objectstore.delete(self) - def expire(self): - objectstore.expire(self) - def refresh(self): - objectstore.refresh(self) - def expunge(self): - objectstore.expunge(self) - class_.commit = commit - class_.delete = delete - class_.expire = expire - class_.refresh = refresh - class_.expunge = expunge </del><span class="cx"> </span><span class="cx"> def cascade_mappers(*classes_or_mappers): </span><span class="cx"> """given a list of classes and/or mappers, identifies the foreign key relationships </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py (1323 => 1324)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py 2006-04-23 20:49:51 UTC (rev 1323) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py 2006-04-23 21:05:13 UTC (rev 1324) </span><span class="lines">@@ -12,7 +12,7 @@ </span><span class="cx"> import sync </span><span class="cx"> from sqlalchemy.exceptions import * </span><span class="cx"> import query </span><del>-import objectstore </del><ins>+import session as sessionlib </ins><span class="cx"> import sys </span><span class="cx"> import weakref </span><span class="cx"> import sets </span><span class="lines">@@ -192,7 +192,7 @@ </span><span class="cx"> proplist.append(prop) </span><span class="cx"> </span><span class="cx"> if not mapper_registry.has_key(self.class_key) or self.is_primary or (inherits is not None and inherits._is_primary_mapper()): </span><del>- objectstore.global_attributes.reset_class_managed(self.class_) </del><ins>+ sessionlib.global_attributes.reset_class_managed(self.class_) </ins><span class="cx"> self._init_class() </span><span class="cx"> elif not non_primary: </span><span class="cx"> raise ArgumentError("Class '%s' already has a primary mapper defined. Use is_primary=True to assign a new primary mapper to the class, or use non_primary=True to create a non primary Mapper" % self.class_) </span><span class="lines">@@ -225,7 +225,7 @@ </span><span class="cx"> query = property(_get_query, doc=\ </span><span class="cx"> """returns an instance of sqlalchemy.orm.query.Query, which implements all the query-constructing </span><span class="cx"> methods such as get(), select(), select_by(), etc. The default Query object uses the global thread-local </span><del>- Session from the objectstore package. To get a Query object for a specific Session, call the </del><ins>+ Session from the session package. To get a Query object for a specific Session, call the </ins><span class="cx"> using(session) method.""") </span><span class="cx"> </span><span class="cx"> def get(self, *ident, **kwargs): </span><span class="lines">@@ -348,13 +348,13 @@ </span><span class="cx"> </span><span class="cx"> # this gets the AttributeManager to do some pre-initialization, </span><span class="cx"> # in order to save on KeyErrors later on </span><del>- objectstore.global_attributes.init_attr(self) </del><ins>+ sessionlib.global_attributes.init_attr(self) </ins><span class="cx"> </span><span class="cx"> nohist = kwargs.pop('_mapper_nohistory', False) </span><span class="cx"> if kwargs.has_key('_sa_session'): </span><span class="cx"> session = kwargs.pop('_sa_session') </span><span class="cx"> else: </span><del>- session = objectstore.get_session(self, raiseerror=False) </del><ins>+ session = sessionlib.get_session(self, raiseerror=False) </ins><span class="cx"> if session is not None: </span><span class="cx"> if not nohist: </span><span class="cx"> # register new with the correct session, before the object's </span><span class="lines">@@ -415,11 +415,11 @@ </span><span class="cx"> return result </span><span class="cx"> </span><span class="cx"> def identity_key(self, *primary_key): </span><del>- """returns the instance key for the given identity value. this is a global tracking object used by the objectstore, and is usually available off a mapped object as instance._instance_key.""" - return objectstore.get_id_key(tuple(primary_key), self.class_, self.entity_name) </del><ins>+ """returns the instance key for the given identity value. this is a global tracking object used by the Session, and is usually available off a mapped object as instance._instance_key.""" + return sessionlib.get_id_key(tuple(primary_key), self.class_, self.entity_name) </ins><span class="cx"> </span><span class="cx"> def instance_key(self, instance): </span><del>- """returns the instance key for the given instance. this is a global tracking object used by the objectstore, and is usually available off a mapped object as instance._instance_key.""" </del><ins>+ """returns the instance key for the given instance. this is a global tracking object used by the Session, and is usually available off a mapped object as instance._instance_key.""" </ins><span class="cx"> return self.identity_key(*self.identity(instance)) </span><span class="cx"> </span><span class="cx"> def identity(self, instance): </span><span class="lines">@@ -683,7 +683,7 @@ </span><span class="cx"> return False </span><span class="cx"> </span><span class="cx"> def register_dependencies(self, uowcommit, *args, **kwargs): </span><del>- """called by an instance of objectstore.UOWTransaction to register </del><ins>+ """called by an instance of unitofwork.UOWTransaction to register </ins><span class="cx"> which mappers are dependent on which, as well as DependencyProcessor </span><span class="cx"> objects which will process lists of objects in between saves and deletes.""" </span><span class="cx"> for prop in self.props.values(): </span><span class="lines">@@ -702,7 +702,7 @@ </span><span class="cx"> yield c </span><span class="cx"> </span><span class="cx"> def _identity_key(self, row): </span><del>- return objectstore.get_row_key(row, self.class_, self.pks_by_table[self.table], self.entity_name) </del><ins>+ return sessionlib.get_row_key(row, self.class_, self.pks_by_table[self.table], self.entity_name) </ins><span class="cx"> </span><span class="cx"> def _instance(self, session, row, imap, result = None, populate_existing = False): </span><span class="cx"> """pulls an object instance from the given row and appends it to the given result </span><span class="lines">@@ -767,7 +767,7 @@ </span><span class="cx"> </span><span class="cx"> # this gets the AttributeManager to do some pre-initialization, </span><span class="cx"> # in order to save on KeyErrors later on </span><del>- objectstore.global_attributes.init_attr(obj) </del><ins>+ sessionlib.global_attributes.init_attr(obj) </ins><span class="cx"> </span><span class="cx"> session._bind_to(obj) </span><span class="cx"> return obj </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormobjectstorepy"></a> <div class="delfile"><h4>Deleted: sqlalchemy/branches/schema/lib/sqlalchemy/orm/objectstore.py (1323 => 1324)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/objectstore.py 2006-04-23 20:49:51 UTC (rev 1323) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/objectstore.py 2006-04-23 21:05:13 UTC (rev 1324) </span><span class="lines">@@ -1,448 +0,0 @@ </span><del>-# objectstore.py -# Copyright (C) 2005,2006 Michael Bayer mi...@zz... -# -# This module is part of SQLAlchemy and is released under -# the MIT License: http://www.opensource.org/licenses/mit-license.php - -from sqlalchemy import util -from sqlalchemy.exceptions import * -import unitofwork, query -import weakref -import sqlalchemy -import sqlalchemy.sql as sql - - -class SessionTransaction(object): - def __init__(self, session, parent=None, autoflush=True): - self.session = session - self.connections = {} - self.parent = parent - self.autoflush = autoflush - def connection(self, mapper): - if self.parent is not None: - return self.parent.connection(mapper) - engine = self.session.get_bind(mapper) - return self.add(engine) - def _begin(self): - return SessionTransaction(self.session, self) - def add(self, connection_or_engine): - if self.connections.has_key(connection_or_engine): - return self.connections[connection_or_engine][0] - c = connection_or_engine.contextual_connect() - e = c.engine - if not self.connections.has_key(e): - self.connections[e] = (c, c.begin()) - return self.connections[e][0] - def commit(self): - if self.parent is not None: - return - if self.autoflush: - self.session.flush() - for t in self.connections.values(): - t[1].commit() - self.close() - def rollback(self): - if self.parent is not None: - self.parent.rollback() - return - for k, t in self.connections.iteritems(): - t[1].rollback() - self.close() - def close(self): - if self.parent is not None: - return - for t in self.connections.values(): - t[0].close() - self.session.transaction = None - -class Session(object): - def __init__(self, bind_to=None, hash_key=None, new_imap=True, import_session=None): - if import_session is not None: - self.uow = unitofwork.UnitOfWork(identity_map=import_session.uow.identity_map) - elif new_imap is False: - self.uow = unitofwork.UnitOfWork(identity_map=objectstore.get_session().uow.identity_map) - else: - self.uow = unitofwork.UnitOfWork() - - self.bind_to = bind_to - self.binds = {} - self.transaction = None - if hash_key is None: - self.hash_key = id(self) - else: - self.hash_key = hash_key - _sessions[self.hash_key] = self - - def create_transaction(self, **kwargs): - """returns a new SessionTransaction corresponding to an existing or new transaction. - if the transaction is new, the returned SessionTransaction will have commit control - over the underlying transaction, else will have rollback control only.""" - if self.transaction is not None: - return self.transaction._begin() - else: - self.transaction = SessionTransaction(self, **kwargs) - return self.transaction - def connect(self, mapper=None, **kwargs): - """returns a unique connection corresponding to the given mapper. this connection - will not be part of any pre-existing transactional context.""" - return self.get_bind(mapper).connect(**kwargs) - def connection(self, mapper, **kwargs): - """returns a Connection corresponding to the given mapper. used by the execute() - method which performs select operations for Mapper and Query. - if this Session is transactional, - the connection will be in the context of this session's transaction. otherwise, the connection - is returned by the contextual_connect method, which some Engines override to return a thread-local - connection, and will have close_with_result set to True. - - the given **kwargs will be sent to the engine's contextual_connect() method, if no transaction is in progress.""" - if self.transaction is not None: - return self.transaction.connection(mapper) - else: - return self.get_bind(mapper).contextual_connect(**kwargs) - def execute(self, mapper, clause, params, **kwargs): - """using the given mapper to identify the appropriate Engine or Connection to be used for statement execution, - executes the given ClauseElement using the provided parameter dictionary. Returns a ResultProxy corresponding - to the execution's results. If this method allocates a new Connection for the operation, then the ResultProxy's close() - method will release the resources of the underlying Connection, otherwise its a no-op. - """ - return self.connection(mapper).execute(clause, params, **kwargs) - def close(self): - """closes this Session. - - TODO: what should we do here ? - """ - if self.transaction is not None: - self.transaction.close() - def bind_mapper(self, mapper, bindto): - """binds the given Mapper to the given Engine or Connection. All subsequent operations involving this - Mapper will use the given bindto.""" - self.binds[mapper] = bindto - def bind_table(self, table, bindto): - """binds the given Table to the given Engine or Connection. All subsequent operations involving this - Table will use the given bindto.""" - self.binds[table] = bindto - def get_bind(self, mapper): - """given a Mapper, returns the Engine or Connection which is used to execute statements on behalf of this - Mapper. Calling connect() on the return result will always result in a Connection object. This method - disregards any SessionTransaction that may be in progress. - - The order of searching is as follows: - - if an Engine or Connection was bound to this Mapper specifically within this Session, returns that - Engine or Connection. - - if an Engine or Connection was bound to this Mapper's underlying Table within this Session - (i.e. not to the Table directly), returns that Engine or Conneciton. - - if an Engine or Connection was bound to this Session, returns that Engine or Connection. - - finally, returns the Engine which was bound directly to the Table's MetaData object. - - If no Engine is bound to the Table, an exception is raised. - """ - if mapper is None: - return self.bind_to - elif self.binds.has_key(mapper): - return self.binds[mapper] - elif self.binds.has_key(mapper.table): - return self.binds[mapper.table] - elif self.bind_to is not None: - return self.bind_to - else: - return mapper.table.engine - def query(self, mapper_or_class): - """given a mapper or Class, returns a new Query object corresponding to this Session and the mapper, or the classes' primary mapper.""" - if isinstance(mapper_or_class, type): - return query.Query(class_mapper(mapper_or_class), self) - else: - return query.Query(mapper_or_class, self) - def _sql(self): - class SQLProxy(object): - def __getattr__(self, key): - def call(*args, **kwargs): - kwargs[engine] = self.engine - return getattr(sql, key)(*args, **kwargs) - - sql = property(_sql) - - - def get_id_key(ident, class_, entity_name=None): - """returns an identity-map key for use in storing/retrieving an item from the identity - map, given a tuple of the object's primary key values. - - ident - a tuple of primary key values corresponding to the object to be stored. these - values should be in the same order as the primary keys of the table - - class_ - a reference to the object's class - - entity_name - optional string name to further qualify the class - """ - return (class_, tuple(ident), entity_name) - get_id_key = staticmethod(get_id_key) - - def get_row_key(row, class_, primary_key, entity_name=None): - """returns an identity-map key for use in storing/retrieving an item from the identity - map, given a result set row. - - row - a sqlalchemy.dbengine.RowProxy instance or other map corresponding result-set - column names to their values within a row. - - class_ - a reference to the object's class - - primary_key - a list of column objects that will target the primary key values - in the given row. - - entity_name - optional string name to further qualify the class - """ - return (class_, tuple([row[column] for column in primary_key]), entity_name) - get_row_key = staticmethod(get_row_key) - - def begin(self, *obj): - """deprecated""" - raise InvalidRequestError("Session.begin() is deprecated. use install_mod('legacy_session') to enable the old behavior") - def commit(self, *obj): - """deprecated""" - raise InvalidRequestError("Session.commit() is deprecated. use install_mod('legacy_session') to enable the old behavior") - - def flush(self, *obj): - """flushes all the object modifications present in this session to the database. if object - arguments are given, then only those objects (and immediate dependencies) are flushed.""" - self.uow.flush(self, *obj) - - def load(self, class_, *ident): - """given a class and a primary key identifier, loads the corresponding object.""" - return self.query(class_).get(*ident) - - def refresh(self, *obj): - """reloads the attributes for the given objects from the database, clears - any changes made.""" - for o in obj: - self.uow.refresh(o) - - def expire(self, *obj): - """invalidates the data in the given objects and sets them to refresh themselves - the next time they are requested.""" - for o in obj: - self.uow.expire(o) - - def expunge(self, *obj): - """removes the given objects from this Session. this will free all internal references to the objects.""" - for o in obj: - self.uow.expunge(o) - - def save(self, *obj, **kwargs): - """adds unsaved objects to this Session. - - The 'entity_name' keyword argument can also be given which will be assigned - to the instances if given. - """ - for o in obj: - for c in object_mapper(o, **kwargs).cascade_iterator('save-update', o): - if c is o: - self._save_impl(c, **kwargs) - else: - self.save_or_update(c, **kwargs) - - def update(self, *obj, **kwargs): - for o in obj: - for c in object_mapper(o, **kwargs).cascade_iterator('save-update', o): - if c is o: - self._update_impl(c, **kwargs) - else: - self.save_or_update(c, **kwargs) - - def save_or_update(self, *obj, **kwargs): - for o in obj: - for c in object_mapper(o, *kwargs).cascade_iterator('save-update', o): - key = getattr(o, '_instance_key', None) - if key is None: - self._save_impl(c, **kwargs) - else: - self._update_impl(c, **kwargs) - - def _save_impl(self, object, **kwargs): - if hasattr(object, '_instance_key'): - if not self.uow.has_key(object._instance_key): - raise InvalidRequestError("Instance '%s' attached to a different Session" % repr(object)) - else: - entity_name = kwargs.get('entity_name', None) - if entity_name is not None: - m = class_mapper(object.__class__, entity_name=entity_name) - m._assign_entity_name(object) - self._register_new(object) - - def _update_impl(self, object, **kwargs): - if self._is_bound(object) and object not in self.deleted: - return - if not hasattr(object, '_instance_key'): - raise InvalidRequestError("Instance '%s' is not persisted" % repr(object)) - if global_attributes.is_modified(object): - self._register_dirty(object) - else: - self._register_clean(object) - - def _register_new(self, obj): - self._bind_to(obj) - self.uow.register_new(obj) - def _register_dirty(self, obj): - self._bind_to(obj) - self.uow.register_dirty(obj) - def _register_clean(self, obj): - self._bind_to(obj) - self.uow.register_clean(obj) - def _register_deleted(self, obj): - self._bind_to(obj) - self.uow.register_deleted(obj) - def _bind_to(self, obj): - """given an object, binds it to this session. changes on the object will affect - the currently scoped UnitOfWork maintained by this session.""" - if getattr(obj, '_sa_session_id', None) != self.hash_key: - old = getattr(obj, '_sa_session_id', None) - # remove from old session. we do this gingerly since _sessions is a WeakValueDict - # and it might be affected by other threads - if old is not None: - try: - sess = _sessions[old] - except KeyError: - sess = None - if sess is not None: - sess.expunge(old) - obj._sa_session_id = self.hash_key - def _is_bound(self, obj): - return getattr(obj, '_sa_session_id', None) == self.hash_key - def __contains__(self, obj): - return self._is_bound(obj) and (obj in self.uow.new or self.uow.has_key(obj._instance_key)) - - def _get(self, key): - return self.uow._get(key) - def has_key(self, key): - return self.uow.has_key(key) - def is_expired(self, instance, **kwargs): - return self.uow.is_expired(instance, **kwargs) - - dirty = property(lambda s:s.uow.dirty) - deleted = property(lambda s:s.uow.deleted) - new = property(lambda s:s.uow.new) - identity_map = property(lambda s:s.uow.identity_map) - - def clear(self): - """removes all object instances from this Session. this is equivalent to calling expunge() for all - objects in this Session.""" - self.uow = unitofwork.UnitOfWork() - - def delete(self, *obj, **kwargs): - """registers the given objects to be deleted upon the next flush(). If the given objects are not part of this - Session, they will be imported. the objects are expected to either have an _instance_key - attribute or have all of their primary key attributes populated. - - the keyword argument 'entity_name' can also be provided which will be used by the import.""" - for o in obj: - for c in object_mapper(o, **kwargs).cascade_iterator('delete', o): - if not self._is_bound(c): - c = self.import_(c, **kwargs) - self.uow.register_deleted(c) - - - def merge(self, instance, entity_name=None): - """given an instance that represents a saved item, adds it to this session. - the return value is either the given instance, or if an instance corresponding to the - identity of the given instance already exists within this session, then that instance is returned; - the returned instance should always be used following this method. - - if the given instance does not have an _instance_key and also does not have all - of its primary key attributes populated, an exception is raised. similarly, if no - mapper can be located for the given instance, an exception is raised. - - this method should be used for any object instance that is coming from a serialized - storage, or was loaded by a Session other than this one. - - the keyword parameter entity_name is optional and is used to locate a Mapper for this - class which also specifies the given entity name. - """ - if instance is None: - return None - key = getattr(object, '_instance_key', None) - if key is None: - mapper = object_mapper(object, raiseerror=False) - if mapper is None: - mapper = class_mapper(object, entity_name=entity_name) - ident = mapper.identity(object) - for k in ident: - if k is None: - if raiseerror: - raise InvalidRequestError("Instance '%s' does not have a full set of identity values, and does not represent a saved entity in the database. Use the add() method to add unsaved instances to this Session." % str(object)) - else: - return None - key = mapper.identity_key(*ident) - u = self.uow - if u.identity_map.has_key(key): - return u.identity_map[key] - else: - instance._instance_key = key - u.identity_map[key] = instance - self._bind_to(instance) - return instance - - def import_instance(self, *args, **kwargs): - """deprecated; a synynom for import()""" - return self.merge(*args, **kwargs) - -def get_id_key(ident, class_, entity_name=None): - return Session.get_id_key(ident, class_, entity_name) - -def get_row_key(row, class_, primary_key, entity_name=None): - return Session.get_row_key(row, class_, primary_key, entity_name) - -def mapper(*args, **params): - return sqlalchemy.orm.mapper(*args, **params) - -def object_mapper(obj, **kwargs): - return sqlalchemy.orm.object_mapper(obj, **kwargs) - -def class_mapper(class_, **kwargs): - return sqlalchemy.orm.class_mapper(class_, **kwargs) - -# this is the AttributeManager instance used to provide attribute behavior on objects. -# to all the "global variable police" out there: its a stateless object. -global_attributes = unitofwork.global_attributes - -# this dictionary maps the hash key of a Session to the Session itself, and -# acts as a Registry with which to locate Sessions. this is to enable -# object instances to be associated with Sessions without having to attach the -# actual Session object directly to the object instance. -_sessions = weakref.WeakValueDictionary() - -def get_session(obj=None, raiseerror=True): - """returns the Session corrseponding to the given object instance. By default, if the object is not bound - to any Session, then an error is raised (or None is returned if raiseerror=False). This behavior can be changed - using the "threadlocal" mod, which will add an additional step to return a Session that is bound to the current - thread.""" - if obj is not None: - # does it have a hash key ? - hashkey = getattr(obj, '_sa_session_id', None) - if hashkey is not None: - # ok, return that - try: - return _sessions[hashkey] - except KeyError: - if raiseerror: - raise InvalidRequestError("Session '%s' referenced by object '%s' no longer exists" % (hashkey, repr(obj))) - else: - return None - - return _default_session(obj=obj, raiseerror=raiseerror) - -def _default_session(obj=None, raiseerror=True): - if obj is None: - if raiseerror: - raise InvalidRequestError("Thread-local Sessions are disabled by default. Use 'import sqlalchemy.mods.threadlocal' to enable.") - else: - return None - else: - if raiseerror: - raise InvalidRequestError("Object '%s' not bound to any Session" % (repr(obj))) - else: - return None - -unitofwork.get_session = get_session - </del></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormpropertiespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py (1323 => 1324)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py 2006-04-23 20:49:51 UTC (rev 1323) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py 2006-04-23 21:05:13 UTC (rev 1324) </span><span class="lines">@@ -16,7 +16,7 @@ </span><span class="cx"> import sqlalchemy.attributes as attributes </span><span class="cx"> import sync </span><span class="cx"> import mapper </span><del>-import objectstore </del><ins>+import session as sessionlib </ins><span class="cx"> import dependency </span><span class="cx"> import util as mapperutil </span><span class="cx"> from sqlalchemy.exceptions import * </span><span class="lines">@@ -34,7 +34,7 @@ </span><span class="cx"> def setattr(self, object, value): </span><span class="cx"> setattr(object, self.key, value) </span><span class="cx"> def get_history(self, obj, passive=False): </span><del>- return objectstore.global_attributes.get_history(obj, self.key, passive=passive) </del><ins>+ return sessionlib.global_attributes.get_history(obj, self.key, passive=passive) </ins><span class="cx"> def copy(self): </span><span class="cx"> return ColumnProperty(*self.columns) </span><span class="cx"> def setup(self, key, statement, eagertable=None, **options): </span><span class="lines">@@ -48,7 +48,7 @@ </span><span class="cx"> # establish a SmartProperty property manager on the object for this key </span><span class="cx"> if parent._is_primary_mapper(): </span><span class="cx"> #print "regiser col on class %s key %s" % (parent.class_.__name__, key) </span><del>- objectstore.global_attributes.register_attribute(parent.class_, key, uselist = False) </del><ins>+ sessionlib.global_attributes.register_attribute(parent.class_, key, uselist = False) </ins><span class="cx"> def execute(self, session, instance, row, identitykey, imap, isnew): </span><span class="cx"> if isnew: </span><span class="cx"> #print "POPULATING OBJ", instance.__class__.__name__, "COL", self.columns[0]._label, "WITH DATA", row[self.columns[0]], "ROW IS A", row.__class__.__name__, "COL ID", id(self.columns[0]) </span><span class="lines">@@ -70,12 +70,12 @@ </span><span class="cx"> # establish a SmartProperty property manager on the object for this key, </span><span class="cx"> # containing a callable to load in the attribute </span><span class="cx"> if self.is_primary(): </span><del>- objectstore.global_attributes.register_attribute(parent.class_, key, uselist=False, callable_=lambda i:self.setup_loader(i)) </del><ins>+ sessionlib.global_attributes.register_attribute(parent.class_, key, uselist=False, callable_=lambda i:self.setup_loader(i)) </ins><span class="cx"> def setup_loader(self, instance): </span><span class="cx"> if not self.parent.is_assigned(instance): </span><span class="cx"> return object_mapper(instance).props[self.key].setup_loader(instance) </span><span class="cx"> def lazyload(): </span><del>- session = objectstore.get_session(instance) </del><ins>+ session = sessionlib.get_session(instance) </ins><span class="cx"> connection = session.connection(self.parent) </span><span class="cx"> clause = sql.and_() </span><span class="cx"> try: </span><span class="lines">@@ -96,7 +96,7 @@ </span><span class="cx"> if prop is self: </span><span class="cx"> continue </span><span class="cx"> instance.__dict__[prop.key] = row[prop.columns[0]] </span><del>- objectstore.global_attributes.create_history(instance, prop.key, uselist=False) </del><ins>+ sessionlib.global_attributes.create_history(instance, prop.key, uselist=False) </ins><span class="cx"> return row[self.columns[0]] </span><span class="cx"> else: </span><span class="cx"> return connection.scalar(sql.select([self.columns[0]], clause, use_labels=True),None) </span><span class="lines">@@ -108,9 +108,9 @@ </span><span class="cx"> def execute(self, session, instance, row, identitykey, imap, isnew): </span><span class="cx"> if isnew: </span><span class="cx"> if not self.is_primary(): </span><del>- objectstore.global_attributes.create_history(instance, self.key, False, callable_=self.setup_loader(instance)) </del><ins>+ sessionlib.global_attributes.create_history(instance, self.key, False, callable_=self.setup_loader(instance)) </ins><span class="cx"> else: </span><del>- objectstore.global_attributes.reset_history(instance, self.key) </del><ins>+ sessionlib.global_attributes.reset_history(instance, self.key) </ins><span class="cx"> </span><span class="cx"> mapper.ColumnProperty = ColumnProperty </span><span class="cx"> </span><span class="lines">@@ -166,9 +166,9 @@ </span><span class="cx"> recursive = sets.Set() </span><span class="cx"> </span><span class="cx"> if self.uselist: </span><del>- childlist = objectstore.global_attributes.get_history(object, self.key, passive = False) </del><ins>+ childlist = sessionlib.global_attributes.get_history(object, self.key, passive = False) </ins><span class="cx"> else: </span><del>- childlist = objectstore.global_attributes.get_history(object, self.key) </del><ins>+ childlist = sessionlib.global_attributes.get_history(object, self.key) </ins><span class="cx"> </span><span class="cx"> for c in childlist.added_items() + childlist.deleted_items() + childlist.unchanged_items(): </span><span class="cx"> if c is not None: </span><span class="lines">@@ -247,14 +247,14 @@ </span><span class="cx"> </span><span class="cx"> if self.backref is not None: </span><span class="cx"> self.backref.compile(self) </span><del>- elif not objectstore.global_attributes.is_class_managed(parent.class_, key): </del><ins>+ elif not sessionlib.global_attributes.is_class_managed(parent.class_, key): </ins><span class="cx"> raise ArgumentError("Attempting to assign a new relation '%s' to a non-primary mapper on class '%s'. New relations can only be added to the primary mapper, i.e. the very first mapper created for class '%s' " % (key, parent.class_.__name__, parent.class_.__name__)) </span><span class="cx"> </span><span class="cx"> self.do_init_subclass(key, parent) </span><span class="cx"> </span><span class="cx"> def _set_class_attribute(self, class_, key): </span><span class="cx"> """sets attribute behavior on our target class.""" </span><del>- objectstore.global_attributes.register_attribute(class_, key, uselist = self.uselist, extension=self.attributeext, cascade=self.cascade, trackparent=True) </del><ins>+ sessionlib.global_attributes.register_attribute(class_, key, uselist = self.uselist, extension=self.attributeext, cascade=self.cascade, trackparent=True) </ins><span class="cx"> </span><span class="cx"> def _get_direction(self): </span><span class="cx"> """determines our 'direction', i.e. do we represent one to many, many to many, etc.""" </span><span class="lines">@@ -334,7 +334,7 @@ </span><span class="cx"> if self.is_primary(): </span><span class="cx"> return </span><span class="cx"> #print "PLAIN PROPLOADER EXEC NON-PRIAMRY", repr(id(self)), repr(self.mapper.class_), self.key </span><del>- objectstore.global_attributes.create_history(instance, self.key, self.uselist, cascade=self.cascade, trackparent=True) </del><ins>+ sessionlib.global_attributes.create_history(instance, self.key, self.uselist, cascade=self.cascade, trackparent=True) </ins><span class="cx"> </span><span class="cx"> def register_dependencies(self, uowcommit): </span><span class="cx"> self._dependency_processor.register_dependencies(uowcommit) </span><span class="lines">@@ -367,7 +367,7 @@ </span><span class="cx"> def _set_class_attribute(self, class_, key): </span><span class="cx"> # establish a class-level lazy loader on our class </span><span class="cx"> #print "SETCLASSATTR LAZY", repr(class_), key </span><del>- objectstore.global_attributes.register_attribute(class_, key, uselist = self.uselist, callable_=lambda i: self.setup_loader(i), extension=self.attributeext, cascade=self.cascade, trackparent=True) </del><ins>+ sessionlib.global_attributes.register_attribute(class_, key, uselist = self.uselist, callable_=lambda i: self.setup_loader(i), extension=self.attributeext, cascade=self.cascade, trackparent=True) </ins><span class="cx"> </span><span class="cx"> def setup_loader(self, instance): </span><span class="cx"> if not self.parent.is_assigned(instance): </span><span class="lines">@@ -375,7 +375,7 @@ </span><span class="cx"> def lazyload(): </span><span class="cx"> params = {} </span><span class="cx"> allparams = True </span><del>- session = objectstore.get_session(instance) </del><ins>+ session = sessionlib.get_session(instance) </ins><span class="cx"> #print "setting up loader, lazywhere", str(self.lazywhere) </span><span class="cx"> for col, bind in self.lazybinds.iteritems(): </span><span class="cx"> params[bind.key] = self.parent._getattrbycolumn(instance, col) </span><span class="lines">@@ -415,14 +415,14 @@ </span><span class="cx"> #print "EXEC NON-PRIAMRY", repr(self.mapper.class_), self.key </span><span class="cx"> # we are not the primary manager for this attribute on this class - set up a per-instance lazyloader, </span><span class="cx"> # which will override the class-level behavior </span><del>- objectstore.global_attributes.create_history(instance, self.key, self.uselist, callable_=self.setup_loader(instance), cascade=self.cascade, trackparent=True) </del><ins>+ sessionlib.global_attributes.create_history(instance, self.key, self.uselist, callable_=self.setup_loader(instance), cascade=self.cascade, trackparent=True) </ins><span class="cx"> else: </span><span class="cx"> #print "EXEC PRIMARY", repr(self.mapper.class_), self.key </span><span class="cx"> # we are the primary manager for this attribute on this class - reset its per-instance attribute state, </span><span class="cx"> # so that the class-level lazy loader is executed when next referenced on this instance. </span><span class="cx"> # this usually is not needed unless the constructor of the object referenced the attribute before we got </span><span class="cx"> # to load data into it. </span><del>- objectstore.global_attributes.reset_history(instance, self.key) </del><ins>+ sessionlib.global_attributes.reset_history(instance, self.key) </ins><span class="cx"> </span><span class="cx"> def create_lazy_clause(table, primaryjoin, secondaryjoin, foreignkey): </span><span class="cx"> binds = {} </span><span class="lines">@@ -566,7 +566,7 @@ </span><span class="cx"> if isnew: </span><span class="cx"> # new row loaded from the database. initialize a blank container on the instance. </span><span class="cx"> # this will override any per-class lazyloading type of stuff. </span><del>- h = objectstore.global_attributes.create_history(instance, self.key, self.uselist, cascade=self.cascade, trackparent=True) </del><ins>+ h = sessionlib.global_attributes.create_history(instance, self.key, self.uselist, cascade=self.cascade, trackparent=True) </ins><span class="cx"> </span><span class="cx"> if not self.uselist: </span><span class="cx"> if isnew: </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormquerypy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py (1323 => 1324)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py 2006-04-23 20:49:51 UTC (rev 1323) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py 2006-04-23 21:05:13 UTC (rev 1324) </span><span class="lines">@@ -5,7 +5,7 @@ </span><span class="cx"> # the MIT License: http://www.opensource.org/licenses/mit-license.php </span><span class="cx"> </span><span class="cx"> </span><del>-import objectstore </del><ins>+import session as sessionlib </ins><span class="cx"> import sqlalchemy.sql as sql </span><span class="cx"> import sqlalchemy.util as util </span><span class="cx"> from sqlalchemy.exceptions import * </span><span class="lines">@@ -28,7 +28,7 @@ </span><span class="cx"> self._get_clause = self.mapper._get_clause </span><span class="cx"> def _get_session(self): </span><span class="cx"> if self._session is None: </span><del>- return objectstore.get_session() </del><ins>+ return sessionlib.get_session() </ins><span class="cx"> else: </span><span class="cx"> return self._session </span><span class="cx"> table = property(lambda s:s.mapper.table) </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormsessionpyfromrev1323sqlalchemybranchesschemalibsqlalchemyormobjectstorepy"></a> <div class="copfile"><h4>Copied: sqlalchemy/branches/schema/lib/sqlalchemy/orm/session.py (from rev 1323, sqlalchemy/branches/schema/lib/sqlalchemy/orm/objectstore.py) ( => )</h4> <pre class="diff"><span> <span class="info">Modified: sqlalchemy/branches/schema/test/mapper.py =================================================================== </span><del>--- sqlalchemy/branches/schema/test/mapper.py 2006-04-23 20:49:51 UTC (rev 1323) </del><ins>+++ sqlalchemy/branches/schema/test/mapper.py 2006-04-23 21:05:13 UTC (rev 1324) </ins><span class="lines">@@ -125,7 +125,7 @@ </span><span class="cx"> self.assert_sql_count(db, go, 1) </span><span class="cx"> </span><span class="cx"> def testsessionpropigation(self): </span><del>- sess = objectstore.Session() </del><ins>+ sess = create_session() </ins><span class="cx"> m = mapper(User, users, properties={'addresses':relation(mapper(Address, addresses), lazy=True)}) </span><span class="cx"> u = m.using(sess).get(7) </span><span class="cx"> assert objectstore.get_session(u) is sess </span><span class="lines">@@ -708,7 +708,7 @@ </span><span class="cx"> </span><span class="cx"> def testcompile(self): </span><span class="cx"> """tests deferred operation of a pre-compiled mapper statement""" </span><del>- session = objectstore.Session() </del><ins>+ session = create_session() </ins><span class="cx"> m = mapper(User, users, properties = dict( </span><span class="cx"> addresses = relation(mapper(Address, addresses), lazy = False) </span... [truncated message content] |