FileDocCategorySizeDatePackage
ExternalSessionFactoryConfig.javaAPI DocHibernate 3.2.511225Tue Nov 21 17:02:40 GMT 2006org.hibernate.util

ExternalSessionFactoryConfig

public abstract class ExternalSessionFactoryConfig extends Object
Defines support for various externally configurable SessionFactory(s), for example, {@link org.hibernate.jmx.HibernateService JMX} or the JCA adapter.
author
Steve Ebersole

Fields Summary
private String
mapResources
private String
dialect
private String
defaultSchema
private String
defaultCatalog
private String
maximumFetchDepth
private String
jdbcFetchSize
private String
jdbcBatchSize
private String
batchVersionedDataEnabled
private String
jdbcScrollableResultSetEnabled
private String
getGeneratedKeysEnabled
private String
streamsForBinaryEnabled
private String
reflectionOptimizationEnabled
private String
querySubstitutions
private String
showSqlEnabled
private String
commentsEnabled
private String
cacheProviderClass
private String
cacheProviderConfig
private String
cacheRegionPrefix
private String
secondLevelCacheEnabled
private String
minimalPutsEnabled
private String
queryCacheEnabled
private Map
additionalProperties
private Set
excludedPropertyNames
private Map
customListeners
Constructors Summary
Methods Summary
public final voidaddAdditionalProperty(java.lang.String name, java.lang.String value)

		if ( !getExcludedPropertyNames().contains( name ) ) {
			if ( additionalProperties == null ) {
				additionalProperties = new HashMap();
			}
			additionalProperties.put( name, value );
		}
	
protected voidaddAll(java.util.Properties target, java.util.Map source)

		Iterator itr = source.entrySet().iterator();
		while ( itr.hasNext() ) {
			final Map.Entry entry = ( Map.Entry ) itr.next();
			final String propertyName = ( String ) entry.getKey();
			final String propertyValue = ( String ) entry.getValue();
			if ( propertyName != null && propertyValue != null ) {
				// Make sure we don't override previous set values
				if ( !target.keySet().contains( propertyName ) ) {
					if ( !getExcludedPropertyNames().contains( propertyName) ) {
						target.put( propertyName, propertyValue );
					}
				}
			}
		}
	
public voidaddMapResource(java.lang.String mapResource)

		if ( mapResources==null || mapResources.length()==0 ) {
			mapResources = mapResource.trim();
		}
		else {
			mapResources += ", " + mapResource.trim();
		}
	
protected final org.hibernate.cfg.ConfigurationbuildConfiguration()


		Configuration cfg = new Configuration().setProperties( buildProperties() );


		String[] mappingFiles = PropertiesHelper.toStringArray( mapResources, " ,\n\t\r\f" );
		for ( int i = 0; i < mappingFiles.length; i++ ) {
			cfg.addResource( mappingFiles[i] );
		}

		if ( customListeners != null && !customListeners.isEmpty() ) {
			Iterator entries = customListeners.entrySet().iterator();
			while ( entries.hasNext() ) {
				final Map.Entry entry = ( Map.Entry ) entries.next();
				final String type = ( String ) entry.getKey();
				final Object value = entry.getValue();
				if ( value != null ) {
					if ( String.class.isAssignableFrom( value.getClass() ) ) {
						// Its the listener class name
						cfg.setListener( type, ( ( String ) value ) );
					}
					else {
						// Its the listener instance (or better be)
						cfg.setListener( type, value );
					}
				}
			}
		}

		return cfg;
	
