/** * Note: this implementation does not yet take into account the mapping * of joined subclasses like Job->UpdateJob. */ public String getSQLJoin(String fromType, String fromAlias, String toType, String toAlias) { String fromPath = "UNKNOWN"; String toPath = "UNKNOWN"; final Relationship fromRel = _getRelationship(fromType, toType); final Relationship toRel = _getRelationship(toType, fromType); if (fromRel != null && !fromRel.collection) { fromPath = fromRel.relationshipName; toPath = "id"; } else if (toRel != null && !toRel.collection) { toPath = toRel.relationshipName; fromPath = "id"; } else { StringBuilder sb = new StringBuilder(); sb.append("fromType="); sb.append(fromType); sb.append(";toType="); sb.append(toType); throw new InternalException("Unhandled SQL Join! -- " + sb); } return String.format("%s.%s = %s.%s", fromAlias, fromPath, toAlias, toPath); }
/** * Walks the data on what locks what * for "from" argument to see if there is any direct relationship to the * "to" argument. If there is, the name will be returned. Otherwise, null. */ public String getRelationship(String from, String to) { Relationship r = _getRelationship(from, to); if (r != null) { return r.relationshipName; } return null; }