29 from cubicweb.server.rqlannotation import set_qdata |
29 from cubicweb.server.rqlannotation import set_qdata |
30 from cubicweb.server.sources import AbstractSource |
30 from cubicweb.server.sources import AbstractSource |
31 from cubicweb.server.sources.rql2sql import SQLGenerator |
31 from cubicweb.server.sources.rql2sql import SQLGenerator |
32 |
32 |
33 |
33 |
|
34 ATTR_MAP = {} |
34 NONSYSTEM_ETYPES = set() |
35 NONSYSTEM_ETYPES = set() |
35 NONSYSTEM_RELATIONS = set() |
36 NONSYSTEM_RELATIONS = set() |
36 |
37 |
37 class LogCursor(object): |
38 class LogCursor(object): |
38 def __init__(self, cursor): |
39 def __init__(self, cursor): |
88 |
89 |
89 |
90 |
90 class NativeSQLSource(SQLAdapterMixIn, AbstractSource): |
91 class NativeSQLSource(SQLAdapterMixIn, AbstractSource): |
91 """adapter for source using the native cubicweb schema (see below) |
92 """adapter for source using the native cubicweb schema (see below) |
92 """ |
93 """ |
|
94 sqlgen_class = SQLGenerator |
93 # need default value on class since migration doesn't call init method |
95 # need default value on class since migration doesn't call init method |
94 has_deleted_entitites_table = True |
96 has_deleted_entitites_table = True |
95 |
97 |
96 passwd_rql = "Any P WHERE X is CWUser, X login %(login)s, X upassword P" |
98 passwd_rql = "Any P WHERE X is CWUser, X login %(login)s, X upassword P" |
97 auth_rql = "Any X WHERE X is CWUser, X login %(login)s, X upassword %(pwd)s" |
99 auth_rql = "Any X WHERE X is CWUser, X login %(login)s, X upassword %(pwd)s" |
139 def __init__(self, repo, appschema, source_config, *args, **kwargs): |
141 def __init__(self, repo, appschema, source_config, *args, **kwargs): |
140 SQLAdapterMixIn.__init__(self, source_config) |
142 SQLAdapterMixIn.__init__(self, source_config) |
141 AbstractSource.__init__(self, repo, appschema, source_config, |
143 AbstractSource.__init__(self, repo, appschema, source_config, |
142 *args, **kwargs) |
144 *args, **kwargs) |
143 # sql generator |
145 # sql generator |
144 self._rql_sqlgen = SQLGenerator(appschema, self.dbhelper, |
146 self._rql_sqlgen = self.sqlgen_class(appschema, self.dbhelper, |
145 self.encoding) |
147 self.encoding, ATTR_MAP.copy()) |
146 # full text index helper |
148 # full text index helper |
147 self.indexer = get_indexer(self.dbdriver, self.encoding) |
149 self.indexer = get_indexer(self.dbdriver, self.encoding) |
148 # advanced functionality helper |
150 # advanced functionality helper |
149 self.dbhelper.fti_uid_attr = self.indexer.uid_attr |
151 self.dbhelper.fti_uid_attr = self.indexer.uid_attr |
150 self.dbhelper.fti_table = self.indexer.table |
152 self.dbhelper.fti_table = self.indexer.table |
207 else: |
209 else: |
208 self.has_deleted_entitites_table = False |
210 self.has_deleted_entitites_table = False |
209 pool.pool_reset() |
211 pool.pool_reset() |
210 self.repo._free_pool(pool) |
212 self.repo._free_pool(pool) |
211 |
213 |
|
214 def map_attribute(self, etype, attr, cb): |
|
215 self._rql_sqlgen.attr_map['%s.%s' % (etype, attr)] = cb |
|
216 |
212 # ISource interface ####################################################### |
217 # ISource interface ####################################################### |
213 |
218 |
214 def compile_rql(self, rql): |
219 def compile_rql(self, rql): |
215 rqlst = self.repo.querier._rqlhelper.parse(rql) |
220 rqlst = self.repo.querier._rqlhelper.parse(rql) |
216 rqlst.restricted_vars = () |
221 rqlst.restricted_vars = () |