Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5548/nhibernate/src/NHibernate/Impl Modified Files: CollectionEntry.cs CollectionKey.cs FilterImpl.cs MessageHelper.cs OnLockVisitor.cs OnUpdateVisitor.cs QueryImpl.cs ScheduledCollectionAction.cs ScheduledCollectionRecreate.cs ScheduledCollectionRemove.cs ScheduledCollectionUpdate.cs ScheduledDeletion.cs ScheduledUpdate.cs SessionFactoryImpl.cs SessionImpl.cs WrapVisitor.cs Added Files: AbstractQueryImpl.cs Log Message: Various refactorings on the way to 2.1 querying capability Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** SessionImpl.cs 16 Feb 2005 20:14:20 -0000 1.67 --- SessionImpl.cs 1 Mar 2005 16:24:47 -0000 1.68 *************** *** 1286,1290 **** } ! internal void RemoveCollection( CollectionPersister role, object id ) { if( log.IsDebugEnabled ) --- 1286,1290 ---- } ! internal void RemoveCollection( ICollectionPersister role, object id ) { if( log.IsDebugEnabled ) *************** *** 1306,1310 **** } ! internal static bool IsOwnerUnchanged( ICollectionSnapshot snapshot, CollectionPersister persister, object id ) { return IsCollectionSnapshotValid( snapshot ) && --- 1306,1310 ---- } ! internal static bool IsOwnerUnchanged( ICollectionSnapshot snapshot, ICollectionPersister persister, object id ) { return IsCollectionSnapshotValid( snapshot ) && *************** *** 1884,1887 **** --- 1884,1888 ---- IClassPersister persister = e.Persister; + ISoftLock myLock = null; if( lockMode.GreaterThan( e.LockMode ) ) *************** *** 1899,1903 **** if( persister.HasCache ) { ! persister.Cache.Lock( e.Id ); } try --- 1900,1904 ---- if( persister.HasCache ) { ! myLock = persister.Cache.Lock( e.Id ); } try *************** *** 1916,1920 **** if( persister.HasCache ) { ! persister.Cache.Release( e.Id ); } } --- 1917,1921 ---- if( persister.HasCache ) { ! persister.Cache.Release( e.Id, myLock ); } } *************** *** 2350,2353 **** --- 2351,2356 ---- private object DoLoad( System.Type clazz, object id, LockMode lockMode, bool allowNull ) { + ISoftLock myLock = null; + if( log.IsDebugEnabled ) { *************** *** 2362,2366 **** if( persister.HasCache ) { ! persister.Cache.Lock( id ); } //increments the lock object result; --- 2365,2369 ---- if( persister.HasCache ) { ! myLock = persister.Cache.Lock( id ); } //increments the lock object result; *************** *** 2375,2379 **** if( persister.HasCache ) { ! persister.Cache.Release( id ); } } --- 2378,2382 ---- if( persister.HasCache ) { ! persister.Cache.Release( id, myLock ); } } *************** *** 3407,3411 **** ce.reached = true; ! CollectionPersister persister = GetCollectionPersister( ( ( PersistentCollectionType ) type ).Role ); ce.currentPersister = persister; ce.currentKey = GetEntityIdentifier( owner ); --- 3410,3414 ---- ce.reached = true; ! ICollectionPersister persister = GetCollectionPersister( ( ( PersistentCollectionType ) type ).Role ); ce.currentPersister = persister; ce.currentKey = GetEntityIdentifier( owner ); *************** *** 3566,3570 **** /// <param name="id"></param> /// <returns></returns> ! public PersistentCollection GetLoadingCollection( CollectionPersister persister, object id ) { LoadingCollectionEntry lce = ( LoadingCollectionEntry ) loadingCollections[ id ]; --- 3569,3573 ---- /// <param name="id"></param> /// <returns></returns> ! public PersistentCollection GetLoadingCollection( ICollectionPersister persister, object id ) { LoadingCollectionEntry lce = ( LoadingCollectionEntry ) loadingCollections[ id ]; *************** *** 3594,3598 **** if( loadingRole != null ) { ! CollectionPersister persister = GetCollectionPersister( loadingRole ); foreach( LoadingCollectionEntry lce in loadingCollections.Values ) { --- 3597,3601 ---- if( loadingRole != null ) { ! ICollectionPersister persister = GetCollectionPersister( loadingRole ); foreach( LoadingCollectionEntry lce in loadingCollections.Values ) { *************** *** 3645,3649 **** collectionEntries[collection] = entry; ! CollectionKey ck = new CollectionKey(entry.loadedPersister, key); PersistentCollection old = (PersistentCollection) collectionsByKey[ck]; collectionsByKey[ck] = collection; --- 3648,3652 ---- collectionEntries[collection] = entry; ! CollectionKey ck = new CollectionKey( entry.loadedPersister, key); PersistentCollection old = (PersistentCollection) collectionsByKey[ck]; collectionsByKey[ck] = collection; *************** *** 3705,3709 **** /// <param name="persister"></param> /// <param name="id"></param> ! private void AddUninitializedCollection( PersistentCollection collection, CollectionPersister persister, object id ) { CollectionEntry ce = new CollectionEntry( persister, id, flushing ); --- 3708,3712 ---- /// <param name="persister"></param> /// <param name="id"></param> ! private void AddUninitializedCollection( PersistentCollection collection, ICollectionPersister persister, object id ) { CollectionEntry ce = new CollectionEntry( persister, id, flushing ); *************** *** 3712,3716 **** } ! private void AddUninitializedDetachedCollection( PersistentCollection collection, CollectionPersister persister, object id ) { CollectionEntry ce = new CollectionEntry( persister, id ); --- 3715,3719 ---- } ! private void AddUninitializedDetachedCollection( PersistentCollection collection, ICollectionPersister persister, object id ) { CollectionEntry ce = new CollectionEntry( persister, id ); *************** *** 3725,3729 **** /// <param name="persister"></param> /// <param name="id"></param> ! public void AddInitializedCollection( PersistentCollection collection, CollectionPersister persister, object id ) { CollectionEntry ce = new CollectionEntry( persister, id, flushing ); --- 3728,3732 ---- /// <param name="persister"></param> /// <param name="id"></param> ! public void AddInitializedCollection( PersistentCollection collection, ICollectionPersister persister, object id ) { CollectionEntry ce = new CollectionEntry( persister, id, flushing ); *************** *** 3747,3751 **** /// <param name="collection"></param> /// <param name="persister"></param> ! internal void AddNewCollection(PersistentCollection collection, CollectionPersister persister) { CollectionEntry ce = AddCollection(collection); --- 3750,3754 ---- /// <param name="collection"></param> /// <param name="persister"></param> ! internal void AddNewCollection(PersistentCollection collection, ICollectionPersister persister) { CollectionEntry ce = AddCollection(collection); *************** *** 3794,3798 **** } ! internal CollectionPersister GetCollectionPersister( string role ) { return factory.GetCollectionPersister( role ); --- 3797,3801 ---- } ! internal ICollectionPersister GetCollectionPersister( string role ) { return factory.GetCollectionPersister( role ); *************** *** 3880,3886 **** { log.Debug("collection not cached"); ! CollectionPersister persister = ce.loadedPersister; object id = ce.loadedKey; - object owner = GetEntity( new Key( id, GetPersister( persister.OwnerClass ) ) ); --- 3883,3888 ---- { log.Debug("collection not cached"); ! ICollectionPersister persister = ce.loadedPersister; object id = ce.loadedKey; object owner = GetEntity( new Key( id, GetPersister( persister.OwnerClass ) ) ); *************** *** 3888,3892 **** try { ! persister.Initializer.Initialize( id, collection, owner, this ); } catch( ADOException sqle ) --- 3890,3894 ---- try { ! ((CollectionPersister) persister).Initializer.Initialize( id, collection, owner, this ); } catch( ADOException sqle ) *************** *** 3911,3914 **** --- 3913,3925 ---- } log.Debug("collection initialized"); + + /* + log.Debug("collection not cached"); + ICollectionPersister persister = ce.loadedPersister; + object id = ce.loadedKey; + object owner = GetEntity( new Key( id, GetPersister( persister.OwnerClass ) ) ); + persister.Initialize( id, owner, this ); + log.Debug("collection initialized"); + */ } } *************** *** 3920,3924 **** } ! public object GetCollectionOwner(object key, CollectionPersister collectionPersister) { //TODO:give collection persister a reference to the owning class persister --- 3931,3935 ---- } ! public object GetCollectionOwner(object key, ICollectionPersister collectionPersister) { //TODO:give collection persister a reference to the owning class persister *************** *** 4220,4224 **** FilterTranslator q; ! CollectionPersister roleBeforeFlush = e.loadedPersister; if( roleBeforeFlush == null ) { //ie. it was previously unreferenced --- 4231,4235 ---- FilterTranslator q; ! ICollectionPersister roleBeforeFlush = e.loadedPersister; if( roleBeforeFlush == null ) { //ie. it was previously unreferenced *************** *** 4561,4565 **** // that references it ! CollectionPersister persister = factory.GetCollectionPersister(role); PersistentCollection collection = GetLoadingCollection(role, id); --- 4572,4576 ---- // that references it ! ICollectionPersister persister = factory.GetCollectionPersister(role); PersistentCollection collection = GetLoadingCollection(role, id); *************** *** 4602,4606 **** /// <param name="collection"></param> /// <returns><c>true</c> if the collection was initialized from the cache, otherwise <c>false</c>.</returns> ! private bool InitializeCollectionFromCache(object id, object owner, CollectionPersister persister, PersistentCollection collection) { if( persister.HasCache==false ) --- 4613,4617 ---- /// <param name="collection"></param> /// <returns><c>true</c> if the collection was initialized from the cache, otherwise <c>false</c>.</returns> ! private bool InitializeCollectionFromCache(object id, object owner, ICollectionPersister persister, PersistentCollection collection) { if( persister.HasCache==false ) Index: WrapVisitor.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/WrapVisitor.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WrapVisitor.cs 14 Feb 2005 03:31:51 -0000 1.3 --- WrapVisitor.cs 1 Mar 2005 16:24:47 -0000 1.4 *************** *** 51,55 **** } ! CollectionPersister persister = Session.GetCollectionPersister( collectionType.Role ); if( collectionType.IsArrayType ) --- 51,55 ---- } ! ICollectionPersister persister = Session.GetCollectionPersister( collectionType.Role ); if( collectionType.IsArrayType ) Index: SessionFactoryImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** SessionFactoryImpl.cs 7 Feb 2005 01:34:41 -0000 1.41 --- SessionFactoryImpl.cs 1 Mar 2005 16:24:46 -0000 1.42 *************** *** 32,36 **** /// <item> /// Caches "compiled" mappings - ie. <see cref="IClassPersister"/> ! /// and <see cref="CollectionPersister"/> /// </item> /// <item> --- 32,36 ---- /// <item> /// Caches "compiled" mappings - ie. <see cref="IClassPersister"/> ! /// and <see cref="ICollectionPersister"/> /// </item> /// <item> *************** *** 121,128 **** foreach( PersistentClass model in cfg.ClassMappings ) { ! System.Type persisterClass = model.Persister; // not used !?! IClassPersister cp; cp = PersisterFactory.Create( model, this ); ! classPersisters[ model.PersistentClazz ] = cp; // Adds the "Namespace.ClassName" (FullClassname) as a lookup to get to the Persiter. --- 121,128 ---- foreach( PersistentClass model in cfg.ClassMappings ) { ! System.Type persisterClass = model.ClassPersisterClass; // not used !?! IClassPersister cp; cp = PersisterFactory.Create( model, this ); ! classPersisters[ model.MappedClass ] = cp; // Adds the "Namespace.ClassName" (FullClassname) as a lookup to get to the Persiter. *************** *** 135,139 **** // In HQL the Imports are used to get from the Classname to the Persister. The // Imports provide the ability to jump from the Classname to the AssemblyQualifiedName. ! classPersistersByName[ model.PersistentClazz.AssemblyQualifiedName ] = cp; } --- 135,139 ---- // In HQL the Imports are used to get from the Classname to the Persister. The // Imports provide the ability to jump from the Classname to the AssemblyQualifiedName. ! classPersistersByName[ model.MappedClass.AssemblyQualifiedName ] = cp; } *************** *** 141,145 **** foreach( Mapping.Collection map in cfg.CollectionMappings ) { ! collectionPersisters[ map.Role ] = new CollectionPersister( map, cfg, this ); } --- 141,146 ---- foreach( Mapping.Collection map in cfg.CollectionMappings ) { ! //collectionPersisters[ map.Role ] = new CollectionPersister( map, cfg, this ); ! collectionPersisters[ map.Role ] = PersisterFactory.CreateCollectionPersister( cfg, map, this ); } *************** *** 531,537 **** /// <param name="role"></param> /// <returns></returns> ! public CollectionPersister GetCollectionPersister( string role ) { ! CollectionPersister result = collectionPersisters[ role ] as CollectionPersister; if( result == null ) { --- 532,538 ---- /// <param name="role"></param> /// <returns></returns> ! public ICollectionPersister GetCollectionPersister( string role ) { ! ICollectionPersister result = collectionPersisters[ role ] as ICollectionPersister; if( result == null ) { *************** *** 599,602 **** --- 600,624 ---- } + /// <summary> + /// + /// </summary> + /// <param name="objectClass"></param> + /// <returns></returns> + public string GetIdentifierPropertyName( System.Type objectClass ) + { + return GetPersister( objectClass ).IdentifierPropertyName; + } + + /// <summary> + /// + /// </summary> + /// <param name="persistentClass"></param> + /// <param name="propertyName"></param> + /// <returns></returns> + public IType GetPropertyType( System.Type persistentClass, string propertyName ) + { + return GetPersister( persistentClass ).GetPropertyType( propertyName ); + } + #region System.Runtime.Serialization.IObjectReference Members *************** *** 667,671 **** throw new HibernateException( "Query does not refer to any persistent classes: " + queryString ); } ! return GetShallowQuery( queries[ 0 ] ).NamedParameters; } --- 689,693 ---- throw new HibernateException( "Query does not refer to any persistent classes: " + queryString ); } ! return GetQuery( queries[ 0 ] ).NamedParameters; } *************** *** 701,705 **** public ICollectionMetadata GetCollectionMetadata( string roleName ) { ! return GetCollectionPersister( roleName ); } --- 723,727 ---- public ICollectionMetadata GetCollectionMetadata( string roleName ) { ! return GetCollectionPersister( roleName ) as ICollectionMetadata; } *************** *** 780,784 **** } ! foreach( CollectionPersister p in collectionPersisters.Values ) { if( p.HasCache ) --- 802,806 ---- } ! foreach( ICollectionPersister p in collectionPersisters.Values ) { if( p.HasCache ) *************** *** 832,836 **** public void EvictCollection( string roleName, object id ) { ! CollectionPersister p = GetCollectionPersister( roleName ); if( p.HasCache ) { --- 854,858 ---- public void EvictCollection( string roleName, object id ) { ! ICollectionPersister p = GetCollectionPersister( roleName ); if( p.HasCache ) { *************** *** 845,849 **** public void EvictCollection( string roleName ) { ! CollectionPersister p = GetCollectionPersister( roleName ); if( p.HasCache ) { --- 867,871 ---- public void EvictCollection( string roleName ) { ! ICollectionPersister p = GetCollectionPersister( roleName ); if( p.HasCache ) { Index: QueryImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/QueryImpl.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** QueryImpl.cs 17 Jan 2005 03:40:57 -0000 1.20 --- QueryImpl.cs 1 Mar 2005 16:24:46 -0000 1.21 *************** *** 10,786 **** namespace NHibernate.Impl { ! internal class QueryImpl : IQuery { ! private ISessionImplementor session; ! private string queryString; ! ! private RowSelection selection; ! private ArrayList values = new ArrayList( 4 ); ! private ArrayList types = new ArrayList( 4 ); ! private IDictionary namedParameters = new Hashtable( 4 ); ! private IDictionary namedParametersLists = new Hashtable( 4 ); ! private IDictionary lockModes = new Hashtable( 2 ); ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="queryString"></param> ! /// <param name="session"></param> ! public QueryImpl( string queryString, ISessionImplementor session ) ! { ! this.session = session; ! this.queryString = queryString; ! selection = new RowSelection(); ! } ! ! /// <summary></summary> ! public virtual IEnumerable Enumerable() ! { ! //TODO: see if there is a better way to implement ! QueryParameters qp = new QueryParameters( ! ( IType[ ] ) types.ToArray( typeof( IType ) ), ! ( object[ ] ) values.ToArray( typeof( object ) ), ! new Hashtable( namedParameters ), ! lockModes, ! selection ); ! ! string query = BindParameterLists( qp.NamedParameters ); ! return session.Enumerable( query, qp ); ! } ! ! /// <summary></summary> ! public IDictionary LockModes ! { ! get { return lockModes; } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="alias"></param> ! /// <param name="lockMode"></param> ! public virtual void SetLockMode( string alias, LockMode lockMode ) ! { ! lockModes[ alias ] = lockMode; ! } ! ! /// <summary></summary> ! public virtual IList List() ! { ! //TODO: see if there is a better way to implement ! QueryParameters qp = new QueryParameters( ! ( IType[ ] ) types.ToArray( typeof( IType ) ), ! ( object[ ] ) values.ToArray( typeof( object ) ), ! new Hashtable( namedParameters ), ! lockModes, ! selection ); ! ! string query = BindParameterLists( qp.NamedParameters ); ! return session.Find( query, qp ); ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="maxResults"></param> ! /// <returns></returns> ! public IQuery SetMaxResults( int maxResults ) ! { ! selection.MaxRows = maxResults; ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="timeout"></param> ! /// <returns></returns> ! public IQuery SetTimeout( int timeout ) ! { ! selection.Timeout = timeout; ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="firstResult"></param> ! /// <returns></returns> ! public IQuery SetFirstResult( int firstResult ) ! { ! selection.FirstRow = firstResult; ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <param name="type"></param> ! /// <returns></returns> ! public IQuery SetParameter( int position, object val, IType type ) ! { ! int size = values.Count; ! if( position < size ) ! { ! values[ position ] = val; ! types[ position ] = type; ! } ! else ! { ! for( int i = 0; i < position - size; i++ ) ! { ! values.Add( null ); ! types.Add( null ); ! } ! values.Add( val ); ! types.Add( type ); ! } ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <param name="type"></param> ! /// <returns></returns> ! public IQuery SetParameter( string name, object val, IType type ) ! { ! namedParameters[ name ] = new TypedValue( type, val ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetAnsiString( int position, string val ) ! { ! SetParameter( position, val, NHibernateUtil.AnsiString ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetString( int position, string val ) ! { ! SetParameter( position, val, NHibernateUtil.String ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetCharacter( int position, char val ) ! { ! SetParameter( position, val, NHibernateUtil.Character ); // ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetBoolean( int position, bool val ) ! { ! SetParameter( position, val, NHibernateUtil.Boolean ); // ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetByte( int position, byte val ) ! { ! SetParameter( position, val, NHibernateUtil.Byte ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetInt16( int position, short val ) ! { ! SetParameter( position, val, NHibernateUtil.Int16 ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetInt32( int position, int val ) ! { ! SetParameter( position, val, NHibernateUtil.Int32 ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetInt64( int position, long val ) ! { ! SetParameter( position, val, NHibernateUtil.Int64 ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetSingle( int position, float val ) ! { ! SetParameter( position, val, NHibernateUtil.Single ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetDouble( int position, double val ) ! { ! SetParameter( position, val, NHibernateUtil.Double ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetBinary( int position, byte[ ] val ) ! { ! SetParameter( position, val, NHibernateUtil.Binary ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetDecimal( int position, decimal val ) ! { ! SetParameter( position, val, NHibernateUtil.Decimal ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetDateTime( int position, DateTime val ) ! { ! SetParameter( position, val, NHibernateUtil.DateTime ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetTime( int position, DateTime val ) ! { ! SetParameter( position, val, NHibernateUtil.DateTime ); //TODO: change to time ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetTimestamp( int position, DateTime val ) ! { ! SetParameter( position, val, NHibernateUtil.Timestamp ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetEntity( int position, object val ) ! { ! SetParameter( position, val, NHibernateUtil.Entity( NHibernateProxyHelper.GetClass( val ) ) ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetEnum( int position, Enum val ) ! { ! SetParameter( position, val, NHibernateUtil.Enum( val.GetType() ) ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetAnsiString( string name, string val ) ! { ! SetParameter( name, val, NHibernateUtil.AnsiString ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetString( string name, string val ) ! { ! SetParameter( name, val, NHibernateUtil.String ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetCharacter( string name, char val ) ! { ! SetParameter( name, val, NHibernateUtil.Character ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetBoolean( string name, bool val ) ! { ! SetParameter( name, val, NHibernateUtil.Boolean ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetByte( string name, byte val ) ! { ! SetParameter( name, val, NHibernateUtil.Byte ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetInt16( string name, short val ) ! { ! SetParameter( name, val, NHibernateUtil.Int16 ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetInt32( string name, int val ) ! { ! SetParameter( name, val, NHibernateUtil.Int32 ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetInt64( string name, long val ) ! { ! SetParameter( name, val, NHibernateUtil.Int64 ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetSingle( string name, float val ) ! { ! SetParameter( name, val, NHibernateUtil.Single ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetDouble( string name, double val ) ! { ! SetParameter( name, val, NHibernateUtil.Double ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetBinary( string name, byte[ ] val ) ! { ! SetParameter( name, val, NHibernateUtil.Binary ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetDecimal( string name, decimal val ) ! { ! SetParameter( name, val, NHibernateUtil.Decimal ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetDateTime( string name, DateTime val ) ! { ! SetParameter( name, val, NHibernateUtil.DateTime ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetTime( string name, DateTime val ) ! { ! SetParameter( name, val, NHibernateUtil.DateTime ); //TODO: change to time ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetTimestamp( string name, DateTime val ) ! { ! SetParameter( name, val, NHibernateUtil.Timestamp ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetEntity( string name, object val ) ! { ! SetParameter( name, val, NHibernateUtil.Entity( NHibernateProxyHelper.GetClass( val ) ) ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetEnum( string name, Enum val ) ! { ! SetParameter( name, val, NHibernateUtil.Enum( val.GetType() ) ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetParameter( string name, object val ) ! { ! SetParameter( name, val, GuessType( val ) ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="position"></param> ! /// <param name="val"></param> ! /// <returns></returns> ! public IQuery SetParameter( int position, object val ) ! { ! SetParameter( position, val, GuessType( val ) ); ! return this; ! } ! ! private IType GuessType( object param ) ! { ! System.Type clazz = NHibernateProxyHelper.GetClass( param ); ! return GuessType( clazz ); ! } ! ! private IType GuessType( System.Type clazz ) ! { ! string typename = clazz.AssemblyQualifiedName; ! IType type = TypeFactory.HueristicType( typename ); ! bool serializable = type != null && type is SerializableType; ! if( type == null || serializable ) ! { ! try ! { ! session.Factory.GetPersister( clazz ); ! } ! catch( MappingException ) ! { ! if( serializable ) ! { ! return type; ! } ! else ! { ! throw new HibernateException( "Could not determine a type for class: " + typename ); ! } ! } ! return NHibernateUtil.Entity( clazz ); ! } ! else ! { ! return type; ! } ! } ! ! /// <summary></summary> ! public IType[ ] ReturnTypes ! { ! get { return session.Factory.GetReturnTypes( queryString ); } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="vals"></param> ! /// <param name="type"></param> ! /// <returns></returns> ! public IQuery SetParameterList( string name, ICollection vals, IType type ) ! { ! namedParametersLists.Add( name, new TypedValue( type, vals ) ); ! return this; ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="namedParams"></param> ! /// <returns></returns> ! protected string BindParameterLists( IDictionary namedParams ) ! { ! string query = queryString; ! foreach( DictionaryEntry de in namedParametersLists ) ! { ! query = BindParameterList( query, ( string ) de.Key, ( TypedValue ) de.Value, namedParams ); ! } ! return query; ! } ! ! private string BindParameterList( string queryString, string name, TypedValue typedList, IDictionary namedParams ) ! { ! ICollection vals = ( ICollection ) typedList.Value; ! IType type = typedList.Type; ! StringBuilder list = new StringBuilder( 16 ); ! int i = 0; ! foreach( object obj in vals ) ! { ! string alias = name + i++ + StringHelper.Underscore; ! namedParams.Add( alias, new TypedValue( type, obj ) ); ! list.Append( ':' + alias ); ! if( i < vals.Count ) ! { ! list.Append( StringHelper.CommaSpace ); ! } ! } ! ! return StringHelper.Replace( queryString, ':' + name, list.ToString() ); ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="vals"></param> ! /// <returns></returns> ! public IQuery SetParameterList( string name, ICollection vals ) ! { ! foreach( object obj in vals ) ! { ! SetParameterList( name, vals, GuessType( obj ) ); ! break; // fairly hackish...need the type of the first object ! } ! return this; ! } ! ! /// <summary></summary> ! public string[ ] NamedParameters ! { ! get ! { ! ICollection parms = session.Factory.GetNamedParameters( queryString ); ! string[ ] retVal = new String[parms.Count]; ! int i = 0; ! foreach( string parm in parms ) ! { ! retVal[ i++ ] = parm; ! } ! return retVal; ! } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="bean"></param> ! /// <returns></returns> ! public IQuery SetProperties( object bean ) ! { ! System.Type clazz = bean.GetType(); ! foreach( string namedParam in session.Factory.GetNamedParameters( queryString ) ) ! { ! try ! { ! IGetter getter = ReflectHelper.GetGetter( clazz, namedParam ); ! SetParameter( namedParam, getter.Get( bean ), GuessType( getter.ReturnType ) ); ! } ! catch( Exception ) ! { ! } ! } ! return this; ! } ! ! /// <summary></summary> ! internal ISessionImplementor Session ! { ! get { return session; } ! } ! ! /// <summary></summary> ! internal ArrayList Values ! { ! get { return values; } ! } ! ! /// <summary></summary> ! internal ArrayList Types ! { ! get { return types; } ! } ! ! internal RowSelection Selection { - get { return selection; } } ! /// <summary></summary> ! public string QueryString { ! get { return queryString; } } /// <summary></summary> ! internal IDictionary NamedParams ! { ! get { return namedParameters; } ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="name"></param> ! /// <param name="vals"></param> ! /// <param name="type"></param> ! /// <returns></returns> ! public IQuery SetParameterList( string name, object[ ] vals, IType type ) ! { ! return SetParameterList( name, vals, type ); ! } ! ! // ! public IQuery SetParameterList( string name, object[ ] vals ) { ! return SetParameterList( name, vals ); } - } } \ No newline at end of file --- 10,34 ---- namespace NHibernate.Impl { ! internal class QueryImpl : AbstractQueryImpl { ! public QueryImpl( string queryString, ISessionImplementor session ) : base( queryString, session ) { } ! /// <summary></summary> ! public override IEnumerable Enumerable() { ! VerifyParameters(); ! IDictionary namedParams = NamedParams; ! return Session.Enumerable( BindParameterLists( namedParams ), QueryParams( namedParams ) ); } /// <summary></summary> ! public override IList List() { ! VerifyParameters(); ! IDictionary namedParams = NamedParams; ! return Session.Find( BindParameterLists( namedParams ), QueryParams( namedParams ) ); } } } \ No newline at end of file Index: ScheduledCollectionRecreate.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledCollectionRecreate.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ScheduledCollectionRecreate.cs 31 Dec 2004 19:52:53 -0000 1.5 --- ScheduledCollectionRecreate.cs 1 Mar 2005 16:24:46 -0000 1.6 *************** *** 15,22 **** /// </summary> /// <param name="collection">The <see cref="PersistentCollection"/> to recreate.</param> ! /// <param name="persister">The <see cref="CollectionPersister"/> that is responsible for the persisting the Collection.</param> /// <param name="id">The identifier of the Collection owner.</param> /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> ! public ScheduledCollectionRecreate( PersistentCollection collection, CollectionPersister persister, object id, ISessionImplementor session ) : base( persister, id, session ) { --- 15,22 ---- /// </summary> /// <param name="collection">The <see cref="PersistentCollection"/> to recreate.</param> ! /// <param name="persister">The <see cref="ICollectionPersister"/> that is responsible for the persisting the Collection.</param> /// <param name="id">The identifier of the Collection owner.</param> /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> ! public ScheduledCollectionRecreate( PersistentCollection collection, ICollectionPersister persister, object id, ISessionImplementor session ) : base( persister, id, session ) { *************** *** 27,32 **** public override void Execute() { - Persister.Softlock( Id ); Persister.Recreate( _collection, Id, Session ); } } --- 27,33 ---- public override void Execute() { Persister.Recreate( _collection, Id, Session ); + // TODO: Commented out as isn't in the 2.1 implementation - test + //Persister.Softlock( Id ); } } Index: OnUpdateVisitor.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/OnUpdateVisitor.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OnUpdateVisitor.cs 7 Feb 2005 01:34:41 -0000 1.2 --- OnUpdateVisitor.cs 1 Mar 2005 16:24:46 -0000 1.3 *************** *** 38,42 **** protected override object ProcessCollection(object collection, PersistentCollectionType type) { ! CollectionPersister persister = Session.GetCollectionPersister( type.Role ); if( collection is PersistentCollection ) --- 38,42 ---- protected override object ProcessCollection(object collection, PersistentCollectionType type) { ! ICollectionPersister persister = Session.GetCollectionPersister( type.Role ); if( collection is PersistentCollection ) Index: FilterImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/FilterImpl.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** FilterImpl.cs 31 Dec 2004 19:51:30 -0000 1.9 --- FilterImpl.cs 1 Mar 2005 16:24:46 -0000 1.10 *************** *** 26,37 **** public override IEnumerable Enumerable() { ! //TODO: see if there is a better way to implement ! QueryParameters qp = new QueryParameters( TypeArray(), ValueArray() ); ! qp.NamedParameters = new Hashtable( NamedParams ); ! qp.RowSelection = Selection; ! qp.LockModes = LockModes; ! ! string query = BindParameterLists( qp.NamedParameters ); ! return Session.EnumerableFilter( collection, query, qp ); } --- 26,33 ---- public override IEnumerable Enumerable() { ! // HACK: Reintroduce once Filter parsing bug resolved ! //VerifyParameters(); ! IDictionary namedParams = NamedParams; ! return Session.EnumerableFilter( collection, BindParameterLists( namedParams ), QueryParams( namedParams ) ); } *************** *** 39,53 **** public override IList List() { ! //TODO: see if there is a better way to implement ! QueryParameters qp = new QueryParameters( TypeArray(), ValueArray() ); ! qp.NamedParameters = new Hashtable( NamedParams ); ! qp.RowSelection = Selection; ! qp.LockModes = LockModes; ! ! string query = BindParameterLists( qp.NamedParameters ); ! return Session.Filter( collection, query, qp ); } ! private IType[ ] TypeArray() { IList typeList = Types; --- 35,45 ---- public override IList List() { ! // HACK: Reintroduce once Filter parsing bug resolved ! //VerifyParameters(); ! IDictionary namedParams = NamedParams; ! return Session.Filter( collection, BindParameterLists( namedParams ), QueryParams( namedParams ) ); } ! protected override IType[ ] TypeArray() { IList typeList = Types; *************** *** 61,65 **** } ! private object[ ] ValueArray() { IList valueList = Values; --- 53,57 ---- } ! protected override object[ ] ValueArray() { IList valueList = Values; Index: MessageHelper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/MessageHelper.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MessageHelper.cs 23 Jan 2005 15:50:21 -0000 1.5 --- MessageHelper.cs 1 Mar 2005 16:24:46 -0000 1.6 *************** *** 110,114 **** /// <param name="id"></param> /// <returns></returns> ! public static String InfoString( CollectionPersister persister, object id ) { StringBuilder s = new StringBuilder(); --- 110,114 ---- /// <param name="id"></param> /// <returns></returns> ! public static String InfoString( ICollectionPersister persister, object id ) { StringBuilder s = new StringBuilder(); Index: ScheduledDeletion.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledDeletion.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ScheduledDeletion.cs 31 Dec 2004 19:53:33 -0000 1.5 --- ScheduledDeletion.cs 1 Mar 2005 16:24:46 -0000 1.6 *************** *** 1,2 **** --- 1,3 ---- + using NHibernate.Cache; using NHibernate.Engine; using NHibernate.Persister; *************** *** 10,13 **** --- 11,15 ---- { private object _version; + private ISoftLock _lock; /// <summary> *************** *** 30,34 **** if( Persister.HasCache ) { ! Persister.Cache.Lock( Id ); } Persister.Delete( Id, _version, Instance, Session ); --- 32,36 ---- if( Persister.HasCache ) { ! _lock = Persister.Cache.Lock( Id ); } Persister.Delete( Id, _version, Instance, Session ); *************** *** 41,45 **** if( Persister.HasCache ) { ! Persister.Cache.Release( Id ); } } --- 43,47 ---- if( Persister.HasCache ) { ! Persister.Cache.Release( Id, _lock ); } } Index: OnLockVisitor.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/OnLockVisitor.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OnLockVisitor.cs 7 Feb 2005 01:34:41 -0000 1.2 --- OnLockVisitor.cs 1 Mar 2005 16:24:46 -0000 1.3 *************** *** 22,26 **** protected override object ProcessCollection(object collection, PersistentCollectionType type) { ! CollectionPersister persister = Session.GetCollectionPersister( type.Role ); if( collection == null ) --- 22,26 ---- protected override object ProcessCollection(object collection, PersistentCollectionType type) { ! ICollectionPersister persister = Session.GetCollectionPersister( type.Role ); if( collection == null ) Index: ScheduledCollectionAction.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledCollectionAction.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ScheduledCollectionAction.cs 31 Dec 2004 19:52:43 -0000 1.9 --- ScheduledCollectionAction.cs 1 Mar 2005 16:24:46 -0000 1.10 *************** *** 1,2 **** --- 1,3 ---- + using NHibernate.Cache; using NHibernate.Collection; using NHibernate.Engine; *************** *** 10,24 **** internal abstract class ScheduledCollectionAction : IExecutable { ! private CollectionPersister _persister; private object _id; private ISessionImplementor _session; /// <summary> /// Initializes a new instance of <see cref="ScheduledCollectionAction"/>. /// </summary> ! /// <param name="persister">The <see cref="CollectionPersister"/> that is responsible for the persisting the Collection.</param> /// <param name="id">The identifier of the Collection owner.</param> /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> ! public ScheduledCollectionAction( CollectionPersister persister, object id, ISessionImplementor session ) { _persister = persister; --- 11,26 ---- internal abstract class ScheduledCollectionAction : IExecutable { ! private ICollectionPersister _persister; private object _id; private ISessionImplementor _session; + private ISoftLock _lock = null; /// <summary> /// Initializes a new instance of <see cref="ScheduledCollectionAction"/>. /// </summary> ! /// <param name="persister">The <see cref="ICollectionPersister"/> that is responsible for the persisting the Collection.</param> /// <param name="id">The identifier of the Collection owner.</param> /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> ! public ScheduledCollectionAction( ICollectionPersister persister, object id, ISessionImplementor session ) { _persister = persister; *************** *** 28,34 **** /// <summary> ! /// Gets the <see cref="CollectionPersister"/> that is responsible for persisting the Collection. /// </summary> ! public CollectionPersister Persister { get { return _persister; } --- 30,36 ---- /// <summary> ! /// Gets the <see cref="ICollectionPersister"/> that is responsible for persisting the Collection. /// </summary> ! public ICollectionPersister Persister { get { return _persister; } *************** *** 56,60 **** public void AfterTransactionCompletion() { ! _persister.ReleaseSoftlock( _id ); } --- 58,65 ---- public void AfterTransactionCompletion() { ! if ( _persister.HasCache ) ! { ! _persister.Cache.Release( _id, _lock ); ! } } *************** *** 64,68 **** public object[ ] PropertySpaces { ! get { return new string[ ] {_persister.QualifiedTableName}; } //TODO: cache the array on the persister } --- 69,73 ---- public object[ ] PropertySpaces { ! get { return new object[ ] {_persister.CollectionSpace}; } //TODO: cache the array on the persister } Index: CollectionKey.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/CollectionKey.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CollectionKey.cs 7 Feb 2005 01:34:40 -0000 1.2 --- CollectionKey.cs 1 Mar 2005 16:24:46 -0000 1.3 *************** *** 11,15 **** private object key; ! public CollectionKey(string role, object key) { this.role = role; --- 11,15 ---- private object key; ! public CollectionKey( string role, object key ) { this.role = role; *************** *** 17,22 **** } ! public CollectionKey(CollectionPersister persister, object key) ! : this(persister.Role, key) { } --- 17,22 ---- } ! public CollectionKey( ICollectionPersister persister, object key ) ! : this( persister.Role, key ) { } --- NEW FILE: AbstractQueryImpl.cs --- using System; using System.Collections; using System.Text; using Iesi.Collections; using NHibernate.Engine; using NHibernate.Property; using NHibernate.Proxy; using NHibernate.Type; using NHibernate.Util; namespace NHibernate.Impl { /// <summary> /// Abstract implementation of the IQuery interface. /// </summary> internal abstract class AbstractQueryImpl : IQuery { private string queryString; private IDictionary lockModes = new Hashtable( 2 ); private ISessionImplementor session; private RowSelection selection; private ArrayList values = new ArrayList( 4 ); private ArrayList types = new ArrayList( 4 ); private int positionalParameterCount = 0; private ISet actualNamedParameters; private IDictionary namedParameters = new Hashtable( 4 ); private IDictionary namedParametersLists = new Hashtable( 4 ); private static readonly object UNSET_PARAMETER = new Object(); private static readonly object UNSET_TYPE = new Object(); /// <summary> /// /// </summary> /// <param name="queryString"></param> /// <param name="session"></param> public AbstractQueryImpl( string queryString, ISessionImplementor session ) { this.session = session; this.queryString = queryString; selection = new RowSelection(); InitParameterBookKeeping(); } protected void VerifyParameters() { actualNamedParameters = new ListSet( session.Factory.GetNamedParameters( queryString ) ); if ( actualNamedParameters.Count != namedParameters.Count + namedParametersLists.Count ) { Set missingParams = new ListSet( actualNamedParameters ); missingParams.RemoveAll( namedParametersLists.Keys ); missingParams.RemoveAll( namedParameters.Keys ); throw new QueryException( "Not all named parameters have been set: " + missingParams ) ; } if ( positionalParameterCount != values.Count ) throw new QueryException( string.Format( "Not all positional parameters have been set. Expected {0}, set {1}.", positionalParameterCount, values.Count ) ); for ( int i = 0; i < values.Count; i++ ) { if ( values[i] == UNSET_PARAMETER || types[i] == UNSET_TYPE ) throw new QueryException( string.Format( "Not all positional parameters have been set. Found unset parameter at position {0}.", i) ); } } // Leave it to the kids to do public abstract IEnumerable Enumerable(); /// <summary></summary> public IDictionary LockModes { get { return lockModes; } } /// <summary> /// /// </summary> /// <param name="alias"></param> /// <param name="lockMode"></param> public virtual void SetLockMode( string alias, LockMode lockMode ) { lockModes[ alias ] = lockMode; } protected virtual IType[] TypeArray() { return ( IType[ ] ) types.ToArray( typeof( IType ) ); } protected virtual object[] ValueArray() { return ( object[ ] ) values.ToArray( typeof( object ) ); } protected QueryParameters QueryParams( IDictionary namedParams ) { return new QueryParameters( TypeArray(), ValueArray(), namedParams, lockModes, selection ); } // Leave it to the kids to do public abstract IList List(); /// <summary> /// /// </summary> /// <param name="maxResults"></param> /// <returns></returns> public IQuery SetMaxResults( int maxResults ) { selection.MaxRows = maxResults; return this; } /// <summary> /// /// </summary> /// <param name="timeout"></param> /// <returns></returns> public IQuery SetTimeout( int timeout ) { selection.Timeout = timeout; return this; } /// <summary> /// /// </summary> /// <param name="firstResult"></param> /// <returns></returns> public IQuery SetFirstResult( int firstResult ) { selection.FirstRow = firstResult; return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <param name="type"></param> /// <returns></returns> public IQuery SetParameter( int position, object val, IType type ) { if ( positionalParameterCount == 0 ) throw new ArgumentOutOfRangeException( string.Format( "No positional parameters in query: {0}", queryString ) ); if ( position < 0 || position > positionalParameterCount - 1 ) throw new ArgumentOutOfRangeException( string.Format( "Positional parameter does not exists: {0} in query: {1}", position, queryString ) ); int size = values.Count; if ( position < size ) { values[ position ] = val; types[ position ] = type; } else { // Put guard values in for any positions before the wanted position - allows us to detect unset parameters on validate. for( int i = 0; i < position - size; i++ ) { values.Add( UNSET_PARAMETER ); types.Add( UNSET_TYPE ); } values.Add( val ); types.Add( type ); } return this; } /// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="val"></param> /// <param name="type"></param> /// <returns></returns> public IQuery SetParameter( string name, object val, IType type ) { namedParameters[ name ] = new TypedValue( type, val ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetAnsiString( int position, string val ) { SetParameter( position, val, NHibernateUtil.AnsiString ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetString( int position, string val ) { SetParameter( position, val, NHibernateUtil.String ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetCharacter( int position, char val ) { SetParameter( position, val, NHibernateUtil.Character ); // ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetBoolean( int position, bool val ) { SetParameter( position, val, NHibernateUtil.Boolean ); // ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetByte( int position, byte val ) { SetParameter( position, val, NHibernateUtil.Byte ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetInt16( int position, short val ) { SetParameter( position, val, NHibernateUtil.Int16 ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetInt32( int position, int val ) { SetParameter( position, val, NHibernateUtil.Int32 ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetInt64( int position, long val ) { SetParameter( position, val, NHibernateUtil.Int64 ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetSingle( int position, float val ) { SetParameter( position, val, NHibernateUtil.Single ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetDouble( int position, double val ) { SetParameter( position, val, NHibernateUtil.Double ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetBinary( int position, byte[ ] val ) { SetParameter( position, val, NHibernateUtil.Binary ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetDecimal( int position, decimal val ) { SetParameter( position, val, NHibernateUtil.Decimal ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetDateTime( int position, DateTime val ) { SetParameter( position, val, NHibernateUtil.DateTime ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetTime( int position, DateTime val ) { SetParameter( position, val, NHibernateUtil.DateTime ); //TODO: change to time return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetTimestamp( int position, DateTime val ) { SetParameter( position, val, NHibernateUtil.Timestamp ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetEntity( int position, object val ) { SetParameter( position, val, NHibernateUtil.Entity( NHibernateProxyHelper.GetClass( val ) ) ); return this; } /// <summary> /// /// </summary> /// <param name="position"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetEnum( int position, Enum val ) { SetParameter( position, val, NHibernateUtil.Enum( val.GetType() ) ); return this; } /// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetAnsiString( string name, string val ) { SetParameter( name, val, NHibernateUtil.AnsiString ); return this; } /// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetString( string name, string val ) { SetParameter( name, val, NHibernateUtil.String ); return this; } /// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="val"></param> /// <returns></returns> public IQuery SetCharacter( string name, char val ) { SetParameter( name, val, NHibernateUtil.Character ); return this; } ///... [truncated message content] |