Skip to content

Commit 09e39b2

Browse files
committed
NH-2943: Add support for OracleDbType.XmlType
1 parent 4c77d6a commit 09e39b2

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.Data.Common;
5-
using System.Reflection;
65
using System.Text;
76
using NHibernate.AdoNet.Util;
87
using NHibernate.Exceptions;
@@ -16,7 +15,7 @@ namespace NHibernate.AdoNet
1615
public class OracleDataClientBatchingBatcher : AbstractBatcher
1716
{
1817
private int _batchSize;
19-
private int _countOfCommands = 0;
18+
private int _countOfCommands;
2019
private int _totalExpectedRowsAffected;
2120
private IDbCommand _currentBatch;
2221
private IDictionary<string, List<object>> _parameterValueListHashTable;
@@ -69,9 +68,9 @@ public override void AddToBatch(IExpectation expectation)
6968
firstOnBatch = false;
7069
}
7170

72-
List<object> parameterValueList;
7371
foreach (IDataParameter currentParameter in CurrentCommand.Parameters)
7472
{
73+
List<object> parameterValueList;
7574
if (firstOnBatch)
7675
{
7776
parameterValueList = new List<object>();
@@ -125,7 +124,7 @@ protected override void DoExecuteBatch(IDbCommand ps)
125124
// setting the ArrayBindCount on the OracleCommand
126125
// this value is not a part of the ADO.NET API.
127126
// It's and ODP implementation, so it is being set by reflection
128-
SetObjectParam(_currentBatch, "ArrayBindCount", arraySize);
127+
SetArrayBindCount(arraySize);
129128
int rowsAffected;
130129
try
131130
{
@@ -149,11 +148,12 @@ protected override int CountOfStatementsInCurrentBatch
149148
get { return _countOfCommands; }
150149
}
151150

152-
private void SetObjectParam(Object obj, string paramName, object paramValue)
151+
private void SetArrayBindCount(int arraySize)
153152
{
154-
System.Type objType = obj.GetType();
155-
PropertyInfo propInfo = objType.GetProperty(paramName);
156-
propInfo.SetValue(obj, paramValue, null);
153+
//TODO: cache the property info.
154+
var objType = _currentBatch.GetType();
155+
var propInfo = objType.GetProperty("ArrayBindCount");
156+
propInfo.SetValue(_currentBatch, arraySize, null);
157157
}
158158

159159
public override int BatchSize

src/NHibernate/Driver/OracleDataClientDriver.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Data;
23
using System.Reflection;
34
using NHibernate.AdoNet;
@@ -23,8 +24,9 @@ public class OracleDataClientDriver : ReflectionBasedDriver, IEmbeddedBatcherFac
2324
private static readonly SqlType GuidSqlType = new SqlType(DbType.Binary, 16);
2425
private readonly PropertyInfo oracleCommandBindByName;
2526
private readonly PropertyInfo oracleDbType;
26-
private readonly object oracleDbTypeRefCursor;
27-
27+
private readonly object oracleDbTypeRefCursor;
28+
private readonly object oracleDbTypeXmlType;
29+
2830
/// <summary>
2931
/// Initializes a new instance of <see cref="OracleDataClientDriver"/>.
3032
/// </summary>
@@ -45,7 +47,8 @@ public OracleDataClientDriver()
4547
oracleDbType = parameterType.GetProperty("OracleDbType");
4648

4749
System.Type oracleDbTypeEnum = ReflectHelper.TypeFromAssembly("Oracle.DataAccess.Client.OracleDbType", driverAssemblyName, false);
48-
oracleDbTypeRefCursor = System.Enum.Parse(oracleDbTypeEnum, "RefCursor");
50+
oracleDbTypeRefCursor = Enum.Parse(oracleDbTypeEnum, "RefCursor");
51+
oracleDbTypeXmlType = Enum.Parse(oracleDbTypeEnum, "XmlType");
4952
}
5053

5154
/// <summary></summary>
@@ -81,13 +84,22 @@ protected override void InitializeParameter(IDbDataParameter dbParam, string nam
8184
break;
8285
case DbType.Guid:
8386
base.InitializeParameter(dbParam, name, GuidSqlType);
87+
break;
88+
case DbType.Xml:
89+
this.InitializeParameter(dbParam, name, oracleDbTypeXmlType);
8490
break;
8591
default:
8692
base.InitializeParameter(dbParam, name, sqlType);
8793
break;
8894
}
89-
}
90-
95+
}
96+
97+
private void InitializeParameter(IDbDataParameter dbParam, string name, object sqlType)
98+
{
99+
dbParam.ParameterName = FormatNameForParameter(name);
100+
oracleDbType.SetValue(dbParam, sqlType, null);
101+
}
102+
91103
protected override void OnBeforePrepare(IDbCommand command)
92104
{
93105
base.OnBeforePrepare(command);
@@ -111,15 +123,11 @@ protected override void OnBeforePrepare(IDbCommand command)
111123
outCursor.Direction = detail.HasReturn ? ParameterDirection.ReturnValue : ParameterDirection.Output;
112124

113125
command.Parameters.Insert(0, outCursor);
114-
}
115-
116-
#region IEmbeddedBatcherFactoryProvider Members
117-
126+
}
127+
118128
System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass
119129
{
120130
get { return typeof (OracleDataClientBatchingBatcherFactory); }
121-
}
122-
123-
#endregion
131+
}
124132
}
125133
}

0 commit comments

Comments
 (0)