Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor reader to work better.

Basic fix was to make the connection open and close properly, this will
make it function faster.
  • Loading branch information...
commit 497e5b82c69ecd4f6be818228400c8d210902a5f 1 parent 7b72cac
@DavidBasarab authored
View
28 Source/Projects/YADA.Acceptance/Features/SmallTableReading.feature
@@ -1,14 +1,14 @@
-Feature: Small table reading
- In order to read a records from a small table
- As a developer
- I want to use YADA in the most simple way to read items out of the database and populate value objects
-
-Background:
- Given I have a test database created
- Given I have small table created
- Given I have small table populated
-
-@database
-Scenario: I want to read 1 row
- When using a store procedure to read a record
- Then the operation should happen in less than 1000 ms
+Feature: Small table reading
+ In order to read a records from a small table
+ As a developer
+ I want to use YADA in the most simple way to read items out of the database and populate value objects
+
+Background:
+ Given I have a test database created
+ Given I have small table created
+ Given I have small table populated
+
+@database
+Scenario: I want to read 1 row
+ When using a store procedure to read a record
+ Then the operation should happen in less than 3 ms
View
204 Source/Projects/YADA.Acceptance/Features/SmallTableReading.feature.cs
@@ -1,102 +1,102 @@
-// ------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by SpecFlow (http://www.specflow.org/).
-// SpecFlow Version:1.8.1.0
-// SpecFlow Generator Version:1.8.0.0
-// Runtime Version:4.0.30319.17626
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-// ------------------------------------------------------------------------------
-#region Designer generated code
-#pragma warning disable
-namespace YADA.Acceptance.Features
-{
- using TechTalk.SpecFlow;
-
-
- [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.8.1.0")]
- [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [NUnit.Framework.TestFixtureAttribute()]
- [NUnit.Framework.DescriptionAttribute("Small table reading")]
- public partial class SmallTableReadingFeature
- {
-
- private static TechTalk.SpecFlow.ITestRunner testRunner;
-
-#line 1 "SmallTableReading.feature"
-#line hidden
-
- [NUnit.Framework.TestFixtureSetUpAttribute()]
- public virtual void FeatureSetup()
- {
- testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
- TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Small table reading", " In order to read a records from a small table\r\n As a developer\r\n I want to us" +
- "e YADA in the most simple way to read items out of the database and populate val" +
- "ue objects", ProgrammingLanguage.CSharp, ((string[])(null)));
- testRunner.OnFeatureStart(featureInfo);
- }
-
- [NUnit.Framework.TestFixtureTearDownAttribute()]
- public virtual void FeatureTearDown()
- {
- testRunner.OnFeatureEnd();
- testRunner = null;
- }
-
- [NUnit.Framework.SetUpAttribute()]
- public virtual void TestInitialize()
- {
- }
-
- [NUnit.Framework.TearDownAttribute()]
- public virtual void ScenarioTearDown()
- {
- testRunner.OnScenarioEnd();
- }
-
- public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
- {
- testRunner.OnScenarioStart(scenarioInfo);
- }
-
- public virtual void ScenarioCleanup()
- {
- testRunner.CollectScenarioErrors();
- }
-
- public virtual void FeatureBackground()
- {
-#line 6
-#line 7
- testRunner.Given("I have a test database created");
-#line 8
- testRunner.Given("I have small table created");
-#line 9
- testRunner.Given("I have small table populated");
-#line hidden
- }
-
- [NUnit.Framework.TestAttribute()]
- [NUnit.Framework.DescriptionAttribute("I want to read 1 row")]
- [NUnit.Framework.CategoryAttribute("database")]
- public virtual void IWantToRead1Row()
- {
- TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("I want to read 1 row", new string[] {
- "database"});
-#line 12
-this.ScenarioSetup(scenarioInfo);
-#line 6
-this.FeatureBackground();
-#line 13
- testRunner.When("using a store procedure to read a record");
-#line 14
- testRunner.Then("the operation should happen in less than 1000 ms");
-#line hidden
- this.ScenarioCleanup();
- }
- }
-}
-#pragma warning restore
-#endregion
+// ------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by SpecFlow (http://www.specflow.org/).
+// SpecFlow Version:1.8.1.0
+// SpecFlow Generator Version:1.8.0.0
+// Runtime Version:4.0.30319.17626
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+// ------------------------------------------------------------------------------
+#region Designer generated code
+#pragma warning disable
+namespace YADA.Acceptance.Features
+{
+ using TechTalk.SpecFlow;
+
+
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.8.1.0")]
+ [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [NUnit.Framework.TestFixtureAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Small table reading")]
+ public partial class SmallTableReadingFeature
+ {
+
+ private static TechTalk.SpecFlow.ITestRunner testRunner;
+
+#line 1 "SmallTableReading.feature"
+#line hidden
+
+ [NUnit.Framework.TestFixtureSetUpAttribute()]
+ public virtual void FeatureSetup()
+ {
+ testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
+ TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Small table reading", " In order to read a records from a small table\r\n As a developer\r\n I want to us" +
+ "e YADA in the most simple way to read items out of the database and populate val" +
+ "ue objects", ProgrammingLanguage.CSharp, ((string[])(null)));
+ testRunner.OnFeatureStart(featureInfo);
+ }
+
+ [NUnit.Framework.TestFixtureTearDownAttribute()]
+ public virtual void FeatureTearDown()
+ {
+ testRunner.OnFeatureEnd();
+ testRunner = null;
+ }
+
+ [NUnit.Framework.SetUpAttribute()]
+ public virtual void TestInitialize()
+ {
+ }
+
+ [NUnit.Framework.TearDownAttribute()]
+ public virtual void ScenarioTearDown()
+ {
+ testRunner.OnScenarioEnd();
+ }
+
+ public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
+ {
+ testRunner.OnScenarioStart(scenarioInfo);
+ }
+
+ public virtual void ScenarioCleanup()
+ {
+ testRunner.CollectScenarioErrors();
+ }
+
+ public virtual void FeatureBackground()
+ {
+#line 6
+#line 7
+ testRunner.Given("I have a test database created");
+#line 8
+ testRunner.Given("I have small table created");
+#line 9
+ testRunner.Given("I have small table populated");
+#line hidden
+ }
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("I want to read 1 row")]
+ [NUnit.Framework.CategoryAttribute("database")]
+ public virtual void IWantToRead1Row()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("I want to read 1 row", new string[] {
+ "database"});
+#line 12
+this.ScenarioSetup(scenarioInfo);
+#line 6
+this.FeatureBackground();
+#line 13
+ testRunner.When("using a store procedure to read a record");
+#line 14
+ testRunner.Then("the operation should happen in less than 3 ms");
+#line hidden
+ this.ScenarioCleanup();
+ }
+ }
+}
+#pragma warning restore
+#endregion
View
370 Source/Projects/YADA.Acceptance/Scripts/CreateYadaTestDB.sql
@@ -1,184 +1,186 @@
-USE [master];
-GO
-
-IF (EXISTS (SELECT 1 FROM master.dbo.sysdatabases WHERE ('[' + name + ']' = '[YadaTesting]' OR name = 'YadaTesting')))
- BEGIN
-
- ALTER DATABASE [YadaTesting]
-
- SET SINGLE_USER
-
- WITH ROLLBACK IMMEDIATE
-
- DROP DATABASE [YadaTesting];
-
- END
-
-GO
-
-USE [master];
-GO
-
-CREATE DATABASE [YadaTesting]
-GO
-
-ALTER DATABASE [YadaTesting] SET COMPATIBILITY_LEVEL = 100
-GO
-
-IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
-begin
-EXEC [YadaTesting].[dbo].[sp_fulltext_database] @action = 'enable'
-end
-GO
-
-ALTER DATABASE [YadaTesting] SET ANSI_NULL_DEFAULT OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET ANSI_NULLS OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET ANSI_PADDING OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET ANSI_WARNINGS OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET ARITHABORT OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET AUTO_CLOSE OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET AUTO_CREATE_STATISTICS ON
-GO
-
-ALTER DATABASE [YadaTesting] SET AUTO_SHRINK OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET AUTO_UPDATE_STATISTICS ON
-GO
-
-ALTER DATABASE [YadaTesting] SET CURSOR_CLOSE_ON_COMMIT OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET CURSOR_DEFAULT GLOBAL
-GO
-
-ALTER DATABASE [YadaTesting] SET CONCAT_NULL_YIELDS_NULL OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET NUMERIC_ROUNDABORT OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET QUOTED_IDENTIFIER OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET RECURSIVE_TRIGGERS OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET DISABLE_BROKER
-GO
-
-ALTER DATABASE [YadaTesting] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET DATE_CORRELATION_OPTIMIZATION OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET TRUSTWORTHY OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET ALLOW_SNAPSHOT_ISOLATION OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET PARAMETERIZATION SIMPLE
-GO
-
-ALTER DATABASE [YadaTesting] SET READ_COMMITTED_SNAPSHOT OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET HONOR_BROKER_PRIORITY OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET RECOVERY SIMPLE
-GO
-
-ALTER DATABASE [YadaTesting] SET MULTI_USER
-GO
-
-ALTER DATABASE [YadaTesting] SET PAGE_VERIFY CHECKSUM
-GO
-
-ALTER DATABASE [YadaTesting] SET DB_CHAINING OFF
-GO
-
-ALTER DATABASE [YadaTesting] SET READ_WRITE
-GO
-
-
-USE [YadaTesting]
-GO
-
-IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='[dbo].[NarrowSmallData]')
- BEGIN
-
- ALTER TABLE [dbo].[NarrowSmallData] DROP CONSTRAINT [DF_NarrowNoKeysSmallData_DateAdded]
-
-
- DROP TABLE [dbo].[NarrowSmallData]
-
- END
-
-GO
-
-SET ANSI_NULLS ON
-GO
-
-SET QUOTED_IDENTIFIER ON
-GO
-
-SET ANSI_PADDING ON
-GO
-
-CREATE TABLE [dbo].[NarrowSmallData](
- [TableKey] [int] IDENTITY(1,1) NOT NULL,
- [TestValue1] [varchar](50) NOT NULL,
- [TestValue2] [varchar](255) NOT NULL,
- [DateAdded] [datetime] NOT NULL
-) ON [PRIMARY]
-
-GO
-
-SET ANSI_PADDING OFF
-GO
-
-ALTER TABLE [dbo].[NarrowSmallData] ADD CONSTRAINT [DF_NarrowNoKeysSmallData_DateAdded] DEFAULT (getdate()) FOR [DateAdded]
-GO
-
-USE [YadaTesting]
-GO
-
-IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[claims].[RCSelect]') AND type in (N'P', N'PC'))
-DROP PROCEDURE [claims].[RCSelect]
-GO
-
-SET ANSI_NULLS ON
-GO
-
-SET QUOTED_IDENTIFIER ON
-GO
-
-CREATE PROCEDURE [dbo].[GetNarrowSmallDataByID]
- @SmallDataID INT
-AS
-BEGIN
- SELECT
- TableKey,
- TestValue1,
- TestValue2,
- DateAdded
- FROM [dbo].[NarrowSmallData]
-END
-GO
-
-
+USE [master];
+GO
+
+IF (EXISTS (SELECT 1 FROM master.dbo.sysdatabases WHERE ('[' + name + ']' = '[YadaTesting]' OR name = 'YadaTesting')))
+ BEGIN
+
+ ALTER DATABASE [YadaTesting]
+
+ SET SINGLE_USER
+
+ WITH ROLLBACK IMMEDIATE
+
+ DROP DATABASE [YadaTesting];
+
+ END
+
+GO
+
+USE [master];
+GO
+
+CREATE DATABASE [YadaTesting]
+GO
+
+ALTER DATABASE [YadaTesting] SET COMPATIBILITY_LEVEL = 100
+GO
+
+IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
+begin
+EXEC [YadaTesting].[dbo].[sp_fulltext_database] @action = 'enable'
+end
+GO
+
+ALTER DATABASE [YadaTesting] SET ANSI_NULL_DEFAULT OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET ANSI_NULLS OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET ANSI_PADDING OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET ANSI_WARNINGS OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET ARITHABORT OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET AUTO_CLOSE OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET AUTO_CREATE_STATISTICS ON
+GO
+
+ALTER DATABASE [YadaTesting] SET AUTO_SHRINK OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET AUTO_UPDATE_STATISTICS ON
+GO
+
+ALTER DATABASE [YadaTesting] SET CURSOR_CLOSE_ON_COMMIT OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET CURSOR_DEFAULT GLOBAL
+GO
+
+ALTER DATABASE [YadaTesting] SET CONCAT_NULL_YIELDS_NULL OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET NUMERIC_ROUNDABORT OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET QUOTED_IDENTIFIER OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET RECURSIVE_TRIGGERS OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET DISABLE_BROKER
+GO
+
+ALTER DATABASE [YadaTesting] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET DATE_CORRELATION_OPTIMIZATION OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET TRUSTWORTHY OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET ALLOW_SNAPSHOT_ISOLATION OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET PARAMETERIZATION SIMPLE
+GO
+
+ALTER DATABASE [YadaTesting] SET READ_COMMITTED_SNAPSHOT OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET HONOR_BROKER_PRIORITY OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET RECOVERY SIMPLE
+GO
+
+ALTER DATABASE [YadaTesting] SET MULTI_USER
+GO
+
+ALTER DATABASE [YadaTesting] SET PAGE_VERIFY CHECKSUM
+GO
+
+ALTER DATABASE [YadaTesting] SET DB_CHAINING OFF
+GO
+
+ALTER DATABASE [YadaTesting] SET READ_WRITE
+GO
+
+
+USE [YadaTesting]
+GO
+
+IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='[dbo].[NarrowSmallData]')
+ BEGIN
+
+ ALTER TABLE [dbo].[NarrowSmallData] DROP CONSTRAINT [DF_NarrowNoKeysSmallData_DateAdded]
+
+
+ DROP TABLE [dbo].[NarrowSmallData]
+
+ END
+
+GO
+
+SET ANSI_NULLS ON
+GO
+
+SET QUOTED_IDENTIFIER ON
+GO
+
+SET ANSI_PADDING ON
+GO
+
+CREATE TABLE [dbo].[NarrowSmallData](
+ [TableKey] [int] IDENTITY(1,1) NOT NULL,
+ [TestValue1] [varchar](50) NOT NULL,
+ [TestValue2] [varchar](255) NOT NULL,
+ [DateAdded] [datetime] NOT NULL
+) ON [PRIMARY]
+
+GO
+
+SET ANSI_PADDING OFF
+GO
+
+ALTER TABLE [dbo].[NarrowSmallData] ADD CONSTRAINT [DF_NarrowNoKeysSmallData_DateAdded] DEFAULT (getdate()) FOR [DateAdded]
+GO
+
+USE [YadaTesting]
+GO
+
+IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[claims].[RCSelect]') AND type in (N'P', N'PC'))
+DROP PROCEDURE [claims].[RCSelect]
+GO
+
+SET ANSI_NULLS ON
+GO
+
+SET QUOTED_IDENTIFIER ON
+GO
+
+CREATE PROCEDURE [dbo].[GetNarrowSmallDataByID]
+ @SmallDataID INT
+AS
+BEGIN
+ SELECT
+ TableKey,
+ TestValue1,
+ TestValue2,
+ DateAdded
+ FROM [dbo].[NarrowSmallData]
+ WHERE
+ TableKey = @SmallDataID
+END
+GO
+
+
View
37 Source/Projects/YADA.Acceptance/StepDefinations/SmallTableReading.cs
@@ -66,24 +66,43 @@ public void WhenUsingAStoreProcedureToReadARecord()
{
var stopWatch = Stopwatch.StartNew();
- var item = Reader<NarrowSmallData>.GetRecord("YadaTesting.dbo.GetNarrowSmallDataByID", 1);
+ var keyID = (i % 2) + 1;
+
+ var item = Database<NarrowSmallData>.GetRecord("YadaTesting.dbo.GetNarrowSmallDataByID", new Parameter("SmallDataID", keyID));
stopWatch.Stop();
ExecutionTime = stopWatch.Elapsed;
- Console.WriteLine("Time for read {0} MS", ExecutionTime.Milliseconds);
-
ExecutionTimes.Add(ExecutionTime.Milliseconds);
+
+ switch (keyID)
+ {
+ case 1:
+ item.TableKey.Should().Be(1);
+ item.TestValue1.Should().Be("WhatIsOurTopic");
+ item.TestValue2.Should().Be("RellectionAndTheBartletPyshcos");
+ item.DateAdded.Should().BeBefore(DateTime.Now);
+ item.DateAdded.Should().BeAfter(DateTime.Now.AddDays(-1));
+ break;
+ case 2:
+ item.TableKey.Should().Be(2);
+ item.TestValue1.Should().Be("FoldedPieceOfPaper");
+ item.TestValue2.Should().Be("They are Teaching Us something about ourselves");
+ item.DateAdded.Should().BeBefore(DateTime.Now);
+ item.DateAdded.Should().BeAfter(DateTime.Now.AddDays(-1));
+ break;
+ default:
+ item.TableKey.Should().Be(3);
+ item.TestValue1.Should().Be("DropOff");
+ item.TestValue2.Should().Be("What time do you want to drop off the kids?");
+ item.DateAdded.Should().BeBefore(DateTime.Now);
+ item.DateAdded.Should().BeAfter(DateTime.Now.AddDays(-1));
+ break;
+ }
}
Console.WriteLine("Average Read Time for read {0} MS", AverageExecutionTime);
-
- //item.TableKey.Should().Be(1);
- //item.TestValue1.Should().Be("WhatIsOurTopic");
- //item.TestValue2.Should().Be("RellectionAndTheBartletPyshcos");
- //item.DateAdded.Should().BeBefore(DateTime.Now);
- //item.DateAdded.Should().BeAfter(DateTime.Now.AddDays(-1));
}
}
}
View
14 Source/Projects/YADA/DataAccess/DataOperation.cs
@@ -6,15 +6,10 @@ namespace YADA.DataAccess
{
internal class DataOperation : IDisposable
{
- public static IDataReader RetrieveRecord(string storeProcedure, Parameter parameter)
- {
- return new DataOperation(storeProcedure, parameter).RetrieveRecord();
- }
-
protected SqlCommand _command;
protected SqlConnection _conn;
- private DataOperation(string storeProcedure, Parameter parameter)
+ public DataOperation(string storeProcedure, Parameter parameter)
{
CommandText = storeProcedure;
Parameter = parameter;
@@ -26,6 +21,9 @@ private DataOperation(string storeProcedure, Parameter parameter)
public void Dispose()
{
if (_conn.State == ConnectionState.Open) _conn.Close();
+
+ _command.Dispose();
+ _conn.Dispose();
}
private SqlCommand CreateCommand()
@@ -41,7 +39,7 @@ private SqlConnection CreateConnection()
return _conn = new SqlConnection(ConfigurationManager.ConnectionString);
}
- private IDataReader RetrieveRecord()
+ public IDataReader RetrieveRecord()
{
CreateConnection();
using (CreateCommand())
@@ -52,8 +50,6 @@ private IDataReader RetrieveRecord()
var reader = _command.ExecuteReader(CommandBehavior.SingleRow);
- //_conn.Close();
-
return reader;
}
}
View
201 Source/Projects/YADA/DataAccess/YadaReader.cs
@@ -0,0 +1,201 @@
+using System;
+using System.Data;
+
+namespace YADA.DataAccess
+{
+ internal class YadaReader : IDataReader
+ {
+ public static IDataReader RetrieveRecord(string storeProcedure, Parameter parameter)
+ {
+ return new YadaReader(storeProcedure, parameter).GetReader();
+ }
+
+ private YadaReader(string storeProcedure, Parameter parameter)
+ {
+ DataOperation = new DataOperation(storeProcedure, parameter);
+ }
+
+ public YadaReader(IDataReader reader)
+ {
+ Reader = reader;
+ }
+
+ private DataOperation DataOperation { get; set; }
+
+ private IDataReader Reader { get; set; }
+
+ public void Dispose()
+ {
+ Reader.Dispose();
+ DataOperation.Dispose();
+ }
+
+ public string GetName(int i)
+ {
+ return Reader.GetName(i);
+ }
+
+ public string GetDataTypeName(int i)
+ {
+ return Reader.GetDataTypeName(i);
+ }
+
+ public Type GetFieldType(int i)
+ {
+ return Reader.GetFieldType(i);
+ }
+
+ public object GetValue(int i)
+ {
+ return Reader.GetValue(i);
+ }
+
+ public int GetValues(object[] values)
+ {
+ return Reader.GetValues(values);
+ }
+
+ public int GetOrdinal(string name)
+ {
+ return Reader.GetOrdinal(name);
+ }
+
+ public bool GetBoolean(int i)
+ {
+ return Reader.GetBoolean(i);
+ }
+
+ public byte GetByte(int i)
+ {
+ return Reader.GetByte(i);
+ }
+
+ public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
+ {
+ return Reader.GetBytes(i, fieldOffset, buffer, bufferoffset, length);
+ }
+
+ public char GetChar(int i)
+ {
+ return Reader.GetChar(i);
+ }
+
+ public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
+ {
+ return Reader.GetChars(i, fieldoffset, buffer, bufferoffset, length);
+ }
+
+ public Guid GetGuid(int i)
+ {
+ return Reader.GetGuid(i);
+ }
+
+ public short GetInt16(int i)
+ {
+ return Reader.GetInt16(i);
+ }
+
+ public int GetInt32(int i)
+ {
+ return Reader.GetInt32(i);
+ }
+
+ public long GetInt64(int i)
+ {
+ return Reader.GetInt64(i);
+ }
+
+ public float GetFloat(int i)
+ {
+ return Reader.GetFloat(i);
+ }
+
+ public double GetDouble(int i)
+ {
+ return Reader.GetDouble(i);
+ }
+
+ public string GetString(int i)
+ {
+ return Reader.GetString(i);
+ }
+
+ public decimal GetDecimal(int i)
+ {
+ return Reader.GetDecimal(i);
+ }
+
+ public DateTime GetDateTime(int i)
+ {
+ return Reader.GetDateTime(i);
+ }
+
+ public IDataReader GetData(int i)
+ {
+ return Reader.GetData(i);
+ }
+
+ public bool IsDBNull(int i)
+ {
+ return Reader.IsDBNull(i);
+ }
+
+ public int FieldCount
+ {
+ get { return Reader.FieldCount; }
+ }
+
+ object IDataRecord.this[int i]
+ {
+ get { return Reader[i]; }
+ }
+
+ object IDataRecord.this[string name]
+ {
+ get { return Reader[name]; }
+ }
+
+ public void Close()
+ {
+ Reader.Close();
+ DataOperation.Dispose();
+ }
+
+ public DataTable GetSchemaTable()
+ {
+ return Reader.GetSchemaTable();
+ }
+
+ public bool NextResult()
+ {
+ return Reader.NextResult();
+ }
+
+ public bool Read()
+ {
+ return Reader.Read();
+ }
+
+ public int Depth
+ {
+ get { return Reader.Depth; }
+ }
+
+ public bool IsClosed
+ {
+ get { return Reader.IsClosed; }
+ }
+
+ public int RecordsAffected
+ {
+ get { return Reader.RecordsAffected; }
+ }
+
+ private YadaReader GetReader()
+ {
+ Reader = DataOperation.RetrieveRecord();
+
+ return this;
+ }
+ }
+}
View
30 Source/Projects/YADA/DataBase.cs
@@ -0,0 +1,30 @@
+using YADA.DataAccess;
+
+namespace YADA
+{
+ public class Database<TEntity> where TEntity : new()
+ {
+ public static TEntity GetRecord(string procedureName, Parameter parameter)
+ {
+ var newObject = new TEntity();
+
+ using (var reader = YadaReader.RetrieveRecord(procedureName, parameter))
+ {
+ reader.Read();
+
+ var properties = typeof(TEntity).GetProperties();
+
+ foreach(var propertyInfo in properties)
+ {
+ var value = reader[propertyInfo.Name];
+
+ propertyInfo.SetValue(newObject, value, null);
+ }
+
+ reader.Close();
+ }
+
+ return newObject;
+ }
+ }
+}
View
31 Source/Projects/YADA/Reader.cs
@@ -1,31 +0,0 @@
-using YADA.DataAccess;
-
-namespace YADA
-{
- public class Reader<TEntity> where TEntity : new()
- {
- public static TEntity GetRecord(string procedureName, int keyID)
- {
- var parameter = new Parameter("SmallDataID", keyID);
-
- var reader = DataOperation.RetrieveRecord(procedureName, parameter);
-
- reader.Read();
-
- var properties = typeof(TEntity).GetProperties();
-
- var newObject = new TEntity();
-
- foreach(var propertyInfo in properties)
- {
- var value = reader[propertyInfo.Name];
-
- propertyInfo.SetValue(newObject, value, null);
- }
-
- reader.Close();
-
- return newObject;
- }
- }
-}
View
3  Source/Projects/YADA/YADA.csproj
@@ -43,10 +43,11 @@
<ItemGroup>
<Compile Include="ConfigurationManager.cs" />
<Compile Include="DataAccess\DataOperation.cs" />
+ <Compile Include="DataAccess\YadaReader.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Parameter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Reader.cs" />
+ <Compile Include="DataBase.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Please sign in to comment.
Something went wrong with that request. Please try again.