protected final java.util.PropertiesbuildProperties()

		Properties props = new Properties();
		setUnlessNull( props, Environment.DIALECT, dialect );
		setUnlessNull( props, Environment.DEFAULT_SCHEMA, defaultSchema );
		setUnlessNull( props, Environment.DEFAULT_CATALOG, defaultCatalog );
		setUnlessNull( props, Environment.MAX_FETCH_DEPTH, maximumFetchDepth );
		setUnlessNull( props, Environment.STATEMENT_FETCH_SIZE, jdbcFetchSize );
		setUnlessNull( props, Environment.STATEMENT_BATCH_SIZE, jdbcBatchSize );
		setUnlessNull( props, Environment.BATCH_VERSIONED_DATA, batchVersionedDataEnabled );
		setUnlessNull( props, Environment.USE_SCROLLABLE_RESULTSET, jdbcScrollableResultSetEnabled );
		setUnlessNull( props, Environment.USE_GET_GENERATED_KEYS, getGeneratedKeysEnabled );
		setUnlessNull( props, Environment.USE_STREAMS_FOR_BINARY, streamsForBinaryEnabled );
		setUnlessNull( props, Environment.USE_REFLECTION_OPTIMIZER, reflectionOptimizationEnabled );
		setUnlessNull( props, Environment.QUERY_SUBSTITUTIONS, querySubstitutions );
		setUnlessNull( props, Environment.SHOW_SQL, showSqlEnabled );
		setUnlessNull( props, Environment.USE_SQL_COMMENTS, commentsEnabled );
		setUnlessNull( props, Environment.CACHE_PROVIDER, cacheProviderClass );
		setUnlessNull( props, Environment.CACHE_PROVIDER_CONFIG, cacheProviderConfig );
		setUnlessNull( props, Environment.CACHE_REGION_PREFIX, cacheRegionPrefix );
		setUnlessNull( props, Environment.USE_MINIMAL_PUTS, minimalPutsEnabled );
		setUnlessNull( props, Environment.USE_SECOND_LEVEL_CACHE, secondLevelCacheEnabled );
		setUnlessNull( props, Environment.USE_QUERY_CACHE, queryCacheEnabled );

		Map extraProperties = getExtraProperties();
		if ( extraProperties != null ) {
			addAll( props, extraProperties );
		}

		if ( additionalProperties != null ) {
			addAll( props, additionalProperties );
		}

		return props;
	
public final java.lang.StringgetBatchVersionedDataEnabled()

		return batchVersionedDataEnabled;
	
public final java.lang.StringgetCacheProviderClass()

		return cacheProviderClass;
	
public java.lang.StringgetCacheProviderConfig()

		return cacheProviderConfig;
	
public final java.lang.StringgetCacheRegionPrefix()

		return cacheRegionPrefix;
	
public final java.lang.StringgetCommentsEnabled()

		return commentsEnabled;
	
public final java.util.MapgetCustomListeners()

		return customListeners;
	
public final java.lang.StringgetDefaultCatalog()

		return defaultCatalog;
	
public final java.lang.StringgetDefaultSchema()

		return defaultSchema;
	
public final java.lang.StringgetDialect()

		return dialect;
	
protected java.util.SetgetExcludedPropertyNames()



	   
		return excludedPropertyNames;
	
protected java.util.MapgetExtraProperties()

		return null;
	
public final java.lang.StringgetGetGeneratedKeysEnabled()

		return getGeneratedKeysEnabled;
	
public final java.lang.StringgetJdbcBatchSize()

		return jdbcBatchSize;
	
public final java.lang.StringgetJdbcFetchSize()

		return jdbcFetchSize;
	
public final java.lang.StringgetJdbcScrollableResultSetEnabled()

		return jdbcScrollableResultSetEnabled;
	
public final java.lang.StringgetMapResources()

		return mapResources;
	
public final java.lang.StringgetMaximumFetchDepth()

		return maximumFetchDepth;
	
public final java.lang.StringgetMinimalPutsEnabled()

		return minimalPutsEnabled;
	
public final java.lang.StringgetQueryCacheEnabled()

		return queryCacheEnabled;
	
public final java.lang.StringgetQuerySubstitutions()

		return querySubstitutions;
	
public final java.lang.StringgetReflectionOptimizationEnabled()

		return reflectionOptimizationEnabled;
	
public final java.lang.StringgetSecondLevelCacheEnabled()

		return secondLevelCacheEnabled;
	
public final java.lang.StringgetShowSqlEnabled()

		return showSqlEnabled;
	
public final java.lang.StringgetStreamsForBinaryEnabled()

		return streamsForBinaryEnabled;
	
public final voidsetBatchVersionedDataEnabled(java.lang.String batchVersionedDataEnabled)

		this.batchVersionedDataEnabled = batchVersionedDataEnabled;
	
public final voidsetCacheProviderClass(java.lang.String cacheProviderClass)

		this.cacheProviderClass = cacheProviderClass;
	
public voidsetCacheProviderConfig(java.lang.String cacheProviderConfig)

		this.cacheProviderConfig = cacheProviderConfig;
	
