Commit ef6aeb346febc0040e29cee09a30d68e37205f67

Authored by Cleverson Sacramento
2 parents 750b7bea a99f52a3
Exists in master

Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into

2.4.0

Conflicts:
	impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerWithJndiTest.java
	impl/extension/jdbc/src/test/resources/producer/with-jndi/demoiselle.properties
Showing 34 changed files with 1280 additions and 67 deletions   Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationMapValueExtractor.java
... ... @@ -50,6 +50,12 @@ import org.apache.commons.configuration.Configuration;
50 50 import br.gov.frameworkdemoiselle.annotation.Priority;
51 51 import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor;
52 52  
  53 +/**
  54 + *
  55 + * TODO Adicionar verificação da existência de duas ou mais configurações JDBC com mesmo nome. Lançar INFO ou Exceção.
  56 + *
  57 + */
  58 +
53 59 @Priority(L2_PRIORITY)
54 60 public class ConfigurationMapValueExtractor implements ConfigurationValueExtractor {
55 61  
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
... ... @@ -46,15 +46,14 @@ import java.util.Set;
46 46 import javax.enterprise.context.ApplicationScoped;
47 47 import javax.enterprise.context.RequestScoped;
48 48 import javax.inject.Inject;
49   -import javax.management.ReflectionException;
50 49 import javax.validation.ConstraintViolation;
  50 +import javax.validation.ConstraintViolationException;
51 51 import javax.validation.Validation;
52 52 import javax.validation.ValidationException;
53 53 import javax.validation.Validator;
54 54  
55 55 import org.slf4j.Logger;
56 56  
57   -import br.gov.frameworkdemoiselle.DemoiselleException;
58 57 import br.gov.frameworkdemoiselle.annotation.ManagedProperty;
59 58 import br.gov.frameworkdemoiselle.annotation.Name;
60 59 import br.gov.frameworkdemoiselle.internal.context.ContextManager;
... ... @@ -62,6 +61,8 @@ import br.gov.frameworkdemoiselle.internal.context.ManagedContext;
62 61 import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail;
63 62 import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;
64 63 import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
  64 +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
  65 +import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
65 66 import br.gov.frameworkdemoiselle.management.NotificationManager;
66 67 import br.gov.frameworkdemoiselle.stereotype.ManagementController;
67 68 import br.gov.frameworkdemoiselle.util.Beans;
... ... @@ -124,7 +125,7 @@ public class Management implements Serializable {
124 125 * parameters.
125 126 * @return The return value of the original invoked operation. Methods of return type <code>void</code> will return
126 127 * the {@link Void} type.
127   - * @throws ReflectionException
  128 + * @throws ManagedInvokationException
128 129 * In case the operation doesn't exist or have a different signature
129 130 */
130 131 public Object invoke(ManagedType managedType, String actionName, Object[] params) {
... ... @@ -141,16 +142,16 @@ public class Management implements Serializable {
141 142 .getType().getCanonicalName()));
142 143 return method.getMethod().invoke(delegate, params);
143 144 } catch (Exception e) {
144   - throw new DemoiselleException(bundle.getString("management-invoke-error", actionName), e);
  145 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName), e);
