1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony GEAY (EDF R&D)
21 #include "SALOMESDS_Transaction.hxx"
22 #include "SALOMESDS_Exception.hxx"
23 #include "SALOMESDS_PickelizedPyObjServer.hxx"
24 #include "SALOMESDS_PickelizedPyObjRdWrServer.hxx"
25 #include "SALOMESDS_PickelizedPyObjRdExtServer.hxx"
29 using namespace SALOMESDS;
31 void Transaction::FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret)
33 std::size_t sz(bsToBeConv.length());
35 unsigned char *buf(const_cast<unsigned char *>(&ret[0]));
36 for(std::size_t i=0;i<sz;i++)
40 void Transaction::FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret)
42 std::size_t sz(bsToBeConv.size());
44 for(std::size_t i=0;i<sz;i++)
48 Transaction::~Transaction()
52 TransactionVarCreate::TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):Transaction(dsct,varName)
54 FromByteSeqToVB(constValue,_data);
57 void TransactionVarCreate::prepareRollBackInCaseOfFailure()
58 {//nothing it is not a bug
59 checkNotAlreadyExisting();
62 void TransactionVarCreate::rollBack()
64 if(_dsct->existVar(_var_name.c_str()))
65 _dsct->deleteVar(_var_name.c_str());
69 * no implementation it is not a bug !
71 void TransactionVarCreate::notify()
75 void TransactionRdOnlyVarCreate::perform()
77 SALOME::ByteVec data2;
78 FromVBToByteSeq(_data,data2);
79 _dsct->createRdOnlyVarInternal(_var_name,data2);
82 void TransactionRdExtVarCreate::perform()
84 SALOME::ByteVec data2;
85 FromVBToByteSeq(_data,data2);
86 _dsct->createRdExtVarInternal(_var_name,data2);
89 void TransactionRdWrVarCreate::perform()
91 SALOME::ByteVec data2;
92 FromVBToByteSeq(_data,data2);
93 _dsct->createRdWrVarInternal(_var_name,data2);
96 TransactionDictModify::TransactionDictModify(DataScopeServerTransaction *dsct, const std::string& varName):Transaction(dsct,varName),_varc(0)
98 _varc=checkVarExistingAndDict();
101 void TransactionDictModify::prepareRollBackInCaseOfFailure()
103 _zeDataBefore.clear();
104 PyObject *zeDictPy(_varc->getPyObj());
105 Py_XINCREF(zeDictPy);
106 _zeDataBefore=_varc->pickelize(zeDictPy);
109 void TransactionDictModify::rollBack()
111 PyObject *obj(_varc->getPyObjFromPickled(_zeDataBefore));
112 _varc->setNewPyObj(obj);
113 _zeDataBefore.clear();
116 TransactionAddKeyValue::TransactionAddKeyValue(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value):TransactionDictModify(dsct,varName)
118 std::vector<unsigned char> key2,value2;
119 FromByteSeqToVB(key,key2);
120 FromByteSeqToVB(value,value2);
121 _key=PickelizedPyObjServer::GetPyObjFromPickled(key2,_dsct);
122 _value=PickelizedPyObjServer::GetPyObjFromPickled(value2,_dsct);
125 void TransactionAddKeyValue::prepareRollBackInCaseOfFailure()
127 TransactionDictModify::prepareRollBackInCaseOfFailure();
128 _dsct->pingKey(_key);// check that key is OK with all waiting keys
131 void TransactionAddKeyValue::notify()
133 _dsct->notifyKey(getVarName(),_key,_value);
136 TransactionAddKeyValue::~TransactionAddKeyValue()
142 TransactionAddKeyValueHard::TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value):TransactionAddKeyValue(dsct,varName,key,value)
146 void TransactionAddKeyValueHard::perform()
148 _varc->addKeyValueHard(_key,_value);
151 TransactionAddKeyValueErrorIfAlreadyExisting::TransactionAddKeyValueErrorIfAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value):TransactionAddKeyValue(dsct,varName,key,value)
153 _varc->checkKeyNotAlreadyPresent(_key);
156 void TransactionAddKeyValueErrorIfAlreadyExisting::perform()
158 _varc->addKeyValueErrorIfAlreadyExisting(_key,_value);
161 TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::TransactionRemoveKeyInVarErrorIfNotAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key):TransactionDictModify(dsct,varName),_key(0)
163 std::vector<unsigned char> key2;
164 FromByteSeqToVB(key,key2);
165 _key=PickelizedPyObjServer::GetPyObjFromPickled(key2,_dsct);
168 void TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::perform()
170 _varc->removeKeyInVarErrorIfNotAlreadyExisting(_key);
174 * no implementation it is not a bug !
176 void TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::notify()
180 TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::~TransactionRemoveKeyInVarErrorIfNotAlreadyExisting()
185 TransactionMorphRdWrIntoRdOnly::TransactionMorphRdWrIntoRdOnly(DataScopeServerTransaction *dsct, const std::string& varName):Transaction(dsct,varName)
189 SALOME::PickelizedPyObjRdWrServer_ptr TransactionMorphRdWrIntoRdOnly::getVar()
191 SALOME::BasicDataServer_var obj(_dsct->retrieveVarInternal(_var_name.c_str()));
192 SALOME::PickelizedPyObjRdWrServer_ptr ret(SALOME::PickelizedPyObjRdWrServer::_narrow(obj));
193 if(CORBA::is_nil(ret))
195 std::ostringstream oss; oss << "TransactionMorphRdWrIntoRdOnly::getVar : var \"" << _var_name << "\" has not expected PickelizedPyObjRdWrServer type !";
196 throw Exception(oss.str());
201 void TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure()
203 BasicDataServer *var(_dsct->retrieveVarInternal2(_var_name));
205 throw Exception("TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure : Returned var is NULL !");
206 PickelizedPyObjRdWrServer *varc(dynamic_cast<PickelizedPyObjRdWrServer *>(var));
208 throw Exception("TransactionMorphRdWrIntoRdOnly::prepareRollBackInCaseOfFailure : Returned var has not expected type !");
211 void TransactionMorphRdWrIntoRdOnly::perform()
213 _dsct->moveStatusOfVarFromRdWrToRdOnly(_var_name);
216 void TransactionMorphRdWrIntoRdOnly::rollBack()
218 _dsct->moveStatusOfVarFromRdOnlyToRdWr(_var_name);
222 * no implementation it is not a bug !
224 void TransactionMorphRdWrIntoRdOnly::notify()