Add Transactional
This commit is contained in:
@@ -5,6 +5,7 @@ import de.htwsaar.webshop.repository.CustomerRepository;
|
|||||||
import de.htwsaar.webshop.repository.entities.Account;
|
import de.htwsaar.webshop.repository.entities.Account;
|
||||||
import de.htwsaar.webshop.service.AccountService;
|
import de.htwsaar.webshop.service.AccountService;
|
||||||
import de.htwsaar.webshop.service.PasswordService;
|
import de.htwsaar.webshop.service.PasswordService;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -29,11 +30,13 @@ public class AccountServiceImpl implements AccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Account save(Account account) {
|
public Account save(Account account) {
|
||||||
return accountRepository.save(account);
|
return accountRepository.save(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Account saveNew(Account account) {
|
public Account saveNew(Account account) {
|
||||||
if (account.getCustomer() != null) {
|
if (account.getCustomer() != null) {
|
||||||
account.getCustomer().setId(null); // Ensure new customer
|
account.getCustomer().setId(null); // Ensure new customer
|
||||||
@@ -44,6 +47,7 @@ public class AccountServiceImpl implements AccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public boolean deleteIfExists(Account account) {
|
public boolean deleteIfExists(Account account) {
|
||||||
Account tbd = accountRepository.getAccountByEmail(account.getEmail());
|
Account tbd = accountRepository.getAccountByEmail(account.getEmail());
|
||||||
if (tbd == null) {
|
if (tbd == null) {
|
||||||
@@ -54,6 +58,7 @@ public class AccountServiceImpl implements AccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public boolean deleteIfExists(Long id) {
|
public boolean deleteIfExists(Long id) {
|
||||||
Account tbd = accountRepository.getAccountById(id);
|
Account tbd = accountRepository.getAccountById(id);
|
||||||
if (tbd == null) {
|
if (tbd == null) {
|
||||||
@@ -78,6 +83,7 @@ public class AccountServiceImpl implements AccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public boolean setAdmin(Long id, boolean admin) {
|
public boolean setAdmin(Long id, boolean admin) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -52,11 +52,13 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
articleRepository.deleteById(id);
|
articleRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void delete(UUID uuid) {
|
public void delete(UUID uuid) {
|
||||||
articleRepository.deleteByUuid(uuid);
|
articleRepository.deleteByUuid(uuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.htwsaar.webshop.service.impl;
|
|||||||
import de.htwsaar.webshop.repository.CustomerRepository;
|
import de.htwsaar.webshop.repository.CustomerRepository;
|
||||||
import de.htwsaar.webshop.repository.entities.Customer;
|
import de.htwsaar.webshop.repository.entities.Customer;
|
||||||
import de.htwsaar.webshop.service.CustomerService;
|
import de.htwsaar.webshop.service.CustomerService;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -18,11 +19,13 @@ public class CustomerServiceImpl implements CustomerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Customer save(Customer customer) {
|
public Customer save(Customer customer) {
|
||||||
return customerRepository.save(customer);
|
return customerRepository.save(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void delete(Customer customer) {
|
public void delete(Customer customer) {
|
||||||
customerRepository.delete(customer);
|
customerRepository.delete(customer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -55,11 +53,13 @@ public class FarmImageServiceImpl implements FarmImageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public FarmImage save(FarmImageModel model) {
|
public FarmImage save(FarmImageModel model) {
|
||||||
return save(new FarmImage(model.getId(), articleService.findByUUID(model.getArticleUuid()), model.getBase64(), model.getStandard()));
|
return save(new FarmImage(model.getId(), articleService.findByUUID(model.getArticleUuid()), model.getBase64(), model.getStandard()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public FarmImage save(UUID uuid, String base64, boolean standard) {
|
public FarmImage save(UUID uuid, String base64, boolean standard) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
log.warn("Got no UUID, aborting");
|
log.warn("Got no UUID, aborting");
|
||||||
|
|||||||
@@ -51,11 +51,13 @@ public class ImageServiceImpl implements ImageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Image save(ImageModel model) {
|
public Image save(ImageModel model) {
|
||||||
return save(new Image(model.getId(), articleService.findByUUID(model.getArticleUuid()), model.getBase64()));
|
return save(new Image(model.getId(), articleService.findByUUID(model.getArticleUuid()), model.getBase64()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Image save(UUID uuid, MultipartFile file) {
|
public Image save(UUID uuid, MultipartFile file) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
log.warn("Got no UUID, aborting");
|
log.warn("Got no UUID, aborting");
|
||||||
@@ -85,6 +87,7 @@ public class ImageServiceImpl implements ImageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Image save(UUID uuid, String base64) {
|
public Image save(UUID uuid, String base64) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
log.warn("Got no UUID, aborting");
|
log.warn("Got no UUID, aborting");
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import de.htwsaar.webshop.util.TimeUtil;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -41,11 +42,13 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Order saveNew(Order order) {
|
public Order saveNew(Order order) {
|
||||||
return orderRepository.save(order);
|
return orderRepository.save(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Order saveNew(OrderModel model) {
|
public Order saveNew(OrderModel model) {
|
||||||
Order order = saveNew(new Order(
|
Order order = saveNew(new Order(
|
||||||
model.getId(),
|
model.getId(),
|
||||||
@@ -75,6 +78,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void delete(Long orderId) {
|
public void delete(Long orderId) {
|
||||||
orderRepository.deleteById(orderId);
|
orderRepository.deleteById(orderId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import de.htwsaar.webshop.service.ReviewService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -25,12 +26,14 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Review save(Review review) {
|
public Review save(Review review) {
|
||||||
review.setTimestamp(System.currentTimeMillis());
|
review.setTimestamp(System.currentTimeMillis());
|
||||||
return reviewRepository.save(review);
|
return reviewRepository.save(review);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Review save(UUID articleUuid, int rating, String content) {
|
public Review save(UUID articleUuid, int rating, String content) {
|
||||||
if (articleUuid == null) {
|
if (articleUuid == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -40,6 +43,7 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void delete(Long reviewId) {
|
public void delete(Long reviewId) {
|
||||||
reviewRepository.deleteById(reviewId);
|
reviewRepository.deleteById(reviewId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import de.htwsaar.webshop.util.TimeUtil;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ public class SessionServiceImpl implements SessionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public Session create(Account account) {
|
public Session create(Account account) {
|
||||||
long timeout = TimeUtil.nowPlusDays(7);
|
long timeout = TimeUtil.nowPlusDays(7);
|
||||||
UUID token = UUID.randomUUID();
|
UUID token = UUID.randomUUID();
|
||||||
@@ -34,6 +36,7 @@ public class SessionServiceImpl implements SessionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void delete(Session session) {
|
public void delete(Session session) {
|
||||||
sessionRepository.delete(session);
|
sessionRepository.delete(session);
|
||||||
}
|
}
|
||||||
@@ -59,7 +62,6 @@ public class SessionServiceImpl implements SessionService {
|
|||||||
}
|
}
|
||||||
if (session.getTimeout() <= System.currentTimeMillis()) {
|
if (session.getTimeout() <= System.currentTimeMillis()) {
|
||||||
log.info("Session with email {} is expired", email);
|
log.info("Session with email {} is expired", email);
|
||||||
delete(session);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
log.info("Session with email {} is valid", email);
|
log.info("Session with email {} is valid", email);
|
||||||
@@ -94,6 +96,7 @@ public class SessionServiceImpl implements SessionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteExpired() {
|
public void deleteExpired() {
|
||||||
sessionRepository.deleteSessionsByTimeoutBefore(System.currentTimeMillis());
|
sessionRepository.deleteSessionsByTimeoutBefore(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user