{"action":"created","comment":{"url":"https://api.github.com/repos/terasolunaorg/guideline/pulls/comments/32596226","id":32596226,"diff_hunk":"@@ -526,19 +524,120 @@ log4jdbcのオプションの設定\n How to extend\r\n --------------------------------------------------------------------------------\r\n \r\n+.. _data-access-common_todo_multiple_datasource_howtoextends:\r\n+\r\n 複数データソースを使用するための設定\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n \r\n-.. _data-access-common_todo_multiple_datasource_howtoextends:\r\n-\r\n-.. todo::\r\n+ .. todo::\r\n \r\n     **TBD**\r\n \r\n     今後、以下の内容を追加する予定である。\r\n \r\n-    * 複数データソースを使う際の注意点などを踏まえた設定例。\r\n-    * 実装にも影響がある場合は、実装例。\r\n+    * 処理パターン（複数のデータソースに対して更新あり、更新は１つのデータソース、参照のみ、同時アクセスはなしなど）によってトランザクション管理の方法がかわると思うので、その辺りを中心にブレークダウンする予定である。\r\n+\r\n+\r\n+動的にデータソースを切り替えるための設定\r\n+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n+\r\n+\r\n+AbstractRoutingDataSourceの実装\r\n+\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\r\n+複数のデータソースを定義し、動的に切り替えを行うには、\r\n+\\ ``org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource``\\を継承したクラスを実装し、どのような条件でデータソースを切り替えるか定義する必要がある。具体的にはdetermineCurrentLookupKeyメソッドの戻り値とデータソースをマッピングさせることによって、これを実現する。\r\n+\r\n+- :file:`AbstractRoutingDataSourceを継承したクラスの実装例`\r\n+\r\n+ .. code-block:: java\r\n+\r\n+    package com.examples.domain.service;\r\n+\r\n+    import javax.inject.Inject;\r\n+\r\n+    import org.joda.time.DateTime;\r\n+    import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;\r\n+    import org.terasoluna.gfw.common.date.jodatime.JodaTimeDateFactory;\r\n+\r\n+    public class RoutingDataSource extends AbstractRoutingDataSource { // (1)\r\n+        \r\n+        @Inject\r\n+        JodaTimeDateFactory dateFactory; // (2)\r\n+\r\n+        @Override\r\n+        protected Object determineCurrentLookupKey() { // (3)\r\n+\r\n+            DateTime dateTime = dateFactory.newDateTime(); // (4)\r\n+            int hour = dateTime.getHourOfDay();\r\n+\r\n+            if (7 <= hour && hour <= 23) {\r\n+                return \"OPEN\"; // (5)\r\n+            } else {\r\n+                return \"CLOSE\";\r\n+            }\r\n+        }\r\n+    }\r\n+\r\n+\r\n+ .. tabularcolumns:: |p{0.10\\linewidth}|p{0.90\\linewidth}|\r\n+ .. list-table::\r\n+    :header-rows: 1\r\n+    :widths: 10 90\r\n+\r\n+    * - 項番\r\n+      - 説明\r\n+    * - | (1)\r\n+      - \\ ``AbstractRoutingDataSource``\\を継承する。\r\n+    * - | (2)\r\n+      - 時刻を取得するため、\\ ``JodaTimeDateFactory``\\を使用する。詳細は、\\ :doc:`./SystemDate`\\を参照のこと。\r\n+    * - | (3)\r\n+      - \\ ``determineCurrentLookupKey``\\メソッドを実装する。このメソッドの返り値と後述するbean定義ファイル内の\\ ``targetDataSources``\\に定義した\\ ``key``\\をマッピングすることにより使用するデータソースが決定される。\r\n+    * - | (4)\r\n+      - メソッド内で、何らかのコンテキスト情報（認証ユーザー情報、時間、ロケール等）のにより、値の切り替えを行う。業務用件に合わせて実装する必要がある。このサンプルは、時間によりデータソースを切り替える実装例である。\r","path":"source/ArchitectureInDetail/DataAccessCommon.rst","position":98,"original_position":98,"commit_id":"32ac0fa435c34a87c7cacbda6b9380325aebbcd4","original_commit_id":"32ac0fa435c34a87c7cacbda6b9380325aebbcd4","user":{"login":"iwanagah","id":11847042,"avatar_url":"https://avatars.githubusercontent.com/u/11847042?v=3","gravatar_id":"","url":"https://api.github.com/users/iwanagah","html_url":"https://github.com/iwanagah","followers_url":"https://api.github.com/users/iwanagah/followers","following_url":"https://api.github.com/users/iwanagah/following{/other_user}","gists_url":"https://api.github.com/users/iwanagah/gists{/gist_id}","starred_url":"https://api.github.com/users/iwanagah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iwanagah/subscriptions","organizations_url":"https://api.github.com/users/iwanagah/orgs","repos_url":"https://api.github.com/users/iwanagah/repos","events_url":"https://api.github.com/users/iwanagah/events{/privacy}","received_events_url":"https://api.github.com/users/iwanagah/received_events","type":"User","site_admin":false},"body":"「～を参照し、～」に修正します。","created_at":"2015-06-17T05:28:23Z","updated_at":"2015-06-17T05:28:23Z","html_url":"https://github.com/terasolunaorg/guideline/pull/1153#discussion_r32596226","pull_request_url":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153","_links":{"self":{"href":"https://api.github.com/repos/terasolunaorg/guideline/pulls/comments/32596226"},"html":{"href":"https://github.com/terasolunaorg/guideline/pull/1153#discussion_r32596226"},"pull_request":{"href":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153"}}},"pull_request":{"url":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153","id":37768202,"html_url":"https://github.com/terasolunaorg/guideline/pull/1153","diff_url":"https://github.com/terasolunaorg/guideline/pull/1153.diff","patch_url":"https://github.com/terasolunaorg/guideline/pull/1153.patch","issue_url":"https://api.github.com/repos/terasolunaorg/guideline/issues/1153","number":1153,"state":"open","locked":false,"title":"Adding the RoutingDataSource with simple example. #1071","user":{"login":"iwanagah","id":11847042,"avatar_url":"https://avatars.githubusercontent.com/u/11847042?v=3","gravatar_id":"","url":"https://api.github.com/users/iwanagah","html_url":"https://github.com/iwanagah","followers_url":"https://api.github.com/users/iwanagah/followers","following_url":"https://api.github.com/users/iwanagah/following{/other_user}","gists_url":"https://api.github.com/users/iwanagah/gists{/gist_id}","starred_url":"https://api.github.com/users/iwanagah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iwanagah/subscriptions","organizations_url":"https://api.github.com/users/iwanagah/orgs","repos_url":"https://api.github.com/users/iwanagah/repos","events_url":"https://api.github.com/users/iwanagah/events{/privacy}","received_events_url":"https://api.github.com/users/iwanagah/received_events","type":"User","site_admin":false},"body":"Please review #1071 .","created_at":"2015-06-16T07:56:14Z","updated_at":"2015-06-17T05:28:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"221ee2ee974415c881142ef0dcc03248a8cc34d6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153/commits","review_comments_url":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153/comments","review_comment_url":"https://api.github.com/repos/terasolunaorg/guideline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/terasolunaorg/guideline/issues/1153/comments","statuses_url":"https://api.github.com/repos/terasolunaorg/guideline/statuses/32ac0fa435c34a87c7cacbda6b9380325aebbcd4","head":{"label":"terasolunaorg:issues/1071_RoutingDataSourceSimple","ref":"issues/1071_RoutingDataSourceSimple","sha":"32ac0fa435c34a87c7cacbda6b9380325aebbcd4","user":{"login":"terasolunaorg","id":2259156,"avatar_url":"https://avatars.githubusercontent.com/u/2259156?v=3","gravatar_id":"","url":"https://api.github.com/users/terasolunaorg","html_url":"https://github.com/terasolunaorg","followers_url":"https://api.github.com/users/terasolunaorg/followers","following_url":"https://api.github.com/users/terasolunaorg/following{/other_user}","gists_url":"https://api.github.com/users/terasolunaorg/gists{/gist_id}","starred_url":"https://api.github.com/users/terasolunaorg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terasolunaorg/subscriptions","organizations_url":"https://api.github.com/users/terasolunaorg/orgs","repos_url":"https://api.github.com/users/terasolunaorg/repos","events_url":"https://api.github.com/users/terasolunaorg/events{/privacy}","received_events_url":"https://api.github.com/users/terasolunaorg/received_events","type":"Organization","site_admin":false},"repo":{"id":15253684,"name":"guideline","full_name":"terasolunaorg/guideline","owner":{"login":"terasolunaorg","id":2259156,"avatar_url":"https://avatars.githubusercontent.com/u/2259156?v=3","gravatar_id":"","url":"https://api.github.com/users/terasolunaorg","html_url":"https://github.com/terasolunaorg","followers_url":"https://api.github.com/users/terasolunaorg/followers","following_url":"https://api.github.com/users/terasolunaorg/following{/other_user}","gists_url":"https://api.github.com/users/terasolunaorg/gists{/gist_id}","starred_url":"https://api.github.com/users/terasolunaorg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terasolunaorg/subscriptions","organizations_url":"https://api.github.com/users/terasolunaorg/orgs","repos_url":"https://api.github.com/users/terasolunaorg/repos","events_url":"https://api.github.com/users/terasolunaorg/events{/privacy}","received_events_url":"https://api.github.com/users/terasolunaorg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/terasolunaorg/guideline","description":"TERASOLUNA Server Framework for Java (5.x)  Development Guideline","fork":false,"url":"https://api.github.com/repos/terasolunaorg/guideline","forks_url":"https://api.github.com/repos/terasolunaorg/guideline/forks","keys_url":"https://api.github.com/repos/terasolunaorg/guideline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/terasolunaorg/guideline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/terasolunaorg/guideline/teams","hooks_url":"https://api.github.com/repos/terasolunaorg/guideline/hooks","issue_events_url":"https://api.github.com/repos/terasolunaorg/guideline/issues/events{/number}","events_url":"https://api.github.com/repos/terasolunaorg/guideline/events","assignees_url":"https://api.github.com/repos/terasolunaorg/guideline/assignees{/user}","branches_url":"https://api.github.com/repos/terasolunaorg/guideline/branches{/branch}","tags_url":"https://api.github.com/repos/terasolunaorg/guideline/tags","blobs_url":"https://api.github.com/repos/terasolunaorg/guideline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/terasolunaorg/guideline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/terasolunaorg/guideline/git/refs{/sha}","trees_url":"https://api.github.com/repos/terasolunaorg/guideline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/terasolunaorg/guideline/statuses/{sha}","languages_url":"https://api.github.com/repos/terasolunaorg/guideline/languages","stargazers_url":"https://api.github.com/repos/terasolunaorg/guideline/stargazers","contributors_url":"https://api.github.com/repos/terasolunaorg/guideline/contributors","subscribers_url":"https://api.github.com/repos/terasolunaorg/guideline/subscribers","subscription_url":"https://api.github.com/repos/terasolunaorg/guideline/subscription","commits_url":"https://api.github.com/repos/terasolunaorg/guideline/commits{/sha}","git_commits_url":"https://api.github.com/repos/terasolunaorg/guideline/git/commits{/sha}","comments_url":"https://api.github.com/repos/terasolunaorg/guideline/comments{/number}","issue_comment_url":"https://api.github.com/repos/terasolunaorg/guideline/issues/comments{/number}","contents_url":"https://api.github.com/repos/terasolunaorg/guideline/contents/{+path}","compare_url":"https://api.github.com/repos/terasolunaorg/guideline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/terasolunaorg/guideline/merges","archive_url":"https://api.github.com/repos/terasolunaorg/guideline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/terasolunaorg/guideline/downloads","issues_url":"https://api.github.com/repos/terasolunaorg/guideline/issues{/number}","pulls_url":"https://api.github.com/repos/terasolunaorg/guideline/pulls{/number}","milestones_url":"https://api.github.com/repos/terasolunaorg/guideline/milestones{/number}","notifications_url":"https://api.github.com/repos/terasolunaorg/guideline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/terasolunaorg/guideline/labels{/name}","releases_url":"https://api.github.com/repos/terasolunaorg/guideline/releases{/id}","created_at":"2013-12-17T12:19:55Z","updated_at":"2015-06-14T14:52:28Z","pushed_at":"2015-06-17T04:18:28Z","git_url":"git://github.com/terasolunaorg/guideline.git","ssh_url":"git@github.com:terasolunaorg/guideline.git","clone_url":"https://github.com/terasolunaorg/guideline.git","svn_url":"https://github.com/terasolunaorg/guideline","homepage":"http://terasolunaorg.github.io/guideline/","size":51985,"stargazers_count":31,"watchers_count":31,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":105,"forks":5,"open_issues":105,"watchers":31,"default_branch":"master"}},"base":{"label":"terasolunaorg:master","ref":"master","sha":"ffe8f4c7db99b29a62c24b2bb66daa25c43f783c","user":{"login":"terasolunaorg","id":2259156,"avatar_url":"https://avatars.githubusercontent.com/u/2259156?v=3","gravatar_id":"","url":"https://api.github.com/users/terasolunaorg","html_url":"https://github.com/terasolunaorg","followers_url":"https://api.github.com/users/terasolunaorg/followers","following_url":"https://api.github.com/users/terasolunaorg/following{/other_user}","gists_url":"https://api.github.com/users/terasolunaorg/gists{/gist_id}","starred_url":"https://api.github.com/users/terasolunaorg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terasolunaorg/subscriptions","organizations_url":"https://api.github.com/users/terasolunaorg/orgs","repos_url":"https://api.github.com/users/terasolunaorg/repos","events_url":"https://api.github.com/users/terasolunaorg/events{/privacy}","received_events_url":"https://api.github.com/users/terasolunaorg/received_events","type":"Organization","site_admin":false},"repo":{"id":15253684,"name":"guideline","full_name":"terasolunaorg/guideline","owner":{"login":"terasolunaorg","id":2259156,"avatar_url":"https://avatars.githubusercontent.com/u/2259156?v=3","gravatar_id":"","url":"https://api.github.com/users/terasolunaorg","html_url":"https://github.com/terasolunaorg","followers_url":"https://api.github.com/users/terasolunaorg/followers","following_url":"https://api.github.com/users/terasolunaorg/following{/other_user}","gists_url":"https://api.github.com/users/terasolunaorg/gists{/gist_id}","starred_url":"https://api.github.com/users/terasolunaorg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terasolunaorg/subscriptions","organizations_url":"https://api.github.com/users/terasolunaorg/orgs","repos_url":"https://api.github.com/users/terasolunaorg/repos","events_url":"https://api.github.com/users/terasolunaorg/events{/privacy}","received_events_url":"https://api.github.com/users/terasolunaorg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/terasolunaorg/guideline","description":"TERASOLUNA Server Framework for Java (5.x)  Development Guideline","fork":false,"url":"https://api.github.com/repos/terasolunaorg/guideline","forks_url":"https://api.github.com/repos/terasolunaorg/guideline/forks","keys_url":"https://api.github.com/repos/terasolunaorg/guideline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/terasolunaorg/guideline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/terasolunaorg/guideline/teams","hooks_url":"https://api.github.com/repos/terasolunaorg/guideline/hooks","issue_events_url":"https://api.github.com/repos/terasolunaorg/guideline/issues/events{/number}","events_url":"https://api.github.com/repos/terasolunaorg/guideline/events","assignees_url":"https://api.github.com/repos/terasolunaorg/guideline/assignees{/user}","branches_url":"https://api.github.com/repos/terasolunaorg/guideline/branches{/branch}","tags_url":"https://api.github.com/repos/terasolunaorg/guideline/tags","blobs_url":"https://api.github.com/repos/terasolunaorg/guideline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/terasolunaorg/guideline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/terasolunaorg/guideline/git/refs{/sha}","trees_url":"https://api.github.com/repos/terasolunaorg/guideline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/terasolunaorg/guideline/statuses/{sha}","languages_url":"https://api.github.com/repos/terasolunaorg/guideline/languages","stargazers_url":"https://api.github.com/repos/terasolunaorg/guideline/stargazers","contributors_url":"https://api.github.com/repos/terasolunaorg/guideline/contributors","subscribers_url":"https://api.github.com/repos/terasolunaorg/guideline/subscribers","subscription_url":"https://api.github.com/repos/terasolunaorg/guideline/subscription","commits_url":"https://api.github.com/repos/terasolunaorg/guideline/commits{/sha}","git_commits_url":"https://api.github.com/repos/terasolunaorg/guideline/git/commits{/sha}","comments_url":"https://api.github.com/repos/terasolunaorg/guideline/comments{/number}","issue_comment_url":"https://api.github.com/repos/terasolunaorg/guideline/issues/comments{/number}","contents_url":"https://api.github.com/repos/terasolunaorg/guideline/contents/{+path}","compare_url":"https://api.github.com/repos/terasolunaorg/guideline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/terasolunaorg/guideline/merges","archive_url":"https://api.github.com/repos/terasolunaorg/guideline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/terasolunaorg/guideline/downloads","issues_url":"https://api.github.com/repos/terasolunaorg/guideline/issues{/number}","pulls_url":"https://api.github.com/repos/terasolunaorg/guideline/pulls{/number}","milestones_url":"https://api.github.com/repos/terasolunaorg/guideline/milestones{/number}","notifications_url":"https://api.github.com/repos/terasolunaorg/guideline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/terasolunaorg/guideline/labels{/name}","releases_url":"https://api.github.com/repos/terasolunaorg/guideline/releases{/id}","created_at":"2013-12-17T12:19:55Z","updated_at":"2015-06-14T14:52:28Z","pushed_at":"2015-06-17T04:18:28Z","git_url":"git://github.com/terasolunaorg/guideline.git","ssh_url":"git@github.com:terasolunaorg/guideline.git","clone_url":"https://github.com/terasolunaorg/guideline.git","svn_url":"https://github.com/terasolunaorg/guideline","homepage":"http://terasolunaorg.github.io/guideline/","size":51985,"stargazers_count":31,"watchers_count":31,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":105,"forks":5,"open_issues":105,"watchers":31,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153"},"html":{"href":"https://github.com/terasolunaorg/guideline/pull/1153"},"issue":{"href":"https://api.github.com/repos/terasolunaorg/guideline/issues/1153"},"comments":{"href":"https://api.github.com/repos/terasolunaorg/guideline/issues/1153/comments"},"review_comments":{"href":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153/comments"},"review_comment":{"href":"https://api.github.com/repos/terasolunaorg/guideline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/terasolunaorg/guideline/pulls/1153/commits"},"statuses":{"href":"https://api.github.com/repos/terasolunaorg/guideline/statuses/32ac0fa435c34a87c7cacbda6b9380325aebbcd4"}}}}