Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:grails/grails-core

  • Loading branch information...
commit 413fdfc3ccb607c0d170c9f8408c27fc50392f85 2 parents 7e0fd13 + 4d8a1dc
@graemerocher graemerocher authored
View
46 grails-hibernate/src/main/groovy/grails/orm/HibernateCriteriaBuilder.java
@@ -67,6 +67,7 @@
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.AssociationType;
import org.hibernate.type.EmbeddedComponentType;
+import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.springframework.beans.BeanUtils;
import org.springframework.orm.hibernate3.SessionHolder;
@@ -1937,4 +1938,49 @@ private static void addOrder(Criteria c, String sort, String order, boolean igno
c.addOrder( ignoreCase ? Order.asc(sort).ignoreCase() : Order.asc(sort) );
}
}
+
+ /*
+ * Define constants which may be used inside of criteria queries
+ * to refer to standard Hibernate Type instances.
+ */
+ public static final Type BOOLEAN = StandardBasicTypes.BOOLEAN;
+ public static final Type YES_NO = StandardBasicTypes.YES_NO;
+ public static final Type BYTE = StandardBasicTypes.BYTE;
+ public static final Type CHARACTER = StandardBasicTypes.CHARACTER;
+ public static final Type SHORT = StandardBasicTypes.SHORT;
+ public static final Type INTEGER = StandardBasicTypes.INTEGER;
+ public static final Type LONG = StandardBasicTypes.LONG;
+ public static final Type FLOAT = StandardBasicTypes.FLOAT;
+ public static final Type DOUBLE = StandardBasicTypes.DOUBLE;
+ public static final Type BIG_DECIMAL = StandardBasicTypes.BIG_DECIMAL;
+ public static final Type BIG_INTEGER = StandardBasicTypes.BIG_INTEGER;
+ public static final Type STRING = StandardBasicTypes.STRING;
+ public static final Type NUMERIC_BOOLEAN = StandardBasicTypes.NUMERIC_BOOLEAN;
+ public static final Type TRUE_FALSE = StandardBasicTypes.TRUE_FALSE;
+ public static final Type URL = StandardBasicTypes.URL;
+ public static final Type TIME = StandardBasicTypes.TIME;
+ public static final Type DATE = StandardBasicTypes.DATE;
+ public static final Type TIMESTAMP = StandardBasicTypes.TIMESTAMP;
+ public static final Type CALENDAR = StandardBasicTypes.CALENDAR;
+ public static final Type CALENDAR_DATE = StandardBasicTypes.CALENDAR_DATE;
+ public static final Type CLASS = StandardBasicTypes.CLASS;
+ public static final Type LOCALE = StandardBasicTypes.LOCALE;
+ public static final Type CURRENCY = StandardBasicTypes.CURRENCY;
+ public static final Type TIMEZONE = StandardBasicTypes.TIMEZONE;
+ public static final Type UUID_BINARY = StandardBasicTypes.UUID_BINARY;
+ public static final Type UUID_CHAR = StandardBasicTypes.UUID_CHAR;
+ public static final Type BINARY = StandardBasicTypes.BINARY;
+ public static final Type WRAPPER_BINARY = StandardBasicTypes.WRAPPER_BINARY;
+ public static final Type IMAGE = StandardBasicTypes.IMAGE;
+ public static final Type BLOB = StandardBasicTypes.BLOB;
+ public static final Type MATERIALIZED_BLOB = StandardBasicTypes.MATERIALIZED_BLOB;
+ public static final Type WRAPPER_MATERIALIZED_BLOB = StandardBasicTypes.WRAPPER_MATERIALIZED_BLOB;
+ public static final Type CHAR_ARRAY = StandardBasicTypes.CHAR_ARRAY;
+ public static final Type CHARACTER_ARRAY = StandardBasicTypes.CHARACTER_ARRAY;
+ public static final Type TEXT = StandardBasicTypes.TEXT;
+ public static final Type CLOB = StandardBasicTypes.CLOB;
+ public static final Type MATERIALIZED_CLOB = StandardBasicTypes.MATERIALIZED_CLOB;
+ public static final Type WRAPPER_CHARACTERS_CLOB = StandardBasicTypes.WRAPPER_CHARACTERS_CLOB;
+ public static final Type CHARACTERS_CLOB = StandardBasicTypes.CHARACTERS_CLOB;
+ public static final Type SERIALIZABLE = StandardBasicTypes.SERIALIZABLE;
}
View
89 ...test/groovy/org/codehaus/groovy/grails/orm/hibernate/HibernateCriteriaBuilderTests.groovy
@@ -5,10 +5,6 @@ import grails.persistence.Entity
import org.codehaus.groovy.grails.commons.DomainClassArtefactHandler
import org.codehaus.groovy.grails.commons.GrailsDomainClass
-import org.hibernate.Hibernate
-import org.hibernate.criterion.Projections
-import org.hibernate.type.StandardBasicTypes
-import org.hibernate.type.Type
/**
* @author Graeme Rocher
@@ -92,28 +88,99 @@ class HibernateCriteriaBuilderTests extends AbstractGrailsHibernateTests {
def results = Box.withCriteria {
projections {
- sqlProjection 'sum(width * height) as totalArea', 'totalArea', StandardBasicTypes.INTEGER
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', BYTE
}
}
assert 1 == results?.size()
assert 84 == results[0]
+ assert results[0] instanceof Byte
results = Box.withCriteria {
projections {
- sqlProjection '(width + height) as perimeter, (width * height) as area', ['perimeter', 'area'], [StandardBasicTypes.INTEGER, StandardBasicTypes.INTEGER]
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', SHORT
+ }
+ }
+
+ assert 1 == results?.size()
+ assert 84 == results[0]
+ assert results[0] instanceof Short
+
+ results = Box.withCriteria {
+ projections {
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', INTEGER
+ }
+ }
+
+ assert 1 == results?.size()
+ assert 84 == results[0]
+ assert results[0] instanceof Integer
+
+ results = Box.withCriteria {
+ projections {
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', LONG
+ }
+ }
+
+ assert 1 == results?.size()
+ assert 84 == results[0]
+ assert results[0] instanceof Long
+
+ results = Box.withCriteria {
+ projections {
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', FLOAT
+ }
+ }
+
+ assert 1 == results?.size()
+ assert 84 == results[0]
+ assert results[0] instanceof Float
+
+ results = Box.withCriteria {
+ projections {
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', DOUBLE
+ }
+ }
+
+ assert 1 == results?.size()
+ assert 84 == results[0]
+ assert results[0] instanceof Double
+
+ results = Box.withCriteria {
+ projections {
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', BIG_INTEGER
+ }
+ }
+
+ assert 1 == results?.size()
+ assert 84 == results[0]
+ assert results[0] instanceof BigInteger
+
+ results = Box.withCriteria {
+ projections {
+ sqlProjection 'sum(width * height) as totalArea', 'totalArea', BIG_DECIMAL
+ }
+ }
+
+ assert 1 == results?.size()
+ assert 84 == results[0]
+ assert results[0] instanceof BigDecimal
+
+ results = Box.withCriteria {
+ projections {
+ sqlProjection '(2 * (width + height)) as perimeter, (width * height) as area', ['perimeter', 'area'], [INTEGER, INTEGER]
}
}
assert 4 == results?.size()
- assert [9, 14] == results[0]
- assert [10, 16] == results[1]
- assert [11, 18] == results[2]
- assert [13, 36] == results[3]
+ assert [18, 14] == results[0]
+ assert [20, 16] == results[1]
+ assert [22, 18] == results[2]
+ assert [26, 36] == results[3]
results = Box.withCriteria {
projections {
- sqlGroupProjection 'width, sum(height) as combinedHeightsForThisWidth', 'width', ['width', 'combinedHeightsForThisWidth'], [StandardBasicTypes.INTEGER, StandardBasicTypes.INTEGER]
+ sqlGroupProjection 'width, sum(height) as combinedHeightsForThisWidth', 'width', ['width', 'combinedHeightsForThisWidth'], [INTEGER, INTEGER]
}
}

0 comments on commit 413fdfc

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