Trees | Indices | Help |
|
---|
|
1 # This file is part of Buildbot. Buildbot is free software: you can 2 # redistribute it and/or modify it under the terms of the GNU General Public 3 # License as published by the Free Software Foundation, version 2. 4 # 5 # This program is distributed in the hope that it will be useful, but WITHOUT 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 8 # details. 9 # 10 # You should have received a copy of the GNU General Public License along with 11 # this program; if not, write to the Free Software Foundation, Inc., 51 12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 13 # 14 # Copyright Buildbot Team Members 1517 # A fixed component of the DBConnector, handling one particular aspect of 18 # the database. Instances of subclasses are assigned to attributes of the 19 # DBConnector object, so that they are available at e.g., 20 # C{master.db.model} or C{master.db.changes}. This parent class takes care 21 # of the necessary backlinks and other housekeeping. 22 23 connector = None 2455 5626 self.db = connector 27 28 # set up caches 29 for method in dir(self.__class__): 30 o = getattr(self, method) 31 if isinstance(o, CachedMethod): 32 setattr(self, method, o.get_cached_method(self))33 34 _is_check_length_necessary = None36 # for use by subclasses to check that 'value' will fit in 'col', where 37 # 'col' is a table column from the model. 38 39 # ignore this check for database engines that either provide this error 40 # themselves (postgres) or that do not enforce maximum-length 41 # restrictions (sqlite) 42 if not self._is_check_length_necessary: 43 if self.db.pool.engine.dialect.name == 'mysql': 44 self._is_check_length_necessary = True 45 else: 46 # not necessary, so just stub out the method 47 self.check_length = lambda col, value : None 48 return 49 50 assert col.type.length, "column %s does not have a length" % (col,) 51 if value and len(value) > col.type.length: 52 raise RuntimeError( 53 "value for column %s is greater than max of %d characters: %s" 54 % (col, col.type.length, value))617763 meth = self.method 64 65 meth_name = meth.__name__ 66 cache = component.db.master.caches.get_cache(self.cache_name, 67 lambda key : meth(component, key)) 68 def wrap(key, no_cache=0): 69 if no_cache: 70 return meth(component, key) 71 return cache.get(key)72 wrap.__name__ = meth_name + " (wrapped)" 73 wrap.__module__ = meth.__module__ 74 wrap.__doc__ = meth.__doc__ 75 wrap.cache = cache 76 return wrap79 return lambda method : CachedMethod(cache_name, method)80
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Nov 21 16:22:54 2012 | http://epydoc.sourceforge.net |