|
From: <fab...@us...> - 2008-10-19 21:16:51
|
Revision: 3867
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3867&view=rev
Author: fabiomaulo
Date: 2008-10-19 21:16:44 +0000 (Sun, 19 Oct 2008)
Log Message:
-----------
Improv session Load to use entity-name
Possible breaking change for related FWs: see ISession
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/ISession.cs
trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs
Modified: trunk/nhibernate/src/NHibernate/ISession.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/ISession.cs 2008-10-19 20:25:16 UTC (rev 3866)
+++ trunk/nhibernate/src/NHibernate/ISession.cs 2008-10-19 21:16:44 UTC (rev 3867)
@@ -214,6 +214,16 @@
/// <returns>the persistent instance</returns>
object Load(System.Type theType, object id, LockMode lockMode);
+ /// <summary>
+ /// Return the persistent instance of the given entity class with the given identifier,
+ /// obtaining the specified lock mode, assuming the instance exists.
+ /// </summary>
+ /// <param name="entityName">The entity-name of a persistent class</param>
+ /// <param name="id">a valid identifier of an existing persistent instance of the class </param>
+ /// <param name="lockMode">the lock level </param>
+ /// <returns> the persistent instance or proxy </returns>
+ object Load(string entityName, object id, LockMode lockMode);
+
/// <summary>
/// Return the persistent instance of the given entity class with the given identifier,
/// assuming that the instance exists.
@@ -252,6 +262,20 @@
/// <returns>The persistent instance or proxy</returns>
T Load<T>(object id);
+ /// <summary>
+ /// Return the persistent instance of the given <paramref name="entityName"/> with the given identifier,
+ /// assuming that the instance exists.
+ /// </summary>
+ /// <param name="entityName">The entity-name of a persistent class</param>
+ /// <param name="id">a valid identifier of an existing persistent instance of the class </param>
+ /// <returns> The persistent instance or proxy </returns>
+ /// <remarks>
+ /// You should not use this method to determine if an instance exists (use <see cref="Get(string,object)"/>
+ /// instead). Use this only to retrieve an instance that you assume exists, where non-existence
+ /// would be an actual error.
+ /// </remarks>
+ object Load(string entityName, object id);
+
/// <summary>
/// Read the persistent state associated with the given identifier into the given transient
/// instance.
Modified: trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2008-10-19 20:25:16 UTC (rev 3866)
+++ trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2008-10-19 21:16:44 UTC (rev 3867)
@@ -47,7 +47,7 @@
private readonly IInterceptor interceptor;
- [NonSerialized] private readonly EntityMode entityMode = NHibernate.EntityMode.Poco;
+ [NonSerialized] private readonly EntityMode entityMode = EntityMode.Poco;
[NonSerialized]
private readonly EventListeners listeners;
@@ -58,7 +58,7 @@
private readonly ConnectionManager connectionManager;
[NonSerialized]
- private int dontFlushFromFind = 0;
+ private int dontFlushFromFind;
[NonSerialized] private readonly IDictionary<string, IFilter> enabledFilters = new Dictionary<string, IFilter>();
@@ -541,7 +541,7 @@
public IEnumerable Enumerable(string query, object value, IType type)
{
- return Enumerable(query, new object[] { value }, new IType[] { type });
+ return Enumerable(query, new[] { value }, new[] { type });
}
public IEnumerable Enumerable(string query, object[] values, IType[] types)
@@ -594,7 +594,7 @@
public int Delete(string query, object value, IType type)
{
- return Delete(query, new object[] { value }, new IType[] { type });
+ return Delete(query, new[] { value }, new[] { type });
}
public int Delete(string query, object[] values, IType[] types)
@@ -937,28 +937,61 @@
return autoFlushEvent.FlushRequired;
}
+ #region load()/get() operations
+
public void Load(object obj, object id)
{
LoadEvent loadEvent = new LoadEvent(id, obj, this);
FireLoad(loadEvent, LoadEventListener.Reload);
}
- public object Load(System.Type clazz, object id)
+ public T Load<T>(object id)
{
+ return (T)Load(typeof(T), id);
+ }
+
+ public T Load<T>(object id, LockMode lockMode)
+ {
+ return (T)Load(typeof(T), id, lockMode);
+ }
+
+ /// <summary>
+ /// Load the data for the object with the specified id into a newly created object
+ /// using "for update", if supported. A new key will be assigned to the object.
+ /// This should return an existing proxy where appropriate.
+ ///
+ /// If the object does not exist in the database, an exception is thrown.
+ /// </summary>
+ /// <param name="entityClass"></param>
+ /// <param name="id"></param>
+ /// <param name="lockMode"></param>
+ /// <returns></returns>
+ /// <exception cref="ObjectNotFoundException">
+ /// Thrown when the object with the specified id does not exist in the database.
+ /// </exception>
+ public object Load(System.Type entityClass, object id, LockMode lockMode)
+ {
+ return Load(entityClass.FullName, id, lockMode);
+ }
+
+ public object Load(string entityName, object id)
+ {
if (id == null)
{
throw new ArgumentNullException("id", "null is not a valid identifier");
}
- LoadEvent loadEvent = new LoadEvent(id, clazz.FullName, false, this);
+
+ var @event = new LoadEvent(id, entityName, false, this);
bool success = false;
try
{
- FireLoad(loadEvent, LoadEventListener.Load);
- if (loadEvent.Result == null)
- Factory.EntityNotFoundDelegate.HandleEntityNotFound(clazz.FullName, id);
-
+ FireLoad(@event, LoadEventListener.Load);
+ if (@event.Result == null)
+ {
+ Factory.EntityNotFoundDelegate.HandleEntityNotFound(entityName, id);
+ }
success = true;
- return loadEvent.Result;
+ return @event.Result;
}
finally
{
@@ -966,14 +999,16 @@
}
}
- public T Load<T>(object id)
+ public object Load(string entityName, object id, LockMode lockMode)
{
- return (T)Load(typeof(T), id);
+ var @event = new LoadEvent(id, entityName, lockMode, this);
+ FireLoad(@event, LoadEventListener.Load);
+ return @event.Result;
}
- public T Load<T>(object id, LockMode lockMode)
+ public object Load(System.Type entityClass, object id)
{
- return (T)Load(typeof(T), id, lockMode);
+ return Load(entityClass.FullName, id);
}
public T Get<T>(object id)
@@ -986,6 +1021,29 @@
return (T)Get(typeof(T), id, lockMode);
}
+ public object Get(System.Type entityClass, object id)
+ {
+ return Get(entityClass.FullName, id);
+ }
+
+ /// <summary>
+ /// Load the data for the object with the specified id into a newly created object
+ /// using "for update", if supported. A new key will be assigned to the object.
+ /// This should return an existing proxy where appropriate.
+ ///
+ /// If the object does not exist in the database, null is returned.
+ /// </summary>
+ /// <param name="clazz"></param>
+ /// <param name="id"></param>
+ /// <param name="lockMode"></param>
+ /// <returns></returns>
+ public object Get(System.Type clazz, object id, LockMode lockMode)
+ {
+ LoadEvent loadEvent = new LoadEvent(id, clazz.FullName, lockMode, this);
+ FireLoad(loadEvent, LoadEventListener.Get);
+ return loadEvent.Result;
+ }
+
public string GetEntityName(object obj)
{
CheckAndUpdateSessionStatus();
@@ -1011,11 +1069,6 @@
return entry.Persister.EntityName;
}
- public object Get(System.Type entityClass, object id)
- {
- return Get(entityClass.FullName, id);
- }
-
public object Get(string entityName, object id)
{
LoadEvent loadEvent = new LoadEvent(id, entityName, false, this);
@@ -1068,45 +1121,8 @@
return loadEvent.Result;
}
- /// <summary>
- /// Load the data for the object with the specified id into a newly created object
- /// using "for update", if supported. A new key will be assigned to the object.
- /// This should return an existing proxy where appropriate.
- ///
- /// If the object does not exist in the database, an exception is thrown.
- /// </summary>
- /// <param name="clazz"></param>
- /// <param name="id"></param>
- /// <param name="lockMode"></param>
- /// <returns></returns>
- /// <exception cref="ObjectNotFoundException">
- /// Thrown when the object with the specified id does not exist in the database.
- /// </exception>
- public object Load(System.Type clazz, object id, LockMode lockMode)
- {
- LoadEvent loadEvent = new LoadEvent(id, clazz.FullName, lockMode, this);
- FireLoad(loadEvent, LoadEventListener.Load);
- return loadEvent.Result;
- }
+ #endregion
- /// <summary>
- /// Load the data for the object with the specified id into a newly created object
- /// using "for update", if supported. A new key will be assigned to the object.
- /// This should return an existing proxy where appropriate.
- ///
- /// If the object does not exist in the database, null is returned.
- /// </summary>
- /// <param name="clazz"></param>
- /// <param name="id"></param>
- /// <param name="lockMode"></param>
- /// <returns></returns>
- public object Get(System.Type clazz, object id, LockMode lockMode)
- {
- LoadEvent loadEvent = new LoadEvent(id, clazz.FullName, lockMode, this);
- FireLoad(loadEvent, LoadEventListener.Get);
- return loadEvent.Result;
- }
-
public void Refresh(object obj)
{
FireRefresh(new RefreshEvent(obj, this));
@@ -1616,7 +1632,7 @@
public IQuery CreateSQLQuery(string sql, string returnAlias, System.Type returnClass)
{
CheckAndUpdateSessionStatus();
- return new SqlQueryImpl(sql, new string[] { returnAlias }, new System.Type[] { returnClass }, this, Factory.QueryPlanCache.GetSQLParameterMetadata(sql));
+ return new SqlQueryImpl(sql, new[] { returnAlias }, new[] { returnClass }, this, Factory.QueryPlanCache.GetSQLParameterMetadata(sql));
}
public IQuery CreateSQLQuery(string sql, string[] returnAliases, System.Type[] returnClasses)
@@ -1798,7 +1814,7 @@
}
string filterName = filterParameterName.Substring(0, dot);
string parameterName = filterParameterName.Substring(dot + 1);
- return new string[] { filterName, parameterName };
+ return new[] { filterName, parameterName };
}
public override ConnectionManager ConnectionManager
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|