From: Gustavo Martin Morcuende Date: Thu, 27 Jun 2013 00:09:38 +0000 (+0200) Subject: Remove old data. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=99920fee5c150d1ed0fa20acea0b167f8728bbfb;p=JavaForFun Remove old data. --- diff --git a/SpringJava/SpringLTW/pom.xml b/SpringJava/SpringLTW/pom.xml index 75bab27..d55d01f 100644 --- a/SpringJava/SpringLTW/pom.xml +++ b/SpringJava/SpringLTW/pom.xml @@ -29,11 +29,6 @@ - com.sun.jdmk - jmxtools - 1.2.1 - - javax.activation activation 1.1 diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/MyAdvice.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/MyAdvice.java index 5f61578..4704d0b 100644 --- a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/MyAdvice.java +++ b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/MyAdvice.java @@ -3,23 +3,22 @@ package de.spring.example; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; -import de.spring.example.TransactionManagerN2A; @Aspect public class MyAdvice { - - - @Before("@annotation(de.spring.example.annotation.initTransactionalN2A)") - public void initTransactionalN2A() - { - System.out.println("I am the Advice initTransaction."); - TransactionManagerN2A.getInstance().initTransaction(); - } - - @After("@annotation(de.spring.example.annotation.commitTransactionalN2A)") - public void commitTransactionalN2A() { - System.out.println("I am the Advice commitTransaction."); - TransactionManagerN2A.getInstance().commitTransaction(); - } + + @Before("execution(* de.spring.example.web.Gus.prueba())") + public void initTransactional() + { + System.out.println("I am the Advice initTransaction."); + TransactionManager.getInstance().initTransaction(); + } + + + @After("@annotation(de.spring.example.annotation.commitTransactional)") + public void commitTransactional() { + System.out.println("I am the Advice commitTransaction."); + TransactionManager.getInstance().commitTransaction(); + } } diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/TransactionManager.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/TransactionManager.java new file mode 100644 index 0000000..d8657f2 --- /dev/null +++ b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/TransactionManager.java @@ -0,0 +1,45 @@ +package de.spring.example; + +import org.aspectj.lang.annotation.Aspect; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.transaction.TransactionStatus; + +@Aspect +public class TransactionManager { + private static TransactionManager instance = new TransactionManager(); + private DataSourceTransactionManager transactionManager; + private TransactionStatus transactionStatus; + + //Why could you want to extend this class? + private TransactionManager() { + } + + public static TransactionManager getInstance() { + return instance; + } + + public void initTransaction() + { + System.out.println("initTRANSACTION"); + // transactionStatus = this.transactionManager.getTransaction(null); + } + + public void rollbackTransaction() + { + this.transactionManager.rollback(this.transactionStatus); + } + + + public void commitTransaction() + { + System.out.println("commitTRANSACTION"); + // this.transactionManager.commit(this.transactionStatus); + } + + + /************************* Setters and getters *******************************************/ + public void setTransactionManager(final DataSourceTransactionManager transactionManager) + { + this.transactionManager = transactionManager; + } +} diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/TransactionManagerN2A.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/TransactionManagerN2A.java deleted file mode 100644 index 867b4bb..0000000 --- a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/TransactionManagerN2A.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.spring.example; - -import org.aspectj.lang.annotation.Aspect; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.transaction.TransactionStatus; - -@Aspect -public class TransactionManagerN2A { - private static TransactionManagerN2A instance = new TransactionManagerN2A(); - private DataSourceTransactionManager transactionManager; - private TransactionStatus transactionStatus; - - //Why could you want to extend this class? - private TransactionManagerN2A() {} - - public static TransactionManagerN2A getInstance() { - return instance; - } - - public void initTransaction() - { - System.out.println("initTRANSACTION"); - transactionStatus = this.transactionManager.getTransaction(null); - } - - public void rollbackTransaction() - { - this.transactionManager.rollback(this.transactionStatus); - } - - - public void commitTransaction() - { - System.out.println("commitTRANSACTION"); - this.transactionManager.commit(this.transactionStatus); - } - - - /************************* Setters and getters *******************************************/ - public void setTransactionManager(final DataSourceTransactionManager transactionManager) - { - this.transactionManager = transactionManager; - } -} diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/commitTransactional.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/commitTransactional.java new file mode 100644 index 0000000..1fda03f --- /dev/null +++ b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/commitTransactional.java @@ -0,0 +1,14 @@ +package de.spring.example.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.stereotype.Component; + +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Component +public @interface commitTransactional { +} diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/commitTransactionalN2A.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/commitTransactionalN2A.java deleted file mode 100644 index 950c319..0000000 --- a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/commitTransactionalN2A.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.spring.example.annotation; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.annotation.ElementType; -import org.springframework.stereotype.Component; - -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Component -public @interface commitTransactionalN2A { -} diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/initTransactional.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/initTransactional.java new file mode 100644 index 0000000..dad0b3e --- /dev/null +++ b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/initTransactional.java @@ -0,0 +1,14 @@ +package de.spring.example.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.stereotype.Component; + +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Component +public @interface initTransactional { +} diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/initTransactionalN2A.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/initTransactionalN2A.java deleted file mode 100644 index 7996478..0000000 --- a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/annotation/initTransactionalN2A.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.spring.example.annotation; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.annotation.ElementType; -import org.springframework.stereotype.Component; - -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Component -public @interface initTransactionalN2A { -} diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/web/Gus.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/web/Gus.java new file mode 100644 index 0000000..2d11f75 --- /dev/null +++ b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/web/Gus.java @@ -0,0 +1,11 @@ +package de.spring.example.web; + +import de.spring.example.annotation.initTransactional; + +public class Gus { + + @initTransactional + public void prueba() { + System.out.println("GUSOOK"); + } +} diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/web/Test.java b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/web/Test.java index d17d3ef..cc21d8f 100644 --- a/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/web/Test.java +++ b/SpringJava/SpringLTW/spring-ltw-example/src/main/java/de/spring/example/web/Test.java @@ -1,23 +1,23 @@ package de.spring.example.web; -import de.spring.example.annotation.commitTransactionalN2A; -import de.spring.example.annotation.initTransactionalN2A; +import de.spring.example.annotation.commitTransactional; +import de.spring.example.annotation.initTransactional; public class Test { - @initTransactionalN2A - public int myMethod() - { - System.out.println("The Advice should be run before."); - - //This value will be caught by the Advice with the @AfterReturning annotation. - return 666; - } - - public class InnerTest { - @commitTransactionalN2A - public void innerMethod() { - System.out.println("I am the inner class. The Advice should be run after. "); - } - } + @initTransactional + public int myMethod() + { + System.out.println("The Advice should be run before."); + + //This value will be caught by the Advice with the @AfterReturning annotation. + return 666; + } + + public class InnerTest { + @commitTransactional + public void innerMethod() { + System.out.println("I am the inner class. The Advice should be run after. "); + } + } } diff --git a/SpringJava/SpringLTW/spring-ltw-example/src/main/resources/spring-config.xml b/SpringJava/SpringLTW/spring-ltw-example/src/main/resources/spring-config.xml index b358f70..0710eee 100644 --- a/SpringJava/SpringLTW/spring-ltw-example/src/main/resources/spring-config.xml +++ b/SpringJava/SpringLTW/spring-ltw-example/src/main/resources/spring-config.xml @@ -43,8 +43,8 @@ -