28
28
/**
29
29
* An adapter for a target {@link DataSource}, designed to apply sharding keys, if specified,
30
30
* to every standard {@code #getConnection} call, returning a direct connection to the shard
31
- * corresponding to the specified sharding key value. All other methods are simply delegated
32
- * to the corresponding methods of the target DataSource.
31
+ * corresponding to the specified sharding key value. All other methods simply delegate
32
+ * to the corresponding methods of the target {@code DataSource} .
33
33
*
34
- * <p>The target {@link DataSource} must implement the {@link #createConnectionBuilder} method;
34
+ * <p>The target {@code DataSource} must implement the {@link #createConnectionBuilder} method;
35
35
* otherwise, a {@link java.sql.SQLFeatureNotSupportedException} will be thrown when attempting
36
36
* to acquire shard connections.
37
37
*
40
40
*
41
41
* <pre class="code">
42
42
* ShardingKeyDataSourceAdapter dataSourceAdapter = new ShardingKeyDataSourceAdapter(dataSource);
43
- * dataSourceAdapter.setShardingKeyProvider(() -> dataSource.createShardingKeyBuilder()
43
+ * dataSourceAdapter.setShardingKeyProvider(() -> dataSource.createShardingKeyBuilder()
44
44
* .subkey(SecurityContextHolder.getContext().getAuthentication().getName(), JDBCType.VARCHAR).build());
45
45
* </pre>
46
46
*
@@ -58,17 +58,20 @@ public class ShardingKeyDataSourceAdapter extends DelegatingDataSource {
58
58
59
59
60
60
/**
61
- * Create a new instance of ShardingKeyDataSourceAdapter, wrapping the given {@link DataSource}.
62
- * @param dataSource the target DataSource to be wrapped
61
+ * Create a new instance of {@code ShardingKeyDataSourceAdapter}, wrapping the
62
+ * given {@link DataSource}.
63
+ * @param dataSource the target {@code DataSource} to be wrapped
63
64
*/
64
65
public ShardingKeyDataSourceAdapter (DataSource dataSource ) {
65
66
super (dataSource );
66
67
}
67
68
68
69
/**
69
- * Create a new instance of ShardingKeyDataSourceAdapter, wrapping the given {@link DataSource}.
70
- * @param dataSource the target DataSource to be wrapped
71
- * @param shardingKeyProvider the ShardingKeyProvider used to get the sharding keys
70
+ * Create a new instance of {@code ShardingKeyDataSourceAdapter}, wrapping the
71
+ * given {@link DataSource}.
72
+ * @param dataSource the target {@code DataSource} to be wrapped
73
+ * @param shardingKeyProvider the {@code ShardingKeyProvider} used to get the
74
+ * sharding keys
72
75
*/
73
76
public ShardingKeyDataSourceAdapter (DataSource dataSource , ShardingKeyProvider shardingKeyProvider ) {
74
77
super (dataSource );
@@ -87,8 +90,9 @@ public void setShardingKeyProvider(ShardingKeyProvider shardingKeyProvider) {
87
90
/**
88
91
* Obtain a connection to the database shard using the provided sharding key
89
92
* and super sharding key (if available).
90
- * <p>The sharding key is obtained from the {@link ShardingKeyProvider}.
91
- * @return a Connection object representing a direct shard connection
93
+ * <p>The sharding key is obtained from the configured
94
+ * {@link #setShardingKeyProvider ShardingKeyProvider}.
95
+ * @return a {@code Connection} object representing a direct shard connection
92
96
* @throws SQLException if an error occurs while creating the connection
93
97
* @see #createConnectionBuilder()
94
98
*/
@@ -100,21 +104,22 @@ public Connection getConnection() throws SQLException {
100
104
/**
101
105
* Obtain a connection to the database shard using the provided username and password,
102
106
* considering the sharding keys (if available) and the given credentials.
103
- * <p>The sharding key is obtained from the {@link ShardingKeyProvider}.
107
+ * <p>The sharding key is obtained from the configured
108
+ * {@link #setShardingKeyProvider ShardingKeyProvider}.
104
109
* @param username the database user on whose behalf the connection is being made
105
110
* @param password the user's password
106
- * @return a Connection object representing a direct shard connection.
107
- * @throws SQLException if an error occurs while creating the connection.
111
+ * @return a {@code Connection} object representing a direct shard connection
112
+ * @throws SQLException if an error occurs while creating the connection
108
113
*/
109
114
@ Override
110
115
public Connection getConnection (String username , String password ) throws SQLException {
111
116
return createConnectionBuilder ().user (username ).password (password ).build ();
112
117
}
113
118
114
119
/**
115
- * Create a new instance of {@link ConnectionBuilder} using the target DataSource's
116
- * {@code createConnectionBuilder()} method, and sets the appropriate sharding keys
117
- * from the {@link ShardingKeyProvider}.
120
+ * Create a new instance of {@link ConnectionBuilder} using the target {@code DataSource} 's
121
+ * {@code createConnectionBuilder()} method and set the appropriate sharding keys
122
+ * from the configured {@link #setShardingKeyProvider ShardingKeyProvider}.
118
123
* @return a ConnectionBuilder object representing a builder for direct shard connections
119
124
* @throws SQLException if an error occurs while creating the ConnectionBuilder
120
125
*/
0 commit comments