Record a prepare operation.

@param preparedOperation the prepared operation
3420
void recordPreparedOperation(final TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> preparedOperation) {
        recordPreparedTask(new ServerTaskExecutor.ServerPreparedResponse(preparedOperation));
    }
834034
public int prepare() throws ProtocolException, RollbackException, SeverePersistenceException, TransactionException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "prepare");

        // Check the current transaction state (use state lock to ensure we see the latest value)
        synchronized (_stateLock)
        {
            if (_state != TransactionState.STATE_ACTIVE)
            {
                ProtocolException pe = new ProtocolException("TRAN_PROTOCOL_ERROR_SIMS1001", new Object[]{});
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.event(this, tc, "Cannot prepare Transaction. Transaction is complete or completing!", pe);
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "prepare");
                throw pe;
            }

            // Transition our prepare sub-state immediately - before we call the callbacks
            _preCommitSubstate = TransactionState.STATE_PREPARING;
        }

        // PK81848
        // From this point on, we must perform a rollback if we fail to complete the prepare,
        // or another thread requests a deferred rollback
        try
        {
            // Call beforeCompletion on MP callback
            for (int i = 0; i < _callbacks.size(); i++)
            {
                TransactionCallback callback = (TransactionCallback) _callbacks.get(i);
                callback.beforeCompletion(this);
            }

            // Do we have work to do?
            if (_workList != null)
            {
                _workList.preCommit(this);

                synchronized (_stateLock)
                {
                    // Need to change the overalll state after we have 
                    // called the callbacks and preCommitted 
                    // the workList as they may trigger
                    // an addWork call to add work to the
                    // transaction.
                    _state = TransactionState.STATE_PREPARING;
                }

                // The transaction is about to be in a state where any rollback must
                // update the database.  We cannot narrow the window any more than this
                _rollbackChanges = true;
                
                // Perform the prepare
                _persistence.prepare(this);

                // State check/change must be performed holding the state lock
                synchronized (_stateLock)
                {
                    // Another thread may have have received a rollback, while we were
                    // performing our prepare - if the database was extremely slow to respond
                    if (_preCommitSubstate == TransactionState.STATE_ROLLBACK_DEFERRED)
                    {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.event(this, tc, "Deferred rollback requested during prepare for TranId: "+_ptid);

                        // Throw an exception to trigger rollback processing.
                        throw new DeferredRollbackException();
                    }
                    else
                    {
                        _state = _preCommitSubstate = TransactionState.STATE_PREPARED;
                    }
                }                
            }
            else
            {
                // State change must be performed holding the state lock
                synchronized (_stateLock)
                {
                    // Defect 301480
                    // We don't have any work in our workList so in theory we should be
                    // able to vote READ_ONLY at this point. However in a particular case
                    // (Best Effort message being sent off server) a call back in an empty
                    // XAResource is used to trigger work on a remote server. In this case 
                    // we need beforeCompletion AND afterCompletion to be called at the 
                    // CORRECT time during transaction completion to ensure that the off 
                    // server work stays part of the XA transaction and gets informed of 
                    // the correct completion direction.
                    _state = _preCommitSubstate = TransactionState.STATE_PREPARED;
                }
            }
        }
        catch (SeverePersistenceException spe)
        {
            // SPE exceptions are handled with an RMFAIL return code by the caller,
            // so unlike all other types of exception no attempt is made here to
            // rollback the transaction. However, we report a local error - so
            // the whole JVM will be coming down with a few minutes.
            com.ibm.ws.ffdc.FFDCFilter.processException(spe, "com.ibm.ws.sib.msgstore.transactions.XidParticipant.prepare", "1:420:1.73", this);

            // As we have thrown a severe exception we need to inform
            // the ME that this instance is no longer able to continue.
            if (_ms != null)
            {
                _ms.reportLocalError();
            }
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.event(this, tc, "Unrecoverable persistence exception caught during prepare phase of transaction!", spe);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "prepare", spe);
            throw spe;
        }
        // Catch and handle all exceptions but allow 
        // Errors to filter up without interference
        catch (Exception e)
        {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ws.sib.msgstore.transactions.XidParticipant.prepare", "1:436:1.73", this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.event(this, tc, "Transaction will roll-back due to Exception in prepare!", e);

            // Update our prepare state before calling rollback. If we are responding
            // to a deferred rollback request this will have no affect but if this is 
            // due to some other failure it will lock out any other attempts to rollback
            synchronized (_stateLock)
            {
                _preCommitSubstate = TransactionState.STATE_ROLLINGBACK;
            }

            // An error has occurred but we are able to keep the ME
            // going so we just need to clean up this transaction.
            try
            {
                // When we throw our RollbackException the TM is
                // going to assume we are complete so we need to 
                // ensure we are rolled-back.
                // 
                // PK81848.2
                // We need to pass "true" in order to turn off the
                // state checking which should block other threads 
                // from attempting a rollback when we are in the 
                // middle of internal rollback processing.
                rollback(true);
            }
            // Catch and handle all exceptions but allow 
            // Errors to filter up without interference
            catch (Exception e2)
            {
                com.ibm.ws.ffdc.FFDCFilter.processException(e2, "com.ibm.ws.sib.msgstore.transactions.XIDParticipant.prepare", "1:466:1.73", this);
                
                // This is a problem because we now must RMFAIL this prepare call as we do not know the outcome.
                // Transition to rollback expected state now even if we are in deferred rollback.  This is the
                // only thing we can do (problem is we said XA_OK to roll back in deferred case and now we
                // cannot honour it).  This case may still leave indoubts.
                synchronized(_stateLock)
                {
                    _state = _preCommitSubstate = TransactionState.STATE_ROLLBACK_EXPECTED;
                }
                
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "prepare", "Exception caught rolling-back transaction after preCommit failure! " + e2);
                throw new TransactionException(e2);
            }

            // Mark ourselves as complete, regardless of the outcome of the attempt to rollback.
            synchronized (_stateLock)
            {
                _state = _preCommitSubstate = TransactionState.STATE_ROLLEDBACK;
            }

            // Wrap any persistence exception, or an unexpected exception, in a rollback exception.
            // This informs the TM that they can forget about this transaction.
            RollbackException re = new RollbackException("COMPLETION_EXCEPTION_SIMS1002", new Object[]{e}, e);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "prepare", re);
            throw re;
        }

        // Non-exception return path always returns XA_OK
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "prepare", "return="+XAResource.XA_OK);
        return XAResource.XA_OK;
    }
