Search in sources :

Example 1 with ExpressionOperator

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);
}
Also used : ExpressionOperator(org.eclipse.persistence.expressions.ExpressionOperator)

Example 2 with ExpressionOperator

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;
}
Also used : ExpressionOperator(org.eclipse.persistence.expressions.ExpressionOperator)

Example 3 with ExpressionOperator

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;
}
Also used : JpqlFunction(com.blazebit.persistence.spi.JpqlFunction) HashMap(java.util.HashMap) DatabasePlatform(org.eclipse.persistence.platform.database.DatabasePlatform) ExpressionOperator(org.eclipse.persistence.expressions.ExpressionOperator) JpaEntityManagerFactory(org.eclipse.persistence.jpa.JpaEntityManagerFactory) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 4 with ExpressionOperator

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);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) JGeometry(oracle.spatial.geometry.JGeometry) BindCallCustomParameter(org.eclipse.persistence.internal.databaseaccess.BindCallCustomParameter) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector) ExpressionOperator(org.eclipse.persistence.expressions.ExpressionOperator)

Example 5 with ExpressionOperator

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;
}
Also used : FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) Expression(org.eclipse.persistence.expressions.Expression) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) Vector(java.util.Vector) ExpressionOperator(org.eclipse.persistence.expressions.ExpressionOperator)

Aggregations

ExpressionOperator (org.eclipse.persistence.expressions.ExpressionOperator)93 ArrayList (java.util.ArrayList)57 Expression (org.eclipse.persistence.expressions.Expression)10 List (java.util.List)5 Vector (java.util.Vector)4 ExpressionJavaPrinter (org.eclipse.persistence.internal.expressions.ExpressionJavaPrinter)4 ExpressionSQLPrinter (org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter)4 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)3 LiteralExpression (org.eclipse.persistence.internal.expressions.LiteralExpression)3 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)3 JpqlFunction (com.blazebit.persistence.spi.JpqlFunction)2 HashMap (java.util.HashMap)2 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)2 RelationExpression (org.eclipse.persistence.internal.expressions.RelationExpression)2 JpaEntityManagerFactory (org.eclipse.persistence.jpa.JpaEntityManagerFactory)2 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)2 CountStarFunction (com.blazebit.persistence.integration.jpa.function.CountStarFunction)1 JpqlFunctionGroup (com.blazebit.persistence.spi.JpqlFunctionGroup)1 BigDecimal (java.math.BigDecimal)1 Connection (java.sql.Connection)1