Skip to content

Commit dc4e4fe

Browse files
authored
Added global fetchSize variables to DAOs (USACE#877)
Added global fetchSize variables to JooqDao and appropriate DAOs
1 parent 0e97993 commit dc4e4fe

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
public abstract class JooqDao<T> extends Dao<T> {
7373
protected static final int ORACLE_CURSOR_TYPE = -10;
7474
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
75+
public static final int DEFAULT_FETCH_SIZE = 1000;
76+
public static final int DEFAULT_SMALL_FETCH_SIZE = 500;
7577

7678
static ExecuteListener listener = new ExceptionWrappingListener();
7779
private static Pattern INVALID_OFFICE_ID = Pattern.compile(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public Optional<LocationGroup> getLocationGroup(@NotNull String officeId, @NotNu
124124
.and(alcg.CAT_DB_OFFICE_ID.in(CWMS, officeId))
125125
.and(assignmentOffice)
126126
)
127-
.orderBy(alga.ATTRIBUTE).fetchSize(1000).fetch(mapper);
127+
.orderBy(alga.ATTRIBUTE).fetchSize(DEFAULT_FETCH_SIZE).fetch(mapper);
128128

129129
// Might want to verify that all the groups in the list are the same?
130130
LocationGroup locGroup =
@@ -379,7 +379,7 @@ public List<LocationGroup> getLocationGroups(String locationOfficeId, String gro
379379

380380
Map<LocationGroup, List<AssignedLocation>> map = new LinkedHashMap<>();
381381
connectBy.orderBy(alcg.LOC_CATEGORY_ID, alcg.LOC_GROUP_ID, alga.ATTRIBUTE)
382-
.fetchSize(1000) // This made the query go from 2 minutes to 10 seconds?
382+
.fetchSize(DEFAULT_FETCH_SIZE) // This made the query go from 2 minutes to 10 seconds?
383383
.stream().map(mapper::map).forEach(pair -> {
384384
LocationGroup locationGroup = pair.component1();
385385
List<AssignedLocation> list = map.computeIfAbsent(locationGroup, k -> new ArrayList<>());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public List<Location> getLocations(String nameRegex, String unitSystem, String d
121121
return dsl.select(AV_LOC.asterisk())
122122
.from(AV_LOC)
123123
.where(whereCondition)
124-
.fetchSize(500)
124+
.fetchSize(DEFAULT_SMALL_FETCH_SIZE)
125125
.fetch(this::buildLocation);
126126
}
127127

@@ -291,7 +291,7 @@ public FeatureCollection buildFeatureCollection(String names, String units, Stri
291291
selectQuery = selectQuery.and(AV_LOC.LOCATION_ID.in(identifiers));
292292
}
293293

294-
List<Feature> features = selectQuery.fetchSize(500).stream()
294+
List<Feature> features = selectQuery.fetchSize(DEFAULT_SMALL_FETCH_SIZE).stream()
295295
.map(LocationsDaoImpl::buildFeatureFromAvLocRecord)
296296
.collect(toList());
297297
FeatureCollection collection = new FeatureCollection();
@@ -433,7 +433,7 @@ private Catalog getLocationCatalog(Catalog.CatalogPage catPage, int pageSize, Ca
433433
.orderBy(avLoc2.DB_OFFICE_ID.asc(),limitId.asc(),avLoc2.ALIASED_ITEM.asc());
434434
logger.log(Level.FINER, () -> query.getSQL(ParamType.INLINED));
435435
List<? extends CatalogEntry> entries = query
436-
.fetchSize(1000)
436+
.fetchSize(DEFAULT_FETCH_SIZE)
437437
.fetchStream()
438438
.map(r -> r.into(AV_LOC2.AV_LOC2))
439439
.collect(groupingBy(usace.cwms.db.jooq.codegen.tables.records.AV_LOC2::getLOCATION_CODE))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Collection<RatingSpec> retrieveRatingSpecs(String office, String specIdMa
9494
.leftOuterJoin(ratView)
9595
.on(specView.RATING_SPEC_CODE.eq(ratView.RATING_SPEC_CODE))
9696
.where(condition)
97-
.fetchSize(1000);
97+
.fetchSize(DEFAULT_FETCH_SIZE);
9898

9999
logger.fine(() -> query.getSQL(ParamType.INLINED));
100100

@@ -248,7 +248,7 @@ public Optional<RatingSpec> retrieveRatingSpec(String office, String specId) {
248248
.on(specView.RATING_SPEC_CODE.eq(ratView.RATING_SPEC_CODE))
249249
.where(condition)
250250
.orderBy(specView.OFFICE_ID, specView.RATING_ID, ratView.EFFECTIVE_DATE)
251-
.fetchSize(1000);
251+
.fetchSize(DEFAULT_FETCH_SIZE);
252252

253253
logger.fine(() -> query.getSQL(ParamType.INLINED));
254254

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Set<RatingTemplate> retrieveRatingTemplates(String office, String templat
8787
.leftOuterJoin(specView)
8888
.on(specView.TEMPLATE_CODE.eq(tempView.TEMPLATE_CODE))
8989
.where(condition)
90-
.fetchSize(1000);
90+
.fetchSize(DEFAULT_FETCH_SIZE);
9191

9292
logger.fine(() -> query.getSQL(ParamType.INLINED));
9393

@@ -130,7 +130,7 @@ public Optional<RatingTemplate> retrieveRatingTemplate(String office, String tem
130130
.leftOuterJoin(specView).on(
131131
specView.TEMPLATE_CODE.eq(tempView.TEMPLATE_CODE))
132132
.where(condition)
133-
.fetchSize(1000);
133+
.fetchSize(DEFAULT_FETCH_SIZE);
134134

135135
logger.fine(() -> query.getSQL(ParamType.INLINED));
136136

0 commit comments

Comments
 (0)