minor cleanup.

pull/3113/head
Keivan Beigi 11 years ago
parent e0aceb98d2
commit 89b43836d0

@ -18,12 +18,9 @@ using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Reflection;
using System.Collections;
using System.Linq;
using Marr.Data.Mapping;
using Marr.Data.Converters;
using Marr.Data.Parameters;
using Marr.Data.QGen;
using System.Linq.Expressions;
@ -39,8 +36,6 @@ namespace Marr.Data
#region - Contructor, Members -
private DbProviderFactory _dbProviderFactory;
private string _connectionString;
private DbCommand _command;
/// <summary>
@ -55,43 +50,32 @@ namespace Marr.Data
/// <summary>
/// A database provider agnostic initialization.
/// </summary>
/// <param name="connection">The database connection string.</param>
/// <param name="connectionString">The database connection string.</param>
public DataMapper(DbProviderFactory dbProviderFactory, string connectionString)
{
SqlMode = SqlModes.StoredProcedure;
if (dbProviderFactory == null)
throw new ArgumentNullException("dbProviderFactory instance cannot be null.");
throw new ArgumentNullException("dbProviderFactory");
if (string.IsNullOrEmpty(connectionString))
throw new ArgumentNullException("connectionString cannot be null or empty.");
throw new ArgumentNullException("connectionString");
_dbProviderFactory = dbProviderFactory;
ProviderFactory = dbProviderFactory;
_connectionString = connectionString;
ConnectionString = connectionString;
}
public string ConnectionString
{
get
{
return _connectionString;
}
}
public string ConnectionString { get; private set; }
public DbProviderFactory ProviderFactory { get; private set; }
public DbProviderFactory ProviderFactory
{
get
{
return _dbProviderFactory;
}
}
/// <summary>
/// Creates a new command utilizing the connection string.
/// </summary>
private DbCommand CreateNewCommand()
{
DbConnection conn = _dbProviderFactory.CreateConnection();
conn.ConnectionString = _connectionString;
DbConnection conn = ProviderFactory.CreateConnection();
conn.ConnectionString = ConnectionString;
DbCommand cmd = conn.CreateCommand();
SetSqlMode(cmd);
return cmd;
@ -155,23 +139,12 @@ namespace Marr.Data
#region - SP / SQL Mode -
private SqlModes _sqlMode = SqlModes.StoredProcedure; // Defaults to SP.
/// <summary>
/// Gets or sets a value that determines whether the DataMapper will
/// use a stored procedure or a sql text command to access
/// the database. The default is stored procedure.
/// </summary>
public SqlModes SqlMode
{
get
{
return _sqlMode;
}
set
{
_sqlMode = value;
}
}
public SqlModes SqlMode { get; set; }
/// <summary>
/// Sets the DbCommand objects CommandType to the current SqlMode.
@ -257,7 +230,7 @@ namespace Marr.Data
{
OpenConnection();
List<TResult> list = new List<TResult>();
var list = new List<TResult>();
DbDataReader reader = null;
try
{
@ -290,8 +263,8 @@ namespace Marr.Data
{
if (string.IsNullOrEmpty(sql))
throw new ArgumentNullException("sql", "A SQL query or stored procedure name is required");
else
Command.CommandText = sql;
Command.CommandText = sql;
try
{
@ -334,7 +307,7 @@ namespace Marr.Data
try
{
using (DbDataAdapter adapter = _dbProviderFactory.CreateDataAdapter())
using (DbDataAdapter adapter = ProviderFactory.CreateDataAdapter())
{
Command.CommandText = sql;
adapter.SelectCommand = Command;
@ -370,7 +343,7 @@ namespace Marr.Data
try
{
using (DbDataAdapter adapter = _dbProviderFactory.CreateDataAdapter())
using (DbDataAdapter adapter = ProviderFactory.CreateDataAdapter())
{
Command.CommandText = sql;
adapter.SelectCommand = Command;
@ -404,7 +377,7 @@ namespace Marr.Data
try
{
adapter = _dbProviderFactory.CreateDataAdapter();
adapter = ProviderFactory.CreateDataAdapter();
adapter.UpdateCommand = Command;
adapter.UpdateCommand.CommandText = sql;
@ -437,7 +410,7 @@ namespace Marr.Data
try
{
adapter = _dbProviderFactory.CreateDataAdapter();
adapter = ProviderFactory.CreateDataAdapter();
adapter.InsertCommand = Command;
adapter.InsertCommand.CommandText = sql;
@ -467,7 +440,7 @@ namespace Marr.Data
try
{
adapter = _dbProviderFactory.CreateDataAdapter();
adapter = ProviderFactory.CreateDataAdapter();
adapter.DeleteCommand = Command;
adapter.DeleteCommand.CommandText = sql;
@ -620,7 +593,7 @@ namespace Marr.Data
#endregion
#region - Query to Graph -
public List<T> QueryToGraph<T>(string sql)
{
return (List<T>)QueryToGraph<T>(sql, new List<T>());
@ -696,7 +669,7 @@ namespace Marr.Data
public UpdateQueryBuilder<T> Update<T>()
{
return new UpdateQueryBuilder<T>(this);
return new UpdateQueryBuilder<T>(this);
}
public int Update<T>(T entity, Expression<Func<T, bool>> filter)
@ -844,7 +817,7 @@ namespace Marr.Data
}
#endregion
#region - Events -
public event EventHandler OpeningConnection;
@ -894,7 +867,7 @@ namespace Marr.Data
{
if (MapRepository.Instance.EnableTraceLogging)
{
StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("==== Begin Query Trace ====");
sb.AppendLine();
@ -920,11 +893,8 @@ namespace Marr.Data
private void UnbindEvents()
{
if (OpeningConnection != null)
OpeningConnection = null;
if (ClosingConnection != null)
ClosingConnection = null;
OpeningConnection = null;
ClosingConnection = null;
}
public void BeginTransaction()

@ -6,10 +6,10 @@ namespace NzbDrone.Common
{
public static class PathExtensions
{
private static readonly string APP_CONFIG_FILE = "config.xml";
private static readonly string NZBDRONE_DB = "nzbdrone.db";
private static readonly string NZBDRONE_LOG_DB = "logs.db";
private static readonly string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
private const string APP_CONFIG_FILE = "config.xml";
private const string NZBDRONE_DB = "nzbdrone.db";
private const string NZBDRONE_LOG_DB = "logs.db";
private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone" + Path.DirectorySeparatorChar;

@ -73,7 +73,7 @@ namespace NzbDrone.Core.Notifications.Email
var settings = new EmailSettings();
settings.InjectFrom(message);
var body = "Success! You have properly configured your email notification settings";
const string body = "Success! You have properly configured your email notification settings";
SendEmail(settings, "NzbDrone - Test Notification", body);
}

Loading…
Cancel
Save