[Sqlalchemy-commits] [1321] sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py: added temporary optio
Brought to you by:
zzzeek
<!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>[1321] sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py: added temporary option "construct_new" to mapper which will cause the mapper to use __new__ to create loaded instances instead of the __init__ method</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1321</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-04-23 15:37:53 -0500 (Sun, 23 Apr 2006)</dd> </dl> <h3>Log Message</h3> <pre>added temporary option "construct_new" to mapper which will cause the mapper to use __new__ to create loaded instances instead of the __init__ method</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunklibsqlalchemymappingmapperpy">sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunklibsqlalchemymappingmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py (1320 => 1321)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py 2006-04-22 22:15:36 UTC (rev 1320) +++ sqlalchemy/trunk/lib/sqlalchemy/mapping/mapper.py 2006-04-23 20:37:53 UTC (rev 1321) </span><span class="lines">@@ -49,6 +49,7 @@ </span><span class="cx"> entity_name = None, </span><span class="cx"> always_refresh = False, </span><span class="cx"> version_id_col = None, </span><ins>+ construct_new = False, </ins><span class="cx"> **kwargs): </span><span class="cx"> </span><span class="cx"> if primarytable is not None: </span><span class="lines">@@ -73,6 +74,7 @@ </span><span class="cx"> self._options = {} </span><span class="cx"> self.always_refresh = always_refresh </span><span class="cx"> self.version_id_col = version_id_col </span><ins>+ self.construct_new = construct_new </ins><span class="cx"> </span><span class="cx"> if not issubclass(class_, object): </span><span class="cx"> raise ArgumentError("Class '%s' is not a new-style class" % class_.__name__) </span><span class="lines">@@ -724,7 +726,7 @@ </span><span class="cx"> # plugin point </span><span class="cx"> instance = self.extension.create_instance(self, row, imap, self.class_) </span><span class="cx"> if instance is EXT_PASS: </span><del>- instance = self.class_(_mapper_nohistory=True, _sa_entity_name=self.entity_name, _sa_session=session) </del><ins>+ instance = self._create_instance(session) </ins><span class="cx"> imap[identitykey] = instance </span><span class="cx"> isnew = True </span><span class="cx"> else: </span><span class="lines">@@ -742,6 +744,21 @@ </span><span class="cx"> result.append_nohistory(instance) </span><span class="cx"> return instance </span><span class="cx"> </span><ins>+ def _create_instance(self, session): + if not self.construct_new: + return self.class_(_mapper_nohistory=True, _sa_entity_name=self.entity_name, _sa_session=session) + + obj = self.class_.__new__(self.class_) + obj._entity_name = self.entity_name + + # this gets the AttributeManager to do some pre-initialization, + # in order to save on KeyErrors later on + objectstore.global_attributes.init_attr(obj) + + session._bind_to(obj) + + return obj + </ins><span class="cx"> def translate_row(self, tomapper, row): </span><span class="cx"> """attempts to take a row and translate its values to a row that can </span><span class="cx"> be understood by another mapper. breaks the column references down to their </span></span></pre> </div> </div> </body> </html> |