GeezerVison is showing github.com — Added UseSharedConnection to AdoAdapter · ThatRendle/Simple.Data@504a9f5
File treeExpand file treeCollapse file tree Open diff view settings Simple.Data.BehaviourTest
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: CommonAssemblyInfo.cs +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | // COM, set the ComVisible attribute to true on that type. | 20 | 20 | [assembly: ComVisible(false)] | 21 | 21 |
| 22 | | -[assembly: AssemblyVersion("0.10.2.1")] | 23 | | -[assembly: AssemblyFileVersion("0.10.2.1")] | | 22 | +[assembly: AssemblyVersion("0.11.0.1")] | | 23 | +[assembly: AssemblyFileVersion("0.11.0.1")] | 24 | 24 |
|
Collapse file Copy file name to clipboard +102Lines changed: 102 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +<?xml version="1.0" encoding="UTF-8"?> | | 2 | +<VSPerformanceSession Version="1.00"> | | 3 | + <Options> | | 4 | + <Solution>D:\Code\Simple.Data\Simple.Data.sln</Solution> | | 5 | + <CollectionMethod>Instrumentation</CollectionMethod> | | 6 | + <AllocationMethod>None</AllocationMethod> | | 7 | + <LaunchRuntimeControl>true</LaunchRuntimeControl> | | 8 | + <AddReport>true</AddReport> | | 9 | + <ResourceBasedAnalysisSelected>false</ResourceBasedAnalysisSelected> | | 10 | + <ThreadBasedAnalysisSelected>false</ThreadBasedAnalysisSelected> | | 11 | + <UniqueReport>Timestamp</UniqueReport> | | 12 | + <SamplingMethod>Cycles</SamplingMethod> | | 13 | + <CycleCount>10000000</CycleCount> | | 14 | + <PageFaultCount>10</PageFaultCount> | | 15 | + <SysCallCount>10</SysCallCount> | | 16 | + <SamplingCounter Name="" ReloadValue="00000000000f4240" DisplayName="" /> | | 17 | + <RelocateBinaries>false</RelocateBinaries> | | 18 | + <CollectOnHpcCluster>false</CollectOnHpcCluster> | | 19 | + <HPCSettings> | | 20 | + <NumberOfProcesses>0</NumberOfProcesses> | | 21 | + <TargetSelection>UnknownDisabled</TargetSelection> | | 22 | + <ProfileOnRank>0</ProfileOnRank> | | 23 | + <AdvancedProperties> | | 24 | + <Project>PerformanceTestConsole</Project> | | 25 | + <CleanUp>true</CleanUp> | | 26 | + <MpiexecCommand>mpiexec.exe</MpiexecCommand> | | 27 | + <DeployCRT>true</DeployCRT> | | 28 | + </AdvancedProperties> | | 29 | + </HPCSettings> | | 30 | + <HardwareCounters EnableHWCounters="false" /> | | 31 | + <EtwSettings /> | | 32 | + <PdhSettings> | | 33 | + <PdhCountersEnabled>false</PdhCountersEnabled> | | 34 | + <PdhCountersRate>500</PdhCountersRate> | | 35 | + <PdhCounters> | | 36 | + <PdhCounter>\Memory\Pages/sec</PdhCounter> | | 37 | + <PdhCounter>\PhysicalDisk(_Total)\Avg. Disk Queue Length</PdhCounter> | | 38 | + <PdhCounter>\Processor(_Total)\% Processor Time</PdhCounter> | | 39 | + </PdhCounters> | | 40 | + </PdhSettings> | | 41 | + </Options> | | 42 | + <ExcludeSmallFuncs>true</ExcludeSmallFuncs> | | 43 | + <JScriptProfilingEnabled>false</JScriptProfilingEnabled> | | 44 | + <PreinstrumentEvent> | | 45 | + <InstrEventExclude>false</InstrEventExclude> | | 46 | + </PreinstrumentEvent> | | 47 | + <PostinstrumentEvent> | | 48 | + <InstrEventExclude>false</InstrEventExclude> | | 49 | + </PostinstrumentEvent> | | 50 | + <Binaries> | | 51 | + <ProjBinary> | | 52 | + <Path>D:\Code\Simple.Data\PerformanceTestConsole\obj\x86\Debug\PerformanceTestConsole.exe</Path> | | 53 | + <ArgumentTimestamp>01/01/0001 00:00:00</ArgumentTimestamp> | | 54 | + <Instrument>true</Instrument> | | 55 | + <Sample>true</Sample> | | 56 | + <ExternalWebsite>false</ExternalWebsite> | | 57 | + <InteractionProfilingEnabled>false</InteractionProfilingEnabled> | | 58 | + <IsLocalJavascript>false</IsLocalJavascript> | | 59 | + <LaunchProject>true</LaunchProject> | | 60 | + <OverrideProjectSettings>false</OverrideProjectSettings> | | 61 | + <LaunchMethod>Executable</LaunchMethod> | | 62 | + <ExecutablePath>D:\Code\Simple.Data\PerformanceTestConsole\bin\Debug\PerformanceTestConsole.exe</ExecutablePath> | | 63 | + <StartupDirectory>D:\Code\Simple.Data\PerformanceTestConsole\bin\Debug\</StartupDirectory> | | 64 | + <Arguments /> | | 65 | + <NetAppHost>IIS</NetAppHost> | | 66 | + <NetBrowser>InternetExplorer</NetBrowser> | | 67 | + <ExcludeSmallFuncs>true</ExcludeSmallFuncs> | | 68 | + <JScriptProfilingEnabled>false</JScriptProfilingEnabled> | | 69 | + <PreinstrumentEvent> | | 70 | + <InstrEventExclude>false</InstrEventExclude> | | 71 | + </PreinstrumentEvent> | | 72 | + <PostinstrumentEvent> | | 73 | + <InstrEventExclude>false</InstrEventExclude> | | 74 | + </PostinstrumentEvent> | | 75 | + <ProjRef>{C88EA51F-59C4-4283-97AC-06440F4AA4F6}|PerformanceTestConsole\PerformanceTestConsole.csproj</ProjRef> | | 76 | + <ProjPath>D:\Code\Simple.Data\PerformanceTestConsole\PerformanceTestConsole.csproj</ProjPath> | | 77 | + <ProjName>PerformanceTestConsole</ProjName> | | 78 | + </ProjBinary> | | 79 | + </Binaries> | | 80 | + <Reports> | | 81 | + <Report> | | 82 | + <Path>D:\Code\Simple.Data\PerformanceTestConsole111123.vsp</Path> | | 83 | + </Report> | | 84 | + </Reports> | | 85 | + <Launches> | | 86 | + <ProjBinary> | | 87 | + <Path>:PB:{C88EA51F-59C4-4283-97AC-06440F4AA4F6}|PerformanceTestConsole\PerformanceTestConsole.csproj</Path> | | 88 | + </ProjBinary> | | 89 | + </Launches> | | 90 | + <RuntimeMarks> | | 91 | + <MarkName>Mark One</MarkName> | | 92 | + <MarkName>Mark Two</MarkName> | | 93 | + <MarkName>Mark Three</MarkName> | | 94 | + <MarkName>Mark Four</MarkName> | | 95 | + <MarkName>Mark Five</MarkName> | | 96 | + <MarkName>Mark Six</MarkName> | | 97 | + <MarkName>Mark Seven</MarkName> | | 98 | + <MarkName>Mark Eight</MarkName> | | 99 | + <MarkName>Mark Nine</MarkName> | | 100 | + <MarkName>Mark Ten</MarkName> | | 101 | + </RuntimeMarks> | | 102 | +</VSPerformanceSession> |
Collapse file Copy file name to clipboardExpand all lines: PerformanceTestConsole/PerformanceTestConsole.csproj +11-12Lines changed: 11 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 34 | 34 | <WarningLevel>4</WarningLevel> | 35 | 35 | </PropertyGroup> | 36 | 36 | <ItemGroup> | 37 | | - <Reference Include="Simple.Data, Version=0.6.1.0, Culture=neutral, processorArchitecture=MSIL"> | 38 | | - <HintPath>..\packages\Simple.Data.Core.0.6.1\lib\net40\Simple.Data.dll</HintPath> | 39 | | - </Reference> | 40 | | - <Reference Include="Simple.Data.Ado, Version=0.6.1.0, Culture=neutral, processorArchitecture=MSIL"> | 41 | | - <HintPath>..\packages\Simple.Data.Ado.0.6.1\lib\net40\Simple.Data.Ado.dll</HintPath> | 42 | | - </Reference> | 43 | | - <Reference Include="Simple.Data.SqlCe40"> | 44 | | - <HintPath>..\packages\Simple.Data.SqlCompact40.0.6.1\lib\net40\Simple.Data.SqlCe40.dll</HintPath> | 45 | | - </Reference> | 46 | 37 | <Reference Include="System" /> | 47 | 38 | <Reference Include="System.Core" /> | 48 | 39 | <Reference Include="System.Xml.Linq" /> | | 56 | 47 | <Compile Include="Properties\AssemblyInfo.cs" /> | 57 | 48 | </ItemGroup> | 58 | 49 | <ItemGroup> | | 50 | + <None Include="packages.config" /> | | 51 | + </ItemGroup> | | 52 | + <ItemGroup> | | 53 | + <ProjectReference Include="..\Simple.Data.Ado\Simple.Data.Ado.csproj"> | | 54 | + <Project>{ECC2D7DB-EC7F-44B6-B09F-5B471C629685}</Project> | | 55 | + <Name>Simple.Data.Ado</Name> | | 56 | + </ProjectReference> | 59 | 57 | <ProjectReference Include="..\Simple.Data.SqlServer\Simple.Data.SqlServer.csproj"> | 60 | 58 | <Project>{E24F1C0F-3DCD-4BE5-9A6E-78EF6CB392A1}</Project> | 61 | 59 | <Name>Simple.Data.SqlServer</Name> | 62 | 60 | </ProjectReference> | 63 | | - </ItemGroup> | 64 | | - <ItemGroup> | 65 | | - <None Include="packages.config" /> | | 61 | + <ProjectReference Include="..\Simple.Data\Simple.Data.csproj"> | | 62 | + <Project>{148CEE80-2E84-4ABD-B5AB-20415B2BBD21}</Project> | | 63 | + <Name>Simple.Data</Name> | | 64 | + </ProjectReference> | 66 | 65 | </ItemGroup> | 67 | 66 | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | 68 | 67 | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |
Collapse file Copy file name to clipboardExpand all lines: PerformanceTestConsole/Program.cs +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 |
| 9 | 9 | namespace PerformanceTestConsole | 10 | 10 | { | | 11 | + using Simple.Data.Ado; | | 12 | + | 11 | 13 | class Post | 12 | 14 | { | 13 | 15 | public int Id { get; set; } | @@ -29,11 +31,11 @@ class Post | 29 | 31 | class Program | 30 | 32 | { | 31 | 33 |
| 32 | | - public static readonly string connectionString = "Data Source=SQL2008;Initial Catalog=tempdb;User ID=sa;Password=SAPassword01"; | | 34 | + public static readonly string ConnectionString = "Data Source=.;Initial Catalog=tempdb;Integrated Security=true"; | 33 | 35 |
| 34 | 36 | public static SqlConnection GetOpenConnection() | 35 | 37 | { | 36 | | - var connection = new SqlConnection(connectionString); | | 38 | + var connection = new SqlConnection(ConnectionString); | 37 | 39 | connection.Open(); | 38 | 40 | return connection; | 39 | 41 | } | @@ -166,7 +168,8 @@ public void Run(int iterations) | 166 | 168 | public void Run(int iterations) | 167 | 169 | { | 168 | 170 | var tests = new Tests(); | 169 | | - var simpleDb = Simple.Data.Database.OpenConnection(Program.connectionString); | | 171 | + var simpleDb = Simple.Data.Database.OpenConnection(Program.ConnectionString); | | 172 | + ((AdoAdapter)simpleDb.GetAdapter()).UseSharedConnection(Program.GetOpenConnection()); | 170 | 173 | simpleDb.Posts.FindById(1); | 171 | 174 | tests.Add(id => simpleDb.Posts.FindById(id), "Dynamic Simple.Data Query"); | 172 | 175 |
| @@ -176,7 +179,7 @@ public void Run(int iterations) | 176 | 179 |
| 177 | 180 | var postCommand = new SqlCommand(); | 178 | 181 | postCommand.Connection = connection; | 179 | | - postCommand.CommandText = @"select Id, [Text], [CreationDate], LastChangeDate, | | 182 | + postCommand.CommandText = @"select top 1 Id, [Text], [CreationDate], LastChangeDate, | 180 | 183 | Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9 from Posts where Id = @Id"; | 181 | 184 | var idParam = postCommand.Parameters.Add("@Id", System.Data.SqlDbType.Int); | 182 | 185 |
| |
Collapse file Copy file name to clipboard Collapse file Copy file name to clipboardExpand all lines: ProfilingApp/FindByTask.cs +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ namespace ProfilingApp | 9 | 9 |
| 10 | 10 | class FindByTask : IProfileTask | 11 | 11 | { | | 12 | + private readonly dynamic _db = Database.OpenConnection(Properties.Settings.Default.ConnectionString); | 12 | 13 | public void Run() | 13 | 14 | { | 14 | 15 | for (int i = 1; i < 101; i++) | @@ -17,9 +18,9 @@ public void Run() | 17 | 18 | } | 18 | 19 | } | 19 | 20 |
| 20 | | - private static void GetPostAndPrintTitle(int i) | | 21 | + private void GetPostAndPrintTitle(int i) | 21 | 22 | { | 22 | | - var post = Database.OpenConnection(Properties.Settings.Default.ConnectionString).Posts.FindById(i); | | 23 | + var post = _db.Posts.FindById(i); | 23 | 24 | Console.WriteLine(post.Title); | 24 | 25 | } | 25 | 26 | } | |
Collapse file Copy file name to clipboardExpand all lines: ProfilingApp/Program.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,7 @@ static void Main(string[] args) | 14 | 14 | { | 15 | 15 | ResetDatabase(); | 16 | 16 |
| 17 | | - new QueryWithCountTask().Run(); | | 17 | + new FindByTask().Run(); | 18 | 18 | } | 19 | 19 |
| 20 | 20 | private static void ResetDatabase() | |
Collapse file Copy file name to clipboardExpand all lines: Simple.Data.Ado/AdoAdapter.cs +14-2Lines changed: 14 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,7 @@ public IConnectionProvider ConnectionProvider | 39 | 39 |
| 40 | 40 | private DatabaseSchema _schema; | 41 | 41 | private Lazy<AdoAdapterRelatedFinder> _relatedFinder; | | 42 | + private IDbConnection _sharedConnection; | 42 | 43 |
| 43 | 44 | public AdoAdapter() | 44 | 45 | { | @@ -355,7 +356,8 @@ public IEnumerable<string> GetKeyFieldNames(string tableName) | 355 | 356 |
| 356 | 357 | private int Execute(ICommandBuilder commandBuilder) | 357 | 358 | { | 358 | | - using (var connection = CreateConnection()) | | 359 | + var connection = CreateConnection(); | | 360 | + using (connection.MaybeDisposable()) | 359 | 361 | { | 360 | 362 | using (var command = commandBuilder.GetCommand(connection)) | 361 | 363 | { | @@ -388,9 +390,19 @@ private static int TryExecute(IDbCommand command) | 388 | 390 | } | 389 | 391 | } | 390 | 392 |
| | 393 | + public void UseSharedConnection(IDbConnection connection) | | 394 | + { | | 395 | + _sharedConnection = connection; | | 396 | + } | | 397 | + | | 398 | + public void StopUsingSharedConnection() | | 399 | + { | | 400 | + _sharedConnection = null; | | 401 | + } | | 402 | + | 391 | 403 | internal IDbConnection CreateConnection() | 392 | 404 | { | 393 | | - return _connectionProvider.CreateConnection(); | | 405 | + return _sharedConnection ?? _connectionProvider.CreateConnection(); | 394 | 406 | } | 395 | 407 |
| 396 | 408 | internal DatabaseSchema GetSchema() | |
Collapse file Copy file name to clipboardExpand all lines: Simple.Data.Ado/AdoAdapterFinder.cs +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | using System.Data.Common; | 6 | 6 | using System.Linq; | 7 | 7 | using System.Text; | 8 | | -using Simple.Data.Ado.Schema; | 9 | 8 |
| 10 | 9 | namespace Simple.Data.Ado | 11 | 10 | { | @@ -19,7 +18,6 @@ class AdoAdapterFinder | 19 | 18 | private readonly AdoAdapter _adapter; | 20 | 19 | private readonly IDbTransaction _transaction; | 21 | 20 | private readonly IDbConnection _connection; | 22 | | - private readonly DatabaseSchema _schema; | 23 | 21 |
| 24 | 22 | public AdoAdapterFinder(AdoAdapter adapter) : this(adapter, null) | 25 | 23 | { | @@ -157,7 +155,7 @@ private static IEnumerable<IDictionary<string, object>> TryExecuteQuery(IDbConne | 157 | 155 | private static IDictionary<string, object> TryExecuteSingletonQuery(IDbConnection connection, IDbCommand command, IDictionary<string, int> index) | 158 | 156 | { | 159 | 157 | command.WriteTrace(); | 160 | | - using (connection) | | 158 | + using (connection.MaybeDisposable()) | 161 | 159 | using (command) | 162 | 160 | { | 163 | 161 | try | @@ -180,6 +178,16 @@ private static IDictionary<string, object> TryExecuteSingletonQuery(IDbConnectio | 180 | 178 | return null; | 181 | 179 | } | 182 | 180 |
| | 181 | + private static IDisposable DisposeWrap(IDbConnection connection) | | 182 | + { | | 183 | + if (connection.State == ConnectionState.Open) | | 184 | + { | | 185 | + return ActionDisposable.NoOp; | | 186 | + } | | 187 | + | | 188 | + return new ActionDisposable(connection.Dispose); | | 189 | + } | | 190 | + | 183 | 191 | private static object FixObjectType(object value) | 184 | 192 | { | 185 | 193 | if (value == null) return DBNull.Value; | |
Collapse file Copy file name to clipboardExpand all lines: Simple.Data.Ado/AdoAdapterInserter.cs +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -103,7 +103,8 @@ internal IDictionary<string, object> ExecuteSingletonQuery(string sql, IEnumerab | 103 | 103 | return TryExecuteSingletonQuery(command); | 104 | 104 | } | 105 | 105 |
| 106 | | - using (var connection = _adapter.CreateConnection()) | | 106 | + var connection = _adapter.CreateConnection(); | | 107 | + using (connection.MaybeDisposable()) | 107 | 108 | { | 108 | 109 | using (var command = new CommandHelper(_adapter).CreateInsert(connection, sql, columns, values.ToArray())) | 109 | 110 | { | @@ -125,7 +126,8 @@ internal IDictionary<string, object> ExecuteSingletonQuery(string insertSql, str | 125 | 126 | return TryExecuteSingletonQuery(command); | 126 | 127 | } | 127 | 128 |
| 128 | | - using (var connection = _adapter.CreateConnection()) | | 129 | + var connection = _adapter.CreateConnection(); | | 130 | + using (connection.MaybeDisposable()) | 129 | 131 | { | 130 | 132 | using (var command = new CommandHelper(_adapter).CreateInsert(connection, insertSql, columns, values.ToArray())) | 131 | 133 | { | @@ -167,7 +169,8 @@ internal int Execute(string sql, IEnumerable<Column> columns, IEnumerable<Object | 167 | 169 | command.Transaction = _transaction; | 168 | 170 | return TryExecute(command); | 169 | 171 | } | 170 | | - using (var connection = _adapter.CreateConnection()) | | 172 | + var connection = _adapter.CreateConnection(); | | 173 | + using (connection.MaybeDisposable()) | 171 | 174 | { | 172 | 175 | using (var command = new CommandHelper(_adapter).CreateInsert(connection, sql, columns, values.ToArray())) | 173 | 176 | { | |
|