Skip to content

Commit e0439dc

Browse files
committed
Avoid opening a 2nd connection.
1 parent 1fc8681 commit e0439dc

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

cwms-data-api/src/main/java/cwms/cda/data/dao/LocationGroupDao.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public void create(LocationGroup group) {
486486
CWMS_LOC_PACKAGE.call_CREATE_LOC_GROUP2(dslContext.configuration(), categoryId,
487487
group.getId(), group.getDescription(), group.getOfficeId(), group.getSharedLocAliasId(),
488488
group.getSharedRefLocationId());
489-
assignLocs(group, office);
489+
assignLocs(dslContext, group, office);
490490
});
491491
}
492492

@@ -522,19 +522,28 @@ public void unassignAllLocs(LocationGroup group, String office) {
522522
}
523523

524524
public void assignLocs(LocationGroup group, String office) {
525+
connection(dsl, conn -> {
526+
DSLContext dslContext = getDslContext(conn, office);
527+
assignLocs(dslContext,group, office);
528+
});
529+
}
530+
531+
/**
532+
* Used when an appropriate context already exists to avoid opening a second connection.
533+
* @param dslContext a dslContext that is assumed to be fully prepared for use in this operation
534+
* @param group
535+
* @param office
536+
*/
537+
public void assignLocs(DSLContext dslContext, LocationGroup group, String office) {
525538
List<AssignedLocation> assignedLocations = group.getAssignedLocations();
526539
if (assignedLocations != null) {
527540
List<LOC_ALIAS_TYPE3> collect = assignedLocations.stream()
528541
.map(LocationGroupDao::convertToLocAliasType)
529542
.collect(toList());
530543
LOC_ALIAS_ARRAY3 assignedLocs = new LOC_ALIAS_ARRAY3(collect);
531-
532-
LocationCategory cat = group.getLocationCategory();
533-
connection(dsl, conn -> {
534-
DSLContext dslContext = getDslContext(conn, office);
544+
LocationCategory cat = group.getLocationCategory();
535545
CWMS_LOC_PACKAGE.call_ASSIGN_LOC_GROUPS3(dslContext.configuration(),
536546
cat.getId(), group.getId(), assignedLocs, office);
537-
});
538547
}
539548
}
540549
}

0 commit comments

Comments
 (0)