Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.grails.datastore.mapping.query.api.QueryArgumentsAware
import org.grails.datastore.mapping.query.api.QueryableCriteria
import org.grails.orm.hibernate.AbstractHibernateSession
import org.hibernate.QueryException
import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.springframework.core.convert.ConverterNotFoundException

import gorm.tools.beans.Pager
import gorm.tools.mango.api.QueryArgs
Expand All @@ -39,7 +39,6 @@ import yakworks.api.problem.ThrowableProblem
import yakworks.api.problem.data.DataProblem
import yakworks.commons.lang.NameUtils
import yakworks.gorm.config.GormConfig
import yakworks.spring.AppCtx

/**
* This is here to make it easier to build criteria with domain bean paths
Expand Down Expand Up @@ -264,9 +263,13 @@ class MangoDetachedCriteria<T> extends DetachedCriteria<T> {
}
return query.list()
}
} catch (IllegalArgumentException | QueryException ex) {
} catch (IllegalArgumentException | QueryException | ClassCastException | ConverterNotFoundException ex) {
//Hibernate throws IllegalArgumentException when Antlr fails to parse query
//and throws QueryException when hibernate fails to execute query
//QueryException when hibernate fails to execute query
//ClassCast exception, when the value type doesnt match the field type
//ConverterNotFoundException when trying to convert string to an association type, etc
//We catch individual exceptions instead of a catch all RuntimeException, so that when some thing fails
//it will be logged and we can see, or else, it will come to notice only when api user's report why some queries arent working.
throw toDataProblem(ex)
}
}
Expand Down Expand Up @@ -319,9 +322,13 @@ class MangoDetachedCriteria<T> extends DetachedCriteria<T> {
try {
def list = hq.list(queryInfo.query, queryInfo.paramMap, args)
return list as List<Map>
} catch (IllegalArgumentException | QueryException ex) {
} catch (IllegalArgumentException | QueryException | ClassCastException | ConverterNotFoundException ex) {
//Hibernate throws IllegalArgumentException when Antlr fails to parse query
//and throws QueryException when hibernate fails to execute query
//QueryException when hibernate fails to execute query
//ClassCast exception, when the value type doesnt match the field type
//ConverterNotFoundException when trying to convert string to an association type, etc
//We catch individual exceptions instead of a catch all RuntimeException, so that when some thing fails
//it will be logged and we can see, or else, it will come to notice only when api user's report why some queries arent working.
throw toDataProblem(ex)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package gorm.tools.mango

import org.springframework.beans.factory.annotation.Autowired
import spock.lang.IgnoreRest
import spock.lang.Issue
import spock.lang.Specification
import testing.Address
import testing.AddyNested
Expand Down Expand Up @@ -192,4 +194,27 @@ class DefaultMangoQuerySpec extends Specification implements GormHibernateTest {
ex.detail.contains("Text 'xxx' could not be parsed")
}

@Issue("#3227")
void "query fails with class cast exception"() {
when:
Cust.query("location":[[address:['add 1']]]).list()

then:
DataProblemException ex = thrown()
ex.code == 'error.query.invalid'
ex.detail.contains "java.util.ArrayList cannot be cast to class java.lang.String"
}


@Issue("#3189")
void "no converters found"() {
when:
Cust.query("location":"add 1").list()

then:
DataProblemException ex = thrown()
ex.code == 'error.query.invalid'
ex.detail.contains "No converter found capable of converting from type [java.lang.String] to type [testing.Address]"
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package gorm.tools.mango


import gorm.tools.mango.jpql.JpqlQueryBuilder
import spock.lang.Specification
import testing.Cust
import yakworks.testing.gorm.model.KitchenSink
import yakworks.testing.gorm.unit.GormHibernateTest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ class MangoTidyMapSpec extends Specification {
]
]

when:
mmap = tidy([
"num": ['num1', 'num2']
])

then:
mmap == [
num: [
'$in': ['num1', 'num2']
]
]
}

void "test like"() {
Expand Down