use of org.eclipse.persistence.internal.expressions.LiteralExpression in project eclipselink by eclipse-ee4j.
the class DerbyPlatform method derbyExtractOperator.
/**
* INTERNAL:
* Derby does not support EXTRACT, but does have YEAR, MONTH, DAY, etc.
*/
public static ExpressionOperator derbyExtractOperator() {
ExpressionOperator exOperator = new ExpressionOperator() {
// QUARTER emulation: ((MONTH(:first)+2)/3)
private final String[] QUARTER_STRINGS = new String[] { "((MONTH(", ")+2)/3)" };
private void printQuarterSQL(final Expression first, final ExpressionSQLPrinter printer) {
printer.printString(QUARTER_STRINGS[0]);
first.printSQL(printer);
printer.printString(QUARTER_STRINGS[1]);
}
private void printQuarterJava(final Expression first, final ExpressionJavaPrinter printer) {
printer.printString(QUARTER_STRINGS[0]);
first.printJava(printer);
printer.printString(QUARTER_STRINGS[1]);
}
@Override
public void printDuo(Expression first, Expression second, ExpressionSQLPrinter printer) {
if (second instanceof LiteralExpression && "QUARTER".equals(((LiteralExpression) second).getValue().toUpperCase())) {
printQuarterSQL(first, printer);
} else {
super.printDuo(first, second, printer);
}
}
@Override
public void printCollection(List items, ExpressionSQLPrinter printer) {
if (items.size() == 2) {
Expression first = (Expression) items.get(0);
Expression second = (Expression) items.get(1);
if (second instanceof LiteralExpression && "QUARTER".equals(((LiteralExpression) second).getValue().toUpperCase())) {
printQuarterSQL(first, printer);
return;
}
}
super.printCollection(items, printer);
}
@Override
public void printJavaDuo(Expression first, Expression second, ExpressionJavaPrinter printer) {
if (second instanceof LiteralExpression && "QUARTER".equals(((LiteralExpression) second).getValue().toUpperCase())) {
printQuarterJava(first, printer);
} else {
super.printJavaDuo(first, second, printer);
}
}
@Override
public void printJavaCollection(List items, ExpressionJavaPrinter printer) {
if (items.size() == 2) {
Expression first = (Expression) items.get(0);
Expression second = (Expression) items.get(1);
if (second instanceof LiteralExpression && "QUARTER".equals(((LiteralExpression) second).getValue().toUpperCase())) {
printQuarterJava(first, printer);
return;
}
}
super.printJavaCollection(items, printer);
}
};
exOperator.setType(ExpressionOperator.FunctionOperator);
exOperator.setSelector(ExpressionOperator.Extract);
exOperator.setName("EXTRACT");
List<String> v = new ArrayList<>(3);
v.add("");
v.add("(");
v.add(")");
exOperator.printsAs(v);
int[] indices = new int[2];
indices[0] = 1;
indices[1] = 0;
exOperator.setArgumentIndices(indices);
exOperator.bePrefix();
exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
return exOperator;
}
Aggregations