Exemplo n.º 1
0
    def create_multi(self, values, collection, enable_update_if_current=False):
        dbcol = self.db[collection]
        txn_k = update_if_current.SERIAL_TXN_COUNTER_KEY

        serials = []
        for v in values:
            if enable_update_if_current:
                update_if_current.enable_check_for(v)
            serial = v.serialize()
            if hasattr(v, txn_k):
                serial[txn_k] = 0
                setattr(v, txn_k, 0)
            serials.append(serial)

        try:
            id_or_error = dbcol.insert(serials, getLastError=1)
            if isinstance(id_or_error, basestring) \
                and '_id' in serial and id_or_error != serial['_id']:
                raise BiiStoreException(id_or_error)
        except Exception, e:
            logger.error(traceback.format_exc())
            raise e
Exemplo n.º 2
0
    def create_multi(self, values, collection, enable_update_if_current=False):
        dbcol = self.db[collection]
        txn_k = update_if_current.SERIAL_TXN_COUNTER_KEY

        serials = []
        for v in values:
            if enable_update_if_current:
                update_if_current.enable_check_for(v)
            serial = v.serialize()
            if hasattr(v, txn_k):
                serial[txn_k] = 0
                setattr(v, txn_k, 0)
            serials.append(serial)

        try:
            id_or_error = dbcol.insert(serials, getLastError=1)
            if isinstance(id_or_error, basestring) \
                and '_id' in serial and id_or_error != serial['_id']:
                raise BiiStoreException(id_or_error)
        except Exception, e:
            logger.error(traceback.format_exc())
            raise e
Exemplo n.º 3
0
    def create(self, value, collection, enable_update_if_current=False):
        dbcol = self.db[collection]
        txn_k = update_if_current.SERIAL_TXN_COUNTER_KEY

        if enable_update_if_current:
            update_if_current.enable_check_for(value)

        serial = value.serialize()
        if hasattr(value, txn_k):
            serial[txn_k] = 0
            setattr(value, txn_k, 0)

        try:
            id_or_error = dbcol.insert(serial, getLastError=1)
            if isinstance(id_or_error, basestring) \
                and '_id' in serial and id_or_error != serial['_id']:
                raise BiiStoreException(id_or_error)
            return id_or_error
        except DuplicateKeyError as e:
            raise AlreadyInStoreException(e)
        except Exception as e:
            logger.error(traceback.format_exc())
            raise e
Exemplo n.º 4
0
    def create(self, value, collection, enable_update_if_current=False):
        dbcol = self.db[collection]
        txn_k = update_if_current.SERIAL_TXN_COUNTER_KEY

        if enable_update_if_current:
            update_if_current.enable_check_for(value)

        serial = value.serialize()
        if hasattr(value, txn_k):
            serial[txn_k] = 0
            setattr(value, txn_k, 0)

        try:
            id_or_error = dbcol.insert(serial, getLastError=1)
            if isinstance(id_or_error, basestring) \
                and '_id' in serial and id_or_error != serial['_id']:
                raise BiiStoreException(id_or_error)
            return id_or_error
        except DuplicateKeyError as e:
            raise AlreadyInStoreException(e)
        except Exception as e:
            logger.error(traceback.format_exc())
            raise e