/
allalex
/
Spring-AOP
Обзор
Документация
Войти
/
allalex
/
Spring-AOP
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/springaopopenschool1/firsttask/service/ExecutionLogServiceImpl.java
39 строк
1 KB
Alexey Layko
фикс бага + рефактор
10 май 2024, 02:12
10 май 2024, 02:12
e17481a
Код
Авторство
О чём код?
package com.springaopopenschool1.firsttask.service; import com.springaopopenschool1.firsttask.model.ExecutionLog; import com.springaopopenschool1.firsttask.repository.ExecutionLogRepository; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.UUID; @Service @Slf4j public class ExecutionLogServiceImpl implements ExecutionLogService { private final ExecutionLogRepository repository; public ExecutionLogServiceImpl(ExecutionLogRepository repository) { this.repository = repository; } @Override @Transactional public void logExecutionTime(ProceedingJoinPoint joinPoint, long timeExecuted, boolean isAsyncExecuted) { try { ExecutionLog log = ExecutionLog.builder() .id(UUID.randomUUID()) .className(joinPoint.getSignature().getDeclaringTypeName()) .methodName(joinPoint.getSignature().getName()) .executionTime(timeExecuted) .createdAt(LocalDateTime.now()) .isAsyncExecuted(isAsyncExecuted) .build(); repository.save(log); } catch (Exception e) { log.error("Error when trying to complete a transaction", e); } } }