-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add public API to configure connectors. Fixes #1226
- Loading branch information
Showing
14 changed files
with
594 additions
and
75 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
core/src/main/java/com/google/cloud/sql/ConnectorRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.sql; | ||
|
||
import com.google.cloud.sql.core.InternalConnectorRegistry; | ||
|
||
/** Configure the CloudSQL JDBC Connector. */ | ||
public final class ConnectorRegistry { | ||
|
||
/** | ||
* Register a named connection so that it can later be referenced by name in a JDBC or R2DBC URL. | ||
* | ||
* @param name the named connection name. | ||
* @param config the full configuration of the connection. | ||
*/ | ||
public static void register(String name, ConnectorConfig config) { | ||
InternalConnectorRegistry.getInstance().register(name, config); | ||
} | ||
|
||
/** | ||
* Close a named connector. This will stop all background credential refresh processes. All future | ||
* attempts to connect via this named connection will fail. | ||
* | ||
* @param name the name of the connector to close. | ||
*/ | ||
public static void close(String name) { | ||
InternalConnectorRegistry.getInstance().close(name); | ||
} | ||
|
||
/** | ||
* Shutdown the entire CloudSQL JDBC Connector. This will stop all background threads. All future | ||
* attempts to connect to a CloudSQL database will fail. | ||
*/ | ||
public static void shutdown() { | ||
InternalConnectorRegistry.shutdownInstance(); | ||
} | ||
|
||
/** | ||
* Adds an external application name to the user agent string for tracking. This is known to be | ||
* used by the spring-cloud-gcp project. | ||
* | ||
* @throws IllegalStateException if the SQLAdmin client has already been initialized | ||
*/ | ||
public static void addArtifactId(String artifactId) { | ||
InternalConnectorRegistry.getInstance().addArtifactId(artifactId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.