equal
deleted
inserted
replaced
32 |
32 |
33 def __init__(self, sources): |
33 def __init__(self, sources): |
34 # dictionnary of (source, connection), indexed by sources'uri |
34 # dictionnary of (source, connection), indexed by sources'uri |
35 self.source_cnxs = {} |
35 self.source_cnxs = {} |
36 for source in sources: |
36 for source in sources: |
37 self.source_cnxs[source.uri] = (source, source.get_connection()) |
37 self.add_source(source) |
38 if not 'system' in self.source_cnxs: |
38 if not 'system' in self.source_cnxs: |
39 self.source_cnxs['system'] = self.source_cnxs[sources[0].uri] |
39 self.source_cnxs['system'] = self.source_cnxs[sources[0].uri] |
40 self._cursors = {} |
40 self._cursors = {} |
41 |
41 |
42 def __getitem__(self, uri): |
42 def __getitem__(self, uri): |
47 cursor = self.source_cnxs[uri][1].cursor() |
47 cursor = self.source_cnxs[uri][1].cursor() |
48 if cursor is not None: |
48 if cursor is not None: |
49 # None possible on sources without cursor support such as ldap |
49 # None possible on sources without cursor support such as ldap |
50 self._cursors[uri] = cursor |
50 self._cursors[uri] = cursor |
51 return cursor |
51 return cursor |
|
52 |
|
53 def add_source(self, source): |
|
54 assert not source.uri in self.source_cnxs |
|
55 self.source_cnxs[source.uri] = (source, source.get_connection()) |
|
56 |
|
57 def remove_source(self, source): |
|
58 source, cnx = self.source_cnxs.pop(source.uri) |
|
59 cnx.close() |
|
60 self._cursors.pop(source.uri, None) |
52 |
61 |
53 def commit(self): |
62 def commit(self): |
54 """commit the current transaction for this user""" |
63 """commit the current transaction for this user""" |
55 # FIXME: what happends if a commit fail |
64 # FIXME: what happends if a commit fail |
56 # would need a two phases commit or like, but I don't know how to do |
65 # would need a two phases commit or like, but I don't know how to do |