I tried a db trigger fired on db commit (when all cayenne data is flushed to
db), but a problem arise if there is some db exception: persistent objects stay
"commited" because commitChanges changes the persistenceState before db commit,
It is desirable that persistenceState remains o returns to the value before
commitChanges in case of rollback. This behavior works well if there is a db
exception during commitChanges (while cayenne is flushing persistent objects to
db, like a not null) but not when a db exception raise between cayenne flush
and db commit.
Atte. Juan Manuel Díaz Lara
On Tuesday, March 6, 2018, 9:46:30 AM CST, Maik Musall
<[email protected]> wrote:
Hi Juan,
couldn't you do this more easily and reliably with a db trigger?
Maik
> Am 06.03.2018 um 16:11 schrieb Juan Manuel Diaz Lara
> <[email protected]>:
>
> Is there any way to call a stored procedure as part of commitChanges ?
> I would like to call a stored procedure after flushing my persistent objects
> but before the real db commit, for instance, to make some process on the db
> as part of committing my objects, but transactionally.
>
> performInTransaction(..) { commitChanges(); //Only flush to db, no commit,
> no in memory accounting of commit (no modifications to persitenctState)
> procedureCall.call(..); //Call a SP, save db transaction, can post-process
>data, and if it throws exception we can rollback db and persistentState stays
>the same before commitChanges
> }
> I am now om 4.0.M5.
>
> In a previous version (I do not remember which), I made some hack to replace
> DataDomain and other classes to allow to differ the in memory accounting of
> persistent objects until the db commit is done and allow call a SP after
> commitChanges() in the same db commit, I made a module to install my hacks,
> but it is not working now on M5, maybe new rules to replace cayenne services:
>
> public class ServerModuleWithPostCommitActions implements
> org.apache.cayenne.di.Module {
>
> @Override
> public void configure(Binder binder) {
>
>
>binder.bindList(Constants.SERVER_DOMAIN_FILTERS_LIST).add(PCATransactionFilter.class);
>
>
>binder.bind(TransactionFactory.class).to(TransactionWithPostCommitActionsFactory.class);
>
> binder.bind(DataDomain.class).toProvider(PCADataDomainProvider.class);
>
>
>binder.bind(ObjectContextFactory.class).to(PCADataContextFactory.class);
>
> }
> }
>
> This worked, but it was not a clear solution. specifically
> PCADataDomainProviderPCA is never called.
> Thanks.
>
> Atte. Juan Manuel Díaz Lara