Skip to content

Commit

Permalink
add joins to entity types (range variables), RIGHT JOIN, and FULL JOIN
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Aug 15, 2023
1 parent 5604d11 commit efbb339
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 85 deletions.
37 changes: 36 additions & 1 deletion api/src/main/java/jakarta/persistence/criteria/From.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package jakarta.persistence.criteria;

import jakarta.persistence.metamodel.EntityType;
import jakarta.persistence.metamodel.SingularAttribute;
import jakarta.persistence.metamodel.CollectionAttribute;
import jakarta.persistence.metamodel.ListAttribute;
Expand Down Expand Up @@ -68,6 +69,40 @@ public interface From<Z, X> extends Path<X>, FetchParent<Z, X> {
*/
From<Z, X> getCorrelationParent();

/**
* Create and add an inner join to the given entity.
* @param entityClass the target entity class
* @return the resulting join
* @since 3.2
*/
<Y> Join<X, Y> join(Class<Y> entityClass);

/**
* Create and add a join to the given entity.
* @param entityClass the target entity class
* @param joinType join type
* @return the resulting join
* @since 3.2
*/
<Y> Join<X, Y> join(Class<Y> entityClass, JoinType joinType);

/**
* Create and add an inner join to the given entity.
* @param entity metamodel entity representing the join target
* @return the resulting join
* @since 3.2
*/
<Y> Join<X, Y> join(EntityType<Y> entity);

/**
* Create and add a join to the given entity.
* @param entity metamodel entity representing the join target
* @param joinType join type
* @return the resulting join
* @since 3.2
*/
<Y> Join<X, Y> join(EntityType<Y> entity, JoinType joinType);

/**
* Create an inner join to the specified single-valued
* attribute.
Expand Down Expand Up @@ -150,7 +185,7 @@ public interface From<Z, X> extends Path<X>, FetchParent<Z, X> {
*/
<K, V> MapJoin<X, K, V> join(MapAttribute<? super X, K, V> map, JoinType jt);


//String-based:

/**
Expand Down
6 changes: 4 additions & 2 deletions api/src/main/java/jakarta/persistence/criteria/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public interface Join<Z, X> extends From<Z, X> {
Predicate getOn();

/**
* Return the metamodel attribute corresponding to the join.
* @return metamodel attribute corresponding to the join
* Return the metamodel attribute representing the join
* target, if any, or null if the target of the join is an
* entity type.
* @return metamodel attribute or null
*/
Attribute<? super Z, ?> getAttribute();

Expand Down
29 changes: 21 additions & 8 deletions api/src/main/java/jakarta/persistence/criteria/JoinType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,35 @@
package jakarta.persistence.criteria;

/**
* Defines the three types of joins.
* Defines the four varieties of join.
*
* Right outer joins and right outer fetch joins are not required
* to be supported. Applications that use <code>RIGHT</code> join
* types will not be portable.
* <p>Support for {@link #RIGHT} or {@link #FULL} joins is only
* required when these join types are natively supported by the
* database. Applications that depend on these join types are not
* portable between all SQL databases.
*
* @since 2.0
*/
public enum JoinType {

/** Inner join. */
/**
* Inner join.
*/
INNER,

/** Left outer join. */
/**
* Left outer join.
*/
LEFT,

/** Right outer join. */
RIGHT
/**
* Right outer join.
*/
RIGHT,

/**
* Full outer join.
* @since 3.2
*/
FULL
}
Loading

0 comments on commit efbb339

Please sign in to comment.