Skip to content

Commit 49fa36e

Browse files
Merge branch '2.1.x' into 2.2.x
Conflicts: build.gradle build.properties grails-test-suite-uber/src/test/groovy/grails/util/GrailsUtilTests.java grails-web/src/main/groovy/org/codehaus/groovy/grails/web/binding/DefaultASTDatabindingHelper.java grails-web/src/test/groovy/org/codehaus/groovy/grails/web/binding/DefaultASTDatabindingHelperSpec.groovy
2 parents 8d96388 + 3ddb412 commit 49fa36e

File tree

7 files changed

+103
-26
lines changed

7 files changed

+103
-26
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2013 SpringSource
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.codehaus.groovy.grails.support;
17+
18+
public interface ParticipatingInterceptor extends PersistenceContextInterceptor {
19+
20+
void setParticipate(boolean participate);
21+
22+
boolean getParticipate();
23+
}

grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/support/AggregatePersistenceContextInterceptor.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020

2121
import org.codehaus.groovy.grails.commons.GrailsDomainClassProperty;
22+
import org.codehaus.groovy.grails.support.ParticipatingInterceptor;
2223
import org.codehaus.groovy.grails.support.PersistenceContextInterceptor;
2324
import org.hibernate.SessionFactory;
2425
import org.springframework.beans.factory.InitializingBean;
@@ -28,7 +29,7 @@
2829
/**
2930
* @author Burt Beckwith
3031
*/
31-
public class AggregatePersistenceContextInterceptor implements PersistenceContextInterceptor, InitializingBean, ApplicationContextAware {
32+
public class AggregatePersistenceContextInterceptor implements ParticipatingInterceptor, InitializingBean, ApplicationContextAware {
3233

3334
private List<PersistenceContextInterceptor> interceptors = new ArrayList<PersistenceContextInterceptor>();
3435
private List<String> dataSourceNames = new ArrayList<String>();
@@ -94,6 +95,26 @@ public void setReadWrite() {
9495
}
9596
}
9697

98+
public void setParticipate(boolean flag) {
99+
for (PersistenceContextInterceptor interceptor : interceptors) {
100+
if (interceptor instanceof ParticipatingInterceptor) {
101+
((ParticipatingInterceptor)interceptor).setParticipate(flag);
102+
}
103+
}
104+
}
105+
106+
public boolean getParticipate() {
107+
for (PersistenceContextInterceptor interceptor : interceptors) {
108+
if (interceptor instanceof ParticipatingInterceptor) {
109+
if (((ParticipatingInterceptor)interceptor).getParticipate()) {
110+
// true at least one is true
111+
return true;
112+
}
113+
}
114+
}
115+
return false;
116+
}
117+
97118
/**
98119
* Dependency injection for the datasource names.
99120
* @param names the names

grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/support/HibernatePersistenceContextInterceptor.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.codehaus.groovy.grails.lifecycle.ShutdownOperations;
2222
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil;
2323
import org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod;
24-
import org.codehaus.groovy.grails.support.PersistenceContextInterceptor;
24+
import org.codehaus.groovy.grails.support.ParticipatingInterceptor;
2525
import org.hibernate.FlushMode;
2626
import org.hibernate.Session;
2727
import org.hibernate.SessionFactory;
@@ -33,7 +33,7 @@
3333
* @author Graeme Rocher
3434
* @since 0.4
3535
*/
36-
public class HibernatePersistenceContextInterceptor implements PersistenceContextInterceptor {
36+
public class HibernatePersistenceContextInterceptor implements ParticipatingInterceptor {
3737

3838
private static final Log LOG = LogFactory.getLog(HibernatePersistenceContextInterceptor.class);
3939
private SessionFactory sessionFactory;
@@ -136,6 +136,15 @@ public void init() {
136136
}
137137
}
138138

139+
public void setParticipate(boolean flag) {
140+
participate.set(flag);
141+
}
142+
143+
public boolean getParticipate() {
144+
Boolean ret = participate.get();
145+
return (ret != null) ? ret : false;
146+
}
147+
139148
private Session getSession() {
140149
return getSession(true);
141150
}
@@ -174,13 +183,4 @@ private int decNestingCount() {
174183
nestingCount.set(value);
175184
return value;
176185
}
177-
178-
private void setParticipate(boolean flag) {
179-
participate.set(flag);
180-
}
181-
182-
private boolean getParticipate() {
183-
Boolean ret = participate.get();
184-
return (ret != null) ? ret : false;
185-
}
186186
}

grails-plugin-tomcat/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def tomcatVersion = "7.0.30"
1+
def tomcatVersion = "7.0.39"
22
dependencies {
33
compile "org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion"
44
compile "org.apache.tomcat.embed:tomcat-embed-logging-log4j:$tomcatVersion"

grails-web/src/main/groovy/org/codehaus/groovy/grails/web/binding/DefaultASTDatabindingHelper.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class DefaultASTDatabindingHelper implements ASTDatabindingHelper {
3030
public static final String BINDABLE_CONSTRAINT_NAME = "bindable";
3131

3232
public static final String DEFAULT_DATABINDING_WHITELIST = "$defaultDatabindingWhiteList";
33+
public static final String NO_BINDABLE_PROPERTIES = "$_NO_BINDABLE_PROPERTIES_$";
3334

3435
private static Map<ClassNode, Set<String>> CLASS_NODE_TO_WHITE_LIST_PROPERTY_NAMES = new HashMap<ClassNode, Set<String>>();
3536

@@ -84,21 +85,25 @@ private void addDefaultDatabindingWhitelistField(final SourceUnit sourceUnit, fi
8485
final Set<String> propertyNamesToIncludeInWhiteList = getPropertyNamesToIncludeInWhiteList(sourceUnit, classNode);
8586

8687
final ListExpression listExpression = new ListExpression();
87-
for (String propertyName : propertyNamesToIncludeInWhiteList) {
88-
listExpression.addExpression(new ConstantExpression(propertyName));
88+
if (propertyNamesToIncludeInWhiteList.size() > 0) {
89+
for (String propertyName : propertyNamesToIncludeInWhiteList) {
90+
listExpression.addExpression(new ConstantExpression(propertyName));
8991

90-
final FieldNode declaredField = getDeclaredFieldInInheritanceHierarchy(classNode, propertyName);
91-
boolean isSimpleType = false;
92-
if (declaredField != null) {
93-
final ClassNode type = declaredField.getType();
94-
if (type != null) {
95-
isSimpleType = SIMPLE_TYPES.contains(type);
92+
final FieldNode declaredField = getDeclaredFieldInInheritanceHierarchy(classNode, propertyName);
93+
boolean isSimpleType = false;
94+
if (declaredField != null) {
95+
final ClassNode type = declaredField.getType();
96+
if (type != null) {
97+
isSimpleType = SIMPLE_TYPES.contains(type);
98+
}
99+
}
100+
if (!isSimpleType) {
101+
listExpression.addExpression(new ConstantExpression(propertyName + "_*"));
102+
listExpression.addExpression(new ConstantExpression(propertyName + ".*"));
96103
}
97104
}
98-
if (!isSimpleType) {
99-
listExpression.addExpression(new ConstantExpression(propertyName + "_*"));
100-
listExpression.addExpression(new ConstantExpression(propertyName + ".*"));
101-
}
105+
} else {
106+
listExpression.addExpression(new ConstantExpression(NO_BINDABLE_PROPERTIES));
102107
}
103108

104109
classNode.addField(DEFAULT_DATABINDING_WHITELIST,

grails-web/src/main/groovy/org/codehaus/groovy/grails/web/sitemesh/GrailsPageFilter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import org.codehaus.groovy.grails.commons.GrailsApplication;
3333
import org.codehaus.groovy.grails.support.NullPersistentContextInterceptor;
34+
import org.codehaus.groovy.grails.support.ParticipatingInterceptor;
3435
import org.codehaus.groovy.grails.support.PersistenceContextInterceptor;
3536
import org.codehaus.groovy.grails.web.util.WebUtils;
3637
import org.springframework.web.context.WebApplicationContext;
@@ -176,6 +177,11 @@ public void doFilter(ServletRequest rq, ServletResponse rs, FilterChain chain)
176177
request.setAttribute(ALREADY_APPLIED_KEY, null);
177178
}
178179
if (persistenceInterceptor.isOpen()) {
180+
if (persistenceInterceptor instanceof ParticipatingInterceptor) {
181+
// to ensure that it will close the session in the destroy() call
182+
((ParticipatingInterceptor)persistenceInterceptor).setParticipate(false);
183+
}
184+
179185
persistenceInterceptor.destroy();
180186
}
181187
}

grails-web/src/test/groovy/org/codehaus/groovy/grails/web/binding/DefaultASTDatabindingHelperSpec.groovy

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class DefaultASTDatabindingHelperSpec extends Specification {
1919
static setterGetterClass
2020
static dateBindingClass
2121
static classWithHasMany
22+
static classWithNoBindableProperties
2223

2324
def setupSpec() {
2425
final gcl = new GrailsAwareClassLoader()
@@ -111,11 +112,20 @@ class DefaultASTDatabindingHelperSpec extends Specification {
111112
}
112113
}
113114
''')
115+
classWithNoBindableProperties = gcl.parseClass('''
116+
class ClassWithNoBindableProperties {
117+
String firstName
118+
String lastName
119+
static constraints = {
120+
firstName bindable: false
121+
lastName bindable: false
122+
}
123+
}''')
114124

115125
// there must be a request bound in order for the structured date editor to be registered
116126
GrailsWebUtil.bindMockWebRequest()
117127
}
118-
128+
119129
void 'Test class with hasMany'() {
120130
when:
121131
final whiteListField = classWithHasMany.getDeclaredField(DefaultASTDatabindingHelper.DEFAULT_DATABINDING_WHITELIST)
@@ -191,6 +201,18 @@ class DefaultASTDatabindingHelperSpec extends Specification {
191201
'person.*' in whiteList
192202
'person_*' in whiteList
193203
}
204+
205+
void 'Test binding to a class that has no bindable properties'() {
206+
given:
207+
def obj = classWithNoBindableProperties.newInstance()
208+
209+
when:
210+
obj.properties = [firstName: 'First Name', lastName: 'Last Name']
211+
212+
then:
213+
obj.firstName == null
214+
obj.lastName == null
215+
}
194216

195217
void 'Test that binding respects the generated white list'() {
196218
given:

0 commit comments

Comments
 (0)