1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
import java .lang .annotation .Retention ;
22
22
import java .lang .annotation .RetentionPolicy ;
23
23
import java .lang .reflect .Method ;
24
-
25
24
import javax .ejb .TransactionAttributeType ;
26
25
26
+ import groovy .lang .GroovyObject ;
27
+ import groovy .lang .MetaClass ;
27
28
import org .junit .Test ;
28
29
29
30
import org .springframework .aop .framework .Advised ;
@@ -54,7 +55,7 @@ public void serializable() throws Exception {
54
55
TransactionInterceptor ti = new TransactionInterceptor (ptm , tas );
55
56
56
57
ProxyFactory proxyFactory = new ProxyFactory ();
57
- proxyFactory .setInterfaces (new Class [] { ITestBean .class } );
58
+ proxyFactory .setInterfaces (ITestBean .class );
58
59
proxyFactory .addAdvice (ti );
59
60
proxyFactory .setTarget (tb );
60
61
ITestBean proxy = (ITestBean ) proxyFactory .getProxy ();
@@ -369,6 +370,20 @@ public void transactionAttributeDeclaredOnInterfaceWithJta() throws Exception {
369
370
assertEquals (TransactionAttribute .PROPAGATION_SUPPORTS , getNameAttr .getPropagationBehavior ());
370
371
}
371
372
373
+ @ Test
374
+ public void transactionAttributeDeclaredOnGroovyClass () throws Exception {
375
+ Method getAgeMethod = ITestBean .class .getMethod ("getAge" );
376
+ Method getNameMethod = ITestBean .class .getMethod ("getName" );
377
+ Method getMetaClassMethod = GroovyObject .class .getMethod ("getMetaClass" );
378
+
379
+ AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource ();
380
+ TransactionAttribute getAgeAttr = atas .getTransactionAttribute (getAgeMethod , GroovyTestBean .class );
381
+ assertEquals (TransactionAttribute .PROPAGATION_REQUIRED , getAgeAttr .getPropagationBehavior ());
382
+ TransactionAttribute getNameAttr = atas .getTransactionAttribute (getNameMethod , GroovyTestBean .class );
383
+ assertEquals (TransactionAttribute .PROPAGATION_REQUIRED , getNameAttr .getPropagationBehavior ());
384
+ assertNull (atas .getTransactionAttribute (getMetaClassMethod , GroovyTestBean .class ));
385
+ }
386
+
372
387
373
388
interface ITestBean {
374
389
@@ -470,7 +485,7 @@ public void setName(String name) {
470
485
}
471
486
472
487
@ Override
473
- @ Transactional (rollbackFor = Exception .class )
488
+ @ Transactional (rollbackFor = Exception .class )
474
489
public int getAge () {
475
490
return age ;
476
491
}
@@ -543,8 +558,8 @@ public void setName(String name) {
543
558
}
544
559
545
560
@ Override
546
- @ Transactional (propagation = Propagation .REQUIRES_NEW , isolation =Isolation .REPEATABLE_READ , timeout = 5 ,
547
- readOnly = true , rollbackFor = Exception .class , noRollbackFor ={ IOException .class } )
561
+ @ Transactional (propagation = Propagation .REQUIRES_NEW , isolation =Isolation .REPEATABLE_READ ,
562
+ timeout = 5 , readOnly = true , rollbackFor = Exception .class , noRollbackFor = IOException .class )
548
563
public int getAge () {
549
564
return age ;
550
565
}
@@ -556,7 +571,7 @@ public void setAge(int age) {
556
571
}
557
572
558
573
559
- @ Transactional (rollbackFor = Exception .class , noRollbackFor ={ IOException .class } )
574
+ @ Transactional (rollbackFor = Exception .class , noRollbackFor = IOException .class )
560
575
static class TestBean4 implements ITestBean3 {
561
576
562
577
private String name ;
@@ -594,7 +609,7 @@ public void setAge(int age) {
594
609
595
610
596
611
@ Retention (RetentionPolicy .RUNTIME )
597
- @ Transactional (rollbackFor = Exception .class , noRollbackFor ={ IOException .class } )
612
+ @ Transactional (rollbackFor = Exception .class , noRollbackFor = IOException .class )
598
613
@interface Tx {
599
614
}
600
615
@@ -618,13 +633,13 @@ public int getAge() {
618
633
619
634
620
635
@ Retention (RetentionPolicy .RUNTIME )
621
- @ Transactional (rollbackFor = Exception .class , noRollbackFor ={ IOException .class } )
636
+ @ Transactional (rollbackFor = Exception .class , noRollbackFor = IOException .class )
622
637
@interface TxWithAttribute {
623
638
boolean readOnly ();
624
639
}
625
640
626
641
627
- @ TxWithAttribute (readOnly = true )
642
+ @ TxWithAttribute (readOnly = true )
628
643
static class TestBean7 {
629
644
630
645
public int getAge () {
@@ -641,11 +656,14 @@ public int getAge() {
641
656
}
642
657
}
643
658
659
+
644
660
@ TxWithAttribute (readOnly = true )
645
661
interface TestInterface9 {
662
+
646
663
int getAge ();
647
664
}
648
665
666
+
649
667
static class TestBean9 implements TestInterface9 {
650
668
651
669
@ Override
@@ -654,12 +672,14 @@ public int getAge() {
654
672
}
655
673
}
656
674
675
+
657
676
interface TestInterface10 {
658
677
659
- @ TxWithAttribute (readOnly = true )
678
+ @ TxWithAttribute (readOnly = true )
660
679
int getAge ();
661
680
}
662
681
682
+
663
683
static class TestBean10 implements TestInterface10 {
664
684
665
685
@ Override
@@ -888,4 +908,56 @@ public void setAge(int age) {
888
908
}
889
909
}
890
910
911
+
912
+ @ Transactional
913
+ static class GroovyTestBean implements ITestBean , GroovyObject {
914
+
915
+ private String name ;
916
+
917
+ private int age ;
918
+
919
+ @ Override
920
+ public String getName () {
921
+ return name ;
922
+ }
923
+
924
+ @ Override
925
+ public void setName (String name ) {
926
+ this .name = name ;
927
+ }
928
+
929
+ @ Override
930
+ public int getAge () {
931
+ return age ;
932
+ }
933
+
934
+ @ Override
935
+ public void setAge (int age ) {
936
+ this .age = age ;
937
+ }
938
+
939
+ @ Override
940
+ public Object invokeMethod (String name , Object args ) {
941
+ return null ;
942
+ }
943
+
944
+ @ Override
945
+ public Object getProperty (String propertyName ) {
946
+ return null ;
947
+ }
948
+
949
+ @ Override
950
+ public void setProperty (String propertyName , Object newValue ) {
951
+ }
952
+
953
+ @ Override
954
+ public MetaClass getMetaClass () {
955
+ return null ;
956
+ }
957
+
958
+ @ Override
959
+ public void setMetaClass (MetaClass metaClass ) {
960
+ }
961
+ }
962
+
891
963
}
0 commit comments