/** * Gets the join predicate for a sub-query, or branch. * * <p>Sample query (1) below exemplifies query where join is not required. Sample query (2) below * exemplifies query where join is required. * * <p>1. SELECT ro.* FROM RegistryObject ro WHERE (ro.status == "<status>") * * <p>2. SELECT ro.* FROM RegistryObject ro, VersionInfo v WHERE ((v.parent = ro.id) AND * v.versionName = "1.2"); * * <p>ro = parentAlias v = alias status = filterColumn versionName = filterColumn parent = * foreignKeyColumn id = parent.primaryKeyColumn * * <p>This method provides the (v.parent = ro.id) portion. Filters are added elsewhere */ protected String getJoinPredicate() { String joinPredicate = ""; if ((parentQueryProcessor != null) && (foreignKeyColumn != null)) { String parentAlias = parentQueryProcessor.getAlias(); String parentPrimaryKeyColumn = parentQueryProcessor.getPrimaryKeyColumn(); String parentJoinPredicate = parentQueryProcessor.getJoinPredicate(); // Use full version of appendPredicate() to avoid recursion joinPredicate = appendPredicate( joinPredicate, parentJoinPredicate, alias + "." + foreignKeyColumn + " = " + parentAlias + "." + parentPrimaryKeyColumn); } return joinPredicate; }
/* * Gets the alias name for the table for this FilterQuery within the SELECT stmt. * Handles case where same table may be used more than once in a SELECT statment. * Forward to parentProcessor if any since only top level processor is emitting * SELECT statement that contains all aliases (no nested SELECTs). * */ protected String getAliasForTable(String tableName) { String alias = null; if (parentQueryProcessor != null) { alias = parentQueryProcessor.getAliasForTable(tableName); } else { alias = tableName.toLowerCase(); String originalAlias = alias; int i = 0; while (aliases.contains(alias)) { alias = originalAlias + i; i++; } addTableNameAndAlias(tableName, alias); } return alias; }