- All Implemented Interfaces:
Encodable<Cluster.CodingKeys>
A class to represent a cluster.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if a cluster with the same ID was already persistedstatic ClusterConvenience method that wrapsDecoder, allows deserializing the cluster with the requested ID fromPreferencesvoidencode(Encoder<Cluster.CodingKeys> encoder) Encodes the fields in this class with an encoder.boolean@NotNull String@NotNull StringgetDBMS()@NotNull StringgetHost()@NotNull StringgetID()Get an ID unique to this database cluster.@NotNull StringgetName()Get the user-facing name of this cluster.@NotNull IntegergetPort()@Nullable Stringvoidpersist()Persist the current instance to non-volatile storage with JavaPreferences.voidremove()Removes a cluster from non-volatile storage.voidUpdate the name of the current cluster.
-
Constructor Details
-
Cluster
public Cluster(Decoder<Cluster.CodingKeys> decoder) throws DecodingException, NoSuchElementException Decoding constructor.- Parameters:
decoder- Decoder to be used for decoding- Throws:
DecodingException- If decoding methods threw during decodingNoSuchElementException- 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 DBMShost- Connection hostdatabase- Database pathusername- Connection username for authentication, if applicableport- Connection portname- Cluster name
-
-
Method Details
-
getPort
- Returns:
- Database connection port
-
getHost
- Returns:
- Database host
-
getDatabase
- Returns:
- The database path
-
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
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
- Returns:
- Username for authenticating with database
-
getDBMS
- Returns:
- A string identifying the DBMS of this cluster
-
setName
Update the name of the current cluster. Callpersist()to persist the updated cluster info- Parameters:
newName- New name to update cluster with
-
decode
Convenience method that wrapsDecoder, allows deserializing the cluster with the requested ID fromPreferences- 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
Persist the current instance to non-volatile storage with JavaPreferences.Note: Uses
Encodableunder the hood to serialize and store the object inPreferences.- Throws:
EncodingException- If encoding failed for whatever reason.
-
remove
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 persistedNote: Does not validate if persisted cluster is actually valid
- Returns:
trueif the node with this cluster's ID already exists
-
encode
Description copied from interface:EncodableEncodes 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
-