Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv15147/SQLObject
Modified Files:
DBConnection.py SQLObject.py
Log Message:
Took out all the lazy retrieval of stuff from the database
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** DBConnection.py 21 Apr 2003 22:43:48 -0000 1.26
--- DBConnection.py 22 Apr 2003 02:27:10 -0000 1.27
***************
*** 141,148 ****
yield select.sourceClass(result[0])
else:
! obj = select.sourceClass(result[0])
! obj._SO_writeLock.acquire()
! obj._SO_selectInit(result[1:])
! obj._SO_writeLock.release()
yield obj
--- 141,145 ----
yield select.sourceClass(result[0])
else:
! obj = select.sourceClass(result[0], selectResults=result[1:])
yield obj
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** SQLObject.py 21 Apr 2003 22:37:16 -0000 1.26
--- SQLObject.py 22 Apr 2003 02:27:10 -0000 1.27
***************
*** 295,303 ****
_style = None
! def __new__(cls, id, connection=None):
# When id is None, that means we are trying
# to create a new object. This is done by the
! # `new` method.
if id is None:
# Create an actual new object:
--- 295,303 ----
_style = None
! def __new__(cls, id, connection=None, selectResults=None):
# When id is None, that means we are trying
# to create a new object. This is done by the
! # `new()` method.
if id is None:
# Create an actual new object:
***************
*** 318,326 ****
cache = connection.cache
val = cache.get(id, cls)
if val is None:
try:
! val = object.__new__(cls, id, connection)
! val._init(id, connection)
cache.put(id, cls, val)
finally:
--- 318,328 ----
cache = connection.cache
+ # This whole sequence comes from Cache.CacheFactory's
+ # behavior, where a None returned means a cache miss.
val = cache.get(id, cls)
if val is None:
try:
! val = object.__new__(cls)
! val._init(id, connection, selectResults)
cache.put(id, cls, val)
finally:
***************
*** 347,365 ****
# We create a method here, which is just a function
! # that takes "self" as the first argument. The
! # basic logic of the lambda is:
! # When we have cached values, self._SO_autoInitDone
! # is true, so we skip out of the parenthesis.
! # If we don't, we run self._SO_autoInit() which
! # gets the cached values (for all columns).
! # The cached values are stored in something
! # like _SO_val_columnName, so we return that
! # last.
! setattr(cls, rawGetterName(name), eval('lambda self: (self._SO_autoInitDone or self._SO_autoInit()) and self.%s' % (instanceName(name))))
else:
# If we aren't caching values, we just call the
# function _SO_getValue, which fetches from the
# database.
! setattr(cls, rawGetterName(name), eval('lambda self: self._SO_getValue(%s)' % repr(name)))
# Here if the _get_columnName method isn't in the
--- 349,360 ----
# We create a method here, which is just a function
! # that takes "self" as the first argument.
! getter = eval('lambda self: self.%s' % instanceName(name))
else:
# If we aren't caching values, we just call the
# function _SO_getValue, which fetches from the
# database.
! getter = eval('lambda self: self._SO_getValue(%s)' % repr(name))
! setattr(cls, rawGetterName(name), getter)
# Here if the _get_columnName method isn't in the
***************
*** 367,371 ****
# _SO_get_columnName definition.
if not hasattr(cls, getterName(name)):
! setattr(cls, getterName(name), getattr(cls, rawGetterName(name)))
cls._SO_plainGetters[name] = 1
--- 362,366 ----
# _SO_get_columnName definition.
if not hasattr(cls, getterName(name)):
! setattr(cls, getterName(name), getter)
cls._SO_plainGetters[name] = 1
***************
*** 378,385 ****
# We start by just using the _SO_setValue method
! setattr(cls, rawSetterName(name), eval('lambda self, val: self._SO_setValue(%s, val)' % repr(name)))
# Then do the aliasing
if not hasattr(cls, setterName(name)):
! setattr(cls, setterName(name), getattr(cls, rawSetterName(name)))
# We keep track of setters that haven't been
# overridden, because we can combine these
--- 373,381 ----
# We start by just using the _SO_setValue method
! setter = eval('lambda self, val: self._SO_setValue(%s, val)' % repr(name))
! setattr(cls, rawSetterName(name), setter)
# Then do the aliasing
if not hasattr(cls, setterName(name)):
! setattr(cls, setterName(name), setter)
# We keep track of setters that haven't been
# overridden, because we can combine these
***************
*** 402,421 ****
# self._SO_class_className is a reference
# to the class in question.
! setattr(cls, rawGetterName(name)[:-2], eval('lambda self: (self._SO_autoInitDone or self._SO_autoInit()) and self._SO_class_%s(self.%s)' % (column.foreignKey, instanceName(name))))
else:
# Same non-caching version as above.
! setattr(cls, rawGetterName(name)[:-2], eval('lambda self: self._SO_class_%s(self._SO_getValue(%s))' % (column.foreignKey, repr(name))))
# And we set the _get_columnName version
# (sans ID ending)
if not hasattr(cls, getterName(name)[:-2]):
! setattr(cls, getterName(name)[:-2], getattr(cls, rawGetterName(name)[:-2]))
cls._SO_plainForeignGetters[name[:-2]] = 1
# The setter just gets the ID of the object,
# and then sets the real column.
! setattr(cls, rawSetterName(name)[:-2], eval('lambda self, val: setattr(self, %s, self._SO_getID(val))' % (repr(name))))
if not hasattr(cls, setterName(name)[:-2]):
! setattr(cls, setterName(name)[:-2], getattr(cls, rawSetterName(name)[:-2]))
cls._SO_plainForeignSetters[name[:-2]] = 1
# We'll need to put in a real reference at
# some point. See needSet at the top of the
--- 398,421 ----
# self._SO_class_className is a reference
# to the class in question.
! getter = eval('lambda self: self._SO_class_%s(self.%s)' % (column.foreignKey, instanceName(name)))
else:
# Same non-caching version as above.
! getter = eval('lambda self: self._SO_class_%s(self._SO_getValue(%s))' % (column.foreignKey, repr(name)))
! setattr(cls, rawGetterName(name)[:-2], getter)
!
# And we set the _get_columnName version
# (sans ID ending)
if not hasattr(cls, getterName(name)[:-2]):
! setattr(cls, getterName(name)[:-2], getter)
cls._SO_plainForeignGetters[name[:-2]] = 1
# The setter just gets the ID of the object,
# and then sets the real column.
! setter = eval('lambda self, val: setattr(self, %s, self._SO_getID(val))' % (repr(name)))
! setattr(cls, rawSetterName(name)[:-2], setter)
if not hasattr(cls, setterName(name)[:-2]):
! setattr(cls, setterName(name)[:-2], setter)
cls._SO_plainForeignSetters[name[:-2]] = 1
+
# We'll need to put in a real reference at
# some point. See needSet at the top of the
***************
*** 443,449 ****
def delColumn(cls, column, changeSchema=False):
- cls._columns.remove(column)
if isinstance(column, str):
column = cls._SO_columnDict[column]
name = column.name
del cls._SO_columnDict[name]
--- 443,449 ----
def delColumn(cls, column, changeSchema=False):
if isinstance(column, str):
column = cls._SO_columnDict[column]
+ cls._columns.remove(column)
name = column.name
del cls._SO_columnDict[name]
***************
*** 554,558 ****
delJoin = classmethod(delJoin)
! def _init(self, id, connection=None):
assert id is not None
# This function gets called only when the object is
--- 554,558 ----
delJoin = classmethod(delJoin)
! def _init(self, id, connection=None, selectResults=None):
assert id is not None
# This function gets called only when the object is
***************
*** 571,574 ****
--- 571,582 ----
# This flag tells us that:
self._SO_perConnection = True
+
+ dbNames = [col.dbName for col in self._columns]
+ if not selectResults:
+ selectResults = (connection or self._connection)._SO_selectOne(self, dbNames)
+ if not selectResults:
+ raise SQLObjectNotFound, "The object %s by the ID %s does not exist" % (self.__class__.__name__, self.id)
+ self._SO_selectInit(selectResults)
+
def _SO_setValue(self, name, value):
***************
*** 627,658 ****
self._SO_writeLock.release()
- def _SO_autoInit(self):
- # This loads all the columns from the database, and
- # caches them in instance variables.
-
- # First check we aren't dead:
- assert not self._SO_obsolete, "%s with id %s has become obsolete" \
- % (self.__class__.__name__, self.id)
-
- # Make sure nobody changes things underneith us:
- self._SO_writeLock.acquire()
-
- # Database (_-using) names:
- dbNames = [col.dbName for col in self._columns]
-
- results = self._connection._SO_selectOne(self, dbNames)
- assert results, "The object %s by the ID %s does not exist" % (self.__class__.__name__, self.id)
-
- self._SO_selectInit(results)
- self._SO_writeLock.release()
-
- # We have to return True so that the fancy
- # (... or ...) and ... logic in the lambda works out.
- return True
-
def _SO_selectInit(self, row):
for col, colValue in zip(self._columns, row):
setattr(self, instanceName(col.name), colValue)
- self._SO_autoInitDone = 1
def _SO_getValue(self, name):
--- 635,641 ----
|