316789
protected <V> V execute (Operation<V> op)
        throws PersistenceException
    {
        return execute(op, true, true);
    }
165423
public void setOperations(java.util.Collection<String> operations) {
        if (operations == null) {
            this.operations = null;
            return;
        }

        this.operations = new com.amazonaws.internal.SdkInternalList<String>(operations);
    }
834745
protected void handleOperation(Map<String, String> map, String operation) throws Exception {
        int index=operation.indexOf('.');
        if(index == -1)
            throw new IllegalArgumentException("operation " + operation + " is missing the protocol name");
        String prot_name=operation.substring(0, index);
        Protocol prot=ch.getProtocolStack().findProtocol(prot_name);
        if(prot == null) {
            log.error("protocol %s not found", prot_name);
            return; // less drastic than throwing an exception...
        }

        int args_index=operation.indexOf('[');
        String method_name;
        if(args_index != -1)
            method_name=operation.substring(index +1, args_index).trim();
        else
            method_name=operation.substring(index+1).trim();

        String[] args=null;
        if(args_index != -1) {
            int end_index=operation.indexOf(']');
            if(end_index == -1)
                throw new IllegalArgumentException("] not found");
            List<String> str_args=Util.parseCommaDelimitedStrings(operation.substring(args_index + 1, end_index));
            Object[] strings=str_args.toArray();
            args=new String[strings.length];
            for(int i=0; i < strings.length; i++)
                args[i]=(String)strings[i];
        }

        Method method=findMethod(prot, method_name, args);
        MethodCall call=new MethodCall(method);
        Object[] converted_args=null;
        if(args != null) {
            converted_args=new Object[args.length];
            Class<?>[] types=method.getParameterTypes();
            for(int i=0; i < args.length; i++)
                converted_args[i]=Util.convert(args[i], types[i]);
        }
        Object retval=call.invoke(prot, converted_args);
        if(retval != null)
            map.put(prot_name + "." + method_name, retval.toString());
    }
1093944
@Override
    public void planOperation(Runnable operation) {
        operations.add(operation);

        if (operation instanceof AbstractOperation) {
            ExecutionEntity execution = ((AbstractOperation) operation).getExecution();
            if (execution != null) {
                commandContext.addInvolvedExecution(execution);
            }
        }

        logger.debug("Operation {} added to agenda", operation.getClass());
    }
1174644
@SuppressWarnings("unchecked")
    private void prepareKarafRbacInvocations(String fullName, Map<String, Object> mBeanInfo,
                                             Map<String, List<String>> queryForMBeans,
                                             Map<String, List<String>> queryForMBeanOperations) {
        queryForMBeans.put(fullName, new ArrayList<>());
        List<String> operations = operations((Map<String, Object>) mBeanInfo.get("op"));
        // prepare opByString for MBeainInfo
        Map<String, Map<String, Object>> opByString = new HashMap<>();
        mBeanInfo.put("opByString", opByString);
        if (operations.isEmpty()) {
            return;
        }

        queryForMBeanOperations.put(fullName, operations);
        for (String op : operations) {
            // ! no need to copy relevant map for "op['opname']" - hawtio uses only 'canInvoke' property
            opByString.put(op, new HashMap<>());
        }
    }
