---
# System prepended metadata

title: Артём Шидлов

---

# Артём Шидлов

```java
class Employee {
    private UUID id;
    private String firstName;
    private String lastName;
    private String middleName;
    private Int age;
    private String address;
    private String phoneNumber;
    private UUID departmentId;
}
```

## StreamAPI

List<Employee> employees = ...
    
1. Сгруппировать всех сотрудников по departmentId
    
```java
    
Map<UUID, List<Employee>> departmentId2Employees = 

```
    
2. Сгруппировать всех сотрудников по departmentId против имени
    
```java
Map<UUID, List<String>> departmentId2EmployeeNames = 
```


## Hibernate    
    
1. Используя HikariPool, в какой момент будет взят connection из pool? 

```java
@Transactional
public void doWork() throws InterruptedException {
    System.out.println("doWork - STARTED");

    Thread.sleep(40000);
    
    System.out.println("Выполняю запрос к БД");    
    Author author = authorRepository.findById(1L).get();
    
    Thread.sleep(40000);

    author.setAge(44);
} 
```
    
2. Какие данные будут сохранены?
    
```java
class UserService {    

private final UserRepo repo;
    
@Transactional
public void updateUser(UUID userId, UpdateUser req) {
        val user = repo.getById(userId);
        user.setAddress(req.getAddress());
    
        userRepo.save(user);
        user.setAge(user.getAge() + 1);
    }
    
}
```  
    
3. Сколько транзакций будет создано?

```java
@Service
class MyService {

private final TransactionalService service;

	@Scheduled(/* cron */)
	public void scheduledJob() {
	    Collection<UUID> uuids = getUuids() // 1k ids
		this.doWork(uuids);
	}

	@Transactional
	void doWork(Collection<UUID> uuids) {
		collection.forEach((uuid) -> service.doSomeWork(uuid));
	}

}

@Service
@Transactional
class TransactionalService  {

	public void doSomeWork(UUID uuid) {
        // some logic
	}
}
```

