Skip to content

Commit

Permalink
* Compiles and passes initial tests
Browse files Browse the repository at this point in the history
** refactored Controller.cs to perform DB operations directly
   -- avoid use of Repositories
   -- use SPs for INSERTS
      *** except for the DATA (IMAGE) records, which are done in BATCH mode
  • Loading branch information
NikTJ777 committed Sep 15, 2015
1 parent 22fa2d3 commit 86a21eb
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 85 deletions.
27 changes: 15 additions & 12 deletions TreeLoader/Application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ db.init.sql=DROP PROCEDURE ${db.schema}.${sp.name.prefix}InsertOwner IF EXISTS;\
DROP PROCEDURE ${db.schema}.${sp.name.prefix}InsertGroup IF EXISTS;\n\
DROP PROCEDURE ${db.schema}.${sp.name.prefix}InsertData IF EXISTS;\n\
DROP PROCEDURE ${db.schema}.${sp.name.prefix}UpdateGroup IF EXISTS;\n\
DROP TRIGGER ${db.schema}.Trigger_data_update_data_count IF EXISTS;\n\
DROP INDEX ${db.schema}.groupLookup IF EXISTS;\n\
DROP INDEX ${db.schema}.eventLookup IF EXISTS;\n\
DROP TABLE ${db.schema}."OWNER" IF EXISTS;\n\
Expand All @@ -136,46 +137,46 @@ db.init.sql=DROP PROCEDURE ${db.schema}.${sp.name.prefix}InsertOwner IF EXISTS;\
create table ${db.schema}."DATA" (id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, groupId BIGINT, dataGuid String, instanceUID STRING, createdDateTime TIMESTAMP(0), acquiredDateTime TIMESTAMP(0), version INT, active BOOLEAN, sizeOnDiskMB DECIMAL(6,2), regionWeek STRING);\n\
CREATE INDEX groupLookup on ${db.schema}."DATA" (groupId);\n\
CREATE INDEX eventLookup on ${db.schema}."GROUP" (eventId);\n\
create procedure ${db.schema}.${sp.name.prefix}InsertOwner (OUT "@id" BIGINT, $customerId BIGINT, $ownerGuid STRING, $createdDate DATE, $lastUpdated DATE, $name STRING, $masterAliasId BIGINT, $region STRING)\n\
create procedure ${db.schema}.${sp.name.prefix}InsertOwner (OUT "@ID" BIGINT, $customerId BIGINT, $ownerGuid STRING, $createdDate DATE, $lastUpdated DATE, $name STRING, $masterAliasId BIGINT, $region STRING)\n\
AS\n\
VAR $ownerId BIGINT = (SELECT id from ${db.schema}."OWNER" where customerId = $customerId AND ownerGuid = $ownerGuid);\n\
IF ($ownerId IS NULL)\n\
FOR INSERT into ${db.schema}."OWNER" (customerId, ownerGuid, dateCreated, lastUpdated, name, masterAliasId, region)\n\
VALUES ($customerId, $ownerGuid||'-SP', NOW(), NOW(), $name, $masterAliasId, $region);\n\
"@id" = id;\n\
"@ID" = id;\n\
END_FOR;\n\
ELSE\n\
UPDATE ${db.schema}."OWNER" SET lastUpdated = (NOW()) where id = $ownerId;\n\
"@id" = $ownerId;\n\
"@ID" = $ownerId;\n\
END_IF;\n\
END_PROCEDURE;\n\
create procedure ${db.schema}.${sp.name.prefix}InsertEvent (OUT "@id" BIGINT, $customerId BIGINT, $ownerId BIGINT, $eventGuid STRING, $name STRING, $description STRING, $createdDate DATE, $lastUpdated DATE, $region STRING)\n\
create procedure ${db.schema}.${sp.name.prefix}InsertEvent (OUT "@ID" BIGINT, $customerId BIGINT, $ownerId BIGINT, $eventGuid STRING, $name STRING, $description STRING, $createdDate DATE, $lastUpdated DATE, $region STRING)\n\
AS\n\
VAR $eventId BIGINT = (SELECT id from ${db.schema}."EVENT" where customerId = $customerId AND ownerId = $ownerId AND eventGuid = $eventGuid);\n\
IF ($eventId IS NULL)\n\
FOR INSERT into ${db.schema}."EVENT" (customerId, ownerId, eventGuid, name, description, dateCreated, lastUpdated, region)\n\
VALUES ($customerId, $ownerId, $eventGuid||'-SP', $name, $description, NOW(), NOW(), $region);\n\
"@id" = id;\n\
"@ID" = id;\n\
END_FOR;\n\
ELSE\n\
UPDATE ${db.schema}."EVENT" SET lastUpdated = (NOW()) where id = $ownerId;\n\
"@id" = $eventId;\n\
"@ID" = $eventId;\n\
END_IF;\n\
END_PROCEDURE;\n\
create procedure ${db.schema}.${sp.name.prefix}InsertGroup (OUT "@id" BIGINT, $eventId BIGINT, $groupGuid STRING, $description STRING, $dataCount INT, $dateCreated DATE, $lastUpdated DATE, $region STRING, $week BIGINT)\n\
create procedure ${db.schema}.${sp.name.prefix}InsertGroup (OUT "@ID" BIGINT, $eventId BIGINT, $groupGuid STRING, $description STRING, $dataCount INT, $dateCreated DATE, $lastUpdated DATE, $region STRING, $week BIGINT)\n\
AS\n\
VAR $groupId BIGINT = (SELECT id from ${db.schema}."GROUP" where eventId = $eventId AND groupGuid = $groupGuid);\n\
IF ($groupId IS NULL)\n\
FOR INSERT into ${db.schema}."GROUP" (eventId, groupGuid, description, dataCount, dateCreated, lastUpdated, region, week)\n\
VALUES ($eventId, $groupGuid||'-SP', $description, $dataCount, NOW(), NOW(), $region, $week);\n\
"@id" = id;\n\
"@ID" = id;\n\
END_FOR;\n\
ELSE\n\
UPDATE ${db.schema}."GROUP" SET lastUpdated = (NOW()) where id = $groupId;\n\
"@id" = $groupId;\n\
"@ID" = $groupId;\n\
END_IF;\n\
END_PROCEDURE;\n\
create procedure ${db.schema}.${sp.name.prefix}InsertData (OUT "@id" BIGINT, $groupId BIGINT, $dataGuid STRING, $instanceUID STRING, $createdDateTime TIMESTAMP, $acquiredDateTime TIMESTAMP, $version INT, $active BOOLEAN, $sizeOnDiskMB DECIMAL, $regionWeek STRING)\n\
create procedure ${db.schema}.${sp.name.prefix}InsertData (OUT "@ID" BIGINT, $groupId BIGINT, $dataGuid STRING, $instanceUID STRING, $createdDateTime TIMESTAMP, $acquiredDateTime TIMESTAMP, $version INT, $active BOOLEAN, $sizeOnDiskMB DECIMAL, $regionWeek STRING)\n\
AS\n\
VAR $dataId BIGINT;\n\
VAR $currVersion DECIMAL;\n\
Expand All @@ -193,7 +194,9 @@ db.init.sql=DROP PROCEDURE ${db.schema}.${sp.name.prefix}InsertOwner IF EXISTS;\
END_IF;\n\
END_IF;\n\
END_PROCEDURE;\n\
create procedure ${db.schema}.${sp.name.prefix}UpdateGroup ("@id" BIGINT, $dataCount INT)\n\
create procedure ${db.schema}.${sp.name.prefix}UpdateGroup ("@ID" BIGINT)\n\
AS\n\
UPDATE ${db.schema}."GROUP" SET dataCount = $dataCount WHERE id = "@id";\n\
VAR $dataCount = (SELECT count(groupId) from ${db.schema}."DATA" where groupId = "@ID" AND active = '1');\n\
UPDATE ${db.schema}."GROUP" SET dataCount = $dataCount WHERE id = "@ID";\n\
END_PROCEDURE

Loading

0 comments on commit 86a21eb

Please sign in to comment.