@transactional_session
def __bulk_add_replicas(rse_id, files, account, session=None):
    '\n    Bulk add new dids.\n\n    :param rse_id: the RSE id.\n    :param dids: the list of files.\n    :param account: The account owner.\n    :param session: The database session in use.\n    :returns: True is successful.\n    '
    (nbfiles, bytes) = (0, 0)
    condition = []
    for f in files:
        condition.append(and_((models.RSEFileAssociation.scope == f['scope']), (models.RSEFileAssociation.name == f['name']), (models.RSEFileAssociation.rse_id == rse_id)))
    query = session.query(models.RSEFileAssociation.scope, models.RSEFileAssociation.name, models.RSEFileAssociation.rse_id).with_hint(models.RSEFileAssociation, text='INDEX(REPLICAS REPLICAS_PK)', dialect_name='oracle').filter(or_(*condition))
    available_replicas = [dict([(column, getattr(row, column)) for column in row._fields]) for row in query]
    default_tombstone_delay = next(iter(get_rse_attribute('tombstone_delay', rse_id=rse_id, session=session)), None)
    default_tombstone = tombstone_from_delay(default_tombstone_delay)
    new_replicas = []
    for file in files:
        found = False
        for available_replica in available_replicas:
            if ((file['scope'] == available_replica['scope']) and (file['name'] == available_replica['name']) and (rse_id == available_replica['rse_id'])):
                found = True
                break
        if (not found):
            nbfiles += 1
            bytes += file['bytes']
            new_replicas.append({'rse_id': rse_id, 'scope': file['scope'], 'name': file['name'], 'bytes': file['bytes'], 'path': file.get('path'), 'state': ReplicaState(file.get('state', 'A')), 'md5': file.get('md5'), 'adler32': file.get('adler32'), 'lock_cnt': file.get('lock_cnt', 0), 'tombstone': (file.get('tombstone') or default_tombstone)})
    try:
        (new_replicas and session.bulk_insert_mappings(models.RSEFileAssociation, new_replicas))
        session.flush()
        return (nbfiles, bytes)
    except IntegrityError as error:
        if (match('.*IntegrityError.*ORA-00001: unique constraint .*REPLICAS_PK.*violated.*', error.args[0]) or match('.*IntegrityError.*1062.*Duplicate entry.*', error.args[0]) or match('.*IntegrityError.*columns? rse_id.*scope.*name.*not unique.*', error.args[0]) or match('.*IntegrityError.*duplicate key value violates unique constraint.*', error.args[0])):
            raise exception.Duplicate('File replica already exists!')
        raise exception.RucioException(error.args)
    except DatabaseError as error:
        raise exception.RucioException(error.args)
Bulk add new dids.

:param rse_id: the RSE id.
:param dids: the list of files.
:param account: The account owner.
:param session: The database session in use.
:returns: True is successful.
@transactional_session
def __bulk_add_replicas(rse_id, files, account, session=None):
    '\n    Bulk add new dids.\n\n    :param rse_id: the RSE id.\n    :param dids: the list of files.\n    :param account: The account owner.\n    :param session: The database session in use.\n    :returns: True is successful.\n    '
    (nbfiles, bytes) = (0, 0)
    condition = []
    for f in files:
        condition.append(and_((models.RSEFileAssociation.scope == f['scope']), (models.RSEFileAssociation.name == f['name']), (models.RSEFileAssociation.rse_id == rse_id)))
    query = session.query(models.RSEFileAssociation.scope, models.RSEFileAssociation.name, models.RSEFileAssociation.rse_id).with_hint(models.RSEFileAssociation, text='INDEX(REPLICAS REPLICAS_PK)', dialect_name='oracle').filter(or_(*condition))
    available_replicas = [dict([(column, getattr(row, column)) for column in row._fields]) for row in query]
    default_tombstone_delay = next(iter(get_rse_attribute('tombstone_delay', rse_id=rse_id, session=session)), None)
    default_tombstone = tombstone_from_delay(default_tombstone_delay)
    new_replicas = []
    for file in files:
        found = False
        for available_replica in available_replicas:
            if ((file['scope'] == available_replica['scope']) and (file['name'] == available_replica['name']) and (rse_id == available_replica['rse_id'])):
                found = True
                break
        if (not found):
            nbfiles += 1
            bytes += file['bytes']
            new_replicas.append({'rse_id': rse_id, 'scope': file['scope'], 'name': file['name'], 'bytes': file['bytes'], 'path': file.get('path'), 'state': ReplicaState(file.get('state', 'A')), 'md5': file.get('md5'), 'adler32': file.get('adler32'), 'lock_cnt': file.get('lock_cnt', 0), 'tombstone': (file.get('tombstone') or default_tombstone)})
    try:
        (new_replicas and session.bulk_insert_mappings(models.RSEFileAssociation, new_replicas))
        session.flush()
        return (nbfiles, bytes)
    except IntegrityError as error:
        if (match('.*IntegrityError.*ORA-00001: unique constraint .*REPLICAS_PK.*violated.*', error.args[0]) or match('.*IntegrityError.*1062.*Duplicate entry.*', error.args[0]) or match('.*IntegrityError.*columns? rse_id.*scope.*name.*not unique.*', error.args[0]) or match('.*IntegrityError.*duplicate key value violates unique constraint.*', error.args[0])):
            raise exception.Duplicate('File replica already exists!')
        raise exception.RucioException(error.args)
    except DatabaseError as error:
        raise exception.RucioException(error.args)