@@ -63,9 +63,19 @@ public class ConnectionConfig {
63
63
64
64
private final AuthType authType ;
65
65
private final String unixSocketPathSuffix ;
66
+ private final String domainName ;
66
67
67
68
/** Create a new ConnectionConfig from the well known JDBC Connection properties. */
68
69
public static ConnectionConfig fromConnectionProperties (Properties props ) {
70
+ // TODO convert internal uses to fromConnectionProperties(props, domainName)
71
+ return fromConnectionProperties (props , null );
72
+ }
73
+
74
+ /**
75
+ * Create a new ConnectionConfig from the well known JDBC Connection properties, also setting
76
+ * database domain name.
77
+ */
78
+ public static ConnectionConfig fromConnectionProperties (Properties props , String domainName ) {
69
79
final String csqlInstanceName = props .getProperty (ConnectionConfig .CLOUD_SQL_INSTANCE_PROPERTY );
70
80
final String namedConnection =
71
81
props .getProperty (ConnectionConfig .CLOUD_SQL_NAMED_CONNECTOR_PROPERTY );
@@ -113,6 +123,7 @@ public static ConnectionConfig fromConnectionProperties(Properties props) {
113
123
ipTypes ,
114
124
authType ,
115
125
unixSocketPathSuffix ,
126
+ domainName ,
116
127
new ConnectorConfig .Builder ()
117
128
.withTargetPrincipal (targetPrincipal )
118
129
.withDelegates (delegates )
@@ -162,13 +173,20 @@ public boolean equals(Object o) {
162
173
&& Objects .equals (unixSocketPath , config .unixSocketPath )
163
174
&& Objects .equals (ipTypes , config .ipTypes )
164
175
&& Objects .equals (authType , config .authType )
176
+ && Objects .equals (domainName , config .domainName )
165
177
&& Objects .equals (connectorConfig , config .connectorConfig );
166
178
}
167
179
168
180
@ Override
169
181
public int hashCode () {
170
182
return Objects .hash (
171
- cloudSqlInstance , namedConnector , unixSocketPath , ipTypes , authType , connectorConfig );
183
+ cloudSqlInstance ,
184
+ namedConnector ,
185
+ unixSocketPath ,
186
+ ipTypes ,
187
+ authType ,
188
+ domainName ,
189
+ connectorConfig );
172
190
}
173
191
174
192
private ConnectionConfig (
@@ -178,6 +196,7 @@ private ConnectionConfig(
178
196
List <IpType > ipTypes ,
179
197
AuthType authType ,
180
198
String unixSocketPathSuffix ,
199
+ String domainName ,
181
200
ConnectorConfig connectorConfig ) {
182
201
this .cloudSqlInstance = cloudSqlInstance ;
183
202
this .namedConnector = namedConnector ;
@@ -186,6 +205,7 @@ private ConnectionConfig(
186
205
this .unixSocketPathSuffix = unixSocketPathSuffix ;
187
206
this .connectorConfig = connectorConfig ;
188
207
this .authType = authType ;
208
+ this .domainName = domainName ;
189
209
}
190
210
191
211
/** Creates a new instance of the ConnectionConfig with an updated connectorConfig. */
@@ -197,9 +217,36 @@ public ConnectionConfig withConnectorConfig(ConnectorConfig config) {
197
217
ipTypes ,
198
218
authType ,
199
219
unixSocketPathSuffix ,
220
+ domainName ,
200
221
config );
201
222
}
202
223
224
+ /** Creates a new instance of the ConnectionConfig with an updated cloudSqlInstance. */
225
+ public ConnectionConfig withCloudSqlInstance (String newCloudSqlInstance ) {
226
+ return new ConnectionConfig (
227
+ newCloudSqlInstance ,
228
+ namedConnector ,
229
+ unixSocketPath ,
230
+ ipTypes ,
231
+ authType ,
232
+ unixSocketPathSuffix ,
233
+ domainName ,
234
+ connectorConfig );
235
+ }
236
+
237
+ /** Creates a new instance of the ConnectionConfig with an updated cloudSqlInstance. */
238
+ public ConnectionConfig withDomainName (String domainName ) {
239
+ return new ConnectionConfig (
240
+ cloudSqlInstance ,
241
+ namedConnector ,
242
+ unixSocketPath ,
243
+ ipTypes ,
244
+ authType ,
245
+ unixSocketPathSuffix ,
246
+ domainName ,
247
+ connectorConfig );
248
+ }
249
+
203
250
public String getNamedConnector () {
204
251
return namedConnector ;
205
252
}
@@ -228,6 +275,10 @@ public AuthType getAuthType() {
228
275
return authType ;
229
276
}
230
277
278
+ public String getDomainName () {
279
+ return domainName ;
280
+ }
281
+
231
282
/** The builder for the ConnectionConfig. */
232
283
public static class Builder {
233
284
@@ -238,6 +289,7 @@ public static class Builder {
238
289
private String unixSocketPathSuffix ;
239
290
private ConnectorConfig connectorConfig = new ConnectorConfig .Builder ().build ();
240
291
private AuthType authType = DEFAULT_AUTH_TYPE ;
292
+ private String domainName ;
241
293
242
294
/** Chained setter for CloudSqlInstance field. */
243
295
public Builder withCloudSqlInstance (String cloudSqlInstance ) {
@@ -281,6 +333,12 @@ public Builder withIpTypes(List<IpType> ipTypes) {
281
333
return this ;
282
334
}
283
335
336
+ /** Set domainName. */
337
+ public Builder withDomainName (String domainName ) {
338
+ this .domainName = domainName ;
339
+ return this ;
340
+ }
341
+
284
342
/** Chained setter for UnixSocketPathSuffix field. */
285
343
public Builder withUnixSocketPathSuffix (String unixSocketPathSuffix ) {
286
344
this .unixSocketPathSuffix = unixSocketPathSuffix ;
@@ -296,6 +354,7 @@ public ConnectionConfig build() {
296
354
ipTypes ,
297
355
authType ,
298
356
unixSocketPathSuffix ,
357
+ domainName ,
299
358
connectorConfig );
300
359
}
301
360
}
0 commit comments