protected String getRoleHandlerName(Role role, boolean otherClass) { StringBuilder buf = new StringBuilder(); if (otherClass) { buf.append(getTypeFullName(role.getOtherRole().getType())); buf.append("."); } buf.append("role$$"); buf.append(role.getName()); return buf.toString(); }
/** * Indicates whether the relation is direct on this role */ public boolean isDirect() { return this.isFirstRole() || this.getOtherRole().getName() == null; } }
protected String getNewRoleStarSlotExpressionWithBackingSet(Role role, String theSet) { StringBuilder buf = new StringBuilder(); // generate the relation aware collection String thisType = getTypeFullName(role.getOtherRole().getType()); buf.append("new "); buf.append(getRelationAwareTypeFor(role)); buf.append("("); buf.append(theSet); buf.append(", "); buf.append("("); buf.append(thisType); buf.append(")this, "); buf.append(getRelationMethodNameFor(role)); buf.append(", keyFunction$$"); buf.append(role.getName()); buf.append(")"); return buf.toString(); }
protected String getInitRoleSlotStarExpression(Role role, String initExpression, PrintWriter out) { StringBuilder buf = new StringBuilder(); // generate the relation aware collection String thisType = getTypeFullName(role.getOtherRole().getType()); buf.append("new "); buf.append(getRelationAwareTypeFor(role)); buf.append("(("); buf.append(thisType); buf.append(")this, "); buf.append(getRelationMethodNameFor(role)); buf.append(", " + initExpression); buf.append(", keyFunction$$"); buf.append(role.getName()); buf.append(")"); return buf.toString(); }
@Override protected String getNewRoleStarSlotExpression(Role role) { StringBuilder buf = new StringBuilder(); // generate the relation aware collection String thisType = getTypeFullName(role.getOtherRole().getType()); buf.append("new "); buf.append(getRelationAwareTypeFor(role)); buf.append("(("); buf.append(thisType); buf.append(")this, "); buf.append(getRelationMethodNameFor(role)); buf.append(", \""); buf.append(role.getName()); buf.append("\", allocateOnly)"); return buf.toString(); }
protected String getNewRoleStarSlotExpressionWithBackingSet(Role role, String theSet) { StringBuilder buf = new StringBuilder(); // generate the relation aware collection String thisType = getTypeFullName(role.getOtherRole().getType()); buf.append("new "); buf.append(getRelationAwareTypeFor(role)); buf.append("("); buf.append(theSet); buf.append(", "); buf.append("("); buf.append(thisType); buf.append(")this, "); buf.append(getRelationMethodNameFor(role)); buf.append(", keyFunction$$"); buf.append(role.getName()); buf.append(")"); return buf.toString(); }
private static ClassDescriptor getOtherRoleClassDescriptor(Role role) { String classname = role.getOtherRole().getType().getFullName(); return getDescriptorTable().get(classname); }
protected void ormAddRole(Role role) { Role otherRole = role.getOtherRole();
protected String getConcreteSetTypeDeclarationFor(Role role) { String elemType = getTypeFullName(role.getType()); String thisType = getTypeFullName(role.getOtherRole().getType()); return makeGenericType(getRelationAwareBaseTypeFor(role), thisType, elemType); }
protected String getRelationAwareTypeFor(Role role) { String elemType = getTypeFullName(role.getType()); String thisType = getTypeFullName(role.getOtherRole().getType()); return makeGenericType(getRelationAwareBaseTypeFor(role), thisType, elemType); }
protected String getRoleType(Role role) { return makeGenericType(getRoleBaseType(role), getTypeFullName(role.getOtherRole().getType()), getTypeFullName(role.getType())); }
if (role.getOtherRole().getMultiplicityUpper() == 1) { String fkField = "oid" + StringUtils.capitalize(role.getOtherRole().getName());
private static void generateManyToManyCollectionDescriptor(CollectionDescriptor collectionDescriptor, Role role) { String indirectionTableName = DbUtil.convertToDBStyle(role.getRelation().getName()); String fkToItemClass = DbUtil.getFkName(role.getType().getName()); String fkToThisClass = DbUtil.getFkName(role.getOtherRole().getType().getName()); if (fkToItemClass.equals(fkToThisClass)) { fkToItemClass = fkToItemClass + "_" + DbUtil.convertToDBStyle(role.getName()); fkToThisClass = fkToThisClass + "_" + DbUtil.convertToDBStyle(role.getOtherRole().getName()); } collectionDescriptor.setIndirectionTable(indirectionTableName); collectionDescriptor.addFkToItemClass(fkToItemClass); collectionDescriptor.addFkToThisClass(fkToThisClass); collectionDescriptor.setCascadingDelete(ObjectReferenceDescriptor.CASCADE_NONE); }
protected void generateRelationAddMethodCall(Role role, String otherArg, String indexParam, PrintWriter out) { print(out, getRelationMethodNameFor(role, true)); print(out, ".add("); if (role.isDirect()) { print(out, "("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this, "); print(out, otherArg); } else { print(out, otherArg); print(out, ", ("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this"); } print(out, ");"); }
protected void generateRelationRemoveMethodCall(Role role, String otherArg, PrintWriter out) { print(out, getRelationMethodNameFor(role, true)); print(out, ".remove("); if (role.isDirect()) { print(out, "("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this, "); print(out, otherArg); } else { print(out, otherArg); print(out, ", ("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this"); } print(out, ");"); }
protected void generateStaticRoleSlots(Role role, PrintWriter out) { onNewline(out); Role otherRole = role.getOtherRole(); // The Role slot String roleType = getRoleType(role); printWords(out, "public", "final", "static", roleType, getRoleHandlerName(role, false), "=", "new", roleType); print(out, "("); print(out, getRoleArgs(role)); print(out, ")"); newBlock(out); boolean multOne = (role.getMultiplicityUpper() == 1); if (multOne) { generateStaticRoleSlotsMultOne(role, otherRole, out); } else { generateStaticRoleSlotsMultStar(role, otherRole, out); } generateRoleMethodGetInverseRole(role, otherRole, out); closeBlock(out, false); println(out, ";"); }
protected void generateRelationGetterBody(Role role, PrintWriter out) { print(out, "return "); print(out, "new "); print(out, getRelationAwareTypeFor(role)); print(out, "(("); print(out, getTypeFullName(role.getOtherRole().getType())); print(out, ")this, "); print(out, getRelationMethodNameFor(role)); print(out, ", "); print(out, role.getName()); print(out, ", "); print(out, "keyFunction$$"); print(out, role.getName()); print(out, ");"); }
@Override protected void generateRoleSlotMethodsMultStarGetter(String methodName, Role role, PrintWriter out) { newline(out); printFinalMethod(out, "public", getSetTypeDeclarationFor(role), methodName); startMethodBody(out); generateGetterDAPStatement(dC, role.getName(), role.getType().getFullName(), out);//DAP read stats update statement print(out, "return new "); print(out, getRelationAwareTypeFor(role)); print(out, "(("); print(out, getTypeFullName(role.getOtherRole().getType())); print(out, ") this, "); print(out, getRelationMethodNameFor(role)); print(out, ", this."); print(out, role.getName()); print(out, ", keyFunction$$"); print(out, role.getName()); print(out, ");"); endMethodBody(out); }
@Override protected void generateRelationGetter(String getterName, String valueToReturn, Role role, String typeName, PrintWriter out) { newline(out); printFinalMethod(out, "public", typeName, getterName); startMethodBody(out); generateGetterDAPStatement(dC, role.getName(), role.getType().getFullName(), out); String collectionType = getDefaultCollectionFor(role); println(out, collectionType + " internalSet = OgmBackEnd.getInstance().getDomainObject(" + makeForeignKeyName(role.getName()) + ");"); print(out, "return new "); print(out, getRelationAwareTypeFor(role)); print(out, "(("); print(out, getTypeFullName(role.getOtherRole().getType())); print(out, ") this, "); print(out, getRelationMethodNameFor(role)); print(out, ", internalSet, keyFunction$$"); print(out, role.getName()); print(out, ");"); endMethodBody(out); }
protected void generateRoleSlotMethodsMultStarGetter(Role role, PrintWriter out) { newline(out); printFinalMethod(out, "public", getSetTypeDeclarationFor(role), "get" + capitalize(role.getName()) + "Set"); startMethodBody(out); generateGetterDAPStatement(dC, role.getName(), role.getType().getFullName(), out);//DAP read stats update statement String collectionType = getDefaultCollectionFor(role); println(out, collectionType + " internalSet;"); println(out, "Object oid = InfinispanBackEnd.getInstance().cacheGet(getOid().getFullId() + \":" + role.getName() + "\");"); print(out, "if (oid == null || oid instanceof Externalization.NullClass)"); newBlock(out); println(out, "internalSet = new " + collectionType + "();"); print(out, "InfinispanBackEnd.getInstance().cachePut(getOid().getFullId() + \":" + role.getName() + "\", internalSet.getOid());"); closeBlock(out, false); print(out, " else"); newBlock(out); print(out, "internalSet = (" + collectionType + ")InfinispanBackEnd.getInstance().fromOid(oid);"); // print(out, "// no need to test for null. The entry must exist for sure."); closeBlock(out); print(out, "return new "); print(out, getRelationAwareTypeFor(role)); print(out, "(("); print(out, getTypeFullName(role.getOtherRole().getType())); print(out, ") this, "); print(out, getRelationMethodNameFor(role)); print(out, ", internalSet, keyFunction$$"); print(out, role.getName()); print(out, ");"); endMethodBody(out); }