mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-07-30 07:18:37 -09:00
Merge remote-tracking branch 'origin/GP-7070_ghidra1_DBHandleIsChanged'
into patch (Closes #9346)
This commit is contained in:
@@ -46,6 +46,7 @@ public class DBHandle {
|
||||
|
||||
private long lastTransactionID;
|
||||
private volatile boolean txStarted = false;
|
||||
private volatile long txStartingModCount;
|
||||
|
||||
private boolean waitingForNewTransaction = false;
|
||||
private boolean reloadInProgress = false;
|
||||
@@ -472,6 +473,7 @@ public class DBHandle {
|
||||
}
|
||||
waitingForNewTransaction = false;
|
||||
txStarted = true;
|
||||
txStartingModCount = getModCount();
|
||||
return ++lastTransactionID;
|
||||
}
|
||||
|
||||
@@ -509,7 +511,7 @@ public class DBHandle {
|
||||
*/
|
||||
private synchronized boolean doEndTransaction(long id, boolean commit)
|
||||
throws DBRollbackException, IOException {
|
||||
if (id != lastTransactionID) {
|
||||
if (!txStarted || id != lastTransactionID) {
|
||||
throw new IllegalStateException("Transaction id is not active");
|
||||
}
|
||||
try {
|
||||
@@ -530,8 +532,10 @@ public class DBHandle {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (commit) {
|
||||
cachedChangedState = isChanged();
|
||||
}
|
||||
txStarted = false;
|
||||
cacheChangedState();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -762,11 +766,17 @@ public class DBHandle {
|
||||
|
||||
/**
|
||||
* Determine if the underlying database has changed.
|
||||
* NOTE: The returned value reflects a cached state assuming all underlaying database
|
||||
* transactions, saving, etc. are facilitated by this handle object.
|
||||
* <p>
|
||||
* While a transaction is active this value will reflect changes made during the transaction
|
||||
* which could ultimately never get committed. When a transaction is not active it is a
|
||||
* reflection of the committed state.
|
||||
*
|
||||
* @return true if unsaved changes have been made.
|
||||
*/
|
||||
public boolean isChanged() {
|
||||
if (txStarted) {
|
||||
return cachedChangedState || txStartingModCount != getModCount();
|
||||
}
|
||||
return cachedChangedState;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -552,6 +552,37 @@ public class DBTest extends AbstractGenericTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChanged() throws IOException {
|
||||
|
||||
assertFalse(dbh.isChanged());
|
||||
|
||||
long txId = dbh.startTransaction();
|
||||
try {
|
||||
assertFalse(dbh.isChanged());
|
||||
}
|
||||
finally {
|
||||
dbh.endTransaction(txId, true);
|
||||
}
|
||||
|
||||
assertFalse(dbh.isChanged());
|
||||
|
||||
txId = dbh.startTransaction();
|
||||
try {
|
||||
assertFalse(dbh.isChanged());
|
||||
|
||||
DBTestUtils.createLongKeyTable(dbh, "TABLE", DBTestUtils.SINGLE_LONG, false, false);
|
||||
assertEquals(1, dbh.getTableCount());
|
||||
|
||||
assertTrue(dbh.isChanged());
|
||||
}
|
||||
finally {
|
||||
dbh.endTransaction(txId, true);
|
||||
}
|
||||
|
||||
assertTrue(dbh.isChanged());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvents() throws IOException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user