Am I on the right track?
Well, for starters, I really would insist on using database functionality for this. It's quite likely the database will handle this better, and definitely faster than if you roll it manually from the client.
If that's not an option, an alternative might be to write a stored procedure that implements the cascading deletion, in order to prevent the many server round trips that might incur otherwise.
If that's not an option either, then yes, your approach is logically correct, but make sure that you're not going to produce an N+1 problem. The most efficient solution is to recursively go to the leaf child tables first, delete all the relevant rows there in a single bulk delete (semi-joining the entire path up to the original table's deleted rows) and then recurse up the tree. For example:
A
/ \
/ \
B C
/ \
/ \
D E
If you want to emulate a statement like (hypothetical syntax):
DELETE CASCADE FROM a WHERE a_id IN (1, 2, 3)
Then, you should run:
DELETE FROM e WHERE c_id IN (
SELECT c_id FROM c WHERE a_id IN (1, 2, 3)
);
DELETE FROM e WHERE c_id IN (
SELECT c_id FROM c WHERE a_id IN (1, 2, 3)
);
DELETE FROM c WHERE a_id IN (1, 2, 3);
DELETE FROM a WHERE a_id IN (1, 2, 3);
jOOQ will definitely help you generate these dynamically.
Is this functionality already present in JOOQ?
No, but it would be a nice addition: https://github.com/jOOQ/jOOQ/issues/7367