1 16 package org.outerj.daisy.query.model.functions; 17 18 import org.outerj.daisy.query.model.SqlGenerationContext; 19 import org.outerj.daisy.repository.query.QueryException; 20 21 public class RightFunction extends LeftFunction { 22 public static final String NAME = "Right"; 23 24 public String getFunctionName() { 25 return NAME; 26 } 27 28 protected String getFunctionName(SqlGenerationContext context) { 29 return context.getJdbcHelper().getStringRightFunction(); 30 } 31 32 protected Object evaluate(String value, int length) throws QueryException { 33 if (value == null) 34 return null; 35 else if (length < 0) 36 throw new QueryException("Length parameter of " + NAME + " function cannot be negative."); 37 else if (length > value.length()) 38 return value; 39 else 40 return value.substring(value.length() - length, value.length()); 41 } 42 } 43 | Popular Tags |