Skip to content

Commit 706c081

Browse files
committed
Merge pull request #89 from kakusuke/portable-object-mapping
PortableObjectTypeをジェネリクスにして、String等をvalueTypeとして指定できるように
2 parents 1b69473 + 9d67f43 commit 706c081

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/main/java/org/seasar/doma/jdbc/type/JdbcTypes.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public final class JdbcTypes {
6363

6464
public static final ObjectType OBJECT = new ObjectType();
6565

66-
public static final PortableObjectType PORTABLE_OBJECT = new PortableObjectType();
67-
6866
public static final ShortType SHORT = new ShortType();
6967

7068
public static final StringType STRING = new StringType();

src/main/java/org/seasar/doma/jdbc/type/PortableObjectType.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,48 @@
1515
*/
1616
package org.seasar.doma.jdbc.type;
1717

18+
import java.sql.CallableStatement;
1819
import java.sql.PreparedStatement;
20+
import java.sql.ResultSet;
1921
import java.sql.SQLException;
22+
import java.sql.Types;
2023

2124
/**
22-
* {@link Object} 用の {@link JdbcType} の実装です。
25+
* DB固有の型用の {@link JdbcType} の実装です。
2326
* {@link PreparedStatement#setObject(int, Object, int)} を使って値を設定します。
2427
*
2528
* @author nakamura-to
2629
* @since 2.4.0
2730
*/
28-
public class PortableObjectType extends ObjectType {
31+
public class PortableObjectType<T> extends AbstractJdbcType<T> {
32+
33+
private final JdbcType<T> baseType;
34+
35+
public PortableObjectType(JdbcType<T> baseType) {
36+
super(Types.OTHER);
37+
this.baseType = baseType;
38+
}
39+
40+
@Override
41+
public T doGetValue(ResultSet resultSet, int index)
42+
throws SQLException {
43+
return baseType.getValue(resultSet, index);
44+
}
2945

3046
@Override
3147
protected void doSetValue(PreparedStatement preparedStatement, int index,
32-
Object value) throws SQLException {
48+
T value) throws SQLException {
3349
preparedStatement.setObject(index, value, this.type);
3450
}
51+
52+
@Override
53+
protected T doGetValue(CallableStatement callableStatement, int index)
54+
throws SQLException {
55+
return baseType.getValue(callableStatement, index);
56+
}
57+
58+
@Override
59+
protected String doConvertToLogFormat(T value) {
60+
return baseType.convertToLogFormat(value);
61+
}
3562
}

0 commit comments

Comments
 (0)