### Question:
RelationalPathExtractor implements Visitor<Set<RelationalPath<?>>, Set<RelationalPath<?>>> { public static Set<RelationalPath<?>> extract(QueryMetadata md) { Set<RelationalPath<?>> known = ImmutableSet.of(); known = DEFAULT.visitJoins(md.getJoins(), known); if (md.getProjection() != null) { known = md.getProjection().accept(DEFAULT, known); } for (OrderSpecifier<?> o : md.getOrderBy()) { known = o.getTarget().accept(DEFAULT, known); } for (Expression<?> g : md.getGroupBy()) { known = g.accept(DEFAULT, known); } if (md.getHaving() != null) { known = md.getHaving().accept(DEFAULT, known); } if (md.getWhere() != null) { known = md.getWhere().accept(DEFAULT, known); } return known; } private  RelationalPathExtractor(); static Set<RelationalPath<?>> extract(QueryMetadata md); static Set<RelationalPath<?>> extract(Expression<?> expr); @Override Set<RelationalPath<?>> visit(Constant<?> expr, Set<RelationalPath<?>> known); @Override Set<RelationalPath<?>> visit(FactoryExpression<?> expr, Set<RelationalPath<?>> known); @Override Set<RelationalPath<?>> visit(Operation<?> expr, Set<RelationalPath<?>> known); @Override Set<RelationalPath<?>> visit(ParamExpression<?> expr, Set<RelationalPath<?>> known); @Override Set<RelationalPath<?>> visit(Path<?> expr, Set<RelationalPath<?>> known); @Override Set<RelationalPath<?>> visit(SubQueryExpression<?> expr, Set<RelationalPath<?>> known); @Override Set<RelationalPath<?>> visit(TemplateExpression<?> expr, Set<RelationalPath<?>> known); static final RelationalPathExtractor DEFAULT; }### Answer:
@Test public void simpleQuery() { QEmployee employee2 = new QEmployee("employee2"); SQLQuery<?> query = query().from(employee, employee2); assertEquals(ImmutableSet.of(employee, employee2), extract(query.getMetadata())); }
@Test public void joins() { QEmployee employee2 = new QEmployee("employee2"); SQLQuery<?> query = query().from(employee) .innerJoin(employee2).on(employee.superiorId.eq(employee2.id)); assertEquals(ImmutableSet.of(employee, employee2), extract(query.getMetadata())); }
@Test public void subQuery() { SQLQuery<?> query = query().from(employee) .where(employee.id.eq(query().from(employee).select(employee.id.max()))); assertEquals(ImmutableSet.of(employee), extract(query.getMetadata())); }
@Test public void subQuery2() { QEmployee employee2 = new QEmployee("employee2"); SQLQuery<?> query = query().from(employee) .where(Expressions.list(employee.id, employee.lastname) .in(query().from(employee2).select(employee2.id, employee2.lastname))); assertEquals(ImmutableSet.of(employee, employee2), extract(query.getMetadata())); }