public final voidsetCacheRegionPrefix(java.lang.String cacheRegionPrefix)

		this.cacheRegionPrefix = cacheRegionPrefix;
	
public final voidsetCommentsEnabled(java.lang.String commentsEnabled)

		this.commentsEnabled = commentsEnabled;
	
public voidsetCustomListener(java.lang.String type, java.lang.String listenerClass)

		if ( customListeners == null ) {
			customListeners = new HashMap();
		}
		customListeners.put( type, listenerClass );
	
public voidsetCustomListeners(java.util.Map customListeners)

		this.customListeners = customListeners;
	
public voidsetCustomListenersAsString(java.lang.String customListenersString)

		// Note : expected in the syntax:
		//      type=listenerClass
		//          ({sep}type=listenerClass)*
		// where {sep} is any whitespace or comma
		if ( StringHelper.isNotEmpty( customListenersString) ) {
			String[] listenerEntries = PropertiesHelper.toStringArray( customListenersString, " ,\n\t\r\f" );
			for ( int i = 0; i < listenerEntries.length; i++ ) {
				final int keyValueSepPosition = listenerEntries[i].indexOf( '=" );
				final String type = listenerEntries[i].substring( 0, keyValueSepPosition );
				final String listenerClass = listenerEntries[i].substring( keyValueSepPosition + 1 );
				setCustomListener( type, listenerClass );
			}
		}
	
public final voidsetDefaultCatalog(java.lang.String defaultCatalog)

		this.defaultCatalog = defaultCatalog;
	
public final voidsetDefaultSchema(java.lang.String defaultSchema)

		this.defaultSchema = defaultSchema;
	
public final voidsetDialect(java.lang.String dialect)

		this.dialect = dialect;
	
public final voidsetGetGeneratedKeysEnabled(java.lang.String getGeneratedKeysEnabled)

		this.getGeneratedKeysEnabled = getGeneratedKeysEnabled;
	
public final voidsetJdbcBatchSize(java.lang.String jdbcBatchSize)

		verifyInt( jdbcBatchSize );
		this.jdbcBatchSize = jdbcBatchSize;
	
public final voidsetJdbcFetchSize(java.lang.String jdbcFetchSize)

		verifyInt( jdbcFetchSize );
		this.jdbcFetchSize = jdbcFetchSize;
	
public final voidsetJdbcScrollableResultSetEnabled(java.lang.String jdbcScrollableResultSetEnabled)

		this.jdbcScrollableResultSetEnabled = jdbcScrollableResultSetEnabled;
	
public final voidsetMapResources(java.lang.String mapResources)

		this.mapResources = mapResources;
	
public final voidsetMaximumFetchDepth(java.lang.String maximumFetchDepth)

		verifyInt( maximumFetchDepth );
		this.maximumFetchDepth = maximumFetchDepth;
	
public final voidsetMinimalPutsEnabled(java.lang.String minimalPutsEnabled)

		this.minimalPutsEnabled = minimalPutsEnabled;
	
public final voidsetQueryCacheEnabled(java.lang.String queryCacheEnabled)

		this.queryCacheEnabled = queryCacheEnabled;
	
public final voidsetQuerySubstitutions(java.lang.String querySubstitutions)

		this.querySubstitutions = querySubstitutions;
	
public final voidsetReflectionOptimizationEnabled(java.lang.String reflectionOptimizationEnabled)

		this.reflectionOptimizationEnabled = reflectionOptimizationEnabled;
	
public final voidsetSecondLevelCacheEnabled(java.lang.String secondLevelCacheEnabled)

		this.secondLevelCacheEnabled = secondLevelCacheEnabled;
	
public final voidsetShowSqlEnabled(java.lang.String showSqlEnabled)

		this.showSqlEnabled = showSqlEnabled;
	
public final voidsetStreamsForBinaryEnabled(java.lang.String streamsForBinaryEnabled)

		this.streamsForBinaryEnabled = streamsForBinaryEnabled;
	
private voidsetUnlessNull(java.util.Properties props, java.lang.String key, java.lang.String value)

		if ( value != null ) {
			props.setProperty( key, value );
		}
	
private voidverifyInt(java.lang.String value)

		if ( value != null ) {
			Integer.parseInt( value );
		}