Java DDD Repositories
Implement the domain's Gateway contracts faithfully. The authoritative technical
reference is the current ddd-example/domain source supplied for this project,
reviewed at commit 8d964ce4106c2299164e28980ae7553e2afbdc92. Its five Gateways and
four query/pagination/projection types ship as complete Java files, linked from the
references below alongside the contract explanations and portable source paths;
the original checkout was C:\git\ddd-example\domain. Do not substitute generic DDD
preferences, other projects or persistence-framework conventions for this source.
This skill owns the domain boundary, including its projection and media contracts.
It does not implement application use cases, database adapters, storage clients or
transactions. An interface declaration establishes a Java type contract; it does
not prove an adapter's database behavior, error translation or durability.
Define the boundary from evidence
- Identify the corresponding reference port. Keep the interface beside its
aggregate:
category.CategoryGateway, genre.GenreGateway,
castmember.CastMemberGateway, video.VideoGateway, or
video.MediaResourceGateway. When choosing or reviewing methods, read
gateway contracts. Preserve separate create
and update; do not introduce a generic Repository<T, ID>, a shared save,
framework inheritance or a base interface merely because methods repeat.
- Preserve every signature and its differences. Lookups use concrete typed
identifiers and return
Optional<Aggregate>. The first three aggregate ports
return aggregate pages and have existsByIds(Iterable<ID>) -> List<ID>.
VideoGateway returns Pagination<VideoPreview> and has no existsByIds.
Media storage has its own four-method port. Do not homogenize these contracts.
- Keep the supporting types in domain. Read
query, projection and resource types when
constructing criteria, mapping pages, returning previews or handling media.
Preserve component names, order and types, including
String in
VideoPreview.id and typed ID sets in VideoSearchQuery. Do not move the
reference's preview or search types to application, introduce Pageable, or add
normalization, validation or defensive copying that the source does not perform.
- Separate known structure from unknown behavior. The interfaces do not define
sort defaults, page bounds, filter combination, missing-update/delete outcomes,
ordering of existence results, storage failures, transactions or concurrency.
State those limits. If completing the requested behavior requires an unresolved
choice, ask a focused question; do not guess from a method name. Continue the
domain work whose contract is established. New aggregate ports require evidence
for the chosen operations, not automatic copying of every CRUD method.
- Respect aggregate restoration APIs. When a Gateway change touches a
with(...) boundary or is claimed to guarantee persistence behavior, read
reconstitution and concurrency boundaries.
Preserve supplied identity/state and each overload's actual validation and event
behavior. Do not add revision tokens, locking, a unit of work or event delivery
protocols absent from this domain.
- Verify only what the evidence can establish. Read
verification for source comparison, useful domain
checks and concrete review cases. Domain unit tests use real domain objects,
no mocks or Mockito, and explicit
@DisplayName on every test method. Do not
create tests that mock a Gateway and assert its stubbed return value. Report
signature checks, executed domain tests and unverified adapter behavior separately.
Keep the reference's plain Java imports and domain types. Inspect the consuming
project's compiler and test configuration before running examples; the source
shapes here are Java 17 compatible and require no preview feature. Do not upgrade
Java, add frameworks/nullability libraries or infer the domain compiler toolchain
from an unrelated build module.
When copying or compiling the bundled Java files, follow the complete-source links
in the Gateway and boundary-type references. They retain their original packages
and imports and need the remaining reference domain types. Use the source index in
java-ddd when assembling that domain; these nine files are
not a standalone module. If that suggested skill is unavailable, use the supplied
reference domain checkout for the missing types rather than inventing substitutes.
Handoffs and result
Use java-ddd-aggregates for aggregate state, factories and ownership;
java-ddd-value-objects for identifiers and media value objects;
java-ddd-domain-events for event buffering/publication;
java-ddd-domain-services for the reference validation mechanism; and
java-ddd-testing for domain test design. A request about SQL, mapping, locking,
commit, or a concrete storage client is outside this domain-only contract. Identify
that boundary and the missing evidence before changing another layer.
For implementation, deliver the requested domain interfaces/types with their
source counterparts and checks. For review, report concrete differences, affected
contracts and evidence. Keep unresolved behavior explicit; do not present an
interface match or a passing domain test as proof of persistence correctness.
1---2name: java-ddd-repositories3description: >-4 Implement or review domain Gateway interfaces using the ddd-example domain5 reference. Use when defining aggregate lookups and writes, typed-ID existence6 queries, pagination, video previews or media resource ports. Preserves the exact7 domain contracts and package placement; excludes application orchestration,8 persistence adapters, ORM mappings and transaction implementation.9metadata:10 source: https://skillmd.com/skills/robsonkades/java-ddd-repositories11---1213# Java DDD Repositories1415Implement the domain's `Gateway` contracts faithfully. The authoritative technical16reference is the current `ddd-example/domain` source supplied for this project,17reviewed at commit `8d964ce4106c2299164e28980ae7553e2afbdc92`. Its five Gateways and18four query/pagination/projection types ship as complete Java files, linked from the19references below alongside the contract explanations and portable source paths;20the original checkout was `C:\git\ddd-example\domain`. Do not substitute generic DDD21preferences, other projects or persistence-framework conventions for this source.2223This skill owns the domain boundary, including its projection and media contracts.24It does not implement application use cases, database adapters, storage clients or25transactions. An interface declaration establishes a Java type contract; it does26not prove an adapter's database behavior, error translation or durability.2728## Define the boundary from evidence29301. **Identify the corresponding reference port.** Keep the interface beside its31 aggregate: `category.CategoryGateway`, `genre.GenreGateway`,32 `castmember.CastMemberGateway`, `video.VideoGateway`, or33 `video.MediaResourceGateway`. When choosing or reviewing methods, read34 [gateway contracts](references/gateway-contracts.md). Preserve separate `create`35 and `update`; do not introduce a generic `Repository<T, ID>`, a shared `save`,36 framework inheritance or a base interface merely because methods repeat.372. **Preserve every signature and its differences.** Lookups use concrete typed38 identifiers and return `Optional<Aggregate>`. The first three aggregate ports39 return aggregate pages and have `existsByIds(Iterable<ID>) -> List<ID>`.40 `VideoGateway` returns `Pagination<VideoPreview>` and has no `existsByIds`.41 Media storage has its own four-method port. Do not homogenize these contracts.423. **Keep the supporting types in domain.** Read43 [query, projection and resource types](references/domain-boundary-types.md) when44 constructing criteria, mapping pages, returning previews or handling media.45 Preserve component names, order and types, including `String` in46 `VideoPreview.id` and typed ID sets in `VideoSearchQuery`. Do not move the47 reference's preview or search types to application, introduce `Pageable`, or add48 normalization, validation or defensive copying that the source does not perform.494. **Separate known structure from unknown behavior.** The interfaces do not define50 sort defaults, page bounds, filter combination, missing-update/delete outcomes,51 ordering of existence results, storage failures, transactions or concurrency.52 State those limits. If completing the requested behavior requires an unresolved53 choice, ask a focused question; do not guess from a method name. Continue the54 domain work whose contract is established. New aggregate ports require evidence55 for the chosen operations, not automatic copying of every CRUD method.565. **Respect aggregate restoration APIs.** When a Gateway change touches a57 `with(...)` boundary or is claimed to guarantee persistence behavior, read58 [reconstitution and concurrency boundaries](references/reconstitution-and-concurrency.md).59 Preserve supplied identity/state and each overload's actual validation and event60 behavior. Do not add revision tokens, locking, a unit of work or event delivery61 protocols absent from this domain.626. **Verify only what the evidence can establish.** Read63 [verification](references/verification.md) for source comparison, useful domain64 checks and concrete review cases. Domain unit tests use real domain objects,65 no mocks or Mockito, and explicit `@DisplayName` on every test method. Do not66 create tests that mock a Gateway and assert its stubbed return value. Report67 signature checks, executed domain tests and unverified adapter behavior separately.6869Keep the reference's plain Java imports and domain types. Inspect the consuming70project's compiler and test configuration before running examples; the source71shapes here are Java 17 compatible and require no preview feature. Do not upgrade72Java, add frameworks/nullability libraries or infer the domain compiler toolchain73from an unrelated build module.7475When copying or compiling the bundled Java files, follow the complete-source links76in the Gateway and boundary-type references. They retain their original packages77and imports and need the remaining reference domain types. Use the source index in78[java-ddd](../java-ddd/SKILL.md) when assembling that domain; these nine files are79not a standalone module. If that suggested skill is unavailable, use the supplied80reference domain checkout for the missing types rather than inventing substitutes.8182## Handoffs and result8384Use `java-ddd-aggregates` for aggregate state, factories and ownership;85`java-ddd-value-objects` for identifiers and media value objects;86`java-ddd-domain-events` for event buffering/publication;87`java-ddd-domain-services` for the reference validation mechanism; and88`java-ddd-testing` for domain test design. A request about SQL, mapping, locking,89commit, or a concrete storage client is outside this domain-only contract. Identify90that boundary and the missing evidence before changing another layer.9192For implementation, deliver the requested domain interfaces/types with their93source counterparts and checks. For review, report concrete differences, affected94contracts and evidence. Keep unresolved behavior explicit; do not present an95interface match or a passing domain test as proof of persistence correctness.