{"action":"created","comment":{"url":"https://api.github.com/repos/geotools/geotools/pulls/comments/26184961","id":26184961,"diff_hunk":"@@ -0,0 +1,108 @@\n+/*\n+ *    GeoTools - The Open Source Java GIS Toolkit\n+ *    http://geotools.org\n+ * \n+ *    (C) 2002-2015, Open Source Geospatial Foundation (OSGeo)\n+ *\n+ *    This library is free software; you can redistribute it and/or\n+ *    modify it under the terms of the GNU Lesser General Public\n+ *    License as published by the Free Software Foundation;\n+ *    version 2.1 of the License.\n+ *\n+ *    This library is distributed in the hope that it will be useful,\n+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ *    Lesser General Public License for more details.\n+ */\n+package org.geotools.data.shapefile;\n+\n+import java.sql.SQLException;\n+import java.util.HashMap;\n+import java.util.logging.Level;\n+import java.util.logging.Logger;\n+\n+import org.geotools.util.logging.Logging;\n+\n+/**\n+ * Manages a connection pool for the JDBC providers used with the optional RECNO field index.\n+ * \n+ * @author Alvaro Huarte - Tracasa / ahuarte@tracasa.es\n+ */\n+class RecnoConnectionManager\n+{\n+    static final Logger LOGGER = Logging.getLogger(RecnoConnectionManager.class);\n+    \n+    // Provides a helper class to share a Connection.\n+    private class ConnectionPool\n+    {\n+        // Creates a new ConnectionPool object.\n+        public ConnectionPool(java.sql.Connection connection)\n+        {\n+            Connection = connection;\n+            ReferenceCount = 1;\n+        }\n+        // The Connection object managed.\n+        public java.sql.Connection Connection;\n+        // Number of references to the Connection object managed.\n+        public int ReferenceCount;\n+    }\n+    // Hash of ConnectionPools managed.\n+    private HashMap<String,ConnectionPool> connectionHash = new HashMap<String,ConnectionPool>();\n+    \n+    /**\n+     * Attempts to establish a connection to the given database URL.\n+     */\n+    public java.sql.Connection getConnection(String connectionString) throws ClassNotFoundException, SQLException\n+    {\n+        if (connectionString==null || connectionString.length()==0)\n+            return null;\n+        \n+        synchronized (this) \n+        {\n+            ConnectionPool connectionPool = connectionHash.get(connectionString);\n+            \n+            if (connectionPool==null)\n+            {\n+                Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\");\n+                java.sql.Connection connection = java.sql.DriverManager.getConnection(connectionString, \"\", \"\");\n+                \n+                if (connection==null)\n+                {\n+                    LOGGER.log(Level.SEVERE, \"Error getting a shared Connection of '\" + connectionString + \"'.\");\n+                    return null;\n+                }\n+                connectionPool = new ConnectionPool(connection);\n+                connectionHash.put(connectionString, connectionPool);","path":"modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/RecnoConnectionManager.java","position":75,"original_position":75,"commit_id":"82f2bc60160fb69da3af0577736576bb088a1621","original_commit_id":"82f2bc60160fb69da3af0577736576bb088a1621","user":{"login":"aaime","id":325433,"avatar_url":"https://avatars.githubusercontent.com/u/325433?v=3","gravatar_id":"","url":"https://api.github.com/users/aaime","html_url":"https://github.com/aaime","followers_url":"https://api.github.com/users/aaime/followers","following_url":"https://api.github.com/users/aaime/following{/other_user}","gists_url":"https://api.github.com/users/aaime/gists{/gist_id}","starred_url":"https://api.github.com/users/aaime/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaime/subscriptions","organizations_url":"https://api.github.com/users/aaime/orgs","repos_url":"https://api.github.com/users/aaime/repos","events_url":"https://api.github.com/users/aaime/events{/privacy}","received_events_url":"https://api.github.com/users/aaime/received_events","type":"User","site_admin":false},"body":"So you have a single connection used in different threads? This will break under load, the java.sql.Connection is not supposed to be thread safe, as it keeps state. You should use commons-dbpc to manage the connection pool insetad of managing it yourlself, and make sure you clean them up when the store goes down)","created_at":"2015-03-11T02:26:48Z","updated_at":"2015-03-11T02:26:48Z","html_url":"https://github.com/geotools/geotools/pull/768#discussion_r26184961","pull_request_url":"https://api.github.com/repos/geotools/geotools/pulls/768","_links":{"self":{"href":"https://api.github.com/repos/geotools/geotools/pulls/comments/26184961"},"html":{"href":"https://github.com/geotools/geotools/pull/768#discussion_r26184961"},"pull_request":{"href":"https://api.github.com/repos/geotools/geotools/pulls/768"}}},"pull_request":{"url":"https://api.github.com/repos/geotools/geotools/pulls/768","id":30757692,"html_url":"https://github.com/geotools/geotools/pull/768","diff_url":"https://github.com/geotools/geotools/pull/768.diff","patch_url":"https://github.com/geotools/geotools/pull/768.patch","issue_url":"https://api.github.com/repos/geotools/geotools/issues/768","number":768,"state":"open","locked":false,"title":"[GEOS-6842] Share DBF ODBC connection to avoid multithread locking","user":{"login":"ahuarte47","id":5576272,"avatar_url":"https://avatars.githubusercontent.com/u/5576272?v=3","gravatar_id":"","url":"https://api.github.com/users/ahuarte47","html_url":"https://github.com/ahuarte47","followers_url":"https://api.github.com/users/ahuarte47/followers","following_url":"https://api.github.com/users/ahuarte47/following{/other_user}","gists_url":"https://api.github.com/users/ahuarte47/gists{/gist_id}","starred_url":"https://api.github.com/users/ahuarte47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahuarte47/subscriptions","organizations_url":"https://api.github.com/users/ahuarte47/orgs","repos_url":"https://api.github.com/users/ahuarte47/repos","events_url":"https://api.github.com/users/ahuarte47/events{/privacy}","received_events_url":"https://api.github.com/users/ahuarte47/received_events","type":"User","site_admin":false},"body":"This PR protects the DBF ODBC Connection management in multithread environments as Geoserver needs.\r\nIt is a fix to commit https://github.com/geotools/geotools/commit/87736589f88fc4c3b643bb425ffd0c4a1ebe8db2 \r\n\r\nWe have verified that the 'Advantage StreamlineSQL ODBC' driver can crash for massively multithreaded requests to the same shapefile.\r\n","created_at":"2015-03-09T12:53:32Z","updated_at":"2015-03-11T02:26:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"95e020471debd7a343a18a0da46042f6e163357d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/geotools/geotools/pulls/768/commits","review_comments_url":"https://api.github.com/repos/geotools/geotools/pulls/768/comments","review_comment_url":"https://api.github.com/repos/geotools/geotools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/geotools/geotools/issues/768/comments","statuses_url":"https://api.github.com/repos/geotools/geotools/statuses/82f2bc60160fb69da3af0577736576bb088a1621","head":{"label":"ahuarte47:GEOS-6842-fast_query_dbase-windows-shareconn","ref":"GEOS-6842-fast_query_dbase-windows-shareconn","sha":"82f2bc60160fb69da3af0577736576bb088a1621","user":{"login":"ahuarte47","id":5576272,"avatar_url":"https://avatars.githubusercontent.com/u/5576272?v=3","gravatar_id":"","url":"https://api.github.com/users/ahuarte47","html_url":"https://github.com/ahuarte47","followers_url":"https://api.github.com/users/ahuarte47/followers","following_url":"https://api.github.com/users/ahuarte47/following{/other_user}","gists_url":"https://api.github.com/users/ahuarte47/gists{/gist_id}","starred_url":"https://api.github.com/users/ahuarte47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahuarte47/subscriptions","organizations_url":"https://api.github.com/users/ahuarte47/orgs","repos_url":"https://api.github.com/users/ahuarte47/repos","events_url":"https://api.github.com/users/ahuarte47/events{/privacy}","received_events_url":"https://api.github.com/users/ahuarte47/received_events","type":"User","site_admin":false},"repo":{"id":29288550,"name":"geotools","full_name":"ahuarte47/geotools","owner":{"login":"ahuarte47","id":5576272,"avatar_url":"https://avatars.githubusercontent.com/u/5576272?v=3","gravatar_id":"","url":"https://api.github.com/users/ahuarte47","html_url":"https://github.com/ahuarte47","followers_url":"https://api.github.com/users/ahuarte47/followers","following_url":"https://api.github.com/users/ahuarte47/following{/other_user}","gists_url":"https://api.github.com/users/ahuarte47/gists{/gist_id}","starred_url":"https://api.github.com/users/ahuarte47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahuarte47/subscriptions","organizations_url":"https://api.github.com/users/ahuarte47/orgs","repos_url":"https://api.github.com/users/ahuarte47/repos","events_url":"https://api.github.com/users/ahuarte47/events{/privacy}","received_events_url":"https://api.github.com/users/ahuarte47/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ahuarte47/geotools","description":"Official GeoTools repository","fork":true,"url":"https://api.github.com/repos/ahuarte47/geotools","forks_url":"https://api.github.com/repos/ahuarte47/geotools/forks","keys_url":"https://api.github.com/repos/ahuarte47/geotools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ahuarte47/geotools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ahuarte47/geotools/teams","hooks_url":"https://api.github.com/repos/ahuarte47/geotools/hooks","issue_events_url":"https://api.github.com/repos/ahuarte47/geotools/issues/events{/number}","events_url":"https://api.github.com/repos/ahuarte47/geotools/events","assignees_url":"https://api.github.com/repos/ahuarte47/geotools/assignees{/user}","branches_url":"https://api.github.com/repos/ahuarte47/geotools/branches{/branch}","tags_url":"https://api.github.com/repos/ahuarte47/geotools/tags","blobs_url":"https://api.github.com/repos/ahuarte47/geotools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ahuarte47/geotools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ahuarte47/geotools/git/refs{/sha}","trees_url":"https://api.github.com/repos/ahuarte47/geotools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ahuarte47/geotools/statuses/{sha}","languages_url":"https://api.github.com/repos/ahuarte47/geotools/languages","stargazers_url":"https://api.github.com/repos/ahuarte47/geotools/stargazers","contributors_url":"https://api.github.com/repos/ahuarte47/geotools/contributors","subscribers_url":"https://api.github.com/repos/ahuarte47/geotools/subscribers","subscription_url":"https://api.github.com/repos/ahuarte47/geotools/subscription","commits_url":"https://api.github.com/repos/ahuarte47/geotools/commits{/sha}","git_commits_url":"https://api.github.com/repos/ahuarte47/geotools/git/commits{/sha}","comments_url":"https://api.github.com/repos/ahuarte47/geotools/comments{/number}","issue_comment_url":"https://api.github.com/repos/ahuarte47/geotools/issues/comments{/number}","contents_url":"https://api.github.com/repos/ahuarte47/geotools/contents/{+path}","compare_url":"https://api.github.com/repos/ahuarte47/geotools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ahuarte47/geotools/merges","archive_url":"https://api.github.com/repos/ahuarte47/geotools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ahuarte47/geotools/downloads","issues_url":"https://api.github.com/repos/ahuarte47/geotools/issues{/number}","pulls_url":"https://api.github.com/repos/ahuarte47/geotools/pulls{/number}","milestones_url":"https://api.github.com/repos/ahuarte47/geotools/milestones{/number}","notifications_url":"https://api.github.com/repos/ahuarte47/geotools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ahuarte47/geotools/labels{/name}","releases_url":"https://api.github.com/repos/ahuarte47/geotools/releases{/id}","created_at":"2015-01-15T08:46:15Z","updated_at":"2015-03-09T07:45:43Z","pushed_at":"2015-03-09T12:45:20Z","git_url":"git://github.com/ahuarte47/geotools.git","ssh_url":"git@github.com:ahuarte47/geotools.git","clone_url":"https://github.com/ahuarte47/geotools.git","svn_url":"https://github.com/ahuarte47/geotools","homepage":"http://geotools.org","size":102127,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"geotools:master","ref":"master","sha":"9e915ff5319a8fb90ad18e7940911345f78587fb","user":{"login":"geotools","id":1187031,"avatar_url":"https://avatars.githubusercontent.com/u/1187031?v=3","gravatar_id":"","url":"https://api.github.com/users/geotools","html_url":"https://github.com/geotools","followers_url":"https://api.github.com/users/geotools/followers","following_url":"https://api.github.com/users/geotools/following{/other_user}","gists_url":"https://api.github.com/users/geotools/gists{/gist_id}","starred_url":"https://api.github.com/users/geotools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geotools/subscriptions","organizations_url":"https://api.github.com/users/geotools/orgs","repos_url":"https://api.github.com/users/geotools/repos","events_url":"https://api.github.com/users/geotools/events{/privacy}","received_events_url":"https://api.github.com/users/geotools/received_events","type":"Organization","site_admin":false},"repo":{"id":2752522,"name":"geotools","full_name":"geotools/geotools","owner":{"login":"geotools","id":1187031,"avatar_url":"https://avatars.githubusercontent.com/u/1187031?v=3","gravatar_id":"","url":"https://api.github.com/users/geotools","html_url":"https://github.com/geotools","followers_url":"https://api.github.com/users/geotools/followers","following_url":"https://api.github.com/users/geotools/following{/other_user}","gists_url":"https://api.github.com/users/geotools/gists{/gist_id}","starred_url":"https://api.github.com/users/geotools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geotools/subscriptions","organizations_url":"https://api.github.com/users/geotools/orgs","repos_url":"https://api.github.com/users/geotools/repos","events_url":"https://api.github.com/users/geotools/events{/privacy}","received_events_url":"https://api.github.com/users/geotools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/geotools/geotools","description":"Official GeoTools repository","fork":false,"url":"https://api.github.com/repos/geotools/geotools","forks_url":"https://api.github.com/repos/geotools/geotools/forks","keys_url":"https://api.github.com/repos/geotools/geotools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/geotools/geotools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/geotools/geotools/teams","hooks_url":"https://api.github.com/repos/geotools/geotools/hooks","issue_events_url":"https://api.github.com/repos/geotools/geotools/issues/events{/number}","events_url":"https://api.github.com/repos/geotools/geotools/events","assignees_url":"https://api.github.com/repos/geotools/geotools/assignees{/user}","branches_url":"https://api.github.com/repos/geotools/geotools/branches{/branch}","tags_url":"https://api.github.com/repos/geotools/geotools/tags","blobs_url":"https://api.github.com/repos/geotools/geotools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/geotools/geotools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/geotools/geotools/git/refs{/sha}","trees_url":"https://api.github.com/repos/geotools/geotools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/geotools/geotools/statuses/{sha}","languages_url":"https://api.github.com/repos/geotools/geotools/languages","stargazers_url":"https://api.github.com/repos/geotools/geotools/stargazers","contributors_url":"https://api.github.com/repos/geotools/geotools/contributors","subscribers_url":"https://api.github.com/repos/geotools/geotools/subscribers","subscription_url":"https://api.github.com/repos/geotools/geotools/subscription","commits_url":"https://api.github.com/repos/geotools/geotools/commits{/sha}","git_commits_url":"https://api.github.com/repos/geotools/geotools/git/commits{/sha}","comments_url":"https://api.github.com/repos/geotools/geotools/comments{/number}","issue_comment_url":"https://api.github.com/repos/geotools/geotools/issues/comments{/number}","contents_url":"https://api.github.com/repos/geotools/geotools/contents/{+path}","compare_url":"https://api.github.com/repos/geotools/geotools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/geotools/geotools/merges","archive_url":"https://api.github.com/repos/geotools/geotools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/geotools/geotools/downloads","issues_url":"https://api.github.com/repos/geotools/geotools/issues{/number}","pulls_url":"https://api.github.com/repos/geotools/geotools/pulls{/number}","milestones_url":"https://api.github.com/repos/geotools/geotools/milestones{/number}","notifications_url":"https://api.github.com/repos/geotools/geotools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/geotools/geotools/labels{/name}","releases_url":"https://api.github.com/repos/geotools/geotools/releases{/id}","created_at":"2011-11-10T23:22:12Z","updated_at":"2015-03-11T02:05:58Z","pushed_at":"2015-03-11T02:05:57Z","git_url":"git://github.com/geotools/geotools.git","ssh_url":"git@github.com:geotools/geotools.git","clone_url":"https://github.com/geotools/geotools.git","svn_url":"https://github.com/geotools/geotools","homepage":"http://geotools.org","size":218006,"stargazers_count":182,"watchers_count":182,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":280,"mirror_url":null,"open_issues_count":13,"forks":280,"open_issues":13,"watchers":182,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/geotools/geotools/pulls/768"},"html":{"href":"https://github.com/geotools/geotools/pull/768"},"issue":{"href":"https://api.github.com/repos/geotools/geotools/issues/768"},"comments":{"href":"https://api.github.com/repos/geotools/geotools/issues/768/comments"},"review_comments":{"href":"https://api.github.com/repos/geotools/geotools/pulls/768/comments"},"review_comment":{"href":"https://api.github.com/repos/geotools/geotools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/geotools/geotools/pulls/768/commits"},"statuses":{"href":"https://api.github.com/repos/geotools/geotools/statuses/82f2bc60160fb69da3af0577736576bb088a1621"}}}}