@Override
    public StepThreadExecutionEntity createPartitionStepExecutionOnRestartFromPreviousStepInstance(final long jobExecutionId, final StepThreadInstanceEntity stepThreadInstance,
                                                                                                   final boolean isRemoteDispatch) throws NoSuchJobExecutionException {
        EntityManager em = getPsu().createEntityManager();
        try {
            StepThreadExecutionEntity stepExecution = new TranRequest<StepThreadExecutionEntity>(em) {
                @Override
                public StepThreadExecutionEntity call() {

                    // 1. Find related objects
                    JobExecutionEntity newJobExecution = getJobExecution(jobExecutionId);
                    StepThreadExecutionEntity lastStepExecution = stepThreadInstance.getLatestStepThreadExecution();

                    TypedQuery<TopLevelStepExecutionEntity> query = entityMgr.createNamedQuery(TopLevelStepExecutionEntity.GET_TOP_LEVEL_STEP_EXECUTION_BY_JOB_EXEC_AND_STEP_NAME,
                                                                                               TopLevelStepExecutionEntity.class);
                    query.setParameter("jobExecId", jobExecutionId);
                    query.setParameter("stepName", stepThreadInstance.getStepName());
                    // getSingleResult() validates that there is only one match
                    final TopLevelStepExecutionEntity topLevelStepExecution = query.getSingleResult();

                    // 2. Construct and initalize new entity instances
                    StepThreadExecutionEntity newStepExecution = new StepThreadExecutionEntity(newJobExecution, stepThreadInstance.getStepName(), stepThreadInstance.getPartitionNumber());
                    newStepExecution.setPersistentUserDataBytes(lastStepExecution.getPersistentUserDataBytes());

                    // 3. Update the relationships that didn't get updated in constructors

                    // 3a. Reverting to the safety of known-working, trying to do this drags in some
                    // extra considerations, which we'll have to come back to later (and we can since it
                    // shouldn't affect the table structure).
                    stepThreadInstance.setLatestStepThreadExecution(newStepExecution);
//					newJobExecution.getStepThreadExecutions().add(newStepExecution);
                    //topLevelStepExecution.getTopLevelAndPartitionStepExecutions().add(newStepExecution);
                    newStepExecution.setTopLevelStepExecution(topLevelStepExecution);
                    /*
                     * 222050 - Backout 205106
                     * RemotablePartitionEntity remotablePartition = null;
                     * if (isRemoteDispatch) {
                     * RemotablePartitionKey remotablePartitionKey = new RemotablePartitionKey(newJobExecution.getExecutionId(), stepThreadInstance.getStepName(),
                     * stepThreadInstance.getPartitionNumber());
                     * remotablePartition = entityMgr.find(RemotablePartitionEntity.class, remotablePartitionKey);
                     *
                     * //It can be null because if the partition dispatcher is older version, there won't be any remotable partition
                     * if (remotablePartition != null) {
                     * remotablePartition.setStepExecution(newStepExecution);
                     * }
                     * }
                     */
                    entityMgr.persist(newStepExecution);
                    entityMgr.merge(stepThreadInstance);
                    /*
                     * 222050 - Backout 205106
                     * if (isRemoteDispatch && remotablePartition != null) {
                     * entityMgr.persist(remotablePartition);
                     * }
                     */

                    return newStepExecution;
                }
            }.runInNewOrExistingGlobalTran();

            IdentifierValidator.validatePersistedStepExecution(stepExecution);

            return stepExecution;

        } finally {
            em.close();
        }
    }
@ Override public StepThreadExecutionEntity createPartitionStepExecutionOnRestartFromPreviousStepInstance ( final long jobExecutionId , final StepThreadInstanceEntity stepThreadInstance , final boolean isRemoteDispatch ) throws NoSuchJobExecutionException { EntityManager em = getPsu ( ) . createEntityManager ( ) ; try { StepThreadExecutionEntity stepExecution = new TranRequest < StepThreadExecutionEntity > ( em ) { @ Override public StepThreadExecutionEntity call ( ) { JobExecutionEntity newJobExecution = getJobExecution ( jobExecutionId ) ; StepThreadExecutionEntity lastStepExecution = stepThreadInstance . getLatestStepThreadExecution ( ) ; TypedQuery < TopLevelStepExecutionEntity > query = entityMgr . createNamedQuery ( TopLevelStepExecutionEntity . GET_TOP_LEVEL_STEP_EXECUTION_BY_JOB_EXEC_AND_STEP_NAME , TopLevelStepExecutionEntity . class ) ; query . setParameter ( "jobExecId" , jobExecutionId ) ; query . setParameter ( "stepName" , stepThreadInstance . getStepName ( ) ) ; final TopLevelStepExecutionEntity topLevelStepExecution = query . getSingleResult ( ) ; StepThreadExecutionEntity newStepExecution = new StepThreadExecutionEntity ( newJobExecution , stepThreadInstance . getStepName ( ) , stepThreadInstance . getPartitionNumber ( ) ) ; newStepExecution . setPersistentUserDataBytes ( lastStepExecution . getPersistentUserDataBytes ( ) ) ; stepThreadInstance . setLatestStepThreadExecution ( newStepExecution ) ; newStepExecution . setTopLevelStepExecution ( topLevelStepExecution ) ; entityMgr . persist ( newStepExecution ) ; entityMgr . merge ( stepThreadInstance ) ; return newStepExecution ; } } . runInNewOrExistingGlobalTran ( ) ; IdentifierValidator . validatePersistedStepExecution ( stepExecution ) ; return stepExecution ; } finally { em . close ( ) ; } }
Needs to:

1. create new stepthreadexec id, in STARTING state 2. copy over persistent
userdata to new step exec 3. point step thread instance to latest
execution


@param instanceKey
@return new step thread execution