From: <fab...@us...> - 2009-05-09 02:27:13
|
Revision: 4271 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4271&view=rev Author: fabiomaulo Date: 2009-05-09 02:27:10 +0000 (Sat, 09 May 2009) Log Message: ----------- Minor (reformatting) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2009-05-08 16:40:47 UTC (rev 4270) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Loader/QueryLoader.cs 2009-05-09 02:27:10 UTC (rev 4271) @@ -14,7 +14,6 @@ using NHibernate.Transform; using NHibernate.Type; using NHibernate.Util; -using IQueryable=NHibernate.Persister.Entity.IQueryable; namespace NHibernate.Hql.Ast.ANTLR.Loader { @@ -40,11 +39,12 @@ private bool[] _includeInSelect; private int[] _owners; private EntityType[] _ownerAssociationTypes; - private readonly NullableDictionary<string, string> _sqlAliasByEntityAlias= new NullableDictionary<string, string>(); + private readonly NullableDictionary<string, string> _sqlAliasByEntityAlias = new NullableDictionary<string, string>(); private int _selectLength; private LockMode[] _defaultLockModes; - public QueryLoader(QueryTranslatorImpl queryTranslator, ISessionFactoryImplementor factory, SelectClause selectClause) : base(factory) + public QueryLoader(QueryTranslatorImpl queryTranslator, ISessionFactoryImplementor factory, SelectClause selectClause) + : base(factory) { _queryTranslator = queryTranslator; _selectClause = selectClause; @@ -58,15 +58,15 @@ get { return HasSubselectLoadableCollections(); } } + protected override void AdjustNamedParameterLocationsForQueryParameters(QueryParameters parameters) + { + _queryTranslator.AdjustNamedParameterLocationsForQueryParameters(parameters); + } - protected override void AdjustNamedParameterLocationsForQueryParameters(QueryParameters parameters) - { - _queryTranslator.AdjustNamedParameterLocationsForQueryParameters(parameters); - } - - protected override SqlString ApplyLocks(SqlString sql, IDictionary<string, LockMode> lockModes, Dialect.Dialect dialect) + protected override SqlString ApplyLocks(SqlString sql, IDictionary<string, LockMode> lockModes, + Dialect.Dialect dialect) { - if ( lockModes == null || lockModes.Count == 0 ) + if (lockModes == null || lockModes.Count == 0) { return sql; } @@ -74,16 +74,16 @@ // can't cache this stuff either (per-invocation) // we are given a map of user-alias -> lock mode // create a new map of sql-alias -> lock mode - Dictionary<string, LockMode> aliasedLockModes = new Dictionary<string, LockMode>(); + var aliasedLockModes = new Dictionary<string, LockMode>(); Dictionary<string, string[]> keyColumnNames = dialect.ForUpdateOfColumns ? new Dictionary<string, string[]>() : null; foreach (var entry in lockModes) { string userAlias = entry.Key; string drivingSqlAlias = _sqlAliasByEntityAlias[userAlias]; - if ( drivingSqlAlias == null ) + if (drivingSqlAlias == null) { - throw new InvalidOperationException( "could not locate alias to apply lock mode : " + userAlias ); + throw new InvalidOperationException("could not locate alias to apply lock mode : " + userAlias); } // at this point we have (drivingSqlAlias) the SQL alias of the driving table @@ -92,27 +92,28 @@ // the exception case here is joined-subclass hierarchies where we instead // want to apply the lock against the root table (for all other strategies, // it just happens that driving and root are the same). - QueryNode select = ( QueryNode ) _queryTranslator.SqlAST; - ILockable drivingPersister = ( ILockable ) select.FromClause.GetFromElement( userAlias ).Queryable; - string sqlAlias = drivingPersister.GetRootTableAlias( drivingSqlAlias ); + var select = (QueryNode) _queryTranslator.SqlAST; + var drivingPersister = (ILockable) select.FromClause.GetFromElement(userAlias).Queryable; + string sqlAlias = drivingPersister.GetRootTableAlias(drivingSqlAlias); aliasedLockModes.Add(sqlAlias, entry.Value); - if ( keyColumnNames != null ) + if (keyColumnNames != null) { - keyColumnNames.Add( sqlAlias, drivingPersister.RootTableIdentifierColumnNames ); + keyColumnNames.Add(sqlAlias, drivingPersister.RootTableIdentifierColumnNames); } } - return dialect.ApplyLocksToSql( sql, aliasedLockModes, keyColumnNames ); + return dialect.ApplyLocksToSql(sql, aliasedLockModes, keyColumnNames); } - protected override int BindParameterValues(IDbCommand statement, QueryParameters queryParameters, int startIndex, ISessionImplementor session) + protected override int BindParameterValues(IDbCommand statement, QueryParameters queryParameters, int startIndex, + ISessionImplementor session) { int position = startIndex; - + IList<IParameterSpecification> parameterSpecs = _queryTranslator.CollectedParameterSpecifications; - foreach (IParameterSpecification spec in parameterSpecs) + foreach (var spec in parameterSpecs) { position += spec.Bind(statement, queryParameters, session, position); } @@ -182,16 +183,16 @@ // it is per-invocation, not constant for the // QueryTranslator instance - LockMode[] lockModeArray = new LockMode[_entityAliases.Length]; + var lockModeArray = new LockMode[_entityAliases.Length]; for (int i = 0; i < _entityAliases.Length; i++) { LockMode lockMode; - if (!lockModes.TryGetValue(_entityAliases[i], out lockMode)) - { + if (!lockModes.TryGetValue(_entityAliases[i], out lockMode)) + { //NONE, because its the requested lock mode, not the actual! lockMode = LockMode.None; - } + } lockModeArray[i] = lockMode; } @@ -233,30 +234,28 @@ //sqlResultTypes = selectClause.getSqlResultTypes(); _queryReturnTypes = selectClause.QueryReturnTypes; - _selectNewTransformer = HolderInstantiator.CreateSelectNewTransformer( - selectClause.Constructor, - selectClause.IsMap); - + _selectNewTransformer = HolderInstantiator.CreateSelectNewTransformer(selectClause.Constructor, selectClause.IsMap); + // TODO - Java implementation passes IsList into CreateSelectNewTransformer..., // selectClause.IsList); _queryReturnAliases = selectClause.QueryReturnAliases; IList<FromElement> collectionFromElements = selectClause.CollectionFromElements; - if ( collectionFromElements != null && collectionFromElements.Count !=0 ) + if (collectionFromElements != null && collectionFromElements.Count != 0) { int length = collectionFromElements.Count; _collectionPersisters = new IQueryableCollection[length]; _collectionOwners = new int[length]; _collectionSuffixes = new string[length]; - for ( int i=0; i<length; i++ ) + for (int i = 0; i < length; i++) { FromElement collectionFromElement = collectionFromElements[i]; _collectionPersisters[i] = collectionFromElement.QueryableCollection; _collectionOwners[i] = fromElementList.IndexOf(collectionFromElement.Origin); - // collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix(); - // collectionSuffixes[i] = Integer.toString( i ) + "_"; + // collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix(); + // collectionSuffixes[i] = Integer.toString( i ) + "_"; _collectionSuffixes[i] = collectionFromElement.CollectionSuffix; } } @@ -271,42 +270,42 @@ _owners = new int[size]; _ownerAssociationTypes = new EntityType[size]; - for ( int i = 0; i < size; i++ ) + for (int i = 0; i < size; i++) { FromElement element = fromElementList[i]; - _entityPersisters[i] = ( IQueryable ) element.EntityPersister; + _entityPersisters[i] = (IQueryable) element.EntityPersister; - if ( _entityPersisters[i] == null ) + if (_entityPersisters[i] == null) { - throw new InvalidOperationException( "No entity persister for " + element.ToString() ); + throw new InvalidOperationException("No entity persister for " + element); } _entityEagerPropertyFetches[i] = element.IsAllPropertyFetch; _sqlAliases[i] = element.TableAlias; _entityAliases[i] = element.ClassAlias; - _sqlAliasByEntityAlias.Add( _entityAliases[i], _sqlAliases[i] ); + _sqlAliasByEntityAlias.Add(_entityAliases[i], _sqlAliases[i]); // TODO should we just collect these like with the collections above? - _sqlAliasSuffixes[i] = ( size == 1 ) ? "" : i.ToString() + "_"; - // sqlAliasSuffixes[i] = element.getColumnAliasSuffix(); + _sqlAliasSuffixes[i] = (size == 1) ? "" : i + "_"; + // sqlAliasSuffixes[i] = element.getColumnAliasSuffix(); _includeInSelect[i] = !element.IsFetch; - if ( _includeInSelect[i] ) + if (_includeInSelect[i]) { _selectLength++; } _owners[i] = -1; //by default - if ( element.IsFetch ) + if (element.IsFetch) { - if ( element.IsCollectionJoin || element.QueryableCollection != null ) + if (element.IsCollectionJoin || element.QueryableCollection != null) { // This is now handled earlier in this method. } - else if ( element.DataType.IsEntityType ) + else if (element.DataType.IsEntityType) { - EntityType entityType = ( EntityType ) element.DataType; - if ( entityType.IsOneToOne) + var entityType = (EntityType) element.DataType; + if (entityType.IsOneToOne) { - _owners[i] = fromElementList.IndexOf( element.Origin ); + _owners[i] = fromElementList.IndexOf(element.Origin); } _ownerAssociationTypes[i] = entityType; } @@ -317,41 +316,44 @@ _defaultLockModes = ArrayHelper.FillArray(LockMode.None, size); } - public IList List(ISessionImplementor session, QueryParameters queryParameters) + public IList List(ISessionImplementor session, QueryParameters queryParameters) { - CheckQuery( queryParameters ); - return List( session, queryParameters, _queryTranslator.QuerySpaces, _queryReturnTypes ); + CheckQuery(queryParameters); + return List(session, queryParameters, _queryTranslator.QuerySpaces, _queryReturnTypes); } - protected override IList GetResultList(IList results, IResultTransformer resultTransformer) - { - // meant to handle dynamic instantiation queries... - HolderInstantiator holderInstantiator = HolderInstantiator.GetHolderInstantiator(_selectNewTransformer, resultTransformer, _queryReturnAliases); - if (holderInstantiator.IsRequired) - { - for (int i = 0; i < results.Count; i++) - { - Object[] row = (Object[])results[i]; - Object result = holderInstantiator.Instantiate(row); - results[i] = result; - } + protected override IList GetResultList(IList results, IResultTransformer resultTransformer) + { + // meant to handle dynamic instantiation queries... + HolderInstantiator holderInstantiator = HolderInstantiator.GetHolderInstantiator(_selectNewTransformer, + resultTransformer, + _queryReturnAliases); + if (holderInstantiator.IsRequired) + { + for (int i = 0; i < results.Count; i++) + { + var row = (Object[]) results[i]; + Object result = holderInstantiator.Instantiate(row); + results[i] = result; + } - if (!HasSelectNew && resultTransformer != null) - { - return resultTransformer.TransformList(results); - } - else - { - return results; - } - } - else - { - return results; - } - } + if (!HasSelectNew && resultTransformer != null) + { + return resultTransformer.TransformList(results); + } + else + { + return results; + } + } + else + { + return results; + } + } - protected override object GetResultColumnOrRow(object[] row, IResultTransformer resultTransformer, IDataReader rs, ISessionImplementor session) + protected override object GetResultColumnOrRow(object[] row, IResultTransformer resultTransformer, IDataReader rs, + ISessionImplementor session) { row = ToResultRow(row); bool hasTransform = HasSelectNew || resultTransformer != null; @@ -392,7 +394,7 @@ return row; } - object[] result = new object[_selectLength]; + var result = new object[_selectLength]; int j = 0; for (int i = 0; i < row.Length; i++) { @@ -435,13 +437,15 @@ IDbCommand cmd = PrepareQueryCommand(queryParameters, false, session); // This IDataReader is disposed of in EnumerableImpl.Dispose - IDataReader rs = GetResultSet(cmd, queryParameters.HasAutoDiscoverScalarTypes, false, queryParameters.RowSelection, session); + IDataReader rs = GetResultSet(cmd, queryParameters.HasAutoDiscoverScalarTypes, false, queryParameters.RowSelection, + session); - HolderInstantiator hi = - HolderInstantiator.GetHolderInstantiator(_selectNewTransformer, queryParameters.ResultTransformer, _queryReturnAliases); + HolderInstantiator hi = HolderInstantiator.GetHolderInstantiator(_selectNewTransformer, + queryParameters.ResultTransformer, + _queryReturnAliases); - IEnumerable result = - new EnumerableImpl(rs, cmd, session, _queryTranslator.ReturnTypes, _queryTranslator.GetColumnNames(), queryParameters.RowSelection, hi); + IEnumerable result = new EnumerableImpl(rs, cmd, session, _queryTranslator.ReturnTypes, + _queryTranslator.GetColumnNames(), queryParameters.RowSelection, hi); if (statsEnabled) { @@ -454,4 +458,4 @@ return result; } } -} +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |