diff --git a/modules/dcache/pom.xml b/modules/dcache/pom.xml index 04bcb017543..e0ec6f7f7e6 100644 --- a/modules/dcache/pom.xml +++ b/modules/dcache/pom.xml @@ -220,6 +220,7 @@ org.aspectj aspectjweaver + runtime @@ -303,6 +304,11 @@ + + org.codehaus.mojo + aspectj-maven-plugin + + org.datanucleus datanucleus-maven-plugin diff --git a/modules/dcache/src/main/aspect/org/dcache/util/aspects/PerInstanceAnnotationTransactionAspect.aj b/modules/dcache/src/main/aspect/org/dcache/util/aspects/PerInstanceAnnotationTransactionAspect.aj new file mode 100644 index 00000000000..98fc0ceba15 --- /dev/null +++ b/modules/dcache/src/main/aspect/org/dcache/util/aspects/PerInstanceAnnotationTransactionAspect.aj @@ -0,0 +1,86 @@ +/* This class incorporates code from + * + * org.springframework.transaction.aspectj.AnnotationTransactionAspect + * + * which is subject to the following license: + * + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dcache.util.aspects; + +import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.aspectj.AbstractTransactionAspect; + +/** + * Advice @Transactional classes and methods with transaction manager + * controlled transactions. + * + * Similar to AnnotationTransactionAspect, but in contrast to AnnotationTransactionAspect + * this class is not a singleton. Thus it can be used in the presence of multiple + * Spring ApplicationContext instances. + * + * @see org.dcache.util.aspects.PerInstanceAnnotationTransactionBeanPostProcessor + */ +public aspect PerInstanceAnnotationTransactionAspect extends AbstractTransactionAspect perthis(instantiationOfTransactionalClass()) +{ + public PerInstanceAnnotationTransactionAspect() { + super(new AnnotationTransactionAttributeSource(false)); + } + + /** + * Matches the execution of any public method in a type with the Transactional + * annotation, or any subtype of a type with the Transactional annotation. + */ + private pointcut executionOfAnyPublicMethodInAtTransactionalType() : + execution(public * ((@Transactional *)+).*(..)) && within(@Transactional *); + + /** + * Matches the execution of any method with the Transactional annotation. + */ + private pointcut executionOfTransactionalMethod() : + execution(@Transactional * *(..)); + + /** + * Definition of pointcut from super aspect - matched join points + * will have Spring transaction management applied. + */ + protected pointcut transactionalMethodExecution(Object txObject) : + (executionOfAnyPublicMethodInAtTransactionalType() + || executionOfTransactionalMethod() ) + && this(txObject); + + /** + * Marker interface to tag classes that have methods subject to transaction demarcation. + * + * The marker is needed so we can bind the perthis Aspect instantiation to the constructor + * invocation. This in turn is needed to let PerInstanceAnnotationTransactionBeanPostProcessor + * inject the transaction manager during the Spring configuration phase. + */ + public interface HasTransactional {} // marker + + /** + * Matches any constructor of classes implementing the HasTransactional marker. + */ + pointcut instantiationOfTransactionalClass() : + execution(HasTransactional+.new(..)); + + /** + * Make any class that has transactional methods implement HasTransactional. + */ + declare parents : hasmethod(@Transactional * *(..)) implements HasTransactional; + declare parents : @Transactional * implements HasTransactional; +} \ No newline at end of file diff --git a/modules/dcache/src/main/aspect/org/dcache/util/aspects/PerInstanceAnnotationTransactionBeanPostProcessor.java b/modules/dcache/src/main/aspect/org/dcache/util/aspects/PerInstanceAnnotationTransactionBeanPostProcessor.java new file mode 100644 index 00000000000..e4ce1ef8b08 --- /dev/null +++ b/modules/dcache/src/main/aspect/org/dcache/util/aspects/PerInstanceAnnotationTransactionBeanPostProcessor.java @@ -0,0 +1,61 @@ +/* dCache - http://www.dcache.org/ + * + * Copyright (C) 2014 Deutsches Elektronen-Synchrotron + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.dcache.util.aspects; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.transaction.PlatformTransactionManager; + +/** + * BeanPostProcessor to configure PerInstanceAnnotationTransactionAspect instances. + */ +public class PerInstanceAnnotationTransactionBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware +{ + private PlatformTransactionManager txManager; + private BeanFactory beanFactory; + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException + { + if (bean instanceof PerInstanceAnnotationTransactionAspect.HasTransactional) { + PerInstanceAnnotationTransactionAspect aspect = PerInstanceAnnotationTransactionAspect.aspectOf(bean); + aspect.setTransactionManager(txManager); + aspect.setBeanFactory(beanFactory); + } + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException + { + return bean; + } + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException + { + this.beanFactory = beanFactory; + } + + public void setTransactionManager(PlatformTransactionManager txManager) + { + this.txManager = txManager; + } +} diff --git a/modules/dcache/src/main/resources/META-INF/aop.xml b/modules/dcache/src/main/resources/META-INF/aop.xml index c03559ebe99..868fa0472fd 100644 --- a/modules/dcache/src/main/resources/META-INF/aop.xml +++ b/modules/dcache/src/main/resources/META-INF/aop.xml @@ -3,9 +3,11 @@ + - + + diff --git a/modules/dcache/src/main/resources/org/dcache/pinmanager/pinmanager.xml b/modules/dcache/src/main/resources/org/dcache/pinmanager/pinmanager.xml index df06e0b3e40..f2274f8566f 100644 --- a/modules/dcache/src/main/resources/org/dcache/pinmanager/pinmanager.xml +++ b/modules/dcache/src/main/resources/org/dcache/pinmanager/pinmanager.xml @@ -1,11 +1,9 @@ @@ -191,5 +189,7 @@ - + + + diff --git a/modules/srm-server/src/main/aspect/org/dcache/srm/aspects/EofExceptionAspect.aj b/modules/srm-server/src/main/aspect/org/dcache/srm/aspects/EofExceptionAspect.aj index d369c283ed1..1f29efc4f00 100644 --- a/modules/srm-server/src/main/aspect/org/dcache/srm/aspects/EofExceptionAspect.aj +++ b/modules/srm-server/src/main/aspect/org/dcache/srm/aspects/EofExceptionAspect.aj @@ -1,3 +1,20 @@ +/* dCache - http://www.dcache.org/ + * + * Copyright (C) 2014 Deutsches Elektronen-Synchrotron + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ package org.dcache.srm.aspects; import java.io.EOFException; diff --git a/packages/pom.xml b/packages/pom.xml index 66dbaf9f955..930c39f99a4 100644 --- a/packages/pom.xml +++ b/packages/pom.xml @@ -149,10 +149,10 @@ runtime - + org.apache.wicket wicket-core diff --git a/pom.xml b/pom.xml index b1bdeb8bb6b..2c8a1e7c168 100644 --- a/pom.xml +++ b/pom.xml @@ -895,6 +895,12 @@ ${source.version} ${target.version} ${source.version} + true + + + ${project.basedir}/src/main/aspect + +