---

# (DD27) Business Logic — OwnerController.findPaginatedForOwnersLastName() [5 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `org.springframework.samples.petclinic.owner.OwnerController` |
| Layer | Controller |
| Module | `owner` (Package: `org.springframework.samples.petclinic.owner`) |

## 1. Role

### OwnerController.findPaginatedForOwnersLastName()

This method performs the core pagination and search delegation for owner lookup by last-name prefix within the owner management flow. It receives the requested page number and the user-entered last name filter, then converts that UI request into a Spring Data `Pageable` request with a fixed page size of 5 records. The method does not perform any business filtering itself; instead, it acts as a controller-level routing and delegation point that forwards the search criteria to the repository layer. Its role in the larger system is to support the `/owners` search experience used by the owner search screen, where the result set may later be rendered as a single match, no matches, or a paginated list. There are no conditional branches in this method, so its behavior is deterministic: build pagination parameters and return the repository query result.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
START(["findPaginatedForOwnersLastName(page, lastname)"])
SET_PAGE_SIZE["Set pageSize to 5"]
BUILD_PAGEABLE["Create Pageable with PageRequest.of(page - 1, pageSize)"]
CALL_REPO["Call owners.findByLastNameStartingWith(lastname, pageable)"]
END_NODE(["Return Page<Owner>"])
START --> SET_PAGE_SIZE
SET_PAGE_SIZE --> BUILD_PAGEABLE
BUILD_PAGEABLE --> CALL_REPO
CALL_REPO --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `page` | `int` | Requested result page number from the owner search screen. It controls which slice of the matching owner list is retrieved, and is converted to zero-based indexing before querying the repository. |
| 2 | `lastname` | `String` | Last-name search prefix entered by the user. It is passed directly to the repository search so the system can return owners whose last names begin with the provided text. |

External state read by the method:
- `owners` repository instance field, which is used to execute the paginated search.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| R | `owners.findByLastNameStartingWith` | N/A | `Owner` | Reads a paginated set of owners whose last name begins with the supplied search text. |

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

| # | Caller (Screen/Batch) | Call Chain (Full Path to Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|----------------------------------|-------------------------------|
| 1 | Controller:OwnerController | `OwnerController.processFindForm` -> `OwnerController.findPaginatedForOwnersLastName` | `owners.findByLastNameStartingWith [R] Owner` |

Trace who calls this method and what this method ultimately calls.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Controller:OwnerController | `OwnerController.processFindForm` -> `OwnerController.findPaginatedForOwnersLastName` | `owners.findByLastNameStartingWith [R] Owner` |

## 6. Per-Branch Detail Blocks

Block 1 — SEQUENTIAL `(method entry)` (L130)

> Initializes the fixed pagination configuration used for the owner search.

| # | Type | Code |
|---|------|------|
| 1 | SET | `int pageSize = 5;` // fixed page size for owner search results |

Block 2 — SEQUENTIAL `(build pageable request)` (L131)

> Converts the requested page number into Spring Data's zero-based page request model.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Pageable pageable = PageRequest.of(page - 1, pageSize);` // create zero-based pageable request |

Block 3 — SEQUENTIAL `(delegate repository search)` (L132)

> Delegates the actual owner lookup to the repository layer using a last-name prefix filter.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `owners.findByLastNameStartingWith(lastname, pageable);` // query owners by last-name prefix and page request |
| 2 | RETURN | `return owners.findByLastNameStartingWith(lastname, pageable);` // return the paginated result set |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `Owner` | Business term | Pet owner domain entity representing a customer who can register pets in the clinic system. |
| `lastname` | Field / parameter | Owner last name search prefix entered by the user to filter owner records. |
| `page` | Field / parameter | One-based page number requested by the UI for paginated owner search results. |
| `pageSize` | Technical term | Fixed number of owner records shown per page; set to 5 in this method. |
| `Pageable` | Technical term | Spring Data pagination request object containing page number and page size. |
| `PageRequest` | Technical term | Spring Data factory for creating `Pageable` instances. |
| `Page<Owner>` | Technical term | Paginated container for owner search results, including content and paging metadata. |
| `findByLastNameStartingWith` | Repository method | Data access method that returns owners whose last names start with the supplied text. |
| `owners` | Repository | Owner repository used to execute the paginated search query. |
| `Controller` | Layer | Web layer component that handles HTTP requests and coordinates UI-facing business flow. |
| `processFindForm` | Controller method | Higher-level search handler that calls this pagination helper after normalizing input and deciding the response shape. |
