- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.7k
 
HHH-18496 Add support for JSON functions #8793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| ReturnableType<?> returnType, | ||
| SqlAstTranslator<?> walker) { | ||
| if ( arguments.errorBehavior() != null ) { | ||
| throw new QueryException( "Can't emulate on error clause on H2" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
        
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/json/H2JsonValueFunction.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
      | jsonPath = walker.getLiteralValue( (Expression) arguments.jsonPath() ); | ||
| } | ||
| catch (Exception ex) { | ||
| throw new QueryException( "H2 json_value only support literal json paths, but got " + arguments.jsonPath() ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
        
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/json/JsonPathHelper.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/json/JsonPathHelper.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                ...rnate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJsonValueExpression.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                ...rnate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJsonValueExpression.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                ...rnate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJsonValueExpression.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                hibernate-core/src/test/java/org/hibernate/orm/test/function/json/JsonValueTest.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                hibernate-core/src/test/java/org/hibernate/orm/test/function/json/JsonValueTest.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
      | throw new QueryException( "Can't emulate on error clause on H2" ); | ||
| } | ||
| if ( arguments.emptyBehavior() == JsonValueEmptyBehavior.ERROR ) { | ||
| throw new QueryException( "Can't emulate error on empty clause on H2" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| ReturnableType<?> returnType, | ||
| SqlAstTranslator<?> walker) { | ||
| if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.NULL ) { | ||
| throw new QueryException( "Can't emulate on error clause on MariaDB" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| throw new QueryException( "Can't emulate on error clause on MariaDB" ); | ||
| } | ||
| if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) { | ||
| throw new QueryException( "Can't emulate on empty clause on MariaDB" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| scope.inSession( em -> { | ||
| try { | ||
| //tag::hql-json-value-on-error-example[] | ||
| em.createQuery( "select json_value('invalidJson', '$.theInt' error on error) from EntityWithJson e") | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| scope.inSession( em -> { | ||
| try { | ||
| //tag::hql-json-value-on-empty-example[] | ||
| em.createQuery("select json_value(e.json, '$.nonExisting' error on empty error on error) from EntityWithJson e" ) | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| SqlAstTranslator<?> walker) { | ||
| // jsonb_path_query_first errors by default | ||
| if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.ERROR ) { | ||
| throw new QueryException( "Can't emulate on error clause on CockroachDB" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| throw new QueryException( "Can't emulate on error clause on CockroachDB" ); | ||
| } | ||
| if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) { | ||
| throw new QueryException( "Can't emulate on empty clause on CockroachDB" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| jsonPath = walker.getLiteralValue( arguments.jsonPath() ); | ||
| } | ||
| catch (Exception ex) { | ||
| throw new QueryException( "CockroachDB json_value only support literal json paths, but got " + arguments.jsonPath() ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
        
          
                ...rnate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJsonValueExpression.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                ...rnate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJsonValueExpression.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
      | public void testSimple(SessionFactoryScope scope) { | ||
| scope.inSession( em -> { | ||
| //tag::hql-json-array-example[] | ||
| em.createQuery( "select json_array('val1', 'val2'), json_array(1, false, 'val')" ).getResultList(); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| public void testNullClause(SessionFactoryScope scope) { | ||
| scope.inSession( em -> { | ||
| //tag::hql-json-array-on-null-example[] | ||
| em.createQuery("select json_array(null, 1 null on null)" ).getResultList(); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| @Test | ||
| public void testAbsentOnNull(SessionFactoryScope scope) { | ||
| scope.inSession( em -> { | ||
| em.createQuery("select json_array(null, 1 absent on null)" ).getResultList(); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| public void testSimple(SessionFactoryScope scope) { | ||
| scope.inSession( em -> { | ||
| //tag::hql-json-object-example[] | ||
| em.createQuery( "select json_object('key', 'value'), json_object(KEY 'key1' VALUE 'value1', 'key2' VALUE 'value2', 'key3': 'value3')" ).getResultList(); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| @Test | ||
| public void testNullClause(SessionFactoryScope scope) { | ||
| scope.inSession( em -> { | ||
| em.createQuery("select json_object('key': null null on null)" ).getResultList(); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| public void testAbsentOnNull(SessionFactoryScope scope) { | ||
| scope.inSession( em -> { | ||
| //tag::hql-json-object-on-null-example[] | ||
| em.createQuery("select json_object('key': null absent on null)" ).getResultList(); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
e0417d5    to
    4654f88      
    Compare
  
    | final String parameterName = ( (JsonPathHelper.JsonParameterIndexAccess) jsonPathElement ).parameterName(); | ||
| final Expression expression = jsonPathPassingClause.getPassingExpressions().get( parameterName ); | ||
| if ( expression == null ) { | ||
| throw new QueryException( "JSON path [" + jsonPath + "] uses parameter [" + parameterName + "] that is not passed" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| SqlAstTranslator<?> walker) { | ||
| // Json dereference errors by default if the JSON is invalid | ||
| if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonExistsErrorBehavior.ERROR ) { | ||
| throw new QueryException( "Can't emulate on error clause on H2" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| jsonPath = walker.getLiteralValue( arguments.jsonPath() ); | ||
| } | ||
| catch (Exception ex) { | ||
| throw new QueryException( "H2 json_value only support literal json paths, but got " + arguments.jsonPath() ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| final String parameterName = ( (JsonPathHelper.JsonParameterIndexAccess) jsonPathElement ).parameterName(); | ||
| final Expression expression = passingClause.getPassingExpressions().get( parameterName ); | ||
| if ( expression == null ) { | ||
| throw new QueryException( "JSON path [" + jsonPath + "] uses parameter [" + parameterName + "] that is not passed" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
        
          
                hibernate-core/src/main/java/org/hibernate/dialect/function/json/JsonExistsFunction.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
      | assert jsonPath.charAt( bracketStartIndex ) == '['; | ||
| final int bracketEndIndex = jsonPath.lastIndexOf( ']', endIndex ); | ||
| if ( bracketEndIndex < bracketStartIndex ) { | ||
| throw new QueryException( "Can't emulate non-simple json path expression: " + jsonPath ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| ReturnableType<?> returnType, | ||
| SqlAstTranslator<?> walker) { | ||
| if ( arguments.errorBehavior() == JsonExistsErrorBehavior.TRUE ) { | ||
| throw new QueryException( "Can't emulate json_exists(... true on error) on SQL Server" ); | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
        
          
                ...nate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJsonExistsExpression.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
              
          
                ...nate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJsonExistsExpression.java
              
                Fixed
          
            Show fixed
            Hide fixed
        
      | scope.inSession( em -> { | ||
| try { | ||
| //tag::hql-json-exists-on-error-example[] | ||
| em.createQuery( "select json_exists('invalidJson', '$.theInt' error on error) from EntityWithJson e") | 
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
97e50cd    to
    0a4bbbe      
    Compare
  
    a4db12b    to
    9a6ab64      
    Compare
  
    | 
           Superseded by #8979  | 
    
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-18496