<commit_before>package com.atlassian.jira.plugins.dvcs.service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import com.atlassian.jira.plugins.dvcs.activeobjects.v3.ChangesetMapping;
import com.atlassian.jira.plugins.dvcs.dao.ChangesetDao;
import com.atlassian.jira.plugins.dvcs.dao.RepositoryDao;
import com.atlassian.jira.plugins.dvcs.exception.SourceControlException;
import com.atlassian.jira.plugins.dvcs.model.Changeset;
import com.atlassian.jira.plugins.dvcs.model.ChangesetFile;
import com.atlassian.jira.plugins.dvcs.model.ChangesetFileDetail;
import com.atlassian.jira.plugins.dvcs.model.Changesets;
import com.atlassian.jira.plugins.dvcs.model.GlobalFilter;
import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.service.remote.DvcsCommunicator;
import com.atlassian.jira.plugins.dvcs.service.remote.DvcsCommunicatorProvider;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ChangesetServiceImpl implements ChangesetService
{
    private static final Logger logger = LoggerFactory.getLogger(ChangesetServiceImpl.class);
    private final ConcurrencyService concurrencyService;

    private final ChangesetDao changesetDao;

    @Resource
    private DvcsCommunicatorProvider dvcsCommunicatorProvider;

    @Resource
    private RepositoryDao repositoryDao;

    public ChangesetServiceImpl(ConcurrencyService concurrencyService, ChangesetDao changesetDao)
    {
        this.concurrencyService = concurrencyService;
        this.changesetDao = changesetDao;
    }

    @Override
    public Changeset create(final Changeset changeset, final Set<String> extractedIssues)
    {
        return concurrencyService.synchronizedBlock(new ConcurrencyService.SynchronizedBlock<Changeset, RuntimeException>()
        {

            @Override
            public Changeset perform() throws RuntimeException
            {
                return changesetDao.create(changeset, extractedIssues);
            }

        }, Changeset.class, changeset.getRawNode());
    }

    @Override
    public Changeset update(Changeset changeset)
    {
        return changesetDao.update(changeset);
    }

    @Override
    public void removeAllInRepository(int repositoryId)
    {
        changesetDao.removeAllInRepository(repositoryId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Changeset getByNode(int repositoryId, String changesetNode)
    {
        return changesetDao.getByNode(repositoryId, changesetNode);
    }<commit_msg>JDEV-26465 Replaced synchronized block in ChangesetServiceImpl with cluster lock<commit_after>package com.atlassian.jira.plugins.dvcs.service;

import com.atlassian.beehive.ClusterLockService;
import com.atlassian.beehive.compat.ClusterLockServiceFactory;
import com.atlassian.jira.plugins.dvcs.activeobjects.v3.ChangesetMapping;
import com.atlassian.jira.plugins.dvcs.dao.ChangesetDao;
import com.atlassian.jira.plugins.dvcs.dao.RepositoryDao;
import com.atlassian.jira.plugins.dvcs.exception.SourceControlException;
import com.atlassian.jira.plugins.dvcs.model.Changeset;
import com.atlassian.jira.plugins.dvcs.model.ChangesetFile;
import com.atlassian.jira.plugins.dvcs.model.ChangesetFileDetail;
import com.atlassian.jira.plugins.dvcs.model.Changesets;
import com.atlassian.jira.plugins.dvcs.model.GlobalFilter;
import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.service.remote.DvcsCommunicator;
import com.atlassian.jira.plugins.dvcs.service.remote.DvcsCommunicatorProvider;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;

public class ChangesetServiceImpl implements ChangesetService
{
    private static final Logger logger = LoggerFactory.getLogger(ChangesetServiceImpl.class);

    private final ChangesetDao changesetDao;
    private final ClusterLockService clusterLockService;
    private final DvcsCommunicatorProvider dvcsCommunicatorProvider;
    private final RepositoryDao repositoryDao;

    public ChangesetServiceImpl(final ChangesetDao changesetDao, final ClusterLockServiceFactory clusterLockServiceFactory,
            final DvcsCommunicatorProvider dvcsCommunicatorProvider, final RepositoryDao repositoryDao)
    {
        this.changesetDao = changesetDao;
        this.clusterLockService = clusterLockServiceFactory.getClusterLockService();
        this.dvcsCommunicatorProvider = dvcsCommunicatorProvider;
        this.repositoryDao = repositoryDao;
    }

    @Override
    public Changeset create(final Changeset changeset, final Set<String> extractedIssues)
    {
        final String lockName = Changeset.class.getName() + changeset.getRawNode();
        final Lock createLock = clusterLockService.getLockForName(lockName);
        createLock.lock();
        try
        {
            return changesetDao.create(changeset, extractedIssues);
        }
        finally
        {
            createLock.unlock();
        }
    }

    @Override
    public Changeset update(Changeset changeset)
    {
        return changesetDao.update(changeset);
    }

    @Override
    public void removeAllInRepository(int repositoryId)
    {
        changesetDao.removeAllInRepository(repositoryId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Changeset getByNode(int repositoryId, String changesetNode)
    {
        return changesetDao.getByNode(repositoryId, changesetNode);
    }
{'fraction_non_alphanumeric': 0.08362760834670947, 'fraction_numerical': 0.001765650080256822, 'mean_word_length': 4.312020460358056, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1225599', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1829, 'n_words': 301}