Commits

Takumi IINO committed aa43814

rename: from T4TxAttributeCustomizer to NarrowTxAttributeCustomizer

  • Participants
  • Parent commits 3c6b344

Comments (0)

Files changed (4)

File sastruts-oreo/src/main/java/jp/troter/seasar/struts/customizer/NarrowTxAttributeCustomizer.java

+package jp.troter.seasar.struts.customizer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+import org.seasar.framework.container.ComponentDef;
+import org.seasar.framework.container.customizer.TxAttributeCustomizer;
+import org.seasar.framework.container.factory.AspectDefFactory;
+import org.seasar.framework.util.StringUtil;
+import org.seasar.framework.util.tiger.CollectionsUtil;
+
+/**
+ * 特定のアノテーションが設定されていた場合のみトランザクション制御を有効にします。
+ */
+public class NarrowTxAttributeCustomizer extends TxAttributeCustomizer {
+
+    protected Set<Class<? extends Annotation>> enableTxAnnotationClasses = CollectionsUtil.newHashSet();
+
+    public Set<Class<? extends Annotation>> getEnableTxAnnotationClasses() {
+        return Collections.unmodifiableSet(enableTxAnnotationClasses);
+    }
+
+    /**
+     * トランザクション制御を有効にするアノテーションを追加します。
+     * @param enableTxAnnocationClass
+     */
+    public void addEnableTxAnnotationClasses(Class<? extends Annotation> enableTxAnnotationClass) {
+        enableTxAnnotationClasses.add(enableTxAnnotationClass);
+    }
+
+    /**
+     * トランザクション制御を有効にするアノテーションが適応されたメソッドか
+     * @param method
+     * @return
+     */
+    public boolean isEnableTx(Method method) {
+        for (Class<? extends Annotation> enableTxAnnotationClass : enableTxAnnotationClasses) {
+            if (method.getAnnotation(enableTxAnnotationClass) != null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    protected void doCustomize(ComponentDef componentDef) {
+        final Class<?> componentClass = componentDef.getComponentClass();
+        final TransactionAttribute classAttribute = componentClass
+                .getAnnotation(TransactionAttribute.class);
+        final TransactionAttributeType classAttributeType = classAttribute != null ? classAttribute
+                .value()
+                : defaultAttributeType;
+        for (final Method method : componentClass.getMethods()) {
+            if (method.isSynthetic() || method.isBridge()) {
+                continue;
+            }
+            if (method.getDeclaringClass() == Object.class) {
+                continue;
+            }
+            if (! isEnableTx(method)) {
+                continue;
+            }
+            final TransactionAttribute methodAttribute = method
+                    .getAnnotation(TransactionAttribute.class);
+            final TransactionAttributeType methodAttributeType = methodAttribute != null ? methodAttribute
+                    .value()
+                    : classAttributeType;
+            final String interceptorName = txInterceptors
+                    .get(methodAttributeType);
+            if (!StringUtil.isEmpty(interceptorName)) {
+                componentDef.addAspectDef(AspectDefFactory.createAspectDef(
+                        interceptorName, method));
+            }
+        }
+    }
+}

File sastruts-oreo/src/main/java/jp/troter/seasar/struts/customizer/T4TxAttributeCustomizer.java

-package jp.troter.seasar.struts.customizer;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.Set;
-
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-
-import org.seasar.framework.container.ComponentDef;
-import org.seasar.framework.container.customizer.TxAttributeCustomizer;
-import org.seasar.framework.container.factory.AspectDefFactory;
-import org.seasar.framework.util.StringUtil;
-import org.seasar.framework.util.tiger.CollectionsUtil;
-
-/**
- * 特定のアノテーションが設定されていた場合のみトランザクション制御を有効にします。
- */
-public class T4TxAttributeCustomizer extends TxAttributeCustomizer {
-
-    protected Set<Class<? extends Annotation>> enableTxAnnotationClasses = CollectionsUtil.newHashSet();
-
-    public Set<Class<? extends Annotation>> getEnableTxAnnotationClasses() {
-        return Collections.unmodifiableSet(enableTxAnnotationClasses);
-    }
-
-    /**
-     * トランザクション制御を有効にするアノテーションを追加します。
-     * @param enableTxAnnocationClass
-     */
-    public void addEnableTxAnnotationClasses(Class<? extends Annotation> enableTxAnnotationClass) {
-        enableTxAnnotationClasses.add(enableTxAnnotationClass);
-    }
-
-    /**
-     * トランザクション制御を有効にするアノテーションが適応されたメソッドか
-     * @param method
-     * @return
-     */
-    public boolean isEnableTx(Method method) {
-        for (Class<? extends Annotation> enableTxAnnotationClass : enableTxAnnotationClasses) {
-            if (method.getAnnotation(enableTxAnnotationClass) != null) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    protected void doCustomize(ComponentDef componentDef) {
-        final Class<?> componentClass = componentDef.getComponentClass();
-        final TransactionAttribute classAttribute = componentClass
-                .getAnnotation(TransactionAttribute.class);
-        final TransactionAttributeType classAttributeType = classAttribute != null ? classAttribute
-                .value()
-                : defaultAttributeType;
-        for (final Method method : componentClass.getMethods()) {
-            if (method.isSynthetic() || method.isBridge()) {
-                continue;
-            }
-            if (method.getDeclaringClass() == Object.class) {
-                continue;
-            }
-            if (! isEnableTx(method)) {
-                continue;
-            }
-            final TransactionAttribute methodAttribute = method
-                    .getAnnotation(TransactionAttribute.class);
-            final TransactionAttributeType methodAttributeType = methodAttribute != null ? methodAttribute
-                    .value()
-                    : classAttributeType;
-            final String interceptorName = txInterceptors
-                    .get(methodAttributeType);
-            if (!StringUtil.isEmpty(interceptorName)) {
-                componentDef.addAspectDef(AspectDefFactory.createAspectDef(
-                        interceptorName, method));
-            }
-        }
-    }
-}

File sastruts-oreo/src/test/java/jp/troter/seasar/struts/customizer/NarrowTxAttributeCustomizerTest.java

+package jp.troter.seasar.struts.customizer;
+
+import static org.junit.Assert.*;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class NarrowTxAttributeCustomizerTest extends NarrowTxAttributeCustomizer {
+
+    NarrowTxAttributeCustomizer c;
+
+    @Before
+    public void before() throws Exception {
+        c = new NarrowTxAttributeCustomizer();
+    }
+
+    @Test
+    public void testAddEnableTxAnnotationClasses() {
+        c.addEnableTxAnnotationClasses(EnableTxA.class);
+        Set<Class<? extends Annotation>> enableTxAnnotationClasses = c.getEnableTxAnnotationClasses();
+        assertTrue(enableTxAnnotationClasses.contains(EnableTxA.class));
+    }
+
+    @Test
+    public void testIsEnableTx() throws Exception {
+        c.addEnableTxAnnotationClasses(EnableTxA.class);
+        System.out.println(Component.class.getMethod("enableTxAMethod", new Class[0]));
+        assertTrue(c.isEnableTx(Component.class.getMethod("enableTxAMethod", new Class[0])));
+        assertFalse(c.isEnableTx(Component.class.getMethod("enableTxBMethod", new Class[0])));
+        assertFalse(c.isEnableTx(Component.class.getMethod("disableTxMehtod", new Class[0])));
+
+        c.addEnableTxAnnotationClasses(EnableTxB.class);
+        assertTrue(c.isEnableTx(Component.class.getMethod("enableTxAMethod", new Class[0])));
+        assertTrue(c.isEnableTx(Component.class.getMethod("enableTxBMethod", new Class[0])));
+        assertFalse(c.isEnableTx(Component.class.getMethod("disableTxMehtod", new Class[0])));
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.METHOD)
+    @Documented
+    public static @interface EnableTxA { }
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.METHOD)
+    @Documented
+    public static @interface EnableTxB { }
+
+    public static class Component {
+
+        @EnableTxA
+        public void enableTxAMethod() { }
+
+        @EnableTxB
+        public void enableTxBMethod() { }
+
+        public void disableTxMehtod() { }
+    }
+}

File sastruts-oreo/src/test/java/jp/troter/seasar/struts/customizer/T4TxAttributeCustomizerTest.java

-package jp.troter.seasar.struts.customizer;
-
-import static org.junit.Assert.*;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.util.Set;
-
-import org.junit.Before;
-import org.junit.Test;
-
-public class T4TxAttributeCustomizerTest extends T4TxAttributeCustomizer {
-
-    T4TxAttributeCustomizer c;
-
-    @Before
-    public void before() throws Exception {
-        c = new T4TxAttributeCustomizer();
-    }
-
-    @Test
-    public void testAddEnableTxAnnotationClasses() {
-        c.addEnableTxAnnotationClasses(EnableTxA.class);
-        Set<Class<? extends Annotation>> enableTxAnnotationClasses = c.getEnableTxAnnotationClasses();
-        assertTrue(enableTxAnnotationClasses.contains(EnableTxA.class));
-    }
-
-    @Test
-    public void testIsEnableTx() throws Exception {
-        c.addEnableTxAnnotationClasses(EnableTxA.class);
-        System.out.println(Component.class.getMethod("enableTxAMethod", new Class[0]));
-        assertTrue(c.isEnableTx(Component.class.getMethod("enableTxAMethod", new Class[0])));
-        assertFalse(c.isEnableTx(Component.class.getMethod("enableTxBMethod", new Class[0])));
-        assertFalse(c.isEnableTx(Component.class.getMethod("disableTxMehtod", new Class[0])));
-
-        c.addEnableTxAnnotationClasses(EnableTxB.class);
-        assertTrue(c.isEnableTx(Component.class.getMethod("enableTxAMethod", new Class[0])));
-        assertTrue(c.isEnableTx(Component.class.getMethod("enableTxBMethod", new Class[0])));
-        assertFalse(c.isEnableTx(Component.class.getMethod("disableTxMehtod", new Class[0])));
-    }
-
-    @Retention(RetentionPolicy.RUNTIME)
-    @Target(ElementType.METHOD)
-    @Documented
-    public static @interface EnableTxA { }
-    @Retention(RetentionPolicy.RUNTIME)
-    @Target(ElementType.METHOD)
-    @Documented
-    public static @interface EnableTxB { }
-
-    public static class Component {
-
-        @EnableTxA
-        public void enableTxAMethod() { }
-
-        @EnableTxB
-        public void enableTxBMethod() { }
-
-        public void disableTxMehtod() { }
-    }
-}