Whether it is correct strategy of processing of files with support of transactions is selected?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Whether it is correct strategy of processing of files with support of transactions is selected?

igilfanov
//controller
package org.commons

class FileUploadController {

    def FileUploadService
   
    def upload(){
           
        request.getMultiFileMap()['uploadedfiles[]'].each{file ->    
           FileUploadService.loading(file)
        }
               
        render(contentType: 'text/json') {
           success = true
        }
    }    
}

//service
package org.commons

import org.springframework.transaction.annotation.Transactional

class FileUploadService {

    static transactional = false

    public void loading(file){

        def rows = [:]

        try{

          //1. here read and check file contents and put rows in the map "rows"
         

          //2. if all is successful, then save the data
          saveRows(rows)

        }catch(ex){

          try{
              //register error in database  
          }catch(ex2){
             throw ex
   }

        }
    }

    @Transactional
    private void saveRows(rows) {
        //save rows in database
    }
}