davidmoten / davidmoten/rxjava2-jdbc

Having a tough time with Tx

Open
#25 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
394
Forks
41
Avg merge
2m
Merged PRs (30d)
1

Description

Hello there!

I feel that I'm over complicating over, possibly overkilling it... but I need the following operations to be within a transaction:

1. Update parent resource
2. Delete orphan child resource
3. Update child resource
4. Insert new child resource
5. Fetch just updated parent resource
6. Fetch all child resources

My code looks like this so far...
```
try (Database database = Database.fromBlocking(dataSource)) {
return database.update(updateParentResourceQuery)
.parameter()
.transacted()
.counts()
.flatMap(tx -> {
return tx.update(deleteChildResource)
.parameter()
.counts()
.flatMap(tx2 -> {
TransactedUpdateBuilder createChildResource = tx2.update(createChildResourceQuery);
childResourcesToBeCreated.forEach(entityLanguage -> createChildResource
.parameter());
return createChildResource
.counts()
.flatMap(tx3 -> {
TransactedUpdateBuilder updateChildResource = tx3.update(updateChildResourceQuery);
childResourcesToBeUpdated.forEach(
entityLanguage -> updateChildResource
.parameter());
return updateChildResource
.counts()
.flatMap(tx4 -> {
return tx4.select(selectParentResource)
.parameter()
.transactedValuesOnly()
.get(new Mapper())
.flatMap(tx5 -> {
return tx5
.select(selectAllChildResources)
.parameter()
.valuesOnly()
.get(new Mapper())
.flatMap(childResources -> {
ParentResource parentResource = tx5.value();
parentResource.setChildResources(childResources);
return Flowable.just(parentResource);
});
});
});
});
});
});
}
```

It doesn't work. When I do the parent update and fetch it back it works, but when I start chaining the operations everything goes haywire.

Any input will be much much appreciated!

Thank you very much for your time!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.