java

java
@MappedSuperclass
@FilterDef(
    name = "tenantFilter",
    parameters = @ParamDef(name = "tenantId", type = String.class)
)
@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")

Enforce Multi-Tenant Row Isolation With Hibernate @Filter Enabled Per Request in Spring Boot

spring-boot hibernate jpa
by codesnips 4 tabs
java
@Component
public class SalesRollupScheduler {

    private static final Logger log = LoggerFactory.getLogger(SalesRollupScheduler.class);
    private static final int ROLLUP_WINDOW_DAYS = 3;

Roll Up Daily Sales Totals With a Scheduled Spring Batch Upsert via JdbcTemplate

spring-boot jdbctemplate postgres
by codesnips 3 tabs
java
package com.example.demo.dto;

import com.example.demo.validation.UniqueEmail;
import jakarta.validation.constraints.*;
import lombok.Data;

Validation with Bean Validation API

java validation bean-validation
by David Kumar 3 tabs
java
package com.example.cache;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CompletionException;
import java.util.concurrent.atomic.AtomicBoolean;

Single-Flight Cache Loader: Coalesce Concurrent Identical Loads in Java

caching concurrency single-flight
by codesnips 3 tabs
java
package com.example.ratelimit;

public class TokenBucket {

    private final long capacity;
    private final long refillTokens;

Per-Client Token Bucket Rate Limiting with a Spring Boot HandlerInterceptor

spring-boot rate-limiting token-bucket
by codesnips 4 tabs
java
package com.example.security;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

Method-Level Role Authorization with a Custom @RequireRole Annotation and Spring AOP

spring spring-boot aop
by codesnips 4 tabs
java
package com.shop.inventory;

import jakarta.persistence.*;

@Entity
@Table(name = "inventory_item")

Optimistic Locking on Inventory Updates with @Version and a Retrying Conflict Handler in Spring Boot

spring-boot jpa hibernate
by codesnips 3 tabs
java
package com.example.github;

import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;

Declarative Typed HTTP Client With Retrofit and an OkHttp Auth Interceptor

retrofit okhttp http-client
by codesnips 3 tabs
java
@RestController
@RequestMapping("/users")
public class UserPatchController {

    private final UserRepository users;
    private final JsonPatchService patchService;

Applying RFC 6902 JSON Patch with Optimistic Locking in Spring Boot

spring-boot rest-api json-patch
by codesnips 3 tabs
java
package com.example.orders;

public final class Order {

    public static final Order POISON_PILL = new Order(-1L, 0.0);

Producer/Consumer Order Processing With a Bounded BlockingQueue in Java

java concurrency blockingqueue
by codesnips 3 tabs
java
package com.example.demo.scheduled;

import com.example.demo.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;

Scheduled tasks with @Scheduled

java spring-boot scheduling
by David Kumar 2 tabs
java
package com.example.users.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;

Mapping JPA Entities to DTOs with a MapStruct Mapper Injected into a Spring Service

spring-boot mapstruct dto
by codesnips 4 tabs