|
@@ -123,13 +123,11 @@ class EmComponent(object):
|
123
|
123
|
## Shortcut that return the sqlAlchemy engine
|
124
|
124
|
def db_engine(cls):
|
125
|
125
|
return sqlutils.getEngine(cls.dbconf)
|
126
|
|
- @classmethod
|
127
|
|
- def getDbE(cls): return cls.db_engine();
|
128
|
126
|
|
129
|
127
|
## Do the query on the database for EmComponent::populate()
|
130
|
128
|
# @throw EmComponentNotExistError if the instance is not anymore stored in database
|
131
|
129
|
def _populate_db(self):
|
132
|
|
- dbe = self.__class__.getDbE()
|
|
130
|
+ dbe = self.__class__.db_engine()
|
133
|
131
|
component = sql.Table(self.table, sqlutils.meta(dbe))
|
134
|
132
|
req = sql.sql.select([component])
|
135
|
133
|
|
|
@@ -174,7 +172,7 @@ class EmComponent(object):
|
174
|
172
|
kwargs['uid'] = cls.new_uid()
|
175
|
173
|
kwargs['date_update'] = kwargs['date_create'] = datetime.datetime.utcnow()
|
176
|
174
|
|
177
|
|
- dbe = cls.getDbE()
|
|
175
|
+ dbe = cls.db_engine()
|
178
|
176
|
conn = dbe.connect()
|
179
|
177
|
|
180
|
178
|
kwargs['rank'] = -1 # Warning !!!
|
|
@@ -207,7 +205,7 @@ class EmComponent(object):
|
207
|
205
|
# @throw RunTimeError if it was unable to do the Db update
|
208
|
206
|
def _save_db(self, values):
|
209
|
207
|
""" Do the query on the db """
|
210
|
|
- dbe = self.__class__.getDbE()
|
|
208
|
+ dbe = self.__class__.db_engine()
|
211
|
209
|
component = sql.Table(self.table, sqlutils.meta(dbe))
|
212
|
210
|
req = sql.update(component, values=values).where(component.c.uid == self.uid)
|
213
|
211
|
|
|
@@ -223,7 +221,7 @@ class EmComponent(object):
|
223
|
221
|
# @throw RunTimeError if it was unable to do the deletion
|
224
|
222
|
def delete(self):
|
225
|
223
|
#<SQL>
|
226
|
|
- dbe = self.__class__.getDbE()
|
|
224
|
+ dbe = self.__class__.db_engine()
|
227
|
225
|
component = sql.Table(self.table, sqlutils.meta(dbe))
|
228
|
226
|
req = component.delete().where(component.c.uid == self.uid)
|
229
|
227
|
conn = dbe.connect()
|
|
@@ -240,7 +238,7 @@ class EmComponent(object):
|
240
|
238
|
# Retourne le rank le plus élevé pour le groupe de component au quel apartient l'objet actuelle
|
241
|
239
|
#return int
|
242
|
240
|
def get_max_rank(self):
|
243
|
|
- dbe = self.__class__.getDbE()
|
|
241
|
+ dbe = self.__class__.db_engine()
|
244
|
242
|
component = sql.Table(self.table, sqlutils.meta(dbe))
|
245
|
243
|
req = sql.sql.select([component.c.rank]).where(getattr(component.c, self.ranked_in) == getattr(self, self.ranked_in)).order_by(component.c.rank.desc())
|
246
|
244
|
conn = dbe.connect()
|
|
@@ -269,7 +267,7 @@ class EmComponent(object):
|
269
|
267
|
|
270
|
268
|
if isinstance(new_rank, int):
|
271
|
269
|
if (new_rank >= 0):
|
272
|
|
- dbe = self.__class__.getDbE()
|
|
270
|
+ dbe = self.__class__.db_engine()
|
273
|
271
|
component = sql.Table(self.table, sqlutils.meta(dbe))
|
274
|
272
|
req = sql.sql.select([component.c.uid, component.c.rank])
|
275
|
273
|
|
|
@@ -401,7 +399,7 @@ class EmComponent(object):
|
401
|
399
|
if cls.table is None:
|
402
|
400
|
raise NotImplementedError("Abstract method")
|
403
|
401
|
|
404
|
|
- dbe = cls.getDbE()
|
|
402
|
+ dbe = cls.db_engine()
|
405
|
403
|
|
406
|
404
|
uidtable = sql.Table('uids', sqlutils.meta(dbe))
|
407
|
405
|
conn = dbe.connect()
|