GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / src / persistence / org / codehaus / groovy / grails / orm / hibernate / metaclass / AbstractDynamicPersistentMethod.java
blob2557a1f9abc171691fe2cfb31e2242bd56dd4c2f
1 /*
2 * Copyright 2004-2005 the original author or authors.
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.orm.hibernate.metaclass;
18 import org.codehaus.groovy.grails.commons.metaclass.AbstractDynamicMethodInvocation;
19 import org.hibernate.SessionFactory;
20 import org.springframework.orm.hibernate3.HibernateTemplate;
21 import org.springframework.util.Assert;
23 import java.util.regex.Pattern;
25 /**
28 * @author Steven Devijver
29 * @since Aug 7, 2005
31 public abstract class AbstractDynamicPersistentMethod extends
32 AbstractDynamicMethodInvocation {
34 private SessionFactory sessionFactory = null;
35 private ClassLoader classLoader = null;
37 public AbstractDynamicPersistentMethod(Pattern pattern, SessionFactory sessionFactory, ClassLoader classLoader) {
38 super(pattern);
39 this.sessionFactory = sessionFactory;
40 this.classLoader = classLoader;
43 protected HibernateTemplate getHibernateTemplate() {
44 Assert.notNull(sessionFactory, "Session factory is required!");
45 return new HibernateTemplate(this.sessionFactory);
48 public Object invoke(Object target, String methodName, Object[] arguments) {
49 ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
50 Thread.currentThread().setContextClassLoader(this.classLoader);
51 Object returnValue = doInvokeInternal(target, arguments);
52 Thread.currentThread().setContextClassLoader(originalClassLoader);
53 return returnValue;
56 protected abstract Object doInvokeInternal(Object target, Object[] arguments);