Skip to content

Commit 0d96873

Browse files
author
Jarvis Song
authored
Merge pull request #92 from hatunet/dev
Dev
2 parents af301f5 + 5b1256b commit 0d96873

14 files changed

+756
-11
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.data.build</groupId>
88
<artifactId>spring-data-parent</artifactId>
9-
<version>1.9.0.RC1</version>
9+
<version>1.9.0.RELEASE</version>
1010
</parent>
1111

1212
<groupId>com.ifrabbit</groupId>
@@ -40,7 +40,7 @@
4040
</scm>
4141

4242
<properties>
43-
<springdata.commons.version>1.13.0.RC1</springdata.commons.version>
43+
<springdata.commons.version>1.13.0.RELEASE</springdata.commons.version>
4444
<mybatis.version>3.4.2</mybatis.version>
4545
</properties>
4646

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
*
3+
* Copyright 2017 the original author or authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.springframework.data.mybatis.handlers;
20+
21+
import org.apache.ibatis.type.BaseTypeHandler;
22+
import org.apache.ibatis.type.JdbcType;
23+
import org.apache.ibatis.type.MappedJdbcTypes;
24+
import org.apache.ibatis.type.MappedTypes;
25+
26+
import java.sql.CallableStatement;
27+
import java.sql.PreparedStatement;
28+
import java.sql.ResultSet;
29+
import java.sql.SQLException;
30+
import java.util.HashSet;
31+
import java.util.Set;
32+
33+
/**
34+
* @author Jarvis Song
35+
*/
36+
@MappedJdbcTypes(value = {JdbcType.VARCHAR, JdbcType.CLOB, JdbcType.LONGVARCHAR, JdbcType.NVARCHAR}, includeNullJdbcType = true)
37+
@MappedTypes({Set.class})
38+
public class SetStringTypeHandler extends BaseTypeHandler<Set> {
39+
40+
41+
@Override
42+
public void setNonNullParameter(PreparedStatement ps, int i, Set parameter, JdbcType jdbcType) throws SQLException {
43+
StringBuilder builder = new StringBuilder();
44+
if (!parameter.isEmpty()) {
45+
for (Object o : parameter) {
46+
builder.append(o).append(",");
47+
}
48+
builder.deleteCharAt(builder.length() - 1);
49+
}
50+
ps.setString(i, builder.toString());
51+
}
52+
53+
private Set<String> convertStringToSet(String str) {
54+
if (null == str) {
55+
return null;
56+
}
57+
Set<String> set = new HashSet<String>();
58+
String[] split = str.split(",");
59+
if (null != split && split.length > 0) {
60+
for (String s : split) {
61+
if (null == s || s.length() == 0) {
62+
continue;
63+
}
64+
set.add(s);
65+
}
66+
}
67+
return set;
68+
}
69+
70+
@Override
71+
public Set getNullableResult(ResultSet rs, String columnName) throws SQLException {
72+
return convertStringToSet(rs.getString(columnName));
73+
}
74+
75+
@Override
76+
public Set getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
77+
return convertStringToSet(rs.getString(columnIndex));
78+
}
79+
80+
@Override
81+
public Set getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
82+
return convertStringToSet(cs.getString(columnIndex));
83+
}
84+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.springframework.data.mybatis.replication.datasource;
2+
3+
import javax.sql.DataSource;
4+
import java.util.List;
5+
6+
/**
7+
* @author Jarvis Song
8+
*/
9+
public interface DatasourceSelectPolicy {
10+
11+
int select(List<DataSource> slaves);
12+
13+
}

0 commit comments

Comments
 (0)