private int handleSpecialFunctions ( ) { boolean needsSpecialAttention = false ; outer : for ( UpdateClause c : kunderaQuery . getUpdateClauseQueue ( ) ) { for ( int i = 0 ; i < FUNCTION_KEYWORDS . length ; i ++ ) { if ( c . getValue ( ) instanceof String ) { String func = c . getValue ( ) . toString ( ) ; func = func . replaceAll ( " " , "" ) ; if ( func . toUpperCase ( ) . matches ( FUNCTION_KEYWORDS [ i ] ) ) { needsSpecialAttention = true ; c . setValue ( func ) ; break outer ; } } } } if ( ! needsSpecialAttention ) return - 1 ; EntityMetadata m = getEntityMetadata ( ) ; Metamodel metaModel = kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; Queue filterClauseQueue = kunderaQuery . getFilterClauseQueue ( ) ; BasicDBObject query = createMongoQuery ( m , filterClauseQueue ) ; BasicDBObject update = new BasicDBObject ( ) ; for ( UpdateClause c : kunderaQuery . getUpdateClauseQueue ( ) ) { String columName = getColumnName ( m , metaModel . entity ( m . getEntityClazz ( ) ) , c . getProperty ( ) ) ; boolean isSpecialFunction = false ; for ( int i = 0 ; i < FUNCTION_KEYWORDS . length ; i ++ ) { if ( c . getValue ( ) instanceof String && c . getValue ( ) . toString ( ) . toUpperCase ( ) . matches ( FUNCTION_KEYWORDS [ i ] ) ) { isSpecialFunction = true ; if ( c . getValue ( ) . toString ( ) . toUpperCase ( ) . startsWith ( "INCREMENT(" ) ) { String val = c . getValue ( ) . toString ( ) . toUpperCase ( ) ; val = val . substring ( 10 , val . indexOf ( ")" ) ) ; update . put ( "$inc" , new BasicDBObject ( columName , Integer . valueOf ( val ) ) ) ; } else if ( c . getValue ( ) . toString ( ) . toUpperCase ( ) . startsWith ( "DECREMENT(" ) ) { String val = c . getValue ( ) . toString ( ) . toUpperCase ( ) ; val = val . substring ( 10 , val . indexOf ( ")" ) ) ; update . put ( "$inc" , new BasicDBObject ( columName , - Integer . valueOf ( val ) ) ) ; } } } if ( ! isSpecialFunction ) { update . put ( columName , c . getValue ( ) ) ; } } Client client = persistenceDelegeator . getClient ( m ) ; return ( ( MongoDBClient ) client ) . handleUpdateFunctions ( query , update , m . getTableName ( ) ) ; }
Handle special functions .