211547
public void setPatchOperations(java.util.Collection<PatchOperation> patchOperations) {
        if (patchOperations == null) {
            this.patchOperations = null;
            return;
        }

        this.patchOperations = new java.util.ArrayList<PatchOperation>(patchOperations);
    }
535883
public <T> CompletableFuture<T> submit(Operation<T> operation) {
    if (operation instanceof Query) {
      return submit((Query<T>) operation);
    } else if (operation instanceof Command) {
      return submit((Command<T>) operation);
    } else {
      throw new UnsupportedOperationException("unknown operation type: " + operation.getClass());
    }
  }
1094857
async def prepare(self):
        

        if not self._parent.is_active:
            raise exc.InvalidRequestError("This transaction is inactive")
        await self._connection._prepare_twophase_impl(self._xid)
        self._is_prepared = True
170783
public synchronized void preparing() {
      if (trace) {
         log.tracef("[%s] Current status is %s, setting status to: PREPARING", globalTransaction.globalId(),
                    transactionState);
      }
      transactionState.add(State.PREPARING);
   }
1053029
public synchronized Vote prepare() throws SystemException, HeuristicMixedException, HeuristicHazardException, RollbackException
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "prepare", this);

        Vote result = Vote.VoteRollback;

        // If there is no associated transaction, raise an execption which should
        // cause the superior transaction to be rolled back.  We should only lose
        // the transaction if we do a destroy, eg on a rollback, or previous prepare
        // vote, etc. in which case we should never be calling prepare again.
        if (_transaction == null)
        {
            final SystemException se = new SystemException(MinorCode.NO_COORDINATOR);

            FFDCFilter.processException(se, "com.ibm.tx.remote.TransactionWrapper.prepare", "157", this);
            Tr.error(tc, "WTRN0001_ERR_INT_ERROR", new Object[] { "prepare", "com.ibm.ws.Transaction.JTS.TransactionWrapper" });
            destroy();
            if (tc.isEntryEnabled())
                Tr.exit(tc, "prepare", se);
            throw se;
        }

        // Ensure timeout cannot rollback the underlying transaction
        ((DistributableTransaction) _transaction).addAssociation();

        if (_transaction.getTransactionState().getState() == TransactionState.STATE_ACTIVE) {
            try {
                // Resume the transaction created from the incoming
                // request so that it is installed on the thread.
                ((EmbeddableTranManagerSet) TransactionManagerFactory.getTransactionManager()).resume(_transaction);

                // Get the TransactionImpl's vote.
                // If the TransactionImpl throws HeuristicMixed, then rethrow.
                // internalPrepare checks the tx state
                final int state = _transaction.internalPrepare();
                switch (state) {
                    case TransactionState.STATE_PREPARED:
                        // Start the in-doubt timer in case we never get a commit/rollback
                        EmbeddableTimeoutManager.setTimeout(_transaction, EmbeddableTimeoutManager.IN_DOUBT_TIMEOUT, _retryWait);
                        result = Vote.VoteCommit;
                        break;
                    case TransactionState.STATE_ROLLED_BACK: // one phase opt
                        result = Vote.VoteRollback;
                        _transaction.notifyCompletion();
                        break;
                    case TransactionState.STATE_COMMITTED:
                        result = Vote.VoteReadOnly;
                        _transaction.notifyCompletion();
                        break;
                    // If the TransactionImpl has voted to roll the transaction back, then this
                    // CoordinatorResourceImpl will not be called again.  Ensure that the
                    // TransactionImpl has rolled back.
                    case TransactionState.STATE_ROLLING_BACK:
                    default:
                        _transaction.internalRollback();
                        result = Vote.VoteRollback;
                        _transaction.notifyCompletion();
                        break;
                }
            } catch (HeuristicMixedException hme) {
                // No FFDC code needed.
                // This exception should not be raised by internalPrepare for a subordinate
                // but may be raised by internalRollback 

                // must rollback any prepared resources ...
                try {
                    _transaction.internalRollback();
                } catch (Throwable t) {
                    FFDCFilter.processException(t, "com.ibm.tx.remote.TransactionWrapper.prepare", "228", this);
                    // swallow any exceptions ...
                }

                ((DistributableTransaction) _transaction).removeAssociation();

                final HeuristicMixedException hm = new HeuristicMixedException();
                if (tc.isEntryEnabled())
                    Tr.exit(tc, "prepare", hm);
                throw hm;
            } catch (HeuristicHazardException hhe) {
                // No FFDC code needed.
                // This exception should not be raised by internalPrepare for a subordinate
                // but may be raised by internalRollback 

                // must rollback any prepared resources ...
                try {
                    _transaction.internalRollback();
                } catch (Throwable t) {
                    FFDCFilter.processException(t, "com.ibm.tx.remote.TransactionWrapper.prepare", "250", this);
                    // swallow any exceptions ...
                }

                ((DistributableTransaction) _transaction).removeAssociation();

                final HeuristicHazardException hh = new HeuristicHazardException();
                if (tc.isEntryEnabled())
                    Tr.exit(tc, "prepare", hh);
                throw hh;
            } catch (Throwable t) { // IllegalState or javax.transaction.SystemException
                FFDCFilter.processException(t, "com.ibm.tx.remote.TransactionWrapper.prepare", "241", this);
                result = Vote.VoteRollback;
                _transaction.notifyCompletion();
            } finally {
                // suspend any context that is still on the thread
                // NB we may have called notifyCompletion at this point,
                // and suspend calls notifyUOWCallbacks, so if the tx is
                // still on the thread, there could be a problem.
                ((EmbeddableTranManagerSet) TransactionManagerFactory.getTransactionManager()).suspend();
            }
        } else { // probably timed out
            result = Vote.VoteRollback;
        }

        ((DistributableTransaction) _transaction).removeAssociation();

        if (tc.isEntryEnabled())
            Tr.exit(tc, "prepare", result);
        return result;
    }
