{"action":"opened","number":554,"pull_request":{"url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/554","id":185950630,"html_url":"https://github.com/spring-projects/spring-data-mongodb/pull/554","diff_url":"https://github.com/spring-projects/spring-data-mongodb/pull/554.diff","patch_url":"https://github.com/spring-projects/spring-data-mongodb/pull/554.patch","issue_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/554","number":554,"state":"open","locked":false,"title":"DATAMONGO-1920 - Add support for MongoDB 4.0 transactions (snyc) ","user":{"login":"christophstrobl","id":2317257,"avatar_url":"https://avatars1.githubusercontent.com/u/2317257?v=4","gravatar_id":"","url":"https://api.github.com/users/christophstrobl","html_url":"https://github.com/christophstrobl","followers_url":"https://api.github.com/users/christophstrobl/followers","following_url":"https://api.github.com/users/christophstrobl/following{/other_user}","gists_url":"https://api.github.com/users/christophstrobl/gists{/gist_id}","starred_url":"https://api.github.com/users/christophstrobl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christophstrobl/subscriptions","organizations_url":"https://api.github.com/users/christophstrobl/orgs","repos_url":"https://api.github.com/users/christophstrobl/repos","events_url":"https://api.github.com/users/christophstrobl/events{/privacy}","received_events_url":"https://api.github.com/users/christophstrobl/received_events","type":"User","site_admin":false},"body":"\r\nℹ️ Requires: [MongoDB Server 3.7.9](https://www.mongodb.com/download-center#development) ℹ️ \r\n\r\n----\r\n\r\n### MongoDB Transactions\r\n\r\nAs of version 4, MongoDB will support [Transactions](https://www.mongodb.com/transactions). Transactions are built on top of ``Session``s and therefore require an active `ClientSession`.\r\n\r\n⚠️  Unless you specify a `MongoTransactionManager` within your application context, transaction support is **DISABLED**. You may use `setSessionSynchronization(ANY)` to participate in ongoing non-native MongoDB transactions.\r\n\r\nTo get full programmatic control over transactions, you may want to use the session callback on `MongoOperations`.\r\n\r\nAn example of programmatic transaction control within a `SessionCallback` is shown below:\r\n\r\n**Programmatic transactions**\r\n\r\n```java\r\nClientSession session = client.startSession(options); \r\n\r\ntemplate.withSession(session)\r\n    .execute(action -> {\r\n\r\n        session.startTransaction();\r\n\r\n        try {\r\n\r\n            Step step = // ...;\r\n            action.insert(step);\r\n\r\n            process(step);\r\n\r\n            action.update(Step.class).apply(Update.set(\"state\", // ...\r\n\r\n            session.commitTransaction();\r\n\r\n        } catch (RuntimeException e) {\r\n            session.abortTransaction();\r\n        }\r\n    }, ClientSession::close)\r\n    .subscribe();\r\n```\r\n\r\nThe above example allows you to have full control over transactional behavior while using the session scoped `MongoOperations` instance within the callback to ensure the session is passed on to every server call.\r\nTo avoid some of the overhead that comes with this approach usage of a `TransactionTemplate` can take away some of the noise of manual transaction flow.\r\n\r\n**Transactions with TransactionTemplate**\r\n\r\n```java\r\ntemplate.setSessionSynchronization(ANY);\r\n\r\n// ...\r\n\r\nTransactionTemplate txTemplate = new TransactionTemplate(anyTxManager);\r\n\r\ntxTemplate.execute(new TransactionCallbackWithoutResult() {\r\n\r\n\t@Override\r\n\tprotected void doInTransactionWithoutResult(TransactionStatus status) {\r\n\r\n\t\tStep step = // ...;\r\n\t\ttemplate.insert(step);\r\n\r\n\t\tprocess(step);\r\n\r\n\t\ttemplate.update(Step.class).apply(Update.set(\"state\", // ...\r\n\t};\r\n});\r\n```\r\n\r\n**Transactions with MongoTransactionManager**\r\n\r\n`MongoTransactionManager` is the gateway to the well known Spring transaction support. It allows applications to use [managed transaction features of Spring](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html).\r\nThe `MongoTransactionManager` binds a `ClientSession` to the thread. `MongoTemplate` detects those and operates on these resources which are associated with the transaction accordingly. `MongoTemplate` can also participate in other, ongoing transactions.\r\n\r\n```java\r\n@Configuration\r\nstatic class Config extends AbstractMongoConfiguration {\r\n\r\n\t@Bean\r\n\tMongoTransactionManager transactionManager(MongoDbFactory dbFactory) {\r\n\t\treturn new MongoTransactionManager(dbFactory);\r\n\t}\r\n\r\n\t// ...\r\n}\r\n\r\n@Component\r\npublic class StateService {\r\n\r\n\t@Transactional\r\n\tvoid someBusinessFunction(Step step) {\r\n\r\n\t\ttemplate.insert(step);\r\n\r\n\t\tprocess(step);\r\n\r\n\t\ttemplate.update(Step.class).apply(Update.set(\"state\", // ...\r\n\t};\r\n});\r\n```\r\n\r\n⚠️ `@Transactional(readOnly = true)` advises `MongoTransactionManager` also to start a transaction adding the`ClientSession` to outgoing requests.\r\n","created_at":"2018-05-04T10:53:45Z","updated_at":"2018-05-04T10:53:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/554/commits","review_comments_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/554/comments","review_comment_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/554/comments","statuses_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/statuses/004c32fd20d03e988573d7f64bf3fd1b362c03d6","head":{"label":"spring-projects:issue/DATAMONGO-1920","ref":"issue/DATAMONGO-1920","sha":"004c32fd20d03e988573d7f64bf3fd1b362c03d6","user":{"login":"spring-projects","id":317776,"avatar_url":"https://avatars0.githubusercontent.com/u/317776?v=4","gravatar_id":"","url":"https://api.github.com/users/spring-projects","html_url":"https://github.com/spring-projects","followers_url":"https://api.github.com/users/spring-projects/followers","following_url":"https://api.github.com/users/spring-projects/following{/other_user}","gists_url":"https://api.github.com/users/spring-projects/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-projects/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-projects/subscriptions","organizations_url":"https://api.github.com/users/spring-projects/orgs","repos_url":"https://api.github.com/users/spring-projects/repos","events_url":"https://api.github.com/users/spring-projects/events{/privacy}","received_events_url":"https://api.github.com/users/spring-projects/received_events","type":"Organization","site_admin":false},"repo":{"id":2566570,"name":"spring-data-mongodb","full_name":"spring-projects/spring-data-mongodb","owner":{"login":"spring-projects","id":317776,"avatar_url":"https://avatars0.githubusercontent.com/u/317776?v=4","gravatar_id":"","url":"https://api.github.com/users/spring-projects","html_url":"https://github.com/spring-projects","followers_url":"https://api.github.com/users/spring-projects/followers","following_url":"https://api.github.com/users/spring-projects/following{/other_user}","gists_url":"https://api.github.com/users/spring-projects/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-projects/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-projects/subscriptions","organizations_url":"https://api.github.com/users/spring-projects/orgs","repos_url":"https://api.github.com/users/spring-projects/repos","events_url":"https://api.github.com/users/spring-projects/events{/privacy}","received_events_url":"https://api.github.com/users/spring-projects/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spring-projects/spring-data-mongodb","description":"Provide support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.","fork":false,"url":"https://api.github.com/repos/spring-projects/spring-data-mongodb","forks_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/forks","keys_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/teams","hooks_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/hooks","issue_events_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/events{/number}","events_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/events","assignees_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/assignees{/user}","branches_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/branches{/branch}","tags_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/tags","blobs_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/statuses/{sha}","languages_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/languages","stargazers_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/stargazers","contributors_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/contributors","subscribers_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/subscribers","subscription_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/subscription","commits_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/contents/{+path}","compare_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/merges","archive_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/downloads","issues_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues{/number}","pulls_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls{/number}","milestones_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/milestones{/number}","notifications_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/labels{/name}","releases_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/releases{/id}","deployments_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/deployments","created_at":"2011-10-13T01:06:55Z","updated_at":"2018-05-02T07:29:55Z","pushed_at":"2018-05-04T10:21:21Z","git_url":"git://github.com/spring-projects/spring-data-mongodb.git","ssh_url":"git@github.com:spring-projects/spring-data-mongodb.git","clone_url":"https://github.com/spring-projects/spring-data-mongodb.git","svn_url":"https://github.com/spring-projects/spring-data-mongodb","homepage":"http://projects.spring.io/spring-data-mongodb/","size":14900,"stargazers_count":849,"watchers_count":849,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":666,"mirror_url":null,"archived":false,"open_issues_count":25,"license":null,"forks":666,"open_issues":25,"watchers":849,"default_branch":"master"}},"base":{"label":"spring-projects:master","ref":"master","sha":"304e1c607f6d5c2af17b6f368566405792bcd639","user":{"login":"spring-projects","id":317776,"avatar_url":"https://avatars0.githubusercontent.com/u/317776?v=4","gravatar_id":"","url":"https://api.github.com/users/spring-projects","html_url":"https://github.com/spring-projects","followers_url":"https://api.github.com/users/spring-projects/followers","following_url":"https://api.github.com/users/spring-projects/following{/other_user}","gists_url":"https://api.github.com/users/spring-projects/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-projects/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-projects/subscriptions","organizations_url":"https://api.github.com/users/spring-projects/orgs","repos_url":"https://api.github.com/users/spring-projects/repos","events_url":"https://api.github.com/users/spring-projects/events{/privacy}","received_events_url":"https://api.github.com/users/spring-projects/received_events","type":"Organization","site_admin":false},"repo":{"id":2566570,"name":"spring-data-mongodb","full_name":"spring-projects/spring-data-mongodb","owner":{"login":"spring-projects","id":317776,"avatar_url":"https://avatars0.githubusercontent.com/u/317776?v=4","gravatar_id":"","url":"https://api.github.com/users/spring-projects","html_url":"https://github.com/spring-projects","followers_url":"https://api.github.com/users/spring-projects/followers","following_url":"https://api.github.com/users/spring-projects/following{/other_user}","gists_url":"https://api.github.com/users/spring-projects/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-projects/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-projects/subscriptions","organizations_url":"https://api.github.com/users/spring-projects/orgs","repos_url":"https://api.github.com/users/spring-projects/repos","events_url":"https://api.github.com/users/spring-projects/events{/privacy}","received_events_url":"https://api.github.com/users/spring-projects/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spring-projects/spring-data-mongodb","description":"Provide support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.","fork":false,"url":"https://api.github.com/repos/spring-projects/spring-data-mongodb","forks_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/forks","keys_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/teams","hooks_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/hooks","issue_events_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/events{/number}","events_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/events","assignees_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/assignees{/user}","branches_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/branches{/branch}","tags_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/tags","blobs_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/statuses/{sha}","languages_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/languages","stargazers_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/stargazers","contributors_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/contributors","subscribers_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/subscribers","subscription_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/subscription","commits_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/contents/{+path}","compare_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/merges","archive_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/downloads","issues_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues{/number}","pulls_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls{/number}","milestones_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/milestones{/number}","notifications_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/labels{/name}","releases_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/releases{/id}","deployments_url":"https://api.github.com/repos/spring-projects/spring-data-mongodb/deployments","created_at":"2011-10-13T01:06:55Z","updated_at":"2018-05-02T07:29:55Z","pushed_at":"2018-05-04T10:21:21Z","git_url":"git://github.com/spring-projects/spring-data-mongodb.git","ssh_url":"git@github.com:spring-projects/spring-data-mongodb.git","clone_url":"https://github.com/spring-projects/spring-data-mongodb.git","svn_url":"https://github.com/spring-projects/spring-data-mongodb","homepage":"http://projects.spring.io/spring-data-mongodb/","size":14900,"stargazers_count":849,"watchers_count":849,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":666,"mirror_url":null,"archived":false,"open_issues_count":25,"license":null,"forks":666,"open_issues":25,"watchers":849,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/554"},"html":{"href":"https://github.com/spring-projects/spring-data-mongodb/pull/554"},"issue":{"href":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/554"},"comments":{"href":"https://api.github.com/repos/spring-projects/spring-data-mongodb/issues/554/comments"},"review_comments":{"href":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/554/comments"},"review_comment":{"href":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spring-projects/spring-data-mongodb/pulls/554/commits"},"statuses":{"href":"https://api.github.com/repos/spring-projects/spring-data-mongodb/statuses/004c32fd20d03e988573d7f64bf3fd1b362c03d6"}},"author_association":"MEMBER","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":false,"commits":3,"additions":2420,"deletions":169,"changed_files":42}}
{"actor":{"display_login":"christophstrobl"}}