use of com.servoy.j2db.persistence.ITransactable in project servoy-client by Servoy.
the class PKDataSet method pksToBeUpdated.
private void pksToBeUpdated() {
if (transactionListener == null && pksAndRecordsHolder != null && pksAndRecordsHolder.hasDynamicPlaceholder()) {
// check if I am within a transaction
GlobalTransaction globalTransaction = pksAndRecordsHolder.getFoundSet().getFoundSetManager().getGlobalTransaction();
if (globalTransaction != null) {
// add a listener for rollback to restore pks on rollback so that query returns deleted records
DynamicPkValuesArray dynArray = getDynamicPkValuesArray();
if (dynArray != null) {
final DynamicPkValuesArray pksBeforeTransaction = dynArray.clone();
globalTransaction.addTransactionEndListener(transactionListener = new ITransactable() {
public void processPostRollBack() {
// restore old pks from before transaction, so that pks deleted in the transaction are still found
if (pksAndRecordsHolder.hasDynamicPlaceholder()) {
// query still has the pk set condition, set the condition back to the pk set from before the transaction
pksAndRecordsHolder.getQuerySelectForReading().acceptVisitor(new PlaceHolderSetter(new TablePlaceholderKey(pksAndRecordsHolder.getQuerySelectForReading().getTable(), SQLGenerator.PLACEHOLDER_FOUNDSET_PKS), pksBeforeTransaction));
}
transactionListener = null;
}
public void processPostCommit() {
transactionListener = null;
}
});
}
}
}
}
use of com.servoy.j2db.persistence.ITransactable in project servoy-client by Servoy.
the class GlobalTransaction method fireTransactionEnded.
private void fireTransactionEnded(boolean committed) {
ITransactable[] listeners = null;
synchronized (transactionEndListeners) {
if (transactionEndListeners.size() > 0) {
listeners = transactionEndListeners.toArray(new ITransactable[transactionEndListeners.size()]);
transactionEndListeners.clear();
}
}
if (listeners != null) {
for (ITransactable listener : listeners) {
if (committed) {
listener.processPostCommit();
} else {
listener.processPostRollBack();
}
}
}
}
Aggregations