|
| 1 | +/* |
| 2 | + * Copyright (C) 2009-2019 Slava Semushin <[email protected]> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | + */ |
| 18 | +package ru.mystamps.web.feature.series; |
| 19 | + |
| 20 | +import ru.mystamps.web.common.Currency; |
| 21 | +import ru.mystamps.web.common.JdbcUtils; |
| 22 | +import ru.mystamps.web.common.LinkEntityDto; |
| 23 | + |
| 24 | +import java.math.BigDecimal; |
| 25 | +import java.sql.ResultSet; |
| 26 | +import java.sql.SQLException; |
| 27 | +import java.util.Date; |
| 28 | + |
| 29 | +import static ru.mystamps.web.support.jdbc.RowMappers.createLinkEntityDto; |
| 30 | + |
| 31 | +final class RowMappers { |
| 32 | + |
| 33 | + private RowMappers() { |
| 34 | + } |
| 35 | + |
| 36 | + /* default */ static SitemapInfoDto forSitemapInfoDto(ResultSet rs, int unused) |
| 37 | + throws SQLException { |
| 38 | + |
| 39 | + return new SitemapInfoDto( |
| 40 | + rs.getInt("id"), |
| 41 | + rs.getTimestamp("updated_at") |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + /* default */ static SeriesLinkDto forSeriesLinkDto(ResultSet rs, int unused) |
| 46 | + throws SQLException { |
| 47 | + |
| 48 | + Integer id = rs.getInt("id"); |
| 49 | + Integer year = JdbcUtils.getInteger(rs, "release_year"); |
| 50 | + Integer quantity = rs.getInt("quantity"); |
| 51 | + Boolean perforated = rs.getBoolean("perforated"); |
| 52 | + String country = rs.getString("country_name"); |
| 53 | + |
| 54 | + return new SeriesLinkDto(id, year, quantity, perforated, country); |
| 55 | + } |
| 56 | + |
| 57 | + /* default */ static SeriesInfoDto forSeriesInfoDto(ResultSet rs, int unused) |
| 58 | + throws SQLException { |
| 59 | + |
| 60 | + Integer seriesId = rs.getInt("id"); |
| 61 | + Integer releaseDay = JdbcUtils.getInteger(rs, "release_day"); |
| 62 | + Integer releaseMonth = JdbcUtils.getInteger(rs, "release_month"); |
| 63 | + Integer releaseYear = JdbcUtils.getInteger(rs, "release_year"); |
| 64 | + Integer quantity = rs.getInt("quantity"); |
| 65 | + Boolean perforated = rs.getBoolean("perforated"); |
| 66 | + |
| 67 | + LinkEntityDto category = |
| 68 | + createLinkEntityDto(rs, "category_id", "category_slug", "category_name"); |
| 69 | + LinkEntityDto country = |
| 70 | + createLinkEntityDto(rs, "country_id", "country_slug", "country_name"); |
| 71 | + |
| 72 | + return new SeriesInfoDto( |
| 73 | + seriesId, |
| 74 | + category, |
| 75 | + country, |
| 76 | + releaseDay, |
| 77 | + releaseMonth, |
| 78 | + releaseYear, |
| 79 | + quantity, |
| 80 | + perforated |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @author Sergey Chechenev |
| 86 | + */ |
| 87 | + /* default */ static PurchaseAndSaleDto forPurchaseAndSaleDto(ResultSet rs, int unused) |
| 88 | + throws SQLException { |
| 89 | + |
| 90 | + Date date = rs.getDate("date"); |
| 91 | + String sellerName = rs.getString("seller_name"); |
| 92 | + String sellerUrl = rs.getString("seller_url"); |
| 93 | + String buyerName = rs.getString("buyer_name"); |
| 94 | + String buyerUrl = rs.getString("buyer_url"); |
| 95 | + String transactionUrl = rs.getString("transaction_url"); |
| 96 | + BigDecimal firstPrice = rs.getBigDecimal("first_price"); |
| 97 | + Currency firstCurrency = JdbcUtils.getCurrency(rs, "first_currency"); |
| 98 | + BigDecimal secondPrice = rs.getBigDecimal("second_price"); |
| 99 | + Currency secondCurrency = JdbcUtils.getCurrency(rs, "second_currency"); |
| 100 | + |
| 101 | + return new PurchaseAndSaleDto( |
| 102 | + date, |
| 103 | + sellerName, |
| 104 | + sellerUrl, |
| 105 | + buyerName, |
| 106 | + buyerUrl, |
| 107 | + transactionUrl, |
| 108 | + firstPrice, |
| 109 | + firstCurrency, |
| 110 | + secondPrice, |
| 111 | + secondCurrency |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + /* default */ static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int unused) |
| 116 | + throws SQLException { |
| 117 | + |
| 118 | + Integer seriesId = rs.getInt("id"); |
| 119 | + Integer releaseDay = JdbcUtils.getInteger(rs, "release_day"); |
| 120 | + Integer releaseMonth = JdbcUtils.getInteger(rs, "release_month"); |
| 121 | + Integer releaseYear = JdbcUtils.getInteger(rs, "release_year"); |
| 122 | + Integer quantity = rs.getInt("quantity"); |
| 123 | + Boolean perforated = rs.getBoolean("perforated"); |
| 124 | + String comment = rs.getString("comment"); |
| 125 | + Integer createdBy = rs.getInt("created_by"); |
| 126 | + |
| 127 | + BigDecimal michelPrice = rs.getBigDecimal("michel_price"); |
| 128 | + BigDecimal scottPrice = rs.getBigDecimal("scott_price"); |
| 129 | + BigDecimal yvertPrice = rs.getBigDecimal("yvert_price"); |
| 130 | + BigDecimal gibbonsPrice = rs.getBigDecimal("gibbons_price"); |
| 131 | + BigDecimal solovyovPrice = rs.getBigDecimal("solovyov_price"); |
| 132 | + BigDecimal zagorskiPrice = rs.getBigDecimal("zagorski_price"); |
| 133 | + |
| 134 | + LinkEntityDto category = |
| 135 | + createLinkEntityDto(rs, "category_id", "category_slug", "category_name"); |
| 136 | + |
| 137 | + LinkEntityDto country = |
| 138 | + createLinkEntityDto(rs, "country_id", "country_slug", "country_name"); |
| 139 | + |
| 140 | + return new SeriesFullInfoDto( |
| 141 | + seriesId, |
| 142 | + category, |
| 143 | + country, |
| 144 | + releaseDay, |
| 145 | + releaseMonth, |
| 146 | + releaseYear, |
| 147 | + quantity, |
| 148 | + perforated, |
| 149 | + comment, |
| 150 | + createdBy, |
| 151 | + michelPrice, |
| 152 | + scottPrice, |
| 153 | + yvertPrice, |
| 154 | + gibbonsPrice, |
| 155 | + solovyovPrice, |
| 156 | + zagorskiPrice |
| 157 | + ); |
| 158 | + } |
| 159 | + |
| 160 | +} |
0 commit comments