Package gavo :: Package rsc :: Module metatable
[frames] | no frames]

Source Code for Module gavo.rsc.metatable

 1  """ 
 2  Handling table metadata in the dc.(table|column)meta tables. 
 3   
 4  This has been a mediocre plan, and it's almost unused these days except 
 5  to locate RDs for tables.  Hence, we should tear this entire thing down 
 6  and have the table->RD mapping stowed somewhere else. 
 7   
 8  Or at least give up on the extra connection and have the clients use 
 9  base.getTableDefForTable(connection, tableName) directly. 
10  """ 
11   
12  #c Copyright 2008-2019, the GAVO project 
13  #c 
14  #c This program is free software, covered by the GNU GPL.  See the 
15  #c COPYING file in the source distribution. 
16   
17   
18  import functools 
19   
20  from gavo import base 
21 22 23 24 -def _retryProtect(m):
25 """decorates m such that any function call is retried after self.reset 26 is called. 27 """ 28 def f(self, *args, **kwargs): 29 try: 30 return m(self, *args, **kwargs) 31 except: 32 self.reset() 33 return m(self, *args, **kwargs)
34 35 return functools.update_wrapper(f, m) 36
37 38 -class MetaTableHandler(object):
39 """an interface to DaCHS meta tables. 40 41 This used to be a fairly complex interface to all sorts for DC-related 42 metadata. These day, the only thing it does is figure out where 43 table definitions reside and which are available for ADQL. This thing 44 has been a bad idea all around. 45 46 Though you can construct MetaTableHandlers of your own, you should 47 use base.caches.getMTH(None) when reading. 48 """
49 - def __init__(self):
50 self.rd = base.caches.getRD("__system__/dc_tables") 51 self._createObjects()
52
53 - def _createObjects(self):
54 self.readerConnection = base.getDBConnection( 55 "trustedquery", autocommitted=True)
56
57 - def close(self):
58 try: 59 self.readerConnection.close() 60 except base.InterfaceError: 61 # connection already closed 62 pass
63
64 - def reset(self):
65 self.close() 66 self._createObjects()
67 68 @_retryProtect
69 - def getTableDefForTable(self, tableName):
70 """returns a TableDef for tableName. 71 72 As it is not a priori clear which RD a given table lives in, 73 this goes through dc.tablemeta to figure this out. The 74 object comes from the actual RD, though, so this might very well 75 trigger database action and RD loading. 76 """ 77 return base.getTableDefForTable( 78 self.readerConnection, 79 tableName)
80 81 @_retryProtect
82 - def getTAPTables(self):
83 """returns a list of all names of tables accessible through TAP in 84 this data center. 85 """ 86 return [r["tablename"] for r in 87 self.readerConnection.queryToDicts( 88 "select tablename from dc.tablemeta where adql")]
89
90 91 -def _getMetaTable(ignored):
92 return MetaTableHandler()
93 94 base.caches.makeCache("getMTH", _getMetaTable) 95