Class DatabaseUtils

java.lang.Object
com.cryptoalgo.oursql.model.db.DatabaseUtils

public class DatabaseUtils extends Object
Various utilities for working with JDBC databases.
  • Constructor Details

    • DatabaseUtils

      public DatabaseUtils()
  • Method Details

    • getConnectionURI

      public static URI getConnectionURI(@NotNull @NotNull Cluster cluster) throws URISyntaxException
      Generates a database connection URI given a Cluster 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 if password is null 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 port
      host - Database host
      path - Database path (relative to host)
      utils - An instance of the database utils for the cluster's DBMS
      includeJDBC - 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 is null and Cluster.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 of
      password - Connection password, if applicable
      Returns:
      The database connection object
      Throws:
      URISyntaxException - If construction of the connection URI failed due to invalid characters/syntax
      SQLException - 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 URI
      cluster - Cluster to get connection of
      password - Connection password, if applicable
      Returns:
      The database connection object
      Throws:
      SQLException - If the underlying JDBC driver threw an exception while a connection was attempted