Skip to content

Commit

Permalink
update to use office id in the clob cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkorynta committed Nov 8, 2024
1 parent a9d602f commit d6f48b6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
17 changes: 10 additions & 7 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/ClobDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ public Optional<Clob> getByUniqueName(String uniqueName, String office) {
public Clobs getClobs(String cursor, int pageSize, String officeLike,
boolean includeValues, String idRegex) {
int total = 0;
String clobCursor = "*";
String cursorOffice = null;
String cursorClobId = null;
AV_CLOB v_clob = AV_CLOB.AV_CLOB;
AV_OFFICE v_office = AV_OFFICE.AV_OFFICE;

Condition whereClause = JooqDao.caseInsensitiveLikeRegex(v_clob.ID, idRegex)
.and(officeLike == null ? noCondition() : JooqDao.caseInsensitiveLikeRegex(v_office.OFFICE_ID, officeLike));
.and(JooqDao.caseInsensitiveLikeRegexNullTrue(v_office.OFFICE_ID, officeLike));
if (cursor == null || cursor.isEmpty()) {
SelectConditionStep<Record1<Integer>> count = dsl.select(count(asterisk()))
.from(v_clob)
Expand All @@ -92,9 +93,8 @@ public Clobs getClobs(String cursor, int pageSize, String officeLike,
}

if (parts.length > 1) {
clobCursor = parts[0].split(";")[0];
clobCursor = clobCursor.substring(clobCursor.indexOf("/") + 1); // ditch the
// officeId that's embedded in
cursorOffice = Clobs.getOffice(cursor);
cursorClobId = Clobs.getId(cursor);
total = Integer.parseInt(parts[1]);
pageSize = Integer.parseInt(parts[2]);
}
Expand All @@ -109,12 +109,15 @@ public Clobs getClobs(String cursor, int pageSize, String officeLike,
.from(v_clob)
.join(v_office).on(v_clob.OFFICE_CODE.eq(v_office.OFFICE_CODE))
.where(whereClause)
.and(DSL.upper(v_clob.ID).greaterThan(clobCursor))
.and(cursorClobId == null ? DSL.noCondition() :
DSL.upper(v_clob.ID).greaterThan(cursorClobId.toUpperCase()))
.and(cursorOffice == null ? DSL.noCondition() :
DSL.upper(v_office.OFFICE_ID).greaterThan(cursorOffice.toUpperCase()))
.orderBy(v_office.OFFICE_ID, v_clob.ID)
.limit(pageSize);


Clobs.Builder builder = new Clobs.Builder(clobCursor, pageSize, total);
Clobs.Builder builder = new Clobs.Builder(cursor, pageSize, total);

logger.atFine().log(query.getSQL(ParamType.INLINED));

Expand Down
46 changes: 40 additions & 6 deletions cwms-data-api/src/main/java/cwms/cda/data/dto/Clobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,53 @@ private void addClob(Clob clob) {
clobs.add(clob);
}

/**
* Extract the office from the cursor.
*
* @param cursor the cursor
* @return office
*/
public static String getOffice(String cursor) {
String[] parts = CwmsDTOPaginated.decodeCursor(cursor);
if (parts.length > 1) {
String[] idAndOffice = CwmsDTOPaginated.decodeCursor(parts[0]);
if (idAndOffice.length > 0) {
return idAndOffice[0];
}
}
return null;
}

/**
* Extract the id from the cursor.
*
* @param cursor the cursor
* @return id
*/
public static String getId(String cursor) {
String[] parts = CwmsDTOPaginated.decodeCursor(cursor);
if (parts.length > 1) {
String[] idAndOffice = CwmsDTOPaginated.decodeCursor(parts[0]);
if (idAndOffice.length > 1) {
return idAndOffice[1];
}
}
return null;
}

public static class Builder {
private Clobs workingClobs;
private final Clobs workingClobs;

public Builder(String cursor, int pageSize, int total) {
workingClobs = new Clobs(cursor, pageSize, total);
}

public Clobs build() {
if (this.workingClobs.clobs.size() == this.workingClobs.pageSize) {
this.workingClobs.nextPage = encodeCursor(
this.workingClobs.clobs.get(this.workingClobs.clobs.size() - 1).toString().toUpperCase(),
this.workingClobs.pageSize,
this.workingClobs.total);
if (this.workingClobs.clobs.size() == this.workingClobs.pageSize && !this.workingClobs.clobs.isEmpty()) {
Clob lastClob = this.workingClobs.clobs.get(this.workingClobs.clobs.size() - 1);
String cursor = encodeCursor(CwmsDTOPaginated.delimiter, lastClob.getOfficeId(),
lastClob.getId());
this.workingClobs.nextPage = encodeCursor(cursor, this.workingClobs.pageSize, this.workingClobs.total);
} else {
this.workingClobs.nextPage = null;
}
Expand Down

0 comments on commit d6f48b6

Please sign in to comment.