|
@@ -76,8 +76,10 @@ class LeObject(object):
|
76
|
76
|
_fields = None
|
77
|
77
|
##@brief A tuple of fieldname (or a uniq fieldname) representing uid
|
78
|
78
|
_uid = None
|
79
|
|
- ##@brief The datasource name ( see @ref lodel2_datasources )
|
80
|
|
- _datasource = None
|
|
79
|
+ ##@brief Read only datasource ( see @ref lodel2_datasources )
|
|
80
|
+ _ro_datasource = None
|
|
81
|
+ ##@breif Read & write datasource ( see @ref lodel2_datasources )
|
|
82
|
+ _rw_datasource = None
|
81
|
83
|
|
82
|
84
|
##@brief Construct an object representing an Editorial component
|
83
|
85
|
# @note Can be considered as EmClass instance
|
|
@@ -185,25 +187,57 @@ class LeObject(object):
|
185
|
187
|
raise NameError("No field named '%s' in %s" % ( fieldname,
|
186
|
188
|
cls.__name__))
|
187
|
189
|
|
|
190
|
+ ##@brief Initialise both datasources (ro and rw)
|
|
191
|
+ #
|
|
192
|
+ #This method is used once at dyncode load to replace the datasource string
|
|
193
|
+ #by a datasource instance to avoid doing this operation for each query
|
|
194
|
+ #@see LeObject::_init_datasource()
|
|
195
|
+ @classmethod
|
|
196
|
+ def _init_datasources(cls):
|
|
197
|
+ if isinstance(cls._datasource_name, str):
|
|
198
|
+ rw_ds = ro_ds = cls._datasource_name
|
|
199
|
+ else:
|
|
200
|
+ ro_ds, rw_ds = cls._datasource_name
|
|
201
|
+ #Read only datasource initialisation
|
|
202
|
+ cls._ro_datasource = cls._init_datasource(ro_ds, True)
|
|
203
|
+ log_msg = "Read only datasource %s initialized for LeObject %s"
|
|
204
|
+ log_msg %= (ro_ds, cls.__name__)
|
|
205
|
+ logger.debug(log_msg)
|
|
206
|
+ #Read write datasource initialisation
|
|
207
|
+ cls._rw_datasource = cls._init_datasource(rw_ds, False)
|
|
208
|
+ log_msg = "Read&write only datasource %s initialized for LeObject %s"
|
|
209
|
+ log_msg %= (rw_ds, cls.__name__)
|
|
210
|
+ logger.debug(log_msg)
|
|
211
|
+
|
|
212
|
+
|
188
|
213
|
##@brief Replace the _datasource attribute value by a datasource instance
|
189
|
214
|
#
|
190
|
|
- # This method is used once at dyncode load to replace the datasource string
|
191
|
|
- # by a datasource instance to avoid doing this operation for each query
|
|
215
|
+ #This method is used once at dyncode load to replace the datasource string
|
|
216
|
+ #by a datasource instance to avoid doing this operation for each query
|
|
217
|
+ #@param ds_name str : The name of the datasource to instanciate
|
|
218
|
+ #@param ro bool : if true initialise the _ro_datasource attribute else
|
|
219
|
+ #initialise _rw_datasource attribute
|
192
|
220
|
@classmethod
|
193
|
|
- def _init_datasource(cls):
|
|
221
|
+ def _init_datasource(cls, ds_name, ro):
|
194
|
222
|
expt_msg = "In LeAPI class '%s' " % cls.__name__
|
195
|
|
- datasource_orig_name = cls._datasource_name
|
196
|
|
- if cls._datasource_name not in Settings.datasources._fields:
|
|
223
|
+ datasource_orig_name = ds_name
|
|
224
|
+ if ds_name not in Settings.datasources._fields:
|
197
|
225
|
expt_msg += "Unknow or unconfigured datasource %s"
|
198
|
|
- expt_msg %= (cls._datasource_name, cls.__name__)
|
|
226
|
+ expt_msg %= (ds_name, cls.__name__)
|
199
|
227
|
raise SettingsError(expt_msg)
|
200
|
228
|
|
201
|
|
- ds_identifier = getattr(Settings.datasources, cls._datasource_name)
|
|
229
|
+ ds_identifier = getattr(Settings.datasources, ds_name)
|
|
230
|
+ read_only = getattr(ds_identifier, 'read_only')
|
202
|
231
|
try:
|
203
|
232
|
ds_identifier = getattr(ds_identifier, 'identifier')
|
204
|
233
|
except NameError:
|
205
|
234
|
expt_msg += "Datasource %s is missconfigured, missing identifier."
|
206
|
|
- expt_msg %= cls._datasource_name
|
|
235
|
+ expt_msg %= ds_name
|
|
236
|
+ raise SettingsError(expt_msg)
|
|
237
|
+ if read_only and not ro:
|
|
238
|
+ expt_msg += "Error in datasource %s configuration. Trying to use \
|
|
239
|
+a read only as a read&write datasource"
|
|
240
|
+ expt_msg %= ds_name
|
207
|
241
|
raise SettingsError(expt_msg)
|
208
|
242
|
|
209
|
243
|
ds_plugin, ds_name = ds_identifier.split('.')
|
|
@@ -226,7 +260,8 @@ class LeObject(object):
|
226
|
260
|
datasource_class = getattr(ds_plugin_module, "Datasource")
|
227
|
261
|
except AttributeError as e:
|
228
|
262
|
raise e
|
229
|
|
- expt_msg += "The datasource plugin %s seems to be invalid. Error raised when trying to import Datasource"
|
|
263
|
+ expt_msg += "The datasource plugin %s seems to be invalid. Error \
|
|
264
|
+raised when trying to import Datasource"
|
230
|
265
|
expt_msg %= ds_identifier
|
231
|
266
|
raise SettingsError(expt_msg)
|
232
|
267
|
ds_conf_old = ds_conf
|
|
@@ -234,10 +269,7 @@ class LeObject(object):
|
234
|
269
|
for k in ds_conf_old._fields:
|
235
|
270
|
ds_conf[k] = getattr(ds_conf_old, k)
|
236
|
271
|
|
237
|
|
- cls._datasource = datasource_class(**ds_conf)
|
238
|
|
- log_msg = "Datasource %s initialized for LeObject %s"
|
239
|
|
- log_msg %= (datasource_orig_name, cls.__name__)
|
240
|
|
- logger.debug(log_msg)
|
|
272
|
+ return datasource_class(**ds_conf)
|
241
|
273
|
|
242
|
274
|
##@brief Read only access to all datas
|
243
|
275
|
# @note for fancy data accessor use @ref LeObject.g attribute @ref LeObjectValues instance
|