You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2014/09/25 10:55:43 UTC

svn commit: r1627489 - in /ofbiz/trunk/framework/entity: dtd/entity-config.xsd src/org/ofbiz/entity/config/model/Datasource.java src/org/ofbiz/entity/jdbc/DatabaseUtil.java

Author: jacopoc
Date: Thu Sep 25 08:55:42 2014
New Revision: 1627489

URL: http://svn.apache.org/r1627489
Log:
Based on review and comments from Adrian Crum, re-added the max-worker-pool-size element (that was removed as part of the changes in commit 1627092) but with a new implementation that preserves all the cleanups done in rev. 1627092.
This new implementation should be slightly more flexible but with default setup will end up with the same behavior as before 1627092.

Modified:
    ofbiz/trunk/framework/entity/dtd/entity-config.xsd
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/Datasource.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java

Modified: ofbiz/trunk/framework/entity/dtd/entity-config.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/dtd/entity-config.xsd?rev=1627489&r1=1627488&r2=1627489&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/dtd/entity-config.xsd (original)
+++ ofbiz/trunk/framework/entity/dtd/entity-config.xsd Thu Sep 25 08:55:42 2014
@@ -411,6 +411,7 @@ under the License.
         <xs:attribute type="xs:string" name="table-type"/>
         <xs:attribute type="xs:string" name="character-set"/>
         <xs:attribute type="xs:string" name="collate"/>
+        <xs:attribute type="xs:integer" name="max-worker-pool-size" default="1"/>
     </xs:attributeGroup>
     <xs:element name="sql-load-path">
         <xs:complexType>

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/Datasource.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/Datasource.java?rev=1627489&r1=1627488&r2=1627489&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/Datasource.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/model/Datasource.java Thu Sep 25 08:55:42 2014
@@ -74,6 +74,7 @@ public final class Datasource {
     private final String tableType; // type = xs:string
     private final String characterSet; // type = xs:string
     private final String collate; // type = xs:string
+    private final int maxWorkerPoolSize; // type = xs:integer
     private final List<SqlLoadPath> sqlLoadPathList; // <sql-load-path>
     private final List<ReadData> readDataList; // <read-data>
     private final InlineJdbc inlineJdbc; // <inline-jdbc>
@@ -160,6 +161,22 @@ public final class Datasource {
         this.tableType = element.getAttribute("table-type").intern();
         this.characterSet = element.getAttribute("character-set").intern();
         this.collate = element.getAttribute("collate").intern();
+        String maxWorkerPoolSize = element.getAttribute("max-worker-pool-size").intern();
+        if (maxWorkerPoolSize.isEmpty()) {
+            this.maxWorkerPoolSize = 1;
+        } else {
+            try {
+                int maxWorkerPoolSizeInt = Integer.parseInt(maxWorkerPoolSize);
+                if (maxWorkerPoolSizeInt == 0) {
+                    maxWorkerPoolSizeInt = 1;
+                } else if (maxWorkerPoolSizeInt < 0) {
+                    maxWorkerPoolSizeInt = Math.abs(maxWorkerPoolSizeInt) * Runtime.getRuntime().availableProcessors();
+                }
+                this.maxWorkerPoolSize = maxWorkerPoolSizeInt;
+            } catch (Exception e) {
+                throw new GenericEntityConfException("<datasource> element max-worker-pool-size attribute is invalid" + lineNumberText);
+            }
+        }
         List<? extends Element> sqlLoadPathElementList = UtilXml.childElementList(element, "sql-load-path");
         if (sqlLoadPathElementList.isEmpty()) {
             this.sqlLoadPathList = Collections.emptyList();
@@ -367,6 +384,11 @@ public final class Datasource {
         return this.collate;
     }
 
+    /** Returns the value of the <code>max-worker-pool-size</code> attribute. */
+    public int getMaxWorkerPoolSize() {
+        return this.maxWorkerPoolSize;
+    }
+
     /** Returns the <code>&lt;sql-load-path&gt;</code> child elements. */
     public List<SqlLoadPath> getSqlLoadPathList() {
         return this.sqlLoadPathList;

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java?rev=1627489&r1=1627488&r2=1627489&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java Thu Sep 25 08:55:42 2014
@@ -91,15 +91,6 @@ public class DatabaseUtil {
         this.datasourceInfo = EntityConfig.getDatasource(helperInfo.getHelperBaseName());
     }
 
-    // Legacy DatabaseUtil
-    public DatabaseUtil(String driverName, String connectionUrl, String userName, String password) {
-        this.driverName = driverName;
-        this.connectionUrl = connectionUrl;
-        this.userName = userName;
-        this.password = password;
-        this.isLegacy = true;
-    }
-
     protected Connection getConnection() throws SQLException, GenericEntityException {
         Connection connection = null;
         if (!isLegacy) {
@@ -184,7 +175,7 @@ public class DatabaseUtil {
             throw new RuntimeException("Cannot run checkDb on a legacy database connection; configure a database helper (entityengine.xml)");
         }
 
-        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+        ExecutorService executor = Executors.newFixedThreadPool(datasourceInfo.getMaxWorkerPoolSize());
 
         UtilTimer timer = new UtilTimer();
         timer.timerString("Start - Before Get Database Meta Data");
@@ -731,7 +722,7 @@ public class DatabaseUtil {
 
     /** Creates a list of ModelEntity objects based on meta data from the database */
     public List<ModelEntity> induceModelFromDb(Collection<String> messages) {
-        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+        ExecutorService executor = Executors.newFixedThreadPool(datasourceInfo.getMaxWorkerPoolSize());
 
         // get ALL tables from this database
         TreeSet<String> tableNames = this.getTableNames(messages);