|
@@ -5,6 +5,75 @@ from lodel.settings.validator import SettingValidator
|
5
|
5
|
|
6
|
6
|
|
7
|
7
|
_glob_typename = 'datasource'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+##@brief Datasource class in plugins HAVE TO inherit from this abstract class
|
|
11
|
+class AbstractDatasource(object):
|
|
12
|
+
|
|
13
|
+ ##@brief Trigger LodelFatalError when abtract method called
|
|
14
|
+ @staticmethod
|
|
15
|
+ def _abs_err():
|
|
16
|
+ raise LodelFatalError("This method is abstract and HAVE TO be \
|
|
17
|
+reimplemented by plugin datasource child class")
|
|
18
|
+
|
|
19
|
+ ##@brief The constructor
|
|
20
|
+ def __init__(self, *conn_args, **conn_kwargs):
|
|
21
|
+ self._abs_err()
|
|
22
|
+
|
|
23
|
+ ##@brief Provide a new uniq numeric ID
|
|
24
|
+ #@param emcomp LeObject subclass (not instance) : To know on wich things we
|
|
25
|
+ #have to be uniq
|
|
26
|
+ #@return an integer
|
|
27
|
+ def new_numeric_id(self, emcomp):
|
|
28
|
+ self._abs_err()
|
|
29
|
+
|
|
30
|
+ ##@brief returns a selection of documents from the datasource
|
|
31
|
+ #@param target_cls Emclass
|
|
32
|
+ #@param field_list list
|
|
33
|
+ #@param filters list : List of filters
|
|
34
|
+ #@param rel_filters list : List of relational filters
|
|
35
|
+ #@param order list : List of column to order. ex: order = [('title', 'ASC'),]
|
|
36
|
+ #@param group list : List of tupple representing the column to group together. ex: group = [('title', 'ASC'),]
|
|
37
|
+ #@param limit int : Number of records to be returned
|
|
38
|
+ #@param offset int: used with limit to choose the start record
|
|
39
|
+ #@param instanciate bool : If true, the records are returned as instances, else they are returned as dict
|
|
40
|
+ #@return list
|
|
41
|
+ def select(self, target, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0,
|
|
42
|
+ instanciate=True):
|
|
43
|
+ self._abs_err()
|
|
44
|
+
|
|
45
|
+ ##@brief Deletes records according to given filters
|
|
46
|
+ #@param target Emclass : class of the record to delete
|
|
47
|
+ #@param filters list : List of filters
|
|
48
|
+ #@param relational_filters list : List of relational filters
|
|
49
|
+ #@return int : number of deleted records
|
|
50
|
+ def delete(self, target, filters, relational_filters):
|
|
51
|
+ self._abs_err()
|
|
52
|
+
|
|
53
|
+ ## @brief updates records according to given filters
|
|
54
|
+ #@param target Emclass : class of the object to insert
|
|
55
|
+ #@param filters list : List of filters
|
|
56
|
+ #@param relational_filters list : List of relational filters
|
|
57
|
+ #@param upd_datas dict : datas to update (new values)
|
|
58
|
+ #@return int : Number of updated records
|
|
59
|
+ def update(self, target, filters, relational_filters, upd_datas):
|
|
60
|
+ self._abs_err()
|
|
61
|
+
|
|
62
|
+ ## @brief Inserts a record in a given collection
|
|
63
|
+ # @param target Emclass : class of the object to insert
|
|
64
|
+ # @param new_datas dict : datas to insert
|
|
65
|
+ # @return the inserted uid
|
|
66
|
+ def insert(self, target, new_datas):
|
|
67
|
+ self._abs_err()
|
|
68
|
+
|
|
69
|
+ ## @brief Inserts a list of records in a given collection
|
|
70
|
+ # @param target Emclass : class of the objects inserted
|
|
71
|
+ # @param datas_list list : list of dict
|
|
72
|
+ # @return list : list of the inserted records' ids
|
|
73
|
+ def insert_multi(self, target, datas_list):
|
|
74
|
+ self._abs_err()
|
|
75
|
+
|
|
76
|
+
|
8
|
77
|
##@brief Designed to handles datasources plugins
|
9
|
78
|
#
|
10
|
79
|
#A datasource provide data access to LeAPI typically a connector on a DB
|
|
@@ -41,6 +110,10 @@ class DatasourcePlugin(Plugin):
|
41
|
110
|
def datasource_cls(self):
|
42
|
111
|
if self.__datasource_cls is None:
|
43
|
112
|
self.__datasource_cls = self.loader_module().Datasource
|
|
113
|
+ if not issubclass(self.__datasource_cls, AbstractDatasource):
|
|
114
|
+ raise DatasourcePluginError("The datasource class of the \
|
|
115
|
+'%s' plugin is not a child class of \
|
|
116
|
+lodel.plugin.datasource_plugin.AbstractDatasource" % (self.name))
|
44
|
117
|
return self.__datasource_cls
|
45
|
118
|
|
46
|
119
|
##@brief Accessor to migration handler class
|
|
@@ -163,70 +236,6 @@ but %s is a %s" % (ds_name, pinstance.__class__.__name__))
|
163
|
236
|
def get_migration_handler(cls, ds_plugin_name):
|
164
|
237
|
return cls.get(ds_plugin_name).migration_handler_cls()
|
165
|
238
|
|
166
|
|
-class AbstractDatasource(object):
|
167
|
|
-
|
168
|
|
- ##@brief Trigger LodelFatalError when abtract method called
|
169
|
|
- @staticmethod
|
170
|
|
- def _abs_err():
|
171
|
|
- raise LodelFatalError("This method is abstract and HAVE TO be \
|
172
|
|
-reimplemented by plugin datasource child class")
|
173
|
|
-
|
174
|
|
- ##@brief The constructor
|
175
|
|
- def __init__(self, *conn_args, **conn_kwargs):
|
176
|
|
- self._abs_err()
|
177
|
|
-
|
178
|
|
- ##@brief Provide a new uniq numeric ID
|
179
|
|
- #@param emcomp LeObject subclass (not instance) : To know on wich things we
|
180
|
|
- #have to be uniq
|
181
|
|
- #@return an integer
|
182
|
|
- def new_numeric_id(self, emcomp):
|
183
|
|
- self._abs_err()
|
184
|
|
-
|
185
|
|
- ##@brief returns a selection of documents from the datasource
|
186
|
|
- #@param target_cls Emclass
|
187
|
|
- #@param field_list list
|
188
|
|
- #@param filters list : List of filters
|
189
|
|
- #@param rel_filters list : List of relational filters
|
190
|
|
- #@param order list : List of column to order. ex: order = [('title', 'ASC'),]
|
191
|
|
- #@param group list : List of tupple representing the column to group together. ex: group = [('title', 'ASC'),]
|
192
|
|
- #@param limit int : Number of records to be returned
|
193
|
|
- #@param offset int: used with limit to choose the start record
|
194
|
|
- #@param instanciate bool : If true, the records are returned as instances, else they are returned as dict
|
195
|
|
- #@return list
|
196
|
|
- def select(self, target, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0,
|
197
|
|
- instanciate=True):
|
198
|
|
- self._abs_err()
|
199
|
|
-
|
200
|
|
- ##@brief Deletes records according to given filters
|
201
|
|
- #@param target Emclass : class of the record to delete
|
202
|
|
- #@param filters list : List of filters
|
203
|
|
- #@param relational_filters list : List of relational filters
|
204
|
|
- #@return int : number of deleted records
|
205
|
|
- def delete(self, target, filters, relational_filters):
|
206
|
|
- self._abs_err()
|
207
|
|
-
|
208
|
|
- ## @brief updates records according to given filters
|
209
|
|
- #@param target Emclass : class of the object to insert
|
210
|
|
- #@param filters list : List of filters
|
211
|
|
- #@param relational_filters list : List of relational filters
|
212
|
|
- #@param upd_datas dict : datas to update (new values)
|
213
|
|
- #@return int : Number of updated records
|
214
|
|
- def update(self, target, filters, relational_filters, upd_datas):
|
215
|
|
- self._abs_err()
|
216
|
|
-
|
217
|
|
- ## @brief Inserts a record in a given collection
|
218
|
|
- # @param target Emclass : class of the object to insert
|
219
|
|
- # @param new_datas dict : datas to insert
|
220
|
|
- # @return the inserted uid
|
221
|
|
- def insert(self, target, new_datas):
|
222
|
|
- self._abs_err()
|
223
|
|
-
|
224
|
|
- ## @brief Inserts a list of records in a given collection
|
225
|
|
- # @param target Emclass : class of the objects inserted
|
226
|
|
- # @param datas_list list : list of dict
|
227
|
|
- # @return list : list of the inserted records' ids
|
228
|
|
- def insert_multi(self, target, datas_list):
|
229
|
|
- self._abs_err()
|
230
|
239
|
|
231
|
240
|
##@page lodel2_datasources Lodel2 datasources
|
232
|
241
|
#
|