Search in sources :

Example 1 with PersistenceContextInterceptor

use of grails.persistence.support.PersistenceContextInterceptor in project grails-core by grails.

the class GrailsConfigUtils method executeGrailsBootstraps.

/**
     * Executes Grails bootstrap classes
     *
     * @param application The Grails ApplicationContext instance
     * @param webContext The WebApplicationContext instance
     * @param servletContext The ServletContext instance
     */
public static void executeGrailsBootstraps(GrailsApplication application, WebApplicationContext webContext, ServletContext servletContext) {
    PersistenceContextInterceptor interceptor = null;
    String[] beanNames = webContext.getBeanNamesForType(PersistenceContextInterceptor.class);
    if (beanNames.length > 0) {
        interceptor = (PersistenceContextInterceptor) webContext.getBean(beanNames[0]);
    }
    if (interceptor != null) {
        interceptor.init();
    }
    // init the Grails application
    try {
        GrailsClass[] bootstraps = application.getArtefacts(BootstrapArtefactHandler.TYPE);
        for (GrailsClass bootstrap : bootstraps) {
            final GrailsBootstrapClass bootstrapClass = (GrailsBootstrapClass) bootstrap;
            final Object instance = bootstrapClass.getReferenceInstance();
            webContext.getAutowireCapableBeanFactory().autowireBeanProperties(instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
            bootstrapClass.callInit(servletContext);
        }
        if (interceptor != null) {
            interceptor.flush();
        }
    } finally {
        if (interceptor != null) {
            interceptor.destroy();
        }
    }
}
Also used : GrailsClass(grails.core.GrailsClass) PersistenceContextInterceptor(grails.persistence.support.PersistenceContextInterceptor) GrailsBootstrapClass(grails.web.servlet.bootstrap.GrailsBootstrapClass)

Aggregations

GrailsClass (grails.core.GrailsClass)1 PersistenceContextInterceptor (grails.persistence.support.PersistenceContextInterceptor)1 GrailsBootstrapClass (grails.web.servlet.bootstrap.GrailsBootstrapClass)1