home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 262,557 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: Spring Batch (2/2)   
   28 Mar 25 09:02:40   
   
   [continued from previous message]   
      
           
           
           
      
      
           
           
           
           
           
      
      
           
           
           
      
      
           
           
           
               
                   
               
           
      
      
   import java.lang.reflect.Method;   
      
   import dk.vajhoej.isam.IsamSource;   
      
   public class WriterSecondarySource {   
        private String primaryList; // name of list in primary source   
   containing records from secondary source   
        private IsamSource source; // secondary source   
        private Method primaryListGetter;   
        public String getPrimaryList() {   
            return primaryList;   
        }   
        public void setPrimaryList(String primaryList) {   
            this.primaryList = primaryList;   
        }   
        public IsamSource getSource() {   
            return source;   
        }   
        public void setSource(IsamSource source) {   
            this.source = source;   
        }   
        public Method getPrimaryListGetter() {   
            return primaryListGetter;   
        }   
        public void setPrimaryListGetter(Method primaryListGetter) {   
            this.primaryListGetter = primaryListGetter;   
        }   
   }   
      
   import java.lang.reflect.Method;   
   import java.util.List;   
      
   import org.springframework.batch.item.ExecutionContext;   
   import org.springframework.batch.item.support.AbstractItemStreamItemWriter;   
      
   import dk.vajhoej.isam.IsamException;   
   import dk.vajhoej.isam.IsamSource;   
      
   public class MultiIsamItemWriter extends   
   AbstractItemStreamItemWriter {   
        private IsamSource primarySource;   
        private Class type;   
        private List secondarySources;   
        public IsamSource getPrimarySource() {   
            return primarySource;   
        }   
        public void setPrimarySource(IsamSource primarySource) {   
            this.primarySource = primarySource;   
        }   
        public Class getType() {   
            return type;   
        }   
        public void setType(Class type) {   
            this.type = type;   
        }   
        public List getSecondarySources() {   
            return secondarySources;   
        }   
        public void setSecondarySources(List   
   secondarySources) {   
            this.secondarySources = secondarySources;   
        }   
        private Method getGetter(String fldnam) {   
            try {   
                return type.getMethod("get" + fldnam.substring(0,   
   1).toUpperCase() + fldnam.substring(1));   
            } catch (NoSuchMethodException e) {   
                throw new RuntimeException(e);   
            } catch (SecurityException e) {   
                throw new RuntimeException(e);   
            }   
        }   
        @Override   
        public void open(ExecutionContext ec) {   
            for(WriterSecondarySource src2 : secondarySources) {   
                src2.setPrimaryListGetter(getGetter(src2.getPrimaryList()));   
            }   
        }   
        @Override   
        public void write(List items) throws Exception {   
            for(T item : items) {   
                primarySource.create(item);   
                for(WriterSecondarySource src2 : secondarySources) {   
                    for(Object o :   
   (List)src2.getPrimaryListGetter().invoke(item) ) {   
                        src2.getSource().create(o);   
                    }   
                }   
            }   
        }   
        @Override   
        public void close() {   
            try {   
                primarySource.close();   
                for(WriterSecondarySource src2 : secondarySources) {   
                    src2.getSource().close();   
                }   
            } catch (IsamException e) {   
                throw new RuntimeException(e);   
            }   
        }   
   }   
      
      
           
           
           
      
      
           
           
      
      
           
           
           
      
      
           
           
           
               
                   
               
           
      
      
   Arne   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca