Salome HOME
In SDS add killVar transaction.
[modules/kernel.git] / src / SALOMESDS / SALOMESDS_Transaction.hxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony GEAY (EDF R&D)
20
21 #ifndef __SALOMESDS_TRANSACTION_HXX__
22 #define __SALOMESDS_TRANSACTION_HXX__
23
24 #include "SALOMEconfig.h"
25 #include CORBA_SERVER_HEADER(SALOME_SDS)
26
27 #include "SALOMESDS_Defines.hxx"
28 #include "SALOMESDS_Exception.hxx"
29 #include "SALOMESDS_DataServerManager.hxx"
30
31 #include <string>
32 #include <vector>
33
34 namespace SALOMESDS
35 {
36   class PickelizedPyObjServer;
37   class PickelizedPyObjRdWrServer;
38   class PickelizedPyObjRdExtServer;
39
40   class SALOMESDS_EXPORT Transaction : public virtual POA_SALOME::Transaction, public POAHolder
41   {
42   public:
43     Transaction(DataScopeServerTransaction *dsct, const std::string& varName):_dsct(dsct),_var_name(varName) { if(!_dsct) throw Exception("Transaction constructor error !"); }
44     std::string getVarName() const { return _var_name; }
45     void checkVarExisting() { _dsct->checkExistingVar(_var_name); }
46     void checkNotAlreadyExisting() { _dsct->checkNotAlreadyExistingVar(_var_name); }
47     PortableServer::POA_var getPOA() const { return _dsct->getPOA(); }
48     virtual void prepareRollBackInCaseOfFailure() = 0;
49     virtual void perform() = 0;
50     virtual void rollBack() = 0;
51     virtual void notify() = 0;
52     virtual ~Transaction();
53   public:
54     static void FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret);
55     static void FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret);
56   protected:
57     DataScopeServerTransaction *_dsct;
58     std::string _var_name;
59   };
60
61   class TransactionVarCreate : public Transaction
62   {
63   public:
64     TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue);
65     void prepareRollBackInCaseOfFailure();
66     void rollBack();
67     void notify();
68   protected:
69     std::vector<unsigned char> _data;
70   };
71
72   class TransactionRdOnlyVarCreate : public TransactionVarCreate
73   {
74   public:
75     TransactionRdOnlyVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
76     void perform();
77   };
78
79   class TransactionRdExtVarCreate : public TransactionVarCreate
80   {
81   public:
82     TransactionRdExtVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
83     void perform();
84   };
85
86   class TransactionRdExtInitVarCreate : public TransactionVarCreate
87   {
88   public:
89     TransactionRdExtInitVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
90     void perform();
91   };
92
93   class TransactionRdWrVarCreate : public TransactionVarCreate
94   {
95   public:
96     TransactionRdWrVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):TransactionVarCreate(dsct,varName,constValue) { }
97     void perform();
98   };
99
100   class TransactionKillVar : public Transaction
101   {
102   public:
103     TransactionKillVar(DataScopeServerTransaction *dsct, const std::string& varName);
104     void prepareRollBackInCaseOfFailure();
105     void perform();
106     void rollBack();
107     void notify();
108   };
109
110   class PickelizedPyObjServer;
111
112   class TransactionDictModify : public Transaction
113   {
114   public:
115     TransactionDictModify(DataScopeServerTransaction *dsct, const std::string& varName);
116     PickelizedPyObjServer *checkVarExistingAndDict() { return _dsct->checkVarExistingAndDict(_var_name); }
117     void prepareRollBackInCaseOfFailure();
118     void rollBack();
119   protected:
120     std::string _zeDataBefore;
121     PickelizedPyObjServer *_varc;
122   };
123
124   class TransactionAddKeyValue : public TransactionDictModify
125   {
126   public:
127     TransactionAddKeyValue(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
128     void prepareRollBackInCaseOfFailure();
129     void notify();
130     ~TransactionAddKeyValue();
131   protected:
132     PyObject *_key;
133     PyObject *_value;
134   };
135
136   class TransactionAddKeyValueHard : public TransactionAddKeyValue
137   {
138   public:
139     TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
140     void perform();
141   };
142
143   class TransactionAddKeyValueErrorIfAlreadyExisting : public TransactionAddKeyValue
144   {
145   public:
146     TransactionAddKeyValueErrorIfAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value);
147     void perform();
148   };
149
150   class TransactionRemoveKeyInVarErrorIfNotAlreadyExisting : public TransactionDictModify
151   {
152   public:
153     TransactionRemoveKeyInVarErrorIfNotAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key);
154     void perform();
155     void notify();
156     ~TransactionRemoveKeyInVarErrorIfNotAlreadyExisting();
157   private:
158     PyObject *_key;
159   };
160
161   class TransactionMorphRdWrIntoRdOnly : public Transaction, public virtual POA_SALOME::TransactionRdWrAccess
162   {
163   public:
164     TransactionMorphRdWrIntoRdOnly(DataScopeServerTransaction *dsct, const std::string& varName);
165   public:
166     SALOME::PickelizedPyObjRdWrServer_ptr getVar();
167   public:
168     void prepareRollBackInCaseOfFailure();
169     void perform();
170     void rollBack();
171     void notify();
172   };
173
174   class TransactionMultiKeyAddSession : public Transaction, public virtual POA_SALOME::TransactionMultiKeyAddSession
175   {
176   public:
177     TransactionMultiKeyAddSession(DataScopeServerTransaction *dsct, const std::string& varName);
178   public://remotely callable
179     void addKeyValueInVarErrorIfAlreadyExistingNow(const SALOME::ByteVec& key, const SALOME::ByteVec& value);
180   public:
181     void prepareRollBackInCaseOfFailure();
182     void perform();
183     void rollBack();
184     void notify();
185   };
186 }
187
188 #endif