private String getSearchForKey(Role role, String retType) { boolean indexMult = role.isIndexed() && role.getIndexCardinality() == Role.MULTIPLICITY_MANY; String fetchMethod = "get" + (indexMult ? "Values" : ""); return "((" + getRelationAwareTypeFor(role) + ") get" + capitalize(role.getName()) + "Set())." + fetchMethod + "(key)"; }
@Override protected void generateRoleSlotMethodsMultStar(Role role, PrintWriter out) { super.generateRoleSlotMethodsMultStar(role, out); boolean isIndexed = role.isIndexed(); String typeName = getTypeFullName(role.getType()); String slotName = role.getName(); String capitalizedSlotName = capitalize(slotName); String slotAccessExpression = "get" + capitalizedSlotName + "()"; String methodModifiers = getMethodModifiers(role); if (isIndexed) { generateRoleSlotMethodsMultStarIndexed(role, out, methodModifiers, capitalizedSlotName, slotAccessExpression, typeName, slotName); } }
protected void generateRoleSlotMethodsMultStarIndexed(Role role, PrintWriter out, String methodModifiers, String capitalizedSlotName, String slotAccessExpression, String typeName, String slotName) { Slot indexedSlot = getIndexedSlot(role); String keyField = role.getIndexProperty(); String retType = role.getType().getFullName(); String methodNameSufix = ""; boolean haveMany = role.getIndexCardinality() == Role.MULTIPLICITY_MANY; if (haveMany) { retType = makeGenericType("java.util.Set", retType); } onNewline(out); printMethod(out, "public", retType, "get" + capitalize(role.getName()) + "By" + capitalize(keyField) + methodNameSufix, indexedSlot.getSlotType().getFullname() + " key"); startMethodBody(out); printWords(out, "return", getSearchForKey(role, haveMany ? getCollectionToUse() : retType)); print(out, ";"); endMethodBody(out); }