private StringBuilder appendOrderByClause ( MetamodelImpl metaModel , EntityMetadata m , EmbeddableType keyObj , StringBuilder builder , CQLTranslator translator ) { List < SortOrdering > orders = getKunderaQuery ( ) . getOrdering ( ) ; if ( orders != null ) { builder . append ( CQLTranslator . SPACE_STRING ) ; builder . append ( CQLTranslator . SORT_CLAUSE ) ; for ( SortOrdering order : orders ) { String orderColumnName = order . getColumnName ( ) ; orderColumnName = orderColumnName . substring ( orderColumnName . indexOf ( "." ) + 1 , orderColumnName . length ( ) ) ; String orderByColumnName ; if ( StringUtils . contains ( orderColumnName , ' ' ) ) { String propertyName = orderColumnName . substring ( 0 , orderColumnName . indexOf ( "." ) ) ; Attribute embeddableAttribute = metaModel . getEntityAttribute ( m . getEntityClazz ( ) , propertyName ) ; EmbeddableType embeddableType = metaModel . embeddable ( ( ( AbstractAttribute ) embeddableAttribute ) . getBindableJavaType ( ) ) ; orderColumnName = orderColumnName . substring ( orderColumnName . indexOf ( "." ) + 1 ) ; AbstractAttribute attribute = ( AbstractAttribute ) embeddableType . getAttribute ( orderColumnName ) ; orderByColumnName = attribute . getJPAColumnName ( ) ; } else { Attribute attribute = metaModel . getEntityAttribute ( m . getEntityClazz ( ) , orderColumnName ) ; orderByColumnName = ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) ; } builder = translator . ensureCase ( builder , orderByColumnName , false ) ; builder . append ( CQLTranslator . SPACE_STRING ) ; builder . append ( order . getOrder ( ) ) ; builder . append ( CQLTranslator . COMMA_STR ) ; } if ( ! orders . isEmpty ( ) ) { builder . deleteCharAt ( builder . lastIndexOf ( CQLTranslator . COMMA_STR ) ) ; } } return builder ; }
Append order by clause .