FileDocCategorySizeDatePackage
ExecutionEnvironment.javaAPI DocHibernate 3.2.55035Wed Mar 28 11:03:18 BST 2007org.hibernate.junit.functional

ExecutionEnvironment

public class ExecutionEnvironment extends Object
{@inheritDoc}
author
Steve Ebersole

Fields Summary
public static final org.hibernate.dialect.Dialect
DIALECT
private final Settings
settings
private org.hibernate.cfg.Configuration
configuration
private org.hibernate.SessionFactory
sessionFactory
private boolean
allowRebuild
Constructors Summary
public ExecutionEnvironment(Settings settings)


	   
		this.settings = settings;
	
Methods Summary
private voidapplyCacheSettings(org.hibernate.cfg.Configuration configuration)

		if ( settings.getCacheConcurrencyStrategy() != null ) {
			Iterator iter = configuration.getClassMappings();
			while ( iter.hasNext() ) {
				PersistentClass clazz = (PersistentClass) iter.next();
				Iterator props = clazz.getPropertyClosureIterator();
				boolean hasLob = false;
				while ( props.hasNext() ) {
					Property prop = (Property) props.next();
					if ( prop.getValue().isSimpleValue() ) {
						String type = ( ( SimpleValue ) prop.getValue() ).getTypeName();
						if ( "blob".equals(type) || "clob".equals(type) ) {
							hasLob = true;
						}
						if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) {
							hasLob = true;
						}
					}
				}
				if ( !hasLob && !clazz.isInherited() && settings.overrideCacheStrategy() ) {
					configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), settings.getCacheConcurrencyStrategy() );
				}
			}
			iter = configuration.getCollectionMappings();
			while ( iter.hasNext() ) {
				Collection coll = (Collection) iter.next();
				configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), settings.getCacheConcurrencyStrategy() );
			}
		}
	
private voidapplyMappings(org.hibernate.cfg.Configuration configuration)

		String[] mappings = settings.getMappings();
		for ( int i = 0; i < mappings.length; i++ ) {
			configuration.addResource( settings.getBaseForMappings() + mappings[i], ExecutionEnvironment.class.getClassLoader() );
		}
	
public voidcomplete()

		if ( sessionFactory != null ) {
			sessionFactory.close();
			sessionFactory = null;
		}
		configuration = null;
	
public org.hibernate.cfg.ConfigurationgetConfiguration()

		return configuration;
	
public org.hibernate.dialect.DialectgetDialect()

		return DIALECT;
	
public org.hibernate.SessionFactorygetSessionFactory()

		return sessionFactory;
	
public voidinitialize()

		if ( sessionFactory != null ) {
			throw new IllegalStateException( "attempt to initialize already initialized ExecutionEnvironment" );
		}
		if ( ! settings.appliesTo( getDialect() ) ) {
			return;
		}

		Configuration configuration = new Configuration();
		configuration.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );

		settings.configure( configuration );

		applyMappings( configuration );
		applyCacheSettings( configuration );


		if ( settings.createSchema() ) {
			configuration.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
		}

		// make sure we use the same dialect...
		configuration.setProperty( Environment.DIALECT, getDialect().getClass().getName() );

		configuration.buildMappings();
		settings.afterConfigurationBuilt( configuration.createMappings(), getDialect() );

		SessionFactory sessionFactory = configuration.buildSessionFactory();
		this.configuration = configuration;
		this.sessionFactory = sessionFactory;

		settings.afterSessionFactoryBuilt( ( SessionFactoryImplementor ) sessionFactory );
	
public booleanisAllowRebuild()

		return allowRebuild;
	
public voidrebuild()

		if ( !allowRebuild ) {
			return;
		}
		if ( sessionFactory != null ) {
			sessionFactory.close();
			sessionFactory = null;
		}
		sessionFactory = configuration.buildSessionFactory();
		settings.afterSessionFactoryBuilt( ( SessionFactoryImplementor ) sessionFactory );
	
public voidsetAllowRebuild(boolean allowRebuild)

		this.allowRebuild = allowRebuild;