Skip to content

Commit 247345e

Browse files
committed
Added Batch handling via Stored Procedures.
1 parent 12e17aa commit 247345e

28 files changed

+1628
-32
lines changed
0 Bytes
Binary file not shown.

020_DIRECT_Framework/Direct_Framework/Direct_Framework.sqlproj

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
<Folder Include="Schemas" />
7070
</ItemGroup>
7171
<ItemGroup>
72-
<Build Include="Functions\GetConsistencyDateTime.sql" />
73-
<Build Include="Functions\GetDependency.sql" />
74-
<Build Include="Functions\GetLoadWindowDateTimes.sql" />
75-
<Build Include="Functions\GetLoadWindowModuleInstance.sql" />
72+
<Build Include="Functions\omd.GetConsistencyDateTime.sql" />
73+
<Build Include="Functions\omd.GetDependency.sql" />
74+
<Build Include="Functions\omd.GetLoadWindowDateTimes.sql" />
75+
<Build Include="Functions\omd.GetLoadWindowModuleInstance.sql" />
7676
<None Include="Scripts\InsertReferenceData.sql" />
7777
<Build Include="Tables\omd.AREA.sql" />
7878
<Build Include="Tables\omd.BATCH.sql" />
@@ -99,18 +99,12 @@
9999
<QuotedIdentifier>On</QuotedIdentifier>
100100
</None>
101101
<Build Include="Schemas\omd.sql" />
102-
<None Include="Views\omd_processing.vw_QUEUE_MODULE_PROCESSING.sql">
103-
<QuotedIdentifier>On</QuotedIdentifier>
104-
</None>
105-
<None Include="Views\omd_processing.vw_QUEUE_BATCH_PROCESSING.sql">
106-
<QuotedIdentifier>On</QuotedIdentifier>
107-
</None>
108102
<Build Include="Schemas\omd_processing.sql" />
109103
<Build Include="Schemas\omd_reporting.sql" />
110104
<None Include="Views\omd_processing.vw_CURRENT_PROCESSING.sql" />
111105
<None Include="Views\omd_reporting.vw_QUEUE_PROGRESS.sql" />
112106
<None Include="Views\omd_reporting.vw_CURRENT_PROCESSING.sql" />
113-
<Build Include="Functions\CalculateChangeKey.sql" />
107+
<Build Include="Functions\omd.CalculateChangeKey.sql" />
114108
<None Include="Functions\omd_processing.NextModuleInQueue.sql" />
115109
<Build Include="Functions\omd_processing.GetDependentTables.sql" />
116110
<Build Include="Views\omd_reporting.vw_CUMULATIVE_LOAD_TIME.sql" />
@@ -123,7 +117,30 @@
123117
<Build Include="Views\omd_reporting.vw_EXCEPTIONS_NON_RUNNING_BATCHES.sql" />
124118
<Build Include="Views\omd_reporting.vw_EXCEPTIONS_NON_RUNNING_MODULES.sql" />
125119
<Build Include="Views\omd_reporting.vw_EXCEPTIONS_TABLE_CONSISTENCY.sql" />
126-
<Build Include="Stored Procedures\usp_Condensing.sql" />
120+
<Build Include="Stored Procedures\omd.TableCondensing.sql" />
121+
<None Include="Views\omd_processing.vw_QUEUE_BATCH_PROCESSING.sql">
122+
<QuotedIdentifier>Off</QuotedIdentifier>
123+
</None>
124+
<None Include="Views\omd_processing.vw_QUEUE_MODULE_PROCESSING.sql">
125+
<QuotedIdentifier>Off</QuotedIdentifier>
126+
</None>
127+
<Build Include="Stored Procedures\omd.CreateModuleInstance.sql" />
128+
<Build Include="Stored Procedures\omd.ModuleEvaluation.sql" />
129+
<Build Include="Stored Procedures\omd.RunModule.sql" />
130+
<Build Include="Stored Procedures\omd.UpdateModuleInstance.sql" />
131+
<Build Include="Functions\omd.GetBatchIdByModuleInstanceId.sql" />
132+
<Build Include="Functions\omd.GetBatchModuleActiveIndicatorValue.sql" />
133+
<Build Include="Functions\omd.GetModuleIdByModuleInstanceId.sql" />
134+
<Build Include="Functions\omd.GetModuleIdByName.sql" />
135+
<Build Include="Functions\omd.GetPreviousModuleInstanceDetails.sql" />
136+
<Build Include="Stored Procedures\omd.BatchEvaluation.sql" />
137+
<Build Include="Stored Procedures\omd.CreateBatchInstance.sql" />
138+
<Build Include="Stored Procedures\omd.RunBatch.sql" />
139+
<Build Include="Stored Procedures\omd.UpdateBatchInstance.sql" />
140+
<Build Include="Functions\omd.GetBatchIdByBatchInstanceId.sql" />
141+
<Build Include="Functions\omd.GetBatchIdByName.sql" />
142+
<Build Include="Functions\omd.GetFailedBatchIdList.sql" />
143+
<Build Include="Functions\omd.GetPreviousBatchInstanceDetails.sql" />
127144
</ItemGroup>
128145
<ItemGroup>
129146
<PostDeploy Include="Scripts\Script.PostDeployment.sql" />
File renamed without changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
CREATE FUNCTION [omd].[GetBatchIdByBatchInstanceId]
4+
(
5+
@BatchInstanceId INT -- An instance of the Batch.
6+
)
7+
RETURNS INT AS
8+
9+
-- =============================================
10+
-- Function: Get Batch Id (by Batch Instance Id)
11+
-- Description: Takes the Batch instance id as input and returns the Batch Id as registered in the framework
12+
-- =============================================
13+
14+
BEGIN
15+
-- Declare ouput variable
16+
17+
DECLARE @BatchId INT =
18+
(
19+
SELECT DISTINCT BatchInstance.Batch_ID
20+
FROM omd.BATCH_INSTANCE BatchInstance
21+
WHERE BatchInstance.BATCH_INSTANCE_ID = @BatchInstanceId
22+
)
23+
24+
SET @BatchId = COALESCE(@BatchId,0)
25+
26+
-- Return the result of the function
27+
RETURN @BatchId
28+
END
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
CREATE FUNCTION [omd].[GetBatchIdByModuleInstanceId]
4+
(
5+
@ModuleInstanceId INT -- An instance of the module.
6+
)
7+
RETURNS INT AS
8+
9+
-- =============================================
10+
-- Function: Get Batch Id (by Module Instance Id)
11+
-- Description: Takes the module instance id as input and returns the Batch Id as registered in the framework
12+
-- =============================================
13+
14+
BEGIN
15+
-- Declare ouput variable
16+
17+
DECLARE @BatchId INT =
18+
(
19+
SELECT DISTINCT batchInstance.BATCH_ID
20+
FROM omd.MODULE_INSTANCE moduleInstance
21+
JOIN omd.BATCH_INSTANCE batchInstance ON moduleInstance.BATCH_INSTANCE_ID = batchInstance.BATCH_INSTANCE_ID
22+
WHERE moduleInstance.MODULE_INSTANCE_ID = @ModuleInstanceId
23+
)
24+
25+
SET @BatchId = COALESCE(@BatchId,0)
26+
27+
-- Return the result of the function
28+
RETURN @BatchId
29+
END
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
CREATE FUNCTION [omd].[GetBatchIdByName]
3+
(
4+
@BatchCode VARCHAR(255) -- The name of the batch, as identified in the BATCH_CODE attribute in the BATCH table.
5+
)
6+
RETURNS VARCHAR(255) AS
7+
8+
-- =============================================
9+
-- Function: Get Batch Id (by name)
10+
-- Description: Takes the batch code as input and returns the Batch ID as registered in the framework
11+
-- =============================================
12+
13+
BEGIN
14+
-- Declare ouput variable
15+
16+
DECLARE @BatchId INT =
17+
(
18+
SELECT batch.Batch_ID
19+
FROM omd.BATCH batch
20+
WHERE BATCH_CODE = @BatchCode
21+
)
22+
23+
SET @BatchId = COALESCE(@BatchId,0)
24+
25+
-- Return the result of the function
26+
RETURN @BatchId
27+
END
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
3+
CREATE FUNCTION [omd].[GetBatchModuleActiveIndicatorValue]
4+
(
5+
@ModuleId INT,
6+
@BatchId INT
7+
)
8+
RETURNS VARCHAR(1) AS
9+
10+
-- =============================================
11+
-- Function: Get the Batch/Module active/inactive flag.
12+
-- Description: Retrieve the Inactive Indicator (flag) for a Batch / Module combination.
13+
-- =============================================
14+
15+
BEGIN
16+
-- Declare ouput variable
17+
18+
DECLARE @InactiveIndicator VARCHAR(1)
19+
20+
SET @InactiveIndicator =
21+
(
22+
SELECT
23+
MIN(INACTIVE_INDICATOR)
24+
FROM
25+
(
26+
SELECT INACTIVE_INDICATOR
27+
FROM omd.BATCH_MODULE
28+
WHERE BATCH_ID = @BatchId AND MODULE_ID = @ModuleId
29+
UNION
30+
-- Return if there is nothing, to give at least a result row for further processing
31+
SELECT null
32+
) sub
33+
)
34+
35+
-- Return the result of the function
36+
RETURN @InactiveIndicator
37+
END

