From: Michael D. <mik...@us...> - 2004-10-29 05:58:19
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17342/NHibernate/Impl Modified Files: SessionFactoryImpl.cs Log Message: NH-90 : code for a pluggable cache. Added a Settings class and removed some old hibernate properties that don't apply to .net. Index: SessionFactoryImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** SessionFactoryImpl.cs 26 Oct 2004 21:22:18 -0000 1.33 --- SessionFactoryImpl.cs 29 Oct 2004 05:58:06 -0000 1.34 *************** *** 64,67 **** --- 64,68 ---- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(SessionFactoryImpl)); + [NonSerialized] private Settings settings; private string name; private string uuid; *************** *** 72,199 **** [NonSerialized] private IDictionary namedQueries; [NonSerialized] private IDictionary imports; - [NonSerialized] private IConnectionProvider connectionProvider; [NonSerialized] private IDictionary properties; - [NonSerialized] private bool showSql; - [NonSerialized] private bool useOuterJoin; - [NonSerialized] private IsolationLevel isolation; // TODO: figure out why this is commented out in nh and not h2.0.3 //[NonSerialized] private Templates templates; - [NonSerialized] private IDictionary querySubstitutions; - [NonSerialized] private Dialect.Dialect dialect; - [NonSerialized] private ITransactionFactory transactionFactory; - [NonSerialized] private int adoBatchSize; - [NonSerialized] private bool useScrollableResultSets; - - [NonSerialized] private string defaultSchema; - [NonSerialized] private object statementFetchSize; [NonSerialized] private IInterceptor interceptor; private static IIdentifierGenerator uuidgen = new UUIDHexGenerator(); ! public SessionFactoryImpl(Configuration cfg, IDictionary properties, IInterceptor interceptor) { - log.Info("building session factory"); if ( log.IsDebugEnabled ) { StringBuilder sb = new StringBuilder("instantiating session factory with properties: "); ! foreach(DictionaryEntry entry in properties) sb.AppendFormat("{0}={1};", entry.Key, ((string)entry.Key).IndexOf("connection_string")>0?"***":entry.Value); log.Debug(sb.ToString()); } this.interceptor = interceptor; - - Dialect.Dialect dl = null; - - try - { - dl = HibernateDialect.GetDialect(properties); - IDictionary temp = new Hashtable(); - - foreach(DictionaryEntry de in dl.DefaultProperties) - { - temp[de.Key] = de.Value; - } - foreach(DictionaryEntry de in properties) - { - temp[de.Key] = de.Value; - } - properties = temp; - } - catch (HibernateException he) - { - log.Warn( "No dialect set - using GenericDialect: " + he.Message ); - dl = new GenericDialect(); - } - dialect = dl; - - connectionProvider = ConnectionProviderFactory.NewConnectionProvider(properties); - - statementFetchSize = PropertiesHelper.GetInt32( Cfg.Environment.StatementFetchSize, properties, -1); - if((int)statementFetchSize==-1) statementFetchSize = null; - if (statementFetchSize!=null) log.Info("ado result set fetch size: " + statementFetchSize); - - useOuterJoin = PropertiesHelper.GetBoolean(Cfg.Environment.OuterJoin, properties); - log.Info("use outer join fetching: " + useOuterJoin); - - // default the isolationLevel to Unspecified to indicate to our code that no isolation level - // has been set so just use the default of the DataProvider. - string isolationString = PropertiesHelper.GetString( Cfg.Environment.Isolation, properties, String.Empty ); - if( isolationString.Length > 0) - { - try - { - isolation = (IsolationLevel)Enum.Parse( typeof(IsolationLevel), isolationString ); - log.Info( "Using Isolation Level: " + isolation.ToString() ); - } - catch( ArgumentException ae ) - { - log.Error( "error configuring IsolationLevel " + isolationString, ae ); - throw new HibernateException( - "The isolation level of " + isolationString + " is not a valid IsolationLevel. Please " + - "use one of the Member Names from the IsolationLevel.", ae ); - } - } - else - { - isolation = IsolationLevel.Unspecified; - } - - - bool usrs = PropertiesHelper.GetBoolean(Cfg.Environment.UseScrollableResultSet, properties); - int batchSize = PropertiesHelper.GetInt32(Cfg.Environment.StatementBatchSize, properties, 0); - - try - { - IDbConnection conn = connectionProvider.GetConnection(); - try - { - //get meta data - usrs = false; // no scrollable results sets in .net -> forward only readers... - batchSize = 0; // is this - } - finally - { - connectionProvider.CloseConnection(conn); - } - } - catch (Exception e) - { - log.Warn("could not obtain connection metadata", e); - } - - useScrollableResultSets = usrs; - adoBatchSize = batchSize; - - defaultSchema = properties[Cfg.Environment.DefaultSchema] as string; - if ( defaultSchema!=null) log.Info ("Default schema set to: " + defaultSchema); - - transactionFactory = BuildTransactionFactory(properties); - - showSql = PropertiesHelper.GetBoolean(Cfg.Environment.ShowSql, properties); - if (showSql) log.Info("echoing all SQL to stdout"); - this.properties = properties; // Persisters: --- 73,99 ---- [NonSerialized] private IDictionary namedQueries; [NonSerialized] private IDictionary imports; [NonSerialized] private IDictionary properties; // TODO: figure out why this is commented out in nh and not h2.0.3 //[NonSerialized] private Templates templates; [NonSerialized] private IInterceptor interceptor; private static IIdentifierGenerator uuidgen = new UUIDHexGenerator(); ! public SessionFactoryImpl(Configuration cfg, IDictionary properties, IInterceptor interceptor, Settings settings) { log.Info("building session factory"); if ( log.IsDebugEnabled ) { StringBuilder sb = new StringBuilder("instantiating session factory with properties: "); ! foreach(DictionaryEntry entry in properties) ! { sb.AppendFormat("{0}={1};", entry.Key, ((string)entry.Key).IndexOf("connection_string")>0?"***":entry.Value); + } log.Debug(sb.ToString()); } this.interceptor = interceptor; this.properties = properties; + this.settings = settings; // Persisters: *************** *** 202,206 **** classPersistersByName = new Hashtable(); ! foreach(PersistentClass model in cfg.ClassMappings) { System.Type persisterClass = model.Persister; IClassPersister cp; --- 102,107 ---- classPersistersByName = new Hashtable(); ! foreach(PersistentClass model in cfg.ClassMappings) ! { System.Type persisterClass = model.Persister; IClassPersister cp; *************** *** 221,229 **** collectionPersisters = new Hashtable(); ! foreach( Mapping.Collection map in cfg.CollectionMappings ) { collectionPersisters[map.Role] = new CollectionPersister(map, cfg, this) ; } ! foreach(IClassPersister persister in classPersisters.Values) { persister.PostInstantiate(this); } --- 122,132 ---- collectionPersisters = new Hashtable(); ! foreach( Mapping.Collection map in cfg.CollectionMappings ) ! { collectionPersisters[map.Role] = new CollectionPersister(map, cfg, this) ; } ! foreach(IClassPersister persister in classPersisters.Values) ! { persister.PostInstantiate(this); } *************** *** 231,236 **** //TODO: Add for databinding - name = (string) properties[ Cfg.Environment.SessionFactoryName ]; try { --- 134,140 ---- //TODO: Add for databinding + // serialization info + name = settings.SessionFactoryName; try { *************** *** 243,256 **** SessionFactoryObjectFactory.AddInstance(uuid, name, this, properties); - // queries: - - querySubstitutions = PropertiesHelper.ToDictionary(Cfg.Environment.QuerySubstitutions, " ,=;:\n\t\r\f", properties); - if ( log.IsInfoEnabled ) - { - StringBuilder sb = new StringBuilder("Query language substitutions: "); - foreach(DictionaryEntry entry in querySubstitutions) - sb.AppendFormat("{0}={1};", entry.Key, entry.Value); - log.Info(sb.ToString()); - } namedQueries = cfg.NamedQueries; --- 147,150 ---- *************** *** 409,418 **** public IConnectionProvider ConnectionProvider { ! get {return this.connectionProvider;} } public IsolationLevel Isolation { ! get { return isolation; } } --- 303,312 ---- public IConnectionProvider ConnectionProvider { ! get {return settings.ConnectionProvider;} } public IsolationLevel Isolation { ! get { return settings.IsolationLevel; } } *************** *** 439,447 **** if ( q==null) { ! q = new QueryTranslator(dialect); Put(cacheKey, q); } ! q.Compile(this, query, querySubstitutions, shallow); return q; --- 333,341 ---- if ( q==null) { ! q = new QueryTranslator( Dialect ); Put(cacheKey, q); } ! q.Compile(this, query, settings.QuerySubstitutions, shallow); return q; *************** *** 455,463 **** if ( q==null ) { ! q = new FilterTranslator(dialect); Put(cacheKey, q); } ! q.Compile(collectionRole, this, query, querySubstitutions, scalar); return q; --- 349,357 ---- if ( q==null ) { ! q = new FilterTranslator( Dialect ); Put(cacheKey, q); } ! q.Compile(collectionRole, this, query, settings.QuerySubstitutions, scalar); return q; *************** *** 495,499 **** try { ! return connectionProvider.GetConnection(); } catch (Exception sqle) --- 389,393 ---- try { ! return ConnectionProvider.GetConnection(); } catch (Exception sqle) *************** *** 507,511 **** try { ! connectionProvider.CloseConnection(conn); } catch (Exception e) --- 401,405 ---- try { ! ConnectionProvider.CloseConnection(conn); } catch (Exception e) *************** *** 552,556 **** public Dialect.Dialect Dialect { ! get { return dialect; } } --- 446,450 ---- public Dialect.Dialect Dialect { ! get { return settings.Dialect; } } *************** *** 562,583 **** public ITransactionFactory TransactionFactory { ! get { return transactionFactory; } } ! public bool UseAdoBatch { ! get { return adoBatchSize > 0; } ! } ! public int ADOBatchSize { ! get { return adoBatchSize; } ! } ! public bool EnableJoinedFetch { ! get { return useOuterJoin; } } ! public bool UseScrollableResultSets { ! get { return useScrollableResultSets; } ! } public string GetNamedQuery(string name) --- 456,479 ---- public ITransactionFactory TransactionFactory { ! get { return settings.TransactionFactory; } } ! // public bool UseAdoBatch ! // { ! // get { return adoBatchSize > 0; } ! // } ! // public int ADOBatchSize { ! // get { return adoBatchSize; } ! // } ! public bool EnableJoinedFetch ! { ! get { return settings.IsOuterJoinFetchEnabled; } } ! // public bool UseScrollableResultSets { ! // get { return useScrollableResultSets; } ! // } public string GetNamedQuery(string name) *************** *** 646,659 **** public string DefaultSchema { ! get { return defaultSchema; } } ! public void SetFetchSize(IDbCommand statement) ! { ! if ( statementFetchSize!=null) ! { ! // nothing to do in ADO.NET ! } ! } public IClassMetadata GetClassMetadata(System.Type persistentClass) --- 542,555 ---- public string DefaultSchema { ! get { return settings.DefaultSchemaName; } } ! // public void SetFetchSize(IDbCommand statement) ! // { ! // if ( settings.sstatementFetchSize!=null) ! // { ! // // nothing to do in ADO.NET ! // } ! // } public IClassMetadata GetClassMetadata(System.Type persistentClass) *************** *** 733,737 **** try { ! connectionProvider.Close(); } finally --- 629,633 ---- try { ! ConnectionProvider.Close(); } finally |