private static < L extends Annotation > String defineOrderByStatement ( final SQLiteModelMethod method , final JQL result , Class < L > annotation , Map < JQLDynamicStatementType , String > dynamicReplace ) { StringBuilder builder = new StringBuilder ( ) ; String orderBy = AnnotationUtility . extractAsString ( method . getElement ( ) , annotation , AnnotationAttributeType . ORDER_BY ) ; if ( StringUtils . hasText ( orderBy ) ) { result . annotatedOrderBy = true ; } final One < String > orderDynamicName = new One < String > ( null ) ; forEachParameter ( method , new OnMethodParameterListener ( ) { @ Override public void onMethodParameter ( VariableElement methodParam ) { if ( methodParam . getAnnotation ( BindSqlDynamicOrderBy . class ) != null ) { orderDynamicName . value0 = methodParam . getSimpleName ( ) . toString ( ) ; result . paramOrderBy = orderDynamicName . value0 ; // CONSTRAINT: @BindSqlOrderBy can be used only on String // parameter type AssertKripton . assertTrueOrInvalidTypeForAnnotationMethodParameterException ( TypeUtility . isEquals ( TypeUtility . typeName ( String . class ) , TypeUtility . typeName ( methodParam ) ) , method . getParent ( ) . getElement ( ) , method . getElement ( ) , methodParam , BindSqlDynamicOrderBy . class ) ; } } } ) ; if ( StringUtils . hasText ( orderBy ) || StringUtils . hasText ( orderDynamicName . value0 ) ) { builder . append ( " " + ORDER_BY_KEYWORD ) ; if ( StringUtils . hasText ( orderBy ) ) { result . staticOrderBy = true ; builder . append ( StringUtils . startWithSpace ( orderBy ) ) ; } StringBuilder dynamicBuffer = new StringBuilder ( ) ; if ( StringUtils . hasText ( orderDynamicName . value0 ) ) { if ( StringUtils . hasText ( orderBy ) ) { dynamicBuffer . append ( "," ) ; builder . append ( "," ) ; } dynamicBuffer . append ( " #{" + JQLDynamicStatementType . DYNAMIC_ORDER_BY + "}" ) ; builder . append ( " #{" + JQLDynamicStatementType . DYNAMIC_ORDER_BY + "}" ) ; // define replacement string for WHERE dynamicReplace . put ( JQLDynamicStatementType . DYNAMIC_ORDER_BY , dynamicBuffer . toString ( ) ) ; } } return builder . toString ( ) ; }
Define ORDER BY statement .