Permalink
Browse files

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

  • Loading branch information...
2 parents 124a8c4 + 0522d99 commit c413d4bd1f8a4e191cdbc2adf0064c334650fd2a @graemerocher graemerocher committed May 11, 2010
Showing with 518 additions and 125 deletions.
  1. +1 −1 bin/startGrails
  2. +2 −2 bin/startGrails.bat
  3. +1 −1 build.gradle
  4. +2 −2 build.properties
  5. +3 −3 samples/petclinic/application.properties
  6. +1 −0 scripts/BugReport.groovy
  7. +5 −0 src/java/grails/util/GrailsNameUtils.java
  8. +17 −9 src/java/org/codehaus/groovy/grails/orm/hibernate/cfg/HibernateNamedQueriesBuilder.groovy
  9. +18 −1 src/java/org/codehaus/groovy/grails/orm/hibernate/metaclass/FindAllPersistentMethod.java
  10. +2 −1 src/java/org/codehaus/groovy/grails/plugins/web/filters/FilterToHandlerAdapter.groovy
  11. +93 −2 src/java/org/codehaus/groovy/grails/plugins/web/filters/FiltersGrailsPlugin.groovy
  12. +1 −0 src/java/org/codehaus/groovy/grails/web/taglib/GrailsTagRegistry.java
  13. +63 −0 src/java/org/codehaus/groovy/grails/web/taglib/GroovyConditionalTag.java
  14. +8 −33 src/java/org/codehaus/groovy/grails/web/taglib/GroovyElseIfTag.java
  15. +3 −55 src/java/org/codehaus/groovy/grails/web/taglib/GroovyIfTag.java
  16. +32 −0 src/java/org/codehaus/groovy/grails/web/taglib/GroovyUnlessTag.java
  17. +10 −0 src/test/grails/util/GrailsNameUtilsTests.java
  18. +1 −1 src/test/grails/util/GrailsUtilTests.java
  19. +106 −0 src/test/org/codehaus/groovy/grails/orm/hibernate/FindAllMethodTests.groovy
  20. +35 −8 src/test/org/codehaus/groovy/grails/orm/hibernate/NamedCriteriaTests.groovy
  21. +70 −4 src/test/org/codehaus/groovy/grails/plugins/web/filters/FilterExecutionTests.groovy
  22. +20 −1 src/test/org/codehaus/groovy/grails/web/servlet/mvc/RedirectMethodTests.groovy
  23. +24 −1 src/test/org/codehaus/groovy/grails/web/taglib/CoreTagsTests.groovy
