1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Facilities
.ActiveRecordIntegration
18 using System
.Collections
;
22 using NHibernate
.Stat
;
23 using NHibernate
.Type
;
25 using Castle
.ActiveRecord
.Framework
;
28 /// This class implements <see cref="ISession"/>
29 /// and delegates <see cref="Close"/> and
30 /// <see cref="Dispose"/> to <see cref="ISessionFactoryHolder.ReleaseSession"/>
31 /// as the session is in fact managed by ActiveRecord framework
33 public class SafeSessionProxy
: ISession
, IDisposable
35 private readonly ISession innerSession
;
36 private readonly ISessionFactoryHolder holder
;
38 private bool wasClosed
;
41 /// Initializes a new instance of the <see cref="SafeSessionProxy"/> class.
43 /// <param name="holder">The holder.</param>
44 /// <param name="innerSession">The inner session.</param>
45 public SafeSessionProxy(ISessionFactoryHolder holder
, ISession innerSession
)
47 if (innerSession
== null) throw new ArgumentNullException("innerSession");
49 this.innerSession
= innerSession
;
54 /// Determines at which points Hibernate automatically flushes the session.
58 /// For a readonly session, it is reasonable to set the flush mode to <c>FlushMode.Never</c>
59 /// at the start of the session (in order to achieve some extra performance).
61 public FlushMode FlushMode
63 get { return innerSession.FlushMode; }
64 set { innerSession.FlushMode = value; }
68 /// Get the <see cref="T:NHibernate.ISessionFactory"/> that created this instance.
71 public ISessionFactory SessionFactory
73 get { return innerSession.SessionFactory; }
77 /// Gets the ADO.NET connection.
81 /// Applications are responsible for calling commit/rollback upon the connection before
82 /// closing the <c>ISession</c>.
84 public IDbConnection Connection
86 get { return innerSession.Connection; }
90 /// Is the <c>ISession</c> still open?
95 get { return innerSession.IsOpen; }
99 /// Is the <c>ISession</c> currently connected?
102 public bool IsConnected
104 get { return innerSession.IsConnected; }
108 /// Get the current Unit of Work and return the associated <c>ITransaction</c> object.
111 public ITransaction Transaction
113 get { return innerSession.Transaction; }
117 /// Force the <c>ISession</c> to flush.
120 /// Must be called at the end of a unit of work, before commiting the transaction and closing
121 /// the session (<c>Transaction.Commit()</c> calls this method). <i>Flushing</i> if the process
122 /// of synchronising the underlying persistent store with persistable state held in memory.
126 innerSession
.Flush();
130 /// Disconnect the <c>ISession</c> from the current ADO.NET connection.
133 /// The connection provided by the application or <see langword="null"/>
136 /// If the connection was obtained by Hibernate, close it or return it to the connection
137 /// pool. Otherwise return it to the application. This is used by applications which require
138 /// long transactions.
140 public IDbConnection
Disconnect()
142 return innerSession
.Disconnect();
146 /// Obtain a new ADO.NET connection.
149 /// This is used by applications which require long transactions
151 public void Reconnect()
153 innerSession
.Reconnect();
157 /// Reconnect to the given ADO.NET connection.
159 /// <param name="connection">An ADO.NET connection</param>
160 /// <remarks>This is used by applications which require long transactions</remarks>
161 public void Reconnect(IDbConnection connection
)
163 innerSession
.Reconnect(connection
);
167 /// End the <c>ISession</c> by disconnecting from the ADO.NET connection and cleaning up.
170 /// The connection provided by the application or <see langword="null"/>
173 /// It is not strictly necessary to <c>Close()</c> the <c>ISession</c> but you must
174 /// at least <c>Disconnect()</c> it.
176 public IDbConnection
Close()
181 holder
.ReleaseSession( innerSession
);
186 throw new InvalidOperationException("Session was closed");
191 /// Cancel execution of the current query.
194 /// May be called from one thread to stop execution of a query in another thread.
197 public void CancelQuery()
199 innerSession
.CancelQuery();
203 /// Does this <c>ISession</c> contain any changes which must be
204 /// synchronized with the database? Would any SQL be executed if
205 /// we flushed this session?
207 /// <returns></returns>
208 public bool IsDirty()
210 return innerSession
.IsDirty();
214 /// Return the identifier of an entity instance cached by the <c>ISession</c>
216 /// <param name="obj">a persistent instance</param>
217 /// <returns>the identifier</returns>
219 /// Throws an exception if the instance is transient or associated with a different
222 public object GetIdentifier(object obj
)
224 return innerSession
.GetIdentifier(obj
);
228 /// Is this instance associated with this Session?
230 /// <param name="obj">an instance of a persistent class</param>
232 /// true if the given instance is associated with this Session
234 public bool Contains(object obj
)
236 return innerSession
.Contains(obj
);
240 /// Remove this instance from the session cache.
242 /// <param name="obj">a persistent instance</param>
244 /// Changes to the instance will not be synchronized with the database.
245 /// This operation cascades to associated instances if the association is mapped
246 /// with <c>cascade="all"</c> or <c>cascade="all-delete-orphan"</c>.
248 public void Evict(object obj
)
250 innerSession
.Evict(obj
);
254 /// Return the persistent instance of the given entity class with the given identifier,
255 /// obtaining the specified lock mode.
257 /// <param name="theType">A persistent class</param>
258 /// <param name="id">A valid identifier of an existing persistent instance of the class</param>
259 /// <param name="lockMode">The lock level</param>
260 /// <returns>the persistent instance</returns>
261 public object Load(Type theType
, object id
, LockMode lockMode
)
263 return innerSession
.Load(theType
, id
, lockMode
);
267 /// Return the persistent instance of the given entity class with the given identifier,
268 /// assuming that the instance exists.
270 /// <param name="theType">A persistent class</param>
271 /// <param name="id">A valid identifier of an existing persistent instance of the class</param>
272 /// <returns>The persistent instance or proxy</returns>
274 /// You should not use this method to determine if an instance exists (use a query or
275 /// <see cref="M:NHibernate.ISession.Get(System.Type,System.Object)"/> instead). Use this only to retrieve an instance
276 /// that you assume exists, where non-existence would be an actual error.
278 public object Load(Type theType
, object id
)
280 return innerSession
.Load(theType
, id
);
284 /// Loads the specified id.
286 /// <typeparam name="T"></typeparam>
287 /// <param name="id">The id.</param>
288 /// <param name="lockMode">The lock mode.</param>
289 /// <returns></returns>
290 public T Load
<T
>(object id
, LockMode lockMode
)
292 return innerSession
.Load
<T
>(id
, lockMode
);
296 /// Loads the specified id.
298 /// <typeparam name="T"></typeparam>
299 /// <param name="id">The id.</param>
300 /// <returns></returns>
301 public T Load
<T
>(object id
)
303 return innerSession
.Load
<T
>(id
);
307 /// Read the persistent state associated with the given identifier into the given transient
310 /// <param name="obj">An "empty" instance of the persistent class</param>
311 /// <param name="id">A valid identifier of an existing persistent instance of the class</param>
312 public void Load(object obj
, object id
)
314 innerSession
.Load(obj
, id
);
318 /// Return the persistent instance of the given entity class with the given identifier, or null
319 /// if there is no such persistent instance. (If the instance, or a proxy for the instance, is
320 /// already associated with the session, return that instance or proxy.)
322 /// <param name="clazz">a persistent class</param>
323 /// <param name="id">an identifier</param>
324 /// <returns>a persistent instance or null</returns>
325 public object Get(Type clazz
, object id
)
327 return innerSession
.Get(clazz
, id
);
331 /// Return the persistent instance of the given entity class with the given identifier, or null
332 /// if there is no such persistent instance. Obtain the specified lock mode if the instance
335 /// <param name="clazz">a persistent class</param>
336 /// <param name="id">an identifier</param>
337 /// <param name="lockMode">the lock mode</param>
338 /// <returns>a persistent instance or null</returns>
339 public object Get(Type clazz
, object id
, LockMode lockMode
)
341 return innerSession
.Get(clazz
, id
, lockMode
);
345 /// Return the persistent instance of the given named entity with the given identifier,
346 /// or null if there is no such persistent instance. (If the instance, or a proxy for the
347 /// instance, is already associated with the session, return that instance or proxy.)
349 /// <param name="entityName">the entity name </param>
350 /// <param name="id">an identifier </param>
351 /// <returns> a persistent instance or null </returns>
352 public object Get(string entityName
, object id
)
354 return innerSession
.Get(entityName
, id
);
358 /// Gets the specified id.
360 /// <typeparam name="T"></typeparam>
361 /// <param name="id">The id.</param>
362 /// <returns></returns>
363 public T Get
<T
>(object id
)
365 return innerSession
.Get
<T
>(id
);
369 /// Gets the specified id.
371 /// <typeparam name="T"></typeparam>
372 /// <param name="id">The id.</param>
373 /// <param name="lockMode">The lock mode.</param>
374 /// <returns></returns>
375 public T Get
<T
>(object id
, LockMode lockMode
)
377 return innerSession
.Get
<T
>(id
, lockMode
);
381 /// Enable the named filter for this current session.
383 /// <param name="filterName">The name of the filter to be enabled.</param>
385 /// The Filter instance representing the enabled fiter.
387 public IFilter
EnableFilter(string filterName
)
389 return innerSession
.EnableFilter(filterName
);
393 /// Retrieve a currently enabled filter by name.
395 /// <param name="filterName">The name of the filter to be retrieved.</param>
397 /// The Filter instance representing the enabled fiter.
399 public IFilter
GetEnabledFilter(string filterName
)
401 return innerSession
.GetEnabledFilter(filterName
);
405 /// Disable the named filter for the current session.
407 /// <param name="filterName">The name of the filter to be disabled.</param>
408 public void DisableFilter(string filterName
)
410 innerSession
.DisableFilter(filterName
);
414 /// Create a multi query, a query that can send several
415 /// queries to the server, and return all their results in a single
419 /// An <see cref="T:NHibernate.IMultiQuery"/> that can return
420 /// a list of all the results of all the queries.
421 /// Note that each query result is itself usually a list.
423 public IMultiQuery
CreateMultiQuery()
425 return innerSession
.CreateMultiQuery();
429 /// Persist all reachable transient objects, reusing the current identifier
430 /// values. Note that this will not trigger the Interceptor of the Session.
432 /// <param name="obj"></param>
433 /// <param name="replicationMode"></param>
434 public void Replicate(object obj
, ReplicationMode replicationMode
)
436 innerSession
.Replicate(obj
, replicationMode
);
440 /// Persist the state of the given detached instance, reusing the current
441 /// identifier value. This operation cascades to associated instances if
442 /// the association is mapped with <tt>cascade="replicate"</tt>.
444 /// <param name="entityName"></param>
445 /// <param name="obj">a detached instance of a persistent class </param>
446 /// <param name="replicationMode"></param>
447 public void Replicate(string entityName
, object obj
, ReplicationMode replicationMode
)
449 innerSession
.Replicate(entityName
, obj
, replicationMode
);
453 /// Persist the given transient instance, first assigning a generated identifier.
455 /// <param name="obj">A transient instance of a persistent class</param>
456 /// <returns>The generated identifier</returns>
458 /// Save will use the current value of the identifier property if the <c>Assigned</c>
459 /// generator is used.
461 public object Save(object obj
)
463 return innerSession
.Save(obj
);
467 /// Persist the given transient instance, using the given identifier.
469 /// <param name="obj">A transient instance of a persistent class</param>
470 /// <param name="id">An unused valid identifier</param>
471 public void Save(object obj
, object id
)
473 innerSession
.Save(obj
, id
);
477 /// Persist the given transient instance, first assigning a generated identifier. (Or
478 /// using the current value of the identifier property if the <tt>assigned</tt>
479 /// generator is used.)
481 /// <param name="entityName">The Entity name.</param>
482 /// <param name="obj">a transient instance of a persistent class </param>
483 /// <returns> the generated identifier </returns>
485 /// This operation cascades to associated instances if the
486 /// association is mapped with <tt>cascade="save-update"</tt>.
488 public object Save(string entityName
, object obj
)
490 return innerSession
.Save(entityName
, obj
);
494 /// Either <c>Save()</c> or <c>Update()</c> the given instance, depending upon the value of
495 /// its identifier property.
497 /// <param name="obj">A transient instance containing new or updated state</param>
499 /// By default the instance is always saved. This behaviour may be adjusted by specifying
500 /// an <c>unsaved-value</c> attribute of the identifier property mapping
502 public void SaveOrUpdate(object obj
)
504 innerSession
.SaveOrUpdate(obj
);
508 /// Either <see cref="Save(String,Object)"/> or <see cref="Update(String,Object)"/>
509 /// the given instance, depending upon resolution of the unsaved-value checks
510 /// (see the manual for discussion of unsaved-value checking).
512 /// <param name="entityName">The name of the entity </param>
513 /// <param name="obj">a transient or detached instance containing new or updated state </param>
514 /// <seealso cref="ISession.Save(String,Object)"/>
515 /// <seealso cref="ISession.Update(String,Object)"/>
517 /// This operation cascades to associated instances if the association is mapped
518 /// with <tt>cascade="save-update"</tt>.
520 public void SaveOrUpdate(string entityName
, object obj
)
522 innerSession
.SaveOrUpdate(entityName
, obj
);
526 /// Update the persistent instance with the identifier of the given transient instance.
528 /// <param name="obj">A transient instance containing updated state</param>
530 /// If there is a persistent instance with the same identifier, an exception is thrown. If
531 /// the given transient instance has a <see langword="null"/> identifier, an exception will be thrown.
533 public void Update(object obj
)
535 innerSession
.Update(obj
);
539 /// Update the persistent state associated with the given identifier.
541 /// <param name="obj">A transient instance containing updated state</param>
542 /// <param name="id">Identifier of persistent instance</param>
544 /// An exception is thrown if there is a persistent instance with the same identifier
545 /// in the current session.
547 public void Update(object obj
, object id
)
549 innerSession
.Update(obj
, id
);
553 /// Update the persistent instance with the identifier of the given detached
556 /// <param name="entityName">The Entity name.</param>
557 /// <param name="obj">a detached instance containing updated state </param>
559 /// If there is a persistent instance with the same identifier,
560 /// an exception is thrown. This operation cascades to associated instances
561 /// if the association is mapped with <tt>cascade="save-update"</tt>.
563 public void Update(string entityName
, object obj
)
565 innerSession
.Update(entityName
, obj
);
569 /// Copy the state of the given object onto the persistent object with the same
570 /// identifier. If there is no persistent instance currently associated with
571 /// the session, it will be loaded. Return the persistent instance. If the
572 /// given instance is unsaved, save a copy of and return it as a newly persistent
573 /// instance. The given instance does not become associated with the session.
574 /// This operation cascades to associated instances if the association is mapped
575 /// with <tt>cascade="merge"</tt>.<br/>
577 /// The semantics of this method are defined by JSR-220.
579 /// <param name="obj">a detached instance with state to be copied </param>
580 /// <returns> an updated persistent instance </returns>
581 public object Merge(object obj
)
583 return innerSession
.Merge(obj
);
587 /// Copy the state of the given object onto the persistent object with the same
588 /// identifier. If there is no persistent instance currently associated with
589 /// the session, it will be loaded. Return the persistent instance. If the
590 /// given instance is unsaved, save a copy of and return it as a newly persistent
591 /// instance. The given instance does not become associated with the session.
592 /// This operation cascades to associated instances if the association is mapped
593 /// with <tt>cascade="merge"</tt>.<br/>
595 /// The semantics of this method are defined by JSR-220.
597 /// <param name="entityName">The entity name</param>
598 /// <param name="obj">a detached instance with state to be copied </param>
599 /// <returns> an updated persistent instance </returns>
600 public object Merge(string entityName
, object obj
)
602 return innerSession
.Merge(entityName
, obj
);
606 /// Make a transient instance persistent. This operation cascades to associated
607 /// instances if the association is mapped with <tt>cascade="persist"</tt>.<br/>
609 /// The semantics of this method are defined by JSR-220.
611 /// <param name="obj">a transient instance to be made persistent </param>
612 public void Persist(object obj
)
614 innerSession
.Persist(obj
);
618 /// Make a transient instance persistent. This operation cascades to associated
619 /// instances if the association is mapped with <tt>cascade="persist"</tt>.<br/>
621 /// The semantics of this method are defined by JSR-220.
623 /// <param name="entityName">The entity name.</param>
624 /// <param name="obj">a transient instance to be made persistent </param>
625 public void Persist(string entityName
, object obj
)
627 innerSession
.Persist(entityName
, obj
);
631 /// Copy the state of the given object onto the persistent object with the same
632 /// identifier. If there is no persistent instance currently associated with
633 /// the session, it will be loaded. Return the persistent instance. If the
634 /// given instance is unsaved or does not exist in the database, save it and
635 /// return it as a newly persistent instance. Otherwise, the given instance
636 /// does not become associated with the session.
638 /// <param name="obj">a transient instance with state to be copied</param>
639 /// <returns>an updated persistent instance</returns>
640 public object SaveOrUpdateCopy(object obj
)
642 return innerSession
.SaveOrUpdateCopy(obj
);
646 /// Copy the state of the given object onto the persistent object with the
647 /// given identifier. If there is no persistent instance currently associated
648 /// with the session, it will be loaded. Return the persistent instance. If
649 /// there is no database row with the given identifier, save the given instance
650 /// and return it as a newly persistent instance. Otherwise, the given instance
651 /// does not become associated with the session.
653 /// <param name="obj">a persistent or transient instance with state to be copied</param>
654 /// <param name="id">the identifier of the instance to copy to</param>
655 /// <returns>an updated persistent instance</returns>
656 public object SaveOrUpdateCopy(object obj
, object id
)
658 return innerSession
.SaveOrUpdateCopy(obj
, id
);
662 /// Remove a persistent instance from the datastore.
664 /// <param name="obj">The instance to be removed</param>
666 /// The argument may be an instance associated with the receiving <c>ISession</c> or a
667 /// transient instance with an identifier associated with existing persistent state.
669 public void Delete(object obj
)
671 innerSession
.Delete(obj
);
677 /// <param name="query">A query expressed in Hibernate's query language</param>
678 /// <returns>A distinct list of instances</returns>
679 /// <remarks>See <see cref="M:NHibernate.IQuery.List"/> for implications of <c>cache</c> usage.</remarks>
680 public IList
Find(String query
)
682 return innerSession
.CreateQuery(query
).List();
686 /// Execute a query, binding a value to a "?" parameter in the query string.
688 /// <param name="query">The query string</param>
689 /// <param name="value">A value to be bound to a "?" placeholder</param>
690 /// <param name="type">The Hibernate type of the value</param>
691 /// <returns>A distinct list of instances</returns>
692 /// <remarks>See <see cref="M:NHibernate.IQuery.List"/> for implications of <c>cache</c> usage.</remarks>
693 public IList
Find(String query
, object value, IType type
)
695 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
696 return innerSession
.Find(query
, value, type
);
700 /// Execute a query, binding an array of values to a "?" parameters in the query string.
702 /// <param name="query">The query string</param>
703 /// <param name="values">An array of values to be bound to the "?" placeholders</param>
704 /// <param name="types">An array of Hibernate types of the values</param>
705 /// <returns>A distinct list of instances</returns>
706 /// <remarks>See <see cref="M:NHibernate.IQuery.List"/> for implications of <c>cache</c> usage.</remarks>
707 public IList
Find(String query
, object[] values
, IType
[] types
)
709 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
710 return innerSession
.Find(query
, values
, types
);
714 /// Execute a query and return the results in an interator.
716 /// <param name="query">The query string</param>
717 /// <returns>An enumerator</returns>
720 /// If the query has multiple return values, values will be returned in an array of
721 /// type <c>object[]</c>.
724 /// Entities returned as results are initialized on demand. The first SQL query returns
725 /// identifiers only. So <c>Enumerator()</c> is usually a less efficient way to retrieve
726 /// object than <c>List()</c>.
729 public IEnumerable
Enumerable(String query
)
731 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
732 return innerSession
.Enumerable(query
);
736 /// Execute a query and return the results in an interator,
737 /// binding a value to a "?" parameter in the query string.
739 /// <param name="query">The query string</param>
740 /// <param name="value">A value to be written to a "?" placeholder in the query string</param>
741 /// <param name="type">The hibernate type of the value</param>
742 /// <returns>An enumerator</returns>
745 /// If the query has multiple return values, values will be returned in an array of
746 /// type <c>object[]</c>.
749 /// Entities returned as results are initialized on demand. The first SQL query returns
750 /// identifiers only. So <c>Enumerator()</c> is usually a less efficient way to retrieve
751 /// object than <c>List()</c>.
754 public IEnumerable
Enumerable(String query
, object value, IType type
)
756 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
757 return innerSession
.Enumerable(query
, value, type
);
761 /// Execute a query and return the results in an interator,
762 /// binding the values to "?"s parameters in the query string.
764 /// <param name="query">The query string</param>
765 /// <param name="values">A list of values to be written to "?" placeholders in the query</param>
766 /// <param name="types">A list of hibernate types of the values</param>
767 /// <returns>An enumerator</returns>
770 /// If the query has multiple return values, values will be returned in an array of
771 /// type <c>object[]</c>.
774 /// Entities returned as results are initialized on demand. The first SQL query returns
775 /// identifiers only. So <c>Enumerator()</c> is usually a less efficient way to retrieve
776 /// object than <c>List()</c>.
779 public IEnumerable
Enumerable(String query
, object[] values
, IType
[] types
)
781 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
782 return innerSession
.Enumerable(query
, values
, types
);
786 /// Apply a filter to a persistent collection.
788 /// <param name="collection">A persistent collection to filter</param>
789 /// <param name="filter">A filter query string</param>
790 /// <returns>The resulting collection</returns>
792 /// A filter is a Hibernate query that may refer to <c>this</c>, the collection element.
793 /// Filters allow efficient access to very large lazy collections. (Executing the filter
794 /// does not initialize the collection.)
796 public ICollection
Filter(object collection
, String filter
)
798 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
799 return innerSession
.Filter(collection
, filter
);
803 /// Apply a filter to a persistent collection, binding the given parameter to a "?" placeholder
805 /// <param name="collection">A persistent collection to filter</param>
806 /// <param name="filter">A filter query string</param>
807 /// <param name="value">A value to be written to a "?" placeholder in the query</param>
808 /// <param name="type">The hibernate type of value</param>
809 /// <returns>A collection</returns>
811 /// A filter is a Hibernate query that may refer to <c>this</c>, the collection element.
812 /// Filters allow efficient access to very large lazy collections. (Executing the filter
813 /// does not initialize the collection.)
815 public ICollection
Filter(object collection
, String filter
, object value, IType type
)
817 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
818 return innerSession
.Filter(collection
, filter
, value, type
);
822 /// Apply a filter to a persistent collection, binding the given parameters to "?" placeholders.
824 /// <param name="collection">A persistent collection to filter</param>
825 /// <param name="filter">A filter query string</param>
826 /// <param name="values">The values to be written to "?" placeholders in the query</param>
827 /// <param name="types">The hibernate types of the values</param>
828 /// <returns>A collection</returns>
830 /// A filter is a Hibernate query that may refer to <c>this</c>, the collection element.
831 /// Filters allow efficient access to very large lazy collections. (Executing the filter
832 /// does not initialize the collection.)
834 public ICollection
Filter(object collection
, String filter
, object[] values
, IType
[] types
)
836 // TODO: This is deprecated. Use ISession.CreateQuery().SetXYZ().List()
837 return innerSession
.Filter(collection
, filter
, values
, types
);
841 /// Return the entity name for a persistent entity
843 /// <param name="obj">a persistent entity</param>
844 /// <returns>the entity name</returns>
845 public string GetEntityName(object obj
)
847 return innerSession
.GetEntityName(obj
);
851 /// Sets the batch size of the session
853 /// <param name="batchSize"></param>
854 /// <returns></returns>
855 public ISession
SetBatchSize(int batchSize
)
857 return innerSession
.SetBatchSize(batchSize
);
861 /// An <see cref="T:NHibernate.IMultiCriteria"/> that can return a list of all the results
862 /// of all the criterias.
864 /// <returns></returns>
865 public IMultiCriteria
CreateMultiCriteria()
867 return innerSession
.CreateMultiCriteria();
871 /// The current cache mode.
875 /// Cache mode determines the manner in which this session can interact with
876 /// the second level cache.
878 public CacheMode CacheMode
880 get { return innerSession.CacheMode; }
881 set { innerSession.CacheMode = value; }
885 /// Get the statistics for this session.
888 public ISessionStatistics Statistics
890 get { return innerSession.Statistics; }
894 /// Delete all objects returned by the query.
896 /// <param name="query">The query string</param>
897 /// <returns>Returns the number of objects deleted.</returns>
898 public int Delete(String query
)
900 return innerSession
.Delete(query
);
904 /// Delete all objects returned by the query.
906 /// <param name="query">The query string</param>
907 /// <param name="value">A value to be written to a "?" placeholer in the query</param>
908 /// <param name="type">The hibernate type of value.</param>
909 /// <returns>The number of instances deleted</returns>
910 public int Delete(String query
, object value, IType type
)
912 return innerSession
.Delete(query
, value, type
);
916 /// Delete all objects returned by the query.
918 /// <param name="query">The query string</param>
919 /// <param name="values">A list of values to be written to "?" placeholders in the query</param>
920 /// <param name="types">A list of Hibernate types of the values</param>
921 /// <returns>The number of instances deleted</returns>
922 public int Delete(String query
, object[] values
, IType
[] types
)
924 return innerSession
.Delete(query
, values
, types
);
928 /// Obtain the specified lock level upon the given object.
930 /// <param name="obj">A persistent instance</param>
931 /// <param name="lockMode">The lock level</param>
932 public void Lock(object obj
, LockMode lockMode
)
934 innerSession
.Lock(obj
, lockMode
);
938 /// Obtain the specified lock level upon the given object.
940 /// <param name="entityName">The Entity name.</param>
941 /// <param name="obj">a persistent or transient instance </param>
942 /// <param name="lockMode">the lock level </param>
944 /// This may be used to perform a version check (<see cref="LockMode.Read"/>), to upgrade to a pessimistic
945 /// lock (<see cref="LockMode.Upgrade"/>), or to simply reassociate a transient instance
946 /// with a session (<see cref="LockMode.None"/>). This operation cascades to associated
947 /// instances if the association is mapped with <tt>cascade="lock"</tt>.
949 public void Lock(string entityName
, object obj
, LockMode lockMode
)
951 innerSession
.Lock(entityName
, obj
, lockMode
);
955 /// Re-read the state of the given instance from the underlying database.
957 /// <param name="obj">A persistent instance</param>
960 /// It is inadvisable to use this to implement long-running sessions that span many
961 /// business tasks. This method is, however, useful in certain special circumstances.
966 /// <item>Where a database trigger alters the object state upon insert or update</item>
967 /// <item>After executing direct SQL (eg. a mass update) in the same session</item>
968 /// <item>After inserting a <c>Blob</c> or <c>Clob</c></item>
972 public void Refresh(object obj
)
974 innerSession
.Refresh(obj
);
978 /// Re-read the state of the given instance from the underlying database, with
979 /// the given <c>LockMode</c>.
981 /// <param name="obj">a persistent or transient instance</param>
982 /// <param name="lockMode">the lock mode to use</param>
984 /// It is inadvisable to use this to implement long-running sessions that span many
985 /// business tasks. This method is, however, useful in certain special circumstances.
987 public void Refresh(object obj
, LockMode lockMode
)
989 innerSession
.Refresh(obj
,lockMode
);
993 /// Determine the current lock mode of the given object
995 /// <param name="obj">A persistent instance</param>
996 /// <returns>The current lock mode</returns>
997 public LockMode
GetCurrentLockMode(object obj
)
999 return innerSession
.GetCurrentLockMode(obj
);
1003 /// Begin a unit of work and return the associated <c>ITransaction</c> object.
1005 /// <returns>A transaction instance</returns>
1007 /// If a new underlying transaction is required, begin the transaction. Otherwise
1008 /// continue the new work in the context of the existing underlying transaction.
1009 /// The class of the returned <see cref="T:NHibernate.ITransaction"/> object is determined by
1010 /// the property <c>transaction_factory</c>
1012 public ITransaction
BeginTransaction()
1014 return innerSession
.BeginTransaction();
1018 /// Begin a transaction with the specified <c>isolationLevel</c>
1020 /// <param name="isolationLevel">Isolation level for the new transaction</param>
1022 /// A transaction instance having the specified isolation level
1024 public ITransaction
BeginTransaction(IsolationLevel isolationLevel
)
1026 return innerSession
.BeginTransaction(isolationLevel
);
1030 /// Creates a new <c>Criteria</c> for the entity class.
1032 /// <param name="persistentClass">The class to Query</param>
1033 /// <returns>An ICriteria object</returns>
1034 public ICriteria
CreateCriteria(Type persistentClass
)
1036 return innerSession
.CreateCriteria(persistentClass
);
1040 /// Creates a new <c>Criteria</c> for the entity class with a specific alias
1042 /// <param name="persistentClass">The class to Query</param>
1043 /// <param name="alias">The alias of the entity</param>
1044 /// <returns>An ICriteria object</returns>
1045 public ICriteria
CreateCriteria(Type persistentClass
, string alias)
1047 return innerSession
.CreateCriteria(persistentClass
, alias);
1051 /// Create a new instance of <c>Query</c> for the given query string
1053 /// <param name="queryString">A hibernate query string</param>
1054 /// <returns>The query</returns>
1055 public IQuery
CreateQuery(String queryString
)
1057 return innerSession
.CreateQuery(queryString
);
1061 /// Create a new instance of <c>Query</c> for the given collection and filter string
1063 /// <param name="collection">A persistent collection</param>
1064 /// <param name="queryString">A hibernate query</param>
1065 /// <returns>A query</returns>
1066 public IQuery
CreateFilter(object collection
, String queryString
)
1068 return innerSession
.CreateFilter(collection
, queryString
);
1072 /// Obtain an instance of <see cref="T:NHibernate.IQuery"/> for a named query string defined in the
1075 /// <param name="queryName">The name of a query defined externally.</param>
1077 /// An <see cref="T:NHibernate.IQuery"/> from a named query string.
1080 /// The query can be either in <c>HQL</c> or <c>SQL</c> format.
1082 public IQuery
GetNamedQuery(String queryName
)
1084 return innerSession
.GetNamedQuery(queryName
);
1088 /// Create a new instance of <see cref="T:NHibernate.ISQLQuery"/> for the given SQL query string.
1090 /// <param name="queryString">a query expressed in SQL</param>
1092 /// An <see cref="T:NHibernate.ISQLQuery"/> from the SQL string
1094 public ISQLQuery
CreateSQLQuery(string queryString
)
1096 return innerSession
.CreateSQLQuery(queryString
);
1100 /// Create a new instance of <c>IQuery</c> for the given SQL string.
1102 /// <param name="sql">a query expressed in SQL</param>
1103 /// <param name="returnAlias">a table alias that appears inside <c>{}</c> in the SQL string</param>
1104 /// <param name="returnClass">the returned persistent class</param>
1106 /// An <see cref="T:NHibernate.IQuery"/> from the SQL string
1108 public IQuery
CreateSQLQuery(String sql
, String returnAlias
, Type returnClass
)
1110 return innerSession
.CreateSQLQuery(sql
, returnAlias
, returnClass
);
1114 /// Create a new instance of <see cref="T:NHibernate.IQuery"/> for the given SQL string.
1116 /// <param name="sql">a query expressed in SQL</param>
1117 /// <param name="returnAliases">an array of table aliases that appear inside <c>{}</c> in the SQL string</param>
1118 /// <param name="returnClasses">the returned persistent classes</param>
1120 /// An <see cref="T:NHibernate.IQuery"/> from the SQL string
1122 public IQuery
CreateSQLQuery(String sql
, String
[] returnAliases
, Type
[] returnClasses
)
1124 return innerSession
.CreateSQLQuery(sql
, returnAliases
, returnClasses
);
1128 /// Completely clear the session. Evict all loaded instances and cancel all pending
1129 /// saves, updates and deletions. Do not close open enumerables or instances of
1130 /// <c>ScrollableResults</c>.
1134 innerSession
.Clear();
1138 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
1140 public void Dispose()
1144 holder
.ReleaseSession( innerSession
);
1148 throw new InvalidOperationException("Session was closed");
1153 /// Gets the session implementation.
1156 /// An NHibernate implementation of the <seealso cref="T:NHibernate.Engine.ISessionImplementor"/> interface
1159 /// This method is provided in order to get the <b>NHibernate</b> implementation of the session from wrapper implementions.
1160 /// Implementors of the <seealso cref="T:NHibernate.ISession"/> interface should return the NHibernate implementation of this method.
1162 public NHibernate
.Engine
.ISessionImplementor
GetSessionImplementation()
1164 return innerSession
.GetSessionImplementation();
1168 /// Starts a new Session with the given entity mode in effect. This secondary
1169 /// Session inherits the connection, transaction, and other context
1170 /// information from the primary Session. It doesn't need to be flushed
1171 /// or closed by the developer.
1173 /// <param name="entityMode">The entity mode to use for the new session.</param>
1174 /// <returns>The new session</returns>
1175 public ISession
GetSession(EntityMode entityMode
)
1177 return innerSession
.GetSession(entityMode
);