private Path < ? > shorten ( Path < ? > path , boolean outer ) { if ( aliases . containsKey ( path ) ) { return aliases . get ( path ) ; } else if ( path . getMetadata ( ) . isRoot ( ) ) { return path ; } else if ( path . getMetadata ( ) . getParent ( ) . getMetadata ( ) . isRoot ( ) && outer ) { return path ; } else { Class < ? > type = JPAQueryMixin . getElementTypeOrType ( path ) ; Path < ? > parent = shorten ( path . getMetadata ( ) . getParent ( ) , false ) ; Path oldPath = ExpressionUtils . path ( path . getType ( ) , new PathMetadata ( parent , path . getMetadata ( ) . getElement ( ) , path . getMetadata ( ) . getPathType ( ) ) ) ; if ( oldPath . getMetadata ( ) . getParent ( ) . getMetadata ( ) . isRoot ( ) && outer ) { return oldPath ; } else { Path newPath = ExpressionUtils . path ( type , ExpressionUtils . createRootVariable ( oldPath ) ) ; aliases . put ( path , newPath ) ; metadata . addJoin ( JoinType . LEFTJOIN , ExpressionUtils . as ( oldPath , newPath ) ) ; return newPath ; } } }
Shorten the parent path to a length of max 2 elements