Commit aae2ffe2f58aeade6445fe2492f9e5b7a1489f2c
1 parent
d0256b51
Exists in
master
FWK-202: Injeção de java.util.logging.Logger
Task-Url: https://demoiselle.atlassian.net/browse/FWK-202
Showing
4 changed files
with
95 additions
and
97 deletions
Show diff stats
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/AbstractEntityManagerStore.java
@@ -39,13 +39,12 @@ package br.gov.frameworkdemoiselle.internal.producer; | @@ -39,13 +39,12 @@ package br.gov.frameworkdemoiselle.internal.producer; | ||
39 | import java.util.Collections; | 39 | import java.util.Collections; |
40 | import java.util.HashMap; | 40 | import java.util.HashMap; |
41 | import java.util.Map; | 41 | import java.util.Map; |
42 | +import java.util.logging.Logger; | ||
42 | 43 | ||
43 | import javax.enterprise.context.RequestScoped; | 44 | import javax.enterprise.context.RequestScoped; |
44 | import javax.persistence.EntityManager; | 45 | import javax.persistence.EntityManager; |
45 | import javax.persistence.FlushModeType; | 46 | import javax.persistence.FlushModeType; |
46 | 47 | ||
47 | -import org.slf4j.Logger; | ||
48 | - | ||
49 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | 48 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; |
50 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig.EntityManagerScope; | 49 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig.EntityManagerScope; |
51 | import br.gov.frameworkdemoiselle.util.Beans; | 50 | import br.gov.frameworkdemoiselle.util.Beans; |
@@ -53,25 +52,25 @@ import br.gov.frameworkdemoiselle.util.NameQualifier; | @@ -53,25 +52,25 @@ import br.gov.frameworkdemoiselle.util.NameQualifier; | ||
53 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 52 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
54 | 53 | ||
55 | /** | 54 | /** |
56 | - * | ||
57 | - * <p>Stores produced entity managers. When the {@link EntityManagerProducer} try to create an entity manager it will | ||
58 | - * seach this store for a cached instance, only creating a new instance if this cache doesn't contain a suitable one.</p> | ||
59 | - * | ||
60 | - * <p>There are several concrete implementations of this class, each one corresponding to a scoped cache (ex: {@link RequestEntityManagerStore} | ||
61 | - * stores Entity Managers on the request scope). To select witch implementation is used (and with that, what scope is used to store Entity Managers) | ||
62 | - * open the "demoiselle.properties" file and edit the property "frameworkdemoiselle.persistence.entitymanager.scope". The default scope is the | ||
63 | - * {@link RequestScoped}.</p> | ||
64 | - * | 55 | + * <p> |
56 | + * Stores produced entity managers. When the {@link EntityManagerProducer} try to create an entity manager it will seach | ||
57 | + * this store for a cached instance, only creating a new instance if this cache doesn't contain a suitable one. | ||
58 | + * </p> | ||
59 | + * <p> | ||
60 | + * There are several concrete implementations of this class, each one corresponding to a scoped cache (ex: | ||
61 | + * {@link RequestEntityManagerStore} stores Entity Managers on the request scope). To select witch implementation is | ||
62 | + * used (and with that, what scope is used to store Entity Managers) open the "demoiselle.properties" file and edit the | ||
63 | + * property "frameworkdemoiselle.persistence.entitymanager.scope". The default scope is the {@link RequestScoped}. | ||
64 | + * </p> | ||
65 | * | 65 | * |
66 | * @author serpro | 66 | * @author serpro |
67 | - * | ||
68 | */ | 67 | */ |
69 | public abstract class AbstractEntityManagerStore implements EntityManagerStore { | 68 | public abstract class AbstractEntityManagerStore implements EntityManagerStore { |
70 | - | 69 | + |
71 | private static final long serialVersionUID = 1L; | 70 | private static final long serialVersionUID = 1L; |
72 | 71 | ||
73 | private final Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | 72 | private final Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); |
74 | - | 73 | + |
75 | public EntityManager getEntityManager(String persistenceUnit) { | 74 | public EntityManager getEntityManager(String persistenceUnit) { |
76 | EntityManager entityManager = null; | 75 | EntityManager entityManager = null; |
77 | 76 | ||
@@ -88,7 +87,7 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | @@ -88,7 +87,7 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | ||
88 | 87 | ||
89 | return entityManager; | 88 | return entityManager; |
90 | } | 89 | } |
91 | - | 90 | + |
92 | void init() { | 91 | void init() { |
93 | for (String persistenceUnit : getFactory().getCache().keySet()) { | 92 | for (String persistenceUnit : getFactory().getCache().keySet()) { |
94 | getEntityManager(persistenceUnit); | 93 | getEntityManager(persistenceUnit); |
@@ -96,11 +95,11 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | @@ -96,11 +95,11 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | ||
96 | } | 95 | } |
97 | 96 | ||
98 | void close() { | 97 | void close() { |
99 | - //Se o produtor não possui escopo, então o ciclo de vida | ||
100 | - //de EntityManager produzidos é responsabilidade do desenvolvedor. Não | ||
101 | - //fechamos os EntityManagers aqui. | 98 | + // Se o produtor não possui escopo, então o ciclo de vida |
99 | + // de EntityManager produzidos é responsabilidade do desenvolvedor. Não | ||
100 | + // fechamos os EntityManagers aqui. | ||
102 | EntityManagerConfig configuration = getConfiguration(); | 101 | EntityManagerConfig configuration = getConfiguration(); |
103 | - if (configuration.getEntityManagerScope() != EntityManagerScope.NOSCOPE){ | 102 | + if (configuration.getEntityManagerScope() != EntityManagerScope.NOSCOPE) { |
104 | for (EntityManager entityManager : cache.values()) { | 103 | for (EntityManager entityManager : cache.values()) { |
105 | entityManager.close(); | 104 | entityManager.close(); |
106 | } | 105 | } |
@@ -109,26 +108,26 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | @@ -109,26 +108,26 @@ public abstract class AbstractEntityManagerStore implements EntityManagerStore { | ||
109 | } | 108 | } |
110 | 109 | ||
111 | public Map<String, EntityManager> getCache() { | 110 | public Map<String, EntityManager> getCache() { |
112 | - if (cache==null || cache.isEmpty()){ | 111 | + if (cache == null || cache.isEmpty()) { |
113 | init(); | 112 | init(); |
114 | } | 113 | } |
115 | - | 114 | + |
116 | return cache; | 115 | return cache; |
117 | } | 116 | } |
118 | - | ||
119 | - private EntityManagerFactoryProducer getFactory(){ | 117 | + |
118 | + private EntityManagerFactoryProducer getFactory() { | ||
120 | return Beans.getReference(EntityManagerFactoryProducer.class); | 119 | return Beans.getReference(EntityManagerFactoryProducer.class); |
121 | } | 120 | } |
122 | - | ||
123 | - private Logger getLogger(){ | ||
124 | - return Beans.getReference(Logger.class); | 121 | + |
122 | + private Logger getLogger() { | ||
123 | + return Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.util")); | ||
125 | } | 124 | } |
126 | - | ||
127 | - private ResourceBundle getBundle(){ | ||
128 | - return Beans.getReference(ResourceBundle.class , new NameQualifier("demoiselle-jpa-bundle")); | 125 | + |
126 | + private ResourceBundle getBundle() { | ||
127 | + return Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-jpa-bundle")); | ||
129 | } | 128 | } |
130 | - | ||
131 | - private EntityManagerConfig getConfiguration(){ | 129 | + |
130 | + private EntityManagerConfig getConfiguration() { | ||
132 | return Beans.getReference(EntityManagerConfig.class); | 131 | return Beans.getReference(EntityManagerConfig.class); |
133 | } | 132 | } |
134 | } | 133 | } |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
@@ -36,11 +36,14 @@ | @@ -36,11 +36,14 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.producer; | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
38 | 38 | ||
39 | +import static java.util.logging.Level.SEVERE; | ||
40 | + | ||
39 | import java.io.Serializable; | 41 | import java.io.Serializable; |
40 | import java.util.ArrayList; | 42 | import java.util.ArrayList; |
41 | import java.util.Collections; | 43 | import java.util.Collections; |
42 | import java.util.HashMap; | 44 | import java.util.HashMap; |
43 | import java.util.Map; | 45 | import java.util.Map; |
46 | +import java.util.logging.Logger; | ||
44 | 47 | ||
45 | import javax.annotation.PostConstruct; | 48 | import javax.annotation.PostConstruct; |
46 | import javax.annotation.PreDestroy; | 49 | import javax.annotation.PreDestroy; |
@@ -54,7 +57,6 @@ import javax.persistence.Persistence; | @@ -54,7 +57,6 @@ import javax.persistence.Persistence; | ||
54 | import javax.xml.parsers.DocumentBuilder; | 57 | import javax.xml.parsers.DocumentBuilder; |
55 | import javax.xml.parsers.DocumentBuilderFactory; | 58 | import javax.xml.parsers.DocumentBuilderFactory; |
56 | 59 | ||
57 | -import org.slf4j.Logger; | ||
58 | import org.w3c.dom.Document; | 60 | import org.w3c.dom.Document; |
59 | import org.w3c.dom.Element; | 61 | import org.w3c.dom.Element; |
60 | import org.w3c.dom.Node; | 62 | import org.w3c.dom.Node; |
@@ -72,20 +74,20 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -72,20 +74,20 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
72 | private static final long serialVersionUID = 1L; | 74 | private static final long serialVersionUID = 1L; |
73 | 75 | ||
74 | private static final String ENTITY_MANAGER_RESOURCE = "META-INF/persistence.xml"; | 76 | private static final String ENTITY_MANAGER_RESOURCE = "META-INF/persistence.xml"; |
75 | - | 77 | + |
76 | @Inject | 78 | @Inject |
77 | protected Logger logger; | 79 | protected Logger logger; |
78 | 80 | ||
79 | @Inject | 81 | @Inject |
80 | @Name("demoiselle-jpa-bundle") | 82 | @Name("demoiselle-jpa-bundle") |
81 | protected ResourceBundle bundle; | 83 | protected ResourceBundle bundle; |
82 | - | 84 | + |
83 | @Inject | 85 | @Inject |
84 | private Persistences persistenceUnitReader; | 86 | private Persistences persistenceUnitReader; |
85 | 87 | ||
86 | private final Map<ClassLoader, Map<String, EntityManagerFactory>> factoryCache = Collections | 88 | private final Map<ClassLoader, Map<String, EntityManagerFactory>> factoryCache = Collections |
87 | .synchronizedMap(new HashMap<ClassLoader, Map<String, EntityManagerFactory>>()); | 89 | .synchronizedMap(new HashMap<ClassLoader, Map<String, EntityManagerFactory>>()); |
88 | - | 90 | + |
89 | @Default | 91 | @Default |
90 | @Produces | 92 | @Produces |
91 | protected EntityManagerFactory createDefault(EntityManagerConfig config) { | 93 | protected EntityManagerFactory createDefault(EntityManagerConfig config) { |
@@ -104,7 +106,7 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -104,7 +106,7 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
104 | String persistenceUnit = ip.getAnnotated().getAnnotation(Name.class).value(); | 106 | String persistenceUnit = ip.getAnnotated().getAnnotation(Name.class).value(); |
105 | return create(persistenceUnit); | 107 | return create(persistenceUnit); |
106 | } | 108 | } |
107 | - | 109 | + |
108 | public EntityManagerFactory create(String persistenceUnit) { | 110 | public EntityManagerFactory create(String persistenceUnit) { |
109 | EntityManagerFactory factory; | 111 | EntityManagerFactory factory; |
110 | 112 | ||
@@ -151,7 +153,7 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -151,7 +153,7 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
151 | 153 | ||
152 | } catch (Exception cause) { | 154 | } catch (Exception cause) { |
153 | String message = bundle.getString("can-not-get-persistence-unit-from-persistence"); | 155 | String message = bundle.getString("can-not-get-persistence-unit-from-persistence"); |
154 | - logger.error(message, cause); | 156 | + logger.log(SEVERE, message, cause); |
155 | 157 | ||
156 | throw new DemoiselleException(message, cause); | 158 | throw new DemoiselleException(message, cause); |
157 | } | 159 | } |
@@ -169,7 +171,7 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -169,7 +171,7 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
169 | throw new DemoiselleException(cause); | 171 | throw new DemoiselleException(cause); |
170 | } | 172 | } |
171 | 173 | ||
172 | - logger.debug(bundle.getString("persistence-unit-name-found", persistenceUnit)); | 174 | + logger.fine(bundle.getString("persistence-unit-name-found", persistenceUnit)); |
173 | } | 175 | } |
174 | } | 176 | } |
175 | 177 | ||
@@ -188,7 +190,7 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -188,7 +190,7 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
188 | Map<String, EntityManagerFactory> result = factoryCache.get(classLoader); | 190 | Map<String, EntityManagerFactory> result = factoryCache.get(classLoader); |
189 | 191 | ||
190 | if (result == null || result.isEmpty()) { | 192 | if (result == null || result.isEmpty()) { |
191 | - logger.debug(bundle.getString("entity-manager-factory-not-found-in-cache")); | 193 | + logger.fine(bundle.getString("entity-manager-factory-not-found-in-cache")); |
192 | for (String persistenceUnit : loadPersistenceUnitFromClassloader(classLoader)) { | 194 | for (String persistenceUnit : loadPersistenceUnitFromClassloader(classLoader)) { |
193 | create(persistenceUnit); | 195 | create(persistenceUnit); |
194 | result = factoryCache.get(classLoader); | 196 | result = factoryCache.get(classLoader); |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/Persistences.java
@@ -36,16 +36,16 @@ | @@ -36,16 +36,16 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.producer; | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
38 | 38 | ||
39 | +import static br.gov.frameworkdemoiselle.configuration.Configuration.DEFAULT_RESOURCE; | ||
40 | + | ||
39 | import java.util.Set; | 41 | import java.util.Set; |
42 | +import java.util.logging.Logger; | ||
40 | 43 | ||
41 | import javax.inject.Inject; | 44 | import javax.inject.Inject; |
42 | import javax.inject.Singleton; | 45 | import javax.inject.Singleton; |
43 | 46 | ||
44 | -import org.slf4j.Logger; | ||
45 | - | ||
46 | import br.gov.frameworkdemoiselle.DemoiselleException; | 47 | import br.gov.frameworkdemoiselle.DemoiselleException; |
47 | import br.gov.frameworkdemoiselle.annotation.Name; | 48 | import br.gov.frameworkdemoiselle.annotation.Name; |
48 | -import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
49 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | 49 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; |
50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
51 | 51 | ||
@@ -73,8 +73,7 @@ public class Persistences { | @@ -73,8 +73,7 @@ public class Persistences { | ||
73 | String persistenceUnit = config.getDefaultPersistenceUnitName(); | 73 | String persistenceUnit = config.getDefaultPersistenceUnitName(); |
74 | 74 | ||
75 | if (persistenceUnit != null) { | 75 | if (persistenceUnit != null) { |
76 | - this.logger.debug(bundle.getString("getting-persistence-unit-from-properties", | ||
77 | - Configuration.DEFAULT_RESOURCE)); | 76 | + this.logger.fine(bundle.getString("getting-persistence-unit-from-properties", DEFAULT_RESOURCE)); |
78 | } | 77 | } |
79 | 78 | ||
80 | return persistenceUnit; | 79 | return persistenceUnit; |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/EntityManagerProxy.java
@@ -38,6 +38,7 @@ package br.gov.frameworkdemoiselle.internal.proxy; | @@ -38,6 +38,7 @@ package br.gov.frameworkdemoiselle.internal.proxy; | ||
38 | 38 | ||
39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
40 | import java.util.Map; | 40 | import java.util.Map; |
41 | +import java.util.logging.Logger; | ||
41 | 42 | ||
42 | import javax.persistence.EntityManager; | 43 | import javax.persistence.EntityManager; |
43 | import javax.persistence.EntityManagerFactory; | 44 | import javax.persistence.EntityManagerFactory; |
@@ -51,8 +52,6 @@ import javax.persistence.criteria.CriteriaBuilder; | @@ -51,8 +52,6 @@ import javax.persistence.criteria.CriteriaBuilder; | ||
51 | import javax.persistence.criteria.CriteriaQuery; | 52 | import javax.persistence.criteria.CriteriaQuery; |
52 | import javax.persistence.metamodel.Metamodel; | 53 | import javax.persistence.metamodel.Metamodel; |
53 | 54 | ||
54 | -import org.slf4j.Logger; | ||
55 | - | ||
56 | import br.gov.frameworkdemoiselle.DemoiselleException; | 55 | import br.gov.frameworkdemoiselle.DemoiselleException; |
57 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | 56 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; |
58 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig.EntityManagerScope; | 57 | import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig.EntityManagerScope; |
@@ -69,19 +68,18 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | @@ -69,19 +68,18 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
69 | public class EntityManagerProxy implements EntityManager, Serializable { | 68 | public class EntityManagerProxy implements EntityManager, Serializable { |
70 | 69 | ||
71 | private static final long serialVersionUID = 1L; | 70 | private static final long serialVersionUID = 1L; |
72 | - | 71 | + |
73 | /* | 72 | /* |
74 | * Persistence unit of the delegated EntityManager. | 73 | * Persistence unit of the delegated EntityManager. |
75 | */ | 74 | */ |
76 | private String persistenceUnit; | 75 | private String persistenceUnit; |
77 | - | 76 | + |
78 | /* | 77 | /* |
79 | * demoiselle-jpa configuration options | 78 | * demoiselle-jpa configuration options |
80 | */ | 79 | */ |
81 | private EntityManagerConfig configuration; | 80 | private EntityManagerConfig configuration; |
82 | - | ||
83 | - | ||
84 | - private EntityManager delegateCache; | 81 | + |
82 | + private EntityManager delegateCache; | ||
85 | 83 | ||
86 | /** | 84 | /** |
87 | * Constructor based on persistence unit name. | 85 | * Constructor based on persistence unit name. |
@@ -99,14 +97,15 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -99,14 +97,15 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
99 | * @return Cached EntityManager | 97 | * @return Cached EntityManager |
100 | */ | 98 | */ |
101 | private EntityManager getEntityManagerDelegate() { | 99 | private EntityManager getEntityManagerDelegate() { |
102 | - //Se o produtor de EntityManager não estiver em um escopo, precisamos guardar em cache o EntityManager produzido, | ||
103 | - //do contrário, basta solicitar uma instância do produtor (que estará em um escopo) e obter a instância real | ||
104 | - //de EntityManager dele. | ||
105 | - if (getConfiguration().getEntityManagerScope()!=EntityManagerScope.NOSCOPE || delegateCache==null){ | 100 | + // Se o produtor de EntityManager não estiver em um escopo, precisamos guardar em cache o EntityManager |
101 | + // produzido, | ||
102 | + // do contrário, basta solicitar uma instância do produtor (que estará em um escopo) e obter a instância real | ||
103 | + // de EntityManager dele. | ||
104 | + if (getConfiguration().getEntityManagerScope() != EntityManagerScope.NOSCOPE || delegateCache == null) { | ||
106 | EntityManagerProducer emp = Beans.getReference(EntityManagerProducer.class); | 105 | EntityManagerProducer emp = Beans.getReference(EntityManagerProducer.class); |
107 | delegateCache = emp.getEntityManager(this.persistenceUnit); | 106 | delegateCache = emp.getEntityManager(this.persistenceUnit); |
108 | } | 107 | } |
109 | - | 108 | + |
110 | return delegateCache; | 109 | return delegateCache; |
111 | } | 110 | } |
112 | 111 | ||
@@ -347,7 +346,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -347,7 +346,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
347 | */ | 346 | */ |
348 | @Override | 347 | @Override |
349 | public Query createQuery(String qlString) { | 348 | public Query createQuery(String qlString) { |
350 | - return new QueryProxy(getEntityManagerDelegate().createQuery(qlString) , this) ; | 349 | + return new QueryProxy(getEntityManagerDelegate().createQuery(qlString), this); |
351 | } | 350 | } |
352 | 351 | ||
353 | /* | 352 | /* |
@@ -356,7 +355,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -356,7 +355,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
356 | */ | 355 | */ |
357 | @Override | 356 | @Override |
358 | public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) { | 357 | public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) { |
359 | - return new TypedQueryProxy<T>( getEntityManagerDelegate().createQuery(criteriaQuery) , this ); | 358 | + return new TypedQueryProxy<T>(getEntityManagerDelegate().createQuery(criteriaQuery), this); |
360 | } | 359 | } |
361 | 360 | ||
362 | /* | 361 | /* |
@@ -365,7 +364,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -365,7 +364,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
365 | */ | 364 | */ |
366 | @Override | 365 | @Override |
367 | public <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass) { | 366 | public <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass) { |
368 | - return new TypedQueryProxy<T>(getEntityManagerDelegate().createQuery(qlString, resultClass),this); | 367 | + return new TypedQueryProxy<T>(getEntityManagerDelegate().createQuery(qlString, resultClass), this); |
369 | } | 368 | } |
370 | 369 | ||
371 | /* | 370 | /* |
@@ -383,7 +382,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -383,7 +382,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
383 | */ | 382 | */ |
384 | @Override | 383 | @Override |
385 | public <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass) { | 384 | public <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass) { |
386 | - return new TypedQueryProxy<T>(getEntityManagerDelegate().createNamedQuery(name, resultClass),this); | 385 | + return new TypedQueryProxy<T>(getEntityManagerDelegate().createNamedQuery(name, resultClass), this); |
387 | } | 386 | } |
388 | 387 | ||
389 | /* | 388 | /* |
@@ -410,7 +409,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -410,7 +409,7 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
410 | */ | 409 | */ |
411 | @Override | 410 | @Override |
412 | public Query createNativeQuery(String sqlString, String resultSetMapping) { | 411 | public Query createNativeQuery(String sqlString, String resultSetMapping) { |
413 | - return new QueryProxy(getEntityManagerDelegate().createNativeQuery(sqlString, resultSetMapping),this); | 412 | + return new QueryProxy(getEntityManagerDelegate().createNativeQuery(sqlString, resultSetMapping), this); |
414 | } | 413 | } |
415 | 414 | ||
416 | /* | 415 | /* |
@@ -427,17 +426,16 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -427,17 +426,16 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
427 | */ | 426 | */ |
428 | protected final void joinTransactionIfNecessary() { | 427 | protected final void joinTransactionIfNecessary() { |
429 | try { | 428 | try { |
430 | - /*EntityTransaction transaction = */getEntityManagerDelegate().getTransaction(); | 429 | + /* EntityTransaction transaction = */getEntityManagerDelegate().getTransaction(); |
431 | } catch (IllegalStateException cause) { | 430 | } catch (IllegalStateException cause) { |
432 | - //IllegalStateException is launched if we are on a JTA entity manager, so | ||
433 | - //we assume we need to join transaction instead of creating one. | ||
434 | - | ||
435 | - try{ | 431 | + // IllegalStateException is launched if we are on a JTA entity manager, so |
432 | + // we assume we need to join transaction instead of creating one. | ||
433 | + | ||
434 | + try { | ||
436 | getEntityManagerDelegate().joinTransaction(); | 435 | getEntityManagerDelegate().joinTransaction(); |
437 | - } | ||
438 | - catch(TransactionRequiredException te){ | ||
439 | - //It get's launched if there is no JTA transaction opened. It usually means we are | ||
440 | - //being launched inside a method not marked with @Transactional so we ignore the exception. | 436 | + } catch (TransactionRequiredException te) { |
437 | + // It get's launched if there is no JTA transaction opened. It usually means we are | ||
438 | + // being launched inside a method not marked with @Transactional so we ignore the exception. | ||
441 | } | 439 | } |
442 | } | 440 | } |
443 | } | 441 | } |
@@ -540,51 +538,51 @@ public class EntityManagerProxy implements EntityManager, Serializable { | @@ -540,51 +538,51 @@ public class EntityManagerProxy implements EntityManager, Serializable { | ||
540 | public String toString() { | 538 | public String toString() { |
541 | return getEntityManagerDelegate().toString(); | 539 | return getEntityManagerDelegate().toString(); |
542 | } | 540 | } |
543 | - | ||
544 | - private void checkEntityManagerScopePassivable(Object entity) { | 541 | + |
542 | + private void checkEntityManagerScopePassivable(Object entity) { | ||
545 | EntityManagerConfig configuration = getConfiguration(); | 543 | EntityManagerConfig configuration = getConfiguration(); |
546 | - if (configuration.getEntityManagerScope()==EntityManagerScope.CONVERSATION | ||
547 | - || configuration.getEntityManagerScope()==EntityManagerScope.SESSION | ||
548 | - || configuration.getEntityManagerScope()==EntityManagerScope.VIEW){ | ||
549 | - | 544 | + if (configuration.getEntityManagerScope() == EntityManagerScope.CONVERSATION |
545 | + || configuration.getEntityManagerScope() == EntityManagerScope.SESSION | ||
546 | + || configuration.getEntityManagerScope() == EntityManagerScope.VIEW) { | ||
547 | + | ||
550 | LockModeType lockMode = null; | 548 | LockModeType lockMode = null; |
551 | - if (getEntityManagerDelegate().contains(entity)){ | 549 | + if (getEntityManagerDelegate().contains(entity)) { |
552 | lockMode = getEntityManagerDelegate().getLockMode(entity); | 550 | lockMode = getEntityManagerDelegate().getLockMode(entity); |
553 | } | 551 | } |
554 | checkEntityManagerScopePassivable(lockMode); | 552 | checkEntityManagerScopePassivable(lockMode); |
555 | } | 553 | } |
556 | } | 554 | } |
557 | 555 | ||
558 | - private void checkEntityManagerScopePassivable(LockModeType lockMode) { | 556 | + private void checkEntityManagerScopePassivable(LockModeType lockMode) { |
559 | EntityManagerConfig configuration = getConfiguration(); | 557 | EntityManagerConfig configuration = getConfiguration(); |
560 | - if (configuration.getEntityManagerScope()==EntityManagerScope.CONVERSATION | ||
561 | - || configuration.getEntityManagerScope()==EntityManagerScope.SESSION | ||
562 | - || configuration.getEntityManagerScope()==EntityManagerScope.VIEW){ | ||
563 | - | ||
564 | - if (lockMode!=null | ||
565 | - && lockMode!=LockModeType.NONE | ||
566 | - && lockMode!=LockModeType.OPTIMISTIC_FORCE_INCREMENT){ | ||
567 | - String message = getBundle().getString("passivable-scope-without-optimistic-lock" , configuration.getEntityManagerScope().toString()); | ||
568 | - getLogger().error(message); | 558 | + if (configuration.getEntityManagerScope() == EntityManagerScope.CONVERSATION |
559 | + || configuration.getEntityManagerScope() == EntityManagerScope.SESSION | ||
560 | + || configuration.getEntityManagerScope() == EntityManagerScope.VIEW) { | ||
561 | + | ||
562 | + if (lockMode != null && lockMode != LockModeType.NONE | ||
563 | + && lockMode != LockModeType.OPTIMISTIC_FORCE_INCREMENT) { | ||
564 | + String message = getBundle().getString("passivable-scope-without-optimistic-lock", | ||
565 | + configuration.getEntityManagerScope().toString()); | ||
566 | + getLogger().severe(message); | ||
569 | throw new DemoiselleException(message); | 567 | throw new DemoiselleException(message); |
570 | } | 568 | } |
571 | } | 569 | } |
572 | } | 570 | } |
573 | - | ||
574 | - private EntityManagerConfig getConfiguration(){ | ||
575 | - if (configuration==null){ | 571 | + |
572 | + private EntityManagerConfig getConfiguration() { | ||
573 | + if (configuration == null) { | ||
576 | configuration = Beans.getReference(EntityManagerConfig.class); | 574 | configuration = Beans.getReference(EntityManagerConfig.class); |
577 | } | 575 | } |
578 | - | 576 | + |
579 | return configuration; | 577 | return configuration; |
580 | } | 578 | } |
581 | - | 579 | + |
582 | private Logger getLogger() { | 580 | private Logger getLogger() { |
583 | - return Beans.getReference(Logger.class); | 581 | + return Beans.getReference(Logger.class, new NameQualifier("br.gov.frameworkdemoiselle.util")); |
584 | } | 582 | } |
585 | - | ||
586 | - private ResourceBundle getBundle(){ | ||
587 | - return Beans.getReference(ResourceBundle.class,new NameQualifier("demoiselle-jpa-bundle")); | 583 | + |
584 | + private ResourceBundle getBundle() { | ||
585 | + return Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-jpa-bundle")); | ||
588 | } | 586 | } |
589 | - | 587 | + |
590 | } | 588 | } |