java.lang.Object
com.cryptoalgo.oursql.model.db.DatabaseUtils
Various utilities for working with JDBC databases.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Connection
getConnection
(@NotNull Cluster cluster, @Nullable String password) Convenience method to get a JDBC connection from a cluster and password.static Connection
getConnection
(@NotNull URI connURI, @NotNull Cluster cluster, @Nullable String password) Get a database connectionstatic URI
getConnectionURI
(@NotNull Cluster cluster) Generates a database connection URI given aCluster
and a password.static URI
getConnectionURI
(@NotNull Integer port, @NotNull String host, @NotNull String path, @NotNull DBMSUtils utils, boolean includeJDBC) Constructs a database connection URI from connection parameters and a password.
-
Constructor Details
-
DatabaseUtils
public DatabaseUtils()
-
-
Method Details
-
getConnectionURI
Generates a database connection URI given aCluster
and a password.Implementation Note: Calls
getConnectionURI(Integer, String, String, DBMSUtils, boolean)
internally.- Parameters:
cluster
- Cluster to get connection URI from- Returns:
- A connection URI for the provided
Cluster
, not valid for connection ifpassword
isnull
and - Throws:
URISyntaxException
- If non-permitted characters were present in constructed URI- See Also:
-
getConnectionURI
public static URI getConnectionURI(@NotNull @NotNull Integer port, @NotNull @NotNull String host, @NotNull @NotNull String path, @NotNull @NotNull DBMSUtils utils, boolean includeJDBC) throws URISyntaxException Constructs a database connection URI from connection parameters and a password.Tip: If the password argument is
null
, a placeholder is used. Useful for display in uncensored UI.- Parameters:
port
- Database connection porthost
- Database hostpath
- Database path (relative tohost
)utils
- An instance of the database utils for the cluster's DBMSincludeJDBC
- If jdbc: should be appended before the scheme. Set to false for user-facing UIs- Returns:
- A connection URI for the provided connection params, not valid for
connection if
password
isnull
andCluster.getUsername()
is not null. - Throws:
URISyntaxException
- If construction of the connection URI failed due to invalid characters/syntax
-
getConnection
public static Connection getConnection(@NotNull @NotNull Cluster cluster, @Nullable @Nullable String password) throws URISyntaxException, SQLException Convenience method to get a JDBC connection from a cluster and password.- Parameters:
cluster
- Cluster to get connection ofpassword
- Connection password, if applicable- Returns:
- The database connection object
- Throws:
URISyntaxException
- If construction of the connection URI failed due to invalid characters/syntaxSQLException
- If the underlying JDBC driver threw an exception while a connection was attempted- See Also:
-
getConnection
public static Connection getConnection(@NotNull @NotNull URI connURI, @NotNull @NotNull Cluster cluster, @Nullable @Nullable String password) throws SQLException Get a database connection- Parameters:
connURI
- Connection URIcluster
- Cluster to get connection ofpassword
- Connection password, if applicable- Returns:
- The database connection object
- Throws:
SQLException
- If the underlying JDBC driver threw an exception while a connection was attempted
-