<commit_before>package de.fau.cs.mad.kwikshop.server.sorting;

import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

import de.fau.cs.mad.kwikshop.common.sorting.BoughtItem;
import de.fau.cs.mad.kwikshop.server.dao.BoughtItemDAO;
import de.fau.cs.mad.kwikshop.server.dao.EdgeDAO;
import de.fau.cs.mad.kwikshop.server.dao.SupermarketChainDAO;
import de.fau.cs.mad.kwikshop.server.dao.SupermarketDAO;

public class DAOHelperImpl extends AbstractDAOHelper {

    private BoughtItemDAO boughtItemDAO;
    private EdgeDAO edgeDAO;
    private SupermarketDAO supermarketDAO;
    private SupermarketChainDAO supermarketChainDAO;

    public DAOHelperImpl(BoughtItemDAO boughtItemDAO, EdgeDAO edgeDAO,
                         SupermarketDAO supermarketDAO, SupermarketChainDAO supermarketChainDAO) {
        super();
        this.boughtItemDAO = boughtItemDAO;
        this.edgeDAO = edgeDAO;
        this.supermarketDAO = supermarketDAO;
        this.supermarketChainDAO = supermarketChainDAO;
        this.supermarketChainDAO.setUp();
    }

    @Override
    public Supermarket getSupermarketByPlaceID(String placeId) {
        return supermarketDAO.getByPlaceId(placeId);
    }

    @Override
    public List<SupermarketChain> getAllSupermarketChains() {
        return supermarketChainDAO.getAll();
    }

    @Override
    public void createSupermarket(Supermarket supermarket) {
        supermarketDAO.createSupermarket(supermarket);
    }

    @Override
    public List<Edge> getEdgesBySupermarket(Supermarket supermarket) {
        return edgeDAO.getBySupermarket(supermarket);
    }

    @Override
    public Edge getEdgeByFromTo(BoughtItem from, BoughtItem to, Supermarket supermarket) {
        return edgeDAO.getByFromTo(from, to, supermarket);
    }

    @Override
    public List<Edge> getEdgesByTo(BoughtItem boughtItem, Supermarket supermarket) {
        return edgeDAO.getByTo(boughtItem, supermarket);
    }

    @Override
    public Edge createEdge(Edge edge) {
        return edgeDAO.createEdge(edge);
    }

    @Override
    public void deleteEdge(Edge edge) {
        edgeDAO.deleteEdge(edge);
    }

    @Override
    public BoughtItem getStartBoughtItem() {
        return boughtItemDAO.getStart();
    }

    @Override
    public BoughtItem getEndBoughtItem() {
        return boughtItemDAO.getEnd();
    }

    @Override
    public BoughtItem getBoughtItemByName(String name) {
        return boughtItemDAO.getByName(name);
    }

    @Override
    public BoughtItem getBoughtItemByNameIncludingStartAndEnd(String name) {
        return boughtItemDAO.getByNameIncludingStartAndEnd(name);
    }

    @Override
    public void createBoughtItem(BoughtItem boughtItem) {
        boughtItemDAO.createBoughtItem(boughtItem);
    }

    @Override
    public Supermarket getGlobalSupermarketBySupermarketChain(SupermarketChain supermarketChain) {
        return supermarketDAO.getGlobalBySupermarketChain(supermarketChain);
    }

    @Override
    public Supermarket getGlobalSupermarket(SupermarketChain supermarketChain) {
        return supermarketChainDAO.getGlobalSupermarket(supermarketChain);
    }
}
<commit_msg>Made a simple synchronization for the DAOHelperImpl. It should (TM) work, but if not, there is still the synchronization (/ consistency constraints) of the database beyond, so worst case scenario is that a user obtains old data<commit_after>package de.fau.cs.mad.kwikshop.server.sorting;

import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

import de.fau.cs.mad.kwikshop.common.sorting.BoughtItem;
import de.fau.cs.mad.kwikshop.server.dao.BoughtItemDAO;
import de.fau.cs.mad.kwikshop.server.dao.EdgeDAO;
import de.fau.cs.mad.kwikshop.server.dao.SupermarketChainDAO;
import de.fau.cs.mad.kwikshop.server.dao.SupermarketDAO;

public class DAOHelperImpl extends AbstractDAOHelper {

