[jToolkit-cvs] jToolkit/data database.py,1.6,1.7
Brought to you by:
davidfraser,
friedelwolff
|
From: <dav...@us...> - 2004-02-09 12:26:49
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20348 Modified Files: database.py Log Message: updated caching logic to clear '' caches whenever clearing (we don't know what other tables are involved...) rearranged so all caching code is together Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** database.py 9 Feb 2004 12:19:59 -0000 1.6 --- database.py 9 Feb 2004 12:23:36 -0000 1.7 *************** *** 115,130 **** def clearcache(self, cachetables): """clears all the caches for the given sql command""" ! if len(cachetables) == 0: ! self.singlerowcaches[''].clear() ! self.allrowscaches[''].clear() ! else: ! for cachetable in cachetables: ! # TODO: handle ripple-through effects... ! if not cachetable in self.cachetables: ! self.singlerowcaches[''].clear() ! self.allrowscaches[''].clear() ! else: ! self.singlerowcaches[cachetable].clear() ! self.allrowscaches[cachetable].clear() def getcachetables(self, sql): --- 115,125 ---- def clearcache(self, cachetables): """clears all the caches for the given sql command""" ! self.singlerowcaches[''].clear() ! self.allrowscaches[''].clear() ! for cachetable in cachetables: ! # TODO: handle ripple-through effects... ! if cachetable in self.cachetables: ! self.singlerowcaches[cachetable].clear() ! self.allrowscaches[cachetable].clear() def getcachetables(self, sql): *************** *** 137,140 **** --- 132,183 ---- return cachetables + def getsinglerowcache(self, sql): + """returns cached single row result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + cachedrow, description = self.singlerowcaches[''].get(sql, (None, None)) + elif len(cachetables) == 1: + cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) + else: + # TODO: check that it's the same for all of them + cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) + return cachedrow, description + + def setsinglerowcache(self, sql, cachedrow, description): + """caches single row result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + self.singlerowcaches[''][sql] = (cachedrow, description) + else: + for cachetable in cachetables: + if cachetable in self.cachetables: + self.singlerowcaches[cachetables][sql] = (cachedrow, description) + else: + self.singlerowcaches[''][sql] = (cachedrow, description) + + def getallrowscache(self, sql): + """returns cached all rows result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + cachedrows, description = self.allrowscaches[''].get(sql, (None, None)) + elif len(cachetables) == 1: + cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) + else: + # TODO: check that it's the same for all of them + cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) + return cachedrows, description + + def setallrowscache(self, sql, cachedrows, description): + """caches all rows result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + self.allrowscaches[''][sql] = (cachedrows, description) + else: + for cachetable in cachetables: + if cachetable in self.cachetables: + self.allrowscaches[cachetables][sql] = (cachedrows, description) + else: + self.allrowscaches[''][sql] = (cachedrows, description) + def importdriver(self): if self.DBTYPE == 'oracle' and hasattr(self.instance, 'NLS_LANG'): *************** *** 190,194 **** try: cursor = self.db.cursor() - self.errorhandler.logtrace("uncacheable sql query: " + str(sql)) cursor.execute(sql) self.db.commit() --- 233,236 ---- *************** *** 370,397 **** print - def getsinglerowcache(self, sql): - """returns cached single row result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - cachedrow, description = self.singlerowcaches[''].get(sql, (None, None)) - elif len(cachetables) == 1: - cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) - else: - # TODO: check that it's the same for all of them - cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) - return cachedrow, description - - def setsinglerowcache(self, sql, cachedrow, description): - """caches single row result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - self.singlerowcaches[''][sql] = (cachedrow, description) - else: - for cachetable in cachetables: - if cachetable in self.cachetables: - self.singlerowcaches[cachetables][sql] = (cachedrow, description) - else: - self.singlerowcaches[''][sql] = (cachedrow, description) - def singlerow(self, sql, withdescription=0): """runs sql and retrieves a single row""" --- 412,415 ---- *************** *** 416,443 **** return row[0] - def getallrowscache(self, sql): - """returns cached all rows result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - cachedrows, description = self.allrowscaches[''].get(sql, (None, None)) - elif len(cachetables) == 1: - cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) - else: - # TODO: check that it's the same for all of them - cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) - return cachedrows, description - - def setallrowscache(self, sql, cachedrows, description): - """caches all rows result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - self.allrowscaches[''][sql] = (cachedrows, description) - else: - for cachetable in cachetables: - if cachetable in self.cachetables: - self.allrowscaches[cachetables][sql] = (cachedrows, description) - else: - self.allrowscaches[''][sql] = (cachedrows, description) - def allrows(self, sql, withdescription=0): """runs sql and retrieves all rows""" --- 434,437 ---- |