Commit bdc8ac626a1512f63e46a74d3fee42f9fd12a957
1 parent
841de0ec
Exists in
master
Tratamento de problemas de configuração da aplicação
Showing
3 changed files
with
12 additions
and
9 deletions
Show diff stats
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ConnectionProducer.java
| ... | ... | @@ -70,8 +70,7 @@ public class ConnectionProducer implements Serializable { |
| 70 | 70 | logger.info(bundle.getString("connection-was-created", name)); |
| 71 | 71 | |
| 72 | 72 | } catch (Exception cause) { |
| 73 | - // TODO Colocar uma mensagem amigável | |
| 74 | - throw new DemoiselleException(cause); | |
| 73 | + throw new DemoiselleException(bundle.getString("connection-creation-failed", name), cause); | |
| 75 | 74 | } |
| 76 | 75 | } |
| 77 | 76 | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java
| ... | ... | @@ -110,25 +110,27 @@ public class DataSourceProducer implements Serializable { |
| 110 | 110 | DataSource result; |
| 111 | 111 | |
| 112 | 112 | JDBCConfig config = Beans.getReference(JDBCConfig.class); |
| 113 | - Map<String, String> jndiMap = config.getJndiName(); | |
| 113 | + String jndi = config.getJndiName() == null ? null : config.getJndiName().get(dataSourceName); | |
| 114 | + String url = config.getUrl() == null ? null : config.getUrl().get(dataSourceName); | |
| 114 | 115 | |
| 115 | - if (jndiMap != null) { | |
| 116 | - result = initJNDIDataSource(dataSourceName, config); | |
| 116 | + if (jndi != null) { | |
| 117 | + result = initJNDIDataSource(dataSourceName, jndi); | |
| 117 | 118 | |
| 118 | - } else { | |
| 119 | + } else if (url != null) { | |
| 119 | 120 | result = new BasicDataSourceProxy(dataSourceName, config, bundle); |
| 121 | + | |
| 122 | + } else { | |
| 123 | + throw new DemoiselleException(bundle.getString("uncompleted-datasource-configuration", dataSourceName)); | |
| 120 | 124 | } |
| 121 | 125 | |
| 122 | 126 | return result; |
| 123 | 127 | } |
| 124 | 128 | |
| 125 | - private DataSource initJNDIDataSource(String dataSourceName, JDBCConfig config) { | |
| 129 | + private DataSource initJNDIDataSource(String dataSourceName, String jndi) { | |
| 126 | 130 | DataSource result = null; |
| 127 | 131 | |
| 128 | 132 | try { |
| 129 | 133 | Context context = new InitialContext(); |
| 130 | - String jndi = config.getJndiName().get(dataSourceName); | |
| 131 | - | |
| 132 | 134 | result = (DataSource) context.lookup(jndi); |
| 133 | 135 | |
| 134 | 136 | } catch (NamingException cause) { | ... | ... |
impl/extension/jdbc/src/main/resources/demoiselle-jdbc-bundle.properties
| ... | ... | @@ -34,6 +34,8 @@ |
| 34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | 35 | |
| 36 | 36 | more-than-one-datasource-defined=Existe mais de um banco de dados definido. Utilize @{0} no ponto de inje\u00E7\u00E3o ou defina o atributo "frameworkdemoiselle.persistence.default.datasource.name" no arquivo demoiselle.properties. |
| 37 | +connection-creation-failed=Falha ao estabelecer a conex\u00E3o JDBC {0} | |
| 38 | +uncompleted-datasource-configuration=\u00C9 preciso definir pelo menos a URL ou o JNDI referente \u00E0 conex\u00E3o {0} no demoiselle.properties. | |
| 37 | 39 | connection-was-closed=A conex\u00E3o "{0}" foi fechada. |
| 38 | 40 | connection-has-already-been-closed=A conex\u00E3o "{0}" j\u00E1 havia sido fechada. |
| 39 | 41 | connection-close-failed=Falha ao tentar fechar a conex\u00E3o "{0}" | ... | ... |