Commit b0c0e3ab735d1ccf0508aecff04b62f2ca865b73
1 parent
198d487f
Exists in
master
Mais ajustes para o devido funcionamento do carregamento da estratégia
de transação via properties
Showing
4 changed files
with
32 additions
and
23 deletions
Show diff stats
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/resources/demoiselle.properties
... | ... | @@ -34,4 +34,4 @@ |
34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
35 | 35 | |
36 | 36 | frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JPATransaction |
37 | -#frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JTATransaction | |
38 | 37 | \ No newline at end of file |
38 | +#frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JTATransaction | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/TransactionBootstrap.java
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
38 | 38 | |
39 | 39 | import javax.enterprise.event.Observes; |
40 | +import javax.enterprise.inject.spi.BeforeBeanDiscovery; | |
40 | 41 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
41 | 42 | |
42 | 43 | import org.apache.commons.configuration.Configuration; |
... | ... | @@ -49,7 +50,16 @@ import br.gov.frameworkdemoiselle.util.Reflections; |
49 | 50 | |
50 | 51 | public class TransactionBootstrap extends AbstractBootstrap { |
51 | 52 | |
52 | - private static Class<Transaction> selected = loadSelected(); | |
53 | + private static Class<? extends Transaction> selected = loadSelected(); | |
54 | + | |
55 | + public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) { | |
56 | + selected = loadSelected(); | |
57 | + | |
58 | + if (selected == null) { | |
59 | + selected = DefaultTransaction.class; | |
60 | + } | |
61 | + | |
62 | + } | |
53 | 63 | |
54 | 64 | public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) { |
55 | 65 | Class<?> annotated = event.getAnnotatedType().getJavaClass(); |
... | ... | @@ -61,30 +71,29 @@ public class TransactionBootstrap extends AbstractBootstrap { |
61 | 71 | |
62 | 72 | @SuppressWarnings("unchecked") |
63 | 73 | private static Class<Transaction> loadSelected() { |
64 | - synchronized (selected) { | |
65 | - String canonicalName = null; | |
74 | + Class<Transaction> result = null; | |
75 | + String canonicalName = null; | |
66 | 76 | |
67 | - try { | |
68 | - Configuration config = new PropertiesConfiguration("demoiselle.properties"); | |
69 | - canonicalName = config.getString("frameworkdemoiselle.transaction.class", | |
70 | - DefaultTransaction.class.getCanonicalName()); | |
77 | + try { | |
78 | + Configuration config = new PropertiesConfiguration("demoiselle.properties"); | |
79 | + canonicalName = config.getString("frameworkdemoiselle.transaction.class", | |
80 | + DefaultTransaction.class.getCanonicalName()); | |
71 | 81 | |
72 | - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | |
73 | - selected = (Class<Transaction>) Class.forName(canonicalName, false, classLoader); | |
74 | - selected.asSubclass(Transaction.class); | |
82 | + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | |
83 | + result = (Class<Transaction>) Class.forName(canonicalName, false, classLoader); | |
84 | + result.asSubclass(Transaction.class); | |
75 | 85 | |
76 | - } catch (org.apache.commons.configuration.ConfigurationException cause) { | |
77 | - throw new ConfigurationException(getBundle().getString("file-not-found", "demoiselle.properties")); | |
86 | + } catch (org.apache.commons.configuration.ConfigurationException cause) { | |
87 | + throw new ConfigurationException(getBundle().getString("file-not-found", "demoiselle.properties")); | |
78 | 88 | |
79 | - } catch (ClassNotFoundException cause) { | |
80 | - throw new ConfigurationException(getBundle().getString("transaction-class-not-found", canonicalName)); | |
89 | + } catch (ClassNotFoundException cause) { | |
90 | + throw new ConfigurationException(getBundle().getString("transaction-class-not-found", canonicalName)); | |
81 | 91 | |
82 | - } catch (ClassCastException cause) { | |
83 | - throw new ConfigurationException(getBundle().getString("transaction-class-must-be-of-type", | |
84 | - canonicalName, Transaction.class.getCanonicalName())); | |
85 | - } | |
92 | + } catch (ClassCastException cause) { | |
93 | + throw new ConfigurationException(getBundle().getString("transaction-class-must-be-of-type", canonicalName, | |
94 | + Transaction.class.getCanonicalName())); | |
86 | 95 | } |
87 | - | |
88 | - return selected; | |
96 | + | |
97 | + return result; | |
89 | 98 | } |
90 | 99 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransaction.java
... | ... | @@ -85,6 +85,6 @@ public class DefaultTransaction implements Transaction { |
85 | 85 | |
86 | 86 | private DemoiselleException getException() { |
87 | 87 | return new DemoiselleException(CoreBundle.get().getString("transaction-not-defined", |
88 | - Transactional.class.getSimpleName(), Transaction.class.getSimpleName())); | |
88 | + Transactional.class.getSimpleName())); | |
89 | 89 | } |
90 | 90 | } | ... | ... |
impl/core/src/main/resources/demoiselle-core-bundle.properties
... | ... | @@ -58,7 +58,7 @@ configuration-attribute-is-mandatory=A configura\u00E7\u00E3o {0} \u00E9 obrigat |
58 | 58 | configuration-name-attribute-cant-be-empty=A nota\u00E7\u00E3o Name n\u00E3o pode estar em branco |
59 | 59 | configuration-key-not-found=Chave de configura\u00E7\u00E3o "{0}" n\u00E3o encontrada. Conven\u00E7\u00F5es verificadas\: "{1}" |
60 | 60 | |
61 | -transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso escolher uma extens\u00E3o (ou componente) que possua uma estrat\u00E9gia de transa\u00E7\u00E3o, ou voc\u00EA pode criar a sua pr\u00F3pria estrat\u00E9gia implementando a interface {1} | |
61 | +transaction-not-defined=Nenhuma transa\u00E7\u00E3o foi definida. Para utilizar @{0} \u00E9 preciso definir a propriedade frameworkdemoiselle.transaction.class com a estrat\u00E9gia de transa\u00E7\u00E3o desejada no arquivo demoiselle.properties | |
62 | 62 | executing-all=Executando todos os \: {0} |
63 | 63 | custom-context-was-registered=O contexto {0} foi registrado |
64 | 64 | custom-context-was-unregistered=O contexto {0} foi removido | ... | ... |