Esempio n. 1
0
 def do_it(cursor):
     nw = datetime.datetime.now()
     cursor.execute(stmt, (state, reply_doc, nw, request_id))
     if cursor.rowcount != 1:
         raise exceptions.PersistenceException(
             "%d rows were updated when exactly 1 should have "
             "been" % cursor.rowcount)
Esempio n. 2
0
 def __init__(self, row):
     if row is None:
         raise exceptions.PersistenceException("The row is none")
     column_order = _get_column_order()
     i = 0
     for attr in column_order:
         setattr(self, attr, row[i])
         i += 1
Esempio n. 3
0
 def do_it(cursor):
     cursor.execute(stmt, (agent_id, ))
     if cursor.rowcount < 1:
         raise exceptions.PersistenceException(
             "There is no owner in the database")
     if cursor.rowcount > 1:
         _g_logger.warning(
             "The database has more than 1 user as the owner")
     row = cursor.fetchone()
     return (row[0], row[1])
Esempio n. 4
0
    def update_record(self, request_id, state, reply_doc=None):
        stmt = ("UPDATE requests SET state=?, reply_doc=?, last_update_time=? "
                "WHERE request_id=?")
        try:
            if reply_doc is not None:
                reply_doc = json.dumps(reply_doc)

            def do_it(cursor):
                nw = datetime.datetime.now()
                cursor.execute(stmt, (state, reply_doc, nw, request_id))
                if cursor.rowcount != 1:
                    raise exceptions.PersistenceException(
                        "%d rows were updated when exactly 1 should have "
                        "been" % cursor.rowcount)

            self._execute(do_it)
        except Exception as ex:
            raise exceptions.PersistenceException(ex)
Esempio n. 5
0
    def new_record(self, request_id, request_doc, reply_doc, state, agent_id):
        stmt = ("INSERT INTO requests(request_id, creation_time, request_doc, "
                "reply_doc, state, agent_id, last_update_time) "
                "VALUES(?, ?, ?, ?, ?, ?, ?)")

        if request_id != request_doc['request_id']:
            raise exceptions.PersistenceException("The request_id must match "
                                                  "the request_doc")

        if request_doc is not None:
            request_doc = json.dumps(request_doc)
        if reply_doc is not None:
            reply_doc = json.dumps(reply_doc)

        def do_it(cursor):
            nw = datetime.datetime.now()
            parms = (request_id, nw, request_doc, reply_doc, state, agent_id,
                     nw)
            cursor.execute(stmt, parms)

        self._execute(do_it)