6
6
import java .math .BigDecimal ;
7
7
import java .util .Date ;
8
8
import java .util .HashMap ;
9
+ import java .util .EnumMap ;
9
10
import java .util .Map ;
10
11
import java .util .Set ;
11
12
12
- public class TypeHandlerRegistry {
13
+ public final class TypeHandlerRegistry {
13
14
14
- private static final Map <Class , Class > reversePrimitiveMap = new HashMap <Class , Class >() {
15
+ private static final Map <Class <?> , Class <?>> reversePrimitiveMap = new HashMap <Class <?> , Class <?> >() {
15
16
{
16
17
put (Byte .class , byte .class );
17
18
put (Short .class , short .class );
@@ -23,8 +24,8 @@ public class TypeHandlerRegistry {
23
24
}
24
25
};
25
26
26
- private final Map <JdbcType , TypeHandler > JDBC_TYPE_HANDLER_MAP = new HashMap <JdbcType , TypeHandler >();
27
- private final Map <Class , Map <JdbcType , TypeHandler >> TYPE_HANDLER_MAP = new HashMap <Class , Map <JdbcType , TypeHandler >>();
27
+ private final Map <JdbcType , TypeHandler > JDBC_TYPE_HANDLER_MAP = new EnumMap <JdbcType , TypeHandler >(JdbcType . class );
28
+ private final Map <Class <?> , Map <JdbcType , TypeHandler >> TYPE_HANDLER_MAP = new HashMap <Class <?> , Map <JdbcType , TypeHandler >>();
28
29
private final TypeHandler UNKNOWN_TYPE_HANDLER = new UnknownTypeHandler (this );
29
30
30
31
public TypeHandlerRegistry () {
@@ -98,29 +99,29 @@ public TypeHandlerRegistry() {
98
99
register (java .sql .Timestamp .class , new SqlTimestampTypeHandler ());
99
100
}
100
101
101
- public boolean hasTypeHandler (Class javaType ) {
102
+ public boolean hasTypeHandler (Class <?> javaType ) {
102
103
return hasTypeHandler (javaType , null );
103
104
}
104
105
105
- public boolean hasTypeHandler (Class javaType , JdbcType jdbcType ) {
106
+ public boolean hasTypeHandler (Class <?> javaType , JdbcType jdbcType ) {
106
107
return javaType != null && getTypeHandler (javaType , jdbcType ) != null ;
107
108
}
108
109
109
- public TypeHandler getTypeHandler (Class type ) {
110
+ public TypeHandler getTypeHandler (Class <?> type ) {
110
111
return getTypeHandler (type , null );
111
112
}
112
113
113
114
public TypeHandler getTypeHandler (JdbcType jdbcType ) {
114
115
return JDBC_TYPE_HANDLER_MAP .get (jdbcType );
115
116
}
116
117
117
- public TypeHandler getTypeHandler (Class type , JdbcType jdbcType ) {
118
- Map jdbcHandlerMap = TYPE_HANDLER_MAP .get (type );
118
+ public TypeHandler getTypeHandler (Class <?> type , JdbcType jdbcType ) {
119
+ Map < JdbcType , TypeHandler > jdbcHandlerMap = TYPE_HANDLER_MAP .get (type );
119
120
TypeHandler handler = null ;
120
121
if (jdbcHandlerMap != null ) {
121
- handler = ( TypeHandler ) jdbcHandlerMap .get (jdbcType );
122
+ handler = jdbcHandlerMap .get (jdbcType );
122
123
if (handler == null ) {
123
- handler = ( TypeHandler ) jdbcHandlerMap .get (null );
124
+ handler = jdbcHandlerMap .get (null );
124
125
}
125
126
}
126
127
if (handler == null && type != null && Enum .class .isAssignableFrom (type )) {
@@ -137,11 +138,11 @@ public void register(JdbcType jdbcType, TypeHandler handler) {
137
138
JDBC_TYPE_HANDLER_MAP .put (jdbcType , handler );
138
139
}
139
140
140
- public void register (Class type , TypeHandler handler ) {
141
+ public void register (Class <?> type , TypeHandler handler ) {
141
142
register (type , null , handler );
142
143
}
143
144
144
- public void register (Class type , JdbcType jdbcType , TypeHandler handler ) {
145
+ public void register (Class <?> type , JdbcType jdbcType , TypeHandler handler ) {
145
146
Map <JdbcType , TypeHandler > map = TYPE_HANDLER_MAP .get (type );
146
147
if (map == null ) {
147
148
map = new HashMap <JdbcType , TypeHandler >();
@@ -154,12 +155,12 @@ public void register(Class type, JdbcType jdbcType, TypeHandler handler) {
154
155
}
155
156
156
157
public void register (String packageName ) {
157
- ResolverUtil <Class > resolverUtil = new ResolverUtil <Class >();
158
+ ResolverUtil <Class <?>> resolverUtil = new ResolverUtil <Class <?> >();
158
159
resolverUtil .find (new ResolverUtil .IsA (TypeHandler .class ), packageName );
159
- Set <Class <? extends Class >> handlerSet = resolverUtil .getClasses ();
160
+ Set <Class <? extends Class <?> >> handlerSet = resolverUtil .getClasses ();
160
161
161
162
TypeHandler handler ;
162
- for (Class type : handlerSet ) {
163
+ for (Class <?> type : handlerSet ) {
163
164
@ SuppressWarnings ({"unchecked" })
164
165
Annotation annotation = type .getAnnotation (MappedTypes .class );
165
166
try {
@@ -169,7 +170,7 @@ public void register(String packageName) {
169
170
}
170
171
if (null != annotation ) {
171
172
MappedTypes mappedType = (MappedTypes ) annotation ;
172
- for (Class handledType : mappedType .value ()) {
173
+ for (Class <?> handledType : mappedType .value ()) {
173
174
register (handledType , handler );
174
175
}
175
176
}
0 commit comments