Skip to content

rrezartprebreza/spring-boot-skills / skills/spring-boot-3/multi-tenancy

multi-tenancy

Verified

Use when implementing tenant resolution, database or schema isolation, tenant-aware JPA, reactive tenant context, migrations, caching, jobs, or authorization in Spring Boot 3.

templates/TenantOrderStore.java

View on GitHub
package com.example.tenancy;

import java.util.Optional;
import java.util.UUID;
import org.springframework.jdbc.core.JdbcTemplate;

/** Shared-schema repository; no public unscoped read/write operation. */
public final class TenantOrderStore {
    private final JdbcTemplate jdbc;
    public TenantOrderStore(JdbcTemplate jdbc) { this.jdbc = jdbc; }

    public void create(UUID id, String description) {
        jdbc.update("INSERT INTO tenant_orders (tenant_id, id, description) VALUES (?, ?, ?)",
            TenantContext.required().value(), id, description);
    }

    public Optional<Order> find(UUID id) {
        return jdbc.query("SELECT id, description FROM tenant_orders WHERE tenant_id = ? AND id = ?",
            (rs, row) -> new Order(rs.getObject("id", UUID.class), rs.getString("description")),
            TenantContext.required().value(), id).stream().findFirst();
    }

    public boolean update(UUID id, String description) {
        return jdbc.update("UPDATE tenant_orders SET description = ? WHERE tenant_id = ? AND id = ?",
            description, TenantContext.required().value(), id) == 1;
    }

    public boolean delete(UUID id) {
        return jdbc.update("DELETE FROM tenant_orders WHERE tenant_id = ? AND id = ?",
            TenantContext.required().value(), id) == 1;
    }

    public record Order(UUID id, String description) {}
}
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall