minor cleanup.

This commit is contained in:
Keivan Beigi 2013-07-15 17:46:41 -07:00
parent e0aceb98d2
commit 89b43836d0
3 changed files with 31 additions and 61 deletions

View File

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

View File

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

View File

@ -73,7 +73,7 @@ namespace NzbDrone.Core.Notifications.Email
var settings = new EmailSettings(); var settings = new EmailSettings();
settings.InjectFrom(message); 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); SendEmail(settings, "NzbDrone - Test Notification", body);
} }