You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by Ramon Casha <ra...@megabyte.net> on 2005/08/11 13:37:44 UTC

Feature request + patch

I altered my copy of iBATIS.NET so as to allow a provider to mix classes from different assemblies. In my case I needed it because I created a "wrapper class" around SqlCommand but wanted to retain all the other classes as they were. The way it works now is that if a classname contains a comma, it is loaded via "IBatisNet.Common.Utilities.Resources.TypeForName(className)" which can load from different assemblies, while if it has no comma it is loaded as before.

If you think this is a good idea, here's a patch for Provider.cs:

START PATCH vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Index: Provider.cs
===================================================================
--- Provider.cs	(revision 2)
+++ Provider.cs	(working copy)
@@ -462,6 +462,15 @@
 		#endregion
 
 		#region Methods
+
+		private Type GetType(Assembly assembly, string className) {
+			if(className.IndexOf(',') >= 0) {
+				return IBatisNet.Common.Utilities.Resources.TypeForName(className);
+			} else {
+				return assembly.GetType(className, true);
+			}
+		}
+
 		/// <summary>
 		/// Init the provider.
 		/// </summary>
@@ -476,25 +485,25 @@
 				assembly = Assembly.Load(_assemblyName);
 
 				// Build the Command template 
-				type = assembly.GetType(_commandClass, true);
+				type = GetType(assembly,_commandClass);
 				_templateCommand = (IDbCommand)type.GetConstructor(Type.EmptyTypes).Invoke(null);
 				// Build the DataAdapter template 
-				type = assembly.GetType(_dataAdapterClass, true);
+				type = GetType(assembly,_dataAdapterClass);
 				_templateDataAdapter = (IDbDataAdapter)type.GetConstructor(Type.EmptyTypes).Invoke(null);
 				// Build the connection template 
-				type = assembly.GetType(_connectionClass, true);
+				type = GetType(assembly,_connectionClass);
 				_templateConnection = (IDbConnection)type.GetConstructor(Type.EmptyTypes).Invoke(null);
 				// Get the IDataParameter type
-				_dataParameterType = assembly.GetType(_dataParameter, true);
+				_dataParameterType = GetType(assembly,_dataParameter);
 				// Get the CommandBuilder Type
-				_commandBuilderType = assembly.GetType(_commandBuilderClass, true);
+				_commandBuilderType = GetType(assembly,_commandBuilderClass);
 				if (_parameterDbTypeClass.IndexOf(',')>0)
 				{
 					_parameterDbType = cachedTypeResolver.Resolve(_parameterDbTypeClass);
 				}
 				else
 				{
-					_parameterDbType = assembly.GetType(_parameterDbTypeClass, true);
+					_parameterDbType = GetType(assembly,_parameterDbTypeClass);
 				}
 
 				_templateConnectionIsICloneable = _templateConnection is ICloneable;
END PATCH ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
________________________________

