mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify — inline CompoundSaveSession
This commit is contained in:
-66
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.components.impl.stores;
|
||||
|
||||
import com.intellij.openapi.components.StateStorage;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CompoundSaveSession {
|
||||
private final Map<StateStorage, StateStorage.SaveSession> mySaveSessions = new THashMap<StateStorage, StateStorage.SaveSession>();
|
||||
|
||||
public CompoundSaveSession(@NotNull CompoundExternalizationSession compoundExternalizationSession) {
|
||||
for (StateStorage stateStorage : compoundExternalizationSession.getStateStorages()) {
|
||||
mySaveSessions.put(stateStorage, stateStorage.startSave(compoundExternalizationSession.getExternalizationSession(stateStorage)));
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
for (StateStorage.SaveSession saveSession : mySaveSessions.values()) {
|
||||
saveSession.save();
|
||||
}
|
||||
}
|
||||
|
||||
public void finishSave() {
|
||||
RuntimeException re = null;
|
||||
for (StateStorage stateStorage : mySaveSessions.keySet()) {
|
||||
try {
|
||||
stateStorage.finishSave(mySaveSessions.get(stateStorage));
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
re = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (re != null) {
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
public StateStorage.SaveSession getSaveSession(@NotNull StateStorage storage) {
|
||||
return mySaveSessions.get(storage);
|
||||
}
|
||||
|
||||
public void collectAllStorageFiles(@NotNull List<VirtualFile> files) {
|
||||
for (StateStorage.SaveSession saveSession : mySaveSessions.values()) {
|
||||
saveSession.collectAllStorageFiles(files);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-6
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.components.impl.stores;
|
||||
|
||||
import com.intellij.codeInspection.SmartHashMap;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -467,29 +468,47 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
|
||||
protected abstract String getOldStorageSpec(@NotNull Object component, @NotNull String componentName, @NotNull StateStorageOperation operation);
|
||||
|
||||
protected class MySaveSession implements SaveSession {
|
||||
CompoundSaveSession myCompoundSaveSession;
|
||||
private final Map<StateStorage, StateStorage.SaveSession> mySaveSessions = new SmartHashMap<StateStorage, StateStorage.SaveSession>();
|
||||
|
||||
public MySaveSession(@NotNull MyExternalizationSession externalizationSession) {
|
||||
myCompoundSaveSession = new CompoundSaveSession(externalizationSession.myCompoundExternalizationSession);
|
||||
for (StateStorage stateStorage : externalizationSession.myCompoundExternalizationSession.getStateStorages()) {
|
||||
mySaveSessions.put(stateStorage, stateStorage.startSave(externalizationSession.myCompoundExternalizationSession.getExternalizationSession(stateStorage)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectAllStorageFiles(@NotNull List<VirtualFile> files) {
|
||||
myCompoundSaveSession.collectAllStorageFiles(files);
|
||||
for (StateStorage.SaveSession saveSession : mySaveSessions.values()) {
|
||||
saveSession.collectAllStorageFiles(files);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws StateStorageException {
|
||||
assert mySession == this;
|
||||
myCompoundSaveSession.save();
|
||||
for (StateStorage.SaveSession saveSession : mySaveSessions.values()) {
|
||||
saveSession.save();
|
||||
}
|
||||
}
|
||||
|
||||
public void finishSave() {
|
||||
RuntimeException re = null;
|
||||
try {
|
||||
LOG.assertTrue(mySession == this);
|
||||
}
|
||||
finally {
|
||||
myCompoundSaveSession.finishSave();
|
||||
for (StateStorage stateStorage : mySaveSessions.keySet()) {
|
||||
try {
|
||||
stateStorage.finishSave(mySaveSessions.get(stateStorage));
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
re = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (re != null) {
|
||||
throw re;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,7 +517,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
|
||||
public Set<String> analyzeExternalChanges(@NotNull Set<Pair<VirtualFile, StateStorage>> changedFiles) {
|
||||
Set<String> result = null;
|
||||
for (Pair<VirtualFile, StateStorage> pair : changedFiles) {
|
||||
StateStorage.SaveSession saveSession = myCompoundSaveSession.getSaveSession(pair.second);
|
||||
StateStorage.SaveSession saveSession = mySaveSessions.get(pair.second);
|
||||
if (saveSession == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user