{"id":376836,"date":"2024-05-23T09:00:05","date_gmt":"2024-05-23T09:00:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=376836"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-23T09:00:05","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=376836","title":{"rendered":"<span>\u0417\u0430\u043c\u0435\u0442\u0430\u0435\u043c \u0440\u0443\u0442\u0438\u043d\u0443 \u043f\u043e\u0434 \u043a\u043e\u0432\u0451\u0440. \u0428\u0430\u0431\u043b\u043e\u043d Step Builder \u0432 Java<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u0430\u043b\u043e\u0432\u0430\u0436\u043d\u043e\u0435<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u0443\u043f\u0435\u0440 \u0441\u0442\u0430\u0440 (>=12 \u043b\u0435\u0442). \u042d\u0442\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 Compile time State Machine. \u0410 \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043b\u0443\u0442\u0430\u0442\u044c \u043f\u043e \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c \u043a\u0430\u043a \u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044c \u041f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0430\u0449\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0432\u044b \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u043b\u043e<\/p>\n<\/li>\n<li>\n<p>Help me Step Builder! I copypaste!<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0423 \u043c\u043d\u043e\u0433\u0438\u0445 \u0432 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u043b\u0438\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u0433\u043e\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438 \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e\u0435, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u0435\u0435 \u0436\u0435 \u043e\u0431\u0441\u0442\u043e\u044f\u0442 \u0434\u0435\u043b\u0430, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u0439 \u0436\u0435, \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b. \u0412 \u0442\u0430\u043a\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0437\u0433 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0447\u0435\u0441\u0430\u0442\u044c\u0441\u044f, \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0435\u043b\u044c\u0437\u044f.<\/p>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 &#8212; \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u043e\u0433\u043e JDBC (\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0435\u0441\u0442\u044c\/\u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0433\u043e). \u0421\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 getUser()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">private @Nullable User getUser(int id) {         String sql = \"SELECT * FROM users_table WHERE id = ?\"         try (Connection dbConnect = myConnectionPool.getConnection()) {              try(PreparedStatement sqlPrepare = dbConnect.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {                 sqlPrepare.setInt(1, id);                 try(ResultSet rs = sqlPrepare.executeQuery()) {                     if (rs.next()) {                         return new User(rs.getInt(\"id\"), rs.getInt(\"money\"),                                 rs.getString(\"name\"),                                 rs.getString(\"surname\"),                                 rs.getString(\"patronymic\"),                                 rs.getString(\"login\"));                         }                 }             } catch (SQLException e) {                 log.error(String.format(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \\\"%s\\\"\", sql), e);             }         } catch (SQLException e) {             log.error(\"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a \u0411\u0414\", e);         }         return null;     }<\/code><\/pre>\n<blockquote>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0442\u043e \u0436\u0435 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e \u0424\u0418\u041e, \u0442\u0435\u0445, \u0443 \u043a\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 1000 &#171;\u0434\u0435\u043d\u0435\u0433&#187; \u0438 \u0435\u0449\u0451 100 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439 \u0432 \u0434\u0435\u0441\u044f\u0442\u043a\u0435 \u0442\u0430\u0431\u043b\u0438\u0446.<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0442\u0430\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c <\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u043c\u0441\u044f \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u043c PreparedStatement \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f query plan, \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u0443\u043c\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 ConnectionPool. <\/p>\n<p>\u041d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u043e\u043b\u044f\u043c \u044e\u0437\u0435\u0440\u0430? \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u043c\u044b \u0432\u044b\u043d\u043e\u0441\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 sql \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u041e\u043a\u0435\u0439, \u0442\u0443\u0442 \u0436\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0443\u0447\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u044b\u0448\u0435:<\/p>\n<ol>\n<li>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432?<\/p>\n<\/li>\n<li>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u0430 int?<\/p>\n<\/li>\n<li>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e .executeQuery(), \u043d\u043e \u0438 executeUpdate()? <\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 &#171;\u0427\u0442\u043e \u0435\u0441\u043b\u0438&#187; \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0432\u0435\u043b\u0438\u043a\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0442\u0440\u0451\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u041c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u0442\u0438\u043d\u0443<\/p>\n<\/li>\n<\/ol>\n<p>\u0410 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0430\u0436 \u0442\u0440\u0451\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 try-with-resources, \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442. \u041d\u043e \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043a\u0440\u0443\u0442\u0438\u0442\u044c\u0441\u044f.<\/p>\n<h2>\u0421 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c?<\/h2>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0440\u0430\u0437\u043e\u0431\u044c\u0451\u043c \u043c\u0435\u0442\u043e\u0434, \u0430 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0441\u043e\u0431\u0435\u0440\u0451\u043c? \u041f\u0440\u044f\u043c \u043a\u0430\u043a \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>\u0412\u0441\u0435\u043c \u043d\u0430\u043c \u0437\u043d\u0430\u043a\u043e\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d Builder, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0433\u0438\u0431\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044f \u043a\u0443\u0447\u0443 &#171;\u0442\u0435\u043b\u0435\u0441\u043a\u043e\u043f\u0438\u0447\u0435\u0441\u043a\u0438\u0445&#187; \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439. \u0411\u0438\u043b\u0434\u0435\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 &#171;\u043f\u043e \u043a\u0443\u0441\u043a\u0430\u043c&#187; \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u043a\u043e\u0434\u0430, \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u0445. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0442\u0443\u0442?<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 Builder \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 &#8212; \u043a\u043b\u0430\u0441\u0441 \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0441\u0435\u0442\u0442\u0435\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u0434\u043b\u044f Connection, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0434 Supplier&lt;Connection>, \u0447\u0442\u043e\u0431\u044b \u0431\u0440\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u043e\u0432\u044b\u0439 \u0438\u0437 \u043f\u0443\u043b\u0430<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f SQL-\u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f Consumer&#8217;\u0430 PreparedStatement, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0433\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <\/p>\n<\/li>\n<li>\n<p>\u043a\u0430\u043a \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430, \u0434\u043b\u044f \u0441\u0430\u043c\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443<\/p>\n<\/li>\n<\/ul>\n<p>\u0418, \u043f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 Query \u043c\u0435\u0442\u043e\u0434 &lt;T> execute(), \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 Function&lt;ResultSet, T> \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u0445\u043e\u0442\u044f \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c executeUpdate()?)<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0441\u0451 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u044b &#8212; \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c QueryBuilder&#8217;\u043e\u043c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e &#8212; \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c sql, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c, \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0432 Connection. \u041e\u0436\u0438\u0434\u0430\u0435\u043c\u043e, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c NullPointerException, \u043f\u043e\u043f\u044b\u0442\u0430\u0432\u0448\u0438\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 Connection \u0438\u0437 Supplier&#8217;\u0430. \u0418 \u0445\u043e\u0440\u043e\u0448\u043e, \u0447\u0442\u043e \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u043d\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u043d\u0435 \u043e\u0434\u043d\u0438, \u0434\u0430 \u0438 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043c \u0438 \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e. <\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">class Query {   private Query(\/*args*\/) {}   public static QueryBuilder builder() {} \/\/\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0431\u0438\u043b\u0434\u0435\u0440    public &lt;T> Optional&lt;T> execute(Function&lt;ResultSet, T>) {     \/\/\u0422\u043e \u0436\u0435 \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043d\u043e \u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u043b\u0434\u0435\u0440\u043e\u043c   }    public static class QueryBuilder {     private Connection c;     private String sql;     private List&lt;Consumer&lt;PreparedStatement>> paramSetters = new ArrayList&lt;>();          public QueryBuilder setConnection(Connection)     public QueryBuilder setSql(String)     public QueryBuilder setParam(int\/long\/String\/etc...) \/\/\u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432     public Query build()   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">Query.builder().build().execute(rs -> rs.next); \/\/NullPointerException<\/code><\/pre>\n<p>\u0421 \u0442\u0430\u043a\u0438\u043c \u043c\u044b \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u043f\u043e\u0439\u043c\u0430\u0435\u043c NPE \u0438\u043b\u0438 SQLException. \u0412 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0448\u0430\u0435\u043c\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u0435\u0435.<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u0432\u0441\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0438\u043b\u0434\u0435\u0440 \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442.<\/p>\n<h2>\u0427\u0442\u043e \u043c\u0435\u043d\u044f\u0435\u043c?<\/h2>\n<p>\u0423 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0433\u043e, \u043e\u0431\u0432\u044f\u0437\u043a\u0430 \u0443\u0431\u0440\u0430\u043d\u0430 \u0432 \u043d\u0435\u0434\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Query, \u043d\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e: \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u041e\u043d \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c Connection<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c SQL-statement \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0437\u043d\u0430\u043a\u0430\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0442\u0438\u043f<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434 &#171;\u041e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430 \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0431\u0438\u043b\u0434\u0435\u0440\u0435, \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0435\u0433\u043e \u0436\u0435, \u043d\u043e \u043f\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c&#187;<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0432 \u0441\u0435\u0442\u0438. <\/p>\n<p>\u041f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 &#171;Structured builder&#187; Google \u0432\u044b\u0434\u0430\u0451\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043d\u0430 stackexhcange \u0438 stackoverflow, \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0430\u0440\u043e\u0447\u043a\u0443 \u0441\u0442\u0430\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u0435\u0442\u0443\u044e\u0442 \u043f\u043e \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/blog.crisp.se\/2013\/10\/09\/perlundholm\/another-builder-pattern-for-java\" rel=\"noopener noreferrer nofollow\">\u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u0431\u0438\u043b\u0434\u0435\u0440 \u0432 Java<\/a> &#8212; \u0441\u0442\u0430\u0442\u044c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0447\u0442\u0438 11 \u043b\u0435\u0442 &#8212; \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u043d\u043e\u0432\u0430. \u0417\u0434\u0435\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e \u043f\u043e\u0445\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/rdafbn.blogspot.com\/2012\/07\/step-builder-pattern_28.html\" rel=\"noopener noreferrer nofollow\">Step builder pattern<\/a> &#8212; \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e \u0448\u0430\u0433\u043e\u0432\u043e\u043c\u0443 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044e &#8212; \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u043e \u0447\u0442\u043e \u043d\u0430\u0434\u043e!<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0431\u0438\u043b\u0434\u0435\u0440\u0435, \u043d\u0430\u0445\u043e\u0434\u0438\u043c, \u0447\u0442\u043e \u0443 \u0437\u0430\u043f\u0430\u0434\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u0433 \u043e\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Step Builder, \u0447\u0442\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u043c\u043e\u0435\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f. \u0412\u043f\u0440\u0435\u0434\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e. <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u043c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. <\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043a\u0430\u043f\u0440\u0438\u0437: \u0443 \u043d\u0430\u0441 \u0432\u0441\u0451 \u0435\u0441\u0442\u044c, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u044f \u0445\u043e\u0447\u0443 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u043b\u044e\u0431\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437. \u0414\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u0448\u0430\u0433\u043e\u0432. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u0432\u0435\u0434\u0443\u0449\u0438\u043c\u0438 \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443<\/p>\n<h2>\u0427\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c?<\/h2>\n<details class=\"spoiler\">\n<summary>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 Query (260 \u0441\u0442\u0440\u043e\u043a)<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.Nullable;  import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; import java.util.function.Supplier;  \/**  * \u041a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414.  * \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0448\u0430\u0433\u043e\u0432\u044b\u0439 \u0431\u0438\u043b\u0434\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.  * \u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430 {@link Query#withConnection} \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e \u043c\u0435\u0440\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b  * \u0418\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u0435\u043d, \u043a\u0440\u043e\u043c\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u043c {@link StatementSetter#setParam}  * \u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u043e\u043b\u043d\u0430\u044f \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c {@link StatementSetter#setParams}  *\/ @Slf4j public class Query {      \/**      * \u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e \u043c\u0435\u0440\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b      * @param connection {@link Supplier&lt;Connection>} \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 {@link Connection}      * @return {@link SqlSetter}, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u0437\u0443      *\/     @NonNull     public static SqlSetter withConnection(@NonNull Supplier&lt;Connection> connection) {         return new SqlSetter(connection);     }     \/**      * \u0412\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433. \u041f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 SQL \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0431\u0438\u043b\u0434\u0435\u0440      *\/     public static final class SqlSetter {         private final Supplier&lt;Connection> connection;         private SqlSetter(@NonNull Supplier&lt;Connection> connection) {             this.connection = connection;         }          \/**          * @param sql \u0421\u0442\u0440\u043e\u043a\u0430 SQL \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430          * @return \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433          *\/         @NonNull         public StatementSetter withSql(@NonNull String sql) {             return new StatementSetter(connection, sql);         }     }      \/**      * \u0422\u0440\u0435\u0442\u0438\u0439 \u0448\u0430\u0433. \u041d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 {@link PreparedStatement}      *\/     public static final class StatementSetter {         private final Supplier&lt;Connection> connection;         private final String sql;         private final List&lt;ParamSetter> paramSetters = new ArrayList&lt;>();          private StatementSetter(Supplier&lt;Connection> connection, String sql) {             this.connection = connection;             this.sql = sql;         }          \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(int param) {             paramSetters.add(preparedStatement -> preparedStatement.setInt(paramSetters.size() + 1, param));             return this;         }         \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(@NonNull String param) {             paramSetters.add(preparedStatement -> preparedStatement.setString(paramSetters.size() + 1, param));             return this;         }         \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(boolean param) {         paramSetters.add(preparedStatement -> preparedStatement.setBoolean(paramSetters.size() + 1, param));             return this;         }         \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(@NonNull Date param) {             java.sql.Date date = new java.sql.Date(param.getTime());             paramSetters.add(preparedStatement -> preparedStatement.setDate(paramSetters.size() + 1, date));             return this;         }         \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(double param) {             paramSetters.add(preparedStatement -> preparedStatement.setDouble(paramSetters.size() + 1, param));             return this;         }         \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(short param) {             paramSetters.add(preparedStatement -> preparedStatement.setShort(paramSetters.size() + 1, param));             return this;         }         \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(float param) {             paramSetters.add(preparedStatement -> preparedStatement.setFloat(paramSetters.size() + 1, param));             return this;         }         \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 {@link StatementSetter#done}          *\/         @NonNull         public StatementSetter setParam(long param) {             paramSetters.add(preparedStatement -> preparedStatement.setLong(paramSetters.size() + 1, param));             return this;         }         \/**          * \u0412\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433          *\/         @NonNull         public QueryExecutor done() {             return new QueryExecutor(connection, sql, paramSetters);         }          \/**          * @param statementConsumer \u043a\u043e\u043d\u0441\u0443\u043c\u0435\u0440 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 {@link PreparedStatement}          * @return \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433          *\/         @NonNull         public QueryExecutor setParams(@NonNull ParamSetter statementConsumer) {             return new QueryExecutor(connection, sql, Collections.singletonList(statementConsumer));         }      }      \/**      * \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433 \u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f      *\/     public static final class QueryExecutor {         private final Supplier&lt;Connection> connection;         private final String sql;         private final List&lt;ParamSetter> paramSetters;private QueryExecutor(@NonNull Supplier&lt;Connection> connection,                               @NonNull String sql,                               @NonNull List&lt;ParamSetter> paramSetters) {             this.connection = connection;             this.sql = sql;             this.paramSetters = paramSetters;         }          \/**          * \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439          * @return -1 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u0418\u043d\u0430\u0447\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439          *\/         public int executeUpdate() {             return Optional.ofNullable(executeAndGet(preparedStatement -> {                 try {                     return preparedStatement.executeUpdate();                 } catch (SQLException e) {                     log.error(String.format(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f Update \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \\\"%s\\\"\", sql), e);                     return -1;                 }             })).orElse(0);         }          \/**          * @param executor \u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 {@link ResultSet}          * @param &lt;T> \u0422\u0438\u043f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439          * @return \u0422\u043e, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u0430\u044f \u0432 {@link Optional}          *\/         @NonNull         public &lt;T> Optional&lt;T> executeQuery(@NonNull DataTransformer&lt;ResultSet, T> executor) {             return Optional.ofNullable(executeAndGet(statement -> {                 try {                     return executor.transformData(statement.executeQuery());                 } catch (SQLException e) {                     log.error(String.format(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f Query \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \\\"%s\\\"\", sql), e);                     return null;                 }             }));         }          \/**          * \u041d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 {@link PreparedStatement}.          * @param executor \u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 {@link PreparedStatement}          * @param &lt;T> \u0422\u0438\u043f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439          * @return \u0422\u043e, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f          *\/         @Nullable         private &lt;T> T executeAndGet(@NonNull DataTransformer&lt;PreparedStatement, T> executor) {             try (Connection dbConnect = connection.get()) {                 try(PreparedStatement sqlPrepare = dbConnect.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {                     for (int i = 0; i &lt; paramSetters.size(); i++) {                         try {                             paramSetters.get(i).setParam(sqlPrepare);                         } catch (SQLException e) {                             log.error(\"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c %d \u043f\u043e \u0441\u0447\u0451\u0442\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\".formatted(i), e);                         }                     }                     executor.transformData(sqlPrepare);                 } catch (SQLException e) {                     log.error(String.format(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \\\"%s\\\"\", sql), e);                 }             } catch (SQLException e) {                 log.error(\"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445\", e);             }             return null;         }     }      \/**      * \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 PreparedStatement, \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043b\u044f\u043c\u0431\u0434\u043e\u0439      *\/     public interface ParamSetter {         \/**          * \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 PreparedStatement, \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043b\u044f\u043c\u0431\u0434\u043e\u0439          * @param statement \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0432 \u043b\u044f\u043c\u0431\u0434\u0443 \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a          * @throws SQLException \u0435\u0441\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0435\u0433\u043e \u0432\u044b\u043a\u0438\u043d\u0435\u0442          *\/         void setParam(@NonNull PreparedStatement statement) throws SQLException;     }     \/**      * \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 PreparedStatement \u0438\u043b\u0438 ResultSet), \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043b\u044f\u043c\u0431\u0434\u043e\u0439      *\/     public interface DataTransformer&lt;S, T> {         \/**          * @param source \u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 PreparedStatement \u0438\u043b\u0438 ResultSet)          * @return \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f          * @throws SQLException \u0435\u0441\u043b\u0438 \u0432\u044b\u043b\u0435\u0442\u0438\u0442 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 PreparedStatement \u0438\u043b\u0438 ResultSet          *\/         T transformData(S source) throws SQLException;     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u043e\u0447\u0435, \u043d\u043e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0435\u0435:<\/p>\n<pre><code class=\"java\">@NonNull public Optional&lt;User> getById(int id) {     return Query.withConnection(getConnectionSupplier())         .withSql(\"SELECT * FROM users_table WHERE %s = ?\".formatted(User.Fields.ID))         .setParam(id)         .done()         .executeQuery(resultSet -> {             if (resultSet.next()) {                 return new User(                     resultSet.getInt(\"id\"),                      resultSet.getInt(\"money\"),                     resultSet.getString(\"name\"),                     resultSet.getString(\"surname\"),                     resultSet.getString(\"patronymic\"),                     resultSet.getString(\"login\"));             }              return null;         }); }<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u0435\u0441\u043b\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u043e\u0434\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Query.withConnection(getConnectionSupplier()). <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c .withSql(&#171;SELECT * FROM users_table WHERE %s = ?&#187;.formatted(<a href=\"http:\/\/User.Fields.ID\" rel=\"noopener noreferrer nofollow\">User.Fields.ID<\/a>)) \u0434\u043b\u044f \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u044e\u0449\u0438\u0445 \u0447\u0442\u043e-\u0442\u043e \u0438\u0437 User \u043f\u043e \u0435\u0433\u043e ID (\u0445\u043e\u0442\u044f \u0438 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438). \u0412\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0440\u0435. <\/p>\n<h2>\u041a\u0430\u043a\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u044b \u0434\u0435\u043b\u0430\u0435\u043c?<\/h2>\n<p>\u0428\u0430\u0433\u043e\u0432\u044b\u0439 \u0431\u0438\u043b\u0434\u0435\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0439\u0441\u044f, \u043d\u043e \u043f\u043b\u043e\u0445\u043e \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0432\u044b\u0434\u0435\u043b\u0438\u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u0442\u0430\u043f\u0430. \u0421 \u043d\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0435 \u0437\u0430\u0431\u043b\u0443\u0434\u044f\u0442\u0441\u044f \u0432 \u0447\u0451\u043c-\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u043c.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u0432 \u0447\u0451\u043c \u043f\u043b\u043e\u0445 \u0438 \u0445\u043e\u0440\u043e\u0448 \u0442\u0430\u043a\u043e\u0439 \u0431\u0438\u043b\u0434\u0435\u0440: \u044d\u0442\u043e \u0432\u0438\u0434\u043d\u043e \u0434\u0430\u0436\u0435 \u043d\u0430 \u0442\u0430\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/p>\n<p><strong>\u041f\u043b\u044e\u0441\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041b\u0435\u0433\u043e\u043a \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u043e\u0447\u0435\u0432\u0438\u0434\u0435\u043d<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0451\u043c \u0442\u0435\u043b\u043e\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430, \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043f\u043e\u0440\u044b\u0432\u044b \u043a \u0431\u0435\u0437\u0434\u0443\u043c\u043d\u043e\u043c\u0443 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u043e\u043b\u044c\u043d\u043e\u0434\u0443\u043c\u0441\u0442\u0432\u0430 (\u043f\u0440\u0438 \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438) \u0438 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0439 \u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0438\u043b\u0438 \u0431\u043e\u0433\u0430\u0442\u043e\u0439 \u043d\u0435\u043a\u043e\u043c\u043f\u0435\u0442\u0435\u043d\u0442\u043d\u044b\u043c\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c\u0438 \u0441\u0440\u0435\u0434\u0435 \u0431\u0435\u0437 \u0440\u0438\u0441\u043a\u0430 \u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0439 (\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0442\u0443\u0442 \u044f \u043f\u043e\u0433\u043e\u0440\u044f\u0447\u0438\u043b\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u0439, \u043b\u044e\u0431\u043e\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 (\u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432) \u043a \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041c\u0438\u043d\u0443\u0441\u044b:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u043e\u0442\u0442\u043e\u0447\u0438\u0442\u044c. \u0421\u0445\u043e\u0434\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0434\u044b\u0435 \u0432\u043e\u043b\u043e\u0441\u044b \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u0432 \u0431\u0438\u043b\u0434\u0435\u0440, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b. \u0425\u043e\u0440\u043e\u0448\u0435\u043d\u044c\u043a\u043e \u043f\u043e\u043a\u0440\u043e\u0439\u0442\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0442\u0435\u0441\u0442\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043b\u0435\u0437\u0442\u044c \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c!<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0431\u0438\u043b\u0434\u0435\u0440\u0430, \u043d\u043e \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0442\u0430\u043a \u0438 \u0446\u0435\u043b\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 (\u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0437\u0434\u0440\u0430\u0432\u043e\u0433\u043e \u0441\u043c\u044b\u0441\u043b\u0430). \u0428\u0430\u0431\u043b\u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043f\u0440\u044f\u0442\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0438\u0437 \u0440\u0430\u0437\u0430 \u0432 \u0440\u0430\u0437 \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430, \u0432\u044b\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430.<\/p>\n<p>\u0421 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435\u043c \u043e\u0442\u0432\u0435\u0447\u0443 \u043d\u0430 \u043a\u0440\u0438\u0442\u0438\u043a\u0443 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b. \u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/816471\/\"> https:\/\/habr.com\/ru\/articles\/816471\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<\/p>\n<details class=\"spoiler\">\n<summary>\u041c\u0430\u043b\u043e\u0432\u0430\u0436\u043d\u043e\u0435<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0441\u0443\u043f\u0435\u0440 \u0441\u0442\u0430\u0440 (>=12 \u043b\u0435\u0442). \u042d\u0442\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 Compile time State Machine. \u0410 \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043b\u0443\u0442\u0430\u0442\u044c \u043f\u043e \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c \u043a\u0430\u043a \u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044c \u041f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0430\u0449\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0432\u044b \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u043b\u043e<\/p>\n<\/li>\n<li>\n<p>Help me Step Builder! I copypaste!<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0423 \u043c\u043d\u043e\u0433\u0438\u0445 \u0432 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u043b\u0438\u0441\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u0433\u043e\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438 \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e\u0435, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u0435\u0435 \u0436\u0435 \u043e\u0431\u0441\u0442\u043e\u044f\u0442 \u0434\u0435\u043b\u0430, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u0439 \u0436\u0435, \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b. \u0412 \u0442\u0430\u043a\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0437\u0433 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0447\u0435\u0441\u0430\u0442\u044c\u0441\u044f, \u0431\u0435\u0437\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043d\u043e \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0435\u043b\u044c\u0437\u044f.<\/p>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 &#8212; \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u043e\u0433\u043e JDBC (\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0435\u0441\u0442\u044c\/\u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0433\u043e). \u0421\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 getUser()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">private @Nullable User getUser(int id) {         String sql = \"SELECT * FROM users_table WHERE id = ?\"         try (Connection dbConnect = myConnectionPool.getConnection()) {              try(PreparedStatement sqlPrepare = dbConnect.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {                 sqlPrepare.setInt(1, id);                 try(ResultSet rs = sqlPrepare.executeQuery()) {                     if (rs.next()) {                         return new User(rs.getInt(\"id\"), rs.getInt(\"money\"),                                 rs.getString(\"name\"),                                 rs.getString(\"surname\"),                                 rs.getString(\"patronymic\"),                                 rs.getString(\"login\"));                         }                 }             } catch (SQLException e) {                 log.error(String.format(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \\\"%s\\\"\", sql), e);             }         } catch (SQLException e) {             log.error(\"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a \u0411\u0414\", e);         }         return null;     }<\/code><\/pre>\n<blockquote>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0442\u043e \u0436\u0435 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e \u0424\u0418\u041e, \u0442\u0435\u0445, \u0443 \u043a\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 1000 &#171;\u0434\u0435\u043d\u0435\u0433&#187; \u0438 \u0435\u0449\u0451 100 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439 \u0432 \u0434\u0435\u0441\u044f\u0442\u043a\u0435 \u0442\u0430\u0431\u043b\u0438\u0446.<\/p>\n<\/blockquote>\n<p>\u041d\u0430\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0442\u0430\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c <\/p>\n<\/div>\n<\/details>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u043c\u0441\u044f \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u043c PreparedStatement \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f query plan, \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u0443\u043c\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 ConnectionPool. <\/p>\n<p>\u041d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u043e\u043b\u044f\u043c \u044e\u0437\u0435\u0440\u0430? \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u043c\u044b \u0432\u044b\u043d\u043e\u0441\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 sql \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u041e\u043a\u0435\u0439, \u0442\u0443\u0442 \u0436\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0443\u0447\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u044b\u0448\u0435:<\/p>\n<ol>\n<li>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432?<\/p>\n<\/li>\n<li>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u0430 int?<\/p>\n<\/li>\n<li>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e .executeQuery(), \u043d\u043e \u0438 executeUpdate()? <\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 &#171;\u0427\u0442\u043e \u0435\u0441\u043b\u0438&#187; \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0432\u0435\u043b\u0438\u043a\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0442\u0440\u0451\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/p>\n<\/li>\n<li>\n<p>\u041c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0443\u0442\u0438\u043d\u0443<\/p>\n<\/li>\n<\/ol>\n<p>\u0410 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u043f\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0430\u0436 \u0442\u0440\u0451\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 try-with-resources, \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0432\u044b\u0439\u0434\u0435\u0442. \u041d\u043e \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u043a\u0440\u0443\u0442\u0438\u0442\u044c\u0441\u044f.<\/p>\n<h2>\u0421 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c?<\/h2>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0440\u0430\u0437\u043e\u0431\u044c\u0451\u043c \u043c\u0435\u0442\u043e\u0434, \u0430 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0441\u043e\u0431\u0435\u0440\u0451\u043c? \u041f\u0440\u044f\u043c \u043a\u0430\u043a \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>\u0412\u0441\u0435\u043c \u043d\u0430\u043c \u0437\u043d\u0430\u043a\u043e\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d Builder, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0433\u0438\u0431\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044f \u043a\u0443\u0447\u0443 &#171;\u0442\u0435\u043b\u0435\u0441\u043a\u043e\u043f\u0438\u0447\u0435\u0441\u043a\u0438\u0445&#187; \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439. \u0411\u0438\u043b\u0434\u0435\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 &#171;\u043f\u043e \u043a\u0443\u0441\u043a\u0430\u043c&#187; \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u043a\u043e\u0434\u0430, \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u0445. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0442\u0443\u0442?<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 Builder \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 &#8212; \u043a\u043b\u0430\u0441\u0441 \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0441\u0435\u0442\u0442\u0435\u0440\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>\u0434\u043b\u044f Connection, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0434 Supplier&lt;Connection>, \u0447\u0442\u043e\u0431\u044b \u0431\u0440\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u043e\u0432\u044b\u0439 \u0438\u0437 \u043f\u0443\u043b\u0430<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f SQL-\u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f Consumer&#8217;\u0430 PreparedStatement, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0433\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <\/p>\n<\/li>\n<li>\n<p>\u043a\u0430\u043a \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430, \u0434\u043b\u044f \u0441\u0430\u043c\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443<\/p>\n<\/li>\n<\/ul>\n<p>\u0418, \u043f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 Query \u043c\u0435\u0442\u043e\u0434 &lt;T> execute(), \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 Function&lt;ResultSet, T> \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u0445\u043e\u0442\u044f \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c executeUpdate()?)<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0441\u0451 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u044b &#8212; \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c QueryBuilder&#8217;\u043e\u043c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e &#8212; \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c sql, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c, \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0432 Connection. \u041e\u0436\u0438\u0434\u0430\u0435\u043c\u043e, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c NullPointerException, \u043f\u043e\u043f\u044b\u0442\u0430\u0432\u0448\u0438\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 Connection \u0438\u0437 Supplier&#8217;\u0430. \u0418 \u0445\u043e\u0440\u043e\u0448\u043e, \u0447\u0442\u043e \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u043d\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u043d\u0435 \u043e\u0434\u043d\u0438, \u0434\u0430 \u0438 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u044b\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043c \u0438 \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e. <\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">class Query {   private Query(\/*args*\/) {}   public static QueryBuilder builder() {} \/\/\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0431\u0438\u043b\u0434\u0435\u0440    public &lt;T> Optional&lt;T> execute(Function&lt;ResultSet, T>) {     \/\/\u0422\u043e \u0436\u0435 \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043d\u043e \u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0431\u0438\u043b\u0434\u0435\u0440\u043e\u043c   }    public static class QueryBuilder {     private Connection c;     private String sql;     private List&lt;Consumer&lt;PreparedStatement>> paramSetters = new ArrayList&lt;>();          public QueryBuilder setConnection(Connection)     public QueryBuilder setSql(String)     public QueryBuilder setParam(int\/long\/String\/etc...) \/\/\u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432     public Query build()   } }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">Query.builder().build().execute(rs -> rs.next); \/\/NullPointerException<\/code><\/pre>\n<p>\u0421 \u0442\u0430\u043a\u0438\u043c \u043c\u044b \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u043f\u043e\u0439\u043c\u0430\u0435\u043c NPE \u0438\u043b\u0438 SQLException. \u0412 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0448\u0430\u0435\u043c\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u0435\u0435.<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u0432\u0441\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0438\u043b\u0434\u0435\u0440 \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442.<\/p>\n<h2>\u0427\u0442\u043e \u043c\u0435\u043d\u044f\u0435\u043c?<\/h2>\n<p>\u0423 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0433\u043e, \u043e\u0431\u0432\u044f\u0437\u043a\u0430 \u0443\u0431\u0440\u0430\u043d\u0430 \u0432 \u043d\u0435\u0434\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Query, \u043d\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e: \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u041e\u043d \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c Connection<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c SQL-statement \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0437\u043d\u0430\u043a\u0430\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0442\u0438\u043f<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434 &#171;\u041e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430 \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0431\u0438\u043b\u0434\u0435\u0440\u0435, \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0435\u0433\u043e \u0436\u0435, \u043d\u043e \u043f\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c&#187;<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0432 \u0441\u0435\u0442\u0438. <\/p>\n<p>\u041f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 &#171;Structured builder&#187; Google \u0432\u044b\u0434\u0430\u0451\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043d\u0430 stackexhcange \u0438 stackoverflow, \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0430\u0440\u043e\u0447\u043a\u0443 \u0441\u0442\u0430\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u0435\u0442\u0443\u044e\u0442 \u043f\u043e \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/blog.crisp.se\/2013\/10\/09\/perlundholm\/another-builder-pattern-for-java\" rel=\"noopener noreferrer nofollow\">\u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u0431\u0438\u043b\u0434\u0435\u0440 \u0432 Java<\/a> &#8212; \u0441\u0442\u0430\u0442\u044c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0447\u0442\u0438 11 \u043b\u0435\u0442 &#8212; \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u043d\u043e\u0432\u0430. \u0417\u0434\u0435\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e \u043f\u043e\u0445\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/rdafbn.blogspot.com\/2012\/07\/step-builder-pattern_28.html\" rel=\"noopener noreferrer nofollow\">Step builder pattern<\/a> &#8212; \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e \u0448\u0430\u0433\u043e\u0432\u043e\u043c\u0443 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044e &#8212; \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u043e \u0447\u0442\u043e \u043d\u0430\u0434\u043e!<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0431\u0438\u043b\u0434\u0435\u0440\u0435, \u043d\u0430\u0445\u043e\u0434\u0438\u043c, \u0447\u0442\u043e \u0443 \u0437\u0430\u043f\u0430\u0434\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u0433 \u043e\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Step Builder, \u0447\u0442\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u043c\u043e\u0435\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f. \u0412\u043f\u0440\u0435\u0434\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e. <\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u043c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. <\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043a\u0430\u043f\u0440\u0438\u0437: \u0443 \u043d\u0430\u0441 \u0432\u0441\u0451 \u0435\u0441\u0442\u044c, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u044f \u0445\u043e\u0447\u0443 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u043b\u044e\u0431\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437. \u0414\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0445 \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u0448\u0430\u0433\u043e\u0432. \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u0432\u0435\u0434\u0443\u0449\u0438\u043c\u0438 \u043e\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u043a \u0434\u0440\u0443\u0433\u043e\u043c\u0443<\/p>\n<h2>\u0427\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c?<\/h2>\n<details class=\"spoiler\">\n<summary>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 Query (260 \u0441\u0442\u0440\u043e\u043a)<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.Nullable;  import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; import java.util.function.Supplier;  \/**  * \u041a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414.  * \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0448\u0430\u0433\u043e\u0432\u044b\u0439 \u0431\u0438\u043b\u0434\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.  * \u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u0441 \u043c\u0435\u0442\u043e\u0434\u0430 {@link Query#withConnection} \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e \u043c\u0435\u0440\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b  * \u0418\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u0435\u043d, \u043a\u0440\u043e\u043c\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u043c {@link StatementSetter#setParam}  * \u0415\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043f\u043e\u043b\u043d\u0430\u044f \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c {@link StatementSetter#setParams}  *\/ @Slf4j public class Query {      \/**      * \u041d\u0430\u0447\u043d\u0438\u0442\u0435 \u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e \u043c\u0435\u0440\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b      * @param connection {@link Supplier&lt;Connection>} \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 {@link Connection}      * @return {@link SqlSetter}, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u0437\u0443      *\/     @NonNull     public static SqlSetter withConnection(@NonNull Supplier&lt;Connection> connection) {         return new SqlSetter(connection);     }     \/**      * \u0412\u0442\u043e\u0440\u043e\u0439 \u0448\u0430\u0433. \u041f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 SQL \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0431\u0438\u043b\u0434\u0435\u0440      *\/     public static final class SqlSetter {         private final Supplier&lt;Connection> connection;         private SqlSetter(@NonNull Supplier&lt;Connection> connection) {             this.connection = connection;         }          \/**          * @param sql \u0421\u0442\u0440\u043e\u043a\u0430 SQL \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430          * @return \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433          *\/         @NonNull         public StatementSetter withSql(@NonNull String sql) {             return new StatementSetter(connection, sql);         }     }      \/**      * \u0422\u0440\u0435\u0442\u0438\u0439 \u0448\u0430\u0433. \u041d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 {@link PreparedStatement}      *\/     public static final class StatementSetter {         private final Supplier&lt;Connection> connection;         private final String sql;         private final List&lt;ParamSetter> paramSetters = new ArrayList&lt;>();          private StatementSetter(Supplier&lt;Connection> connection, String sql) {             this.connection = connection;             this.sql = sql;         }          \/**          * \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 {@link PreparedStatement}          * @param param \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d. \u041c\u0435\u0442\u043e\u0434 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432          * @return \u0422\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0434\u043b\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-376836","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=376836"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376836\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=376836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=376836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=376836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}