@Override
    protected void visitOperation(Class<?> type, Operator operator, List<? extends Expression<?>> args) {
        if (operator == Ops.INSTANCE_OF) {
            handle(args.get(0)).append(" instanceof ");
            @SuppressWarnings("unchecked") //This is the expected type for instanceOf
            Constant<Class<?>> rightArg = (Constant<Class<?>>) args.get(1);
            append(rightArg.getConstant().getName());

        } else if (operator == Ops.LIKE || operator == Ops.LIKE_ESCAPE || operator == Ops.LIKE_IC || operator == Ops.LIKE_ESCAPE_IC) {
            @SuppressWarnings("unchecked") //This is the expected type for like
            Expression<String> string = (Expression<String>) args.get(0);
            @SuppressWarnings("unchecked") //This is the expected type for like
            Expression<String> regex = ExpressionUtils.likeToRegex((Expression<String>) args.get(1), false);
            if (operator == Ops.LIKE_IC || operator == Ops.LIKE_ESCAPE_IC) {
                string = ExpressionUtils.toLower(string);
                regex = ExpressionUtils.toLower(regex);
            }
            super.visitOperation(type, Ops.MATCHES,
                Arrays.asList(string, regex));

        // exists
        } else if (operator == Ops.EXISTS && args.get(0) instanceof SubQueryExpression) {
            final SubQueryExpression subQuery = (SubQueryExpression) args.get(0);
            append("(");
            serialize(subQuery.getMetadata(), true, true);
            append(") > 0");

        // not exists
        } else if (operator == Ops.NOT && args.get(0) instanceof Operation
                && ((Operation) args.get(0)).getOperator().equals(Ops.EXISTS)) {
            final SubQueryExpression subQuery = (SubQueryExpression) ((Operation) args.get(0)).getArg(0);
            append("(");
            serialize(subQuery.getMetadata(), true, true);
            append(") == 0");

        } else if (operator == Ops.NUMCAST) {
            @SuppressWarnings("unchecked") //This is the expected type for castToNum
            Constant<Class<?>> rightArg = (Constant<Class<?>>) args.get(1);
            Class<?> clazz = rightArg.getConstant();
            if (Number.class.isAssignableFrom(clazz) && PrimitiveUtils.isWrapperType(clazz)) {
                clazz = PrimitiveUtils.unwrap(clazz);
            }
            append("(" + clazz.getSimpleName() + ")").handle(args.get(0));

        } else if (operator == Ops.ALIAS) {
            if (args.get(1) instanceof Path && !((Path<?>) args.get(1)).getMetadata().isRoot()) {
                Path<?> path = (Path<?>) args.get(1);
                args = Arrays.asList(args.get(0),
                        ExpressionUtils.path(path.getType(), path.getMetadata().getName()));
            }
            super.visitOperation(type, operator, args);

        } else {
            super.visitOperation(type, operator, args);
        }
    }
{@code JDOQLSerializer} serializes Querydsl queries and expressions into JDOQL strings

@author tiwe
querydsl-jdo/src/main/java/com/querydsl/jdo/JDOQLSerializer.java