1 24 package org.riotfamily.riot.hibernate.support; 25 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.riotfamily.riot.job.Job; 30 import org.riotfamily.riot.job.JobContext; 31 import org.riotfamily.riot.job.context.CommonsLogginJobContext; 32 import org.springframework.beans.factory.InitializingBean; 33 import org.springframework.transaction.PlatformTransactionManager; 34 import org.springframework.transaction.TransactionStatus; 35 import org.springframework.transaction.support.TransactionCallback; 36 import org.springframework.transaction.support.TransactionTemplate; 37 import org.springframework.util.Assert; 38 39 public class SetupJobs implements InitializingBean { 40 41 private List jobs; 42 43 private PlatformTransactionManager transactionManager; 44 45 public void setTransactionManager(PlatformTransactionManager transactionManager) { 46 this.transactionManager = transactionManager; 47 } 48 49 public void setJobs(List jobs) { 50 this.jobs = jobs; 51 } 52 53 public void afterPropertiesSet() throws Exception { 54 Assert.notNull(jobs, "Jobs must not be null"); 55 56 if (transactionManager != null) { 57 new TransactionTemplate(transactionManager).execute(new TransactionCallback() { 58 public Object doInTransaction(TransactionStatus status) { 59 executeJobs(); 60 return null; 61 } 62 }); 63 } 64 else { 65 executeJobs(); 66 } 67 68 } 69 70 protected void executeJobs() { 71 JobContext context = new CommonsLogginJobContext(); 72 Iterator it = jobs.iterator(); 73 while (it.hasNext()) { 74 Job job = (Job) it.next(); 75 job.execute(context); 76 } 77 } 78 79 } 80 | Popular Tags |