<commit_before>/* Copyright 2004-2005 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package org.codehaus.groovy.grails.orm.hibernate;

import java.io.IOException;

import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;

/**
 * @author <NAME>
 * @since 07-Jul-2005
 */
public class ConfigurableLocalsSessionFactoryBean extends
		LocalSessionFactoryBean {

	private Configuration configuration;
	private ClassLoader classLoader = null;

	/**
	 * 
	 */
	public ConfigurableLocalsSessionFactoryBean() {
		super();		
	}
	
	/**
	 * Overrides default behaviour to allow for a configurable configuration class 
	 */
	protected Configuration newConfiguration() {
		return this.configuration;
	}

	/**
	 * @return Returns the configuration.
	 */
	public Configuration getConfiguration() {
		return configuration;
	}

	/**
	 * @param configurationClass The configuration to set.
	 */
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	public void setClassLoader(ClassLoader classLoader) {
		this.classLoader = classLoader;
	}
	
	public void afterPropertiesSet() throws IllegalArgumentException,
			HibernateException, IOException {
		ClassLoader originalClassLoader = null;
		if (this.classLoader != null) {
			originalClassLoader = Thread.currentThread().getContextClassLoader();
			Thread.currentThread().setContextClassLoader(this.classLoader);
		}
		super.afterPropertiesSet();
		if (originalClassLoader != null) {
			Thread.currentThread().setContextClassLoader(originalClassLoader);
		}
	}
}<commit_msg>changed to use existing configurationClass property to load correct configuration so we can support annotation configuration<commit_after>
/* Copyright 2004-2005 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package org.codehaus.groovy.grails.orm.hibernate;

import java.io.IOException;

import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainConfiguration;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;

/**
 * @author <NAME>
 * @since 07-Jul-2005
 */
public class ConfigurableLocalsSessionFactoryBean extends
		LocalSessionFactoryBean {

	private ClassLoader classLoader = null;
	private GrailsApplication grailsApplication;	

	/**
	 * 
	 */
	public ConfigurableLocalsSessionFactoryBean() {
		super();		
	}
	
	/**
	 * @return Returns the grailsApplication.
	 */
	public GrailsApplication getGrailsApplication() {
		return grailsApplication;
	}

	/**
	 * @param grailsApplication The grailsApplication to set.
	 */
	public void setGrailsApplication(GrailsApplication grailsApplication) {
		this.grailsApplication = grailsApplication;
	}
	
	/**
	 * Overrides default behaviour to allow for a configurable configuration class 
	 */
	protected Configuration newConfiguration() {
		Configuration config = super.newConfiguration();
		
		if(config instanceof GrailsDomainConfiguration) {
			((GrailsDomainConfiguration)config).setGrailsApplication(this.grailsApplication);
		}
		
		return config;
	}


	public void setClassLoader(ClassLoader classLoader) {
		this.classLoader = classLoader;
	}
	
	public void afterPropertiesSet() throws IllegalArgumentException,
			HibernateException, IOException {
		ClassLoader originalClassLoader = null;
		if (this.classLoader != null) {
			originalClassLoader = Thread.currentThread().getContextClassLoader();
			Thread.currentThread().setContextClassLoader(this.classLoader);
		}
		super.afterPropertiesSet();
		if (originalClassLoader != null) {
			Thread.currentThread().setContextClassLoader(originalClassLoader);
		}
	}
}

{'fraction_non_alphanumeric': 0.08498873643252099, 'fraction_numerical': 0.007782101167315175, 'mean_word_length': 4.652777777777778, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3233967', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1232, 'n_words': 382}