Skip to content

Commit 25af405

Browse files
committed
Bug fixes for new table joins. Still failing alias test case.
1 parent d20d065 commit 25af405

1 file changed

Lines changed: 14 additions & 34 deletions

File tree

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

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@
8787
import org.jooq.DSLContext;
8888
import org.jooq.Field;
8989
import org.jooq.Record;
90-
import org.jooq.Record1;
9190
import org.jooq.Result;
92-
import org.jooq.Select;
9391
import org.jooq.SelectLimitPercentAfterOffsetStep;
9492
import org.jooq.Table;
9593
import org.jooq.conf.ParamType;
@@ -174,32 +172,28 @@ public LocationLevels getLocationLevels(String cursor, int pageSize,
174172
}
175173
}
176174

177-
usace.cwms.db.jooq.codegen.tables.AV_LOC_ALIAS aliasView = AV_LOC_ALIAS;
178-
AV_LOCATION_LEVEL_REF ref = AV_LOCATION_LEVEL_REF.AV_LOCATION_LEVEL_REF;
179-
AV_LOCATION_LEVEL_VALUES values = AV_LOCATION_LEVEL_VALUES.AV_LOCATION_LEVEL_VALUES;
180-
181-
Condition whereCondition;
182-
Condition standardWhereCondition = ref.LOCATION_LEVEL_ID.isNotNull();
183175
LocationFieldMapping mapping;
184176
if (includeAliases) {
185177
mapping = new AliasedLocationFieldMapping();
186178
} else {
187179
mapping = new JooqLocationFieldMapping();
188180
}
189181

190-
whereCondition = (mapping.getUnitSystem().eq(unit.toUpperCase()))
191-
.or(mapping.getLocationLevelId(TABLE_ALIAS1, ref).isNotNull());
182+
usace.cwms.db.jooq.codegen.tables.AV_LOC_ALIAS aliasView = AV_LOC_ALIAS;
183+
AV_LOCATION_LEVEL_REF ref = AV_LOCATION_LEVEL_REF.AV_LOCATION_LEVEL_REF;
184+
AV_LOCATION_LEVEL_VALUES values = AV_LOCATION_LEVEL_VALUES.AV_LOCATION_LEVEL_VALUES;
185+
186+
Condition whereCondition = mapping.getLocationLevelId(TABLE_ALIAS1, ref).isNotNull();
187+
Condition standardWhereCondition = ref.LOCATION_LEVEL_ID.isNotNull();
192188

193189
if (office != null && !office.isEmpty()) {
194-
whereCondition = whereCondition.and(mapping.getOfficeId(TABLE_ALIAS1, ref).eq(office.toUpperCase())
195-
.or(DSL.upper(ref.OFFICE_ID).eq(office.toUpperCase())));
190+
whereCondition = whereCondition.and(mapping.getOfficeId(TABLE_ALIAS1, ref).eq(office.toUpperCase()));
196191
standardWhereCondition = standardWhereCondition.and(DSL.upper(ref.OFFICE_ID).eq(office.toUpperCase()));
197192
}
198193

