Skip to content

Commit b6002bd

Browse files
committed
cleanup
1 parent 68099c0 commit b6002bd

18 files changed

+988
-935
lines changed

src/java/org/codehaus/groovy/grails/orm/hibernate/ConfigurableLocalSessionFactoryBean.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* Copyright 2004-2005 the original author or authors.
2-
*
2+
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
6-
*
6+
*
77
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
8+
*
99
* Unless required by applicable law or agreed to in writing, software
1010
* distributed under the License is distributed on an "AS IS" BASIS,
1111
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
14-
*/
14+
*/
1515
package org.codehaus.groovy.grails.orm.hibernate;
1616

1717
import groovy.lang.GroovySystem;
@@ -84,9 +84,9 @@ public GrailsApplication getGrailsApplication() {
8484
public void setGrailsApplication(GrailsApplication grailsApplication) {
8585
this.grailsApplication = grailsApplication;
8686
}
87-
87+
8888
/**
89-
* Overrides default behaviour to allow for a configurable configuration class
89+
* Overrides default behaviour to allow for a configurable configuration class.
9090
*/
9191
@Override
9292
protected Configuration newConfiguration() {
@@ -97,7 +97,7 @@ protected Configuration newConfiguration() {
9797
}
9898
catch (Throwable e) {
9999
// probably not Java 5 or missing some annotation jars, use default
100-
configClass = DefaultGrailsDomainConfiguration.class;
100+
configClass = DefaultGrailsDomainConfiguration.class;
101101
}
102102
}
103103
Object config = BeanUtils.instantiateClass(configClass);
@@ -138,7 +138,7 @@ private String getCauseMessage(HibernateException e) {
138138
Throwable cause = e.getCause();
139139
if (cause instanceof InvocationTargetException) {
140140
cause = ((InvocationTargetException)cause).getTargetException();
141-
}
141+
}
142142
return cause.getMessage();
143143
}
144144

src/java/org/codehaus/groovy/grails/orm/hibernate/metaclass/AbstractDynamicPersistentMethod.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import groovy.lang.GroovySystem;
1919
import groovy.lang.MetaClass;
20+
21+
import java.util.regex.Pattern;
22+
2023
import org.codehaus.groovy.grails.commons.metaclass.AbstractDynamicMethodInvocation;
2124
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil;
2225
import org.hibernate.SessionFactory;
@@ -26,17 +29,10 @@
2629
import org.springframework.validation.Errors;
2730
import org.springframework.validation.FieldError;
2831

29-
import java.util.List;
30-
import java.util.regex.Pattern;
31-
3232
/**
33-
*
34-
*
3533
* @author Steven Devijver
36-
* @since Aug 7, 2005
3734
*/
38-
public abstract class AbstractDynamicPersistentMethod extends
39-
AbstractDynamicMethodInvocation {
35+
public abstract class AbstractDynamicPersistentMethod extends AbstractDynamicMethodInvocation {
4036

4137
public static final String ERRORS_PROPERTY = "errors";
4238

@@ -45,23 +41,25 @@ public abstract class AbstractDynamicPersistentMethod extends
4541

4642
public AbstractDynamicPersistentMethod(Pattern pattern, SessionFactory sessionFactory, ClassLoader classLoader) {
4743
super(pattern);
48-
this.classLoader = classLoader;
4944
Assert.notNull(sessionFactory, "Session factory is required!");
50-
hibernateTemplate=new HibernateTemplate(sessionFactory);
45+
this.classLoader = classLoader;
46+
hibernateTemplate = new HibernateTemplate(sessionFactory);
5147
hibernateTemplate.setCacheQueries(GrailsHibernateUtil.isCacheQueriesByDefault());
5248
}
5349

5450
protected HibernateTemplate getHibernateTemplate() {
55-
return hibernateTemplate;
51+
return hibernateTemplate;
5652
}
5753

54+
@Override
5855
public Object invoke(Object target, String methodName, Object[] arguments) {
5956
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
6057
try {
6158
Thread.currentThread().setContextClassLoader(this.classLoader);
6259
return doInvokeInternal(target, arguments);
63-
} finally {
64-
Thread.currentThread().setContextClassLoader(originalClassLoader);
60+
}
61+
finally {
62+
Thread.currentThread().setContextClassLoader(originalClassLoader);
6563
}
6664
}
6765

@@ -74,18 +72,13 @@ public Object invoke(Object target, String methodName, Object[] arguments) {
7472
* @param target The target object
7573
*/
7674
protected void setObjectToReadOnly(final Object target) {
77-
SessionFactory sessionFactory = getHibernateTemplate().getSessionFactory();
78-
79-
GrailsHibernateUtil.setObjectToReadyOnly(target, sessionFactory);
75+
GrailsHibernateUtil.setObjectToReadyOnly(target, getHibernateTemplate().getSessionFactory());
8076
}
8177

8278
protected void setObjectToReadWrite(final Object target) {
83-
SessionFactory sessionFactory = getHibernateTemplate().getSessionFactory();
84-
85-
GrailsHibernateUtil.setObjectToReadWrite(target, sessionFactory);
79+
GrailsHibernateUtil.setObjectToReadWrite(target, getHibernateTemplate().getSessionFactory());
8680
}
8781

88-
8982
/**
9083
* Initializes the Errors property on target. The target will be assigned a new
9184
* Errors property. If the target contains any binding errors, those binding
@@ -101,17 +94,14 @@ protected Errors setupErrorsProperty(Object target) {
10194
Errors errors = new BeanPropertyBindingResult(target, target.getClass().getName());
10295

10396
Errors originalErrors = (Errors) mc.getProperty(target, ERRORS_PROPERTY);
104-
List originalFieldErrors = originalErrors.getFieldErrors();
105-
for(Object o : originalFieldErrors) {
106-
FieldError fe = (FieldError) o;
107-
if(fe.isBindingFailure()) {
97+
for (Object o : originalErrors.getFieldErrors()) {
98+
FieldError fe = (FieldError)o;
99+
if (fe.isBindingFailure()) {
108100
errors.rejectValue(fe.getField(), fe.getCode(), fe.getArguments(), fe.getDefaultMessage());
109101
}
110102
}
111103

112104
mc.setProperty(target, ERRORS_PROPERTY, errors);
113105
return errors;
114106
}
115-
116-
117107
}

0 commit comments

Comments
 (0)