svn commit: r1533202 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: GenericEntityConfException.java config/EntityConfigUtil.java config/model/JdbcElement.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1533202 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: GenericEntityConfException.java config/EntityConfigUtil.java config/model/JdbcElement.java

adrianc
Author: adrianc
Date: Thu Oct 17 18:33:49 2013
New Revision: 1533202

URL: http://svn.apache.org/r1533202
Log:
Fixed some flaws in the JDBC password handling code. Improved JavaDocs in updated code.

The original code would provide a null or empty password (depending on code branching) if no password was configured, so I wasn't able to determine what the desired behavior was. Now an exception is thrown if there is no JDBC password, and datasource connection attempts fail gracefully.

If we want to support 'authenticationless' JDBC connections, then this will need to be looked at again.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntityConfException.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/JdbcElement.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntityConfException.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntityConfException.java?rev=1533202&r1=1533201&r2=1533202&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntityConfException.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntityConfException.java Thu Oct 17 18:33:49 2013
@@ -19,8 +19,9 @@
 package org.ofbiz.entity;
 
 /**
- * GenericConfigException
+ * Thrown when there is a problem with the entity engine configuration.
  *
+ * @see <code>entity-config.xsd</code>
  */
 @SuppressWarnings("serial")
 public class GenericEntityConfException extends GenericEntityException {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java?rev=1533202&r1=1533201&r2=1533202&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/EntityConfigUtil.java Thu Oct 17 18:33:49 2013
@@ -22,10 +22,8 @@ import java.net.URL;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilURL;
-import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.entity.GenericEntityConfException;
 import org.ofbiz.entity.config.model.Datasource;
@@ -159,24 +157,28 @@ public final class EntityConfigUtil {
         return getEntityConfig().getDatasourceMap();
     }
 
-    public static String getJdbcPassword(InlineJdbc inlineJdbcElement) {
+    /**
+     * Returns the configured JDBC password.
+     *
+     * @param inlineJdbcElement
+     * @return The configured JDBC password.
+     * @throws GenericEntityConfException If the password was not found.
+     *
+     * @see <code>entity-config.xsd</code>
+     */
+    public static String getJdbcPassword(InlineJdbc inlineJdbcElement) throws GenericEntityConfException {
         String jdbcPassword = inlineJdbcElement.getJdbcPassword();
-        if (UtilValidate.isNotEmpty(jdbcPassword)) {
+        if (!jdbcPassword.isEmpty()) {
             return jdbcPassword;
         }
         String jdbcPasswordLookup = inlineJdbcElement.getJdbcPasswordLookup();
-        if (UtilValidate.isEmpty(jdbcPasswordLookup)) {
-            // FIXME: Include line number in model
-            // Debug.logError("no @jdbc-password or @jdbc-password-lookup specified for inline-jdbc element: %s@%d:%d", module, inlineJdbcElement.getUserData("systemId"), inlineJdbcElement.getUserData("startLine"), inlineJdbcElement.getUserData("startColumn"));
-            Debug.logError("no jdbc-password or jdbc-password-lookup specified for inline-jdbc element", module);
-            return null;
+        if (jdbcPasswordLookup.isEmpty()) {
+            throw new GenericEntityConfException("No jdbc-password or jdbc-password-lookup specified for inline-jdbc element, line: " + inlineJdbcElement.getLineNumber());
         }
-        String key = "jdbc-password." + jdbcPasswordLookup;
+        String key = "jdbc-password.".concat(jdbcPasswordLookup);
         jdbcPassword = UtilProperties.getPropertyValue("passwords.properties", key);
-        if (UtilValidate.isEmpty(jdbcPassword)) {
-            // FIXME: Include line number in model
-            // Debug.logError("no @jdbc-password or @jdbc-password-lookup specified for inline-jdbc element: %s@%d:%d", module, inlineJdbcElement.getUserData("systemId"), inlineJdbcElement.getUserData("startLine"), inlineJdbcElement.getUserData("startColumn"));
-            Debug.logError("no jdbc-password or jdbc-password-lookup specified for inline-jdbc element", module);
+        if (jdbcPassword.isEmpty()) {
+            throw new GenericEntityConfException("'" + key + "' property not found in passwords.properties file for inline-jdbc element, line: " + inlineJdbcElement.getLineNumber());
         }
         return jdbcPassword;
     }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/JdbcElement.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/JdbcElement.java?rev=1533202&r1=1533201&r2=1533202&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/JdbcElement.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/JdbcElement.java Thu Oct 17 18:33:49 2013
@@ -29,13 +29,24 @@ import org.w3c.dom.Element;
 public abstract class JdbcElement {
 
     private final String isolationLevel;
+    private final String lineNumber;
 
     protected JdbcElement(Element element) throws GenericEntityConfException {
         this.isolationLevel = element.getAttribute("isolation-level").intern();
+        Object lineNumber = element.getUserData("startLine");
+        this.lineNumber = lineNumber == null ? "unknown" : lineNumber.toString();
     }
 
     /** Returns the value of the <code>isolation-level</code> attribute. */
     public String getIsolationLevel() {
         return this.isolationLevel;
     }
+
+    /**
+     * Returns the configuration file line number for this element.
+     * @return The configuration file line number for this element
+     */
+    public String getLineNumber() {
+        return this.lineNumber;
+    }
 }