199194
if (levelIdMask != null && !levelIdMask.isEmpty()) {
200195
whereCondition = whereCondition.and(
201-
JooqDao.caseInsensitiveLikeRegex(mapping.getLocationLevelId(TABLE_ALIAS1, ref), levelIdMask)
202-
.or(JooqDao.caseInsensitiveLikeRegex(ref.LOCATION_LEVEL_ID, levelIdMask)));
196+
JooqDao.caseInsensitiveLikeRegex(mapping.getLocationLevelId(TABLE_ALIAS1, ref), levelIdMask));
203197
standardWhereCondition = standardWhereCondition.and(
204198
JooqDao.caseInsensitiveLikeRegex(ref.LOCATION_LEVEL_ID, levelIdMask));
205199
}
@@ -229,20 +223,18 @@ public LocationLevels getLocationLevels(String cursor, int pageSize,
229223
.and(ref.LOCATION_ID.eq(aliasView.LOCATION_ID))
230224
.and(ref.LOCATION_CODE.eq(aliasView.LOCATION_CODE.cast(Long.class))).asTable(TABLE_ALIAS1))
231225
.fullOuterJoin(values)
232-
.on(mapping.getLocationLevelCode().eq((Select<? extends Record1<Long>>) values.LOCATION_LEVEL_CODE)
233-
.and(mapping.getLocationLevelId(TABLE_ALIAS1, null).eq(ref.LOCATION_LEVEL_ID)))
226+
.on(mapping.getLocationLevelCode().eq(values.LOCATION_LEVEL_CODE.cast(Long.class)))
234227
.where(whereCondition).asTable(TABLE_ALIAS2))
235228
.orderBy(mapping.getOfficeId(null, null), mapping.getLocationLevelId(null, null),
236-
field("LEVEL_DATE"), field("CALENDAR_OFFSET"), field("TIME_OFFSET"),
237-
mapping.getLocationLevelId(TABLE_ALIAS2, null), field("EFFECTIVE_DATE_UTC")
229+
field("LOCATION_LEVEL_DATE"), field("CALENDAR_OFFSET"), field("TIME_OFFSET")
238230
)
239231
.offset(offset)
240232
.limit(pageSize);
241233
} else {
242234
query = dsl.selectDistinct(LOCATION_LEVEL_FIELDS)
243235
.from(ref)
244236
.fullOuterJoin(values)
245-
.on(ref.LOCATION_LEVEL_CODE.eq((Select<? extends Record1<Long>>) values.LOCATION_LEVEL_CODE))
237+
.on(ref.LOCATION_LEVEL_CODE.eq(values.LOCATION_LEVEL_CODE.cast(Long.class)))
246238
.where(whereCondition)
247239
.orderBy(DSL.upper(ref.OFFICE_ID), DSL.upper(ref.LOCATION_LEVEL_ID),
248240
ref.LOCATION_LEVEL_DATE, values.CALENDAR_OFFSET, values.TIME_OFFSET
@@ -256,7 +248,7 @@ public LocationLevels getLocationLevels(String cursor, int pageSize,
256248
values.CALENDAR_OFFSET, values.TIME_OFFSET)
257249
.from(ref)
258250
.fullOuterJoin(values)
259-
.on(ref.LOCATION_LEVEL_CODE.eq((Select<? extends Record1<Long>>) values.LOCATION_LEVEL_CODE))
251+
.on(ref.LOCATION_LEVEL_CODE.eq(values.LOCATION_LEVEL_CODE.cast(Long.class)))
260252
.where(standardWhereCondition)
261253
);
262254
}
@@ -796,7 +788,7 @@ private void parseLevels(Record r, Map<LevelLookup, LocationLevel.Builder> build
796788
seasonalBuilder.withLevelComment(levelComment);
797789
seasonalBuilder = withLocationLevelRef(seasonalBuilder, locationLevelRef);
798790
JDomSeasonalIntervalImpl offset = new JDomSeasonalIntervalImpl();
799-
offset.setYearMonthString(calendarInterval.toString());
791+
offset.setYearMonthString(calendarInterval != null ? calendarInterval.toString() : null);
800792
seasonalBuilder.withIntervalMonths(offset.getTotalMonths());
801793
seasonalBuilder.withIntervalOrigin(intervalOrigin, levelZdt);
802794
seasonalBuilder.withAliases(aliases);
@@ -1001,8 +993,6 @@ private interface LocationFieldMapping {
1001993
Field<String> getLocationLevelId(String prefix, Table<?> table);
1002994

1003995
Field<Long> getLocationLevelCode();
1004-
1005-
Field<String> getUnitSystem();
1006996
}
1007997

1008998
private static final class JooqLocationFieldMapping implements LocationFieldMapping {
@@ -1020,11 +1010,6 @@ public Field<String> getLocationLevelId(String prefix, Table<?> table) {
10201010
public Field<Long> getLocationLevelCode() {
10211011
return null;
10221012
}
1023-
1024-
@Override
1025-
public Field<String> getUnitSystem() {
1026-
return null;
1027-
}
10281013
}
10291014

10301015
private static final class AliasedLocationFieldMapping implements LocationFieldMapping {
@@ -1044,11 +1029,6 @@ public Field<String> getLocationLevelId(String prefix, Table<?> table) {
10441029
public Field<Long> getLocationLevelCode() {
10451030
return field(String.format("%s.%s", TABLE_ALIAS1, "LOCATION_LEVEL_CODE"), Long.class);
10461031
}
1047-
1048-
@Override
1049-
public Field<String> getUnitSystem() {
1050-
return field(String.format("%s.%s", TABLE_ALIAS1, "UNIT_SYSTEM"), String.class);
1051-
}
10521032
}
10531033

10541034
private interface LocationParserFieldMapping {
@@ -1444,7 +1424,7 @@ private static void buildAliasedLocationLevelSelectFields() {
14441424
LOCATION_ALIAS_FIELDS.add(field(values.ATTRIBUTE_VALUE_EN.getUnqualifiedName()));
14451425
LOCATION_ALIAS_FIELDS.add(field(values.ATTRIBUTE_UNIT_SI.getUnqualifiedName()));
14461426
LOCATION_ALIAS_FIELDS.add(field(values.ATTRIBUTE_VALUE_SI.getUnqualifiedName()));
1447-
LOCATION_ALIAS_FIELDS.add(field(values.EXPIRATION_DATE.getUnqualifiedName()));
1427+
LOCATION_ALIAS_FIELDS.add(field(DSL.name(TABLE_ALIAS1, "EXPIRATION_DATE")));
14481428
LOCATION_ALIAS_FIELDS.add(field(values.TSID.getUnqualifiedName()));
14491429
LOCATION_ALIAS_FIELDS.add(field(values.CONSTANT_LEVEL_EN.getUnqualifiedName()));
14501430
LOCATION_ALIAS_FIELDS.add(field(values.CONSTANT_LEVEL_SI.getUnqualifiedName()));

0 commit comments

Comments
 (0)