Search in sources :

Example 1 with PlaceHolderSetter

use of com.servoy.j2db.query.AbstractBaseQuery.PlaceHolderSetter in project servoy-client by Servoy.

the class SetCondition method acceptVisitor.

public void acceptVisitor(IVisitor visitor) {
    keys = AbstractBaseQuery.acceptVisitor(keys, visitor);
    values = AbstractBaseQuery.acceptVisitor(values, visitor);
    if (values instanceof Placeholder && visitor instanceof PlaceHolderSetter) {
        PlaceHolderSetter phs = (PlaceHolderSetter) visitor;
        Placeholder ph = (Placeholder) values;
        if (ph.getKey().equals(phs.getKey())) {
            ph.setValue(validateValues(keys, phs.getValue()));
        }
    }
}
Also used : PlaceHolderSetter(com.servoy.j2db.query.AbstractBaseQuery.PlaceHolderSetter)

Example 2 with PlaceHolderSetter

use of com.servoy.j2db.query.AbstractBaseQuery.PlaceHolderSetter 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;
                    }
                });
            }
        }
    }
}
Also used : ITransactable(com.servoy.j2db.persistence.ITransactable) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) PlaceHolderSetter(com.servoy.j2db.query.AbstractBaseQuery.PlaceHolderSetter)

Aggregations

PlaceHolderSetter (com.servoy.j2db.query.AbstractBaseQuery.PlaceHolderSetter)2 ITransactable (com.servoy.j2db.persistence.ITransactable)1 TablePlaceholderKey (com.servoy.j2db.query.TablePlaceholderKey)1