@Override
    public void alreadyExists(User user) throws EntityAlreadyExistsException, UnablePerformDBOperation, CantGetDBConnection {

        log.info("Searching user " + user.toString() + " in DB");

        checkConnection();

        String queryLogin = "select * from users where login = ? ";
        String queryEmail = "select * from users where email = ? ";

        boolean updatingUser = (user.getId() != 0);
        if (updatingUser) {
            queryLogin += "and id != ?";
            queryEmail += "and id != ?";
        }

        String baseErrorMessage = "Exception while checking user in DB: " + user.toString() + ". ";

        try {

            try (PreparedStatement statement = connection.prepareStatement(queryLogin)) {
                statement.setString(1, user.getLogin());
                if (updatingUser) {
                    statement.setInt(2, user.getId());
                }

                try (ResultSet resultSet = statement.executeQuery()) {
                    if (resultSet.next()) {
                        String errorMessage = "User with login " + user.getLogin() + " already alreadyExists in DB";
                        log.error(errorMessage);
                        throw new EntityAlreadyExistsException(errorMessage);
                    }
                }
            }

            try (PreparedStatement statement = connection.prepareStatement(queryEmail)) {
                statement.setString(1, user.getEmail());
                if (updatingUser) {
                    statement.setInt(2, user.getId());
                }

                try (ResultSet resultSet = statement.executeQuery()) {
                    if (resultSet.next()) {
                        String errorMessage = "User with email " + user.getEmail() + " already alreadyExists in DB";
                        log.error(errorMessage);
                        throw new EntityAlreadyExistsException(errorMessage);
                    }
                }
            }

        } catch (EntityAlreadyExistsException e) {
            throw e;
        } catch (Exception e) {
            log.error(baseErrorMessage);
            throw new UnablePerformDBOperation(baseErrorMessage, e);
        }
    }