{"id":1602,"date":"2018-01-30T21:19:58","date_gmt":"2018-01-30T13:19:58","guid":{"rendered":"http:\/\/coderbee.net\/?p=1602"},"modified":"2018-01-30T21:19:58","modified_gmt":"2018-01-30T13:19:58","slug":"%e5%ba%94%e7%94%a8%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86%e6%b7%b7%e4%b9%b1%e5%af%bc%e8%87%b4%e7%9a%84%e4%b8%80%e4%b8%aa%e5%9d%91","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/framework\/20180130\/1602","title":{"rendered":"\u5e94\u7528\u4e8b\u52a1\u7ba1\u7406\u6df7\u4e71\u5bfc\u81f4\u7684\u4e00\u4e2a\u5751"},"content":{"rendered":"<h2>Spring \u7684\u4e8b\u52a1\u4f20\u64ad\u5c5e\u6027<\/h2>\n<p>org.springframework.transaction.annotation.Propagation \u5b9a\u4e49\u4e86 Spring \u7684\u4e8b\u52a1\u4f20\u64ad\u5c5e\u6027\uff1a<\/p>\n<ul>\n<li>\n<p>REQUIRED: \u652f\u6301\u5f53\u524d\u4e8b\u52a1\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u65b0\u5efa\u4e00\u4e2a\u3002<\/p>\n<\/li>\n<li>\n<p>REQUIRES_NEW: \u521b\u5efa\u65b0\u7684\u4e8b\u52a1\uff0c\u5982\u679c\u5f53\u524d\u5b58\u5728\u4e00\u4e2a\u5219 suppend \u5f53\u524d\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>SUPPORTS: \u652f\u6301\u5f53\u524d\u4e8b\u52a1\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u6267\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>MANDATORY: \u652f\u6301\u5f53\u524d\u4e8b\u52a1\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<\/li>\n<li>\n<p>NOT_SUPPORTED: \u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u6267\u884c\uff0c\u5982\u679c\u5f53\u524d\u5b58\u5728\u4e00\u4e2a\u4e8b\u52a1\u5219 suppend \u5f53\u524d\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>NEVER: \u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u6267\u884c\uff0c\u5982\u679c\u5b58\u5728\u4e8b\u52a1\u5219\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<\/li>\n<li>\n<p>NESTED: \u5982\u679c\u5f53\u524d\u5b58\u5728\u4e00\u4e2a\u4e8b\u52a1\u5219\u4ee5\u5d4c\u5957\u4e8b\u52a1\u7684\u65b9\u5f0f\u6267\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u4e00\u4e2a\u751f\u4ea7\u95ee\u9898<\/h2>\n<p>\u4e00\u5f00\u59cb\u662f DBA \u53cd\u9988\u6570\u636e\u5e93\u51fa\u73b0\u4e24\u79cd\u73b0\u8c61\uff1a<\/p>\n<ol>\n<li>\u51fa\u73b0\u4e00\u4e9b\u64cd\u4f5c\u505a\u5b8c\u4f46\u4f1a\u8bdd\u4e00\u76f4\u8fd8\u5728\u7b49\u5f85\u5ba2\u6237\u7aef\u7684\u63d0\u4ea4\u52a8\u4f5c\u3002<\/li>\n<li>\u5076\u5c14\u51fa\u73b0\u5927\u91cf\u7684\u884c\u9501\uff0c\u5bfc\u81f4 JVM \u7ebf\u7a0b\u4e92\u76f8\u7b49\u5f85\u800c\u5047\u6b7b\u3002<\/li>\n<\/ol>\n<p>\u6709\u4e2a\u83b7\u53d6\u6d41\u6c34\u53f7\u7684\u65b9\u6cd5 <code>systemService.getSerialNo<\/code> \u7684\u4e8b\u52a1\u4f20\u64ad\u5c5e\u6027\u662f <code>NOT_SUPPORTED<\/code> \u7684\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u901a\u8fc7\u7c7b\u4f3c\u8fd9\u6837\u7684 <code>update t_serialno set serial_no = :newSerialNo where serial_key = :key and serial_no = :oldSerialNo<\/code> SQL \u8bed\u53e5\u8fdb\u884c\u66f4\u65b0\uff0c\u66f4\u65b0\u8fd4\u56de\u7684\u53d7\u5f71\u54cd\u884c\u6570\u7b49\u4e8e 1 \u8ba4\u4e3a\u65b0\u7684\u6d41\u6c34\u53f7\u662f\u4e0d\u91cd\u590d\u7684\uff0c\u66f4\u65b0\u4e0d\u6210\u529f\u5219\u91cd\u8bd5\u3002<\/p>\n<p>\u884c\u9501\u5c31\u51fa\u73b0\u5728\u8fd9\u4e9b\u6d41\u6c34\u53f7\u7684\u66f4\u65b0\u4e0a\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u6709\u4e9b\u9057\u7559\u4ee3\u7801\u9700\u8981\u76f4\u63a5\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u5bf9\u8c61\uff0c\u5305\u88c5\u6210 ConnectionWrapper(Connection) \u5bf9\u8c61\uff0c\u8fd9\u4e2a ConnectionWrapper \u7684\u6784\u9020\u51fd\u6570\u628a\u4f20\u5165\u7684 Connection \u5bf9\u8c61\u8bbe\u7f6e\u4e3a\u975e\u81ea\u52a8\u63d0\u4ea4\u3002<\/p>\n<p>\u51fa\u95ee\u9898\u7684\u65b9\u6cd5\u4f53\u5927\u6982\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"java\">public void submit() {\n    Connection connection = sqlSessionTemplate.getConnection();\n    ConnectionWrapper wrapper = new ConnectionWrapper(Connection);\n    \/\/ ...\n    String serialNo = systemService.getSerialNo(,,,);\n}\n<\/code><\/pre>\n<p><code>sqlSessionTemplate.getConnection()<\/code> \u83b7\u5f97\u7684\u8fde\u63a5\u9ed8\u8ba4\u662f\u8ddf\u5f53\u524d\u7ebf\u7a0b\u7ed1\u5b9a\u7684\uff0c<code>systemService.getSerialNo<\/code> \u5728\u6ca1\u6709\u4e8b\u52a1\u7684\u65b9\u6cd5\u91cc\uff0c\u4f1a\u91cd\u7528\u5f53\u524d\u7ebf\u7a0b\u7684\u8fde\u63a5\uff0c\u7136\u800c\u6b64\u5904\u8fd9\u4e2a\u8fde\u63a5\u6ca1\u6709\u542f\u52a8\u63d0\u4ea4\u4e8b\u52a1\u7684\u80fd\u529b\uff08\u5982\u679c submit \u65b9\u6cd5\u4e0a\u6709\u58f0\u660e\u4e8b\u52a1\uff0c\u5219\u4f1a suppend \u5f53\u524d\u4e8b\u52a1\uff0c\u7136\u540e\u7528\u4e00\u4e2a\u65b0\u8fde\u63a5\u53bb\u5b8c\u6210\u975e\u4e8b\u52a1\u7684\u64cd\u4f5c\uff09\u3002\u8be5\u65b9\u6cd5\u4f1a\u591a\u6b21\u83b7\u53d6\u6d41\u6c34\u53f7\uff0c\u5728\u5e76\u53d1\u538b\u529b\u5927\u65f6\u5c31\u4f1a\u51fa\u73b0\u4e92\u76f8\u7b49\u5f85\u3002<\/p>\n<p>\u540e\u7eed\u7684\u4ee3\u7801\u5e76\u6ca1\u6709\u628a \u8fde\u63a5 \u8bbe\u7f6e\u56de \u81ea\u52a8\u63d0\u4ea4\uff0c\u68c0\u67e5\u53d1\u73b0\u662f\u91c7\u7528\u7684 DBCP \u8fde\u63a5\u6c60\u5728\u8fde\u63a5\u8fd4\u56de\u7ed9\u6c60\u65f6\u4f1a\u81ea\u52a8\u628a\u8fde\u63a5\u8bbe\u7f6e\u4e3a\u81ea\u52a8\u63d0\u4ea4\u3002<\/p>\n<p>\u4e4b\u524d\u4e00\u76f4\u6ca1\u60f3\u660e\u767d\uff1a\u4e8b\u52a1\u7ba1\u7406\u90fd\u662f\u7531 Spring \u7ba1\u7406\u7684\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u4e8b\u52a1\u505a\u5b8c\u4e86\u53c8\u4e0d\u63d0\u4ea4\uff1f\u5c31\u7b97\u6709\u7684\u91c7\u7528\u4e86\u9057\u7559\u4ee3\u7801\u5bfc\u81f4\u6ca1\u6709\u624b\u5de5\u63d0\u4ea4\u4e8b\u52a1\uff0c\u90a3\u4e48\u540e\u7eed\u7528\u5230\u8fd9\u4e2a\u8fde\u63a5\u7684\u5176\u4ed6\u8bf7\u6c42\u7684\u4e8b\u52a1\u4e5f\u4e0d\u4f1a\u63d0\u4ea4\uff0c\u8fd9\u5e94\u8be5\u5f88\u5feb\u5c31\u80fd\u53d1\u73b0\u624d\u5bf9\u5440\uff0c\u73b0\u5b9e\u4e2d\u597d\u50cf\u6ca1\u6709\u51fa\u73b0\u3002<\/p>\n<p>\u884c\u9501\u4e00\u76f4\u7b49\u5f85\u4e5f\u662f\u56e0\u4e3a\u6ca1\u6709\u8bbe\u7f6e\u8bed\u53e5\u6267\u884c\u7684\u8d85\u65f6\u65f6\u95f4\uff08DBCP 1.4 \u597d\u50cf\u6ca1\u53c2\u6570\u53ef\u8bbe\uff09\uff0c\u5728\u8fde\u63a5\u6c60\u83b7\u53d6\u8fde\u63a5\u4e0a\u4e00\u76f4\u7b49\u5f85\u662f\u56e0\u4e3a\u6ca1\u6709\u8bbe\u7f6e\u83b7\u53d6\u8fde\u63a5\u7684\u6700\u5927\u7b49\u5f85\u65f6\u95f4\u3002<\/p>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring \u7684\u4e8b\u52a1\u4f20\u64ad\u5c5e\u6027 org.springframework.trans &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/framework\/20180130\/1602\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[255],"tags":[172,208],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1602"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=1602"}],"version-history":[{"count":1,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1602\/revisions"}],"predecessor-version":[{"id":1603,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/1602\/revisions\/1603"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=1602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=1602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=1602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}