Skip to main content

Java Advanced Data Operations

This page combines the individual Java APIs into application-sized patterns. The examples use the generated School Management fixture; inspect Assist before substituting names from your model.

Search page with rows and two facets​

One Request can return the primary rows and named navigation sidecars:

SmartList<School> rows = Q.schools()
.withNameContaining("Primary")
.selectSchoolTypeWith(Q.schoolTypesWithMinimalFields().selectCode().selectName())
.selectPlatformWith(Q.platformsWithMinimalFields().selectName())
.facetBySchoolTypeAs(
"schoolTypes",
Q.schoolTypesWithMinimalFields()
.withCodeIn("PRIMARY", "SECONDARY")
.selectCode().selectName().countAs("schoolCount"),
true)
.facetByPlatformAs(
"platforms",
Q.platformsWithMinimalFields().selectName().countAs("schoolCount"),
false)
.orderByIdDescending()
.top(50)
.comment("Search schools with dashboard facets")
.purpose("Render the authorized operations dashboard")
.executeForList(context);

SmartList<SchoolType> typeBuckets = rows.getFacet("schoolTypes");
SmartList<Platform> platformBuckets = rows.getFacet("platforms");

The main rows and Facets share the outer filter. The SchoolType child predicate limits the allowed bucket domain; true keeps allowed zero-count values.

Deep graph and per-parent Top-N​

Build each level with a typed child Request. The child bound applies per parent:

SmartList<Platform> platforms = Q.platforms()
.selectName()
.selectSchoolListWith(
Q.schools()
.selectName()
.selectSchoolTypeWith(
Q.schoolTypesWithMinimalFields().selectCode().selectName())
.orderByStudentCapacityDescending()
.top(3))
.comment("Load each platform and its three largest schools")
.purpose("Render the authorized platform capacity review")
.executeForList(context);

Do not replace top(3) with an application-side slice. Verify the generated SQL uses the provider's partition/window plan when qualifying a database.

Grouped and relation analytics​

Use grouped analytics for distribution rows and relation analytics when each parent needs its own metric:

SmartList<School> distribution = Q.schools()
.groupBySchoolType()
.countAs("schoolCount")
.sumStudentCapacityAs("capacityTotal")
.avgStudentCapacityAs("capacityAverage")
.comment("Aggregate school capacity by type")
.purpose("Build the authorized capacity report")
.executeForList(context);

SmartList<SchoolType> cards = Q.schoolTypesWithMinimalFields()
.selectCode().selectName()
.countSchoolsAs("schoolCount")
.sumStudentCapacityOfSchoolsAs("capacityTotal")
.comment("Calculate type-level school metrics")
.purpose("Render the authorized type cards")
.executeForList(context);

Read grouped rows through distribution.getAggregationResults(). Relation aliases such as schoolCount are dynamic read-only values on each parent.

Audited read-modify-save​

School school = Q.schools()
.withIdIs(schoolId)
.selectPlatformWith(Q.platformsWithMinimalFields().selectName())
.selectSchoolTypeWith(Q.schoolTypesWithMinimalFields().selectCode())
.comment("Load the complete school for capacity approval")
.purpose("Apply an authorized capacity revision")
.executeForOne(context);

school.updateStudentCapacity(newCapacity);
school = school.auditAs("Approve revised student capacity").save(context);

Load every field required by Checker/Fix and retain the returned entity so the authoritative version is used by the next mutation.

Continue with Association Loading, Statistics, and Create, Update, Delete for the older focused Java guides.