@SuppressWarnings("unchecked") @Test public void testReturnsExpression() throws ODataApplicationException { final Expression<?>[] jpaParameter = new Expression<?>[0]; when(jpaFunction.getDBName()).thenReturn("Test"); doReturn(new Integer(5).getClass()).when(jpaResultParam).getType(); when(cb.function(jpaFunction.getDBName(), jpaResultParam.getType(), jpaParameter)).thenReturn(mock( Expression.class)); when(jpaFunction.getResultParameter()).thenReturn(jpaResultParam); Expression<?> act = cut.get(); assertNotNull(act); }
@Override public Expression<?> get() throws ODataApplicationException { if (jpaFunction.getResultParameter().isCollection()) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_COLLECTION, HttpStatusCode.NOT_IMPLEMENTED); } if (!JPATypeConvertor.isScalarType( jpaFunction.getResultParameter().getType())) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_NOT_SCALAR, HttpStatusCode.NOT_IMPLEMENTED); } final CriteriaBuilder cb = visitor.getCriteriaBuilder(); List<JPAParameter> parameters; try { parameters = jpaFunction.getParameter(); } catch (ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } final Expression<?>[] jpaParameter = new Expression<?>[parameters.size()]; for (int i = 0; i < parameters.size(); i++) { final UriParameter p = findUriParameter(parameters.get(i)); if (p != null && p.getText() != null) { final JPALiteralOperator operator = new JPALiteralOperator(visitor.getOdata(), new ParameterLiteral(p .getText())); jpaParameter[i] = cb.literal(operator.get(parameters.get(i))); } else { try { jpaParameter[i] = (Expression<?>) p.getExpression().accept(visitor).get(); } catch (ExpressionVisitException e) { throw new ODataJPAFilterException(e, HttpStatusCode.NOT_IMPLEMENTED); } } } return cb.function(jpaFunction.getDBName(), jpaFunction.getResultParameter().getType(), jpaParameter); }
JPAFunctionOperator implements JPAOperator { @Override public Expression<?> get() throws ODataApplicationException { if (jpaFunction.getResultParameter().isCollection()) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_COLLECTION, HttpStatusCode.NOT_IMPLEMENTED); } if (!JPATypeConvertor.isScalarType( jpaFunction.getResultParameter().getType())) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_NOT_SCALAR, HttpStatusCode.NOT_IMPLEMENTED); } final CriteriaBuilder cb = visitor.getCriteriaBuilder(); List<JPAParameter> parameters; try { parameters = jpaFunction.getParameter(); } catch (ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } final Expression<?>[] jpaParameter = new Expression<?>[parameters.size()]; for (int i = 0; i < parameters.size(); i++) { final UriParameter p = findUriParameter(parameters.get(i)); if (p != null && p.getText() != null) { final JPALiteralOperator operator = new JPALiteralOperator(visitor.getOdata(), new ParameterLiteral(p .getText())); jpaParameter[i] = cb.literal(operator.get(parameters.get(i))); } else { try { jpaParameter[i] = (Expression<?>) p.getExpression().accept(visitor).get(); } catch (ExpressionVisitException e) { throw new ODataJPAFilterException(e, HttpStatusCode.NOT_IMPLEMENTED); } } } return cb.function(jpaFunction.getDBName(), jpaFunction.getResultParameter().getType(), jpaParameter); } }
JPAFunctionOperator implements JPAOperator { @Override public Expression<?> get() throws ODataApplicationException { if (jpaFunction.getResultParameter().isCollection()) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_COLLECTION, HttpStatusCode.NOT_IMPLEMENTED); } if (!JPATypeConvertor.isScalarType( jpaFunction.getResultParameter().getType())) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_NOT_SCALAR, HttpStatusCode.NOT_IMPLEMENTED); } final CriteriaBuilder cb = visitor.getCriteriaBuilder(); List<JPAParameter> parameters; try { parameters = jpaFunction.getParameter(); } catch (ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } final Expression<?>[] jpaParameter = new Expression<?>[parameters.size()]; for (int i = 0; i < parameters.size(); i++) { final UriParameter p = findUriParameter(parameters.get(i)); if (p != null && p.getText() != null) { final JPALiteralOperator operator = new JPALiteralOperator(visitor.getOdata(), new ParameterLiteral(p .getText())); jpaParameter[i] = cb.literal(operator.get(parameters.get(i))); } else { try { jpaParameter[i] = (Expression<?>) p.getExpression().accept(visitor).get(); } catch (ExpressionVisitException e) { throw new ODataJPAFilterException(e, HttpStatusCode.NOT_IMPLEMENTED); } } } return cb.function(jpaFunction.getDBName(), jpaFunction.getResultParameter().getType(), jpaParameter); } JPAFunctionOperator(final JPAVisitor jpaVisitor, final List<UriParameter> uriParams,
      final JPADataBaseFunction jpaFunction); }
