|
40 | 40 | import java.time.Instant; |
41 | 41 | import java.time.ZoneId; |
42 | 42 | import java.time.ZonedDateTime; |
43 | | -import java.time.temporal.ChronoUnit; |
44 | 43 | import java.util.ArrayList; |
45 | 44 | import java.util.Arrays; |
46 | 45 | import java.util.Calendar; |
|
66 | 65 | import org.jetbrains.annotations.NotNull; |
67 | 66 | import org.jooq.Condition; |
68 | 67 | import org.jooq.DSLContext; |
| 68 | +import org.jooq.Field; |
69 | 69 | import org.jooq.Record; |
| 70 | +import org.jooq.Record1; |
| 71 | +import org.jooq.Record2; |
70 | 72 | import org.jooq.ResultQuery; |
| 73 | +import org.jooq.SelectConditionStep; |
| 74 | +import org.jooq.SelectForUpdateStep; |
71 | 75 | import org.jooq.conf.ParamType; |
| 76 | +import org.jooq.impl.DSL; |
| 77 | +import static org.jooq.impl.DSL.field; |
72 | 78 | import usace.cwms.db.dao.util.OracleTypeMap; |
73 | 79 | import usace.cwms.db.jooq.codegen.packages.CWMS_RATING_PACKAGE; |
74 | 80 | import usace.cwms.db.jooq.codegen.tables.AV_RATING; |
@@ -422,13 +428,17 @@ public void create(String xml, boolean failIfExists) { |
422 | 428 |
|
423 | 429 | public RatingEffectiveDatesMap retrieveSpecEffectiveDates(String officeIdMask, String specIdMask, Instant begin, Instant end) { |
424 | 430 | return connectionResult(dsl, conn -> { |
| 431 | + Set<String> ratingIdsNoAliases = getRatingIds(conn, officeIdMask, "*", false); |
425 | 432 | //office->spec->dates |
426 | 433 | NavigableMap<String, NavigableMap<String, NavigableSet<Instant>>> specDateMap = new TreeMap<>(); |
427 | 434 | ResultSet rs = catRatings(conn, officeIdMask, specIdMask, begin, end); |
428 | 435 | OracleTypeMap.checkMetaData(rs.getMetaData(), RATINGS_COLUMN_LIST, "Ratings"); |
429 | 436 | while(rs.next()) { |
430 | 437 | String officeId = rs.getString(OFFICE_ID); |
431 | 438 | String specId = rs.getString(SPECIFICATION_ID); |
| 439 | + if(!ratingIdsNoAliases.contains(specId)) { // skip aliased specs |
| 440 | + continue; |
| 441 | + } |
432 | 442 | Timestamp timestamp = rs.getTimestamp(EFFECTIVE_DATE, GMT_CALENDAR); |
433 | 443 | Instant date = timestamp.toInstant(); |
434 | 444 | NavigableSet<Instant> dateList = specDateMap.computeIfAbsent(officeId, k -> new TreeMap<>()) |
@@ -490,4 +500,36 @@ private ResultSet catRatings(Connection conn, String officeIdMask, String specId |
490 | 500 |
|
491 | 501 | return output; |
492 | 502 | } |
| 503 | + |
| 504 | + private Set<String> getRatingIds(Connection conn, String office, String templateIdMask, boolean includeAliases) { |
| 505 | + AV_RATING_SPEC specView = AV_RATING_SPEC.AV_RATING_SPEC; |
| 506 | + Condition condition = DSL.noCondition(); |
| 507 | + |
| 508 | + if (office != null) { |
| 509 | + condition = condition.and(specView.OFFICE_ID.eq(office)); |
| 510 | + } |
| 511 | + |
| 512 | + if (templateIdMask != null) { |
| 513 | + Condition ratingIdLike = JooqDao.caseInsensitiveLikeRegex(specView.RATING_ID, |
| 514 | + templateIdMask); |
| 515 | + condition = condition.and(ratingIdLike); |
| 516 | + } |
| 517 | + |
| 518 | + if(!includeAliases) { |
| 519 | + condition = condition.and(specView.ALIASED_ITEM.isNull()); |
| 520 | + } |
| 521 | + |
| 522 | + Field<String> idField = field("RATING_ID", String.class); |
| 523 | + |
| 524 | + SelectConditionStep<Record2<String, String>> ratingStep = DSL.using(conn).select( |
| 525 | + specView.OFFICE_ID, |
| 526 | + specView.RATING_ID.as(idField)) |
| 527 | + .from(specView) |
| 528 | + .where(condition); |
| 529 | + |
| 530 | + SelectForUpdateStep<Record1<String>> query = DSL.using(conn).selectDistinct(idField) |
| 531 | + .from(ratingStep) |
| 532 | + .orderBy(idField.asc()); |
| 533 | + return new LinkedHashSet<>(query.fetch(idField)); |
| 534 | + } |
493 | 535 | } |
0 commit comments