use of com.blazebit.persistence.parser.expression.StringLiteral in project blaze-persistence by Blazebit.
the class TestLiterals method testCharacterLiteralWithBackslash.
@Test
public void testCharacterLiteralWithBackslash() {
StringLiteral result = (StringLiteral) parse("'\\'");
assertEquals(new StringLiteral("\\"), result);
}
use of com.blazebit.persistence.parser.expression.StringLiteral in project blaze-persistence by Blazebit.
the class BaseFinalSetOperationBuilderImpl method asExpression.
public Expression asExpression(boolean externalRepresentation, boolean quantifiedPredicate) {
SetOperationManager operationManager = setOperationManager;
if (operationManager.getOperator() == null || !operationManager.hasSetOperations()) {
return asExpression(operationManager.getStartQueryBuilder(), externalRepresentation, quantifiedPredicate);
}
List<Expression> setOperationArgs = new ArrayList<Expression>(operationManager.getSetOperations().size() + 2);
// Use prefix because hibernate uses UNION as keyword
setOperationArgs.add(new StringLiteral("SET_" + operationManager.getOperator().name()));
setOperationArgs.add(asExpression(operationManager.getStartQueryBuilder(), externalRepresentation, quantifiedPredicate));
List<AbstractCommonQueryBuilder<?, ?, ?, ?, ?>> setOperands = operationManager.getSetOperations();
int operandsSize = setOperands.size();
for (int i = 0; i < operandsSize; i++) {
setOperationArgs.add(asExpression(setOperands.get(i), externalRepresentation, quantifiedPredicate));
}
List<? extends OrderByElement> orderByElements = getOrderByElements();
if (orderByElements.size() > 0) {
setOperationArgs.add(new StringLiteral("ORDER_BY"));
int orderByElementsSize = orderByElements.size();
for (int i = 0; i < orderByElementsSize; i++) {
setOperationArgs.add(new StringLiteral(orderByElements.get(i).toString()));
}
}
if (hasLimit()) {
if (maxResults != Integer.MAX_VALUE) {
setOperationArgs.add(new StringLiteral("LIMIT"));
setOperationArgs.add(new NumericLiteral(Integer.toString(maxResults), NumericType.INTEGER));
}
if (firstResult != 0) {
setOperationArgs.add(new StringLiteral("OFFSET"));
setOperationArgs.add(new NumericLiteral(Integer.toString(firstResult), NumericType.INTEGER));
}
}
Expression expression = new FunctionExpression("FUNCTION", setOperationArgs);
if (quantifiedPredicate && hasLimit() && !mainQuery.dbmsDialect.supportsLimitInQuantifiedPredicateSubquery()) {
List<Expression> arguments = new ArrayList<>(2);
arguments.add(new StringLiteral(QueryWrapperFunction.FUNCTION_NAME));
arguments.add(expression);
expression = new FunctionExpression("FUNCTION", arguments);
}
return expression;
}
use of com.blazebit.persistence.parser.expression.StringLiteral in project blaze-persistence by Blazebit.
the class SizeTransformationVisitor method wrapSubqueryConditionally.
private Expression wrapSubqueryConditionally(SubqueryExpression subquery, boolean wrap) {
if (wrap) {
// we need to wrap subqueries in aggregate functions in COALESCE to trick the Hibernate parser
// see https://hibernate.atlassian.net/browse/HHH-9331
List<Expression> subqueryFunctionArguments = new ArrayList<>(1);
subqueryFunctionArguments.add(new StringLiteral(SubqueryFunction.FUNCTION_NAME));
subqueryFunctionArguments.add(subquery);
return new FunctionExpression("FUNCTION", subqueryFunctionArguments);
} else {
return subquery;
}
}
use of com.blazebit.persistence.parser.expression.StringLiteral in project blaze-persistence by Blazebit.
the class ScalarTargetResolvingExpressionVisitor method visit.
@Override
public void visit(FunctionExpression expression) {
String name = expression.getFunctionName().toLowerCase();
switch(name) {
case "function":
String functionName = ((StringLiteral) expression.getExpressions().get(0)).getValue();
JpqlFunction jpqlFunction = functions.get(functionName.toLowerCase());
if (jpqlFunction == null) {
// Can't reliably resolve the type
currentPosition.setAttribute(null);
currentPosition.setCurrentType(null);
} else {
// Skip the function name
resolveFirst(expression.getExpressions().subList(1, expression.getExpressions().size()), true);
resolveToFunctionReturnType(functionName);
}
break;
case "size":
// According to our grammar, we can only get a path here
currentPosition.setAttribute(null);
currentPosition.setCurrentType(metamodel.type(Long.class));
break;
case "coalesce":
resolveAny(expression.getExpressions(), true);
resolveToFunctionReturnType(name);
break;
default:
resolveFirst(expression.getExpressions(), true);
resolveToFunctionReturnType(name);
break;
}
}
use of com.blazebit.persistence.parser.expression.StringLiteral in project blaze-persistence by Blazebit.
the class TestLiterals method testStringLiteral.
@Test
public void testStringLiteral() {
StringLiteral result = (StringLiteral) parse("'abcd'");
assertEquals(new StringLiteral("abcd"), result);
}
Aggregations