Skip to content
Browse files

Merge branch '2.2.x'

  • Loading branch information...
2 parents aca3d75 + 1dac43f commit 5f2aff930c653755bdee8dee3b57bc10c8adf7d7 @graemerocher graemerocher committed
Showing with 3,678 additions and 208 deletions.
  1. +3,640 −203 LICENSE
  2. +10 −0 NOTICE
  3. +28 −5 grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/query/HibernateQuery.java
View
3,843 LICENSE
3,640 additions, 203 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
10 NOTICE
@@ -0,0 +1,10 @@
+Grails 2.2.0
+Copyright (c) 2012 VMware, Inc. All Rights Reserved.
+
+This product is licensed to you under the Apache License, Version 2.0 (the "License").
+You may not use this product except in compliance with the License.
+
+This product may include a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the subcomponent's license, as noted in the LICENSE file.
View
33 ...ernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/query/HibernateQuery.java
@@ -30,6 +30,7 @@
import org.grails.datastore.mapping.query.api.QueryableCriteria;
import org.grails.datastore.mapping.query.criteria.FunctionCallingCriterion;
import org.hibernate.Criteria;
+import org.hibernate.FetchMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.*;
import org.hibernate.dialect.Dialect;
@@ -47,6 +48,8 @@
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.util.ReflectionUtils;
+import javax.persistence.FetchType;
+
/**
* Bridges the Query API with the Hibernate Criteria API
*
@@ -56,6 +59,7 @@
@SuppressWarnings("rawtypes")
public class HibernateQuery extends Query {
+ public static final String SIZE_CONSTRAINT_PREFIX = "Size";
private Criteria criteria;
private HibernateQuery.HibernateProjectionList hibernateProjectionList = null;
private String alias;
@@ -116,6 +120,7 @@ else if (criterion instanceof PropertyCriterion) {
DetachedCriteria hibernateDetachedCriteria = HibernateCriteriaBuilder.getHibernateDetachedCriteria((QueryableCriteria) value);
pc.setValue(hibernateDetachedCriteria);
}
+ // ignore Size related constraints
else {
doTypeConversionIfNeccessary(getEntity(), pc);
}
@@ -127,11 +132,14 @@ else if (criterion instanceof PropertyCriterion) {
}
static void doTypeConversionIfNeccessary(PersistentEntity entity, PropertyCriterion pc) {
- String property = pc.getProperty();
- Object value = pc.getValue();
- PersistentProperty p = entity.getPropertyByName(property);
- if(p != null && !p.getType().isInstance(value)) {
- pc.setValue( conversionService.convert(value, p.getType()));
+ if(!pc.getClass().getSimpleName().startsWith(SIZE_CONSTRAINT_PREFIX)) {
+
+ String property = pc.getProperty();
+ Object value = pc.getValue();
+ PersistentProperty p = entity.getPropertyByName(property);
+ if(p != null && !p.getType().isInstance(value)) {
+ pc.setValue( conversionService.convert(value, p.getType()));
+ }
}
}
@@ -388,9 +396,23 @@ public List list() {
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
}
+
+ applyFetchStrategies();
return criteria.list();
}
+ private void applyFetchStrategies() {
+ for (Map.Entry<String, FetchType> entry : fetchStrategies.entrySet()) {
+ switch(entry.getValue()) {
+ case EAGER:
+ criteria.setFetchMode(entry.getKey(), FetchMode.JOIN); break;
+ case LAZY:
+ criteria.setFetchMode(entry.getKey(), FetchMode.SELECT); break;
+
+ }
+ }
+ }
+
@Override
protected void flushBeforeQuery() {
// do nothing
@@ -402,6 +424,7 @@ public Object singleResult() {
criteria.setProjection(hibernateProjectionList.getHibernateProjectionList());
}
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
+ applyFetchStrategies();
return criteria.uniqueResult();
}

0 comments on commit 5f2aff9

Please sign in to comment.
Something went wrong with that request. Please try again.