Skip to content

Commit

Permalink
Hierarchy rebuilds operate within tx
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwatkins73 committed Jul 20, 2019
1 parent 8923dab commit 35ceca3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Waltz - Enterprise Architecture
* Copyright (C) 2016, 2017 Waltz open source project
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project
* See README.md for more information
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -68,16 +68,17 @@ public int replaceHierarchy(EntityKind kind, List<EntityHierarchyItem> hierarchy
checkNotNull(kind, "kind cannot be null");
checkNotNull(hierarchyItems, "hierarchyItems cannot be null");

LOG.info("Replacing hierarchy items for kind: {}, deleting existing", kind);
dsl.deleteFrom(ENTITY_HIERARCHY)
.where(ENTITY_HIERARCHY.KIND.eq(kind.name()))
.execute();
List<EntityHierarchyRecord> records = map(hierarchyItems, ITEM_TO_RECORD_MAPPER);

LOG.info("Replacing hierarchy items for kind: {}, inserting new record (#{})", kind, hierarchyItems.size());

List<EntityHierarchyRecord> records = map(hierarchyItems, ITEM_TO_RECORD_MAPPER);
dsl.batchInsert(records)
.execute();
dsl.transaction(configuration -> {
DSLContext txDsl = DSL.using(configuration);
txDsl.deleteFrom(ENTITY_HIERARCHY)
.where(ENTITY_HIERARCHY.KIND.eq(kind.name()))
.execute();
txDsl.batchInsert(records)
.execute();
});

return records.size();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Waltz - Enterprise Architecture
* Copyright (C) 2016, 2017 Waltz open source project
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project
* See README.md for more information
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -67,8 +67,11 @@ public int[] build() {

List<PersonHierarchyRecord> records = toHierarchyRecords(forest);

dsl.deleteFrom(PERSON_HIERARCHY).execute();
return dsl.batchStore(records).execute();
return dsl.transactionResult(configuration -> {
DSLContext txDsl = DSL.using(configuration);
txDsl.deleteFrom(PERSON_HIERARCHY).execute();
return txDsl.batchStore(records).execute();
});
}


Expand All @@ -80,7 +83,7 @@ private List<PersonHierarchyRecord> toHierarchyRecords(Forest<Person, String> fo
ListUtilities.reverse(
HierarchyUtilities.parents(node)
.stream()
.map(n -> n.getData())
.map(Node::getData)
.collect(Collectors.toList()));

for (int i = 0; i < ancestors.size(); i++) {
Expand Down

0 comments on commit 35ceca3

Please sign in to comment.