Author: phd
Date: 2005-02-23 19:28:17 +0000 (Wed, 23 Feb 2005)
New Revision: 638
Modified:
trunk/SQLObject/sqlobject/cache.py
trunk/SQLObject/sqlobject/inheritance/__init__.py
trunk/SQLObject/sqlobject/main.py
Log:
The patch simplified and made faster inherited _SO_fetchAlternateID
(_findAlternateID, actually), but changed their signatures.
Fixed a minor bug in cache.py expireAll().
Modified: trunk/SQLObject/sqlobject/cache.py
===================================================================
--- trunk/SQLObject/sqlobject/cache.py 2005-02-23 19:19:42 UTC (rev 637)
+++ trunk/SQLObject/sqlobject/cache.py 2005-02-23 19:28:17 UTC (rev 638)
@@ -225,7 +225,7 @@
self.lock.acquire()
try:
for key, value in self.cache.items():
- self.expiredCache[key] = ref(obj)
+ self.expiredCache[key] = ref(value)
self.cache = {}
finally:
self.lock.release()
Modified: trunk/SQLObject/sqlobject/inheritance/__init__.py
===================================================================
--- trunk/SQLObject/sqlobject/inheritance/__init__.py 2005-02-23 19:19:42 UTC (rev 637)
+++ trunk/SQLObject/sqlobject/inheritance/__init__.py 2005-02-23 19:28:17 UTC (rev 638)
@@ -193,21 +193,8 @@
super(InheritableSQLObject, self)._create(id, **kw)
- def _findAlternateID(cls, dbIDName, value, connection=None):
- found = False
- currentClass = cls
- try:
- while currentClass:
- for col in currentClass.sqlmeta._columns:
- if col.dbName == dbIDName:
- found = True
- raise StopIteration
- currentClass = currentClass._parentClass
- except StopIteration:
- pass
- if not found:
- return [], None
- result = list(cls.selectBy(connection, **{col.name: value}))
+ def _findAlternateID(cls, name, dbName, value, connection=None):
+ result = list(cls.selectBy(connection, **{name: value}))
if not result:
return result, None
obj = result[0]
Modified: trunk/SQLObject/sqlobject/main.py
===================================================================
--- trunk/SQLObject/sqlobject/main.py 2005-02-23 19:19:42 UTC (rev 637)
+++ trunk/SQLObject/sqlobject/main.py 2005-02-23 19:28:17 UTC (rev 638)
@@ -649,7 +649,7 @@
cls, '_SO_class_%s' % column.foreignKey)
if column.alternateMethodName:
- func = eval('lambda cls, val, connection=None: cls._SO_fetchAlternateID(%s, val, connection=connection)' % repr(column.dbName))
+ func = eval('lambda cls, val, connection=None: cls._SO_fetchAlternateID(%s, %s, val, connection=connection)' % (repr(column.name), repr(column.dbName)))
setattr(cls, column.alternateMethodName, classmethod(func))
if changeSchema:
@@ -1119,19 +1119,19 @@
def _SO_getID(self, obj):
return getID(obj)
- def _findAlternateID(cls, dbIDName, value, connection=None):
+ def _findAlternateID(cls, name, dbName, value, connection=None):
return (connection or cls._connection)._SO_selectOneAlt(
cls,
[cls.sqlmeta.idName] +
[col.dbName for col in cls.sqlmeta._columns],
- dbIDName,
+ dbName,
value), None
_findAlternateID = classmethod(_findAlternateID)
- def _SO_fetchAlternateID(cls, dbIDName, value, connection=None):
- result, obj = cls._findAlternateID(dbIDName, value, connection)
+ def _SO_fetchAlternateID(cls, name, dbName, value, connection=None):
+ result, obj = cls._findAlternateID(name, dbName, value, connection)
if not result:
- raise SQLObjectNotFound, "The %s by alternateID %s=%s does not exist" % (cls.__name__, dbIDName, repr(value))
+ raise SQLObjectNotFound, "The %s by alternateID %s=%s does not exist" % (cls.__name__, name, repr(value))
if obj:
return obj
if connection:
|