Skip to content

Commit f60a4a4

Browse files
committed
Synchronize with http://databooster.codeplex.com/ and add ODP.NET conditional compilation as a option of Oracle provider.
1 parent 5939964 commit f60a4a4

File tree

12 files changed

+663
-126
lines changed

12 files changed

+663
-126
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ClassDiagram MajorVersion="1" MinorVersion="1">
3+
<Class Name="DbParallel.DataAccess.Booster.DbLauncher">
4+
<Position X="1" Y="1" Width="1.75" />
5+
<TypeIdentifier>
6+
<HashCode>AkEAAAAACCEAAAJAAEAAACAACEAAAAAAAAgAAAAAAAA=</HashCode>
7+
<FileName>Booster\DbLauncher.cs</FileName>
8+
</TypeIdentifier>
9+
<Lollipop Position="0.2" />
10+
</Class>
11+
<Class Name="DbParallel.DataAccess.Booster.DbRocket">
12+
<Position X="8" Y="1.25" Width="1.5" />
13+
<TypeIdentifier>
14+
<HashCode>AAAAAAAAQCAAAAAAACAAAAAAAAAAAAAAEAAAAAAAEAA=</HashCode>
15+
<FileName>Booster\DbRocket.cs</FileName>
16+
</TypeIdentifier>
17+
<Lollipop Position="0.2" />
18+
</Class>
19+
<Class Name="DbParallel.DataAccess.Booster.SqlServer.SqlLauncher">
20+
<Position X="3.5" Y="5.75" Width="2" />
21+
<TypeIdentifier>
22+
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAA=</HashCode>
23+
<FileName>SqlServer\Booster\SqlLauncher.cs</FileName>
24+
</TypeIdentifier>
25+
</Class>
26+
<Class Name="DbParallel.DataAccess.Booster.SqlServer.SqlRocket">
27+
<Position X="9.25" Y="4.25" Width="1.75" />
28+
<TypeIdentifier>
29+
<HashCode>AAIAAAACQCwAAAAAAAAAAAAAAAAAQAAAEAAAAAAAAAA=</HashCode>
30+
<FileName>SqlServer\Booster\SqlRocket.cs</FileName>
31+
</TypeIdentifier>
32+
</Class>
33+
<Class Name="DbParallel.DataAccess.Booster.Oracle.OracleLauncher">
34+
<Position X="0.75" Y="5.75" Width="2.25" />
35+
<TypeIdentifier>
36+
<HashCode>AAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
37+
<FileName>Oracle\Booster\OracleLauncher.cs</FileName>
38+
</TypeIdentifier>
39+
</Class>
40+
<Class Name="DbParallel.DataAccess.Booster.Oracle.OracleRocket">
41+
<Position X="6.25" Y="4.25" Width="2.5" />
42+
<TypeIdentifier>
43+
<HashCode>AAAAAAACQDCAAAAAAAAAABAAAAAAAACAEAAgAACAAAA=</HashCode>
44+
<FileName>Oracle\Booster\OracleRocket.cs</FileName>
45+
</TypeIdentifier>
46+
</Class>
47+
<Font Name="Tahoma" Size="8.25" />
48+
</ClassDiagram>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
4+
namespace DbParallel.DataAccess.Booster
5+
{
6+
public abstract class DbLauncher : IDisposable
7+
{
8+
protected const int _MinMultipleRockets = 3;
9+
protected const int _MinBulkSize = 1000;
10+
protected const int _DefaultMultipleRockets = 6;
11+
protected const int _DefaultBulkSize = 500000;
12+
protected const int _CommandTimeout = 3600;
13+
14+
protected readonly BlockingCollection<DbRocket> _FreeQueue;
15+
protected DbRocket _FillingRocket;
16+
17+
protected readonly object _FillingLock;
18+
protected readonly ParallelExecuteWaitHandle _ExecutingHandle;
19+
20+
private bool _Disposed = false;
21+
22+
public DbLauncher()
23+
{
24+
_FreeQueue = new BlockingCollection<DbRocket>();
25+
26+
_FillingLock = new object();
27+
_ExecutingHandle = new ParallelExecuteWaitHandle();
28+
}
29+
30+
public void Post(params IConvertible[] values)
31+
{
32+
lock (_FillingLock)
33+
{
34+
if (_FillingRocket.AddRow(values))
35+
{
36+
_ExecutingHandle.StartNewTask(LaunchRocket, _FillingRocket);
37+
_FillingRocket = _FreeQueue.Take();
38+
}
39+
}
40+
}
41+
42+
private void LaunchRocket(DbRocket rocket)
43+
{
44+
rocket.Launch();
45+
_FreeQueue.Add(rocket);
46+
}
47+
48+
public void Complete()
49+
{
50+
lock (_FillingLock)
51+
{
52+
_FillingRocket.Launch();
53+
_ExecutingHandle.Wait();
54+
}
55+
}
56+
57+
public void Dispose()
58+
{
59+
if (_Disposed == false)
60+
{
61+
Complete();
62+
63+
foreach (DbRocket rocket in _FreeQueue)
64+
rocket.Dispose();
65+
66+
if (_FillingRocket != null)
67+
_FillingRocket.Dispose();
68+
69+
_ExecutingHandle.Dispose();
70+
71+
_Disposed = true;
72+
}
73+
}
74+
}
75+
}
76+
77+
78+
////////////////////////////////////////////////////////////////////////////////////////////////////
79+
//
80+
// Copyright 2012 Abel Cheng
81+
// This source code is subject to terms and conditions of the Apache License, Version 2.0.
82+
// See http://www.apache.org/licenses/LICENSE-2.0.
83+
// All other rights reserved.
84+
// You must not remove this notice, or any other, from this software.
85+
//
86+
// Original Author: Abel Cheng <[email protected]>
87+
// Created Date: 2012-06-10
88+
// Primary Host: http://databooster.codeplex.com
89+
// Change Log:
90+
// Author Date Comment
91+
//
92+
//
93+
//
94+
//
95+
// (Keep clean code rather than complicated code plus long comments.)
96+
//
97+
////////////////////////////////////////////////////////////////////////////////////////////////////
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
3+
namespace DbParallel.DataAccess.Booster
4+
{
5+
public abstract class DbRocket : IDisposable
6+
{
7+
protected readonly int _BulkSize;
8+
protected int _FillingCount;
9+
10+
public DbRocket(int bulkSize)
11+
{
12+
_BulkSize = bulkSize;
13+
_FillingCount = 0;
14+
}
15+
16+
public abstract bool AddRow(params IConvertible[] values);
17+
public abstract int Launch();
18+
19+
public abstract void Dispose();
20+
}
21+
}
22+
23+
24+
////////////////////////////////////////////////////////////////////////////////////////////////////
25+
//
26+
// Copyright 2012 Abel Cheng
27+
// This source code is subject to terms and conditions of the Apache License, Version 2.0.
28+
// See http://www.apache.org/licenses/LICENSE-2.0.
29+
// All other rights reserved.
30+
// You must not remove this notice, or any other, from this software.
31+
//
32+
// Original Author: Abel Cheng <[email protected]>
33+
// Created Date: 2012-06-10
34+
// Primary Host: http://databooster.codeplex.com
35+
// Change Log:
36+
// Author Date Comment
37+
//
38+
//
39+
//
40+
//
41+
// (Keep clean code rather than complicated code plus long comments.)
42+
//
43+
////////////////////////////////////////////////////////////////////////////////////////////////////

