java.lang.Object
com.cryptoalgo.oursql.model.HomeViewModel
Over-engineered database connection, loading and updating class.
Serves as a view model for
Home
-
Property Summary
TypePropertyDescriptionjavafx.beans.property.ReadOnlyStringProperty
Get an observableReadOnlyStringProperty
for the current status.javafx.beans.property.ReadOnlyStringProperty
Get an observableReadOnlyStringProperty
for the selected table.javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.paint.Color>
Get an observableReadOnlyStringProperty
for the current status background. -
Field Summary
Modifier and TypeFieldDescriptionfinal javafx.collections.ObservableList<String>
Columns of the current selected tablefinal javafx.collections.ObservableList<javafx.collections.ObservableList<Container<?>>>
Rows of the current selected tablefinal javafx.collections.ObservableList<String>
Columns of the current selected table -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addCachedPassword
(String clusterID, String pw) Add a password to the cache manually, for example right after a cluster is created.void
addCluster
(@NotNull Cluster c) Add a specified cluster, will fire listeners if any are registeredvoid
attemptEdit
(@NotNull String col, @NotNull String ctid, @Nullable String nv) Attempt to edit a field in a tablevoid
createTable
(@NotNull Cluster cluster, @NotNull String table) Create a table in a clustervoid
Remove a row in the current table given a ctidjavafx.beans.property.ReadOnlyStringProperty
Get an observableReadOnlyStringProperty
for the current status.void
Delete a table from a clustervoid
Convenience method to mark a job started by callingsetStatusJob(String status)
as successfully completedvoid
finishStatusJob
(String id, String err) Mark a job started by callingsetStatusJob(String status)
as completed.int
Get the index of the cluster with the specified ID.void
insertColumn
(@NotNull String name, @NotNull String type) Inserts a column into the currently selected table.void
Inserts a new row into the current table with null values for each columnvoid
Load persisted clusters.void
newTableSelection
(Cluster cluster, String table) Select and load a new tablevoid
removeCluster
(@NotNull Integer idx) Remove a cluster at the specified indexvoid
removeCluster
(@NotNull String clusterID) Remove the cluster with the specified ID@Nullable javafx.collections.ObservableList<String>
requestTables
(Cluster cluster) Request to load the tables of a particular database cluster.javafx.util.Pair<javafx.util.Pair<List<String>,
javafx.collections.ObservableList<javafx.collections.ObservableList<Container<?>>>>, Integer> Run a SQL query and return the resultSetjavafx.beans.property.ReadOnlyStringProperty
Get an observableReadOnlyStringProperty
for the selected table.void
Register a new listener to be called when cluster(s) are addedvoid
Register a new listener to be called when cluster(s) are removedsetStatusJob
(String newStatus) Create a job to display its statusjavafx.beans.property.ReadOnlyObjectProperty<javafx.scene.paint.Color>
Get an observableReadOnlyStringProperty
for the current status background.boolean
tablesCached
(String forCluster) Check if the tables for a particular cluster are present in the table cache.void
Fetch the columns and rows of the currently selected table
-
Property Details
-
selectedTable
public javafx.beans.property.ReadOnlyStringProperty selectedTablePropertyGet an observableReadOnlyStringProperty
for the selected table.- Returns:
- Read only observable property for the selected table.
Might be
null
if no table is selected.
-
displayedStatus
public javafx.beans.property.ReadOnlyStringProperty displayedStatusPropertyGet an observableReadOnlyStringProperty
for the current status.- Returns:
- Read only observable property for the current status.
-
statusBg
public javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.paint.Color> statusBgPropertyGet an observableReadOnlyStringProperty
for the current status background. Implementations might choose to transition changes in this property.- Returns:
- Read only observable property for the requested status background.
-
-
Field Details
-
tableColumns
Columns of the current selected table -
columnTypes
Columns of the current selected table -
rows
public final javafx.collections.ObservableList<javafx.collections.ObservableList<Container<?>>> rowsRows of the current selected table
-
-
Constructor Details
-
HomeViewModel
public HomeViewModel()
-
-
Method Details
-
selectedTableProperty
public javafx.beans.property.ReadOnlyStringProperty selectedTableProperty()Get an observableReadOnlyStringProperty
for the selected table.- Returns:
- Read only observable property for the selected table.
Might be
null
if no table is selected.
-
displayedStatusProperty
public javafx.beans.property.ReadOnlyStringProperty displayedStatusProperty()Get an observableReadOnlyStringProperty
for the current status.- Returns:
- Read only observable property for the current status.
-
statusBgProperty
public javafx.beans.property.ReadOnlyObjectProperty<javafx.scene.paint.Color> statusBgProperty()Get an observableReadOnlyStringProperty
for the current status background. Implementations might choose to transition changes in this property.- Returns:
- Read only observable property for the requested status background.
-
requestTables
@Nullable public @Nullable javafx.collections.ObservableList<String> requestTables(Cluster cluster) throws NoSuchElementException, SQLException Request to load the tables of a particular database cluster. Call again with the same cluster ID to refresh clusters.- Parameters:
cluster
- Cluster to fetch tables of- Returns:
- An ObservableList of tables for this cluster. Implementations can bind to this ObservableList to be notified of modifications to tables in this cluster (currently only occurs when this method is called again to refresh tables).
- Throws:
NoSuchElementException
- If the cluster ID doesn't existSQLException
- If the underlying JDBC driver threw an exception during the creation of a connection or during a query.
-
tablesCached
Check if the tables for a particular cluster are present in the table cache.- Parameters:
forCluster
- Cluster ID to check for cached tables- Returns:
- true if tables of the cluster are already present in the cache
-
newTableSelection
Select and load a new table- Parameters:
cluster
- Cluster to load table fromtable
- Table name to load
-
updateTable
public void updateTable()Fetch the columns and rows of the currently selected table -
runQuery
public javafx.util.Pair<javafx.util.Pair<List<String>,javafx.collections.ObservableList<javafx.collections.ObservableList<Container<?>>>>, runQueryInteger> (String query) throws SQLException Run a SQL query and return the resultSet- Parameters:
query
- SQL query to run- Returns:
- A pair containing a pair of the column names and types and a list of rows, and the number of results updated if the operation was an update operation or the length of the result set if the statement returned one
- Throws:
SQLException
- If the statement failed to execute
-
attemptEdit
public void attemptEdit(@NotNull @NotNull String col, @NotNull @NotNull String ctid, @Nullable @Nullable String nv) throws SQLException Attempt to edit a field in a table- Parameters:
col
- Column name of field to editctid
- TID of row to editnv
- New value to update field with (could be null)- Throws:
SQLException
- If editing failed (JDBC driver threw an exception while executing update statement)
-
insertRow
public void insertRow()Inserts a new row into the current table with null values for each column -
deleteRow
Remove a row in the current table given a ctid- Parameters:
ctid
- CTID of row to remove
-
insertColumn
Inserts a column into the currently selected table. -
createTable
Create a table in a cluster- Parameters:
cluster
- Cluster to create table intable
- Name of new table to create
-
dropTable
public void dropTable()Delete a table from a cluster -
loadClusters
public void loadClusters()Load persisted clusters. Listeners registered throughsetOnNewCluster(BiConsumer callback)
will be notified if any new clusters were loaded. -
setOnNewCluster
Register a new listener to be called when cluster(s) are added- Parameters:
cb
- Consumer callback to be call when a new cluster is added
-
setOnRemoveCluster
Register a new listener to be called when cluster(s) are removed- Parameters:
cb
- Consumer callback to be called when a cluster is removed
-
indexOf
Get the index of the cluster with the specified ID.- Parameters:
clusterID
- ID to get index of- Returns:
- Index of cluster with specified ID, -1 if not found
-
addCluster
Add a specified cluster, will fire listeners if any are registered- Parameters:
c
- Cluster to add
-
removeCluster
Remove the cluster with the specified ID- Parameters:
clusterID
- ID of cluster to remove- Throws:
NoSuchElementException
- If no cluster with specified ID exists- See Also:
-
removeCluster
Remove a cluster at the specified index- Parameters:
idx
- Index to remove cluster at
-
setStatusJob
Create a job to display its status- Parameters:
newStatus
- Name or description of new job- Returns:
- ID of job, can be passed to
finishStatusJob(String id)
orfinishStatusJob(String id, String err)
upon job completion
-
finishStatusJob
Convenience method to mark a job started by callingsetStatusJob(String status)
as successfully completed- Parameters:
id
- ID of job, returned bysetStatusJob(String status)
- See Also:
-
finishStatusJob
Mark a job started by callingsetStatusJob(String status)
as completed.- Parameters:
id
- ID of job, returned bysetStatusJob(String status)
err
- If the job failed, the exception string to display (null if no exception)- See Also:
-
addCachedPassword
Add a password to the cache manually, for example right after a cluster is created.Note: No validation is done to ensure the password is valid etc.
- Parameters:
clusterID
- ID of cluster this password is forpw
- Password to add to cache
-