Skip to content

NH-3431 - Replace usage of System.Data classes to System.Data.Common #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/NHibernate.DomainModel/DoubleStringType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

using NHibernate.Engine;
using NHibernate.Type;
Expand Down Expand Up @@ -49,7 +49,7 @@ public bool IsMutable
get { return true; }
}

public Object NullSafeGet(IDataReader rs, string[] names, ISessionImplementor session, Object owner)
public Object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, Object owner)
{
string first = (string) NHibernateUtil.String.NullSafeGet(rs, names[0], session, owner);
string second = (string) NHibernateUtil.String.NullSafeGet(rs, names[1], session, owner);
Expand All @@ -58,7 +58,7 @@ public Object NullSafeGet(IDataReader rs, string[] names, ISessionImplementor se
}


public void NullSafeSet(IDbCommand st, Object value, int index, bool[] settable, ISessionImplementor session)
public void NullSafeSet(DbCommand st, Object value, int index, bool[] settable, ISessionImplementor session)
{
string[] strings = (value == null) ? new string[2] : (string[]) value;

Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate.DomainModel/MultiplicityType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data;
using System.Data.Common;
using System.Linq;
using NHibernate.Engine;
using NHibernate.Type;
Expand Down Expand Up @@ -74,7 +74,7 @@ public int GetHashCode(object x)
}
}

