Skip to content
Browse files

GRAILS-9402 - sqlGroupProjection support

  • Loading branch information...
1 parent 8994b5f commit a745961d0b254252d7ef192e1e184a4bc8249a2b @jeffbrown jeffbrown committed Sep 12, 2012
View
12 grails-hibernate/src/main/groovy/grails/orm/HibernateCriteriaBuilder.java
@@ -256,6 +256,18 @@ protected void sqlProjection(String sql, List<String> columnAliases, List<Type>
}
/**
+ * Adds a sql projection to the criteria
+ *
+ * @param sql SQL projecting
+ * @param groupBy group by clause
+ * @param columnAliases List of column aliases for the projected values
+ * @param type List of types for the projected values
+ */
+ protected void sqlGroupProjection(String sql, String groupBy, List<String> columnAliases, List<Type> types) {
+ projectionList.add(Projections.sqlGroupProjection(sql, groupBy, columnAliases.toArray(new String[columnAliases.size()]), types.toArray(new Type[types.size()])));
+ }
+
+ /**
* A projection that selects a distince property name
* @param propertyName The property name
*/
View
10 ...test/groovy/org/codehaus/groovy/grails/orm/hibernate/HibernateCriteriaBuilderTests.groovy
@@ -110,6 +110,16 @@ class HibernateCriteriaBuilderTests extends AbstractGrailsHibernateTests {
assert [10, 16] == results[1]
assert [11, 18] == results[2]
assert [13, 36] == results[3]
+
+ results = Box.withCriteria {
+ projections {
+ sqlGroupProjection 'width, sum(height) as combinedHeightsForThisWidth', 'width', ['width', 'combinedHeightsForThisWidth'], [StandardBasicTypes.INTEGER, StandardBasicTypes.INTEGER]
+ }
+ }
+
+ assert 2 == results?.size()
+ assert [2, 24] == results[0]
+ assert [4, 9] == results[1]
}
void testSqlRestriction() {

0 comments on commit a745961

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