{"action":"created","comment":{"url":"https://api.github.com/repos/Civcraft/CivModCore/pulls/comments/77945664","id":77945664,"diff_hunk":"@@ -0,0 +1,96 @@\n+package vg.civcraft.mc.civmodcore.dao;\n+\n+import java.sql.Connection;\n+import java.sql.SQLException;\n+import java.sql.Statement;\n+import java.util.logging.Level;\n+import java.util.logging.Logger;\n+\n+import com.zaxxer.hikari.HikariConfig;\n+import com.zaxxer.hikari.HikariDataSource;\n+\n+/**\n+ * Handy Connection Pool / Database wrapper for use by all plugins.\n+ * \n+ * @author ProgrammerDan\n+ *\n+ */\n+public class ConnectionPool {\n+\t\n+\tprivate HikariDataSource datasource;\n+\t\n+\tprivate Logger logger;\n+\t\n+\t/**\n+\t * Creates the Database connection pool backed by HikariCP.\n+\t * \n+\t * @param log The logger to use\n+\t * @param user The user to connection as\n+\t * @param pass The password to use\n+\t * @param host The host to connect to\n+\t * @param port The port on the host to connect to\n+\t * @param database The database to use\n+\t * @param poolSize The maximum size of the connection pool (< 10 recommended)\n+\t * @param connectionTimeout The longest a query can run until timeout occurs (1-5s recommended)\n+\t * @param idleTimeout The longest a connection can sit idle before recycling (10min recom. check dbms config)\n+\t * @param maxLifetime The absolute longest length of time a connection can exist (2hr recom. check dbms config)\n+\t */\n+\tpublic ConnectionPool(Logger log, String user, String pass, String host, int port, String database,\n+\t\t\tint poolSize, long connectionTimeout, long idleTimeout, long maxLifetime) {\n+\t\tthis.logger = log;\n+\t\tif (user != null && host != null && port > 0 && database != null) {\n+\t\t\tHikariConfig config = new HikariConfig();\n+\t\t\tconfig.setJdbcUrl(\"jdbc:mysql://\" + host + \":\" + port + \"/\" + database);\n+\t\t\tconfig.setConnectionTimeout(connectionTimeout); // 1000l);\n+\t\t\tconfig.setIdleTimeout(idleTimeout); //600000l);\n+\t\t\tconfig.setMaxLifetime(maxLifetime); //7200000l);\n+\t\t\tconfig.setMaximumPoolSize(poolSize); //10);\n+\t\t\tconfig.setUsername(user);\n+\t\t\tif (pass != null) {\n+\t\t\t\tconfig.setPassword(pass);\n+\t\t\t}\n+\t\t\tthis.datasource = new HikariDataSource(config);\n+\t\t\t\n+\t\t\ttry (Connection connection = getConnection();\n+\t\t\t\t\tStatement statement = connection.createStatement();) {\n+\t\t\t\tstatement.executeQuery(\"SELECT 1\");\n+\t\t\t} catch (SQLException se) {\n+\t\t\t\tlogger.log(Level.SEVERE, \"Unable to initialize Database\", se);\n+\t\t\t\tthis.datasource = null;","path":"src/main/java/vg/civcraft/mc/civmodcore/dao/ConnectionPool.java","position":59,"original_position":59,"commit_id":"536b6be6a7a265e7033be8ea59d8ef70bf75fa92","original_commit_id":"536b6be6a7a265e7033be8ea59d8ef70bf75fa92","user":{"login":"ProgrammerDan","id":409230,"avatar_url":"https://avatars.githubusercontent.com/u/409230?v=3","gravatar_id":"","url":"https://api.github.com/users/ProgrammerDan","html_url":"https://github.com/ProgrammerDan","followers_url":"https://api.github.com/users/ProgrammerDan/followers","following_url":"https://api.github.com/users/ProgrammerDan/following{/other_user}","gists_url":"https://api.github.com/users/ProgrammerDan/gists{/gist_id}","starred_url":"https://api.github.com/users/ProgrammerDan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProgrammerDan/subscriptions","organizations_url":"https://api.github.com/users/ProgrammerDan/orgs","repos_url":"https://api.github.com/users/ProgrammerDan/repos","events_url":"https://api.github.com/users/ProgrammerDan/events{/privacy}","received_events_url":"https://api.github.com/users/ProgrammerDan/received_events","type":"User","site_admin":false},"body":"Check in ManagedDatasource; effectively I'm leaving it up to the plugin implemented.\r\n\r\nIn reference implementation of Namelayer, I do in fact call Bukkit.shutdown() if the database is unavailable. Pattern-wise I usually stay away from forcing those outcomes at an API/lib level.","created_at":"2016-09-08T04:52:32Z","updated_at":"2016-09-08T04:52:32Z","html_url":"https://github.com/Civcraft/CivModCore/pull/23#discussion_r77945664","pull_request_url":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/Civcraft/CivModCore/pulls/comments/77945664"},"html":{"href":"https://github.com/Civcraft/CivModCore/pull/23#discussion_r77945664"},"pull_request":{"href":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23","id":84412782,"html_url":"https://github.com/Civcraft/CivModCore/pull/23","diff_url":"https://github.com/Civcraft/CivModCore/pull/23.diff","patch_url":"https://github.com/Civcraft/CivModCore/pull/23.patch","issue_url":"https://api.github.com/repos/Civcraft/CivModCore/issues/23","number":23,"state":"open","locked":false,"title":"Adding Managed Database handling.","user":{"login":"ProgrammerDan","id":409230,"avatar_url":"https://avatars.githubusercontent.com/u/409230?v=3","gravatar_id":"","url":"https://api.github.com/users/ProgrammerDan","html_url":"https://github.com/ProgrammerDan","followers_url":"https://api.github.com/users/ProgrammerDan/followers","following_url":"https://api.github.com/users/ProgrammerDan/following{/other_user}","gists_url":"https://api.github.com/users/ProgrammerDan/gists{/gist_id}","starred_url":"https://api.github.com/users/ProgrammerDan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProgrammerDan/subscriptions","organizations_url":"https://api.github.com/users/ProgrammerDan/orgs","repos_url":"https://api.github.com/users/ProgrammerDan/repos","events_url":"https://api.github.com/users/ProgrammerDan/events{/privacy}","received_events_url":"https://api.github.com/users/ProgrammerDan/received_events","type":"User","site_admin":false},"body":"Alright, this is a big PR, I guess.\r\n\r\nAdds HikariCP-backed database pooling as a general resource for all plugins to leverage.\r\n\r\nYes, we'll need to update all the plugins.\r\n\r\nNo, they won't break until we do.\r\n\r\nYes, we absolutely should.\r\n\r\nNote there is some serious javadoc comments describing how to use these new classes and how to migrate old code to use the new pattern, and it's all in the new \"dao\" package.\r\n\r\nPlease review and leave comments if I've missed anything.\r\n\r\nPlease see the companion PR in Namelayer to convert to this ManagedDatasource approach, as a proof of concept and an illustration of concept. Note that I've tested this compliant branch of Namelayer and it works great.","created_at":"2016-09-08T04:24:03Z","updated_at":"2016-09-08T04:52:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"22e8e70c2ca2d2ec79413cd3b9e2016bb931e97a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23/commits","review_comments_url":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23/comments","review_comment_url":"https://api.github.com/repos/Civcraft/CivModCore/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Civcraft/CivModCore/issues/23/comments","statuses_url":"https://api.github.com/repos/Civcraft/CivModCore/statuses/536b6be6a7a265e7033be8ea59d8ef70bf75fa92","head":{"label":"Civcraft:adddb","ref":"adddb","sha":"536b6be6a7a265e7033be8ea59d8ef70bf75fa92","user":{"login":"Civcraft","id":3921874,"avatar_url":"https://avatars.githubusercontent.com/u/3921874?v=3","gravatar_id":"","url":"https://api.github.com/users/Civcraft","html_url":"https://github.com/Civcraft","followers_url":"https://api.github.com/users/Civcraft/followers","following_url":"https://api.github.com/users/Civcraft/following{/other_user}","gists_url":"https://api.github.com/users/Civcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/Civcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Civcraft/subscriptions","organizations_url":"https://api.github.com/users/Civcraft/orgs","repos_url":"https://api.github.com/users/Civcraft/repos","events_url":"https://api.github.com/users/Civcraft/events{/privacy}","received_events_url":"https://api.github.com/users/Civcraft/received_events","type":"Organization","site_admin":false},"repo":{"id":36245057,"name":"CivModCore","full_name":"Civcraft/CivModCore","owner":{"login":"Civcraft","id":3921874,"avatar_url":"https://avatars.githubusercontent.com/u/3921874?v=3","gravatar_id":"","url":"https://api.github.com/users/Civcraft","html_url":"https://github.com/Civcraft","followers_url":"https://api.github.com/users/Civcraft/followers","following_url":"https://api.github.com/users/Civcraft/following{/other_user}","gists_url":"https://api.github.com/users/Civcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/Civcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Civcraft/subscriptions","organizations_url":"https://api.github.com/users/Civcraft/orgs","repos_url":"https://api.github.com/users/Civcraft/repos","events_url":"https://api.github.com/users/Civcraft/events{/privacy}","received_events_url":"https://api.github.com/users/Civcraft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Civcraft/CivModCore","description":"Common Plugin Core derived from Humbug","fork":true,"url":"https://api.github.com/repos/Civcraft/CivModCore","forks_url":"https://api.github.com/repos/Civcraft/CivModCore/forks","keys_url":"https://api.github.com/repos/Civcraft/CivModCore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Civcraft/CivModCore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Civcraft/CivModCore/teams","hooks_url":"https://api.github.com/repos/Civcraft/CivModCore/hooks","issue_events_url":"https://api.github.com/repos/Civcraft/CivModCore/issues/events{/number}","events_url":"https://api.github.com/repos/Civcraft/CivModCore/events","assignees_url":"https://api.github.com/repos/Civcraft/CivModCore/assignees{/user}","branches_url":"https://api.github.com/repos/Civcraft/CivModCore/branches{/branch}","tags_url":"https://api.github.com/repos/Civcraft/CivModCore/tags","blobs_url":"https://api.github.com/repos/Civcraft/CivModCore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Civcraft/CivModCore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Civcraft/CivModCore/git/refs{/sha}","trees_url":"https://api.github.com/repos/Civcraft/CivModCore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Civcraft/CivModCore/statuses/{sha}","languages_url":"https://api.github.com/repos/Civcraft/CivModCore/languages","stargazers_url":"https://api.github.com/repos/Civcraft/CivModCore/stargazers","contributors_url":"https://api.github.com/repos/Civcraft/CivModCore/contributors","subscribers_url":"https://api.github.com/repos/Civcraft/CivModCore/subscribers","subscription_url":"https://api.github.com/repos/Civcraft/CivModCore/subscription","commits_url":"https://api.github.com/repos/Civcraft/CivModCore/commits{/sha}","git_commits_url":"https://api.github.com/repos/Civcraft/CivModCore/git/commits{/sha}","comments_url":"https://api.github.com/repos/Civcraft/CivModCore/comments{/number}","issue_comment_url":"https://api.github.com/repos/Civcraft/CivModCore/issues/comments{/number}","contents_url":"https://api.github.com/repos/Civcraft/CivModCore/contents/{+path}","compare_url":"https://api.github.com/repos/Civcraft/CivModCore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Civcraft/CivModCore/merges","archive_url":"https://api.github.com/repos/Civcraft/CivModCore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Civcraft/CivModCore/downloads","issues_url":"https://api.github.com/repos/Civcraft/CivModCore/issues{/number}","pulls_url":"https://api.github.com/repos/Civcraft/CivModCore/pulls{/number}","milestones_url":"https://api.github.com/repos/Civcraft/CivModCore/milestones{/number}","notifications_url":"https://api.github.com/repos/Civcraft/CivModCore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Civcraft/CivModCore/labels{/name}","releases_url":"https://api.github.com/repos/Civcraft/CivModCore/releases{/id}","deployments_url":"https://api.github.com/repos/Civcraft/CivModCore/deployments","created_at":"2015-05-25T17:36:50Z","updated_at":"2016-03-18T21:57:39Z","pushed_at":"2016-09-08T04:24:03Z","git_url":"git://github.com/Civcraft/CivModCore.git","ssh_url":"git@github.com:Civcraft/CivModCore.git","clone_url":"https://github.com/Civcraft/CivModCore.git","svn_url":"https://github.com/Civcraft/CivModCore","homepage":null,"size":238,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":2,"default_branch":"master"}},"base":{"label":"Civcraft:master","ref":"master","sha":"dc9335803a782e22570f13776822351dd63dc5a0","user":{"login":"Civcraft","id":3921874,"avatar_url":"https://avatars.githubusercontent.com/u/3921874?v=3","gravatar_id":"","url":"https://api.github.com/users/Civcraft","html_url":"https://github.com/Civcraft","followers_url":"https://api.github.com/users/Civcraft/followers","following_url":"https://api.github.com/users/Civcraft/following{/other_user}","gists_url":"https://api.github.com/users/Civcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/Civcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Civcraft/subscriptions","organizations_url":"https://api.github.com/users/Civcraft/orgs","repos_url":"https://api.github.com/users/Civcraft/repos","events_url":"https://api.github.com/users/Civcraft/events{/privacy}","received_events_url":"https://api.github.com/users/Civcraft/received_events","type":"Organization","site_admin":false},"repo":{"id":36245057,"name":"CivModCore","full_name":"Civcraft/CivModCore","owner":{"login":"Civcraft","id":3921874,"avatar_url":"https://avatars.githubusercontent.com/u/3921874?v=3","gravatar_id":"","url":"https://api.github.com/users/Civcraft","html_url":"https://github.com/Civcraft","followers_url":"https://api.github.com/users/Civcraft/followers","following_url":"https://api.github.com/users/Civcraft/following{/other_user}","gists_url":"https://api.github.com/users/Civcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/Civcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Civcraft/subscriptions","organizations_url":"https://api.github.com/users/Civcraft/orgs","repos_url":"https://api.github.com/users/Civcraft/repos","events_url":"https://api.github.com/users/Civcraft/events{/privacy}","received_events_url":"https://api.github.com/users/Civcraft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Civcraft/CivModCore","description":"Common Plugin Core derived from Humbug","fork":true,"url":"https://api.github.com/repos/Civcraft/CivModCore","forks_url":"https://api.github.com/repos/Civcraft/CivModCore/forks","keys_url":"https://api.github.com/repos/Civcraft/CivModCore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Civcraft/CivModCore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Civcraft/CivModCore/teams","hooks_url":"https://api.github.com/repos/Civcraft/CivModCore/hooks","issue_events_url":"https://api.github.com/repos/Civcraft/CivModCore/issues/events{/number}","events_url":"https://api.github.com/repos/Civcraft/CivModCore/events","assignees_url":"https://api.github.com/repos/Civcraft/CivModCore/assignees{/user}","branches_url":"https://api.github.com/repos/Civcraft/CivModCore/branches{/branch}","tags_url":"https://api.github.com/repos/Civcraft/CivModCore/tags","blobs_url":"https://api.github.com/repos/Civcraft/CivModCore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Civcraft/CivModCore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Civcraft/CivModCore/git/refs{/sha}","trees_url":"https://api.github.com/repos/Civcraft/CivModCore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Civcraft/CivModCore/statuses/{sha}","languages_url":"https://api.github.com/repos/Civcraft/CivModCore/languages","stargazers_url":"https://api.github.com/repos/Civcraft/CivModCore/stargazers","contributors_url":"https://api.github.com/repos/Civcraft/CivModCore/contributors","subscribers_url":"https://api.github.com/repos/Civcraft/CivModCore/subscribers","subscription_url":"https://api.github.com/repos/Civcraft/CivModCore/subscription","commits_url":"https://api.github.com/repos/Civcraft/CivModCore/commits{/sha}","git_commits_url":"https://api.github.com/repos/Civcraft/CivModCore/git/commits{/sha}","comments_url":"https://api.github.com/repos/Civcraft/CivModCore/comments{/number}","issue_comment_url":"https://api.github.com/repos/Civcraft/CivModCore/issues/comments{/number}","contents_url":"https://api.github.com/repos/Civcraft/CivModCore/contents/{+path}","compare_url":"https://api.github.com/repos/Civcraft/CivModCore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Civcraft/CivModCore/merges","archive_url":"https://api.github.com/repos/Civcraft/CivModCore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Civcraft/CivModCore/downloads","issues_url":"https://api.github.com/repos/Civcraft/CivModCore/issues{/number}","pulls_url":"https://api.github.com/repos/Civcraft/CivModCore/pulls{/number}","milestones_url":"https://api.github.com/repos/Civcraft/CivModCore/milestones{/number}","notifications_url":"https://api.github.com/repos/Civcraft/CivModCore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Civcraft/CivModCore/labels{/name}","releases_url":"https://api.github.com/repos/Civcraft/CivModCore/releases{/id}","deployments_url":"https://api.github.com/repos/Civcraft/CivModCore/deployments","created_at":"2015-05-25T17:36:50Z","updated_at":"2016-03-18T21:57:39Z","pushed_at":"2016-09-08T04:24:03Z","git_url":"git://github.com/Civcraft/CivModCore.git","ssh_url":"git@github.com:Civcraft/CivModCore.git","clone_url":"https://github.com/Civcraft/CivModCore.git","svn_url":"https://github.com/Civcraft/CivModCore","homepage":null,"size":238,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23"},"html":{"href":"https://github.com/Civcraft/CivModCore/pull/23"},"issue":{"href":"https://api.github.com/repos/Civcraft/CivModCore/issues/23"},"comments":{"href":"https://api.github.com/repos/Civcraft/CivModCore/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/Civcraft/CivModCore/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Civcraft/CivModCore/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/Civcraft/CivModCore/statuses/536b6be6a7a265e7033be8ea59d8ef70bf75fa92"}}}}
{"actor":{"display_login":"ProgrammerDan"}}