View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.batch.service.impl;
17  
18  import java.util.List;
19  
20  import org.apache.log4j.Logger;
21  import org.kuali.ole.sys.batch.service.WrappedBatchExecutorService;
22  import org.kuali.ole.sys.batch.service.WrappingBatchService;
23  import org.springframework.transaction.annotation.Transactional;
24  
25  public class WrappedBatchExecutorServiceImpl implements WrappedBatchExecutorService {
26      private static final Logger LOG = Logger.getLogger(WrappedBatchExecutorServiceImpl.class);
27  
28      @Transactional
29      public boolean execute(List<WrappingBatchService> wrappingBatchServices, CustomBatchExecutor customBatchExecutor) {
30          boolean continueJob;
31          try {
32              for (WrappingBatchService wrappingBatchService : wrappingBatchServices) {
33                  wrappingBatchService.initialize();
34              }
35              continueJob = customBatchExecutor.execute();
36          }
37          finally {
38              for (WrappingBatchService wrappingBatchService : wrappingBatchServices) {
39                  try {
40                      wrappingBatchService.destroy();
41                  }
42                  catch (Exception e) {
43                      LOG.error("Caught exception while destroying service: " + wrappingBatchService.getClass(), e);
44                  }
45              }
46          }
47          return continueJob;
48      }
49  }