Author: jleroux
Date: Wed Jun 15 10:35:18 2016 New Revision: 1748543 URL: http://svn.apache.org/viewvc?rev=1748543&view=rev Log: A patch from Gareth Carter for "DB connections remain open and unused on startup" https://issues.apache.org/jira/browse/OFBIZ-7344 When ofbiz starts and checks the database, it will leave open connections and they will not get reused. If you run Check/Update database from webtools, you can see a new connection is created for your selected group As far as I can tell, the problem lies in DatabaseUtil.getDatabaseMetaData. If the parameter connection is null, a new connection object is created but not closed (like any resource should be!) jleroux: I was unable to "see a new connection is created for your selected group" when running "Check/Update database from webtools". But I tested with Postgres while and after discussing with Gareth about this. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java 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=1748543&r1=1748542&r2=1748543&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 Wed Jun 15 10:35:18 2016 @@ -219,8 +219,7 @@ public class DatabaseUtil { List<ModelEntity> entitiesAdded = new LinkedList<ModelEntity>(); String schemaName; try { - DatabaseMetaData dbData = this.getDatabaseMetaData(null, messages); - schemaName = getSchemaName(dbData); + schemaName = getSchemaName(messages); } catch (SQLException e) { String message = "Could not get schema name the database, aborting."; if (messages != null) messages.add(message); @@ -734,15 +733,7 @@ public class DatabaseUtil { // then print out XML for the entities/fields List<ModelEntity> newEntList = new LinkedList<ModelEntity>(); - boolean isCaseSensitive = false; - DatabaseMetaData dbData = this.getDatabaseMetaData(null, messages); - if (dbData != null) { - try { - isCaseSensitive = dbData.supportsMixedCaseIdentifiers(); - } catch (SQLException e) { - Debug.logError(e, "Error getting db meta data about case sensitive", module); - } - } + boolean isCaseSensitive = getIsCaseSensitive(messages); // iterate over the table names is alphabetical order for (String tableName: new TreeSet<String>(colInfo.keySet())) { @@ -755,18 +746,55 @@ public class DatabaseUtil { return newEntList; } - public DatabaseMetaData getDatabaseMetaData(Connection connection, Collection<String> messages) { - if (connection == null) { + private String getSchemaName(Collection<String> messages) throws SQLException { + String schemaName; + Connection connection = null; + + try { connection = getConnectionLogged(messages); + DatabaseMetaData dbData = this.getDatabaseMetaData(connection, messages); + schemaName = getSchemaName(dbData); + return schemaName; + } + finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + Debug.logError(e, module); + } + } } + } - if (connection == null) { - String message = "Unable to establish a connection with the database, no additional information available."; - Debug.logError(message, module); - if (messages != null) messages.add(message); - return null; + private boolean getIsCaseSensitive(Collection<String> messages) { + Connection connection = null; + + try { + connection = getConnectionLogged(messages); + boolean isCaseSensitive = false; + DatabaseMetaData dbData = this.getDatabaseMetaData(connection, messages); + if (dbData != null) { + try { + isCaseSensitive = dbData.supportsMixedCaseIdentifiers(); + } catch (SQLException e) { + Debug.logError(e, "Error getting db meta data about case sensitive", module); + } + } + return isCaseSensitive; + } + finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + Debug.logError(e, module); + } + } } + } + public DatabaseMetaData getDatabaseMetaData(Connection connection, Collection<String> messages) { DatabaseMetaData dbData = null; try { dbData = connection.getMetaData(); |
Free forum by Nabble | Edit this page |