{"id":6504,"date":"2022-09-23T16:06:24","date_gmt":"2022-09-23T07:06:24","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6504"},"modified":"2024-03-24T15:03:11","modified_gmt":"2024-03-24T06:03:11","slug":"jpapagingitemreader","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6504","title":{"rendered":"JpaPagingItemReader"},"content":{"rendered":"<h1>JpaPagingItemReader<\/h1>\n<p>\ud398\uc774\uc9d5 \ubc29\uc2dd\uc5d0\ub294 \ub450\uac00\uc9c0 \ubb38\uc81c\uac00 \uc788\ub2e4.<\/p>\n<ol>\n<li>\n<p>\ud398\uc774\uc9c0\uac00 \ubb34\uc9c0 \ucee4\uc9c0\uac8c \ub418\uba74 \uc131\ub2a5\ubb38\uc81c\uac00 \ubc1c\uc0dd\ud55c\ub2e4.<\/p>\n<\/li>\n<li>\n<p>\uc5b4\ub514\uae4c\uc9c0 \uac00\uc838\uc654\ub294\uc9c0 \ud45c\uc2dc\ud558\uba74\uc11c \ub370\uc774\ud0c0\ub97c \uac00\uc838\uc624\uac8c \ub418\uba74 \uac00\uc838\uc624\uc9c0 \ubabb\ud558\ub294 \ub370\uc774\ud0c0\uac00 \ubc1c\uc0dd\ud55c\ub2e4.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-sql\">SELECT e\nFROM SrcItemEntity e JOIN SrcItemTransferEntity t ON e.id = t.itemid\nWHERE t.transferDate &lt;= e.modifiedAt\nORDER BY e.id<\/code><\/pre>\n<p>\uc704\uc640\uac19\uc740 \ucffc\ub9ac\ub85c \ub370\uc774\ud0c0\ub97c \uac00\uc838\uc624\uace0,<br \/>\ntransferDate \ub97c \uc218\uc815\ud558\uac8c \ub418\uba74,<br \/>\n\ucc98\uc74c 1~10\uac1c \uac00\uc838\uc628 \ud6c4 transferDate \ub97c \uc218\uc815\ud558\uac8c \ub418\uba74<br \/>\n\ub2e4\uc74c 2\ubc88\uc9f8 \ud398\uc774\uc9c0\ub97c \uac00\uc838\uc62c\ub54c<br \/>\n11~20\uc774 \uc544\ub2c8\ub77c 21~30 \uc744 \uac00\uc838\uc624\uac8c \ub41c\ub2e4.<\/p>\n<p>\uc774 \ubb38\uc81c\ub97c \ud574\uacb0\ud558\uae30 \uc704\ud574 getPage() \ub97c \uc218\uc815\ud574\uc11c,<br \/>\n\ud56d\uc0c1 \uccab\ubc88\uc9f8 \ud398\uc774\uc9c0\ub9cc \uac00\uc838\uc624\ub3c4\ub85d \uc218\uc815\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-java\">@Slf4j\n@Configuration\npublic class SrcItemReader {\n\n    private final EntityManagerFactory entityManagerFactory;\n\n    public SrcItemReader(@Qualifier(&quot;ServerEntityManagerFactory&quot;) EntityManagerFactory entityManagerFactory) {\n        this.entityManagerFactory = entityManagerFactory;\n    }\n\n    @Value(&quot;${batch.read-product.size}&quot;)\n    private int readProduct;\n\n    @Bean\n    public JpaPagingItemReader&lt;SrcItemEntity&gt; readForUpdate() {\n\n        JpaPagingItemReader&lt;SrcItemEntity&gt; reader = new JpaPagingItemReader&lt;&gt;() {\n            @Override\n            public int getPage() {\n                return 0;\n            }\n        };\n\n        try {\n            reader.setQueryString(\n                    &quot; SELECT e &quot;\n                            + &quot; FROM SrcItemEntity e JOIN SrcItemTransferEntity t ON e.id = t.itemid  &quot;\n                            + &quot; WHERE t.transferDate &lt;= e.modifiedAt &quot;\n                            + &quot; ORDER BY e.id &quot;\n            );\n            reader.setPageSize(readProduct);\n            reader.setName(&quot;readForUpdate&quot;);\n            reader.setEntityManagerFactory(entityManagerFactory);\n        } catch (Exception e) {\n            throw new RuntimeException(&quot;Unknown exception occurred&quot;, e);\n        }\n\n        return reader;\n    }\n\n    @Bean\n    public JpaPagingItemReader&lt;SrcItemEntity&gt; readForInsert() {\n\n        JpaPagingItemReader&lt;SrcItemEntity&gt; reader = new JpaPagingItemReader&lt;&gt;() {\n            @Override\n            public int getPage() {\n                return 0;\n            }\n        };\n\n        try {\n            reader.setQueryString(\n                    &quot; SELECT e &quot;\n                            + &quot; FROM SrcItemEntity e LEFT JOIN SrcItemTransferEntity t ON e.id = t.itemid  &quot;\n                            + &quot; WHERE t.itemid is NULL &quot;\n                            + &quot; ORDER BY e.id &quot;\n            );\n            reader.setPageSize(readProduct);\n            reader.setName(&quot;readForInsert&quot;);\n            reader.setEntityManagerFactory(entityManagerFactory);\n        } catch (Exception e) {\n            throw new RuntimeException(&quot;Unknown exception occurred&quot;, e);\n        }\n\n        return reader;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JpaPagingItemReader \ud398\uc774\uc9d5 \ubc29\uc2dd\uc5d0\ub294 \ub450\uac00\uc9c0 \ubb38\uc81c\uac00 \uc788\ub2e4. \ud398\uc774\uc9c0\uac00 \ubb34\uc9c0 \ucee4\uc9c0\uac8c \ub418\uba74 \uc131\ub2a5\ubb38\uc81c\uac00 \ubc1c\uc0dd\ud55c\ub2e4. \uc5b4\ub514\uae4c\uc9c0 \uac00\uc838\uc654\ub294\uc9c0 \ud45c\uc2dc\ud558\uba74\uc11c \ub370\uc774\ud0c0\ub97c \uac00\uc838\uc624\uac8c \ub418\uba74 \uac00\uc838\uc624\uc9c0 \ubabb\ud558\ub294 \ub370\uc774\ud0c0\uac00 \ubc1c\uc0dd\ud55c\ub2e4. SELECT e FROM SrcItemEntity e JOIN SrcItemTransferEntity t ON e.id = t.itemid WHERE t.transferDate &lt;= e.modifiedAt ORDER BY e.id \uc704\uc640\uac19\uc740 \ucffc\ub9ac\ub85c \ub370\uc774\ud0c0\ub97c \uac00\uc838\uc624\uace0, transferDate \ub97c \uc218\uc815\ud558\uac8c \ub418\uba74, \ucc98\uc74c 1~10\uac1c \uac00\uc838\uc628 \ud6c4 transferDate \ub97c\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6504\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-6504","post","type-post","status-publish","format-standard","hentry","category-spring-boot-2-5"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6504"}],"version-history":[{"count":3,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6504\/revisions"}],"predecessor-version":[{"id":8846,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6504\/revisions\/8846"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}