145 146 }
146 147 } else {
147   - throw new DemoiselleException(bundle.getString("management-invoke-error", actionName));
  148 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", actionName));
148 149 }
149 150 } finally {
150 151 deactivateContexts(managedType.getType());
151 152 }
152 153 } else {
153   - throw new DemoiselleException(bundle.getString("management-type-not-found"));
  154 + throw new ManagedInvokationException(bundle.getString("management-type-not-found"));
154 155 }
155 156 }
156 157  
... ... @@ -169,6 +170,8 @@ public class Management implements Serializable {
169 170 * @param propertyName
170 171 * The name of the property
171 172 * @return The current value of the property
  173 + * @throws ManagedAttributeNotFoundException If the given property doesn't exist or there was a problem trying to read the property value.
  174 + * @throws ManagedInvokationException If there was an error trying to invoke the getter method to read the propery value.
172 175 */
173 176 public Object getProperty(ManagedType managedType, String propertyName) {
174 177  
... ... @@ -186,16 +189,16 @@ public class Management implements Serializable {
186 189  
187 190 return getterMethod.invoke(delegate, (Object[]) null);
188 191 } catch (Exception e) {
189   - throw new DemoiselleException(bundle.getString("management-invoke-error", getterMethod.getName()),
  192 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", getterMethod.getName()),
190 193 e);
191 194 } finally {
192 195 deactivateContexts(managedType.getType());
193 196 }
194 197 } else {
195   - throw new DemoiselleException(bundle.getString("management-read-value-error", propertyName));
  198 + throw new ManagedAttributeNotFoundException(bundle.getString("management-read-value-error", propertyName));
196 199 }
197 200 } else {
198   - throw new DemoiselleException(bundle.getString("management-type-not-found"));
  201 + throw new ManagedInvokationException(bundle.getString("management-type-not-found"));
199 202 }
200 203 }
201 204  
... ... @@ -215,7 +218,11 @@ public class Management implements Serializable {
215 218 * The name of the property
216 219 * @param newValue
217 220 * The new value of the property
  221 + * @throws ManagedInvokationException If there was an error trying to call the setter method for this property.
  222 + * @throws ManagedAttributeNotFoundException If the giver property doesn't exist or could'n be written to.
  223 + * @throws ConstraintViolationException If the property defined one or more validation constraints and setting this value violates some of those constraints.
218 224 */
  225 + @SuppressWarnings("unchecked")
219 226 public void setProperty(ManagedType managedType, String propertyName, Object newValue) {
220 227  
221 228 if (managedTypes.contains(managedType)) {
... ... @@ -249,9 +256,9 @@ public class Management implements Serializable {
249 256 errorBuffer.insert(errorBuffer.length(), "\r\n");
250 257 }
251 258  
252   - throw new DemoiselleException(bundle.getString(
253   - "management-validation-constraint-violation", managedType.getType()
254   - .getCanonicalName(), propertyName, errorBuffer.toString()));
  259 + throw new ConstraintViolationException(bundle.getString("management-validation-constraint-violation"
  260 + , managedType.getType().getCanonicalName(), propertyName, errorBuffer.toString())
  261 + , (Set<ConstraintViolation<?>>) violations);
255 262 }
256 263 } else {
257 264 logger.warn(bundle.getString("management-validation-validator-not-found"));
... ... @@ -276,19 +283,19 @@ public class Management implements Serializable {
276 283 .getCanonicalName()), propertyName, attributeType, oldValue, newValue);
277 284 notificationManager.sendNotification(notification);
278 285  
279   - } catch (DemoiselleException de) {
280   - throw de;
  286 + } catch (ConstraintViolationException ce) {
  287 + throw ce;
281 288 } catch (Exception e) {
282   - throw new DemoiselleException(bundle.getString("management-invoke-error", method.getName()), e);
  289 + throw new ManagedInvokationException(bundle.getString("management-invoke-error", method.getName()), e);
283 290 } finally {
284 291 deactivateContexts(managedType.getType());
285 292 }
286 293  
287 294 } else {
288   - throw new DemoiselleException(bundle.getString("management-write-value-error", propertyName));
  295 + throw new ManagedAttributeNotFoundException(bundle.getString("management-write-value-error", propertyName));
289 296 }
290 297 } else {
291   - throw new DemoiselleException(bundle.getString("management-type-not-found"));
  298 + throw new ManagedInvokationException(bundle.getString("management-type-not-found"));
292 299 }
293 300  
294 301 }
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagedAttributeNotFoundException.java 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +package br.gov.frameworkdemoiselle.management;
  2 +
  3 +import br.gov.frameworkdemoiselle.DemoiselleException;
  4 +
  5 +/**
  6 + *
  7 + * Thrown when a management client tries to read or write a property, but the
  8 + * management engine has no knowledge of an attribute with the given name.
  9 + *
  10 + * @author serpro
  11 + *
  12 + */
  13 +public class ManagedAttributeNotFoundException extends DemoiselleException {
  14 +
  15 + private static final long serialVersionUID = 2554101387574235418L;
  16 +
  17 + public ManagedAttributeNotFoundException(String message, Throwable cause) {
  18 + super(message, cause);
  19 + }
  20 +
  21 + public ManagedAttributeNotFoundException(String message) {
  22 + super(message);
  23 + }
  24 +
  25 + public ManagedAttributeNotFoundException(Throwable cause) {
  26 + super(cause);
  27 + }
  28 +
  29 +}
... ...
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/ManagedInvokationException.java 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +package br.gov.frameworkdemoiselle.management;
  2 +
  3 +import br.gov.frameworkdemoiselle.DemoiselleException;
  4 +
  5 +
  6 +public class ManagedInvokationException extends DemoiselleException {
  7 +
  8 + private static final long serialVersionUID = -1542365184737242152L;
  9 +
  10 + public ManagedInvokationException(String message, Throwable cause) {
  11 + super(message, cause);
  12 + }
  13 +
  14 + public ManagedInvokationException(String message) {
  15 + super(message);
  16 + }
  17 +
  18 + public ManagedInvokationException(Throwable cause) {
  19 + super(cause);
  20 + }
  21 +
  22 +
  23 +}