TaskParallelFoundation/DataAccess/DataAccess.csproj

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,49 @@
2323
<DebugType>full</DebugType>
2424
<Optimize>false</Optimize>
2525
<OutputPath>bin\Debug\</OutputPath>
26-
<DefineConstants>TRACE;DEBUG;ORACLE</DefineConstants>
26+
<DefineConstants>TRACE;DEBUG;ORACLE;DATADIRECT</DefineConstants>
2727
<ErrorReport>prompt</ErrorReport>
2828
<WarningLevel>4</WarningLevel>
2929
</PropertyGroup>
3030
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3131
<DebugType>pdbonly</DebugType>
3232
<Optimize>true</Optimize>
3333
<OutputPath>bin\Release\</OutputPath>
34-
<DefineConstants>TRACE;SQL_SERVER</DefineConstants>
34+
<DefineConstants>TRACE;ORACLE;DATADIRECT</DefineConstants>
3535
<ErrorReport>prompt</ErrorReport>
3636
<WarningLevel>4</WarningLevel>
3737
</PropertyGroup>
3838
<ItemGroup>
39-
<Reference Include="DDTek.Oracle, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c84cd5c63851e072, processorArchitecture=MSIL">
39+
<Reference Include="DDTek.Oracle, Version=3.5.0.0, Culture=neutral, PublicKeyToken=c84cd5c63851e072, processorArchitecture=MSIL">
4040
<SpecificVersion>False</SpecificVersion>
4141
<HintPath>..\..\..\..\..\..\..\Program Files\Progress\DataDirect\Connect_for_ADO.NET_35\DDTek.Oracle.dll</HintPath>
4242
<Private>False</Private>
4343
</Reference>
4444
<Reference Include="System" />
4545
<Reference Include="System.configuration" />
4646
<Reference Include="System.Data" />
47+
<Reference Include="System.XML" />
4748
</ItemGroup>
4849
<ItemGroup>
50+
<Compile Include="Booster\DbLauncher.cs" />
51+
<Compile Include="Booster\DbRocket.cs" />
4952
<Compile Include="DbAccess.cs" />
5053
<Compile Include="DbExtensions.cs" />
5154
<Compile Include="DbFieldMap.cs" />
5255
<Compile Include="DbParameterBuilder.cs" />
56+
<Compile Include="Oracle\Booster\OracleLauncher.cs" />
57+
<Compile Include="Oracle\Booster\OracleRocket.cs" />
5358
<Compile Include="Oracle\DbAccess.cs" />
5459
<Compile Include="Oracle\DbExtensions.partial.cs" />
5560
<Compile Include="Oracle\DbParameterBuilder.partial.cs" />
5661
<Compile Include="ParallelExecuteWaitHandle.cs" />
5762
<Compile Include="Properties\AssemblyInfo.cs" />
63+
<Compile Include="SqlServer\Booster\SqlLauncher.cs" />
64+
<Compile Include="SqlServer\Booster\SqlRocket.cs" />
5865
</ItemGroup>
66+
<ItemGroup />
5967
<ItemGroup>
60-
<Folder Include="SqlServer\" />
61-
</ItemGroup>
62-
<ItemGroup>
68+
<None Include="Booster\Booster.cd" />
6369
<None Include="DataAccess.cd" />
6470
</ItemGroup>
6571
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#if ORACLE
2+
using System;
3+
using System.Data;
4+
#if DATADIRECT
5+
using DDTek.Oracle;
6+
#else // ODP.NET
7+
using Oracle.DataAccess.Client;
8+
#endif
9+
10+
namespace DbParallel.DataAccess.Booster.Oracle
11+
{
12+
public class OracleLauncher : DbLauncher
13+
{
14+
public OracleLauncher(string connectionString, string storedProcedure, Action<DbParameterBuilder> parametersBuilder,
15+
int multipleRockets = _DefaultMultipleRockets, int bulkSize = _DefaultBulkSize, int commandTimeout = _CommandTimeout)
16+
{
17+
int[] associativeArrayParameterIds;
18+
19+
if (multipleRockets < _MinMultipleRockets)
20+
multipleRockets = _MinMultipleRockets;
21+
22+
if (bulkSize < _MinBulkSize)
23+
bulkSize = _MinBulkSize;
24+
25+
OracleCommand dbCommand = CreateCommand(connectionString, storedProcedure, parametersBuilder, commandTimeout);
26+
associativeArrayParameterIds = OracleRocket.SearchAssociativeArrayParameters(dbCommand.Parameters);
27+
_FillingRocket = new OracleRocket(dbCommand, associativeArrayParameterIds, bulkSize);
28+
29+
for (int i = 1; i < multipleRockets; i++)
30+
{
31+
dbCommand = CreateCommand(connectionString, storedProcedure, parametersBuilder, commandTimeout);
32+
_FreeQueue.Add(new OracleRocket(dbCommand, associativeArrayParameterIds, bulkSize));
33+
}
34+
}
35+
36+
private static OracleCommand CreateCommand(string connectionString, string storedProcedure,
37+
Action<DbParameterBuilder> parametersBuilder, int commandTimeout)
38+
{
39+
OracleConnection dbConnection = new OracleConnection(connectionString);
40+
41+
OracleCommand dbCommand = dbConnection.CreateCommand();
42+
dbCommand.CommandType = CommandType.StoredProcedure;
43+
dbCommand.CommandText = storedProcedure;
44+
45+
if (commandTimeout > 0)
46+
dbCommand.CommandTimeout = commandTimeout;
47+
48+
parametersBuilder(new DbParameterBuilder(dbCommand));
49+
50+
return dbCommand;
51+
}
52+
}
53+
}
54+
#endif
55+
56+
57+
////////////////////////////////////////////////////////////////////////////////////////////////////
58+
//
59+
// Copyright 2012 Abel Cheng
60+
// This source code is subject to terms and conditions of the Apache License, Version 2.0.
61+
// See http://www.apache.org/licenses/LICENSE-2.0.
62+
// All other rights reserved.
63+
// You must not remove this notice, or any other, from this software.
64+
//
65+
// Original Author: Abel Cheng <[email protected]>
66+
// Created Date: 2012-05-18
67+
// Primary Host: http://databooster.codeplex.com
68+
// Change Log:
69+
// Author Date Comment
70+
//
71+
//
72+
//
73+
//
74+
// (Keep clean code rather than complicated code plus long comments.)
75+
//
76+
////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)