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"
27 using namespace SALOMESDS;
29 void Transaction::FromByteSeqToVB(const SALOME::ByteVec& bsToBeConv, std::vector<unsigned char>& ret)
31 std::size_t sz(bsToBeConv.length());
33 unsigned char *buf(const_cast<unsigned char *>(&ret[0]));
34 for(std::size_t i=0;i<sz;i++)
38 void Transaction::FromVBToByteSeq(const std::vector<unsigned char>& bsToBeConv, SALOME::ByteVec& ret)
40 std::size_t sz(bsToBeConv.size());
42 for(std::size_t i=0;i<sz;i++)
46 Transaction::~Transaction()
50 TransactionVarCreate::TransactionVarCreate(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& constValue):Transaction(dsct,varName)
52 FromByteSeqToVB(constValue,_data);
55 void TransactionVarCreate::prepareRollBackInCaseOfFailure()
56 {//nothing it is not a bug
57 checkNotAlreadyExisting();
60 void TransactionVarCreate::rollBack()
62 if(_dsct->existVar(_var_name.c_str()))
63 _dsct->deleteVar(_var_name.c_str());
67 TODO : To be implemented.
69 void TransactionVarCreate::notify()
73 void TransactionRdOnlyVarCreate::perform()
75 SALOME::ByteVec data2;
76 FromVBToByteSeq(_data,data2);
77 _dsct->createRdOnlyVarInternal(_var_name,data2);
80 void TransactionRdExtVarCreate::perform()
82 SALOME::ByteVec data2;
83 FromVBToByteSeq(_data,data2);
84 _dsct->createRdExtVarInternal(_var_name,data2);
87 void TransactionRdWrVarCreate::perform()
89 SALOME::ByteVec data2;
90 FromVBToByteSeq(_data,data2);
91 _dsct->createRdWrVarInternal(_var_name,data2);
94 TransactionDictModify::TransactionDictModify(DataScopeServerTransaction *dsct, const std::string& varName):Transaction(dsct,varName),_varc(0)
96 _varc=checkVarExistingAndDict();
99 void TransactionDictModify::prepareRollBackInCaseOfFailure()
101 _zeDataBefore.clear();
102 PyObject *zeDictPy(_varc->getPyObj());
103 Py_XINCREF(zeDictPy);
104 _zeDataBefore=_varc->pickelize(zeDictPy);
107 void TransactionDictModify::rollBack()
109 PyObject *obj(_varc->getPyObjFromPickled(_zeDataBefore));
110 _varc->setNewPyObj(obj);
111 _zeDataBefore.clear();
114 TransactionAddKeyValue::TransactionAddKeyValue(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value):TransactionDictModify(dsct,varName)
116 std::vector<unsigned char> key2,value2;
117 FromByteSeqToVB(key,key2);
118 FromByteSeqToVB(value,value2);
119 _key=PickelizedPyObjServer::GetPyObjFromPickled(key2,_dsct);
120 _value=PickelizedPyObjServer::GetPyObjFromPickled(value2,_dsct);
123 void TransactionAddKeyValue::prepareRollBackInCaseOfFailure()
125 TransactionDictModify::prepareRollBackInCaseOfFailure();
126 _dsct->pingKey(_key);// check that key is OK with all waiting keys
129 void TransactionAddKeyValue::notify()
131 _dsct->notifyKey(_key,_value);
134 TransactionAddKeyValue::~TransactionAddKeyValue()
140 TransactionAddKeyValueHard::TransactionAddKeyValueHard(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value):TransactionAddKeyValue(dsct,varName,key,value)
144 void TransactionAddKeyValueHard::perform()
146 _varc->addKeyValueHard(_key,_value);
149 TransactionAddKeyValueErrorIfAlreadyExisting::TransactionAddKeyValueErrorIfAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key, const SALOME::ByteVec& value):TransactionAddKeyValue(dsct,varName,key,value)
151 _varc->checkKeyNotAlreadyPresent(_key);
154 void TransactionAddKeyValueErrorIfAlreadyExisting::perform()
156 _varc->addKeyValueErrorIfAlreadyExisting(_key,_value);
159 TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::TransactionRemoveKeyInVarErrorIfNotAlreadyExisting(DataScopeServerTransaction *dsct, const std::string& varName, const SALOME::ByteVec& key):TransactionDictModify(dsct,varName),_key(0)
161 std::vector<unsigned char> key2;
162 FromByteSeqToVB(key,key2);
163 _key=PickelizedPyObjServer::GetPyObjFromPickled(key2,_dsct);
166 void TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::perform()
168 _varc->removeKeyInVarErrorIfNotAlreadyExisting(_key);
172 * not implementation it is not a bug !
174 void TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::notify()
178 TransactionRemoveKeyInVarErrorIfNotAlreadyExisting::~TransactionRemoveKeyInVarErrorIfNotAlreadyExisting()