... ...
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ConnectionProducer.java
... ... @@ -37,6 +37,7 @@ public class ConnectionProducer implements Serializable {
37 37 private ResourceBundle bundle;
38 38  
39 39 private final Map<String, Connection> cache = Collections.synchronizedMap(new HashMap<String, Connection>());
  40 + private final Map<Connection,Status> statusCache = Collections.synchronizedMap(new HashMap<Connection, Status>());
40 41  
41 42 @Inject
42 43 private DataSourceProducer producer;
... ... @@ -79,6 +80,7 @@ public class ConnectionProducer implements Serializable {
79 80 disableAutoCommit(connection);
80 81  
81 82 cache.put(name, connection);
  83 + statusCache.put(connection, new Status());
82 84 logger.info(bundle.getString("connection-was-created", name));
83 85  
84 86 } catch (Exception cause) {
... ... @@ -150,5 +152,34 @@ public class ConnectionProducer implements Serializable {
150 152 public Map<String, Connection> getCache() {
151 153 return cache;
152 154 }
  155 +
  156 + public Status getStatus(Connection connection) {
  157 + return statusCache.get(connection);
  158 + }
  159 +
  160 + public static class Status implements Serializable {
  161 +
  162 + private static final long serialVersionUID = 1L;
  163 +
  164 + private boolean active = false;
  165 +
  166 + private boolean markedRollback = false;
  167 +
  168 + public boolean isActive() {
  169 + return active;
  170 + }
  171 +
  172 + public void setActive(boolean active) {
  173 + this.active = active;
  174 + }
  175 +
  176 + public boolean isMarkedRollback() {
  177 + return markedRollback;
  178 + }
  179 +
  180 + public void setRollbackOnly(boolean markedRollback) {
  181 + this.markedRollback = markedRollback;
  182 + }
  183 + }
153 184  
154 185 }
... ...
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java
... ... @@ -25,6 +25,12 @@ import br.gov.frameworkdemoiselle.internal.proxy.BasicDataSourceProxy;
25 25 import br.gov.frameworkdemoiselle.util.Beans;
26 26 import br.gov.frameworkdemoiselle.util.ResourceBundle;
27 27  
  28 +/**
  29 + *
  30 + * TODO Verificar métodos públicos que só são usados dentro do pacote. Ajustar o modificador de acesso.
  31 + *
  32 + */
  33 +
28 34 @ApplicationScoped
29 35 public class DataSourceProducer implements Serializable {
30 36  
... ...
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/ConnectionProxy.java
... ... @@ -27,7 +27,7 @@ public class ConnectionProxy implements Connection, Serializable {
27 27 private static final long serialVersionUID = 1L;
28 28  
29 29 private final String dataSourceName;
30   -
  30 +
31 31 public ConnectionProxy(String dataSourceName) {
32 32 this.dataSourceName = dataSourceName;
33 33 }
... ... @@ -236,4 +236,5 @@ public class ConnectionProxy implements Connection, Serializable {
236 236 public <T> T unwrap(Class<T> iface) throws SQLException {
237 237 return getDelegate().unwrap(iface);
238 238 }
  239 +
239 240 }
... ...
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/transaction/JDBCTransaction.java
... ... @@ -38,16 +38,13 @@ package br.gov.frameworkdemoiselle.transaction;
38 38  
39 39 import static br.gov.frameworkdemoiselle.annotation.Priority.L2_PRIORITY;
40 40  
41   -import java.io.Serializable;
42 41 import java.sql.Connection;
43 42 import java.util.Collection;
44   -import java.util.Collections;
45   -import java.util.HashMap;
46   -import java.util.Map;
47 43  
48 44 import br.gov.frameworkdemoiselle.DemoiselleException;
49 45 import br.gov.frameworkdemoiselle.annotation.Priority;
50 46 import br.gov.frameworkdemoiselle.internal.producer.ConnectionProducer;
  47 +import br.gov.frameworkdemoiselle.internal.producer.ConnectionProducer.Status;
51 48 import br.gov.frameworkdemoiselle.util.Beans;
52 49  
53 50 /**
... ... @@ -63,17 +60,9 @@ public class JDBCTransaction implements Transaction {
63 60  
64 61 private ConnectionProducer producer;
65 62  
66   - private Map<Connection, Status> cache = Collections.synchronizedMap(new HashMap<Connection, Status>());
67   -
68 63 private ConnectionProducer getProducer() {
69 64 if (producer == null) {
70 65 producer = Beans.getReference(ConnectionProducer.class);
71   -
72   - for (Connection connection : producer.getCache().values()) {
73   - if (!cache.containsKey(connection)) {
74   - cache.put(connection, new Status());
75   - }
76   - }
77 66 }
78 67  
79 68 return producer;
... ... @@ -87,7 +76,7 @@ public class JDBCTransaction implements Transaction {
87 76 public void begin() {
88 77 Status status;
89 78 for (Connection connection : getDelegate()) {
90   - status = cache.get(connection);
  79 + status = getProducer().getStatus(connection);
91 80 status.setActive(true);
92 81 }
93 82 }
... ... @@ -97,9 +86,13 @@ public class JDBCTransaction implements Transaction {
97 86 */
98 87 @Override
99 88 public void commit() {
  89 + Status status;
  90 +
100 91 for (Connection connection : getDelegate()) {
101 92 try {
102 93 connection.commit();
  94 + status = getProducer().getStatus(connection);
  95 + status.setActive(false);
103 96 } catch (Exception cause) {
104 97 throw new DemoiselleException(cause);
105 98 }
... ... @@ -111,9 +104,13 @@ public class JDBCTransaction implements Transaction {
111 104 */
112 105 @Override
113 106 public void rollback() {
  107 + Status status;
  108 +
114 109 for (Connection connection : getDelegate()) {
115 110 try {
116 111 connection.rollback();
  112 + status = getProducer().getStatus(connection);
  113 + status.setActive(false);
117 114 } catch (Exception cause) {
118 115 throw new DemoiselleException(cause);
119 116 }
... ... @@ -124,7 +121,7 @@ public class JDBCTransaction implements Transaction {
124 121 public void setRollbackOnly() {
125 122 Status status;
126 123 for (Connection connection : getDelegate()) {
127   - status = cache.get(connection);
  124 + status = getProducer().getStatus(connection);
128 125 status.setRollbackOnly(true);
129 126 }
130 127 }
... ... @@ -135,7 +132,7 @@ public class JDBCTransaction implements Transaction {
135 132 boolean result = true;
136 133  
137 134 for (Connection connection : getDelegate()) {
138   - status = cache.get(connection);
  135 + status = getProducer().getStatus(connection);
139 136 result = result && status.isActive();
140 137 }
141 138  
... ... @@ -148,35 +145,10 @@ public class JDBCTransaction implements Transaction {
148 145 boolean result = true;
149 146  
150 147 for (Connection connection : getDelegate()) {
151   - status = cache.get(connection);
  148 + status = getProducer().getStatus(connection);
152 149 result = result && status.isMarkedRollback();
153 150 }
154 151  
155 152 return result;
156 153 }
157   -
158   - private static class Status implements Serializable {
159   -
160   - private static final long serialVersionUID = 1L;
161   -
162   - private boolean active = false;
163   -
164   - private boolean markedRollback = false;
165   -
166   - public boolean isActive() {
167   - return active;
168   - }
169   -
170   - public void setActive(boolean active) {
171   - this.active = active;
172   - }
173   -
174   - public boolean isMarkedRollback() {
175   - return markedRollback;
176   - }
177   -
178   - public void setRollbackOnly(boolean markedRollback) {
179   - this.markedRollback = markedRollback;
180   - }
181   - }
182 154 }
... ...
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerMultipleConnectionsTest.java
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
1 37 package connection.producer;
2 38  
3 39 import static org.junit.Assert.assertEquals;
... ...
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerNoConnectionDriverTest.java
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
1 37 package connection.producer;
2 38  
3 39 import java.sql.Connection;
... ...
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerNoConnectionUrlTest.java
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
1 37 package connection.producer;
2 38  
3 39 import java.sql.Connection;
... ...
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerWithJndiTest.java
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
1 37 package connection.producer;
2 38  
3 39 import static org.junit.Assert.assertEquals;
... ...
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerWithNameTest.java
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
1 37 package connection.producer;
2 38  
3 39 import static org.junit.Assert.assertNotNull;
... ...
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerWithoutJndiTest.java
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
1 37 package connection.producer;
2 38  
3 39 import java.sql.Connection;
... ...
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerWithoutNameTest.java
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
1 37 package connection.producer;
2 38  
3 39 import static org.junit.Assert.assertNotNull;
... ...
impl/extension/jdbc/src/test/java/transaction/DDL.java 0 → 100644
... ... @@ -0,0 +1,86 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package transaction;
  38 +
  39 +import java.sql.Connection;
  40 +import java.sql.PreparedStatement;
  41 +import java.sql.Statement;
  42 +
  43 +import javax.inject.Inject;
  44 +
  45 +import br.gov.frameworkdemoiselle.annotation.Name;
  46 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  47 +
  48 +public class DDL {
  49 +
  50 + @Name("conn1")
  51 + @Inject
  52 + private Connection connection;
  53 +
  54 + @Transactional
  55 + public void dropAndCreate() throws Exception {
  56 + dropTable();
  57 + createTable();
  58 + }
  59 +
  60 + private void dropTable() throws Exception {
  61 +
  62 + Statement st = connection.createStatement();
  63 +
  64 + try {
  65 + String sql = "DROP TABLE myentity";
  66 + st.executeUpdate(sql);
  67 + st.close();
  68 + } catch (Exception e) {
  69 +
  70 + }
  71 + }
  72 +
  73 + private void createTable() throws Exception {
  74 + StringBuffer sql = new StringBuffer();
  75 +
  76 + sql.append("CREATE TABLE myentity ( ");
  77 + sql.append(" id int NOT NULL, ");
  78 + sql.append(" description varchar(10) NOT NULL, ");
  79 + sql.append("CONSTRAINT myentity_pk PRIMARY KEY (id) ");
  80 + sql.append("); ");
  81 +
  82 + PreparedStatement pstmt = connection.prepareStatement(sql.toString());
  83 + pstmt.execute();
  84 + pstmt.close();
  85 + }
  86 +}
... ...
impl/extension/jdbc/src/test/java/transaction/MyEntity1.java 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package transaction;
  38 +
  39 +public class MyEntity1 {
  40 +
  41 + private int id;
  42 +
  43 + private String description;
  44 +
  45 + public int getId() {
  46 + return id;
  47 + }
  48 +
  49 + public void setId(int id) {
  50 + this.id = id;
  51 + }
  52 +
  53 + public String getDescription() {
  54 + return description;
  55 + }
  56 +
  57 + public void setDescription(String description) {
  58 + this.description = description;
  59 + }
  60 +}
... ...
impl/extension/jdbc/src/test/java/transaction/TransactionTest.java 0 → 100644
... ... @@ -0,0 +1,136 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +
  38 +package transaction;
  39 +
  40 +import javax.inject.Inject;
  41 +
  42 +import junit.framework.Assert;
  43 +
  44 +import org.jboss.arquillian.container.test.api.Deployment;
  45 +import org.jboss.arquillian.junit.Arquillian;
  46 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  47 +import org.junit.Before;
  48 +import org.junit.Test;
  49 +import org.junit.runner.RunWith;
  50 +
  51 +import test.Tests;
  52 +import br.gov.frameworkdemoiselle.transaction.JDBCTransaction;
  53 +import br.gov.frameworkdemoiselle.transaction.Transaction;
  54 +import br.gov.frameworkdemoiselle.transaction.TransactionContext;
  55 +
  56 +@RunWith(Arquillian.class)
  57 +public class TransactionTest {
  58 +
  59 + private static String PATH = "src/test/resources/transaction";
  60 +
  61 + @Inject
  62 + private TransactionalBusiness tb;
  63 +
  64 + private Transaction transaction;
  65 +
  66 + @Inject
  67 + private TransactionContext context;
  68 +
  69 + @Inject
  70 + private DDL ddl;
  71 +
  72 + @Deployment
  73 + public static WebArchive createDeployment() {
  74 + WebArchive deployment = Tests.createDeployment(TransactionTest.class);
  75 + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties");
  76 + return deployment;
  77 + }
  78 +
  79 + @Before
  80 + public void init() throws Exception {
  81 + transaction = context.getCurrentTransaction();
  82 + ddl.dropAndCreate();
  83 + transaction.commit();
  84 + }
  85 +
  86 + @Test
  87 + public void isTransactionActiveWithInterceptor() {
  88 + Assert.assertTrue(tb.isTransactionActiveWithInterceptor());
  89 + }
  90 +
  91 + @Test
  92 + public void isTransactionActiveWithoutInterceptor() {
  93 + Assert.assertFalse(tb.isTransactionActiveWithoutInterceptor());
  94 + }
  95 +
  96 + @Test
  97 + public void verifyIfTransactionIsJdbcTransaction() {
  98 + Assert.assertEquals(transaction.getClass(), JDBCTransaction.class);
  99 + }
  100 +
  101 + @Test
  102 + public void verifyIfTransactionIsActive() {
  103 + Assert.assertTrue(!transaction.isActive());
  104 + transaction.begin();
  105 + Assert.assertTrue(transaction.isActive());
  106 + }
  107 +
  108 + @Test
  109 + public void commitWithSuccess() throws Exception{
  110 +
  111 + MyEntity1 m1 = new MyEntity1();
  112 + m1.setId(1);
  113 + m1.setDescription("desc-1");
  114 +
  115 + tb.insert(m1);
  116 +
  117 + Assert.assertEquals("desc-1", tb.find(m1.getId()).getDescription());
  118 +
  119 + tb.delete(m1);
  120 +
  121 + Assert.assertNull(tb.find(m1.getId()).getDescription());
  122 + }
  123 +
  124 + @Test
  125 + public void rollbackWithSuccess() throws Exception {
  126 + try{
  127 + tb.rollbackWithSuccess();
  128 + } catch (Exception e) {
  129 + Assert.assertEquals("Exceção criada para marcar transação para rollback", e.getMessage());
  130 + }
  131 + finally{
  132 + MyEntity1 m1 = tb.find(3);
  133 + Assert.assertNull(tb.find(m1.getId()).getDescription());
  134 + }
  135 + }
  136 +}
... ...
impl/extension/jdbc/src/test/java/transaction/TransactionalBusiness.java 0 → 100644
... ... @@ -0,0 +1,111 @@
  1 +/*
  2 + * Demoiselle Framework
  3 + * Copyright (C) 2010 SERPRO
  4 + * ----------------------------------------------------------------------------
  5 + * This file is part of Demoiselle Framework.
  6 + *
  7 + * Demoiselle Framework is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public License version 3
  9 + * as published by the Free Software Foundation.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU Lesser General Public License version 3
  17 + * along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + * or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + * Fifth Floor, Boston, MA 02110-1301, USA.
  20 + * ----------------------------------------------------------------------------
  21 + * Este arquivo é parte do Framework Demoiselle.
  22 + *
  23 + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + * do Software Livre (FSF).
  26 + *
  27 + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + * para maiores detalhes.
  31 + *
  32 + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + * ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 + */
  37 +package transaction;
  38 +
  39 +import java.sql.Connection;
  40 +import java.sql.ResultSet;
  41 +import java.sql.Statement;
  42 +
  43 +import javax.inject.Inject;
  44 +
  45 +import br.gov.frameworkdemoiselle.annotation.Name;
  46 +import br.gov.frameworkdemoiselle.transaction.TransactionContext;
  47 +import br.gov.frameworkdemoiselle.transaction.Transactional;
  48 +
  49 +public class TransactionalBusiness {
  50 +
  51 + @Inject
  52 + @Name("conn1")
  53 + private Connection conn1;
  54 +
  55 + @Inject
  56 + private TransactionContext transactionContext;
  57 +
  58 + @Transactional
  59 + public boolean isTransactionActiveWithInterceptor() {
  60 + return transactionContext.getCurrentTransaction().isActive();
  61 + }
  62 +
  63 + public boolean isTransactionActiveWithoutInterceptor() {
  64 + return transactionContext.getCurrentTransaction().isActive();
  65 + }
  66 +
  67 + @Transactional
  68 + public void insert(MyEntity1 m) throws Exception {
  69 + String sql = "insert into myentity (id, description) values (" + m.getId() + ", '" + m.getDescription() + "')";
  70 + Statement st = conn1.createStatement();
  71 + st.executeUpdate(sql);
  72 + st.close();
  73 + }
  74 +
  75 + @Transactional
  76 + public void delete(MyEntity1 m1) throws Exception {
  77 + String sql = "delete from myentity where id = " + m1.getId();
  78 + Statement st = conn1.createStatement();
  79 + st.executeUpdate(sql);
  80 + st.close();
  81 + }
  82 +
  83 + @Transactional
  84 + public MyEntity1 find(int id) throws Exception {
  85 + String sql = "select * from myentity where id = " + id;
  86 + Statement st = conn1.createStatement();
  87 + ResultSet rs = st.executeQuery(sql);
  88 +
  89 + MyEntity1 m1 = new MyEntity1();
  90 + while (rs.next()) {
  91 + m1.setId(rs.getInt(1));
  92 + m1.setDescription(rs.getString(2));
  93 + }
  94 +
  95 + rs.close();
  96 + st.close();
  97 +
  98 + return m1;
  99 + }
  100 +
  101 + @Transactional
  102 + public void rollbackWithSuccess() throws Exception {
  103 + MyEntity1 m1 = new MyEntity1();
  104 + m1.setId(3);
  105 +
  106 + this.insert(m1);
  107 +
  108 + throw new Exception("Exceção criada para marcar transação para rollback");
  109 + }
  110 +
  111 +}
... ...
impl/extension/jdbc/src/test/resources/producer/multiple-connections/demoiselle.properties
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  35 +
1 36 frameworkdemoiselle.persistence.conn1.driver.class=org.hsqldb.jdbcDriver
2 37 frameworkdemoiselle.persistence.conn1.url=jdbc:hsqldb:hsql1
3 38 frameworkdemoiselle.persistence.conn1.username=sa
... ... @@ -15,4 +50,4 @@ frameworkdemoiselle.persistence.conn3.password=
15 50  
16 51 frameworkdemoiselle.persistence.conn4.jndi.name=java:jboss/datasources/ExampleDS
17 52  
18   -frameworkdemoiselle.persistence.default.datasource.name=conn3
19 53 \ No newline at end of file
  54 +frameworkdemoiselle.persistence.default.datasource.name=conn3
... ...
impl/extension/jdbc/src/test/resources/producer/no-connection-driver/demoiselle.properties
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  35 +
1 36 frameworkdemoiselle.persistence.conn1.url=jdbc:hsqldb:hsql5
2 37 frameworkdemoiselle.persistence.conn1.username=sa
3 38 frameworkdemoiselle.persistence.conn1.password=
4 39 \ No newline at end of file
... ...
impl/extension/jdbc/src/test/resources/producer/no-connection-url/demoiselle.properties
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  35 +
1 36 frameworkdemoiselle.persistence.conn1.driver.class=org.hsqldb.jdbcDriver
2 37 frameworkdemoiselle.persistence.conn1.username=sa
3 38 frameworkdemoiselle.persistence.conn1.password=
4 39 \ No newline at end of file
... ...
impl/extension/jdbc/src/test/resources/producer/with-jndi/demoiselle.properties
1   -frameworkdemoiselle.persistence.conn1.jndi.name=java:jboss/datasources/ExampleDS
2 1 \ No newline at end of file
  2 +# Demoiselle Framework
  3 +# Copyright (C) 2010 SERPRO
  4 +# ----------------------------------------------------------------------------
  5 +# This file is part of Demoiselle Framework.
  6 +#
  7 +# Demoiselle Framework is free software; you can redistribute it and/or
  8 +# modify it under the terms of the GNU Lesser General Public License version 3
  9 +# as published by the Free Software Foundation.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU Lesser General Public License version 3
  17 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  18 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 +# Fifth Floor, Boston, MA 02110-1301, USA.
  20 +# ----------------------------------------------------------------------------
  21 +# Este arquivo é parte do Framework Demoiselle.
  22 +#
  23 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 +# do Software Livre (FSF).
  26 +#
  27 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 +# para maiores detalhes.
  31 +#
  32 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +
  37 +frameworkdemoiselle.persistence.conn1.jndi.name=java:jboss/datasources/ExampleDS
... ...
impl/extension/jdbc/src/test/resources/producer/with-name/demoiselle.properties
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  35 +
1 36 frameworkdemoiselle.persistence.conn1.driver.class=org.hsqldb.jdbcDriver
2 37 frameworkdemoiselle.persistence.conn1.url=jdbc:hsqldb:hsql
3 38 frameworkdemoiselle.persistence.conn1.username=sa
... ...
impl/extension/jdbc/src/test/resources/producer/without-jndi/demoiselle.properties
... ... @@ -0,0 +1,34 @@
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
0 35 \ No newline at end of file
... ...
impl/extension/jdbc/src/test/resources/producer/without-name/demoiselle.properties
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  35 +
1 36 frameworkdemoiselle.persistence.driver.class=org.hsqldb.jdbcDriver
2 37 frameworkdemoiselle.persistence.url=jdbc:hsqldb:hsql
3 38 frameworkdemoiselle.persistence.username=sa
... ...
impl/extension/jdbc/src/test/resources/transaction/demoiselle.properties 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +# Demoiselle Framework
  2 +# Copyright (C) 2010 SERPRO
  3 +# ----------------------------------------------------------------------------
  4 +# This file is part of Demoiselle Framework.
  5 +#
  6 +# Demoiselle Framework is free software; you can redistribute it and/or
  7 +# modify it under the terms of the GNU Lesser General Public License version 3
  8 +# as published by the Free Software Foundation.
  9 +#
  10 +# This program is distributed in the hope that it will be useful,
  11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +# GNU General Public License for more details.
  14 +#
  15 +# You should have received a copy of the GNU Lesser General Public License version 3
  16 +# along with this program; if not, see <http://www.gnu.org/licenses/>
  17 +# or write to the Free Software Foundation, Inc., 51 Franklin Street,
  18 +# Fifth Floor, Boston, MA 02110-1301, USA.
  19 +# ----------------------------------------------------------------------------
  20 +# Este arquivo é parte do Framework Demoiselle.
  21 +#
  22 +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  23 +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  24 +# do Software Livre (FSF).
  25 +#
  26 +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  27 +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  28 +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  29 +# para maiores detalhes.
  30 +#
  31 +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  32 +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  33 +# ou escreva para a Fundação do Software Livre (FSF) Inc.,
  34 +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  35 +
  36 +frameworkdemoiselle.persistence.conn1.driver.class=org.hsqldb.jdbcDriver
  37 +frameworkdemoiselle.persistence.conn1.url=jdbc:hsqldb:hsql
  38 +frameworkdemoiselle.persistence.conn1.username=sa
  39 +frameworkdemoiselle.persistence.conn1.password=
0 40 \ No newline at end of file
... ...
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/internal/DynamicMBeanProxy.java
... ... @@ -58,6 +58,8 @@ import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail;
58 58 import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail;
59 59 import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail;
60 60 import br.gov.frameworkdemoiselle.internal.management.Management;
  61 +import br.gov.frameworkdemoiselle.management.ManagedAttributeNotFoundException;
  62 +import br.gov.frameworkdemoiselle.management.ManagedInvokationException;
61 63 import br.gov.frameworkdemoiselle.stereotype.ManagementController;
62 64 import br.gov.frameworkdemoiselle.util.Beans;
63 65 import br.gov.frameworkdemoiselle.util.ResourceBundle;
... ... @@ -95,7 +97,21 @@ public class DynamicMBeanProxy implements DynamicMBean {
95 97 }
96 98  
97 99 Management manager = Beans.getReference(Management.class);
98   - return manager.getProperty(managedType, attribute);
  100 +
  101 + try{
  102 + return manager.getProperty(managedType, attribute);
  103 + }
  104 + catch(DemoiselleException de){
  105 + if (ManagedAttributeNotFoundException.class.isInstance(de)){
  106 + throw new AttributeNotFoundException(de.getMessage());
  107 + }
  108 + else if (ManagedInvokationException.class.isInstance(de)){
  109 + throw new MBeanException(new Exception(de.getMessage()));
  110 + }
  111 + else{
  112 + throw de;
  113 + }
  114 + }
99 115 }
100 116  
101 117 @Override
... ... @@ -108,7 +124,21 @@ public class DynamicMBeanProxy implements DynamicMBean {
108 124 }
109 125  
110 126 Management manager = Beans.getReference(Management.class);
111   - manager.setProperty(managedType, attribute.getName(), attribute.getValue());
  127 +
  128 + try{
  129 + manager.setProperty(managedType, attribute.getName(), attribute.getValue());
  130 + }
  131 + catch(DemoiselleException de){
  132 + if (ManagedAttributeNotFoundException.class.isInstance(de)){
  133 + throw new AttributeNotFoundException(de.getMessage());
  134 + }
  135 + else if (ManagedInvokationException.class.isInstance(de)){
  136 + throw new MBeanException(new Exception(de.getMessage()));
  137 + }
  138 + else{
  139 + throw de;
  140 + }
  141 + }
112 142 }
113 143  
114 144 @Override
... ... @@ -161,7 +191,13 @@ public class DynamicMBeanProxy implements DynamicMBean {
161 191 }
162 192  
163 193 Management manager = Beans.getReference(Management.class);
164   - return manager.invoke(managedType, actionName, params);
  194 +
  195 + try{
  196 + return manager.invoke(managedType, actionName, params);
  197 + }
  198 + catch(DemoiselleException de){
  199 + throw new MBeanException(new Exception(de.getMessage()));
  200 + }
165 201 }
166 202  
167 203 /**
... ...
impl/extension/jpa/src/test/java/productor/MyEntity.java 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +package productor;
  2 +
  3 +import javax.persistence.Entity;
  4 +import javax.persistence.Id;
  5 +
  6 +@Entity
  7 +public class MyEntity {
  8 +
  9 + @Id
  10 + private String id;
  11 +
  12 + private String description;
  13 +
  14 + public String getId() {
  15 + return id;
  16 + }
  17 +
  18 + public void setId(String id) {
  19 + this.id = id;
  20 + }
  21 +
  22 + public String getDescription() {
  23 + return description;
  24 + }
  25 +
  26 + public void setDescription(String description) {
  27 + this.description = description;
  28 + }
  29 +}
... ...
impl/extension/jpa/src/test/java/productor/ProductorTest.java 0 → 100644
... ... @@ -0,0 +1,80 @@
  1 +package productor;
  2 +
  3 +import javax.persistence.EntityManager;
  4 +
  5 +import org.jboss.arquillian.container.test.api.Deployment;
  6 +import org.jboss.arquillian.junit.Arquillian;
  7 +import org.jboss.shrinkwrap.api.spec.WebArchive;
  8 +import org.junit.Assert;
  9 +import org.junit.Test;
  10 +import org.junit.runner.RunWith;
  11 +
  12 +import test.Tests;
  13 +import br.gov.frameworkdemoiselle.internal.proxy.EntityManagerProxy;
  14 +import br.gov.frameworkdemoiselle.util.Beans;
  15 +import br.gov.frameworkdemoiselle.util.NameQualifier;
  16 +
  17 +
  18 +@RunWith(Arquillian.class)
  19 +public class ProductorTest {
  20 +
  21 + private static final String PATH = "src/test/resources/productor";
  22 +
  23 + @Deployment
  24 + public static WebArchive createDeployment() {
  25 + WebArchive deployment = Tests.createDeployment(ProductorTest.class);
  26 + deployment.addAsResource(Tests.createFileAsset(PATH + "/persistence.xml"), "META-INF/persistence.xml");
  27 + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties");
  28 +
  29 + return deployment;
  30 + }
  31 +
  32 + @Test
  33 + public void produceEntityManager(){
  34 +
  35 + EntityManager manager = Beans.getReference(EntityManager.class);
  36 + Assert.assertNotNull(manager);
  37 + Assert.assertEquals(EntityManagerProxy.class,manager.getClass());
  38 +
  39 + }
  40 +
  41 + @Test
  42 + public void produceMultipleEntityManagers(){
  43 +
  44 + EntityManager m1 = Beans.getReference(EntityManager.class,new NameQualifier("pu"));
  45 +
  46 + Assert.assertNotNull(m1);
  47 + Assert.assertEquals(EntityManagerProxy.class,m1.getClass());
  48 +
  49 + EntityManager m2 = Beans.getReference(EntityManager.class,new NameQualifier("pu2"));
  50 +
  51 + Assert.assertNotNull(m2);
  52 + Assert.assertEquals(EntityManagerProxy.class,m2.getClass());
  53 +
  54 + }
  55 +
  56 + @Test
  57 + public void produceOneEntityManagerPerRequest(){
  58 + EntityManager m1 = Beans.getReference(EntityManager.class,new NameQualifier("pu"));
  59 +
  60 + Assert.assertNotNull(m1);
  61 + Assert.assertEquals(EntityManagerProxy.class,m1.getClass());
  62 +
  63 + EntityManager m2 = Beans.getReference(EntityManager.class,new NameQualifier("pu"));
  64 +
  65 + Assert.assertNotNull(m2);
  66 + Assert.assertEquals(EntityManagerProxy.class,m2.getClass());
  67 +
  68 + MyEntity entity = new MyEntity();
  69 + entity.setId(createId("testID"));
  70 +
  71 + m1.persist(entity);
  72 +
  73 + Assert.assertTrue( m2.contains(entity) );
  74 + }
  75 +
  76 + private String createId(String id) {
  77 + return this.getClass().getName() + "_" + id;
  78 + }
  79 +
  80 +}
... ...
impl/extension/jpa/src/test/java/transaction/interceptor/JPATransactionTest.java
... ... @@ -82,8 +82,8 @@ public class JPATransactionTest {
82 82 Assert.assertEquals("Exceção criada para marcar transação para rollback", e.getMessage());
83 83 }
84 84 finally{
85   - MyEntity1 entity1 = em1.find(MyEntity1.class, tb.createId("id-1"));
86   - MyEntity2 entity2 = em2.find(MyEntity2.class, tb.createId("id-2"));
  85 + MyEntity1 entity1 = em1.find(MyEntity1.class, tb.createId("id-3"));
  86 + MyEntity2 entity2 = em2.find(MyEntity2.class, tb.createId("id-4"));
87 87  
88 88 Assert.assertNull(entity1);
89 89 Assert.assertNull(entity2);
... ...
impl/extension/jpa/src/test/resources/productor/demoiselle.properties 0 → 100644
... ... @@ -0,0 +1 @@
  1 +frameworkdemoiselle.persistence.default.unit.name=pu
0 2 \ No newline at end of file
... ...
impl/extension/jpa/src/test/resources/productor/persistence.xml 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +<!--
  2 + Demoiselle Framework
  3 + Copyright (C) 2010 SERPRO
  4 + ============================================================================
  5 + This file is part of Demoiselle Framework.
  6 +
  7 + Demoiselle Framework is free software; you can redistribute it and/or
  8 + modify it under the terms of the GNU Lesser General Public License version 3
  9 + as published by the Free Software Foundation.
  10 +
  11 + This program is distributed in the hope that it will be useful,
  12 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + GNU General Public License for more details.
  15 +
  16 + You should have received a copy of the GNU Lesser General Public License version 3
  17 + along with this program; if not, see <http://www.gnu.org/licenses/>
  18 + or write to the Free Software Foundation, Inc., 51 Franklin Street,
  19 + Fifth Floor, Boston, MA 02110-1301, USA.
  20 + ============================================================================
  21 + Este arquivo é parte do Framework Demoiselle.
  22 +
  23 + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
  24 + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
  25 + do Software Livre (FSF).
  26 +
  27 + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
  28 + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
  29 + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
  30 + para maiores detalhes.
  31 +
  32 + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
  33 + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
  34 + ou escreva para a Fundação do Software Livre (FSF) Inc.,
  35 + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
  36 +-->
  37 +<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38 + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  39 +
  40 + <persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
  41 + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
  42 +
  43 + <class>productor.MyEntity</class>
  44 +
  45 + <properties>
  46 + <property name="hibernate.show_sql" value="true" />
  47 + <property name="hibernate.format_sql" value="false" />
  48 + <property name="hibernate.hbm2ddl.auto" value="create-drop" />
  49 + </properties>
  50 + </persistence-unit>
  51 +
  52 + <persistence-unit name="pu2" transaction-type="RESOURCE_LOCAL">
  53 + <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
  54 +
  55 + <class>productor.MyEntity</class>
  56 +
  57 + <properties>
  58 + <property name="hibernate.show_sql" value="true" />
  59 + <property name="hibernate.format_sql" value="false" />
  60 + <property name="hibernate.hbm2ddl.auto" value="create-drop" />
  61 + </properties>
  62 + </persistence-unit>
  63 +
  64 +</persistence>
0 65 \ No newline at end of file
... ...
parent/bom/pom.xml
... ... @@ -107,7 +107,7 @@
107 107 <dependency>
108 108 <groupId>br.gov.frameworkdemoiselle</groupId>
109 109 <artifactId>demoiselle-jmx</artifactId>
110   - <version>2.4.0-BETA2-SNAPSHOT</version>
  110 + <version>2.4.0-BETA4-SNAPSHOT</version>
111 111 </dependency>
112 112 <!--
113 113 <dependency>
... ...