From: <dav...@us...> - 2008-11-24 19:31:59
|
Revision: 3922 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3922&view=rev Author: davybrion Date: 2008-11-24 19:31:52 +0000 (Mon, 24 Nov 2008) Log Message: ----------- minor cleanup, mostly replacing hashtables with dictionaries where it was safe to do so Modified Paths: -------------- trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs trunk/nhibernate/src/NHibernate/Criterion/Projections.cs trunk/nhibernate/src/NHibernate/Dialect/Function/NoArgSQLFunction.cs trunk/nhibernate/src/NHibernate/Id/Enhanced/SequenceStructure.cs trunk/nhibernate/src/NHibernate/Impl/Printer.cs trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs trunk/nhibernate/src/NHibernate/Type/ComponentType.cs trunk/nhibernate/src/NHibernate.Test/ConnectionTest/ThreadLocalCurrentSessionTest.cs trunk/nhibernate/src/NHibernate.Test/Naturalid/Immutable/ImmutableNaturalIdFixture.cs Modified: trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs =================================================================== --- trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Data; using System.Reflection; @@ -15,8 +16,8 @@ private int countOfCommands = 0; private int totalExpectedRowsAffected; private IDbCommand currentBatch; - private Hashtable parameterValueArrayHashTable; - private Hashtable parameterIsAllNullsHashTable; + private IDictionary<string, ArrayList> parameterValueArrayHashTable; + private IDictionary<string, bool> parameterIsAllNullsHashTable; public OracleDataClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) @@ -36,10 +37,10 @@ { // use first command as the batching command currentBatch = CurrentCommand; - parameterValueArrayHashTable = new Hashtable(); + parameterValueArrayHashTable = new Dictionary<string, ArrayList>(); //oracle does not allow array containing all null values - // so this HashTable is keeping track if all values are null or not - parameterIsAllNullsHashTable = new Hashtable(); + // so this Dictionary is keeping track if all values are null or not + parameterIsAllNullsHashTable = new Dictionary<string, bool>(); } else { @@ -57,7 +58,7 @@ } else { - parameterValueArray = parameterValueArrayHashTable[currentParameter.ParameterName] as ArrayList; + parameterValueArray = parameterValueArrayHashTable[currentParameter.ParameterName]; } if (currentParameter.Value != DBNull.Value) @@ -73,8 +74,6 @@ { DoExecuteBatch(currentBatch); } - - } protected override void DoExecuteBatch(IDbCommand ps) @@ -90,7 +89,7 @@ foreach (IDataParameter currentParameter in currentBatch.Parameters) { - ArrayList parameterValueArray = parameterValueArrayHashTable[currentParameter.ParameterName] as ArrayList; + ArrayList parameterValueArray = parameterValueArrayHashTable[currentParameter.ParameterName]; currentParameter.Value = parameterValueArray.ToArray(); arraySize = parameterValueArray.Count; } Modified: trunk/nhibernate/src/NHibernate/Criterion/Projections.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Projections.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Criterion/Projections.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -257,8 +257,9 @@ /// Return a constant value /// </summary> /// <param name="obj">The obj.</param> + /// <param name="type"></param> /// <returns></returns> - public static IProjection Constant(object obj,IType type) + public static IProjection Constant(object obj, IType type) { return new ConstantProjection(obj,type); } Modified: trunk/nhibernate/src/NHibernate/Dialect/Function/NoArgSQLFunction.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Function/NoArgSQLFunction.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Dialect/Function/NoArgSQLFunction.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -58,13 +58,13 @@ { throw new QueryException("function takes no arguments: " + name); } - SqlStringBuilder buf = new SqlStringBuilder(2); - buf.Add(name); + if (hasParenthesesIfNoArguments) { - buf.Add("()"); + return new SqlString(name + "()"); } - return buf.ToSqlString(); + + return new SqlString(name); } #endregion Modified: trunk/nhibernate/src/NHibernate/Id/Enhanced/SequenceStructure.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Id/Enhanced/SequenceStructure.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Id/Enhanced/SequenceStructure.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -113,7 +113,7 @@ { rs.Close(); } - catch (Exception ignore) + catch { // intentionally empty } Modified: trunk/nhibernate/src/NHibernate/Impl/Printer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/Printer.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Impl/Printer.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -27,7 +27,7 @@ return entity.GetType().FullName; } - IDictionary result = new Hashtable(); + IDictionary<string, string> result = new Dictionary<string, string>(); if (cm.HasIdentifierProperty) { @@ -49,7 +49,8 @@ public string ToString(IType[] types, object[] values) { - IList list = new ArrayList(types.Length); + List<string> list = new List<string>(types.Length); + for (int i = 0; i < types.Length; i++) { if (types[i] != null) @@ -62,7 +63,7 @@ public string ToString(IDictionary<string, TypedValue> namedTypedValues) { - IDictionary result = new Hashtable(namedTypedValues.Count); + IDictionary<string, string> result = new Dictionary<string, string>(namedTypedValues.Count); foreach (KeyValuePair<string, TypedValue> me in namedTypedValues) { Modified: trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -28,8 +28,8 @@ private static readonly ILog log; // in h2.0.3 these use a class called "FastHashMap" - private static readonly Hashtable Instances = new Hashtable(); - private static readonly Hashtable NamedInstances = new Hashtable(); + private static readonly IDictionary<string, ISessionFactory> Instances = new Dictionary<string, ISessionFactory>(); + private static readonly IDictionary<string, ISessionFactory> NamedInstances = new Dictionary<string, ISessionFactory>(); /// <summary></summary> static SessionFactoryObjectFactory() @@ -54,13 +54,13 @@ { if (log.IsDebugEnabled) { - string nameMsg = ((name != null && name.Length > 0) ? name : "unnamed"); + string nameMsg = ((!string.IsNullOrEmpty(name)) ? name : "unnamed"); log.Debug("registered: " + uid + "(" + nameMsg + ")"); } Instances[uid] = instance; - if (name != null && name.Length > 0) + if (!string.IsNullOrEmpty(name)) { log.Info("Factory name:" + name); NamedInstances[name] = instance; @@ -79,7 +79,7 @@ /// <param name="properties">The configured properties for the ISessionFactory.</param> public static void RemoveInstance(string uid, string name, IDictionary<string, string> properties) { - if (name != null && name.Length > 0) + if (!string.IsNullOrEmpty(name)) { log.Info("unbinding factory: " + name); @@ -97,7 +97,7 @@ public static ISessionFactory GetNamedInstance(string name) { log.Debug("lookup: name=" + name); - ISessionFactory factory = NamedInstances[name] as ISessionFactory; + ISessionFactory factory = NamedInstances[name]; if (factory == null) { log.Warn("Not found: " + name); @@ -113,7 +113,7 @@ public static ISessionFactory GetInstance(string uid) { log.Debug("lookup: uid=" + uid); - ISessionFactory factory = Instances[uid] as ISessionFactory; + ISessionFactory factory = Instances[uid]; if (factory == null) { log.Warn("Not found: " + uid); Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/Sql/SQLQueryReturnProcessor.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -293,7 +293,7 @@ public IList GenerateCustomReturns(bool queryHadAliases) { IList customReturns = new ArrayList(); - IDictionary customReturnsByAlias = new Hashtable(); + IDictionary<string, object> customReturnsByAlias = new Dictionary<string, object>(); for (int i = 0; i < queryReturns.Length; i++) { if (queryReturns[i] is NativeSQLQueryScalarReturn) Modified: trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Persister/Collection/AbstractCollectionPersister.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -160,8 +160,8 @@ private readonly string[] spaces; - private readonly IDictionary collectionPropertyColumnAliases = new Hashtable(); - private readonly IDictionary collectionPropertyColumnNames = new Hashtable(); + private readonly IDictionary<string, object> collectionPropertyColumnAliases = new Dictionary<string, object>(); + private readonly IDictionary<string, object> collectionPropertyColumnNames = new Dictionary<string, object>(); private static readonly ILog log = LogManager.GetLogger(typeof (ICollectionPersister)); Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -204,7 +204,7 @@ #endregion - private readonly Hashtable uniqueKeyLoaders = new Hashtable(); + private readonly Dictionary<string, EntityLoader> uniqueKeyLoaders = new Dictionary<string, EntityLoader>(); private readonly Dictionary<LockMode, ILockingStrategy> lockers = new Dictionary<LockMode, ILockingStrategy>(); private readonly Dictionary<string, IUniqueEntityLoader> loaders = new Dictionary<string, IUniqueEntityLoader>(); @@ -1996,12 +1996,10 @@ if (useStaticLoader) { - return (EntityLoader)uniqueKeyLoaders[propertyName]; + return uniqueKeyLoaders[propertyName]; } - else - { - return CreateUniqueKeyLoader(propertyMapping.ToType(propertyName), propertyMapping.ToColumns(propertyName), enabledFilters); - } + + return CreateUniqueKeyLoader(propertyMapping.ToType(propertyName), propertyMapping.ToColumns(propertyName), enabledFilters); } public int GetPropertyIndex(string propertyName) Modified: trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs =================================================================== --- trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/SqlCommand/SelectFragment.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Text; using Iesi.Collections; using NHibernate.Util; @@ -12,8 +13,8 @@ public class SelectFragment { private string suffix; - private IList columns = new ArrayList(); - private IList columnAliases = new ArrayList(); + private IList<string> columns = new List<string>(); + private IList<string> columnAliases = new List<string>(); private Dialect.Dialect dialect; private string[] usedAliases; private string extraSelectList; @@ -57,7 +58,7 @@ public SelectFragment AddColumn(string tableAlias, string columnName, string columnAlias) { - if (tableAlias == null || tableAlias.Length == 0) + if (string.IsNullOrEmpty(tableAlias)) { columns.Add(columnName); } @@ -140,8 +141,8 @@ bool found = false; for (int i = 0; i < columns.Count; i++) { - string col = columns[i] as string; - string columnAlias = columnAliases[i] as string; + string col = columns[i]; + string columnAlias = columnAliases[i]; if (columnsUnique.Add(columnAlias)) { Modified: trunk/nhibernate/src/NHibernate/Type/ComponentType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/ComponentType.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate/Type/ComponentType.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Data; using System.Reflection; using System.Xml; @@ -311,7 +312,7 @@ { return "null"; } - IDictionary result = new Hashtable(); + IDictionary<string, string> result = new Dictionary<string, string>(); EntityMode? entityMode = tuplizerMapping.GuessEntityMode(value); if (!entityMode.HasValue) { Modified: trunk/nhibernate/src/NHibernate.Test/ConnectionTest/ThreadLocalCurrentSessionTest.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/ConnectionTest/ThreadLocalCurrentSessionTest.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate.Test/ConnectionTest/ThreadLocalCurrentSessionTest.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -59,7 +59,7 @@ session.CreateQuery("from Silly"); Assert.Fail("method other than beginTransaction{} allowed"); } - catch (HibernateException e) + catch (HibernateException) { // ok } Modified: trunk/nhibernate/src/NHibernate.Test/Naturalid/Immutable/ImmutableNaturalIdFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Naturalid/Immutable/ImmutableNaturalIdFixture.cs 2008-11-24 12:59:36 UTC (rev 3921) +++ trunk/nhibernate/src/NHibernate.Test/Naturalid/Immutable/ImmutableNaturalIdFixture.cs 2008-11-24 19:31:52 UTC (rev 3922) @@ -73,7 +73,7 @@ s.Flush(); Assert.Fail(); } - catch (HibernateException he) {} + catch (HibernateException) {} u.UserName = "steve"; s.Delete(u); t.Commit(); @@ -82,63 +82,63 @@ [Test] public void NaturalIdCache() - { - ISession s = OpenSession(); - s.BeginTransaction(); - User u = new User("steve", "superSecret"); - s.Persist(u); - s.Transaction.Commit(); - s.Close(); - - sessions.Statistics.Clear(); - - s = OpenSession(); - s.BeginTransaction(); + { + ISession s = OpenSession(); + s.BeginTransaction(); + User u = new User("steve", "superSecret"); + s.Persist(u); + s.Transaction.Commit(); + s.Close(); + + sessions.Statistics.Clear(); + + s = OpenSession(); + s.BeginTransaction(); u = (User) s.CreateCriteria(typeof (User)).Add(Restrictions.NaturalId().Set("UserName", "steve")).SetCacheable(true). UniqueResult(); - Assert.That(u, Is.Not.Null); - s.Transaction.Commit(); + Assert.That(u, Is.Not.Null); + s.Transaction.Commit(); s.Close(); Assert.AreEqual(1, sessions.Statistics.QueryExecutionCount); Assert.AreEqual(0, sessions.Statistics.QueryCacheHitCount); - Assert.AreEqual(1, sessions.Statistics.QueryCachePutCount); - - s = OpenSession(); - s.BeginTransaction(); - User v = new User("gavin", "supsup"); - s.Persist(v); - s.Transaction.Commit(); - s.Close(); - - sessions.Statistics.Clear(); - - s = OpenSession(); - s.BeginTransaction(); + Assert.AreEqual(1, sessions.Statistics.QueryCachePutCount); + + s = OpenSession(); + s.BeginTransaction(); + User v = new User("gavin", "supsup"); + s.Persist(v); + s.Transaction.Commit(); + s.Close(); + + sessions.Statistics.Clear(); + + s = OpenSession(); + s.BeginTransaction(); u = (User) s.CreateCriteria(typeof(User)).Add(Restrictions.NaturalId().Set("UserName", "steve")).SetCacheable(true). UniqueResult(); Assert.That(u, Is.Not.Null); Assert.AreEqual(0, sessions.Statistics.QueryExecutionCount); - Assert.AreEqual(1, sessions.Statistics.QueryCacheHitCount); + Assert.AreEqual(1, sessions.Statistics.QueryCacheHitCount); u = (User) s.CreateCriteria(typeof(User)).Add(Restrictions.NaturalId().Set("UserName", "steve")).SetCacheable(true). UniqueResult(); Assert.That(u, Is.Not.Null); Assert.AreEqual(0, sessions.Statistics.QueryExecutionCount); - Assert.AreEqual(2, sessions.Statistics.QueryCacheHitCount); - s.Transaction.Commit(); - s.Close(); - - s = OpenSession(); - s.BeginTransaction(); - s.Delete("from User"); - s.Transaction.Commit(); - s.Close(); + Assert.AreEqual(2, sessions.Statistics.QueryCacheHitCount); + s.Transaction.Commit(); + s.Close(); + + s = OpenSession(); + s.BeginTransaction(); + s.Delete("from User"); + s.Transaction.Commit(); + s.Close(); } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |