Skip to content

Commit b37c3ca

Browse files
Merge #76
1 parent 4073eae commit b37c3ca

File tree

3 files changed

+233
-233
lines changed

3 files changed

+233
-233
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
/**
2-
* Copyright 2009-2016 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.mybatis.guice.mappers;
17-
18-
import org.apache.ibatis.session.SqlSessionManager;
19-
20-
import com.google.common.base.Objects;
21-
22-
import javax.inject.Inject;
23-
import javax.inject.Provider;
24-
25-
/**
26-
* A generic MyBatis mapper provider.
27-
*/
28-
public final class MapperProvider<T> implements Provider<T> {
29-
30-
private final Class<T> mapperType;
31-
32-
@Inject
33-
private SqlSessionManager sqlSessionManager;
34-
35-
public MapperProvider(Class<T> mapperType) {
36-
this.mapperType = mapperType;
37-
}
38-
39-
public void setSqlSessionManager(SqlSessionManager sqlSessionManager) {
40-
this.sqlSessionManager = sqlSessionManager;
41-
}
42-
43-
@Override
44-
public T get() {
45-
return this.sqlSessionManager.getMapper(mapperType);
46-
}
47-
48-
@Override
49-
public int hashCode() {
50-
return Objects.hashCode(this.mapperType);
51-
}
52-
53-
@Override
54-
public boolean equals(Object obj) {
55-
if(obj == null){
56-
return false;
57-
}
58-
MapperProvider other = (MapperProvider) obj;
59-
return Objects.equal(this.mapperType, other.mapperType);
60-
}
61-
}
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.guice.mappers;
17+
18+
import org.apache.ibatis.session.SqlSessionManager;
19+
20+
import com.google.common.base.Objects;
21+
22+
import javax.inject.Inject;
23+
import javax.inject.Provider;
24+
25+
/**
26+
* A generic MyBatis mapper provider.
27+
*/
28+
public final class MapperProvider<T> implements Provider<T> {
29+
30+
private final Class<T> mapperType;
31+
32+
@Inject
33+
private SqlSessionManager sqlSessionManager;
34+
35+
public MapperProvider(Class<T> mapperType) {
36+
this.mapperType = mapperType;
37+
}
38+
39+
public void setSqlSessionManager(SqlSessionManager sqlSessionManager) {
40+
this.sqlSessionManager = sqlSessionManager;
41+
}
42+
43+
@Override
44+
public T get() {
45+
return this.sqlSessionManager.getMapper(mapperType);
46+
}
47+
48+
@Override
49+
public int hashCode() {
50+
return Objects.hashCode(this.mapperType);
51+
}
52+
53+
@Override
54+
public boolean equals(Object obj) {
55+
if(obj == null){
56+
return false;
57+
}
58+
MapperProvider other = (MapperProvider) obj;
59+
return Objects.equal(this.mapperType, other.mapperType);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
1-
/**
2-
* Copyright 2009-2016 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.mybatis.guice.type;
17-
18-
import java.lang.reflect.Constructor;
19-
20-
import org.apache.ibatis.type.TypeException;
21-
import org.apache.ibatis.type.TypeHandler;
22-
23-
import com.google.common.base.Objects;
24-
import com.google.inject.Inject;
25-
import com.google.inject.Injector;
26-
import com.google.inject.TypeLiteral;
27-
28-
import javax.inject.Provider;
29-
30-
/**
31-
* A generic MyBatis type provider.
32-
*/
33-
public final class TypeHandlerProvider<TH extends TypeHandler<? extends T>, T> implements Provider<TH> {
34-
private final TypeLiteral<TH> typeHandlerTypeLiteral;
35-
private final Class<T> handledType;
36-
@Inject
37-
private Injector injector;
38-
39-
public TypeHandlerProvider(Class<TH> typeHandlerType, Class<T> handledType) {
40-
this.typeHandlerTypeLiteral = TypeLiteral.get(typeHandlerType);
41-
this.handledType = handledType;
42-
}
43-
44-
public TypeHandlerProvider(TypeLiteral<TH> typeHandlerType, Class<T> handledType) {
45-
this.typeHandlerTypeLiteral = typeHandlerType;
46-
this.handledType = handledType;
47-
}
48-
49-
@Override
50-
@SuppressWarnings("unchecked")
51-
public TH get() {
52-
TH instance = null;
53-
if (handledType != null) {
54-
try {
55-
Constructor<?> c = typeHandlerTypeLiteral.getRawType().getConstructor(Class.class);
56-
instance = (TH) c.newInstance(handledType);
57-
injector.injectMembers(instance);
58-
} catch (NoSuchMethodException ignored) {
59-
// ignored
60-
} catch (Exception e) {
61-
throw new TypeException("Failed invoking constructor for handler " + typeHandlerTypeLiteral.getType(), e);
62-
}
63-
}
64-
if (instance == null) {
65-
try {
66-
instance = (TH) typeHandlerTypeLiteral.getRawType().newInstance();
67-
injector.injectMembers(instance);
68-
} catch (Exception e) {
69-
throw new TypeException("Failed invoking constructor for handler " + typeHandlerTypeLiteral.getType(), e);
70-
}
71-
}
72-
return instance;
73-
}
74-
75-
@Override
76-
public int hashCode() {
77-
return Objects.hashCode(this.typeHandlerTypeLiteral, this.handledType);
78-
}
79-
80-
@Override
81-
public boolean equals(Object obj) {
82-
if(obj == null){
83-
return false;
84-
}
85-
TypeHandlerProvider other = (TypeHandlerProvider) obj;
86-
return Objects.equal(this.typeHandlerTypeLiteral, other.typeHandlerTypeLiteral) &&
87-
Objects.equal(this.handledType, other.handledType);
88-
}
89-
}
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.guice.type;
17+
18+
import java.lang.reflect.Constructor;
19+
20+
import org.apache.ibatis.type.TypeException;
21+
import org.apache.ibatis.type.TypeHandler;
22+
23+
import com.google.common.base.Objects;
24+
import com.google.inject.Inject;
25+
import com.google.inject.Injector;
26+
import com.google.inject.TypeLiteral;
27+
28+
import javax.inject.Provider;
29+
30+
/**
31+
* A generic MyBatis type provider.
32+
*/
33+
public final class TypeHandlerProvider<TH extends TypeHandler<? extends T>, T> implements Provider<TH> {
34+
private final TypeLiteral<TH> typeHandlerTypeLiteral;
35+
private final Class<T> handledType;
36+
@Inject
37+
private Injector injector;
38+
39+
public TypeHandlerProvider(Class<TH> typeHandlerType, Class<T> handledType) {
40+
this.typeHandlerTypeLiteral = TypeLiteral.get(typeHandlerType);
41+
this.handledType = handledType;
42+
}
43+
44+
public TypeHandlerProvider(TypeLiteral<TH> typeHandlerType, Class<T> handledType) {
45+
this.typeHandlerTypeLiteral = typeHandlerType;
46+
this.handledType = handledType;
47+
}
48+
49+
@Override
50+
@SuppressWarnings("unchecked")
51+
public TH get() {
52+
TH instance = null;
53+
if (handledType != null) {
54+
try {
55+
Constructor<?> c = typeHandlerTypeLiteral.getRawType().getConstructor(Class.class);
56+
instance = (TH) c.newInstance(handledType);
57+
injector.injectMembers(instance);
58+
} catch (NoSuchMethodException ignored) {
59+
// ignored
60+
} catch (Exception e) {
61+
throw new TypeException("Failed invoking constructor for handler " + typeHandlerTypeLiteral.getType(), e);
62+
}
63+
}
64+
if (instance == null) {
65+
try {
66+
instance = (TH) typeHandlerTypeLiteral.getRawType().newInstance();
67+
injector.injectMembers(instance);
68+
} catch (Exception e) {
69+
throw new TypeException("Failed invoking constructor for handler " + typeHandlerTypeLiteral.getType(), e);
70+
}
71+
}
72+
return instance;
73+
}
74+
75+
@Override
76+
public int hashCode() {
77+
return Objects.hashCode(this.typeHandlerTypeLiteral, this.handledType);
78+
}
79+
80+
@Override
81+
public boolean equals(Object obj) {
82+
if(obj == null){
83+
return false;
84+
}
85+
TypeHandlerProvider other = (TypeHandlerProvider) obj;
86+
return Objects.equal(this.typeHandlerTypeLiteral, other.typeHandlerTypeLiteral) &&
87+
Objects.equal(this.handledType, other.handledType);
88+
}
89+
}

0 commit comments

Comments
 (0)