Skip to content

Commit

Permalink
Merge pull request #96 from bpangburn/4.0.5-SNAPSHOT
Browse files Browse the repository at this point in the history
4.0.5 snapshot
  • Loading branch information
bpangburn authored Nov 22, 2021
2 parents ce4ed14 + ea22164 commit 4f1ac8c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
2 changes: 1 addition & 1 deletion swingset-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<version.maven-surefire-plugin>3.0.0-M5</version.maven-surefire-plugin>

<version.maven-compiler-plugin>3.8.1</version.maven-compiler-plugin>
<version.dependency-check-maven>6.4.1</version.dependency-check-maven>
<version.dependency-check-maven>6.5.0</version.dependency-check-maven>
<version.maven-source-plugin>3.2.1</version.maven-source-plugin>
<version.maven-assembly-plugin>3.3.0</version.maven-assembly-plugin>
<version.maven-gpg-plugin>3.0.1</version.maven-gpg-plugin>
Expand Down
4 changes: 3 additions & 1 deletion swingset/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ ChangeLog file for the SwingSet Open Toolkit for Java Swing.
==============================================================================

==============================================================================
SwingSet 4.0.5 - Released 2021-10-25
SwingSet 4.0.5 - Released 2021-11-22
==============================================================================

Changes:
1. Updated POM dependencies.
2. Fix for Issue #95 where adding a record to an empty rowset throws an
exception.

==============================================================================
SwingSet 4.0.4 - Released 2021-03-24
Expand Down
2 changes: 1 addition & 1 deletion swingset/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<version.maven-site-plugin>3.9.1</version.maven-site-plugin>

<version.maven-compiler-plugin>3.8.1</version.maven-compiler-plugin>
<version.dependency-check-maven>6.4.1</version.dependency-check-maven>
<version.dependency-check-maven>6.5.0</version.dependency-check-maven>
<version.maven-source-plugin>3.2.1</version.maven-source-plugin>
<version.maven-javadoc-plugin>3.3.1</version.maven-javadoc-plugin>
<version.maven-gpg-plugin>3.0.1</version.maven-gpg-plugin>
Expand Down
92 changes: 54 additions & 38 deletions swingset/src/main/java/com/nqadmin/swingset/SSDataNavigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,6 @@ class BusReceiver {
// }
// }
}

private void doUpdateRowWithoutPostUpdateOps() throws SQLException {
rowSet.updateRow();
}

private void doUpdateRow() throws SQLException {
// TODO: check consistency row state, button state
doUpdateRowWithoutPostUpdateOps();
dBNav.performPostUpdateOps();
}

