HHH-6655 trim function on DB2 is broken

This commit is contained in:
brmeyer 2012-10-09 11:29:05 -04:00
parent 58fa4c2eac
commit 11dcd9ab46
3 changed files with 14 additions and 4 deletions

View File

@ -159,7 +159,7 @@ public class DB2Dialect extends Dialect {
registerFunction( "substring", new StandardSQLFunction( "substr", StandardBasicTypes.STRING ) );
registerFunction( "bit_length", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "length(?1)*8" ) );
registerFunction( "trim", new AnsiTrimEmulationFunction() );
registerFunction( "trim", new SQLFunctionTemplate( StandardBasicTypes.STRING, "trim(?1 ?2 ?3 ?4)" ) );
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "||", "" ) );

View File

@ -37,6 +37,7 @@ import org.hibernate.jpa.criteria.expression.LiteralExpression;
* Models the ANSI SQL <tt>TRIM</tt> function.
*
* @author Steve Ebersole
* @author Brett Meyer
*/
public class TrimFunction
extends BasicFunctionExpression<String>
@ -118,11 +119,22 @@ public class TrimFunction
@Override
public String render(RenderingContext renderingContext) {
String renderedTrimChar;
if ( trimCharacter.getClass().isAssignableFrom(
LiteralExpression.class ) ) {
// If the character is a literal, treat it as one. A few dialects
// do not support parameters as trim() arguments.
renderedTrimChar = ( ( LiteralExpression<Character> )
trimCharacter ).getLiteral().toString();
} else {
renderedTrimChar = ( (Renderable) trimCharacter ).render(
renderingContext );
}
return new StringBuilder()
.append( "trim(" )
.append( trimspec.name() )
.append( ' ' )
.append( ( (Renderable) trimCharacter ).render( renderingContext ) )
.append( renderedTrimChar )
.append( " from " )
.append( ( (Renderable) trimSource ).render( renderingContext ) )
.append( ')' )

View File

@ -92,8 +92,6 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
}
@Test
@RequiresDialect( DB2Dialect.class )
@FailureExpected( jiraKey = "HHH-6655" )
public void testTrim() {
final String expectedResult = "David R. Vincent";
EntityManager em = getOrCreateEntityManager();