Ramon Casha
Megabyte Ltd (www.megabyte.net <http://www.megabyte.net/> )
F4, The Technopark, Mosta MST02 Malta
tel: (+356) 2142 1600
fax: (+356) 2142 1590 	Megabyte Ltd <file:///C:/Documents%20and%20Settings/rac.MEGABYTE.000/My%20Documents/My%20Pictures/mb-email-signature.gif> 	

DISCLAIMER 
The information contained in this electronic mail may be confidential or legally privileged. It is for the intended recipient(s) only. Should you receive this message in error, please notify the sender by replying to this mail. Unauthorised use of the contents is strictly prohibited. Whilst all care has been taken, the Megabyte Group is not responsible for the integrity of the contents of this electronic mail and any attachments included within. 



Re: [SPAM] - Re: Feature request + patch - Found word(s) removelist list error in the Text body

Posted by Ramon Casha <ra...@megabyte.net>.
On Thu, 2005-08-11 at 12:07 -0700, Ron Grabowski wrote:
> I think this is an ok idea; but not a good idea. I've had problems in
> the past with trying to use a modified version of class alongside
> unmodified versions:
> 
>  http://forum.castleproject.org/posts/list/39.page
Don't know if it helps but mine has something like this:
#region Property: Connection
public SqlConnection Connection {
	get {
		return _cmd.Connection;
	}
	set {
		_cmd.Connection = value;
	}
}
IDbConnection IDbCommand.Connection {
	get {
		return Connection;
	}
	set {
		Connection = value as SqlConnection;
	}
}
#endregion

> 
> You probably won't experience those errors since you're wrapping the
> class.

No problems so far - it works entirely transparently.

> If I were maintaining a project that required me to use a wrapped
> SqlCommand object, I would expect all related objects for accessing the
> datastore to be wrapped.

Yes but ibatis doesn't use datastores does it?

> Have you thought about putting your modified
> SqlCommand along with other thin wrapper classes into their own
> assembly? 

I could, and that would be a "cleaner" solution, but the only one in
which I want to modify anything is the sqlcommand.

> If you want to specify a fully qualified type
> for one thing, I think you should have to use a fully qualified type
> for everything (i.e. remove the assemblyName attribute entirely).
> That's the approach log4net has taken for its config file.

I'll drink to that.

> I'm curious to know what your SqlCommand wrapper class is doing.

Basically writing a webapp which must adhere to the client's corporate
standards, and one of them is that all database accesses must pass
through their own library. Rather than write an app that is completely
non-standard in its database handling, I created this
drop-in-replacement SqlCommand which shunts the database accesses
through their library, so our application can remain blissfully unaware
of anything unusual going on.

________________________________________________________________________


Ramon Casha
Megabyte Ltd (www.megabyte.net)
F4, The Technopark, Mosta MST02
Malta
tel: (+356) 2142 1600
fax: (+356) 2142 1590




DISCLAIMER 
The information contained in this electronic mail may be confidential or legally privileged. It is for the intended recipient(s) only. Should you receive this message in error, please notify the sender by replying to this mail. Unauthorised use of the contents is strictly prohibited. Whilst all care has been taken, the Megabyte Group is not responsible for the integrity of the contents of this electronic mail and any attachments included within. 



Re: Feature request + patch

Posted by Ron Grabowski <ro...@yahoo.com>.
I think this is an ok idea; but not a good idea. I've had problems in
the past with trying to use a modified version of class alongside
unmodified versions:

 http://forum.castleproject.org/posts/list/39.page

You probably won't experience those errors since you're wrapping the
class.

If I were maintaining a project that required me to use a wrapped
SqlCommand object, I would expect all related objects for accessing the
datastore to be wrapped. Have you thought about putting your modified
SqlCommand along with other thin wrapper classes into their own
assembly? By doing that, you could create your own provider node. I
think that's more in-line with the spirit/design of IBatisNet.

I think its confusing specifing an assemblyName in a provider node but
then allow special cases. If you want to specify a fully qualified type
for one thing, I think you should have to use a fully qualified type
for everything (i.e. remove the assemblyName attribute entirely).
That's the approach log4net has taken for its config file.

I'm curious to know what your SqlCommand wrapper class is doing.

--- Ramon Casha <ra...@megabyte.net> wrote:

> I altered my copy of iBATIS.NET so as to allow a provider to mix
> classes from different assemblies. In my case I needed it because I
> created a "wrapper class" around SqlCommand but wanted to retain all
> the other classes as they were. The way it works now is that if a
> classname contains a comma, it is loaded via
> "IBatisNet.Common.Utilities.Resources.TypeForName(className)" which
> can load from different assemblies, while if it has no comma it is
> loaded as before.
> 
> If you think this is a good idea, here's a patch for Provider.cs:
> 
> START PATCH
> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> Index: Provider.cs
> ===================================================================
> --- Provider.cs	(revision 2)
> +++ Provider.cs	(working copy)
> @@ -462,6 +462,15 @@
>  		#endregion
>  
>  		#region Methods
> +
> +		private Type GetType(Assembly assembly, string className) {
> +			if(className.IndexOf(',') >= 0) {
> +				return
> IBatisNet.Common.Utilities.Resources.TypeForName(className);
> +			} else {
> +				return assembly.GetType(className, true);
> +			}
> +		}
> +
>  		/// <summary>
>  		/// Init the provider.
>  		/// </summary>
> @@ -476,25 +485,25 @@
>  				assembly = Assembly.Load(_assemblyName);
>  
>  				// Build the Command template 
> -				type = assembly.GetType(_commandClass, true);
> +				type = GetType(assembly,_commandClass);
>  				_templateCommand =
> (IDbCommand)type.GetConstructor(Type.EmptyTypes).Invoke(null);
>  				// Build the DataAdapter template 
> -				type = assembly.GetType(_dataAdapterClass, true);
> +				type = GetType(assembly,_dataAdapterClass);
>  				_templateDataAdapter =
> (IDbDataAdapter)type.GetConstructor(Type.EmptyTypes).Invoke(null);
>  				// Build the connection template 
> -				type = assembly.GetType(_connectionClass, true);
> +				type = GetType(assembly,_connectionClass);
>  				_templateConnection =
> (IDbConnection)type.GetConstructor(Type.EmptyTypes).Invoke(null);
>  				// Get the IDataParameter type
> -				_dataParameterType = assembly.GetType(_dataParameter, true);
> +				_dataParameterType = GetType(assembly,_dataParameter);
>  				// Get the CommandBuilder Type
> -				_commandBuilderType = assembly.GetType(_commandBuilderClass,
> true);
> +				_commandBuilderType = GetType(assembly,_commandBuilderClass);
>  				if (_parameterDbTypeClass.IndexOf(',')>0)
>  				{
>  					_parameterDbType =
> cachedTypeResolver.Resolve(_parameterDbTypeClass);
>  				}
>  				else
>  				{
> -					_parameterDbType = assembly.GetType(_parameterDbTypeClass,
> true);
> +					_parameterDbType = GetType(assembly,_parameterDbTypeClass);
>  				}
>  
>  				_templateConnectionIsICloneable = _templateConnection is
> ICloneable;
> END PATCH
>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>  
> ________________________________
> 
> Ramon Casha
> Megabyte Ltd (www.megabyte.net <http://www.megabyte.net/> )
> F4, The Technopark, Mosta MST02 Malta
> tel: (+356) 2142 1600
> fax: (+356) 2142 1590 	Megabyte Ltd
>
<file:///C:/Documents%20and%20Settings/rac.MEGABYTE.000/My%20Documents/My%20Pictures/mb-email-signature.gif>
> 	
> 
> DISCLAIMER 
> The information contained in this electronic mail may be confidential
> or legally privileged. It is for the intended recipient(s) only.
> Should you receive this message in error, please notify the sender by
> replying to this mail. Unauthorised use of the contents is strictly
> prohibited. Whilst all care has been taken, the Megabyte Group is not
> responsible for the integrity of the contents of this electronic mail
> and any attachments included within. 
> 
> 
>