2020-02-04
Data Nucleus Contains Function
I have been recently working with Data Nucleus and have found the contains()
function to have an interesting use. Consider this code that executes a Data Nucleus query;
Query<Consignment> query = pm.newQuery(Consignment.class);
query.setFilter("this.parts.contains(p) && p.code == inPartCode");
query.declareParameters("String inPartCode");
query.declareVariables("Part p");
query.setNamedParameters(Map.of("inPartCode", partCode);
query.executeResultList(Consignment.class);
In this case only a Consignment
that has a Part
with the supplied code will be returned. This is how the SQL query might look for this;
SELECT DISTINCT "A0"."CODE", "A0"."ID"
FROM "CONSIGNMENT" "A0"
INNER JOIN "PART" "B0" ON "A0"."ID" = "B0"."CONSIGNMENT_ID_OID"
WHERE "B0"."CODE" = 'P391233'