Permalink
Browse files

Distinct working with List

  • Loading branch information...
1 parent 2a88408 commit 7f8325525a83ba17b8755bdc60624463027e7907 @fabiooshiro committed Dec 23, 2012
View
@@ -11,6 +11,26 @@
<classpathentry kind="src" path="test/integration"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="src" path=".link_to_grails_plugins/release-2.0.0/src/groovy">
+ <attributes>
+ <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" path=".link_to_grails_plugins/release-2.0.0/src/java">
+ <attributes>
+ <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" path=".link_to_grails_plugins/rest-client-builder-1.0.2/src/groovy">
+ <attributes>
+ <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" path=".link_to_grails_plugins/svn-1.0.1/src/groovy">
+ <attributes>
+ <attribute name="com.springsource.sts.grails.core.SOURCE_FOLDER" value="true"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="con" path="com.springsource.sts.grails.core.CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target-eclipse/classes"/>
</classpath>
View
@@ -1,4 +1,5 @@
target
+/.settings
*.class
*.swp
*.log
View
@@ -20,7 +20,7 @@
<link>
<name>.link_to_grails_plugins</name>
<type>2</type>
- <locationURI>GRAILS_ROOT/2.0.1/projects/plastic-criteria/plugins</locationURI>
+ <locationURI>GRAILS_ROOT/2.0.4/projects/plastic-criteria/plugins</locationURI>
</link>
</linkedResources>
</projectDescription>
@@ -1,6 +1,6 @@
class PlasticCriteriaGrailsPlugin {
// the plugin version
- def version = "0.3"
+ def version = "0.4"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3 > *"
// the other plugins this plugin depends on
View
@@ -1,7 +1,7 @@
#Grails Metadata file
-#Sat Sep 22 23:02:00 BRT 2012
-app.grails.version=2.0.4
+#Sat Dec 15 00:20:14 BRST 2012
+app.grails.version=2.1.2
app.name=plastic-criteria
-plugins.hibernate=2.0.4
+plugins.hibernate=2.1.2
plugins.rest-client-builder=1.0.2
plugins.svn=1.0.1
View
@@ -1,4 +1,4 @@
-<plugin name='plastic-criteria' version='0.1' grailsVersion='1.3 &gt; *'>
+<plugin name='plastic-criteria' version='0.4' grailsVersion='1.3 &gt; *'>
<author>Fabio Issamu Oshiro</author>
<title>Plastic Criteria Plugin</title>
<description>Mock Grails Criteria for Unit Tests
@@ -365,4 +365,21 @@ public class CriteriaDocTests {
assert ['Andreas Achenbach', 'Botero', 'Constance Gordon-Cumming'] == artistList
}
+ void testDistinctWithArrayParam(){
+ def b = new Artist(name: 'Tomie Oshiro').save()
+ new Portrait(artist: b, color: 'Ame', name: 'Cat').save() // Ame == yellow
+ new Portrait(artist: b, color: 'Blue', name: 'Fox').save()
+ new Portrait(artist: b, color: 'Ame', name: 'Cat').save()
+ new Portrait(artist: b, color: 'Blue', name: 'Cat').save()
+ def artistList = Portrait.withCriteria{
+ projections{
+ distinct(['color', 'name'])
+ }
+ }
+ assert ([
+ ['Ame', 'Cat'],
+ ['Blue', 'Fox'],
+ ['Blue', 'Cat'],
+ ] as Set) == artistList as Set
+ }
}
@@ -162,7 +162,7 @@ public class PlasticCriteria {
def list(clos){
clos.delegate = this
clos()
- def ls = filteredList()
+ def ls = _filteredList()
if(_props){
def rs = []
def extractProps = { vls ->
@@ -240,13 +240,25 @@ public class PlasticCriteria {
return gotoParadise
}
- def _getProp(obj, propertyName){
+ def __getProperty(obj, propertyName){
def res = obj
propertyName.split('\\.').each{ res = it == 'class' ? res.class.name : res."$it" }
return res
}
+
+ def _getProp(obj, propertyName){
+ def res
+ if(propertyName instanceof List){
+ res = propertyName.collect{ pname ->
+ __getProperty(obj, pname)
+ }
+ } else {
+ res = __getProperty(obj, propertyName)
+ }
+ return res
+ }
- def filteredList(){
+ def _filteredList(){
def r = []
_clazz.list().each{ obj ->
if(knokinOnHeavensDoor(_leCriticalList, obj)){

0 comments on commit 7f83255

Please sign in to comment.