use of org.eclipse.persistence.expressions.ExpressionOperator in project blaze-persistence by Blazebit.
the class EclipseLinkEntityManagerIntegrator method addFunction.
private void addFunction(Map<Integer, ExpressionOperator> platformOperators, String name, JpqlFunction function, AbstractSession session, Map<Class<?>, String> classTypes) {
ExpressionOperator operator = createOperator(name, function, session, classTypes);
ExpressionOperator.registerOperator(operator.getSelector(), operator.getName());
ExpressionOperator.addOperator(operator);
platformOperators.put(Integer.valueOf(operator.getSelector()), operator);
}
use of org.eclipse.persistence.expressions.ExpressionOperator in project blaze-persistence by Blazebit.
the class EclipseLinkEntityManagerIntegrator method createOperator.
private ExpressionOperator createOperator(String name, JpqlFunction function, AbstractSession session, Map<Class<?>, String> classTypes) {
ExpressionOperator operator = new JpqlFunctionExpressionOperator(function, session, classTypes);
operator.setType(ExpressionOperator.FunctionOperator);
operator.setSelector(functionSelectorCounter++);
operator.setName(name);
// Vector v = new Vector();
// v.add("TRIM(LEADING ");
// v.add(" FROM ");
// v.add(")");
// operator.printsAs(v);
// operator.bePrefix();
// int[] argumentIndices = new int[2];
// argumentIndices[0] = 1;
// argumentIndices[1] = 0;
// operator.setArgumentIndices(argumentIndices);
operator.setNodeClass(ClassConstants.FunctionExpression_Class);
operator.setIsBindingSupported(false);
return operator;
}
use of org.eclipse.persistence.expressions.ExpressionOperator in project blaze-persistence by Blazebit.
the class EclipseLinkEntityManagerIntegrator method getRegisteredFunctions.
@Override
public Map<String, JpqlFunction> getRegisteredFunctions(EntityManagerFactory entityManagerFactory) {
AbstractSession session = entityManagerFactory.unwrap(JpaEntityManagerFactory.class).getDatabaseSession();
DatabasePlatform platform = session.getPlatform();
@SuppressWarnings("unchecked") Map<Integer, ExpressionOperator> platformOperators = platform.getPlatformOperators();
Map<String, JpqlFunction> functions = new HashMap<>(platformOperators.size());
for (ExpressionOperator op : platformOperators.values()) {
String name = (String) ExpressionOperator.getPlatformOperatorNames().get(op.getSelector());
if (name != null) {
if (op instanceof JpqlFunctionExpressionOperator) {
functions.put(name.toLowerCase(), ((JpqlFunctionExpressionOperator) op).unwrap());
} else {
int selector = op.getSelector();
// No support for these expressions
if (selector != ExpressionOperator.Union && selector != ExpressionOperator.UnionAll && selector != ExpressionOperator.Intersect && selector != ExpressionOperator.IntersectAll && selector != ExpressionOperator.Except && selector != ExpressionOperator.ExceptAll) {
functions.put(name.toLowerCase(), new ExpressionOperatorJpqlFunction(op));
}
}
}
}
// Eclipselink doesn't report all functions..
functions.put("count", new ExpressionOperatorJpqlFunction(ExpressionOperator.count()));
functions.put("sum", new ExpressionOperatorJpqlFunction(ExpressionOperator.sum()));
functions.put("avg", new ExpressionOperatorJpqlFunction(ExpressionOperator.average()));
functions.put("max", new ExpressionOperatorJpqlFunction(ExpressionOperator.maximum()));
functions.put("min", new ExpressionOperatorJpqlFunction(ExpressionOperator.minimum()));
functions.put("stddev", new ExpressionOperatorJpqlFunction(ExpressionOperator.standardDeviation()));
functions.put("var", new ExpressionOperatorJpqlFunction(ExpressionOperator.variance()));
return functions;
}
use of org.eclipse.persistence.expressions.ExpressionOperator in project eclipselink by eclipse-ee4j.
the class Query_Basic_Tests method testRawUsage.
public void testRawUsage() throws Exception {
Vector stringsVec = new Vector();
// Geometry 1
stringsVec.add("SDO_WITHIN_DISTANCE(");
// Geometry 2
stringsVec.add(",");
// PARAMS
stringsVec.add(",");
stringsVec.add(")");
ExpressionOperator op = new ExpressionOperator(-1, stringsVec);
op.bePrefix();
ReadAllQuery raq = new ReadAllQuery(SimpleSpatial.class);
ExpressionBuilder eb = raq.getExpressionBuilder();
JGeometry comparison = JGeometry.createMultiPoint(new Object[] { new double[] { 5, 6 }, new double[] { 7, 8 } }, 2, 0);
Vector args = new Vector(2);
args.add(new BindCallCustomParameter(comparison));
args.add("DISTANCE=10");
Expression criteria = eb.get("geometry").performOperator(op, args).equal("TRUE");
raq.setSelectionCriteria(criteria);
session.executeQuery(raq);
}
use of org.eclipse.persistence.expressions.ExpressionOperator in project eclipselink by eclipse-ee4j.
the class SpatialExpressionFactory method getSpatialExpression.
/**
* INTERNAL:
* A utility method to build a SpatialExpression
*
* @param operator the ordinal of the operator
*/
public static Expression getSpatialExpression(int operator, Expression geom1, Object geom2, String params) {
List<Object> vParameters = new Vector<>(2);
vParameters.add(geom2);
// by null prior to passing to Geometry call.
if (params == null || params.trim().equals("")) {
vParameters.add(null);
} else {
vParameters.add(params);
}
ExpressionOperator anOperator = geom1.getOperator(operator);
FunctionExpression expression = new FunctionExpression();
expression.create(geom1, vParameters, anOperator);
Expression finalExpression = expression.equal("TRUE");
return finalExpression;
}
Aggregations