Skip to content

Instantly share code, notes, and snippets.

@iundarigun
iundarigun / SomeHttpClient.kt
Created December 11, 2019 16:25
SomeHttpClient
interface SomeHttpClient {
@GetMapping
fun getSomething(
@RequestHeader headers: Map<String, String> = emptyMap(),
@SpringQueryMap @ModelAttribute customObject: Any
): List<SomeResponse>?
@PostMapping
fun postSomething(
@iundarigun
iundarigun / feignBuilder.kt
Created December 11, 2019 16:08
FeignBuilderDeclaration
@Bean
fun feignClient(): Feign.Builder {
return Feign.builder()
.decoder(GsonDecoder())
.encoder(GsonEncoder())
}
@iundarigun
iundarigun / feignBuilder.kt
Created December 11, 2019 16:04
FeignDeclaration
fun feignClient(): GitHub {
return Feign.builder()
.decoder(GsonDecoder())
.encoder(GsonEncoder())
.target(GitHub.class, "https://api.github.com")
}
@Data
@Entity
@NoArgsConstructor
public class Account {
// Outros campos
@Version
private Long version;
}
@Data
@Entity
@NoArgsConstructor
public class Account {
@Id
@GeneratedValue
private Long id;
private BigDecimal amount;
@Autowired
private UserService userService;
@Transactional
public void addBillsNewTransactionByProxy(final Long id, final List<BillVO> billList) {
User user = userRepository.getOne(id);
for (BillVO billVO : billList) {
userService.createBill(billVO, user);
}
throw new RuntimeException();
@Transactional
public void addBillsNewTransactionInThisClass(final Long id, final List<BillVO> billList) {
User user = userRepository.getOne(id);
for (BillVO billVO : billList) {
createBill(billVO, user);
}
throw new RuntimeException();
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Transactional(noRollbackFor = RuntimeException.class)
public void validateBillWithUncheckedException(BillVO bill) {
if (bill.getDate().isAfter(LocalDate.now())) {
throw new RuntimeException();
}
}
@Autowired
private ValidationService validationService;
@Transactional
public void addBillsCatchingProxyUncheckedException(final Long id, final List<BillVO> billList) {
User user = userRepository.getOne(id);
for (BillVO billVO : billList) {
try {
validationService.validateBillWithUncheckedException(billVO);
user.getBillList().add(
@Transactional
public void addBillsCatchingPrivateUncheckedException(final Long id, final List<BillVO> billList) {
User user = userRepository.getOne(id);
for (BillVO billVO : billList) {
try {
validateBillWithUncheckedException(billVO);
user.getBillList().add(
new Bill(billVO.getType(),
billVO.getValue(), billVO.getDate(), user));
} catch (RuntimeException e) {