Commit e386cfd7fc123ba7d564594c7f3d6c6f3230e34a
1 parent
919a4675
Exists in
master
Correção no erro de injeção após as modificações
Showing
3 changed files
with
49 additions
and
41 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/template/DelegateCrud.java
| @@ -41,6 +41,7 @@ import java.util.ListIterator; | @@ -41,6 +41,7 @@ import java.util.ListIterator; | ||
| 41 | 41 | ||
| 42 | import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; | 42 | import br.gov.frameworkdemoiselle.internal.implementation.DefaultTransaction; |
| 43 | import br.gov.frameworkdemoiselle.transaction.Transaction; | 43 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
| 44 | +import br.gov.frameworkdemoiselle.transaction.TransactionContext; | ||
| 44 | import br.gov.frameworkdemoiselle.transaction.Transactional; | 45 | import br.gov.frameworkdemoiselle.transaction.Transactional; |
| 45 | import br.gov.frameworkdemoiselle.util.Beans; | 46 | import br.gov.frameworkdemoiselle.util.Beans; |
| 46 | import br.gov.frameworkdemoiselle.util.Reflections; | 47 | import br.gov.frameworkdemoiselle.util.Reflections; |
| @@ -142,6 +143,8 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { | @@ -142,6 +143,8 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { | ||
| 142 | } else { | 143 | } else { |
| 143 | nonTransactionalInsert(bean); | 144 | nonTransactionalInsert(bean); |
| 144 | } | 145 | } |
| 146 | + | ||
| 147 | + System.out.println(); | ||
| 145 | } | 148 | } |
| 146 | 149 | ||
| 147 | @Transactional | 150 | @Transactional |
| @@ -188,6 +191,7 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { | @@ -188,6 +191,7 @@ public class DelegateCrud<T, I, C extends Crud<T, I>> implements Crud<T, I> { | ||
| 188 | } | 191 | } |
| 189 | 192 | ||
| 190 | private boolean isRunningTransactionalOperations() { | 193 | private boolean isRunningTransactionalOperations() { |
| 191 | - return !(Beans.getReference(Transaction.class) instanceof DefaultTransaction); | 194 | + Transaction transaction = Beans.getReference(TransactionContext.class).getCurrentTransaction(); |
| 195 | + return !(transaction instanceof DefaultTransaction); | ||
| 192 | } | 196 | } |
| 193 | } | 197 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionInfo.java
0 → 100644
| @@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
| 1 | +package br.gov.frameworkdemoiselle.transaction; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +import javax.enterprise.context.RequestScoped; | ||
| 6 | + | ||
| 7 | +@RequestScoped | ||
| 8 | +public class TransactionInfo implements Serializable { | ||
| 9 | + | ||
| 10 | + private static final long serialVersionUID = 1L; | ||
| 11 | + | ||
| 12 | + private int counter = 0; | ||
| 13 | + | ||
| 14 | + private boolean owner; | ||
| 15 | + | ||
| 16 | + public TransactionInfo() { | ||
| 17 | + clear(); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public void clear() { | ||
| 21 | + this.owner = false; | ||
| 22 | + this.counter = 0; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public int getCounter() { | ||
| 26 | + return counter; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public void incrementCounter() { | ||
| 30 | + this.counter++; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void decrementCounter() { | ||
| 34 | + this.counter--; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public void markAsOwner() { | ||
| 38 | + this.owner = true; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public boolean isOwner() { | ||
| 42 | + return owner; | ||
| 43 | + } | ||
| 44 | +} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionalInterceptor.java
| @@ -39,7 +39,6 @@ package br.gov.frameworkdemoiselle.transaction; | @@ -39,7 +39,6 @@ package br.gov.frameworkdemoiselle.transaction; | ||
| 39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
| 40 | 40 | ||
| 41 | import javax.enterprise.context.ContextNotActiveException; | 41 | import javax.enterprise.context.ContextNotActiveException; |
| 42 | -import javax.enterprise.context.RequestScoped; | ||
| 43 | import javax.interceptor.AroundInvoke; | 42 | import javax.interceptor.AroundInvoke; |
| 44 | import javax.interceptor.Interceptor; | 43 | import javax.interceptor.Interceptor; |
| 45 | import javax.interceptor.InvocationContext; | 44 | import javax.interceptor.InvocationContext; |
| @@ -197,43 +196,4 @@ public class TransactionalInterceptor implements Serializable { | @@ -197,43 +196,4 @@ public class TransactionalInterceptor implements Serializable { | ||
| 197 | 196 | ||
| 198 | return logger; | 197 | return logger; |
| 199 | } | 198 | } |
| 200 | - | ||
| 201 | - @RequestScoped | ||
| 202 | - class TransactionInfo implements Serializable { | ||
| 203 | - | ||
| 204 | - private static final long serialVersionUID = 1L; | ||
| 205 | - | ||
| 206 | - private int counter = 0; | ||
| 207 | - | ||
| 208 | - private boolean owner; | ||
| 209 | - | ||
| 210 | - public TransactionInfo() { | ||
| 211 | - clear(); | ||
| 212 | - } | ||
| 213 | - | ||
| 214 | - public void clear() { | ||
| 215 | - this.owner = false; | ||
| 216 | - this.counter = 0; | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | - public int getCounter() { | ||
| 220 | - return counter; | ||
| 221 | - } | ||
| 222 | - | ||
| 223 | - public void incrementCounter() { | ||
| 224 | - this.counter++; | ||
| 225 | - } | ||
| 226 | - | ||
| 227 | - public void decrementCounter() { | ||
| 228 | - this.counter--; | ||
| 229 | - } | ||
| 230 | - | ||
| 231 | - public void markAsOwner() { | ||
| 232 | - this.owner = true; | ||
| 233 | - } | ||
| 234 | - | ||
| 235 | - public boolean isOwner() { | ||
| 236 | - return owner; | ||
| 237 | - } | ||
| 238 | - } | ||
| 239 | } | 199 | } |