JPAFunctionOperator implements JPAOperator { @Override public Expression<?> get() throws ODataApplicationException { if (jpaFunction.getResultParameter().isCollection()) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_COLLECTION, HttpStatusCode.NOT_IMPLEMENTED); } if (!JPATypeConvertor.isScalarType( jpaFunction.getResultParameter().getType())) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_NOT_SCALAR, HttpStatusCode.NOT_IMPLEMENTED); } final CriteriaBuilder cb = visitor.getCriteriaBuilder(); List<JPAParameter> parameters; try { parameters = jpaFunction.getParameter(); } catch (ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } final Expression<?>[] jpaParameter = new Expression<?>[parameters.size()]; for (int i = 0; i < parameters.size(); i++) { final UriParameter p = findUriParameter(parameters.get(i)); if (p != null && p.getText() != null) { final JPALiteralOperator operator = new JPALiteralOperator(visitor.getOdata(), new ParameterLiteral(p .getText())); jpaParameter[i] = cb.literal(operator.get(parameters.get(i))); } else { try { jpaParameter[i] = (Expression<?>) p.getExpression().accept(visitor).get(); } catch (ExpressionVisitException e) { throw new ODataJPAFilterException(e, HttpStatusCode.NOT_IMPLEMENTED); } } } return cb.function(jpaFunction.getDBName(), jpaFunction.getResultParameter().getType(), jpaParameter); } JPAFunctionOperator(final JPAVisitor jpaVisitor, final List<UriParameter> uriParams,
      final JPADataBaseFunction jpaFunction); @Override Expression<?> get(); JPAOperationResultParameter getReturnType(); @Override String getName(); }
JPAFunctionOperator implements JPAOperator { @Override public Expression<?> get() throws ODataApplicationException { if (jpaFunction.getResultParameter().isCollection()) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_COLLECTION, HttpStatusCode.NOT_IMPLEMENTED); } if (!JPATypeConvertor.isScalarType( jpaFunction.getResultParameter().getType())) { throw new ODataJPAFilterException(ODataJPAFilterException.MessageKeys.NOT_SUPPORTED_FUNCTION_NOT_SCALAR, HttpStatusCode.NOT_IMPLEMENTED); } final CriteriaBuilder cb = visitor.getCriteriaBuilder(); List<JPAParameter> parameters; try { parameters = jpaFunction.getParameter(); } catch (ODataJPAModelException e) { throw new ODataJPAProcessorException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } final Expression<?>[] jpaParameter = new Expression<?>[parameters.size()]; for (int i = 0; i < parameters.size(); i++) { final UriParameter p = findUriParameter(parameters.get(i)); if (p != null && p.getText() != null) { final JPALiteralOperator operator = new JPALiteralOperator(visitor.getOdata(), new ParameterLiteral(p .getText())); jpaParameter[i] = cb.literal(operator.get(parameters.get(i))); } else { try { jpaParameter[i] = (Expression<?>) p.getExpression().accept(visitor).get(); } catch (ExpressionVisitException e) { throw new ODataJPAFilterException(e, HttpStatusCode.NOT_IMPLEMENTED); } } } return cb.function(jpaFunction.getDBName(), jpaFunction.getResultParameter().getType(), jpaParameter); } JPAFunctionOperator(final JPAVisitor jpaVisitor, final List<UriParameter> uriParams,
      final JPADataBaseFunction jpaFunction); @Override Expression<?> get(); JPAOperationResultParameter getReturnType(); @Override String getName();  }