/**
* Adds the listeners for the navigator components.
Expand All @@ -460,7 +450,7 @@ private void addNavListeners() {
logger.debug("FIRST button clicked.");
removeRowsetListener();
try {
if (!commitChanges()) return;
if (!commitChangesToDatabase(true)) return;

rowSet.first();

Expand All @@ -484,7 +474,7 @@ private void addNavListeners() {
logger.debug("PREVIOUS button clicked.");
removeRowsetListener();
try {
if (!commitChanges()) return;
if (!commitChangesToDatabase(true)) return;

if ((rowSet.getRow() != 0) && !rowSet.previous()) {
rowSet.first();
Expand All @@ -511,7 +501,7 @@ private void addNavListeners() {
logger.debug("NEXT button clicked.");
removeRowsetListener();
try {
if (!commitChanges()) return;
if (!commitChangesToDatabase(true)) return;

rowSet.next();

Expand All @@ -537,7 +527,7 @@ private void addNavListeners() {
logger.debug("LAST button clicked.");
removeRowsetListener();
try {
if (!commitChanges()) return;
if (!commitChangesToDatabase(true)) return;

rowSet.last();

Expand Down Expand Up @@ -584,14 +574,10 @@ private void addNavListeners() {
setRowModified(false);
updateNavigator();
} else {
// ELSE UPDATE THE PRESENT ROW VALUES.
if (!dBNav.allowUpdate()) {
// UPDATE NOT ALLOWED SO DO NOTHING.
// WE SHOULD NOT MOVE TO THE ROW AS THE USER HAS MADE CHANGES TO
// TO THE ROW THAT SHOULD BE UNDONE.
return;
}
doUpdateRowWithoutPostUpdateOps();
// ELSE UPDATE THE DATABASE BASED ON THE PRESENT ROW VALUES.
// IN THIS CASE WE WILL WAIT TO PERFORM POST-UPDATE OPS BELOW
if (!commitChangesToDatabase(false)) return;

setRowModified(false);
// TODO: why not updateNavigator?
updateButtonState();
Expand All @@ -605,7 +591,7 @@ private void addNavListeners() {
// number did.
//
// 2020-12-24
// TODO: might get rid of this if broadcasing the right info,
// TODO: might get rid of this if broadcasting the right info,
// like picking up on the "other" component broadcast
//
rowSet.absolute(rowSet.getRow());
Expand Down Expand Up @@ -645,7 +631,11 @@ private void addNavListeners() {
rowSet.cancelRowUpdates();
setInserting(rowSet, false);
dBNav.performCancelOps();
rowSet.refreshRow();

// Only attempt to refresh row if we have at least one record
if (rowSet.getRow() > 0) {
rowSet.refreshRow();
}

setRowModified(false);
updateNavigator();
Expand Down Expand Up @@ -704,8 +694,10 @@ private void addNavListeners() {
logger.debug("ADD button clicked.");
removeRowsetListener();
try {
if (!commitChanges()) return;
// Commit changes for current row to database
commitChangesToDatabase(true);

// Move to insert row, update status, and update combo navigator (if applicable)
rowSet.moveToInsertRow();
setInserting(rowSet, true);
if (navCombo!=null) {
Expand Down Expand Up @@ -812,7 +804,7 @@ public void keyPressed(final KeyEvent ke) {

try {

if (!commitChanges()) return;
if (!commitChangesToDatabase(true)) return;

final int row = Integer.parseInt(txtCurrentRow.getText().trim());

Expand Down Expand Up @@ -888,24 +880,48 @@ protected void addToolTips() {

/**
* Common code to commit changes to the database from the rowset if
* modifications are allowed.
* @return true unless dBNav.allowUpdate() returns false
* modifications are allowed. After committing, it performs any
* post-update operations.
* <p>
* If modification==false, then skip the update and return as
* successful, unless we have an empty rowset.
*
* @param _performPostUpdateOps true if performPostUpdateOps() should
* be called after successful update, otherwise false
*
* @return true unless there are no records OR dBNav.allowUpdate() returns false
* @throws SQLException SQL Exception if rowset call to updateRow() fails
*/
private boolean commitChanges() throws SQLException {
if (modification) {
private boolean commitChangesToDatabase(final boolean _performPostUpdateOps) throws SQLException {

boolean result = true;

// check for an empty rowset
if (rowSet.getRow() == 0) {
result = false;
}

// if we have at least one row and the user has not set modifications to false (read-only)
// then continue to attempt to update database based on current rowset values
if (result && modification) {
if (!dBNav.allowUpdate()) {
// UPDATE NOT ALLOWED SO DO NOTHING.
// WE SHOULD NOT MOVE TO THE ROW AS THE USER HAS MADE CHANGES TO
// TO THE ROW THAT SHOULD BE UNDONE.
return false;
result = false;
} else {
rowSet.updateRow();
}
//rowSet.updateRow();
//dBNav.performPostUpdateOps();
doUpdateRow();
}

return true;
// if update was successful or modifications are set to false (read-only) then
// attempt post-update operations based on method parameter
//
// note that where modifications are set to false, we're pretending to have
// successfully updated the database
if (result && _performPostUpdateOps) {
dBNav.performPostUpdateOps();
}

// return
return result;
}

/**
Expand Down

0 comments on commit 4f1ac8c

Please sign in to comment.