1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*******************************************************************************
* Copyright (c) 2013 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.transaction;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
import org.eclipse.osee.orcs.core.internal.graph.GraphData;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.HasSession;
/**
* @author Roberto E. Escobar
* @author Megumi Telles
*/
public class TxData implements HasSession {
public static enum TxState {
NEW_TX,
COMMIT_STARTED,
COMMITTED,
COMMIT_FAILED;
}
private final OrcsSession session;
private final GraphData graph;
private final Map<String, Artifact> writeables = new HashMap<>();
private final Map<String, ArtifactReadable> readables = new HashMap<>();
private ArtifactReadable author;
private String comment;
private volatile boolean isCommitInProgress;
private volatile TxState txState;
public TxData(OrcsSession session, GraphData graph) {
this.session = session;
this.graph = graph;
this.txState = TxState.NEW_TX;
}
public void clear() {
isCommitInProgress = false;
writeables.clear();
readables.clear();
}
@Override
public OrcsSession getSession() {
return session;
}
public IOseeBranch getBranch() {
return graph.getBranch();
}
public GraphData getGraph() {
return graph;
}
public ArtifactReadable getAuthor() {
return author;
}
public String getComment() {
return comment;
}
public TxState getTxState() {
return txState;
}
public boolean isCommitInProgress() {
return isCommitInProgress;
}
public void setAuthor(ArtifactReadable author) {
this.author = author;
}
public void setComment(String comment) {
this.comment = comment;
}
public void setTxState(TxState txState) {
this.txState = txState;
}
public void setCommitInProgress(boolean isCommitInProgress) {
this.isCommitInProgress = isCommitInProgress;
}
public Artifact add(Artifact artifact) {
return writeables.put(artifact.getGuid(), artifact);
}
public void add(ArtifactReadable artifact) {
readables.put(artifact.getGuid(), artifact);
}
public Iterable<Artifact> getAllWriteables() {
return writeables.values();
}
public Artifact getWriteable(ArtifactId artifactId) {
return writeables.get(artifactId.getGuid());
}
public ArtifactReadable getReadable(ArtifactId artifactId) {
return readables.get(artifactId.getGuid());
}
@Override
public String toString() {
return "TxData [session=" + session + ", graph=" + graph + ", author=" + author + ", comment=" + comment + ", isCommitInProgress=" + isCommitInProgress + ", txState=" + txState + "]";
}
}
|