Closure doWithSpring()

in src/main/groovy/quartz/QuartzGrailsPlugin.groovy [56:114]


    Closure doWithSpring() {

                { ->
            Properties properties = loadQuartzProperties()


            boolean hasHibernate = hasHibernate(manager)
            def hasJdbcStore = properties['org.quartz.jdbcStore']?.toBoolean()
            if (hasJdbcStore==null) {
                hasJdbcStore = true
            }

            def pluginEnabled = properties['org.quartz.pluginEnabled']?.toBoolean()
            if (pluginEnabled==null) {
                pluginEnabled = true
            }

            if (pluginEnabled) {
                def purgeTables = properties['org.quartz.purgeQuartzTablesOnStartup']?.toBoolean()

                if (purgeTables==null) {
                    purgeTables = false
                }

                if (hasJdbcStore && hasHibernate && purgeTables) {
                    purgeTablesBean(JdbcCleanup) { bean ->
                        dataSource = ref(properties['org.quartz.jdbcStoreDataSource'] ?: 'dataSource')
                        bean.autowire = 'byName'
                    }
                }
                // Configure job beans
                grailsApplication.jobClasses.each { GrailsJobClass jobClass ->
                    configureJobBeans.delegate = delegate
                    configureJobBeans(jobClass, hasHibernate)
                }

                // Configure the session listener if there is the Hibernate is configured
                if (hasHibernate) {
                    log.debug("Registering hibernate SessionBinderJobListener")

                    // register SessionBinderJobListener to bind Hibernate Session to each Job's thread
                    "${SessionBinderJobListener.NAME}"(SessionBinderJobListener) { bean ->
                        bean.autowire = "byName"
                    }
                }

                // register global ExceptionPrinterJobListener which will log exceptions occured
                // during job's execution
                "${ExceptionPrinterJobListener.NAME}"(ExceptionPrinterJobListener)

                // Configure the job factory to create job instances on executions.
                quartzJobFactory(GrailsJobFactory)

                // Configure Scheduler
                configureScheduler.delegate = delegate
                configureScheduler()
            }
        }
    }