22using System . Collections . Generic ;
33using System . Data ;
44using System . Data . Common ;
5- using System . Threading ;
6- using System . Threading . Tasks ;
75using NHibernate . AdoNet ;
86using NHibernate . Engine . Query ;
97using NHibernate . SqlTypes ;
@@ -21,24 +19,6 @@ namespace NHibernate.Driver
2119 /// </remarks>
2220 public abstract partial class OracleDataClientDriverBase : ReflectionBasedDriver , IEmbeddedBatcherFactoryProvider
2321 {
24- private partial class OracleDbCommandWrapper : DbCommandWrapper
25- {
26- private readonly Action < object , bool > _suppressDecimalInvalidCastExceptionSetter ;
27-
28- public OracleDbCommandWrapper ( DbCommand command , Action < object , bool > suppressDecimalInvalidCastExceptionSetter ) : base ( command )
29- {
30- _suppressDecimalInvalidCastExceptionSetter = suppressDecimalInvalidCastExceptionSetter ;
31- }
32-
33- protected override DbDataReader ExecuteDbDataReader ( CommandBehavior behavior )
34- {
35- var reader = Command . ExecuteReader ( behavior ) ;
36- _suppressDecimalInvalidCastExceptionSetter ( reader , true ) ;
37-
38- return reader ;
39- }
40- }
41-
4222 private const string _commandClassName = "OracleCommand" ;
4323
4424 private static readonly SqlType _guidSqlType = new SqlType ( DbType . Binary , 16 ) ;
@@ -54,6 +34,8 @@ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
5434 private readonly object _oracleDbTypeBinaryDouble ;
5535 private readonly object _oracleDbTypeBinaryFloat ;
5636
37+ private readonly Func < object , object > _oracleGetSessionInfo ;
38+ private readonly Func < object , string > _oracleGetTimeStampFormat ;
5739 /// <summary>
5840 /// Default constructor.
5941 /// </summary>
@@ -89,6 +71,10 @@ private OracleDataClientDriverBase(string driverAssemblyName, string clientNames
8971 {
9072 _suppressDecimalInvalidCastExceptionSetter = DelegateHelper . BuildPropertySetter < bool > ( oracleDataReader , "SuppressGetDecimalInvalidCastException" ) ;
9173 }
74+
75+ var oracleGlobalization = ReflectHelper . TypeFromAssembly ( clientNamespace + ".OracleGlobalization" , driverAssemblyName , true ) ;
76+ _oracleGetTimeStampFormat = DelegateHelper . BuildPropertyGetter < string > ( oracleGlobalization , "TimeStampFormat" ) ;
77+ _oracleGetSessionInfo = DelegateHelper . BuildFunc < object > ( TypeOfConnection , "GetSessionInfo" ) ;
9278 }
9379
9480 /// <inheritdoc/>
@@ -221,25 +207,35 @@ protected override void OnBeforePrepare(DbCommand command)
221207 command . Parameters . Insert ( 0 , outCursor ) ;
222208 }
223209
224- public override DbCommand CreateCommand ( )
210+ public override DbDataReader ExecuteReader ( DbCommand command )
225211 {
226- var command = base . CreateCommand ( ) ;
227- if ( ! SuppressDecimalInvalidCastException )
212+ if ( ! SuppressDecimalInvalidCastException && _suppressDecimalInvalidCastExceptionSetter == null )
228213 {
229- return command ;
214+ throw new NotSupportedException ( "OracleDataReader.SuppressGetDecimalInvalidCastException property is supported only in ODP.NET version 19.10 or newer" ) ;
230215 }
231216
232- if ( _suppressDecimalInvalidCastExceptionSetter == null )
217+ var reader = command . ExecuteReader ( ) ;
218+
219+ if ( SuppressDecimalInvalidCastException )
233220 {
234- throw new NotSupportedException ( "OracleDataReader.SuppressGetDecimalInvalidCastException property is supported only in ODP.NET version 19.10 or newer" ) ;
221+ _suppressDecimalInvalidCastExceptionSetter ( reader , true ) ;
235222 }
236223
237- return new OracleDbCommandWrapper ( command , _suppressDecimalInvalidCastExceptionSetter ) ;
224+ string timestampFormat = GetDateFormat ( command . Connection ) ;
225+
226+ return new OracleDbDataReader ( reader , timestampFormat ) ;
238227 }
239228
240- public override DbCommand UnwrapDbCommand ( DbCommand command )
229+ private string GetDateFormat ( DbConnection connection )
241230 {
242- return command is OracleDbCommandWrapper wrapper ? wrapper . Command : command ;
231+ if ( _oracleGetSessionInfo == null && _oracleGetTimeStampFormat == null )
232+ {
233+ return null ;
234+ }
235+
236+ var sessionInfo = _oracleGetSessionInfo ( connection ) ;
237+
238+ return _oracleGetTimeStampFormat ( sessionInfo ) ;
243239 }
244240
245241 System . Type IEmbeddedBatcherFactoryProvider . BatcherFactoryClass => typeof ( OracleDataClientBatchingBatcherFactory ) ;
0 commit comments