    private BoughtItemDAO boughtItemDAO;
    private EdgeDAO edgeDAO;
    private SupermarketDAO supermarketDAO;
    private SupermarketChainDAO supermarketChainDAO;

    public DAOHelperImpl(BoughtItemDAO boughtItemDAO, EdgeDAO edgeDAO,
                         SupermarketDAO supermarketDAO, SupermarketChainDAO supermarketChainDAO) {
        super();
        this.boughtItemDAO = boughtItemDAO;
        this.edgeDAO = edgeDAO;
        this.supermarketDAO = supermarketDAO;
        this.supermarketChainDAO = supermarketChainDAO;
        this.supermarketChainDAO.setUp();
    }

    @Override
    public Supermarket getSupermarketByPlaceID(String placeId) {
        synchronized (supermarketDAO) {
            return supermarketDAO.getByPlaceId(placeId);
        }
    }

    @Override
    public List<SupermarketChain> getAllSupermarketChains() {
        synchronized (supermarketChainDAO) {
            return supermarketChainDAO.getAll();
        }
    }

    @Override
    public void createSupermarket(Supermarket supermarket) {
        synchronized (supermarketDAO) {
            supermarketDAO.createSupermarket(supermarket);
        }
    }

    @Override
    public List<Edge> getEdgesBySupermarket(Supermarket supermarket) {
        synchronized (edgeDAO) {
            return edgeDAO.getBySupermarket(supermarket);
        }
    }

    @Override
    public Edge getEdgeByFromTo(BoughtItem from, BoughtItem to, Supermarket supermarket) {
        try {
            lockLocksWithIds(from.getId(), to.getId());
            return edgeDAO.getByFromTo(from, to, supermarket);
        } finally {
            unlockLocksWithIds(from.getId(), to.getId());
        }
    }

    @Override
    public List<Edge> getEdgesByTo(BoughtItem boughtItem, Supermarket supermarket) {
        try {
            lockLockWithId(boughtItem.getId());
            return edgeDAO.getByTo(boughtItem, supermarket);
        } finally {
            unlockLockWithId(boughtItem.getId());
        }
    }

    @Override
    public Edge createEdge(Edge edge) {
        int id1 = edge.getFrom().getId();
        int id2 = edge.getTo().getId();
        try {
            lockLocksWithIds(id1, id2);
            return edgeDAO.createEdge(edge);
        } finally {
            unlockLocksWithIds(id1, id2);
        }
    }

    @Override
    public void deleteEdge(Edge edge) {
        int id1 = edge.getFrom().getId();
        int id2 = edge.getTo().getId();
        try {
            lockLocksWithIds(id1, id2);
            edgeDAO.deleteEdge(edge);
        } finally {
            unlockLocksWithIds(id1, id2);
        }
    }

    @Override
    public BoughtItem getStartBoughtItem() {
        synchronized (boughtItemDAO) {
            return boughtItemDAO.getStart();
        }
    }

    @Override
    public BoughtItem getEndBoughtItem() {
        synchronized (boughtItemDAO) {
            return boughtItemDAO.getEnd();
        }
    }

    @Override
    public BoughtItem getBoughtItemByName(String name) {
        synchronized (boughtItemDAO) {
            return boughtItemDAO.getByName(name);
        }
    }

    @Override
    public BoughtItem getBoughtItemByNameIncludingStartAndEnd(String name) {
        synchronized (boughtItemDAO) {
            return boughtItemDAO.getByNameIncludingStartAndEnd(name);
        }
    }

    @Override
    public void createBoughtItem(BoughtItem boughtItem) {
        synchronized (boughtItemDAO) {
            boughtItemDAO.createBoughtItem(boughtItem);
        }
    }

    @Override
    public Supermarket getGlobalSupermarketBySupermarketChain(SupermarketChain supermarketChain) {
        synchronized (supermarketDAO) {
            return supermarketDAO.getGlobalBySupermarketChain(supermarketChain);
        }
    }

    @Override
    public Supermarket getGlobalSupermarket(SupermarketChain supermarketChain) {
        synchronized (supermarketChainDAO) {
            return supermarketChainDAO.getGlobalSupermarket(supermarketChain);
        }
    }
}

{'fraction_non_alphanumeric': 0.0796787353391127, 'fraction_numerical': 0.0015298317185109638, 'mean_word_length': 2.968133535660091, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5014927', 'n_tokens_mistral': 2361, 'n_tokens_neox': 2346, 'n_words': 411}