Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.0.x' of github.com:grails/grails-core into 2.0.x

  • Loading branch information...
commit 30de06cb8c03723b29cec0af34fd2d2916c29cf4 2 parents 5a25482 + b40d493
@jeffbrown jeffbrown authored
View
13 ...ernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/query/HibernateQuery.java
@@ -61,14 +61,12 @@
private int aliasCount;
private Map<String, CriteriaAndAlias> createdAssociationPaths = new HashMap<String, CriteriaAndAlias> ();
private static final String ALIAS = "_alias";
- private Field opField;
+ private static Field opField = ReflectionUtils.findField(SimpleExpression.class, "op");
public HibernateQuery(Criteria criteria, HibernateSession session, PersistentEntity entity) {
super(session, entity);
this.criteria = criteria;
- opField = ReflectionUtils.findField(SimpleExpression.class, "op");
ReflectionUtils.makeAccessible(opField);
-
}
public HibernateQuery(Criteria subCriteria, HibernateSession session, PersistentEntity associatedEntity, String newAlias) {
@@ -127,7 +125,7 @@ else if (criterion instanceof PropertyCriterion) {
SessionFactory sessionFactory = hibernateSession.getSessionFactory();
String property = criterion.getProperty();
- PropertyCriterion propertyCriterion = criterion.getPropertyCriterion();
+ Criterion datastoreCriterion = criterion.getPropertyCriterion();
PersistentProperty pp = entity.getPropertyByName(property);
if (pp == null) throw new InvalidDataAccessResourceUsageException(
@@ -143,9 +141,10 @@ else if (criterion instanceof PropertyCriterion) {
if (sqlFunction != null) {
TypeResolver typeResolver = impl.getTypeResolver();
BasicType basic = typeResolver.basic(pp.getType().getName());
- if (basic != null) {
+ if (basic != null && datastoreCriterion instanceof PropertyCriterion) {
- final org.hibernate.criterion.Criterion hibernateCriterion = new HibernateCriterionAdapter(propertyCriterion, alias).toHibernateCriterion(this);
+ PropertyCriterion pc = (PropertyCriterion) datastoreCriterion;
+ final org.hibernate.criterion.Criterion hibernateCriterion = new HibernateCriterionAdapter(datastoreCriterion, alias).toHibernateCriterion(this);
if (hibernateCriterion instanceof SimpleExpression) {
SimpleExpression expr = (SimpleExpression) hibernateCriterion;
Object op = ReflectionUtils.getField(opField, expr);
@@ -156,7 +155,7 @@ else if (criterion instanceof PropertyCriterion) {
else
columns = mapping.toColumns(property);
String root = sqlFunction.render(basic, Arrays.asList(columns), impl);
- Object value = propertyCriterion.getValue();
+ Object value = pc.getValue();
if (value != null) {
sqlRestriction = Restrictions.sqlRestriction(root + op + "?", value, typeResolver.basic(value.getClass().getName()));
}
View
5 grails-plugin-testing/src/main/groovy/grails/test/MockUtils.groovy
@@ -45,6 +45,7 @@ import org.springframework.validation.FieldError
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.servlet.ModelAndView
import org.codehaus.groovy.grails.validation.DefaultConstraintEvaluator
+import org.codehaus.groovy.grails.validation.ConstrainedProperty
/**
* A utility/helper class for mocking various types of Grails artifacts
@@ -1022,14 +1023,14 @@ class MockUtils {
// that, we also do the normal validation for the case where
// we don't have a GDC, i.e. if we're validating a command
// object.
- constrainedProperties.each { property, constraint ->
+ constrainedProperties.each { property, ConstrainedProperty constraint ->
// Only perform the validation if we don't have a GDC
// (since if there is one the validation has already
// been done).
if (!dc) constraint.validate(obj, obj."${property}", errors)
// Handle the unique constraint if this field has one.
- def uniqueValue = constraint.getMetaConstraintValue("unique")
+ def uniqueValue = constraint.getMetaConstraintValue("unique") ?: constraint.getAppliedConstraint("unique")?.parameter
if (uniqueValue) {
def props
if (uniqueValue instanceof Boolean && uniqueValue) {
View
11 ...groovy/org/codehaus/groovy/grails/orm/hibernate/AdvancedEnumCollectionMappingTests.groovy
@@ -1,6 +1,9 @@
package org.codehaus.groovy.grails.orm.hibernate
import grails.persistence.Entity
+import org.codehaus.groovy.grails.validation.ConstrainedProperty
+import org.grails.datastore.gorm.validation.constraints.UniqueConstraintFactory
+import org.grails.datastore.mapping.simple.SimpleMapDatastore
/**
* @author Graeme Rocher
@@ -14,6 +17,14 @@ class AdvancedEnumCollectionMappingTests extends AbstractGrailsHibernateTests {
[EnumCollectionMappingUser]
}
+ @Override
+ protected void onSetUp() {
+ super.onSetUp()
+ ConstrainedProperty.registerNewConstraint("unique", new UniqueConstraintFactory(new SimpleMapDatastore()))
+ }
+
+
+
void testAdvancedEnumCollectionMapping() {
def User = ga.getDomainClass(EnumCollectionMappingUser.name).clazz
def Role = ga.classLoader.loadClass(EnumCollectionMappingRole.name)
Please sign in to comment.
Something went wrong with that request. Please try again.