1149974
public void setOperation(String operation) throws ApplicationException {
	if (StringUtil.isEmpty(operation)) return;
	operation = operation.toLowerCase().trim();
	if (!operation.equals("httprequest")) throw new ApplicationException("attribute operation must have the value [HTTPRequest]");
    }
1037177
def __prepare_record(self, record, enabled_fields):
        """"""
        message = record.getMessage()
        if hasattr(record, 'prefix'):
            message = "{}{}".format((str(record.prefix) + ' ') if record.prefix else '', message)

        obj = {
            'name': record.name,
            'asctime': self.formatTime(record, self.datefmt),
            'created': record.created,
            'msecs': record.msecs,
            'relativeCreated': record.relativeCreated,
            'levelno': record.levelno,
            'levelname': self._level_names[record.levelname],
            'thread': record.thread,
            'threadName': record.threadName,
            'process': record.process,
            'pathname': record.pathname,
            'filename': record.filename,
            'module': record.module,
            'lineno': record.lineno,
            'funcName': record.funcName,
            'message': message,
            'exception': record.exc_info[0].__name__ if record.exc_info else None,
            'stacktrace': record.exc_text,
        }

        if not isinstance(enabled_fields, list):
            enabled_fields = [str(enabled_fields)]

        ef = {}
        for item in enabled_fields:
            if not isinstance(item, (str, tuple)):
                continue
            if not isinstance(item, tuple):
                ef[item] = item
            else:
                ef[item[0]] = item[1]

        result = {}
        for key, val in obj.items():
            if key in ef:
                result[ef[key]] = val

        return result
661174
public CompensatingTransactionOperationExecutor recordOperation(
            Object[] args) {
        if (args == null || args.length != 3) {
            throw new IllegalArgumentException(
                    "Invalid arguments for bind operation");
        }
        Name dn = LdapTransactionUtils.getFirstArgumentAsName(args);
        Object object = args[1];
        Attributes attributes = null;
        if (args[2] != null && !(args[2] instanceof Attributes)) {
            throw new IllegalArgumentException(
                    "Invalid third argument to bind operation");
        } else if (args[2] != null) {
            attributes = (Attributes) args[2];
        }

        Name temporaryName = renamingStrategy.getTemporaryName(dn);

        return new RebindOperationExecutor(ldapOperations, dn, temporaryName,
                object, attributes);
    }
890736
public static void log(Category category, String prepared, String sql) {
    if (logger != null && isCategoryOk(category)) {
      doLog(-1, category, prepared, sql);
    }
  }
1101404
protected void prepareQuery(Query queryObject) {
		if (isCacheQueries()) {
			queryObject.setCacheable(true);
			if (getQueryCacheRegion() != null) {
				queryObject.setCacheRegion(getQueryCacheRegion());
			}
		}
		if (getFetchSize() > 0) {
			queryObject.setFetchSize(getFetchSize());
		}
		if (getMaxResults() > 0) {
			queryObject.setMaxResults(getMaxResults());
		}

		if (getFirstResult() > 0) {
			queryObject.setFirstResult(getFirstResult());
		}

	}