summaryrefslogtreecommitdiff
path: root/src/TDF/TDF_Transaction.cxx
blob: f7f2b83d15fd44d63691eb2c69988f4a74e2e8c0 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// File:	TDF_Transaction.cxx
//      	-------------------
// Author:	DAUTRY Philippe
//		<fid@fox.paris1.matra-dtv.fr>
// Copyright:	Matra Datavision 1997

// Version:	0.0
// History:	Version	Date		Purpose
//		0.0	Oct  1 1997	Creation



#include <TDF_Transaction.ixx>

#undef DEB_TRANSACTION
#ifdef DEB
#define DEB_TRANSACTION
#endif
#undef DEB_TRANSACTION_DUMP

#include <TDF_Tool.hxx>

//=======================================================================
//function : TDF_Transaction
//purpose  : 
//=======================================================================

TDF_Transaction::TDF_Transaction
(const TCollection_AsciiString& aName)
: myUntilTransaction(0),
  myName(aName)
{}


//=======================================================================
//function : TDF_Transaction
//purpose  : Private copy constructor.
//=======================================================================

TDF_Transaction::TDF_Transaction(const TDF_Transaction& aTrans)
{}


//=======================================================================
//function : TDF_Transaction
//purpose  : 
//=======================================================================

TDF_Transaction::TDF_Transaction
(const Handle(TDF_Data)& aDF,
 const TCollection_AsciiString& aName)
: myDF(aDF),
  myUntilTransaction(0),
  myName(aName)
{}




//=======================================================================
//function : Initialize
//purpose  : Initializes a transaction ready to be opened.
//=======================================================================

void TDF_Transaction::Initialize(const Handle(TDF_Data)& aDF)
{
  if (IsOpen()) myDF->AbortUntilTransaction(myUntilTransaction);
  myDF = aDF;
  myUntilTransaction = 0;
}


//=======================================================================
//function : Open
//purpose  : 
//=======================================================================

Standard_Integer TDF_Transaction::Open()
{
#ifdef DEB_TRANSACTION
  cout<<"Transaction "<<myName<<" opens #"<<myDF->Transaction()+1<<endl;
#endif
  if (IsOpen())
    Standard_DomainError::Raise("This transaction is already open.");
  if (myDF.IsNull())
    Standard_NullObject::Raise("Null TDF_Data.");
  return myUntilTransaction = myDF->OpenTransaction();
}


//=======================================================================
//function : Commit
//purpose  : 
//=======================================================================

Handle(TDF_Delta) TDF_Transaction::Commit(const Standard_Boolean withDelta)
{
#ifdef DEB_TRANSACTION
  cout<<"Transaction "<<myName<<" commits ";
#endif
  Handle(TDF_Delta) delta;
  if (IsOpen()) {
#ifdef DEB_TRANSACTION
    cout<<"from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<endl;
#endif
#ifdef DEB_TRANSACTION_DUMP
    cout<<"DF before commit"<<endl;
    TDF_Tool::DeepDump(cout,myDF);
#endif
    Standard_Integer until = myUntilTransaction;
    myUntilTransaction = 0;
    delta = myDF->CommitUntilTransaction(until, withDelta);
#ifdef DEB_TRANSACTION_DUMP
    cout<<"DF after commit"<<endl;
    TDF_Tool::DeepDump(cout,myDF);
#endif
  }
#ifdef DEB_TRANSACTION
  else cout<<"but this transaction is not open!"<<endl;
#endif
  return delta;
}


//=======================================================================
//function : Abort
//purpose  : alias ~
//=======================================================================

void TDF_Transaction::Abort()
{
  if (IsOpen()) {
#ifdef DEB_TRANSACTION
    cout<<"Transaction "<<myName<<" aborts from #"<<myDF->Transaction()<<" until #"<<myUntilTransaction<<" while current is #"<<myDF->Transaction()<<endl;
#endif
#ifdef DEB_TRANSACTION_DUMP
    cout<<"DF before abort"<<endl;
    TDF_Tool::DeepDump(cout,myDF);
#endif
    myDF->AbortUntilTransaction(myUntilTransaction);
    myUntilTransaction = 0;
#ifdef DEB_TRANSACTION_DUMP
    cout<<"DF after abort"<<endl;
    TDF_Tool::DeepDump(cout,myDF);
#endif
  }
}