All Implemented Interfaces:
Encodable<Cluster.CodingKeys>

public final class Cluster extends Codable<Cluster.CodingKeys>
A class to represent a cluster.
  • Constructor Details

    • Cluster

      Decoding constructor.
      Parameters:
      decoder - Decoder to be used for decoding
      Throws:
      DecodingException - If decoding methods threw during decoding
      NoSuchElementException - If some parameters are not found
      See Also:
    • Cluster

      public Cluster(@NotNull @NotNull String dbms, @NotNull @NotNull String host, @NotNull @NotNull String database, @Nullable @Nullable String username, @NotNull @NotNull Integer port, @NotNull @NotNull String name)
      Create a cluster from cluster parameters
      Parameters:
      dbms - Identifier of the cluster's DBMS
      host - Connection host
      database - Database path
      username - Connection username for authentication, if applicable
      port - Connection port
      name - Cluster name
  • Method Details

    • getPort

      @NotNull public @NotNull Integer getPort()
      Returns:
      Database connection port
    • getHost

      @NotNull public @NotNull String getHost()
      Returns:
      Database host
    • getDatabase

      @NotNull public @NotNull String getDatabase()
      Returns:
      The database path
    • getID

      @NotNull public @NotNull String getID()
      Get an ID unique to this database cluster. Not guaranteed to be unique across clusters with the same URL.
      Returns:
      A unique hash of the cluster's connection URL
    • getName

      @NotNull public @NotNull String getName()
      Get the user-facing name of this cluster. This name can be modified by the user after the creation of this Cluster.
      Returns:
      The user-facing name of this cluster
    • getUsername

      @Nullable public @Nullable String getUsername()
      Returns:
      Username for authenticating with database
    • getDBMS

      @NotNull public @NotNull String getDBMS()
      Returns:
      A string identifying the DBMS of this cluster
    • setName

      public void setName(@NotNull @NotNull String newName)
      Update the name of the current cluster. Call persist() to persist the updated cluster info
      Parameters:
      newName - New name to update cluster with
    • decode

      public static Cluster decode(String ofID) throws DecodingException, InvocationTargetException
      Convenience method that wraps Decoder, allows deserializing the cluster with the requested ID from Preferences
      Parameters:
      ofID - Requested clusterID to use for retrieval from Preferences
      Returns:
      Decoded cluster of requested ID
      Throws:
      DecodingException - If decoding failed for whatever reason (use printStackTrace for more info)
      InvocationTargetException - If the decoding constructor threw an exception
    • persist

      public void persist() throws EncodingException
      Persist the current instance to non-volatile storage with Java Preferences.

      Note: Uses Encodable under the hood to serialize and store the object in Preferences.

      Throws:
      EncodingException - If encoding failed for whatever reason.
    • remove

      public void remove() throws BackingStoreException
      Removes a cluster from non-volatile storage.
      Throws:
      BackingStoreException - If the underlying Preferences driver threw an exception
    • alreadyExists

      public boolean alreadyExists()
      Check if a cluster with the same ID was already persisted

      Note: Does not validate if persisted cluster is actually valid

      Returns:
      true if the node with this cluster's ID already exists
    • encode

      public void encode(Encoder<Cluster.CodingKeys> encoder) throws EncodingException
      Description copied from interface: Encodable
      Encodes the fields in this class with an encoder.
      Parameters:
      encoder - Encoder to be used for encoding
      Throws:
      EncodingException - If the encoder threw an exception
    • equals

      public boolean equals(Object c)
      Overrides:
      equals in class Object