Repository navigation
Description
JobRepository/JobExplorer/JobInstanceDao/StepExecutionDao expose count methods that are documented (or expected, per #5252) to throw NoSuchJobException / NoSuchStepException when the given identifier is unknown. None of these layers has access to the registry of known jobs (JobRegistry) or to a job's declared step topology. They can only see persisted execution history. That makes "is this identifier unknown" unanswerable at this layer without producing false positives on the very common case of "valid identifier, simply never executed yet".
The existing JobInstanceDao implementations already get this wrong as they all infer "unknown job" purely from prior instances. A job that is fully configured but has never been launched would incorrectly throw a NoSuchJobException . JobInstanceDao#getJobInstanceCount has no internal callers at all in the codebase besides the DAO/JobExplorer delegation chain and tests.
For StepExecutionDao#getStepExecutionCount, no real caller needs the identifier-existence distinction. Both internal callers treat "unknown" and "zero" identically:
SimpleStepHandler#shouldStart: fix ImproveSimpleStepHandler::shouldStartto handle NoSuchStepException correctly #5257 catchesNoSuchStepExceptionand treats it as 0.JobFlowExecutor#isStepRestart: catchesNoSuchStepExceptionand returns false.
The only place that can validate existence correctly needs a registry (which is at the job operator level), which this layer doesn't have. This confirms that existence validation is a JobOperator (start/restart-time) concern, not a JobRepository/DAO concern.
The current design also reveals a package dependency cycle. NoSuchJobException is defined in org.springframework.batch.core.launch, yet is imported and thrown from org.springframework.batch.core.repository (JobRepository, JobInstanceDao, etc). Meanwhile org.springframework.batch.core.launch.support correctly depends on repository (operators sit on top of persistence). The result is a repository ↔ launch package cycle. The same pattern exists for NoSuchStepException (defined in org.springframework.batch.core.step package, used in repository package, while step depends on repository).
The goal here is to remove the throws NoSuchJobException / throws NoSuchStepException contract from these repository/DAO-level count methods and keep existence validation exclusively at the JobOperator layer where the registry is available. This should be done in a deprecate-then-remove cycle:
- introduce parallel methods without the checked exception (
countJobInstances,countStepExecutions, same naming as the DAOs) - deprecate the current ones in 6.1 for removal in 7.0
- migrate internal call sites to use the new methods (no functional breaking changes)
Related issues:
Activity
Deprecate count methods that throw NoSuchJobException/NoSuchStepExcep…