Changeset 424 for trunk/grails-app


Ignore:
Timestamp:
Mar 2, 2010, 5:26:05 PM (15 years ago)
Author:
gav
Message:

Add cleanUpGorm() to AssetCsvService.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/AssetCsvService.groovy

    r421 r424  
     1import grails.util.GrailsUtil
    12import au.com.bytecode.opencsv.CSVWriter
    23import au.com.bytecode.opencsv.CSVReader
     
    1213
    1314    def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib()
     15
     16    def sessionFactory
     17    def propertyInstanceMap = org.codehaus.groovy.grails.plugins.DomainClassGrailsPlugin.PROPERTY_INSTANCE_MAP
    1418
    1519    /**
     
    259263
    260264                } // while( nextColumn() )
     265
     266                if(lineNumber % 100 == 0)
     267                    cleanUpGorm()
    261268
    262269                nextLine()
     
    448455    }
    449456
     457    /**
     458    * This cleans up the hibernate session and a grails map.
     459    * For more info see: http://naleid.com/blog/2009/10/01/batch-import-performance-with-grails-and-mysql/
     460    * The hibernate session flush is normal for hibernate.
     461    * The map is apparently used by grails for domain object validation errors.
     462    * A starting point for clean up is every 100 objects.
     463    */
     464    def cleanUpGorm() {
     465        def session = sessionFactory.currentSession
     466        session.flush()
     467        session.clear()
     468        propertyInstanceMap.get().clear()
     469    }
     470
    450471} // end class
Note: See TracChangeset for help on using the changeset viewer.