View
@@ -114,7 +114,7 @@ fi
if [ -z "$GROOVY_CONF" ]; then
GROOVY_CONF="$GRAILS_HOME/conf/groovy-starter.conf"
fi
-STARTER_CLASSPATH="$GRAILS_HOME/lib/groovy-all-1.7.2.jar:$GRAILS_HOME/dist/grails-bootstrap-1.3.0.jar"
+STARTER_CLASSPATH="$GRAILS_HOME/lib/groovy-all-1.7.2.jar:$GRAILS_HOME/dist/grails-bootstrap-1.3.1.BUILD-SNAPSHOT.jar"
# Allow access to Cocoa classes on OS X
if $darwin; then
View
@@ -106,7 +106,7 @@ set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
-set STARTER_CLASSPATH=%GRAILS_HOME%\lib\groovy-all-1.7.2.jar;%GRAILS_HOME%\dist\grails-bootstrap-1.3.0.jar
+set STARTER_CLASSPATH=%GRAILS_HOME%\lib\groovy-all-1.7.2.jar;%GRAILS_HOME%\dist\grails-bootstrap-1.3.1.BUILD-SNAPSHOT.jar
if exist "%USERPROFILE%/.groovy/init.bat" call "%USERPROFILE%/.groovy/init.bat"
@@ -127,7 +127,7 @@ set TOOLS_JAR=%JAVA_HOME%\lib\tools.jar
if "%JAVA_OPTS%" == "" set JAVA_OPTS=-Xmx512m -XX:MaxPermSize=96m
set JAVA_OPTS=%JAVA_OPTS% -Dprogram.name="%PROGNAME%"
set JAVA_OPTS=%JAVA_OPTS% -Dgrails.home="%GRAILS_HOME%"
-set JAVA_OPTS=%JAVA_OPTS% -Dgrails.version="1.3.0"
+set JAVA_OPTS=%JAVA_OPTS% -Dgrails.version="1.3.1.BUILD-SNAPSHOT"
set JAVA_OPTS=%JAVA_OPTS% -Dbase.dir="."
set JAVA_OPTS=%JAVA_OPTS% -Dtools.jar="%TOOLS_JAR%"
set JAVA_OPTS=%JAVA_OPTS% -Dgroovy.starter.conf="%STARTER_CONF%"
View
@@ -9,7 +9,7 @@ buildscript {
apply id: 'groovy'
-version = '1.3.0'
+version = '1.3.1.BUILD-SNAPSHOT'
sourceCompatibility = "1.5"
targetCompatibility = "1.5"
View
@@ -1,5 +1,5 @@
-grails.version=1.3.0
-bundlor.grails.version=1.3.0
+grails.version=1.3.1.BUILD-SNAPSHOT
+bundlor.grails.version=1.3.1.BUILD-SNAPSHOT
grails.src.commons=src/commons
grails.src.groovy=src/groovy
@@ -1,8 +1,8 @@
#Grails Metadata file
#Thu Oct 01 11:54:33 CEST 2009
-app.grails.version=1.3.0
+app.grails.version=1.3.1.BUILD-SNAPSHOT
app.name=petclinic
app.servlet.version=2.4
app.version=0.1
-plugins.hibernate=1.3.0
-plugins.tomcat=1.3.0
+plugins.hibernate=1.3.1.BUILD-SNAPSHOT
+plugins.tomcat=1.3.1.BUILD-SNAPSHOT
View
@@ -49,6 +49,7 @@ target ('default': "Creates a ZIP containing source artifacts for reporting bugs
fileset(dir: "${basedir}", includes: "scripts/**/*")
fileset(dir: "${basedir}", includes: "spring/**/*")
fileset(dir: "${basedir}", includes: "src/**/*")
+ fileset(file: "${basedir}/application.properties")
}
event("StatusFinal", ["Created bug-report ZIP at ${zipName}"])
@@ -121,6 +121,11 @@ public static String getLogicalName(String name, String trailingName) {
}
public static String getLogicalPropertyName(String className, String trailingName) {
+ if(!isBlank(className) && !isBlank(trailingName)) {
+ if(className.length() == trailingName.length() + 1 && className.endsWith(trailingName)) {
+ return className.substring(0, 1).toLowerCase();
+ }
+ }
return getLogicalName(getPropertyName(className), trailingName);
}
@@ -83,16 +83,17 @@ class NamedCriteriaProxy {
private dynamicMethods
private namedCriteriaParams
private previousInChain
+ private queryBuilder
- private invokeCriteriaClosure(delegate, additionalCriteriaClosure = null) {
+ private invokeCriteriaClosure(additionalCriteriaClosure = null) {
def crit = getPreparedCriteriaClosure(additionalCriteriaClosure)
- crit.delegate = delegate
crit()
}
def list(Object[] params, Closure additionalCriteriaClosure = null) {
def listClosure = {
- invokeCriteriaClosure(delegate, additionalCriteriaClosure)
+ queryBuilder = delegate
+ invokeCriteriaClosure(additionalCriteriaClosure)
def paramsMap
if (params && params[-1] instanceof Map) {
paramsMap = params[-1]
@@ -121,7 +122,8 @@ class NamedCriteriaProxy {
def get(id) {
id = HibernatePluginSupport.convertValueToIdentifierType(domainClass, id)
def getClosure = {
- invokeCriteriaClosure(delegate)
+ queryBuilder = delegate
+ invokeCriteriaClosure()
eq 'id', id
uniqueResult = true
}
@@ -130,7 +132,8 @@ class NamedCriteriaProxy {
def count(Closure additionalCriteriaClosure = null) {
def countClosure = {
- invokeCriteriaClosure(delegate, additionalCriteriaClosure)
+ queryBuilder = delegate
+ invokeCriteriaClosure(additionalCriteriaClosure)
uniqueResult = true
projections {
rowCount()
@@ -145,7 +148,8 @@ class NamedCriteriaProxy {
def findAllWhere(Map params, Boolean uniq = false) {
def queryClosure = {
- invokeCriteriaClosure(delegate)
+ queryBuilder = delegate
+ invokeCriteriaClosure()
params.each {key, val ->
eq key, val
}
@@ -173,13 +177,17 @@ class NamedCriteriaProxy {
if (method) {
def preparedClosure = getPreparedCriteriaClosure()
return method.invoke(domainClass.clazz, methodName, preparedClosure, args)
- } else if(domainClass.metaClass.getMetaProperty(methodName)) {
+ } else if(!queryBuilder && domainClass.metaClass.getMetaProperty(methodName)) {
def nextInChain = domainClass.metaClass.getMetaProperty(methodName).getProperty(domainClass)
nextInChain.previousInChain = this
return nextInChain(args)
+ } else if (domainClass.metaClass.getMetaProperty(methodName)) {
+ def nestedCriteria = domainClass.metaClass.getMetaProperty(methodName).getProperty(domainClass).criteriaClosure.clone()
+ nestedCriteria.delegate = queryBuilder
+ nestedCriteria(*args)
+ } else {
+ queryBuilder."${methodName}"(*args)
}
-
- throw new MissingMethodException(methodName, NamedCriteriaProxy, args)
}
private getPreparedCriteriaClosure(additionalCriteriaClosure = null) {
@@ -122,6 +122,7 @@ public Object doInHibernate(Session session) throws HibernateException, SQLExcep
Map queryNamedArgs = null;
int max = retrieveMaxValue(arguments);
int offset = retrieveOffsetValue(arguments);
+ boolean useCache = useCache(arguments);
if (arguments.length > 1) {
if (arguments[1] instanceof Collection) {
queryArgs = GrailsClassUtils.collectionToObjectArray((Collection) arguments[1]);
@@ -148,7 +149,7 @@ public Object doInHibernate(Session session) throws HibernateException, SQLExcep
+ queryNamedArgs.toString());
String stringKey = (String) entry.getKey();
// Won't try to bind these parameters since they are processed separately
- if( GrailsHibernateUtil.ARGUMENT_MAX.equals(stringKey) || GrailsHibernateUtil.ARGUMENT_OFFSET.equals(stringKey) ) continue;
+ if( GrailsHibernateUtil.ARGUMENT_MAX.equals(stringKey) || GrailsHibernateUtil.ARGUMENT_OFFSET.equals(stringKey) || GrailsHibernateUtil.ARGUMENT_CACHE.equals(stringKey)) continue;
Object value = entry.getValue();
if(value == null) {
q.setParameter(stringKey, null);
@@ -170,10 +171,19 @@ else if (value instanceof CharSequence) {
if (offset > 0) {
q.setFirstResult(offset);
}
+ q.setCacheable(useCache);
return q.list();
}
+ private boolean useCache(Object[] arguments) {
+ boolean useCache = false;
+ if(arguments.length > 1 && arguments[arguments.length - 1] instanceof Map) {
+ useCache = retrieveBoolean(arguments[arguments.length - 1], GrailsHibernateUtil.ARGUMENT_CACHE);
+ }
+ return useCache;
+ }
+
private int retrieveMaxValue(Object[] arguments) {
int result = -1;
if( arguments.length > 1) {
@@ -207,6 +217,13 @@ private int retrieveOffsetValue(Object[] arguments) {
return result;
}
+ private boolean retrieveBoolean(Object param, String key) {
+ boolean value = false;
+ if(isMapWithValue(param, key)) {
+ value = converter.convertIfNecessary(((Map)param).get(key), Boolean.class);
+ }
+ return value;
+ }
private int retrieveInt( Object param, String key ) {
if( isMapWithValue(param, key) ) {
Integer convertedParam = converter.convertIfNecessary(((Map) param).get(key),Integer.class);
@@ -49,6 +49,7 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean {
def useRegex // standard regex
def invertRule // invert rule
def useRegexFind // use find instead of match
+ def dependsOn = [] // any filters that need to be processed before this one
void afterPropertiesSet() {
def scope = filterConfig.scope
@@ -211,4 +212,4 @@ class FilterToHandlerAdapter implements HandlerInterceptor, InitializingBean {
String toString() {
return "FilterToHandlerAdapter[$filterConfig, $configClass]"
}
-}
+}
@@ -16,6 +16,7 @@
package org.codehaus.groovy.grails.plugins.web.filters
import grails.util.GrailsUtil
+import java.util.ArrayList
import org.apache.commons.logging.LogFactory
@@ -129,17 +130,107 @@ class FiltersGrailsPlugin {
log.info "reloadFilters"
def filterConfigs = application.getArtefacts(TYPE)
def handlers = []
- for (c in filterConfigs) {
+
+ def sortedFilterConfigs = [] // the new ordered filter list
+ def list = new ArrayList(Arrays.asList(filterConfigs))
+ def addedDeps = [:]
+
+ while (list.size() > 0) {
+ def filtersAdded = 0;
+
+ log.debug("Current filter order is '"+filterConfigs.join(",")+"'")
+
+ for (Iterator iter = list.iterator(); iter.hasNext(); ) {
+ def c = iter.next();
+ def filterClass = applicationContext.getBean("${c.fullName}Class")
+ def bean = applicationContext.getBean(c.fullName)
+ log.debug("Processing filter '${bean.class.name}'")
+
+ def dependsOn = null
+ if (bean.metaClass.hasProperty(bean, "dependsOn")) {
+ dependsOn = bean.dependsOn
+ log.debug(" depends on '"+dependsOn.join(",")+"'")
+ }
+
+ if (dependsOn != null) {
+ // check dependencies to see if all the filters it depends on are already in the list
+ log.debug(" Checking filter '${bean.class.name}' dependencies (${dependsOn.size()})")
+
+ def failedDep = false;
+ for (dep in dependsOn) {
+ log.debug(" Checking filter '${bean.class.name}' dependencies: ${dep.name}")
+ //if (sortedFilterConfigs.find{def b = applicationContext.getBean(it.fullName); b.class == dep} == null) {
+ if (!addedDeps.containsKey(dep)) {
+ // dep not in the list yet, we need to skip adding this to the list for now
+ log.debug(" Skipped Filter '${bean.class.name}', since dependency '${dep.name}' not yet added")
+ failedDep = true
+ break
+ } else {
+ log.debug(" Filter '${bean.class.name}' dependency '${dep.name}' already added")
+ }
+ }
+
+ if (failedDep) {
+ // move on to next dependency
+ continue
+ }
+ }
+
+ log.debug(" Adding filter '${bean.class.name}', since all dependencies have been added")
+ sortedFilterConfigs.add(c)
+ addedDeps.put(bean.class, null);
+ iter.remove()
+ filtersAdded++
+ }
+
+ // if we didn't add any filters this iteration, then we have a cyclical dep problem
+ if (filtersAdded == 0) {
+ // we have a cyclical dependency, warn the user and load in the order they appeared originally
+ log.warn(":::::::::::::::::::::::::::::::::::::::::::::::")
+ log.warn(":: Cyclical Filter dependencies detected ::")
+ log.warn(":: Continuing with original filter order ::")
+ log.warn(":::::::::::::::::::::::::::::::::::::::::::::::")
+ for (c in list) {
+ def filterClass = applicationContext.getBean("${c.fullName}Class")
+ def bean = applicationContext.getBean(c.fullName)
+
+ // display this as a cyclical dep
+ log.warn(":: Filter "+bean.class.name)
+ def dependsOn = null
+ if (bean.metaClass.hasProperty(bean, "dependsOn")) {
+ dependsOn = bean.dependsOn
+ for (dep in dependsOn) {
+ log.warn(":: depends on "+dep.name)
+ }
+ } else {
+ // we should only have items left in the list with deps, so this should never happen
+ // but a wise man once said...check for true, false and otherwise...just in case
+ log.warn(":: Problem while resolving cyclical dependencies.")
+ log.warn(":: Unable to resolve dependency hierarchy.")
+ }
+ log.warn(":::::::::::::::::::::::::::::::::::::::::::::::")
+ }
+ break
+ // if we have processed all the filters, we are done
+ } else if (sortedFilterConfigs.size() == filterConfigs.size()) {
+ log.debug("Filter dependency ordering complete")
+ break
+ }
+ }
+
+ // add the filter configs in dependency sorted order
+ log.debug("Resulting handlers:")
+ for (c in sortedFilterConfigs) {
def filterClass = applicationContext.getBean("${c.fullName}Class")
def bean = applicationContext.getBean(c.fullName)
for (filterConfig in filterClass.getConfigs(bean)) {
def handlerAdapter = new FilterToHandlerAdapter(filterConfig:filterConfig, configClass:bean)
handlerAdapter.afterPropertiesSet()
handlers << handlerAdapter
+ log.debug(" $handlerAdapter")
}
}
- log.debug("resulting handlers: $handlers")
applicationContext.getBean('filterInterceptor').handlers = handlers
}
}
@@ -35,6 +35,7 @@
tagRegistry.registerTag(RenderInputTag.TAG_NAME, RenderInputTag.class);
tagRegistry.registerTag(GroovyEachTag.TAG_NAME, GroovyEachTag.class);
tagRegistry.registerTag(GroovyIfTag.TAG_NAME, GroovyIfTag.class);
+ tagRegistry.registerTag(GroovyUnlessTag.TAG_NAME, GroovyUnlessTag.class);
tagRegistry.registerTag(GroovyElseTag.TAG_NAME, GroovyElseTag.class);
tagRegistry.registerTag(GroovyElseIfTag.TAG_NAME, GroovyElseIfTag.class);
tagRegistry.registerTag(GroovyFindAllTag.TAG_NAME, GroovyFindAllTag.class);
Oops, something went wrong.

0 comments on commit c413d4b

Please sign in to comment.