Skip to content

Commit 56a44c6

Browse files
committed
refactor(RowMappers): move row mappers for the ru.mystamps.web.feature.series package to this package.
Addressed to #927 No functional changes.
1 parent 2a6e796 commit 56a44c6

File tree

3 files changed

+160
-127
lines changed

3 files changed

+160
-127
lines changed

src/main/java/ru/mystamps/web/feature/series/JdbcSeriesDao.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.jdbc.support.GeneratedKeyHolder;
2727
import org.springframework.jdbc.support.KeyHolder;
2828
import ru.mystamps.web.common.JdbcUtils;
29-
import ru.mystamps.web.support.jdbc.RowMappers;
3029

3130
import java.util.Collections;
3231
import java.util.Date;
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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+
}

src/main/java/ru/mystamps/web/support/jdbc/RowMappers.java

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@
1717
*/
1818
package ru.mystamps.web.support.jdbc;
1919

20-
import ru.mystamps.web.common.Currency;
2120
import ru.mystamps.web.common.EntityWithParentDto;
2221
import ru.mystamps.web.common.JdbcUtils;
2322
import ru.mystamps.web.common.LinkEntityDto;
24-
import ru.mystamps.web.feature.series.PurchaseAndSaleDto;
25-
import ru.mystamps.web.feature.series.SeriesFullInfoDto;
26-
import ru.mystamps.web.feature.series.SeriesInfoDto;
27-
import ru.mystamps.web.feature.series.SeriesLinkDto;
28-
import ru.mystamps.web.feature.series.SitemapInfoDto;
2923

30-
import java.math.BigDecimal;
3124
import java.sql.ResultSet;
3225
import java.sql.SQLException;
33-
import java.util.Date;
3426

3527
public final class RowMappers {
3628

@@ -48,124 +40,6 @@ public static Object[] forNameAndCounter(ResultSet rs, int unused) throws SQLExc
4840
};
4941
}
5042

51-
public static SitemapInfoDto forSitemapInfoDto(ResultSet rs, int unused) throws SQLException {
52-
return new SitemapInfoDto(
53-
rs.getInt("id"),
54-
rs.getTimestamp("updated_at")
55-
);
56-
}
57-
58-
public static SeriesLinkDto forSeriesLinkDto(ResultSet rs, int unused) throws SQLException {
59-
Integer id = rs.getInt("id");
60-
Integer year = JdbcUtils.getInteger(rs, "release_year");
61-
Integer quantity = rs.getInt("quantity");
62-
Boolean perforated = rs.getBoolean("perforated");
63-
String country = rs.getString("country_name");
64-
65-
return new SeriesLinkDto(id, year, quantity, perforated, country);
66-
}
67-
68-
public static SeriesInfoDto forSeriesInfoDto(ResultSet rs, int unused) throws SQLException {
69-
Integer seriesId = rs.getInt("id");
70-
Integer releaseDay = JdbcUtils.getInteger(rs, "release_day");
71-
Integer releaseMonth = JdbcUtils.getInteger(rs, "release_month");
72-
Integer releaseYear = JdbcUtils.getInteger(rs, "release_year");
73-
Integer quantity = rs.getInt("quantity");
74-
Boolean perforated = rs.getBoolean("perforated");
75-
76-
LinkEntityDto category =
77-
createLinkEntityDto(rs, "category_id", "category_slug", "category_name");
78-
LinkEntityDto country =
79-
createLinkEntityDto(rs, "country_id", "country_slug", "country_name");
80-
81-
return new SeriesInfoDto(
82-
seriesId,
83-
category,
84-
country,
85-
releaseDay,
86-
releaseMonth,
87-
releaseYear,
88-
quantity,
89-
perforated
90-
);
91-
}
92-
93-
/**
94-
* @author Sergey Chechenev
95-
*/
96-
public static PurchaseAndSaleDto forPurchaseAndSaleDto(ResultSet rs, int unused)
97-
throws SQLException {
98-
99-
Date date = rs.getDate("date");
100-
String sellerName = rs.getString("seller_name");
101-
String sellerUrl = rs.getString("seller_url");
102-
String buyerName = rs.getString("buyer_name");
103-
String buyerUrl = rs.getString("buyer_url");
104-
String transactionUrl = rs.getString("transaction_url");
105-
BigDecimal firstPrice = rs.getBigDecimal("first_price");
106-
Currency firstCurrency = JdbcUtils.getCurrency(rs, "first_currency");
107-
BigDecimal secondPrice = rs.getBigDecimal("second_price");
108-
Currency secondCurrency = JdbcUtils.getCurrency(rs, "second_currency");
109-
110-
return new PurchaseAndSaleDto(
111-
date,
112-
sellerName,
113-
sellerUrl,
114-
buyerName,
115-
buyerUrl,
116-
transactionUrl,
117-
firstPrice,
118-
firstCurrency,
119-
secondPrice,
120-
secondCurrency
121-
);
122-
}
123-
124-
public static SeriesFullInfoDto forSeriesFullInfoDto(ResultSet rs, int unused)
125-
throws SQLException {
126-
127-
Integer seriesId = rs.getInt("id");
128-
Integer releaseDay = JdbcUtils.getInteger(rs, "release_day");
129-
Integer releaseMonth = JdbcUtils.getInteger(rs, "release_month");
130-
Integer releaseYear = JdbcUtils.getInteger(rs, "release_year");
131-
Integer quantity = rs.getInt("quantity");
132-
Boolean perforated = rs.getBoolean("perforated");
133-
String comment = rs.getString("comment");
134-
Integer createdBy = rs.getInt("created_by");
135-
136-
BigDecimal michelPrice = rs.getBigDecimal("michel_price");
137-
BigDecimal scottPrice = rs.getBigDecimal("scott_price");
138-
BigDecimal yvertPrice = rs.getBigDecimal("yvert_price");
139-
BigDecimal gibbonsPrice = rs.getBigDecimal("gibbons_price");
140-
BigDecimal solovyovPrice = rs.getBigDecimal("solovyov_price");
141-
BigDecimal zagorskiPrice = rs.getBigDecimal("zagorski_price");
142-
143-
LinkEntityDto category =
144-
createLinkEntityDto(rs, "category_id", "category_slug", "category_name");
145-
146-
LinkEntityDto country =
147-
createLinkEntityDto(rs, "country_id", "country_slug", "country_name");
148-
149-
return new SeriesFullInfoDto(
150-
seriesId,
151-
category,
152-
country,
153-
releaseDay,
154-
releaseMonth,
155-
releaseYear,
156-
quantity,
157-
perforated,
158-
comment,
159-
createdBy,
160-
michelPrice,
161-
scottPrice,
162-
yvertPrice,
163-
gibbonsPrice,
164-
solovyovPrice,
165-
zagorskiPrice
166-
);
167-
}
168-
16943
public static EntityWithParentDto forEntityWithParentDto(ResultSet rs, int unused)
17044
throws SQLException {
17145

0 commit comments

Comments
 (0)