Skip to content

Commit 28d4f89

Browse files
authored
Merge pull request #321 from domaframework/refactor
Refactor CircleType and PointType into separate files
2 parents 5053cd6 + 82906d1 commit 28d4f89

File tree

4 files changed

+97
-93
lines changed

4 files changed

+97
-93
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package example.geometric.type.domain;
2+
3+
import java.sql.CallableStatement;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.sql.Types;
8+
import org.postgresql.geometric.PGcircle;
9+
import org.postgresql.geometric.PGpoint;
10+
import org.seasar.doma.jdbc.type.AbstractJdbcType;
11+
12+
class CircleType extends AbstractJdbcType<Circle> {
13+
14+
protected CircleType() {
15+
super(Types.OTHER);
16+
}
17+
18+
@Override
19+
protected Circle doGetValue(ResultSet resultSet, int index) throws SQLException {
20+
PGcircle c = resultSet.getObject(index, PGcircle.class);
21+
return toCircle(c);
22+
}
23+
24+
@Override
25+
protected void doSetValue(PreparedStatement preparedStatement, int index, Circle value)
26+
throws SQLException {
27+
PGpoint p = new PGpoint(value.center().x(), value.center().y());
28+
PGcircle c = new PGcircle(p, value.radius());
29+
preparedStatement.setObject(index, c);
30+
}
31+
32+
@Override
33+
protected Circle doGetValue(CallableStatement callableStatement, int index) throws SQLException {
34+
PGcircle c = callableStatement.getObject(index, PGcircle.class);
35+
return toCircle(c);
36+
}
37+
38+
@Override
39+
protected String doConvertToLogFormat(Circle value) {
40+
return value.toString();
41+
}
42+
43+
static Circle toCircle(PGcircle c) {
44+
if (c == null) {
45+
return null;
46+
}
47+
Point center = PointType.toPoint(c.center);
48+
return new Circle(center, c.radius);
49+
}
50+
}
Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
package example.geometric.type.domain;
22

3-
import java.sql.CallableStatement;
4-
import java.sql.PreparedStatement;
5-
import java.sql.ResultSet;
6-
import java.sql.SQLException;
7-
import java.sql.Types;
8-
import org.postgresql.geometric.PGcircle;
9-
import org.postgresql.geometric.PGpoint;
103
import org.seasar.doma.ExternalDomain;
114
import org.seasar.doma.jdbc.domain.JdbcTypeProvider;
12-
import org.seasar.doma.jdbc.type.AbstractJdbcType;
135
import org.seasar.doma.jdbc.type.JdbcType;
146

157
@ExternalDomain
@@ -22,43 +14,3 @@ public JdbcType<Circle> getJdbcType() {
2214
return circleType;
2315
}
2416
}
25-
26-
class CircleType extends AbstractJdbcType<Circle> {
27-
28-
protected CircleType() {
29-
super(Types.OTHER);
30-
}
31-
32-
@Override
33-
protected Circle doGetValue(ResultSet resultSet, int index) throws SQLException {
34-
PGcircle c = resultSet.getObject(index, PGcircle.class);
35-
return toCircle(c);
36-
}
37-
38-
@Override
39-
protected void doSetValue(PreparedStatement preparedStatement, int index, Circle value)
40-
throws SQLException {
41-
PGpoint p = new PGpoint(value.center().x(), value.center().y());
42-
PGcircle c = new PGcircle(p, value.radius());
43-
preparedStatement.setObject(index, c);
44-
}
45-
46-
@Override
47-
protected Circle doGetValue(CallableStatement callableStatement, int index) throws SQLException {
48-
PGcircle c = callableStatement.getObject(index, PGcircle.class);
49-
return toCircle(c);
50-
}
51-
52-
@Override
53-
protected String doConvertToLogFormat(Circle value) {
54-
return value.toString();
55-
}
56-
57-
static Circle toCircle(PGcircle c) {
58-
if (c == null) {
59-
return null;
60-
}
61-
Point center = PointType.toPoint(c.center);
62-
return new Circle(center, c.radius);
63-
}
64-
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package example.geometric.type.domain;
2+
3+
import java.sql.CallableStatement;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.sql.Types;
8+
import org.postgresql.geometric.PGpoint;
9+
import org.seasar.doma.jdbc.type.AbstractJdbcType;
10+
11+
class PointType extends AbstractJdbcType<Point> {
12+
13+
protected PointType() {
14+
super(Types.OTHER);
15+
}
16+
17+
@Override
18+
protected Point doGetValue(ResultSet resultSet, int index) throws SQLException {
19+
PGpoint p = resultSet.getObject(index, PGpoint.class);
20+
return toPoint(p);
21+
}
22+
23+
@Override
24+
protected void doSetValue(PreparedStatement preparedStatement, int index, Point value)
25+
throws SQLException {
26+
PGpoint p = new PGpoint(value.x(), value.y());
27+
preparedStatement.setObject(index, p);
28+
}
29+
30+
@Override
31+
protected Point doGetValue(CallableStatement callableStatement, int index) throws SQLException {
32+
PGpoint p = callableStatement.getObject(index, PGpoint.class);
33+
return toPoint(p);
34+
}
35+
36+
@Override
37+
protected String doConvertToLogFormat(Point value) {
38+
return value.toString();
39+
}
40+
41+
static Point toPoint(PGpoint p) {
42+
if (p == null) {
43+
return null;
44+
}
45+
return new Point(p.x, p.y);
46+
}
47+
}
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
package example.geometric.type.domain;
22

3-
import java.sql.CallableStatement;
4-
import java.sql.PreparedStatement;
5-
import java.sql.ResultSet;
6-
import java.sql.SQLException;
7-
import java.sql.Types;
8-
import org.postgresql.geometric.PGpoint;
93
import org.seasar.doma.ExternalDomain;
104
import org.seasar.doma.jdbc.domain.JdbcTypeProvider;
11-
import org.seasar.doma.jdbc.type.AbstractJdbcType;
125
import org.seasar.doma.jdbc.type.JdbcType;
136

147
@ExternalDomain
@@ -21,41 +14,3 @@ public JdbcType<Point> getJdbcType() {
2114
return pointType;
2215
}
2316
}
24-
25-
class PointType extends AbstractJdbcType<Point> {
26-
27-
protected PointType() {
28-
super(Types.OTHER);
29-
}
30-
31-
@Override
32-
protected Point doGetValue(ResultSet resultSet, int index) throws SQLException {
33-
PGpoint p = resultSet.getObject(index, PGpoint.class);
34-
return toPoint(p);
35-
}
36-
37-
@Override
38-
protected void doSetValue(PreparedStatement preparedStatement, int index, Point value)
39-
throws SQLException {
40-
PGpoint p = new PGpoint(value.x(), value.y());
41-
preparedStatement.setObject(index, p);
42-
}
43-
44-
@Override
45-
protected Point doGetValue(CallableStatement callableStatement, int index) throws SQLException {
46-
PGpoint p = callableStatement.getObject(index, PGpoint.class);
47-
return toPoint(p);
48-
}
49-
50-
@Override
51-
protected String doConvertToLogFormat(Point value) {
52-
return value.toString();
53-
}
54-
55-
static Point toPoint(PGpoint p) {
56-
if (p == null) {
57-
return null;
58-
}
59-
return new Point(p.x, p.y);
60-
}
61-
}

0 commit comments

Comments
 (0)