Selector car1Selector = factory.selector("car:Car", "car1");
Selector car2Selector = factory.selector("car:Car", "car2");
Join join = factory.join(car1Selector, car2Selector, QueryObjectModelConstants.JCR_JOIN_TYPE_INNER,
factory.equiJoinCondition("car1", "car:maker", "car2", "car:maker"));
Column[] columns = new Column[] {factory.column("car1", null, null)};
Constraint constraint = factory.comparison(factory.propertyValue("car1", "car:maker"),
QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
factory.literal(session.getValueFactory().createValue("Toyota")));
Ordering[] orderings = new Ordering[] {factory.descending(factory.propertyValue("car1", "car:year"))};
Query query = factory.createQuery(join, constraint, orderings, columns);
QueryResult result = query.execute();