- try {
- state = HeadState.load(lastSessionDirectory);
- } catch (InvalidHeadStateException e) {
- // For backwards compatibility only!
- Throwable cause = e.getCause();
- if (cause instanceof Throwable) {
- try {
- org.simantics.db.javacore.HeadState oldState = org.simantics.db.javacore.HeadState.load(lastSessionDirectory);
-
- HeadState newState = new HeadState();
- newState.clusters = oldState.clusters;
- newState.cs = oldState.cs;
- newState.files = oldState.files;
- newState.stream = oldState.stream;
- newState.headChangeSetId = oldState.headChangeSetId;
- newState.reservedIds = oldState.reservedIds;
- newState.transactionId = oldState.transactionId;
- state = newState;
- } catch (InvalidHeadStateException e1) {
- throw new IOException("Could not load HeadState due to corruption", e1);
- }
- } else {
- // This should never happen as MainState.load() checks the integrity
- // of head.state files and rolls back in cases of corruption until a
- // consistent state is found (could be case 0 - initial db state)
- // IF this does happen something is completely wrong
- throw new IOException("Could not load HeadState due to corruption", e);
- }
- }
+ if (mainState.isInitial()) {
+ state = new HeadState();
+ } else {
+ try {
+ state = HeadState.load(lastSessionDirectory);
+ } catch (InvalidHeadStateException e) {
+ // For backwards compatibility only!
+ Throwable cause = e.getCause();
+ if (cause instanceof Throwable) {
+ try {
+ org.simantics.db.javacore.HeadState oldState = org.simantics.db.javacore.HeadState.load(lastSessionDirectory);
+
+ HeadState newState = new HeadState();
+ newState.clusters = oldState.clusters;
+ newState.cs = oldState.cs;
+ newState.files = oldState.files;
+ newState.stream = oldState.stream;
+ newState.headChangeSetId = oldState.headChangeSetId;
+ newState.reservedIds = oldState.reservedIds;
+ newState.transactionId = oldState.transactionId;
+ state = newState;
+ } catch (InvalidHeadStateException e1) {
+ throw new IOException("Could not load HeadState due to corruption", e1);
+ }
+ } else {
+ // This should never happen as MainState.load() checks the integrity
+ // of head.state files and rolls back in cases of corruption until a
+ // consistent state is found (could be case 0 - initial db state)
+ // IF this does happen something is completely wrong
+ throw new IOException("Could not load HeadState due to corruption", e);
+ }
+ }
+ }