020_DIRECT_Framework/Direct_Framework/Functions/GetConsistencyDateTime.sql renamed to 020_DIRECT_Framework/Direct_Framework/Functions/omd.GetConsistencyDateTime.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE FUNCTION [dbo].[GetConsistencyDateTime] ( @Table_List VARCHAR(MAX), @MeasurementDate datetime2(7))
1+
CREATE FUNCTION [omd].[GetConsistencyDateTime] ( @Table_List VARCHAR(MAX), @MeasurementDate datetime2(7))
22
RETURNS DATETIME2(7) AS
33
BEGIN
44

020_DIRECT_Framework/Direct_Framework/Functions/GetDependency.sql renamed to 020_DIRECT_Framework/Direct_Framework/Functions/omd.GetDependency.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
CREATE FUNCTION [dbo].[GetDependency] (@SchemaName VARCHAR(128), @Table VARCHAR(128))
3+
CREATE FUNCTION [omd].[GetDependency] (@SchemaName VARCHAR(128), @Table VARCHAR(128))
44
RETURNS VARCHAR(MAX) AS
55
BEGIN
66

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
3+
CREATE FUNCTION [omd].[GetFailedBatchIdList]
4+
(
5+
@BatchId INT -- The array of previously failed Batch process relative to the input Batch Id.
6+
)
7+
RETURNS VARCHAR(MAX) AS
8+
9+
-- =============================================
10+
-- Function: Get the list (array) of failed Batch Ids.
11+
-- Description: Takes the batch id as input and returns the failures prior to the Id (from the last previously successful execution).
12+
-- In other words, the failed execution between the last succesful run and the current one.
13+
-- =============================================
14+
15+
BEGIN
16+
17+
DECLARE @BatchIdArray VARCHAR(MAX);
18+
19+
SELECT @BatchIdArray = CAST('(' + STUFF
20+
(
21+
(SELECT ',' + CAST(BATCH_INSTANCE_ID AS VARCHAR(20))
22+
FROM omd.BATCH_INSTANCE
23+
WHERE BATCH_ID = @BatchId
24+
AND
25+
(
26+
BATCH_INSTANCE_ID > (SELECT MAX(BATCH_INSTANCE_ID) FROM omd.BATCH_INSTANCE WHERE BATCH_ID = @BatchId AND (EXECUTION_STATUS_CODE='S' AND NEXT_RUN_INDICATOR = 'P'))
27+
OR
28+
(SELECT COUNT(BATCH_INSTANCE_ID) FROM omd.BATCH_INSTANCE WHERE BATCH_ID = @BatchId AND (EXECUTION_STATUS_CODE='S' AND NEXT_RUN_INDICATOR = 'P')) = 0
29+
)
30+
AND EXECUTION_STATUS_CODE<>'E'
31+
ORDER BY BATCH_INSTANCE_ID
32+
FOR XML PATH ('')
33+
),1,1,''
34+
) + ')' AS VARCHAR(MAX))
35+
36+
RETURN @BatchIdArray;
37+
END

0 commit comments

Comments
 (0)