public static String joinToString ( CriteriaJoin criteriaJoin ) { StringBuilder builder = new StringBuilder ( "LEFT OUTER JOIN " ) . append ( criteriaJoin . getEntityClass ( ) . getName ( ) ) . append ( " " ) . append ( criteriaJoin . getAlias ( ) ) . append ( " " ) . append ( " ON " ) ; if ( criteriaJoin . getJoinRelations ( ) . size ( ) == 0 ) { throw new RuntimeException ( "Not found any Join Relations in " + criteriaJoin . getAlias ( ) + " Join Criteria ! " ) ; } StringJoiner joiner = new StringJoiner ( " AND " ) ; List < JoinRelation > relationList = criteriaJoin . getJoinRelations ( ) ; for ( JoinRelation joinRelation : relationList ) { StringBuilder relationBuilder = new StringBuilder ( "\n" ) . append ( joinRelation . getRelationCriteria ( ) . getAlias ( ) ) . append ( "." ) . append ( joinRelation . getRelationField ( ) ) . append ( "=" ) . append ( joinRelation . getJoinedCriteria ( ) . getAlias ( ) ) . append ( "." ) . append ( joinRelation . getJoinedField ( ) ) ; joiner . add ( relationBuilder . toString ( ) ) ; } if ( joiner . length ( ) > 0 ) { builder . append ( joiner . toString ( ) ) ; } return builder . toString ( ) ; }
Generates Join Query for the given JoinCriteria