package nl.tehdreamteam.se42.data.user.hibernate;

import nl.tehdreamteam.se42.data.repository.HibernateRepository;
import nl.tehdreamteam.se42.data.user.UserDAO;
import nl.tehdreamteam.se42.data.user.UserRepository;
import nl.tehdreamteam.se42.domain.User;

import javax.persistence.EntityManager;
import java.util.function.Function;

/**
 * A {@code UserHibernateRepository} defines communication between the database and a {@link UserDAO}.
 *
 * @author Lesley
 */
public final class UserHibernateRepository extends HibernateRepository<Long, User, UserDAO> implements UserRepository {

    @Override
    public User get(String username) {
        Function<UserDAO, User> getFunction = dao -> dao.findByUsername(username);

        return super.performTransaction(getFunction);
    }

    @Override
    public void save(User user) {
        super.create(user);
    }

    @Override
    public void remove(User user) {
        super.remove(user);
    }

    @Override
    public void remove(long id) {
        Function<UserDAO, Void> findAndDeleteFunction = dao -> {
            User user = dao.find(id);
            dao.remove(user);

            return null;
        };

        super.performTransaction(findAndDeleteFunction);
    }

    @Override
    protected UserDAO createDao(EntityManager manager) {
        return new UserHibernateDAO(manager);
    }

}

@@ -1000,77 +1000,8 @@
 ) %7B%0A
-        Function%3CUserDAO, Void%3E findAndDeleteFunction = dao -%3E %7B%0A    
     
@@ -1016,20 +1016,16 @@
  user = 
-dao.
 find(id)
@@ -1038,16 +1038,8 @@
     
-    
-dao.
 remo
@@ -1051,103 +1051,8 @@
 er);
-%0A%0A            return null;%0A        %7D;%0A%0A        super.performTransaction(findAndDeleteFunction);
 %0A   

Use separate transactions.