public object NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
public object NullSafeGet(DbDataReader rs, String[] names, ISessionImplementor session, Object owner)
{
int c = (int) NHibernateUtil.Int32.NullSafeGet(rs, names[0], session, owner);
GlarchProxy g = (GlarchProxy) NHibernateUtil.Entity(typeof(Glarch)).NullSafeGet(rs, names[1], session, owner);
Expand All @@ -84,7 +84,7 @@ public object NullSafeGet(IDataReader rs, String[] names, ISessionImplementor se
return m;
}

public void NullSafeSet(IDbCommand st, Object value, int index, bool[] settable, ISessionImplementor session)
public void NullSafeSet(DbCommand st, Object value, int index, bool[] settable, ISessionImplementor session)
{
Multiplicity o = (Multiplicity) value;
GlarchProxy g;
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate.DomainModel/NHSpecific/NullInt32UserType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

using NHibernate.SqlTypes;
using NHibernate.Type;
Expand Down Expand Up @@ -46,11 +46,11 @@ public object DeepCopy(object value)
return value;
}

public void NullSafeSet(IDbCommand cmd, object value, int index)
public void NullSafeSet(DbCommand cmd, object value, int index)
{
if (value.Equals(0))
{
((IDbDataParameter) cmd.Parameters[index]).Value = DBNull.Value;
cmd.Parameters[index].Value = DBNull.Value;
}
else
{
Expand All @@ -63,7 +63,7 @@ public System.Type ReturnedType
get { return typeof(Int32); }
}

public object NullSafeGet(IDataReader rs, string[] names, object owner)
public object NullSafeGet(DbDataReader rs, string[] names, object owner)
{
return _int32Type.NullSafeGet(rs, names);
}
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate.DomainModel/NHSpecific/NullableInt32Type.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

using NHibernate.SqlTypes;
using NHibernate.Type;
Expand All @@ -26,14 +26,14 @@ public override System.Type ReturnedClass
get { return typeof(NullableInt32); }
}

public override object Get(IDataReader rs, int index)
public override object Get(DbDataReader rs, int index)
{
return new NullableInt32(Convert.ToInt32(rs[index]));
}

public override void Set(IDbCommand cmd, object value, int index)
public override void Set(DbCommand cmd, object value, int index)
{
IDataParameter parameter = (IDataParameter) cmd.Parameters[index];
var parameter = cmd.Parameters[index];
NullableInt32 nullableValue = (NullableInt32) value;

if (nullableValue.HasValue)
Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate.DomainModel/NHSpecific/NullableTypesType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data;
using System.Data.Common;

using NHibernate.SqlTypes;
using NHibernate.Type;
Expand All @@ -17,7 +17,7 @@ public NullableTypesType(SqlType type) : base(type)
{
}

public override object NullSafeGet(IDataReader rs, string name)
public override object NullSafeGet(DbDataReader rs, string name)
{
object value = base.NullSafeGet(rs, name);
if (value == null)
Expand All @@ -30,7 +30,7 @@ public override object NullSafeGet(IDataReader rs, string name)
}
}

public override object Get(IDataReader rs, string name)
public override object Get(DbDataReader rs, string name)
{
return Get(rs, rs.GetOrdinal(name));
}
Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate.DomainModel/Northwind/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data;
using System.Data.Common;
using NHibernate.Type;

namespace NHibernate.DomainModel.Northwind.Entities
Expand Down Expand Up @@ -71,15 +71,15 @@ public class EnumStoredAsStringType : EnumStringType
public EnumStoredAsStringType()
: base(typeof(EnumStoredAsString), 12) { }

public override void Set(IDbCommand cmd, object value, int index)
public override void Set(DbCommand cmd, object value, int index)
{
if (value is EnumStoredAsString && (EnumStoredAsString)value == EnumStoredAsString.Unspecified)
base.Set(cmd, null, index);
else
base.Set(cmd, value, index);
}

public override object Get(IDataReader rs, int index)
public override object Get(DbDataReader rs, int index)
{
object obj = base.Get(rs, index);
if (obj == null) return EnumStoredAsString.Unspecified;
Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate.Test/Cascade/RefreshFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using NUnit.Framework;

namespace NHibernate.Test.Cascade
Expand Down Expand Up @@ -51,8 +52,8 @@ public void RefreshCascade()

private void UpdateStatuses(ISession session)
{
IDbConnection conn = session.Connection;
IDbCommand cmd = conn.CreateCommand();
var conn = session.Connection;
var cmd = conn.CreateCommand();
cmd.CommandText = "UPDATE T_JOB SET JOB_STATUS = 1";
cmd.CommandType = CommandType.Text;
session.Transaction.Enlist(cmd);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Data;
using NHibernate.AdoNet;
using NHibernate.Bytecode;
using NHibernate.Cache;
Expand All @@ -8,7 +9,6 @@
using NHibernate.Linq.Functions;
using NHibernate.Type;
using NUnit.Framework;
using System.Data;
using NHibernate.Exceptions;

namespace NHibernate.Test.CfgTest.Loquacious
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using NHibernate.Connection;
using NUnit.Framework;
using Environment=NHibernate.Cfg.Environment;
Expand Down Expand Up @@ -56,10 +56,10 @@ public string PublicConnectionString
}

/// <summary>
/// Get an open <see cref="IDbConnection"/>.
/// Get an open <see cref="DbConnection"/>.
/// </summary>
/// <returns>An open <see cref="IDbConnection"/>.</returns>
public override IDbConnection GetConnection()
/// <returns>An open <see cref="DbConnection"/>.</returns>
public override DbConnection GetConnection()
{
throw new NotImplementedException();
}
Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using NHibernate.Cfg;
using NHibernate.Util;
using NUnit.Framework;
Expand Down Expand Up @@ -176,7 +176,7 @@ public void SuppliedConnection()
{
Prepare();

IDbConnection originalConnection = sessions.ConnectionProvider.GetConnection();
DbConnection originalConnection = sessions.ConnectionProvider.GetConnection();
ISession session = sessions.OpenSession(originalConnection);

Silly silly = new Silly("silly");
Expand All @@ -203,7 +203,7 @@ public void SuppliedConnection()
// Prepare();
// ISession s = GetSessionUnderTest();

// IDbConnection conn = s.Connection;
// DbConnection conn = s.Connection;
// Assert.IsTrue(((SessionImpl) s).ConnectionManager.HasBorrowedConnection);
// conn.Close();
// Assert.IsFalse(((SessionImpl) s).ConnectionManager.HasBorrowedConnection);
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate.Test/DateTimeOffsetUserType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Data;
using System.Data.Common;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;

Expand Down Expand Up @@ -28,7 +29,7 @@ public SqlType[] SqlTypes
get { return new[] { new SqlType(DbType.DateTime) }; }
}

public object NullSafeGet(IDataReader dr, string[] names, object owner)
public object NullSafeGet(DbDataReader dr, string[] names, object owner)
{
var name = names[0];
int index = dr.GetOrdinal(name);
Expand Down Expand Up @@ -61,7 +62,7 @@ public object NullSafeGet(IDataReader dr, string[] names, object owner)
}
}

public void NullSafeSet(IDbCommand cmd, object value, int index)
public void NullSafeSet(DbCommand cmd, object value, int index)
{
if (value == null)
{
Expand All @@ -72,8 +73,7 @@ public void NullSafeSet(IDbCommand cmd, object value, int index)
DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
DateTime paramVal = dateTimeOffset.ToOffset(Offset).DateTime;

IDataParameter parameter = (IDataParameter)cmd.Parameters[index];
parameter.Value = paramVal;
cmd.Parameters[index].Value = paramVal;
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/NHibernate.Test/DebugConnectionProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Data;
using System.Data.Common;
using System.Linq;
using NHibernate.Connection;

Expand All @@ -12,13 +13,13 @@ namespace NHibernate.Test
/// </summary>
public class DebugConnectionProvider : DriverConnectionProvider
{
private ConcurrentDictionary<IDbConnection, byte> connections = new ConcurrentDictionary<IDbConnection, byte>();
private ConcurrentDictionary<DbConnection, byte> connections = new ConcurrentDictionary<DbConnection, byte>();

public override IDbConnection GetConnection()
public override DbConnection GetConnection()
{
try
{
IDbConnection connection = base.GetConnection();
var connection = base.GetConnection();
connections.TryAdd(connection, 0);
return connection;
}
Expand All @@ -28,7 +29,7 @@ public override IDbConnection GetConnection()
}
}

public override void CloseConnection(IDbConnection conn)
public override void CloseConnection(DbConnection conn)
{
base.CloseConnection(conn);
byte _;
Expand All @@ -40,8 +41,8 @@ public bool HasOpenConnections
get
{
// Disposing of an ISession does not call CloseConnection (should it???)
// so a Diposed of ISession will leave an IDbConnection in the list but
// the IDbConnection will be closed (atleast with MsSql it works this way).
// so a Diposed of ISession will leave an DbConnection in the list but
// the DbConnection will be closed (atleast with MsSql it works this way).
return connections.Keys.Any(conn => conn.State != ConnectionState.Closed);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/NHibernate.Test/DialectTest/DialectFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Engine;
Expand Down Expand Up @@ -159,18 +160,16 @@ public void CurrentTimestampSelection()
sessions.ConnectionProvider.Configure(conf.Properties);
IDriver driver = sessions.ConnectionProvider.Driver;

using (IDbConnection connection = sessions.ConnectionProvider.GetConnection())
using (var connection = sessions.ConnectionProvider.GetConnection())
{
IDbCommand statement = driver.GenerateCommand(CommandType.Text, new SqlString(dialect.CurrentTimestampSelectString),
new SqlType[0]);
var statement = driver.GenerateCommand(CommandType.Text, new SqlString(dialect.CurrentTimestampSelectString), new SqlType[0]);
statement.Connection = connection;
using (IDataReader reader = statement.ExecuteReader())
using (var reader = statement.ExecuteReader())
{
Assert.That(reader.Read(), "should return one record");
Assert.That(reader[0], Is.InstanceOf<DateTime>());
}
}
}

}
}
Loading