added marr.datamapper source code for easy debugging.

This commit is contained in:
kay.one 2013-03-30 14:56:34 -07:00
commit 3cdff3bb71
96 changed files with 9198 additions and 363 deletions

View file

@ -0,0 +1,74 @@
/* Copyright (C) 2008 - 2011 Jordan Marr
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>. */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Marr.Data.Mapping;
namespace Marr.Data.Parameters
{
public class DbTypeBuilder : IDbTypeBuilder
{
public Enum GetDbType(Type type)
{
if (type == typeof(String))
return DbType.String;
else if (type == typeof(Int32))
return DbType.Int32;
else if (type == typeof(Decimal))
return DbType.Decimal;
else if (type == typeof(DateTime))
return DbType.DateTime;
else if (type == typeof(Boolean))
return DbType.Boolean;
else if (type == typeof(Int16))
return DbType.Int16;
else if (type == typeof(Single))
return DbType.Single;
else if (type == typeof(Int64))
return DbType.Int64;
else if (type == typeof(Double))
return DbType.Double;
else if (type == typeof(Byte))
return DbType.Byte;
else if (type == typeof(Byte[]))
return DbType.Binary;
else if (type == typeof(Guid))
return DbType.Guid;
else
return DbType.Object;
}
public void SetDbType(System.Data.IDbDataParameter param, Enum dbType)
{
param.DbType = (DbType)dbType;
}
}
}

View file

@ -0,0 +1,34 @@
/* Copyright (C) 2008 - 2011 Jordan Marr
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>. */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Marr.Data.Mapping;
namespace Marr.Data.Parameters
{
/// <summary>
/// Converts from a .NET datatype to the appropriate DB type enum,
/// and then adds the value to the appropriate property on the parameter.
/// </summary>
public interface IDbTypeBuilder
{
Enum GetDbType(Type type);
void SetDbType(IDbDataParameter param, Enum dbType);
}
}

View file

@ -0,0 +1,72 @@
/* Copyright (C) 2008 - 2011 Jordan Marr
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>. */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using Marr.Data.Mapping;
namespace Marr.Data.Parameters
{
public class OleDbTypeBuilder : IDbTypeBuilder
{
public Enum GetDbType(Type type)
{
if (type == typeof(String))
return OleDbType.VarChar;
else if (type == typeof(Int32))
return OleDbType.Integer;
else if (type == typeof(Decimal))
return OleDbType.Decimal;
else if (type == typeof(DateTime))
return OleDbType.DBTimeStamp;
else if (type == typeof(Boolean))
return OleDbType.Boolean;
else if (type == typeof(Int16))
return OleDbType.SmallInt;
else if (type == typeof(Int64))
return OleDbType.BigInt;
else if (type == typeof(Double))
return OleDbType.Double;
else if (type == typeof(Byte))
return OleDbType.Binary;
else if (type == typeof(Byte[]))
return OleDbType.VarBinary;
else if (type == typeof(Guid))
return OleDbType.Guid;
else
return OleDbType.Variant;
}
public void SetDbType(System.Data.IDbDataParameter param, Enum dbType)
{
var oleDbParam = (OleDbParameter)param;
oleDbParam.OleDbType = (OleDbType)dbType;
}
}
}

View file

@ -0,0 +1,124 @@
/* Copyright (C) 2008 - 2011 Jordan Marr
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>. */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using Marr.Data.Converters;
namespace Marr.Data.Parameters
{
/// <summary>
/// This class allows chaining methods to be called for convenience when adding a parameter.
/// </summary>
public class ParameterChainMethods
{
/// <summary>
/// Creates a new parameter and adds it to the command's Parameters collection.
/// </summary>
/// <param name="command">The command that the parameter will be added to.</param>
/// <param name="parameterName">The parameter name.</param>
public ParameterChainMethods(DbCommand command, string parameterName, object value)
{
Parameter = command.CreateParameter();
Parameter.ParameterName = parameterName;
// Convert null to DBNull.Value
if (value == null)
value = DBNull.Value;
Type valueType = value.GetType();
// Check for a registered IConverter
IConverter converter = MapRepository.Instance.GetConverter(valueType);
if (converter != null)
{
Parameter.Value = converter.ToDB(value);
}
else
{
Parameter.Value = value;
}
//// Determine the correct DbType based on the passed in value type
//IDbTypeBuilder typeBuilder = MapRepository.Instance.DbTypeBuilder;
//Enum dbType = typeBuilder.GetDbType(valueType);
//// Set the appropriate DbType property depending on the parameter type
//typeBuilder.SetDbType(Parameter, dbType);
command.Parameters.Add(Parameter);
}
/// <summary>
/// Gets a reference to the parameter.
/// </summary>
public IDbDataParameter Parameter { get; private set; }
/// <summary>
/// Sets the direction of a parameter.
/// </summary>
/// <param name="direction">Determines the direction of a parameter.</param>
/// <returns>Return a ParameterChainMethods object.</returns>
public ParameterChainMethods Direction(ParameterDirection direction)
{
Parameter.Direction = direction;
return this;
}
/// <summary>
/// Sets the direction of a parameter to 'Output'.
/// </summary>
/// <returns></returns>
public ParameterChainMethods Output()
{
Parameter.Direction = ParameterDirection.Output;
return this;
}
public ParameterChainMethods DBType(DbType dbType)
{
Parameter.DbType = dbType;
return this;
}
public ParameterChainMethods Size(int size)
{
Parameter.Size = size;
return this;
}
public ParameterChainMethods Precision(byte precision)
{
Parameter.Precision = precision;
return this;
}
public ParameterChainMethods Scale(byte scale)
{
Parameter.Scale = scale;
return this;
}
public ParameterChainMethods Name(string name)
{
Parameter.ParameterName = name;
return this;
}
}
}

View file

@ -0,0 +1,76 @@
/* Copyright (C) 2008 - 2011 Jordan Marr
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>. */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Marr.Data.Mapping;
namespace Marr.Data.Parameters
{
public class SqlDbTypeBuilder : IDbTypeBuilder
{
public Enum GetDbType(Type type)
{
if (type == typeof(String))
return SqlDbType.VarChar;
else if (type == typeof(Int32))
return SqlDbType.Int;
else if (type == typeof(Decimal))
return SqlDbType.Decimal;
else if (type == typeof(DateTime))
return SqlDbType.DateTime;
else if (type == typeof(Boolean))
return SqlDbType.Bit;
else if (type == typeof(Int16))
return SqlDbType.SmallInt;
else if (type == typeof(Int64))
return SqlDbType.BigInt;
else if (type == typeof(Double))
return SqlDbType.Float;
else if (type == typeof(Char))
return SqlDbType.Char;
else if (type == typeof(Byte))
return SqlDbType.Binary;
else if (type == typeof(Byte[]))
return SqlDbType.VarBinary;
else if (type == typeof(Guid))
return SqlDbType.UniqueIdentifier;
else
return SqlDbType.Variant;
}
public void SetDbType(System.Data.IDbDataParameter param, Enum dbType)
{
var sqlDbParam = (SqlParameter)param;
sqlDbParam.SqlDbType = (SqlDbType)dbType;
}
}
}