|
|
|
@ -58,19 +58,35 @@ public class LiteralExpression<T> extends ExpressionImpl<T> implements Serializa
|
|
|
|
|
return ':' + parameterName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings({ "unchecked" }) |
|
|
|
|
public String renderProjection(RenderingContext renderingContext) { |
|
|
|
|
// some drivers/servers do not like parameters in the select clause
|
|
|
|
|
final ValueHandlerFactory.ValueHandler handler = |
|
|
|
|
ValueHandlerFactory.determineAppropriateHandler( literal.getClass() ); |
|
|
|
|
if ( ValueHandlerFactory.isCharacter( literal ) ) { |
|
|
|
|
return '\'' + handler.render( literal ) + '\''; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return handler.render( literal ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Inline String literal. |
|
|
|
|
* |
|
|
|
|
* @return escaped String |
|
|
|
|
*/ |
|
|
|
|
private String inlineLiteral(String literal) { |
|
|
|
|
return String.format("\'%s\'", escapeLiteral(literal)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Escape String literal. |
|
|
|
|
* |
|
|
|
|
* @return escaped String |
|
|
|
|
*/ |
|
|
|
|
private String escapeLiteral(String literal) { |
|
|
|
|
return literal.replace("'", "''"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
|
public String renderProjection(RenderingContext renderingContext) { |
|
|
|
|
if (ValueHandlerFactory.isCharacter(literal)) { |
|
|
|
|
// In case literal is a Character, pass literal.toString() as the argument.
|
|
|
|
|
return inlineLiteral(literal.toString()); |
|
|
|
|
} |
|
|
|
|
// some drivers/servers do not like parameters in the select clause
|
|
|
|
|
final ValueHandlerFactory.ValueHandler handler = |
|
|
|
|
ValueHandlerFactory.determineAppropriateHandler(literal.getClass()); |
|
|
|
|
return handler.render(literal); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
@SuppressWarnings({ "unchecked" }) |
|
|
|
|
protected void resetJavaType(Class targetType) { |
|
|
|
|