예제 #1
0
 def delete(self):
     delete_condition = "%s='%s' AND %s='%s'" % (
         self.primDAO_PK, self.primDAO_uuid, self.secDAO_PK,
         self.secDAO_uuid)
     sql_delete = self.sql_dict[DAOtoDAO.__DELETE_OBJECT] % (
         self.entity, delete_condition)
     with dbcursor_wrapper(sql_delete) as cursor:
         pass
예제 #2
0
 def deleteall(self):
     for e in self:
         query = DAOtoDAOList.sql_dict[
             DAOtoDAOList.__DELETE_SQL_KEY_NAME] % (
                 self.entity, e.primDAO_PK, e.primDAO_uuid, e.secDAO_PK,
                 e.secDAO_uuid)
         with dbcursor_wrapper(query) as cursor:
             pass
         e.delete()
예제 #3
0
 def load(self, primDAO_uuid):
     query = DAOtoDAOList.sql_dict[DAOtoDAOList.__LOAD_LIST_SQL_KEY_NAME] % (
         self.prim_dao_to_dao.primDAO_PK, self.prim_dao_to_dao.secDAO_PK,
         self.entity, self.prim_dao_to_dao.primDAO_PK, primDAO_uuid)
     with dbcursor_wrapper(query) as cursor:
         rows = cursor.fetchall()
         for row in rows:
             self.add(
                 self.prim_dao_to_dao(
                     getattr(row, self.prim_dao_to_dao.primDAO_PK),
                     getattr(row, self.prim_dao_to_dao.secDAO_PK)))
예제 #4
0
 def __exists(self):
     sql_exists = "SELECT count(*) as counter FROM %s WHERE uuid='%s'" % (
         self.entity, self.uuid)
     counter = 0
     with dbcursor_wrapper(sql_exists) as cursor:
         row = cursor.fetchone()
         if row is not None:
             counter = getattr(row, "counter")
     if counter > 0:
         return True
     else:
         return False
예제 #5
0
 def load(self, subset=None):
     where_clause = ""
     if subset is not None:
         where_clause = "WHERE %s" % subset
     query = DAOList.sql_dict[DAOList.__LOAD_LIST_SQL_KEY_NAME] % (",".join(
         self.dao.data_fields), self.entity, where_clause)
     with dbcursor_wrapper(query) as cursor:
         rows = cursor.fetchall()
         for row in rows:
             uuid = getattr(row, 'uuid')
             dao = self.dao(uuid, row)
             #dao.load()
             self.add(dao)
예제 #6
0
 def __insert(self):
     fieldlist = []
     data = []
     for key in self.data_fields:
         fieldlist.append(key)
         if key in self.binary_fields:
             data.append(psycopg2.Binary(getattr(self, key), ))
         else:
             data.append(getattr(self, key))
     sql_save = self.sql_dict[DAO.__INSERT_OBJECT] % (self.entity, ",".join(
         fieldlist), ",".join(list(map(lambda x: "%s", data))))
     with dbcursor_wrapper(sql_save, data) as cursor:
         pass
     self.__is_persisted = True
     for join_object in self.join_objects.keys():
         join_object_list = getattr(self, join_object)
         for elem in join_object_list:
             elem.save()
예제 #7
0
    def load(self):
        sql_query_load = self.sql_dict[DAO.__LOAD_OBJECT_BY_UUID] % (",".join(
            self.__class__.data_fields), self.__class__.entity, self.uuid)
        order_by_clause = "ORDER BY %s" % self.__class__.sortkey
        sql_query_load = "%s %s" % (sql_query_load, order_by_clause)

        with dbcursor_wrapper(sql_query_load) as cursor:
            row = cursor.fetchone()
            if row is not None:
                for data_field in self.__class__.data_fields:
                    setattr(self, data_field, getattr(row, data_field))
                self.__is_persisted = True
            else:
                raise BaseException("row with uuid %s doesn't exist" %
                                    self.uuid)
        # load daotodao objects
        for join_object in self.join_objects.keys():
            join_object_list = getattr(self, join_object)
            join_object_list.load(self.uuid)
예제 #8
0
 def __update(self):
     psycopg2.extras.register_uuid()
     setstr = ",".join(
         list(
             map(lambda x: x + "=%(" + x + ")s",
                 filter(lambda x: x != "uuid", self.data_fields))))
     sql_update = self.sql_dict[DAO.__UPDATE_OBJECT] % (self.entity, setstr,
                                                        self.uuid)
     h = dict()
     for f in self.data_fields:
         if f != 'uuid':
             h[f] = getattr(self, f)
     with dbcursor_wrapper(sql_update, h) as cursor:
         pass
     for join_object in self.join_objects.keys():
         join_object_list_to_compare = DAOtoDAOList(
             self.join_objects[join_object])
         join_object_list_to_compare.load(self.uuid)
         current_join_object_list = getattr(self, join_object)
         if join_object_list_to_compare ^ current_join_object_list is not None:
             join_object_list_to_compare.deleteall()
             current_join_object_list.save()
예제 #9
0
 def save(self):
     sql_save = self.sql_dict[DAOtoDAO.__INSERT_OBJECT] % (
         self.entity, self.primDAO_PK, self.secDAO_PK)
     with dbcursor_wrapper(sql_save,
                           [self.primDAO_uuid, self.secDAO_uuid]) as cursor:
         pass
예제 #10
0
 def delete(self):
     sql_query = self.sql_dict[DAO.__DELETE_OBJECT_BY_UUID] % (
         self.__class__.entity, self.uuid)
     with dbcursor_wrapper(sql_query) as cursor:
         pass
     self.__is_persisted = False